how to use both wxGUI and command line?

Hi all,

after some time reading the list, it's time to write to ask advice :slight_smile:

I have a Python script that uses wxGUI, but need to set also command
line options to run the script without the GUI.
The script is a GRASS GIS Addon called v.krige [0], developed as Google
Summer of Code project. Code is available on SVN [1].

At the moment, if I type
$ v.krige.py

without options, I get the GUI and run analysis.

I wish to run the script non-interactively typing:
$ v.krige.py input=rs column=elev [more options here]

and it will run in the terminal.

My present idea is to create separate classes for interface and model.
I'm experiencing some difficulties as the functions that respond to
events in the GUI are inside the GUI classes, with the code needed to
perform analysis.
Does it have sense to create a class for the workhorse functions and
call it in the GUI via the OnEvent functions?

Any suggestion will be appreciated.

thanks in advance,
Anne

···

--
http://wiki.osgeo.org/wiki/Anne_Ghisla

[0] http://grass.osgeo.org/wiki/V.krige_GSoC_2009
[1]
https://trac.osgeo.org/grass/browser/grass-addons/vector/v.krige/v.krige.py?rev=38309

Hi Anne,

Hi all,

after some time reading the list, it's time to write to ask advice :slight_smile:

I have a Python script that uses wxGUI, but need to set also command
line options to run the script without the GUI.
The script is a GRASS GIS Addon called v.krige [0], developed as Google
Summer of Code project. Code is available on SVN [1].

At the moment, if I type
$ v.krige.py

without options, I get the GUI and run analysis.

I wish to run the script non-interactively typing:
$ v.krige.py input=rs column=elev [more options here]

and it will run in the terminal.

My present idea is to create separate classes for interface and model.
I'm experiencing some difficulties as the functions that respond to
events in the GUI are inside the GUI classes, with the code needed to
perform analysis.
Does it have sense to create a class for the workhorse functions and
call it in the GUI via the OnEvent functions?

Any suggestion will be appreciated.

thanks in advance,
Anne
--User:Aghisla - OSGeo

[0]V.krige GSoC 2009 - GRASS-Wiki
[1]https://trac.osgeo.org/grass/browser/grass-addons/vector/v.krige/v.kr

You'll need to follow some basic MVC type stuff. Create the View (i.e.
wxPython) stuff separate from the Controller (all the neat guts that
do something). Here's a goofy example:

<code>
# view.py

import wx
import controller

class MyForm(wx.Frame):

    def __init__(self):
        wx.Frame.__init__(self, None, wx.ID_ANY, "wx.Menu Tutorial")

        # Add a panel so it looks the correct on all platforms
        panel = wx.Panel(self, wx.ID_ANY)

        btn = wx.Button(panel, wx.ID_ANY, "Press Me!")

        btn.Bind(wx.EVT_BUTTON, self.onButton)

    def onButton(self, event):
        controller.DoSomething()

# Run the program
if __name__ == "__main__":
    app = wx.PySimpleApp()
    frame = MyForm().Show()
    app.MainLoop()

</code>

And here's a "controller":

<code>
# controller.py

def DoSomething(*args, **kwargs):
    # do something here
    print "I'm running something awesome here!"
</code>

Now, if you need the controller to communicate with the view, you'll
probably need to use pubsub, PostEvent, CallAfter or CallLater. The
last three are threadsafe (I think). If you interact with a database
or something like that then that's where the Model usually comes in.

I hope that all makes sense and that I didn't butcher the MVC model
too much with my explanation.

- Mike

···

On Jul 8, 7:04 am, Anne Ghisla <a.ghi...@gmail.com> wrote:

Hi Anne,

> Hi all,
>
> after some time reading the list, it's time to write to ask advice :slight_smile:
>
> I have a Python script that uses wxGUI, but need to set also command
> line options to run the script without the GUI.

[...]

You'll need to follow some basic MVC type stuff. Create the View (i.e.
wxPython) stuff separate from the Controller (all the neat guts that
do something). Here's a goofy example:

[...]

