|
|
|
Michael Barton
|
Some javascript/style in this post has been disabled (why?)
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. 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). 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. Michael __________________________________________ Michael Barton, Professor of Anthropology School of Human Evolution & Social Change Center for Social Dynamics & Complexity Arizona State University phone: 480-965-6213 fax: 480-965-7671 www: http://www.public.asu.edu/~cmbarton _______________________________________________ grassgui mailing list [hidden email] http://grass.itc.it/mailman/listinfo/grassgui |
||||||||||||||||
|
Jachym Cepicky
|
Hi,
today, I would like introduce few changes to mapdisp.py, which will a) make it possible to use special p.* command set (e.g. p.rast soils) b) use exactly what you are desribing here: timer, which is regulary checking, if something is happening.. on the other hand, I do not think, we should use this kind of code only there, where it is really needed, because messes the code a bit. looking at the menuform.py code, we just need to integrate it a little bit more. I updated menuform.py, see line 342 and in gismutils.py lines 200 and 204 jachym 2007/3/19, Michael Barton <[hidden email]>: > > 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. > > 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). 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. > > > Michael > __________________________________________ > Michael Barton, Professor of Anthropology > School of Human Evolution & Social Change > Center for Social Dynamics & Complexity > Arizona State University > > phone: 480-965-6213 > fax: 480-965-7671 > www: http://www.public.asu.edu/~cmbarton > > -- Jachym Cepicky e-mail: jachym.cepicky gmail com URL: http://les-ejk.cz GPG: http://www.les-ejk.cz/pgp/jachym_cepicky-gpg.pub _______________________________________________ grassgui mailing list [hidden email] http://grass.itc.it/mailman/listinfo/grassgui |
||||||||||||||||
|
Daniel Calvelo
|
In reply to this post
by Michael Barton
You could make your callback function (the one you wish executed as
the value is returned) a parameter to __init__ in menuform, that is called from within menuform.onRun if set to stg else than None. I think that is what you call a hook. You have to build something quite involved to have signaling objects behave like normal variables, AFAICT. Daniel. On 3/19/07, Michael Barton <[hidden email]> 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. > > 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). 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. > > > Michael > __________________________________________ > Michael Barton, Professor of Anthropology > School of Human Evolution & Social Change > Center for Social Dynamics & Complexity > Arizona State University > > phone: 480-965-6213 > fax: 480-965-7671 > www: http://www.public.asu.edu/~cmbarton > > -- -- Daniel Calvelo Aros _______________________________________________ grassgui mailing list [hidden email] http://grass.itc.it/mailman/listinfo/grassgui |
||||||||||||||||
|
Michael Barton
|
In reply to this post
by Jachym Cepicky
Jachym,
It looks like you are doing with menuform and gismutils exactly what I've been messing with in my local copy. Maybe you can do this better than I at this point, so I'll mention a couple of items. There is a section in menuform (near where you asked " Michael, we have the command here, what to do?") that is set up for d.* commands. I thought it should just return the command. if errors: self.OnError(errStr) else: if cmd[0:2] == "d.": # Send GRASS display command(s)with arguments # to the display processor. # Display with focus receives display command(s). ## self.console_output.write(cmd+"\n----------\n") return cmd The idea is to get this d.* command back to the layer manager (where it is called in gismutils.LayerTree.onActivate) so that it can send it on to render.py with the rest the information for each layer. The second thing for anyone wanting to upgrade menuform is to implement the new select.Select class. This will create a nice dropdown combo box for selecting maps or any other gis element in response to the "Prompt" parameter in task-description. I started messing with it and have it working, but working incorrectly. Let me know how the new changes work. Michael On 3/19/07 9:20 AM, "Jachym Cepicky" <[hidden email]> wrote: > Hi, > > today, I would like introduce few changes to mapdisp.py, which will > > a) make it possible to use special p.* command set (e.g. p.rast soils) > b) use exactly what you are desribing here: timer, which is regulary > checking, if something is happening.. > > on the other hand, I do not think, we should use this kind of code > only there, where it is really needed, because messes the code a bit. > > looking at the menuform.py code, we just need to integrate it a little bit > more. > > I updated menuform.py, see line 342 and in gismutils.py lines 200 and 204 > > jachym > > 2007/3/19, Michael Barton <[hidden email]>: >> >> 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. >> >> 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). 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. >> >> >> Michael >> __________________________________________ >> Michael Barton, Professor of Anthropology >> School of Human Evolution & Social Change >> Center for Social Dynamics & Complexity >> Arizona State University >> >> phone: 480-965-6213 >> fax: 480-965-7671 >> www: http://www.public.asu.edu/~cmbarton >> >> > __________________________________________ Michael Barton, Professor of Anthropology School of Human Evolution & Social Change Center for Social Dynamics & Complexity Arizona State University phone: 480-965-6213 fax: 480-965-7671 www: http://www.public.asu.edu/~cmbarton _______________________________________________ grassgui mailing list [hidden email] http://grass.itc.it/mailman/listinfo/grassgui |
||||||||||||||||
|
Michael Barton
|
In reply to this post
by Daniel Calvelo
Daniel,
I don't think I explained myself very clearly. Here is what I had in mind. This is a primitive description of the workflow I'm trying to do 1. module A calls module B 2. module B starts a GUI window that collects user information (d.* command options) 3. User closes GUI window 4. Information collected in GUI window is returned to module A 5. module A processes information collected in GUI launced by module B Is your response below related to such a work flow? It's the same idea as launching a dialog and then invoking the ShowModal() method to wait until it closes and capture what the dialog does. Does this need to be done via a dialog only, or can it be emulated with a normal window? Michael On 3/19/07 9:24 AM, "Daniel Calvelo" <[hidden email]> wrote: > You could make your callback function (the one you wish executed as > the value is returned) a parameter to __init__ in menuform, that is > called from within menuform.onRun if set to stg else than None. I > think that is what you call a hook. > > You have to build something quite involved to have signaling objects > behave like normal variables, AFAICT. > > Daniel. > > On 3/19/07, Michael Barton <[hidden email]> 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. >> >> 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). 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. >> >> >> Michael >> __________________________________________ >> Michael Barton, Professor of Anthropology >> School of Human Evolution & Social Change >> Center for Social Dynamics & Complexity >> Arizona State University >> >> phone: 480-965-6213 >> fax: 480-965-7671 >> www: http://www.public.asu.edu/~cmbarton >> >> > __________________________________________ Michael Barton, Professor of Anthropology School of Human Evolution & Social Change Center for Social Dynamics & Complexity Arizona State University phone: 480-965-6213 fax: 480-965-7671 www: http://www.public.asu.edu/~cmbarton _______________________________________________ grassgui mailing list [hidden email] http://grass.itc.it/mailman/listinfo/grassgui |
||||||||||||||||
|
Daniel Calvelo
|
On 3/19/07, Michael Barton <[hidden email]> wrote:
> Daniel, > > I don't think I explained myself very clearly. Here is what I had in mind. Sorry, it was me who got speedy. > This is a primitive description of the workflow I'm trying to do > > 1. module A calls module B > > 2. module B starts a GUI window that collects user information (d.* command > options) > > 3. User closes GUI window > > 4. Information collected in GUI window is returned to module A > > 5. module A processes information collected in GUI launced by module B > > Is your response below related to such a work flow? Yes. The idea is: module A calls module B *and tells it what to do when closing* technically, you would have in A def do_the_rest( the_value_we_need ): do_it( the_value_we_need ) moduleB.startplease( when_finished = do_the_rest ) and module B has to a) accept this when_finished parameter in the startplease method and b) call it within the button pressed event. Stg like: def startplease( self, when_finished=None): self.onRunHook = when_finished ... def onRun(self, event): ... if self.onRunHook is not None: self.onRunHook() # run it ... > It's the same idea as > launching a dialog and then invoking the ShowModal() method to wait until it > closes and capture what the dialog does. Does this need to be done via a > dialog only, or can it be emulated with a normal window? In wx you can have modal panels, so yes, you can build your own dialog-like window and set it to modal mode. You may grab the thuban sources and look at the classifier ui code for inspiration. > Michael Daniel. > On 3/19/07 9:24 AM, "Daniel Calvelo" <[hidden email]> wrote: > > > You could make your callback function (the one you wish executed as > > the value is returned) a parameter to __init__ in menuform, that is > > called from within menuform.onRun if set to stg else than None. I > > think that is what you call a hook. > > > > You have to build something quite involved to have signaling objects > > behave like normal variables, AFAICT. > > > > Daniel. > > > > On 3/19/07, Michael Barton <[hidden email]> 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. > >> > >> 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). 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. > >> > >> > >> Michael > >> __________________________________________ > >> Michael Barton, Professor of Anthropology > >> School of Human Evolution & Social Change > >> Center for Social Dynamics & Complexity > >> Arizona State University > >> > >> phone: 480-965-6213 > >> fax: 480-965-7671 > >> www: http://www.public.asu.edu/~cmbarton > >> > >> > > > > __________________________________________ > Michael Barton, Professor of Anthropology > School of Human Evolution & Social Change > Center for Social Dynamics & Complexity > Arizona State University > > phone: 480-965-6213 > fax: 480-965-7671 > www: http://www.public.asu.edu/~cmbarton > > > -- -- Daniel Calvelo Aros _______________________________________________ grassgui mailing list [hidden email] http://grass.itc.it/mailman/listinfo/grassgui |
||||||||||||||||
|
Michael Barton
|
Thanks much. I think this is what I need.
Michael On 3/19/07 10:16 AM, "Daniel Calvelo" <[hidden email]> wrote: > On 3/19/07, Michael Barton <[hidden email]> wrote: >> Daniel, >> >> I don't think I explained myself very clearly. Here is what I had in mind. > > Sorry, it was me who got speedy. > >> This is a primitive description of the workflow I'm trying to do >> >> 1. module A calls module B >> >> 2. module B starts a GUI window that collects user information (d.* command >> options) >> >> 3. User closes GUI window >> >> 4. Information collected in GUI window is returned to module A >> >> 5. module A processes information collected in GUI launced by module B >> >> Is your response below related to such a work flow? > > Yes. The idea is: > > module A calls module B *and tells it what to do when closing* > > technically, you would have in A > > def do_the_rest( the_value_we_need ): > do_it( the_value_we_need ) > > moduleB.startplease( when_finished = do_the_rest ) > > and module B has to a) accept this when_finished parameter in the > startplease method and b) call it within the button pressed event. Stg > like: > > def startplease( self, when_finished=None): > self.onRunHook = when_finished > ... > > def onRun(self, event): > ... > if self.onRunHook is not None: > self.onRunHook() # run it > ... > >> It's the same idea as >> launching a dialog and then invoking the ShowModal() method to wait until it >> closes and capture what the dialog does. Does this need to be done via a >> dialog only, or can it be emulated with a normal window? > > In wx you can have modal panels, so yes, you can build your own > dialog-like window and set it to modal mode. You may grab the thuban > sources and look at the classifier ui code for inspiration. > >> Michael > > Daniel. > >> On 3/19/07 9:24 AM, "Daniel Calvelo" <[hidden email]> wrote: >> >>> You could make your callback function (the one you wish executed as >>> the value is returned) a parameter to __init__ in menuform, that is >>> called from within menuform.onRun if set to stg else than None. I >>> think that is what you call a hook. >>> >>> You have to build something quite involved to have signaling objects >>> behave like normal variables, AFAICT. >>> >>> Daniel. >>> >>> On 3/19/07, Michael Barton <[hidden email]> 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. >>>> >>>> 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). 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. >>>> >>>> >>>> Michael >>>> __________________________________________ >>>> Michael Barton, Professor of Anthropology >>>> School of Human Evolution & Social Change >>>> Center for Social Dynamics & Complexity >>>> Arizona State University >>>> >>>> phone: 480-965-6213 >>>> fax: 480-965-7671 >>>> www: http://www.public.asu.edu/~cmbarton >>>> >>>> >>> >> >> __________________________________________ >> Michael Barton, Professor of Anthropology >> School of Human Evolution & Social Change >> Center for Social Dynamics & Complexity >> Arizona State University >> >> phone: 480-965-6213 >> fax: 480-965-7671 >> www: http://www.public.asu.edu/~cmbarton >> >> >> > __________________________________________ Michael Barton, Professor of Anthropology School of Human Evolution & Social Change Center for Social Dynamics & Complexity Arizona State University phone: 480-965-6213 fax: 480-965-7671 www: http://www.public.asu.edu/~cmbarton _______________________________________________ grassgui mailing list [hidden email] http://grass.itc.it/mailman/listinfo/grassgui |
||||||||||||||||
|
Michael Barton
|
In reply to this post
by Daniel Calvelo
Daniel,
Please excuse my novice ignorance. I guess I need a bit of clarification. >> Is your response below related to such a work flow? > > Yes. The idea is: > > module A calls module B *and tells it what to do when closing* > > technically, you would have in A > > def do_the_rest( the_value_we_need ): > do_it( the_value_we_need ) > > moduleB.startplease( when_finished = do_the_rest ) I understand this and can add it to the LayerTree class in gismutils > > and module B has to a) accept this when_finished parameter in the > startplease method and b) call it within the button pressed event. Stg > like: This is where I'm more fuzzy. > > def startplease( self, when_finished=None): > self.onRunHook = when_finished > ... > Is self.onRunHook an event handler method or a variable? Is it built in or something I'd need to create? This (and the button) are in module B. I don't understand what self.onRunHook() is doing. > def onRun(self, event): > ... > if self.onRunHook is not None: > self.onRunHook() # run it > ... > Sorry to be so dense. Michael >> It's the same idea as >> launching a dialog and then invoking the ShowModal() method to wait until it >> closes and capture what the dialog does. Does this need to be done via a >> dialog only, or can it be emulated with a normal window? > > In wx you can have modal panels, so yes, you can build your own > dialog-like window and set it to modal mode. You may grab the thuban > sources and look at the classifier ui code for inspiration. > >> Michael > > Daniel. > >> On 3/19/07 9:24 AM, "Daniel Calvelo" <[hidden email]> wrote: >> >>> You could make your callback function (the one you wish executed as >>> the value is returned) a parameter to __init__ in menuform, that is >>> called from within menuform.onRun if set to stg else than None. I >>> think that is what you call a hook. >>> >>> You have to build something quite involved to have signaling objects >>> behave like normal variables, AFAICT. >>> >>> Daniel. >>> >>> On 3/19/07, Michael Barton <[hidden email]> 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. >>>> >>>> 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). 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. >>>> >>>> >>>> Michael >>>> __________________________________________ >>>> Michael Barton, Professor of Anthropology >>>> School of Human Evolution & Social Change >>>> Center for Social Dynamics & Complexity >>>> Arizona State University >>>> >>>> phone: 480-965-6213 >>>> fax: 480-965-7671 >>>> www: http://www.public.asu.edu/~cmbarton >>>> >>>> >>> >> >> __________________________________________ >> Michael Barton, Professor of Anthropology >> School of Human Evolution & Social Change >> Center for Social Dynamics & Complexity >> Arizona State University >> >> phone: 480-965-6213 >> fax: 480-965-7671 >> www: http://www.public.asu.edu/~cmbarton >> >> >> > __________________________________________ Michael Barton, Professor of Anthropology School of Human Evolution & Social Change Center for Social Dynamics & Complexity Arizona State University phone: 480-965-6213 fax: 480-965-7671 www: http://www.public.asu.edu/~cmbarton _______________________________________________ grassgui mailing list [hidden email] http://grass.itc.it/mailman/listinfo/grassgui |
||||||||||||||||
|
Glynn Clements
|
In reply to this post
by Michael Barton
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 <[hidden email]> _______________________________________________ grassgui mailing list [hidden email] http://grass.itc.it/mailman/listinfo/grassgui |
||||||||||||||||
|
Daniel Calvelo
|
In reply to this post
by Michael Barton
On 3/19/07, Michael Barton <[hidden email]> wrote:
> Daniel, > > Please excuse my novice ignorance. I guess I need a bit of clarification. Oh, I' m sorry I'm being unclear... > >> Is your response below related to such a work flow? > > > > Yes. The idea is: > > > > module A calls module B *and tells it what to do when closing* > > > > technically, you would have in A > > > > def do_the_rest( the_value_we_need ): > > do_it( the_value_we_need ) > > > > moduleB.startplease( when_finished = do_the_rest ) > > I understand this and can add it to the LayerTree class in gismutils > > > > > and module B has to a) accept this when_finished parameter in the > > startplease method and b) call it within the button pressed event. Stg > > like: > > This is where I'm more fuzzy. > > > > > def startplease( self, when_finished=None): > > self.onRunHook = when_finished > > ... > > > > Is self.onRunHook an event handler method or a variable? Is it built in or > something I'd need to create? onRunHook as defined above is a variable holding a function. When you call startplease() you pass it a when_finished parameter (the name is arbitrary, of course) whose value is a function waiting to be called with one argument. You then attach this function to self, which is the only object you may carry through event handlers. > This (and the button) are in module B. I don't understand what > self.onRunHook() is doing. > > > def onRun(self, event): > > ... > > if self.onRunHook is not None: > > self.onRunHook() # run it > > ... Here you are in the event handler. You have "armed" self with a function that has been defined by the calling module and attached to the object by the startplease method. If it is set (is not None, which is the default argument to the startplease method), then do call it. > Sorry to be so dense. > > Michael Don't, please. My fault for being sketchy. It is one of python's strenghts to treat functions, methods, even classes as things that can be carried around with variables. You can do stuff like: def print_one(): print "one" def print_two(): print "two" which_one={1:print_one, 2:print_two} which_one[ 1 ]() # call print_one, the value of which_one[1] This is perfect for event-driven programs, where the flow of the program is determined by what events occur in the interface. I'm sorry I'm not fluent in Tcl/Tk to give you the corresponding equivalents. Maybe somebody else is. Daniel. -- -- Daniel Calvelo Aros _______________________________________________ grassgui mailing list [hidden email] http://grass.itc.it/mailman/listinfo/grassgui |
||||||||||||||||
| Free Embeddable Forum Powered by Nabble | Help |