|
@@ -15,6 +15,7 @@ Classes:
|
|
|
- ProcessModelFile
|
|
|
- WriteModelFile
|
|
|
- PreferencesDialog
|
|
|
+ - PropertiesDialog
|
|
|
|
|
|
(C) 2010 by the GRASS Development Team
|
|
|
This program is free software under the GNU General Public License
|
|
@@ -256,6 +257,7 @@ class ModelFrame(wx.Frame):
|
|
|
self.baseTitle = title
|
|
|
self.modelFile = None # loaded model
|
|
|
self.modelChanged = False
|
|
|
+ self.properties = None
|
|
|
|
|
|
self.cursors = {
|
|
|
"default" : wx.StockCursor(wx.CURSOR_ARROW),
|
|
@@ -353,6 +355,18 @@ class ModelFrame(wx.Frame):
|
|
|
|
|
|
def OnModelProperties(self, event):
|
|
|
"""!Model properties dialog"""
|
|
|
+ dlg = PropertiesDialog(parent = self)
|
|
|
+ dlg.CentreOnParent()
|
|
|
+ if self.properties:
|
|
|
+ dlg.Init(self.properties)
|
|
|
+ else:
|
|
|
+ dlg.Init({ 'name' : '',
|
|
|
+ 'desc' : '',
|
|
|
+ 'author' : getpass.getuser() })
|
|
|
+ if dlg.ShowModal() == wx.ID_OK:
|
|
|
+ self.properties = dlg.GetValues()
|
|
|
+
|
|
|
+ dlg.Destroy()
|
|
|
|
|
|
def OnDeleteData(self, event):
|
|
|
"""!Delete intermediate data"""
|
|
@@ -683,21 +697,31 @@ class ModelFrame(wx.Frame):
|
|
|
|
|
|
def _writePython(self, fd):
|
|
|
"""!Write model to file"""
|
|
|
+ if self.properties:
|
|
|
+ properties = self.properties
|
|
|
+ else:
|
|
|
+ properties = { 'name' : _("Graphical modeler script"),
|
|
|
+ 'desc' : _("Script generated by wxGUI Graphical Modeler"),
|
|
|
+ 'author' : getpass.getuser() }
|
|
|
+
|
|
|
fd.write(
|
|
|
r"""#!/usr/bin/env python
|
|
|
#
|
|
|
############################################################################
|
|
|
#
|
|
|
-# MODULE: Graphical modeler script
|
|
|
+# MODULE: %s
|
|
|
#
|
|
|
# AUTHOR(S): %s
|
|
|
#
|
|
|
-# PURPOSE: Script generated by wxGUI Graphical Modeler
|
|
|
+# PURPOSE: %s
|
|
|
#
|
|
|
# DATE: %s
|
|
|
#
|
|
|
#############################################################################
|
|
|
-""" % (getpass.getuser(), time.asctime()))
|
|
|
+""" % (properties['name'],
|
|
|
+ properties['author'],
|
|
|
+ properties['desc'],
|
|
|
+ time.asctime()))
|
|
|
|
|
|
fd.write(
|
|
|
r"""
|
|
@@ -2103,6 +2127,97 @@ class PreferencesDialog(PreferencesBaseDialog):
|
|
|
|
|
|
self.parent.GetModel().Update()
|
|
|
self.parent.GetCanvas().Refresh()
|
|
|
+
|
|
|
+class PropertiesDialog(wx.Dialog):
|
|
|
+ """!Model properties dialog
|
|
|
+ """
|
|
|
+ def __init__(self, parent, id = wx.ID_ANY,
|
|
|
+ title = _('Model properties'),
|
|
|
+ size = (350, 400),
|
|
|
+ style = wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER):
|
|
|
+ wx.Dialog.__init__(self, parent, id, title, size = size,
|
|
|
+ style = style)
|
|
|
+
|
|
|
+ self.name = wx.TextCtrl(parent = self, id = wx.ID_ANY,
|
|
|
+ size = (300, 25))
|
|
|
+ self.desc = wx.TextCtrl(parent = self, id = wx.ID_ANY,
|
|
|
+ style = wx.TE_MULTILINE,
|
|
|
+ size = (300, 50))
|
|
|
+ self.author = wx.TextCtrl(parent = self, id = wx.ID_ANY,
|
|
|
+ size = (300, 25))
|
|
|
+
|
|
|
+ # buttons
|
|
|
+ self.btnOk = wx.Button(self, wx.ID_OK)
|
|
|
+ self.btnCancel = wx.Button(self, wx.ID_CANCEL)
|
|
|
+ self.btnOk.SetDefault()
|
|
|
+
|
|
|
+ self.btnOk.SetToolTipString(_("Apply properties"))
|
|
|
+ self.btnOk.SetDefault()
|
|
|
+ self.btnCancel.SetToolTipString(_("Close dialog and ignore changes"))
|
|
|
+
|
|
|
+ self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
|
|
|
+
|
|
|
+ self._layout()
|
|
|
+
|
|
|
+ def _layout(self):
|
|
|
+ gridSizer = wx.GridBagSizer (hgap=3, vgap=3)
|
|
|
+ gridSizer.AddGrowableCol(0)
|
|
|
+ gridSizer.Add(item = wx.StaticText(parent = self, id = wx.ID_ANY,
|
|
|
+ label = _("Name:")),
|
|
|
+ flag = wx.ALIGN_LEFT |
|
|
|
+ wx.ALIGN_CENTER_VERTICAL,
|
|
|
+ pos = (0, 0))
|
|
|
+ gridSizer.Add(item = self.name,
|
|
|
+ flag = wx.ALIGN_LEFT |
|
|
|
+ wx.ALIGN_CENTER_VERTICAL,
|
|
|
+ pos = (0, 1))
|
|
|
+ gridSizer.Add(item = wx.StaticText(parent = self, id = wx.ID_ANY,
|
|
|
+ label = _("Description:")),
|
|
|
+ flag = wx.ALIGN_LEFT |
|
|
|
+ wx.ALIGN_CENTER_VERTICAL,
|
|
|
+ pos = (1, 0))
|
|
|
+ gridSizer.Add(item = self.desc,
|
|
|
+ flag = wx.ALIGN_LEFT |
|
|
|
+ wx.ALIGN_CENTER_VERTICAL,
|
|
|
+ pos = (1, 1))
|
|
|
+ gridSizer.Add(item = wx.StaticText(parent = self, id = wx.ID_ANY,
|
|
|
+ label = _("Author(s):")),
|
|
|
+ flag = wx.ALIGN_LEFT |
|
|
|
+ wx.ALIGN_CENTER_VERTICAL,
|
|
|
+ pos = (2, 0))
|
|
|
+ gridSizer.Add(item = self.author,
|
|
|
+ flag = wx.ALIGN_LEFT |
|
|
|
+ wx.ALIGN_CENTER_VERTICAL,
|
|
|
+ pos = (2, 1))
|
|
|
+
|
|
|
+ btnStdSizer = wx.StdDialogButtonSizer()
|
|
|
+ btnStdSizer.AddButton(self.btnCancel)
|
|
|
+ btnStdSizer.AddButton(self.btnOk)
|
|
|
+ btnStdSizer.Realize()
|
|
|
+
|
|
|
+ mainSizer = wx.BoxSizer(wx.VERTICAL)
|
|
|
+ mainSizer.Add(item=gridSizer, proportion=0,
|
|
|
+ flag=wx.EXPAND | wx.ALL, border=5)
|
|
|
+ mainSizer.Add(item=btnStdSizer, proportion=0,
|
|
|
+ flag=wx.EXPAND | wx.ALL | wx.ALIGN_RIGHT, border=5)
|
|
|
+
|
|
|
+ self.SetSizer(mainSizer)
|
|
|
+ mainSizer.Fit(self)
|
|
|
+
|
|
|
+ def OnCloseWindow(self, event):
|
|
|
+ self.Hide()
|
|
|
+
|
|
|
+ def GetValues(self):
|
|
|
+ """!Get values"""
|
|
|
+ return { 'name' : self.name.GetValue(),
|
|
|
+ 'desc' : self.desc.GetValue(),
|
|
|
+ 'author' : self.author.GetValue() }
|
|
|
+
|
|
|
+ def Init(self, prop):
|
|
|
+ """!Initialize dialog"""
|
|
|
+ self.name.SetValue(prop['name'])
|
|
|
+ self.desc.SetValue(prop['desc'])
|
|
|
+ self.author.SetValue(prop['author'])
|
|
|
|
|
|
def main():
|
|
|
app = wx.PySimpleApp()
|