Now, if you need the controller to communicate with the view, you'll
probably need to use pubsub, PostEvent, CallAfter or CallLater. The
last three are threadsafe (I think). If you interact with a database
or something like that then that's where the Model usually comes in.

I hope that all makes sense and that I didn't butcher the MVC model
too much with my explanation.

It does, thanks for the quick response. I'll read some more
documentation about MVC as well.

many thanks and happy coding to everyone,

Anne

···

Il giorno mer, 08/07/2009 alle 06.31 -0700, Mike Driscoll ha scritto:

On Jul 8, 7:04 am, Anne Ghisla <a.ghi...@gmail.com> wrote:

Also see the example “Redirecting text from stdout to a
wx.TextCtrl”

http://wiki.wxpython.org/LongRunningTasks

Ray Schumacher

admin - Blue Cove Interactive

PO Box 8677, La Jolla, CA 92038

http://Blue-Cove.com

···

At 04:19 PM 7/8/2009 +0200, you wrote:

Il giorno mer, 08/07/2009 alle > 06.31 -0700, Mike Driscoll ha scritto:

Hi Anne,

On Jul 8, 7:04 am, Anne Ghisla a.ghi...@gmail.com > wrote:

Hi all,

after some time reading the list, it’s time to write to ask
advice :slight_smile:

I have a Python script that uses wxGUI, but need to set also
command

line options to run the script without the GUI.

[…]

You’ll need to follow some basic MVC type stuff. Create the View
(i.e.

wxPython) stuff separate from the Controller (all the neat guts
that

do something). Here’s a goofy example:

[…]

Now, if you need the controller to communicate with the view,
you’ll

probably need to use pubsub, PostEvent, CallAfter or CallLater.
The

last three are threadsafe (I think). If you interact with a
database

or something like that then that’s where the Model usually comes
in.

I hope that all makes sense and that I didn’t butcher the MVC
model

too much with my explanation.

It does, thanks for the quick response. I’ll read some more

documentation about MVC as well.

Thanks Ray for pointing this out - the module will need all informations
of that wiki page, as kriging is a dead long running task.

A consideration: it's curious how setting up a good interface requires
so much tuning. I'm just giving well-known functions a more humane
appearance, and it's indeed an endless way towards perfection :slight_smile:

regards,

Anne

···

Il giorno mer, 08/07/2009 alle 07.39 -0700, RayS ha scritto:

At 04:19 PM 7/8/2009 +0200, you wrote:
> Il giorno mer, 08/07/2009 alle 06.31 -0700, Mike Driscoll ha
> scritto:
> > Hi Anne,
> >
> > On Jul 8, 7:04 am, Anne Ghisla <a.ghi...@gmail.com> wrote:
> > > Hi all,
> > >
> > > after some time reading the list, it's time to write to ask
> advice :slight_smile:
> > >
> > > I have a Python script that uses wxGUI, but need to set also
> command
> > > line options to run the script without the GUI.
> [...]
> >
> > You'll need to follow some basic MVC type stuff. Create the View
> (i.e.
> > wxPython) stuff separate from the Controller (all the neat guts
> that
> > do something). Here's a goofy example:
> [...]
> >
> > Now, if you need the controller to communicate with the view,
> you'll
> > probably need to use pubsub, PostEvent, CallAfter or CallLater.
> The
> > last three are threadsafe (I think). If you interact with a
> database
> > or something like that then that's where the Model usually comes
> in.
> >
> > I hope that all makes sense and that I didn't butcher the MVC
> model
> > too much with my explanation.
>
> It does, thanks for the quick response. I'll read some more
> documentation about MVC as well.

Also see the example "Redirecting text from stdout to a wx.TextCtrl"
LongRunningTasks - wxPyWiki

Hi Anne,

Just in case you've missed them, take a look at these pages:

http://wiki.wxpython.org/ModelViewController
http://wiki.wxpython.org/ModelViewPresenter

Peter

···

2009/7/8 Anne Ghisla <a.ghisla@gmail.com>:

It does, thanks for the quick response. I'll read some more
documentation about MVC as well.

--
There is NO FATE, we are the creators.
blog: http://damoc.ro/