[GRASSGUI] python question - waiting for a variable to change

Glynn Clements glynn at gclements.plus.com
Mon Mar 19 14:37:26 EDT 2007


Michael Barton wrote:

> I¹ve run into a little problem that is taxing my neophyte Python programming
> abilities. However we do a popup panel for setting display layer options, I
> think it is necessary to do something along the lines of the following....
> 
> 1. Start the options popup. This is currently done with a double click on
> the layer, which calls the onActivate even handler. For a raster, the event
> handler uses...
>         drastcmd = menuform.GUI().parseCommand('d.rast', gmpath)
>     ...to start the autogenerated GUI.
> 
> 2. When you press the ³run² button for this d.* command, the assembled
> command (d.rast + options) is simply returned.
> 
> 3. Now drastcmd should contain a complete d.rast command string.

No, it should contain a list (remember: argv is char**, not char*).

> So, how do I wait in onActivate until the ³run² button is pressed on the
> popup and the information is returned to drastcmd (i.e., the value of
> drastcmd is changed).

You don't. So long as Python is sitting waiting in onActivate, it
isn't going to get around to noticing that you've pressed the Run
button.

> Or, alternatively, how can a change in the value of
> drastcmd generate an event that I can capture and process? I messed around
> with wait() (thinking about tk_wait in TclTk), but couldn¹t get it to do
> what I wanted.

I don't entirely understand what your asking; it might be more clear
if double-clicking on the layer worked:

	Traceback (most recent call last):
	  File "/usr/local/src/grass/gui/Gism/gismutils.py", line 200, in onActivateLayer
	    menuform.GUI().parseCommand('d.rast', gmpath, self)
	TypeError: parseCommand() takes exactly 3 arguments (4 given)

GUI.parseCommand is prototyped as:

	def parseCommand(self, cmd, gmpath):

The "self" is passed automatically, so the call should probaly be:

	    menuform.GUI().parseCommand('d.rast', gmpath)

-- 
Glynn Clements <glynn at gclements.plus.com>




More information about the grass-gui mailing list