[GRASS-SVN] r59516 - grass/trunk/gui/wxpython/modules

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Mar 29 15:57:01 PDT 2014


Author: annakrat
Date: 2014-03-29 15:57:01 -0700 (Sat, 29 Mar 2014)
New Revision: 59516

Modified:
   grass/trunk/gui/wxpython/modules/mcalc_builder.py
Log:
wxGUI/mapcalc: add copy button and show overwrite flag in command

Modified: grass/trunk/gui/wxpython/modules/mcalc_builder.py
===================================================================
--- grass/trunk/gui/wxpython/modules/mcalc_builder.py	2014-03-29 21:59:02 UTC (rev 59515)
+++ grass/trunk/gui/wxpython/modules/mcalc_builder.py	2014-03-29 22:57:01 UTC (rev 59516)
@@ -147,6 +147,8 @@
         self.btn_load = wx.Button(parent = self.panel, id = wx.ID_ANY,
                                   label = _("&Load"))
         self.btn_load.SetToolTipString(_('Load expression from file'))
+        self.btn_copy = wx.Button(parent=self.panel, id=wx.ID_COPY)
+        self.btn_copy.SetToolTipString(_("Copy the current command string to the clipboard"))
         
         self.btn = dict()        
         self.btn['pow'] = wx.Button(parent = self.panel, id = wx.ID_ANY, label = "^")
@@ -253,12 +255,14 @@
         self.btn_help.Bind(wx.EVT_BUTTON, self.OnHelp)
         self.btn_save.Bind(wx.EVT_BUTTON, self.OnSaveExpression)
         self.btn_load.Bind(wx.EVT_BUTTON, self.OnLoadExpression)
+        self.btn_copy.Bind(wx.EVT_BUTTON, self.OnCopy)
         
         self.mapselect.Bind(wx.EVT_TEXT, self.OnSelectTextEvt)
         self.function.Bind(wx.EVT_COMBOBOX, self._return_funct)
         self.function.Bind(wx.EVT_TEXT_ENTER, self.OnSelect)
         self.newmaptxt.Bind(wx.EVT_TEXT, self.OnUpdateStatusBar)
         self.text_mcalc.Bind(wx.EVT_TEXT, self.OnUpdateStatusBar)
+        self.overwrite.Bind(wx.EVT_CHECKBOX, self.OnUpdateStatusBar)
 
         self._layout()
 
@@ -335,6 +339,8 @@
                          flag = wx.ALL, border = 5)
         buttonSizer4.Add(item = self.btn_save,
                          flag = wx.ALL, border = 5)                         
+        buttonSizer4.Add(item = self.btn_copy,
+                         flag = wx.ALL, border = 5)                         
         buttonSizer4.AddSpacer(30)
         buttonSizer4.Add(item = self.btn_help,
                          flag = wx.ALL, border = 5)
@@ -442,14 +448,23 @@
 
     def OnUpdateStatusBar(self, event):
         """!Update statusbar text"""
+        command = self._getCommand()
+        self.SetStatusText(command)
+        event.Skip()
+
+    def _getCommand(self):
+        """!Returns entire command as string."""
         expr = self.text_mcalc.GetValue().strip().replace("\n", " ")
         cmd = 'r.mapcalc'
         if self.rast3d:
             cmd = 'r3.mapcalc'
-        self.SetStatusText("{cmd} '{new} = {expr}'".format(cmd=cmd, expr=expr,
-                                                           new=self.newmaptxt.GetValue()))
-        event.Skip()
-        
+        overwrite = ''
+        if self.overwrite.IsChecked():
+            overwrite = ' --overwrite'
+        return '{cmd} "{new} = {expr}"{overwrite}'.format(cmd=cmd, expr=expr,
+                                                          new=self.newmaptxt.GetValue(),
+                                                          overwrite=overwrite)
+
     def _addSomething(self, what):
         """!Inserts operators, map names, and functions into text area
         """
@@ -583,7 +598,16 @@
             self.text_mcalc.SetInsertionPointEnd()
         
         dlg.Destroy()
-                
+
+    def OnCopy(self, event):
+        command = self._getCommand()
+        cmddata = wx.TextDataObject()
+        cmddata.SetText(command)
+        if wx.TheClipboard.Open():
+            wx.TheClipboard.SetData(cmddata)
+            wx.TheClipboard.Close()
+            self.SetStatusText(_("'{cmd}' copied to clipboard").format(cmd=command))
+
     def OnClear(self, event):
         """!Clears text area
         """



More information about the grass-commit mailing list