[GRASS-SVN] r55383 - in grass/trunk/gui/wxpython: gui_core lmgr web_services

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Mar 14 12:45:32 PDT 2013


Author: annakrat
Date: 2013-03-14 12:45:32 -0700 (Thu, 14 Mar 2013)
New Revision: 55383

Modified:
   grass/trunk/gui/wxpython/gui_core/gselect.py
   grass/trunk/gui/wxpython/gui_core/preferences.py
   grass/trunk/gui/wxpython/gui_core/widgets.py
   grass/trunk/gui/wxpython/lmgr/frame.py
   grass/trunk/gui/wxpython/web_services/dialogs.py
Log:
wxGUI: continue replacing events

Modified: grass/trunk/gui/wxpython/gui_core/gselect.py
===================================================================
--- grass/trunk/gui/wxpython/gui_core/gselect.py	2013-03-14 19:40:54 UTC (rev 55382)
+++ grass/trunk/gui/wxpython/gui_core/gselect.py	2013-03-14 19:45:32 UTC (rev 55383)
@@ -54,7 +54,7 @@
 import grass.temporal as tgis
 from   grass.script import task as gtask
 
-from gui_core.widgets  import ManageSettingsWidget, EVT_SETTINGS_CHANGED, EVT_SETTINGS_SAVING
+from gui_core.widgets  import ManageSettingsWidget
 
 from core.gcmd     import RunCommand, GError, GMessage
 from core.utils    import GetListOfLocations, GetListOfMapsets, GetFormats
@@ -1174,8 +1174,8 @@
         self.settsManager = ManageSettingsWidget(parent = self, 
                                                  id = wx.ID_ANY,
                                                  settingsFile = settingsFile)
-        self.settsManager.Bind(EVT_SETTINGS_CHANGED, self.OnSettingsChanged)
-        self.settsManager.Bind(EVT_SETTINGS_SAVING, self.OnSettingsSaving)
+        self.settsManager.settingsChanged.connect(self.OnSettingsChanged)
+        self.settsManager.settingsSaving.connect(self.OnSettingsSaving)
 
         self.inputBox = wx.StaticBox(parent = self, id = wx.ID_ANY)
         if dest:
@@ -1408,10 +1408,8 @@
         self.SetSizer(mainSizer)
         mainSizer.Fit(self)
 
-    def OnSettingsChanged(self, event):
+    def OnSettingsChanged(self, data):
         """!User changed setting"""
-        data = event.data
-
         # data list: [type, dsn, format, options]
         if len(data) == 3:
             data.append('')
@@ -1423,7 +1421,7 @@
         self.OnSetDsn(event = None, path = data[1])
         self.creationOpt.SetValue(data[3])
 
