Saturday, April 25, 2009

Improved way to convert Python and C into buttons and more

"menu.txt" has been replaced with "clibraries.txt" and "pythonscripts.txt", because the fashion in which C libraries and Python scripts were loaded into TinkerCell has been reconstructed. Both of the new files contain much more flexibility about where and how the C and Python programs run. The screenshot on the right shows Python scripts in the context menu and the tools.

Here is how it works now:

The DynamicLibraryMenu class provides the following functions:

addFunction : adds a function to the functions tree.
arguments: function category, name, and icon

addMenuItem : adds a function to the function menu at the top (play button).
arguments: function name and icon

addContextMenuItem : adds a function to the context menu (mouse right button) when items of a particular family are selected; optionally shows the graphical tool.
arguments: target family, function name and icon, and whether or not to show the graphical tool

Therefore, this class simply serves to add actions and buttons to the functions tree, tool bar, and context menu. The actual actions themselves are determined by two other classes:

The LoadCLibrary class performs the following tasks:
  1. read and parse clibraries.txt
  2. setup the signals and slots that call each function specified in clibraries.txt
  3. place actions and toolbuttons using DynamicLibraryMenu
This class can be summarized by the following logic:

text file ---> actions group
action triggered ---> get name ---> get library name ---> new LibraryThread

The PythonTool class performs the following tasks:
  1. read and parse pythonscripts.txt
  2. host the Python interpreter thread
  3. setup the signals and slots that call each script specified in pythonscripts.txt
  4. place actions and toolbuttons using DynamicLibraryMenu
This class can be summarized by the following logic:

text file ---> actions group
action triggered ---> get name ---> get file name ---> call runPy

Rationale for the new setup:

  1. More modular: if a new interpreter needs to be hosted, say Ruby, then it can use the same format at the PythonTool class.
  2. More GUI: a C and Python program can appear in up to four places, i.e. the functions tree, the main toolbar menu, context menu, graphical tools




No comments: