[GRASS-SVN] r30323 - in grass/trunk/gui/wxpython: . gui_modules

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Feb 24 07:33:47 EST 2008


Author: martinl
Date: 2008-02-24 07:33:47 -0500 (Sun, 24 Feb 2008)
New Revision: 30323

Modified:
   grass/trunk/gui/wxpython/gui_modules/rules.py
   grass/trunk/gui/wxpython/wxgui.py
Log:
wxGUI: fixing #59 (r.colors in wxpython gui fails)

Modified: grass/trunk/gui/wxpython/gui_modules/rules.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/rules.py	2008-02-24 12:32:57 UTC (rev 30322)
+++ grass/trunk/gui/wxpython/gui_modules/rules.py	2008-02-24 12:33:47 UTC (rev 30323)
@@ -17,14 +17,16 @@
 
 """
 
-import wx
 import os
 import sys
 
+import wx
+
+import gcmd
 import gselect
 
 class RulesText(wx.Dialog):
-    def __init__(self, parent, id=wx.ID_ANY, title="Enter rules",
+    def __init__(self, parent, id=wx.ID_ANY, title=_("Enter rules"),
                  pos=wx.DefaultPosition, size=wx.DefaultSize,
                  style=wx.DEFAULT_DIALOG_STYLE,
                  cmd=None):
@@ -33,6 +35,8 @@
         """
         Dialog for interactively entering rules
         for map management commands
