Hi Anne,
Hi all,
after some time reading the list, it's time to write to ask advice
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: