Art Haas wrote:

Hi.

I've been busy with non-computer related things lately, so there has
been very little PythonCAD development activity of late. I removed some
unused code here and there and a few routines that were scheduled to
disappear, but not much new code has appeared lately.

While thinking about what parts of PythonCAD to work on, I began to
re-examine the handling of the commands, and in general how text from
the entry box at the bottom of the screen, is dealt with. Right now,
when text entry can provide data for a tool the usual way to handle this
is via eval(). That's all fine and good, but in view of the goal of
making the program scriptable this approach is too simplistic. A bit of
reading and tinkering with the 'exec' keyword demonstrated how it would
easy to add the ability to store variables and procedures on a per-image
basis. The key is storing in each image a dictionary that 'exec' can
populate with variables, functions, etc., as well as use previous stored
values. The syntax seems a bit odd though:


Hi,
Well... I don't have experience with parser, but thinking about the commands entry it reminded me this:
Have you had a look at gazpacho [1]?. It's a pygtk app that uses a CommandManager class and a Command class that wrap "commands and arguments" and execute them. It also manages undo and redo work.
The best point is that it may be safer than doing eval, as you don't allow your program do anything directly. You could take a command and do dispatching using a dict that has a key as command and a descriptor to the right Command.run(command_variables) to use.


Just an idea. Hope it helps. :)

[1] http://gruppy.sicem.biz/componentes
_______________________________________________
PythonCAD mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pythoncad

Reply via email to