+
+        @param cmd command (given as list)
         """
         self.parent = parent
         self.cmd = cmd # map management command
@@ -41,97 +45,89 @@
         self.rules = '' # rules for changing
         self.overwrite = False
 
-        if self.cmd == 'r.colors':
-            label1 = 'Create new color table using color rules'
-            label2 = 'Raster map:'
+        if self.cmd[0] == 'r.colors':
+            label1 = _('Create new color table using color rules')
+            label2 = _('Raster map:')
             label3 = None
-            label4 = 'Enter color rules'
+            label4 = _('Enter color rules')
             seltype = 'cell'
-        elif self.cmd == 'r.reclass':
-            label1 = 'Reclassify raster map using rules'
-            label2 = 'Map to reclassify:'
-            label3 = 'Reclassified map:'
-            label4 = 'Enter reclassification rules'
+        elif self.cmd[0] == 'r.reclass':
+            label1 = _('Reclassify raster map using rules')
+            label2 = _('Map to reclassify:')
+            label3 = _('Reclassified map:')
+            label4 = _('Enter reclassification rules')
             seltype = 'cell'
-        elif self.cmd == 'r.recode':
-            label1 = 'Recode raster map using rules'
-            label2 = 'Map to recode:'
-            label3 = 'Recoded map:'
-            label4 = 'Enter recoding rules'
+        elif self.cmd[0] == 'r.recode':
+            label1 = _('Recode raster map using rules')
+            label2 = _('Map to recode:')
+            label3 = _('Recoded map:')
+            label4 = _('Enter recoding rules')
             seltype = 'cell'
-        elif self.cmd == 'v.reclass':
-            label1 = 'Reclassify vector map using SQL rules'
-            label2 = 'Map to reclassify:'
-            label3 = 'Reclassified map:'
-            label4 = 'Enter reclassification rules'
+        elif self.cmd[0] == 'v.reclass':
+            label1 = _('Reclassify vector map using SQL rules')
+            label2 = _('Map to reclassify:')
+            label3 = _('Reclassified map:')
+            label4 = _('Enter reclassification rules')
             seltype = 'vector'
 
+        # set window frame title
+        self.SetTitle(label1)
+
         sizer = wx.BoxSizer(wx.VERTICAL)
+        boxSizer =  wx.GridBagSizer(hgap=5, vgap=5)
+        boxSizer.AddGrowableCol(0)
 
-        box = wx.BoxSizer(wx.HORIZONTAL)
-        label = wx.StaticText(self, wx.ID_ANY, label1)
-        box.Add(label, 0, wx.ALIGN_CENTRE|wx.ALL, 5)
-        sizer.Add(item=box, proportion=0,
-                  flag=wx.ALIGN_CENTER|
-                  wx.ALL,border=5)
+        row = 0
+        boxSizer.Add(item=wx.StaticText(parent=self, id=wx.ID_ANY, label=label2),
+                     flag=wx.ALIGN_CENTER_VERTICAL,
+                     pos=(row,0))
 
-        box = wx.BoxSizer(wx.HORIZONTAL)
-        label = wx.StaticText(self, wx.ID_ANY, label2)
-        box.Add(label, 0, wx.ALIGN_RIGHT|wx.ALL, 5)
-        self.selection = gselect.Select(self, id=wx.ID_ANY, size=(300,-1),
-                                        type=seltype)
-        box.Add(self.selection, 0, wx.ALIGN_RIGHT|wx.ALL, 5)
-        sizer.Add(item=box, proportion=0,
-                  flag=wx.ALIGN_CENTER_VERTICAL|
-                  wx.ALIGN_RIGHT|
-                  wx.ALL,border=5)
+        self.selectionInput = gselect.Select(parent=self, id=wx.ID_ANY, size=(300,-1),
+                                             type=seltype)
+        boxSizer.Add(item=self.selectionInput,
+                     pos=(row,1))
+        row += 1
 
-        if cmd != 'r.colors':
-            box = wx.BoxSizer(wx.HORIZONTAL)
-            label = wx.StaticText(self, wx.ID_ANY, label3)
-            box.Add(label, 0, wx.ALIGN_RIGHT|wx.ALL, 5)
-            self.textentry = wx.TextCtrl(self, wx.ID_ANY, "", size=(300,-1))
-            box.Add(self.textentry, 0, wx.ALIGN_RIGHT|wx.ALL, 5)
-            self.textentry.Bind(wx.EVT_TEXT, self.OnText)
-            sizer.Add(item=box, proportion=0,
-                      flag=wx.ALIGN_CENTER_VERTICAL|
-                      wx.ALIGN_RIGHT|
-                      wx.ALL,border=5)
+        if self.cmd[0] != 'r.colors':
+            boxSizer.Add(item=wx.StaticText(parent=self, id=wx.ID_ANY, label=label3),
+                         flag=wx.ALIGN_CENTER_VERTICAL,
+                         pos=(row, 0))
+            self.selectionOutput = gselect.Select(parent=self, id=wx.ID_ANY, size=(300,-1),
+                                                  type=seltype)
+            self.selectionOutput.Bind(wx.EVT_TEXT, self.OnSelectionOutput)
+            boxSizer.Add(item=self.selectionOutput,
+                         pos=(row,1))
+            row += 1
 
-            box = wx.BoxSizer(wx.HORIZONTAL)
-            self.ovrwrtcheck = wx.CheckBox(self, wx.ID_ANY, 'overwrite existing file')
+            self.ovrwrtcheck = wx.CheckBox(parent=self, id=wx.ID_ANY, label=_('overwrite existing file'))
             self.ovrwrtcheck.SetValue(self.overwrite)
-            box.Add(self.ovrwrtcheck, 0, wx.ALIGN_CENTRE|wx.ALL, 5)
-            sizer.Add(item=box, proportion=0,
-                      flag=wx.ALIGN_CENTER_VERTICAL|
-                      wx.ALIGN_RIGHT|
-                      wx.ALL,border=5)
+            boxSizer.Add(item=self.ovrwrtcheck,
+                         pos=(row, 1))
             self.Bind(wx.EVT_CHECKBOX, self.OnOverwrite,   self.ovrwrtcheck)
+            row += 1
 
-        box = wx.BoxSizer(wx.HORIZONTAL)
-        label = wx.StaticText(self, wx.ID_ANY, label4)
-        box.Add(label, 0, wx.ALIGN_CENTRE|wx.ALL, 5)
-        helpbtn = wx.Button(self, wx.ID_ANY, "Help")
-        box.Add(helpbtn, 0, wx.ALIGN_CENTRE|wx.ALL, 5)
-        sizer.Add(item=box, proportion=0,
-                  flag=wx.ALIGN_CENTER|
-                  wx.ALL,border=5)
+        boxSizer.Add(item=wx.StaticText(parent=self, id=wx.ID_ANY, label=label4),
+                     flag=wx.ALIGN_CENTER_VERTICAL,
+                     pos=(row, 0))
+        helpbtn = wx.Button(parent=self, id=wx.ID_HELP)
+        boxSizer.Add(item=helpbtn, flag=wx.ALIGN_RIGHT, pos=(row, 1))
+        row += 1 
 
-        box = wx.BoxSizer(wx.HORIZONTAL)
-        self.rulestxt = wx.TextCtrl(self, id=wx.ID_ANY, value='',
+        self.rulestxt = wx.TextCtrl(parent=self, id=wx.ID_ANY, value='',
                                     pos=wx.DefaultPosition, size=(400,150),
-                                    style=wx.TE_MULTILINE|
-                                    wx.HSCROLL|
+                                    style=wx.TE_MULTILINE |
+                                    wx.HSCROLL |
                                     wx.TE_NOHIDESEL)
         self.rulestxt.SetFont(wx.Font(10, wx.FONTFAMILY_MODERN, wx.NORMAL, wx.NORMAL, 0, ''))
-        box.Add(self.rulestxt, 0, wx.ALIGN_CENTRE|wx.ALL, 5)
-        sizer.Add(item=box, proportion=0,
-                  flag=wx.ALIGN_CENTER|
-                  wx.ALL,border=5)
+        boxSizer.Add(item=self.rulestxt, pos=(row, 0), flag=wx.EXPAND, span=(1, 2))
 
-        line = wx.StaticLine(self, -1, size=(20,-1), style=wx.LI_HORIZONTAL)
-        sizer.Add(line, 0, wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.RIGHT|wx.TOP, 5)
+        sizer.Add(item=boxSizer, proportion=1,
+                  flag=wx.ALL ,border=10)
 
+        line = wx.StaticLine(parent=self, id=wx.ID_ANY, size=(20,-1), style=wx.LI_HORIZONTAL)
+        sizer.Add(item=line, proportion=0,
+                  flag=wx.GROW | wx.ALIGN_CENTER_VERTICAL | wx.ALL, border=5)
+
         btnsizer = wx.StdDialogButtonSizer()
 
         btn = wx.Button(self, wx.ID_OK)
@@ -142,28 +138,32 @@
         btnsizer.AddButton(btn)
         btnsizer.Realize()
 
-        sizer.Add(btnsizer, 0, wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5)
+        sizer.Add(item=btnsizer, proportion=0,
+                  flag=wx.EXPAND | wx.ALL | wx.ALIGN_CENTER, border=5)
 
         self.SetSizer(sizer)
         sizer.Fit(self)
 
+        # bindings
         self.Bind(wx.EVT_BUTTON, self.OnHelp, helpbtn)
-        self.selection.Bind(wx.EVT_TEXT, self.OnSelection)
+        self.selectionInput.Bind(wx.EVT_TEXT, self.OnSelectionInput)
         self.Bind(wx.EVT_TEXT, self.OnRules,   self.rulestxt)
 
-    def OnSelection(self, event):
+    def OnSelectionInput(self, event):
         self.inmap = event.GetString()
 
-    def OnText(self, event):
+    def OnSelectionOutput(self, event):
         self.outmap = event.GetString()
 
     def OnRules(self, event):
         self.rules = event.GetString().strip()
-        if self.cmd == 'r.recode':
-            self.rules = self.rules+'\n'
+        if self.cmd[0] == 'r.recode':
+            self.rules = self.rules + '%s' % os.linesep
 
     def OnHelp(self, event):
-        os.popen('g.manual --quiet %s ' % self.cmd)
+        gcmd.Command(['g.manual',
+                      '--quiet', 
+                      '%s' % self.cmd[0]])
 
     def OnOverwrite(self, event):
         self.overwrite = event.IsChecked()

Modified: grass/trunk/gui/wxpython/wxgui.py
===================================================================
--- grass/trunk/gui/wxpython/wxgui.py	2008-02-24 12:32:57 UTC (rev 30322)
+++ grass/trunk/gui/wxpython/wxgui.py	2008-02-24 12:33:47 UTC (rev 30323)
@@ -789,26 +789,32 @@
         input and processes rules
         """
         command = self.GetMenuCmd(event)
