Panda3D
Classes | Variables
direct.tkpanels.FSMInspector Namespace Reference

Classes

class  FSMInspector
 
class  StateInspector
 

Variables

tuple DELTA = (5.0 / 360.) * 2.0 * math.pi
 

Detailed Description

Defines the `FSMInspector` class, which opens a Tkinter window for
inspecting :ref:`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())

Variable Documentation

◆ DELTA

tuple DELTA = (5.0 / 360.) * 2.0 * math.pi