direct.tkpanels.FSMInspector

from direct.tkpanels.FSMInspector import FSMInspector, StateInspector

Defines the FSMInspector class, which opens a Tkinter window for inspecting Finite State Machines.

Using the Finite State Inspector

  1. In your Config.prc add:

    want-tk #t
    
  2. Start up the show and create a Finite State Machine:

    from direct.showbase.ShowBaseGlobal import *
    
    from direct.fsm import ClassicFSM
    from direct.fsm import State
    
    def enterState():
        print('enterState')
    
    def exitState():
        print 'exitState'
    
    fsm = ClassicFSM.ClassicFSM('stopLight',
              [State.State('red', enterState, exitState, ['green']),
                State.State('yellow', enterState, exitState, ['red']),
                State.State('green', enterState, exitState, ['yellow'])],
              'red',
              'red')
    
    import FSMInspector
    
    inspector = FSMInspector.FSMInspector(fsm, title = fsm.getName())
    
    # Note, the inspectorPos argument is optional, the inspector will
    # automagically position states on startup
    fsm = ClassicFSM.ClassicFSM('stopLight', [
        State.State('yellow',
                    enterState,
                    exitState,
                    ['red'],
                    inspectorPos = [95.9, 48.0]),
        State.State('red',
                    enterState,
                    exitState,
                    ['green'],
                    inspectorPos = [0.0, 0.0]),
        State.State('green',
                    enterState,
                    exitState,
                    ['yellow'],
                    inspectorPos = [0.0, 95.9])],
            'red',
            'red')
    
  3. Pop open a viewer:

    import FSMInspector
    insp = FSMInspector.FSMInspector(fsm)
    

or if you wish to be fancy:

insp = FSMInspector.FSMInspector(fsm, title = fsm.getName())

Features

  • Right mouse button over a state pops up a menu allowing you to request a transition to that state

  • Middle mouse button will grab the canvas and slide things around if your state machine is bigger than the viewing area

  • There are some self explanatory menu options up at the top, the most useful being: “print ClassicFSM layout” which will print out Python code which will create an ClassicFSM augmented with layout information for the viewer so everything shows up in the same place the next time you inspect the state machine

Caveat

There is an unexplained problem with using Tk and emacs right now which occasionally results in everything locking up. This procedure seems to avoid the problem for me:

# Start up the show
from direct.showbase.ShowBaseGlobal import *

# You will see the window and a Tk panel pop open

# Type a number at the emacs prompt
>>> 123

# At this point everything will lock up and you won't get your prompt back

# Hit a bunch of Control-C's in rapid succession, in most cases
# this will break you out of whatever badness you were in and
# from that point on everything will behave normally


# This is how you pop up an inspector
import FSMInspector
inspector = FSMInspector.FSMInspector(fsm, title = fsm.getName())

Inheritance diagram

Inheritance diagram of direct.tkpanels.FSMInspector

class FSMInspector(fsm, **kw)[source]

Bases: AppShell

__init__(self, fsm, **kw)[source]
addState(self, state)[source]
appInit(self)[source]
appname = 'ClassicFSM Inspector'
canvas(self)[source]
computeEndpoints(self, fromState, toState)[source]
computePoint(self, radius, angle)[source]
connectStates(self, fromState, toState)[source]
createInterface(self)[source]
createStateInspectors(self)[source]
drawConnections(self, event=None)[source]
enteredState(self, stateName)[source]
exitedState(self, stateName)[source]
findAngle(self, fromPoint, toPoint)[source]
frameHeight = 450
frameWidth = 400
getStateInspector(self, name)[source]
mouse2Down(self, event)[source]
mouse2Motion(self, event)[source]
onDestroy(self, event)[source]

Called on ClassicFSM Panel shutdown

popupGridDialog(self)[source]
printLayout(self)[source]
scrolledCanvas(self)[source]
setFontSize(self, size)[source]
setGridSize(self, size)[source]
setMarkerSize(self, size)[source]
toggleBalloon(self)[source]
toggleGridSnap(self)[source]
usecommandarea = 0
usestatusarea = 0
class StateInspector(inspector, state, **kw)[source]

Bases: MegaArchetype

__init__(self, inspector, state, **kw)[source]
center(self)[source]
enteredState(self)[source]
exitedState(self)[source]
getName(self)[source]
inspectSubMachine(self)[source]
mouseDown(self, event)[source]
mouseEnter(self, event)[source]
mouseLeave(self, event)[source]
mouseMotion(self, event)[source]
mouseRelease(self, event)[source]
popupStateMenu(self, event)[source]
setGridSize(self, size)[source]
setPos(self, x, y, snapToGrid=0)[source]
setRadius(self, size)[source]
setText(self, text=None)[source]
transitionTo(self)[source]