-    def OnSettingsSaving(self, event):
+    def OnSettingsSaving(self, name):
         """!Saving data"""
         if not self.GetDsn():
             GMessage(parent = self,
@@ -1433,7 +1431,7 @@
         self.settsManager.SetDataToSave((self.dsnType, self.GetDsn(),
                                          self.format.GetStringSelection(),
                                          self.creationOpt.GetValue()))
-        event.Skip()
+        self.settsManager.SaveSettings(name)
 
     def _getExtPatternGlob(self, ext):
         """!Get pattern for case-insensitive globing"""

Modified: grass/trunk/gui/wxpython/gui_core/preferences.py
===================================================================
--- grass/trunk/gui/wxpython/gui_core/preferences.py	2013-03-14 19:40:54 UTC (rev 55382)
+++ grass/trunk/gui/wxpython/gui_core/preferences.py	2013-03-14 19:45:32 UTC (rev 55383)
@@ -40,7 +40,7 @@
 import wx.lib.mixins.listctrl as listmix
 import wx.lib.scrolledpanel as SP
 
-from wx.lib.newevent import NewEvent
+from grass.pydispatch.signal import Signal
 
 from grass.script import core as grass
 
@@ -50,8 +50,6 @@
 from core.settings import UserSettings
 from gui_core.dialogs import SymbolDialog
 
-wxSettingsChanged, EVT_SETTINGS_CHANGED = NewEvent()
-
 class PreferencesBaseDialog(wx.Dialog):
     """!Base preferences dialog"""
     def __init__(self, parent, giface, settings, title = _("User settings"),
@@ -66,6 +64,8 @@
         wx.Dialog.__init__(self, parent = parent, id = wx.ID_ANY, title = title,
                            style = style)
         
+        self.settingsChanged = Signal('PreferencesBaseDialog.settingsChanged')
+        
         # notebook
         self.notebook = wx.Notebook(parent = self, id = wx.ID_ANY, style = wx.BK_DEFAULT)
         
@@ -145,12 +145,11 @@
         
     def OnApply(self, event):
         """!Button 'Apply' pressed
-        Posts event EVT_SETTINGS_CHANGED.
+        Emits signal settingsChanged.
         """
         if self._updateSettings():
             self._giface.WriteLog(_('Settings applied to current session but not saved'))
-            event = wxSettingsChanged()
-            wx.PostEvent(self, event)
+            self.settingsChanged.emit()
             self.Close()
 
     def OnCloseWindow(self, event):
@@ -162,7 +161,7 @@
     
     def OnSave(self, event):
         """!Button 'Save' pressed
-        Posts event EVT_SETTINGS_CHANGED.
+        Emits signal settingsChanged.
         """
         if self._updateSettings():
             lang = self.settings.Get(group = 'language', key = 'locale', subkey = 'lc_all')
@@ -180,8 +179,7 @@
                 StoreEnvVariable(key = 'LANG', value = lang)
             else:
                 StoreEnvVariable(key = 'LANG')
-            event = wxSettingsChanged()
-            wx.PostEvent(self, event)
+            self.settingsChanged.emit()
             self.Close()
 
     def _updateSettings(self):

Modified: grass/trunk/gui/wxpython/gui_core/widgets.py
===================================================================
--- grass/trunk/gui/wxpython/gui_core/widgets.py	2013-03-14 19:40:54 UTC (rev 55382)
+++ grass/trunk/gui/wxpython/gui_core/widgets.py	2013-03-14 19:45:32 UTC (rev 55383)
@@ -52,16 +52,12 @@
 from grass.pydispatch.signal import Signal
 
 from core        import globalvar
-from core.gcmd   import GMessage
+from core.gcmd   import GMessage, GError
 from core.debug  import Debug
 
 from wx.lib.newevent import NewEvent
 wxSymbolSelectionChanged, EVT_SYMBOL_SELECTION_CHANGED  = NewEvent()
 
-# ManageSettingsWidget
-wxOnSettingsLoaded, EVT_SETTINGS_LOADED = NewEvent()
-wxOnSettingsChanged, EVT_SETTINGS_CHANGED = NewEvent()
-wxOnSettingsSaving, EVT_SETTINGS_SAVING = NewEvent()
 
 class NotebookController:
     """!Provides handling of notebook page names.
@@ -979,22 +975,23 @@
     """!Widget which allows loading and saving settings into file."""
     def __init__(self, parent, settingsFile, id = wx.ID_ANY):
         """
-        Events:
-            EVT_SETTINGS_CHANGED - called when users changes setting
-                                - event object has attribute 'data', with chosen setting data
-            EVT_SETTINGS_SAVING - called when settings are saving
-                                - If you bind instance of ManageSettingsWidget with this event,
-                                  you can use SetDataToSave method to set data for save and then call 
-                                  Skip() to save the data.
-                                  If you do not call Skip(), the data will not be saved. 
-            EVT_SETTINGS_LOADED - called when settings are loaded
-                                - event object has attribute 'settings', which is dict with loaded settings
-                                  {nameofsetting : settingdata, ....}
+        Signals:
+            settingsChanged - called when users changes setting
+                            - attribute 'data' with chosen setting data
+            settingsSaving - called when settings are saving
+                           - attribute 'name' with chosen settings name
+            settingsLoaded - called when settings are loaded
+                           - attribute 'settings' is dict with loaded settings
+                             {nameofsetting : settingdata, ....}
 
         @param settingsFile - path to file, where settings will be saved and loaded from
         """
         self.settingsFile = settingsFile
 
+        self.settingsChanged = Signal('ManageSettingsWidget.settingsChanged')
+        self.settingsSaving = Signal('ManageSettingsWidget.settingsSaving')
+        self.settingsLoaded = Signal('ManageSettingsWidget.settingsLoaded')
+
         wx.Panel.__init__(self, parent = parent, id = wx.ID_ANY)
 
         self.settingsBox = wx.StaticBox(parent = self, id = wx.ID_ANY,
@@ -1009,15 +1006,12 @@
         self.btnSettingsDel.Bind(wx.EVT_BUTTON, self.OnSettingsDelete)
         self.btnSettingsSave.SetToolTipString(_("Delete currently selected settings"))
 
-        self.Bind(EVT_SETTINGS_SAVING, self.OnSettingsSaving)
-
         # escaping with '$' character - index in self.esc_chars
         self.e_char_i = 0
         self.esc_chars = ['$', ';']
 
         self._settings = self._loadSettings() # -> self.settingsChoice.SetItems()
-        event = wxOnSettingsLoaded(settings = self._settings)
-        wx.PostEvent(self, event)
+        self.settingsLoaded.emit(settings=self._settings)
 
         self.data_to_save = []
 
@@ -1053,50 +1047,44 @@
             return
 
         data = self._settings[name]
-        event = wxOnSettingsChanged(data = data)
-        wx.PostEvent(self, event)
+        self.settingsChanged.emit(data=data)
 
     def OnSettingsSave(self, event):
         """!Save settings"""
         dlg = wx.TextEntryDialog(parent = self,
                                  message = _("Name:"),
                                  caption = _("Save settings"))
-        if dlg.ShowModal() != wx.ID_OK:
-            return
-        
-        # check required params
-        if not dlg.GetValue():
-            GMessage(parent = self,
-                     message = _("Name not given, settings is not saved."))
-            return
-
-        name = dlg.GetValue()
-
-        event = wxOnSettingsSaving(name = name, dlg = dlg)
-        wx.PostEvent(self, event)
+        if dlg.ShowModal() == wx.ID_OK:
+            name = dlg.GetValue()
+            if not name:
+                GMessage(parent = self,
+                         message = _("Name not given, settings is not saved."))
+            else:
+                self.settingsSaving.emit(name=name)
+                
+            dlg.Destroy()
   
-    def OnSettingsSaving(self, event):
+    def SaveSettings(self, name):
         # check if settings item already exists
-        if event.name in self._settings:
+        if name in self._settings:
             dlgOwt = wx.MessageDialog(self, message = _("Settings <%s> already exists. "
-                                                        "Do you want to overwrite the settings?") % event.name,
+                                                        "Do you want to overwrite the settings?") % name,
                                       caption = _("Save settings"), style = wx.YES_NO | wx.YES_DEFAULT | wx.ICON_QUESTION)
             if dlgOwt.ShowModal() != wx.ID_YES:
                 dlgOwt.Destroy()
                 return
 
         if self.data_to_save:
-            self._settings[event.name] = self.data_to_save
+            self._settings[name] = self.data_to_save
 
-        self.SaveSettings()
-        self.settingsChoice.SetStringSelection(event.name)
+        self._saveSettings()
+        self.settingsChoice.SetStringSelection(name)
 
         self.data_to_save = []
-        event.dlg.Destroy()
  
-    def SaveSettings(self):
-        """!Save settings"""
-        if self._saveSettings() == 0:
+    def _saveSettings(self):
+        """!Save settings and reload if successful"""
+        if self._writeSettings() == 0:
             self._settings = self._loadSettings()
 
     def SetDataToSave(self, data):
@@ -1112,7 +1100,7 @@
         @param settings - dict with all settigs {nameofsetting : settingdata, ....}
         """
         self._settings = settings
-        self.SaveSettings()
+        self._saveSettings()
 
     def OnSettingsDelete(self, event):
         """!Save settings
@@ -1124,10 +1112,10 @@
             return
         
         self._settings.pop(name)
-        if self._saveSettings() == 0:
+        if self._writeSettings() == 0:
             self._settings = self._loadSettings()
         
-    def _saveSettings(self):
+    def _writeSettings(self):
         """!Save settings into the file
 
         @return 0 on success
@@ -1192,8 +1180,7 @@
         self.settingsChoice.SetItems(sorted(data.keys()))
         fd.close()
 
-        event = wxOnSettingsLoaded(settings = data)
-        wx.PostEvent(self, event)
+        self.settingsLoaded.emit(settings=data)
 
         return data
 

Modified: grass/trunk/gui/wxpython/lmgr/frame.py
===================================================================
--- grass/trunk/gui/wxpython/lmgr/frame.py	2013-03-14 19:40:54 UTC (rev 55382)
+++ grass/trunk/gui/wxpython/lmgr/frame.py	2013-03-14 19:45:32 UTC (rev 55383)
@@ -43,7 +43,7 @@
 from core.gcmd             import RunCommand, GError, GMessage, GException
 from core.settings         import UserSettings, GetDisplayVectSettings
 from core.utils            import SetAddOnPath, GetLayerNameFromCmd, command2ltype
-from gui_core.preferences  import MapsetAccess, PreferencesDialog, EVT_SETTINGS_CHANGED
+from gui_core.preferences  import MapsetAccess, PreferencesDialog
 from lmgr.layertree        import LayerTree, LMIcons
 from lmgr.menudata         import LayerManagerMenuData
 from gui_core.widgets      import GNotebook
@@ -419,8 +419,9 @@
                 else:
                     dlg.Destroy()
         
-    def OnSettingsChanged(self, event):
-        """!Here can be functions which have to be called after EVT_SETTINGS_CHANGED. 
+    def OnSettingsChanged(self):
+        """!Here can be functions which have to be called
+        after receiving settingsChanged signal. 
         Now only set copying of selected text to clipboard (in goutput).
         """
         ### self._createMenuBar() # bug when menu is re-created on the fly
@@ -1388,7 +1389,7 @@
             self.dialogs['preferences'] = dlg
             self.dialogs['preferences'].CenterOnScreen()
             
-            dlg.Bind(EVT_SETTINGS_CHANGED, self.OnSettingsChanged)
+            dlg.settingsChanged.connect(self.OnSettingsChanged)
         
         self.dialogs['preferences'].ShowModal()
         

Modified: grass/trunk/gui/wxpython/web_services/dialogs.py
===================================================================
--- grass/trunk/gui/wxpython/web_services/dialogs.py	2013-03-14 19:40:54 UTC (rev 55382)
+++ grass/trunk/gui/wxpython/web_services/dialogs.py	2013-03-14 19:45:32 UTC (rev 55383)
@@ -37,8 +37,7 @@
 from core.gconsole    import CmdThread, GStderr, EVT_CMD_DONE, EVT_CMD_OUTPUT
 
 from gui_core.gselect import Select
-from gui_core.widgets import ManageSettingsWidget,\
-                             EVT_SETTINGS_CHANGED, EVT_SETTINGS_SAVING, EVT_SETTINGS_LOADED
+from gui_core.widgets import ManageSettingsWidget
 
 from web_services.widgets import WSPanel, EVT_CAP_PARSED
 
@@ -145,9 +144,9 @@
         self.server.Bind(wx.EVT_TEXT, self.OnServer)
         self.layerName.Bind(wx.EVT_TEXT, self.OnOutputLayerName)
 
-        self.settsManager.Bind(EVT_SETTINGS_CHANGED, self.OnSettingsChanged)
-        self.settsManager.Bind(EVT_SETTINGS_SAVING, self.OnSettingsSaving)
-        self.settsManager.Bind(EVT_SETTINGS_LOADED, self.OnSettingsLoaded)
+        self.settsManager.settingsChanged.connect(self.OnSettingsChanged)
+        self.settsManager.settingsLoaded.connect(self.OnSettingsLoaded)
+        self.settsManager.settingsSaving.connect(self.OnSettingsSaving)
 
         self.Bind(EVT_CAP_PARSED, self.OnPanelCapParsed)
 
@@ -273,7 +272,7 @@
         pane.SetSizer(adv_conn_sizer)
         adv_conn_sizer.Fit(pane)
 
-    def OnSettingsSaving(self, event):
+    def OnSettingsSaving(self, name):
         """!Check if required data are filled before setting save is performed.
         """
         server = self.server.GetValue().strip()
@@ -285,12 +284,10 @@
         self.settsManager.SetDataToSave((server,
                                          self.username.GetValue(),
                                          self.password.GetValue()))
-        event.Skip()
+        self.settsManager.SaveSettings(name)
 
-    def OnSettingsChanged(self, event):
+    def OnSettingsChanged(self, data):
         """!Update widgets according to chosen settings"""
-        data = event.data
-
         # data list: [server, username, password]
         if len < 3:
             return
@@ -305,10 +302,10 @@
         else:
             self.adv_conn.Collapse(True)
 
-    def OnSettingsLoaded(self, event):
+    def OnSettingsLoaded(self, settings):
         """!If settings are empty set default servers
         """
-        if not event.settings:
+        if not settings:
             self.settsManager.SetSettings(self.default_servers)
 
     def OnClose(self, event):



More information about the grass-commit mailing list