+
         dlg = rules.RulesText(self, cmd=command)
         if dlg.ShowModal() == wx.ID_OK:
             gtemp = utils.GetTempfile()
-            output = open(gtemp,"w")
+            output = open(gtemp, "w")
             try:
                 output.write(dlg.rules)
             finally:
                 output.close()
 
-            if command == 'r.colors':
-                cmdlist = [command,'map=%s' % dlg.inmap,'rules=%s' % gtemp,'--verbose']
+            if command[0] == 'r.colors':
+                cmdlist = [command[0],
+                           'map=%s' % dlg.inmap,
+                           'rules=%s' % gtemp]
             else:
-                cmdlist = [command,'input=%s' % dlg.inmap,'output=%s' % dlg.outmap,'rules=%s' % gtemp]
+                cmdlist = [command[0],
+                           'input=%s' % dlg.inmap,
+                           'output=%s' % dlg.outmap,
+                           'rules=%s' % gtemp]
 
             if dlg.overwrite == True:
                 cmdlist.append('--o')
 
-            gcmd.Command(cmdlist, verbose=3)
+            dlg.Destroy()
 
-        dlg.Destroy()
+            self.goutput.RunCmd(cmdlist)
 
     def OnXTerm(self, event):
         """



More information about the grass-commit mailing list