[GRASS-SVN] r53359 - in grass/trunk/gui/wxpython: gui_core modules

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Oct 11 04:08:52 PDT 2012


Author: martinl
Date: 2012-10-11 04:08:51 -0700 (Thu, 11 Oct 2012)
New Revision: 53359

Modified:
   grass/trunk/gui/wxpython/gui_core/dialogs.py
   grass/trunk/gui/wxpython/gui_core/menu.py
   grass/trunk/gui/wxpython/gui_core/widgets.py
   grass/trunk/gui/wxpython/modules/extensions.py
Log:
wxGUI: define generic ListCtrl (GListCtrl)


Modified: grass/trunk/gui/wxpython/gui_core/dialogs.py
===================================================================
--- grass/trunk/gui/wxpython/gui_core/dialogs.py	2012-10-11 10:56:12 UTC (rev 53358)
+++ grass/trunk/gui/wxpython/gui_core/dialogs.py	2012-10-11 11:08:51 UTC (rev 53359)
@@ -49,7 +49,7 @@
 from core.gcmd        import GError, RunCommand, GMessage
 from gui_core.gselect import ElementSelect, LocationSelect, MapsetSelect, Select, OgrTypeSelect, GdalSelect, MapsetSelect
 from gui_core.forms   import GUI
-from gui_core.widgets import SingleSymbolPanel, EVT_SYMBOL_SELECTION_CHANGED
+from gui_core.widgets import SingleSymbolPanel, EVT_SYMBOL_SELECTION_CHANGED, GListCtrl
 from core.utils       import GetListOfMapsets, GetLayerNameFromCmd, GetValidLayerName
 from core.settings    import UserSettings, GetDisplayVectSettings
 from core.debug       import Debug
@@ -2098,19 +2098,14 @@
         """!Show command dialog"""
         GUI(parent = self, modal = True).ParseCommand(cmd = ['v.in.dxf'])
                 
-class LayersList(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin,
-                 listmix.CheckListCtrlMixin, listmix.TextEditMixin):
+class LayersList(GListCtrl, listmix.TextEditMixin):
     """!List of layers to be imported (dxf, shp...)"""
     def __init__(self, parent, columns, log = None):
-        self.parent = parent
+        GListCtrl.__init__(self, parent)
         
-        wx.ListCtrl.__init__(self, parent, wx.ID_ANY,
-                             style = wx.LC_REPORT)
-        listmix.CheckListCtrlMixin.__init__(self)
         self.log = log
         
         # setup mixins
-        listmix.ListCtrlAutoWidthMixin.__init__(self)
         listmix.TextEditMixin.__init__(self)
         
         for i in range(len(columns)):
@@ -2124,9 +2119,6 @@
         for i in range(len(width)):
             self.SetColumnWidth(col = i, width = width[i])
         
-        self.Bind(wx.EVT_COMMAND_RIGHT_CLICK, self.OnPopupMenu) #wxMSW
-        self.Bind(wx.EVT_RIGHT_UP,            self.OnPopupMenu) #wxGTK
-
     def LoadData(self, data = None):
         """!Load data into list"""
         self.DeleteAllItems()
@@ -2142,50 +2134,6 @@
         if len(data) == 1:
             self.CheckItem(index, True)
         
-    def OnPopupMenu(self, event):
-        """!Show popup menu"""
-        if self.GetItemCount() < 1:
-            return
-        
-        if not hasattr(self, "popupDataID1"):
-            self.popupDataID1 = wx.NewId()
-            self.popupDataID2 = wx.NewId()
-            
-            self.Bind(wx.EVT_MENU, self.OnSelectAll,  id = self.popupDataID1)
-            self.Bind(wx.EVT_MENU, self.OnSelectNone, id = self.popupDataID2)
-        
-        # generate popup-menu
-        menu = wx.Menu()
-        menu.Append(self.popupDataID1, _("Select all"))
-        menu.Append(self.popupDataID2, _("Deselect all"))
-        
-        self.PopupMenu(menu)
-        menu.Destroy()
-
-    def OnSelectAll(self, event):
-        """!Select all items"""
-        item = -1
-        
-        while True:
-            item = self.GetNextItem(item)
-            if item == -1:
-                break
-            self.CheckItem(item, True)
-        
-        event.Skip()
-        
-    def OnSelectNone(self, event):
-        """!Deselect items"""
-        item = -1
-        
-        while True:
-            item = self.GetNextItem(item, wx.LIST_STATE_SELECTED)
-            if item == -1:
-                break
-            self.CheckItem(item, False)
-        
-        event.Skip()
-        
     def OnLeftDown(self, event):
         """!Allow editing only output name
         

Modified: grass/trunk/gui/wxpython/gui_core/menu.py
===================================================================
--- grass/trunk/gui/wxpython/gui_core/menu.py	2012-10-11 10:56:12 UTC (rev 53358)
+++ grass/trunk/gui/wxpython/gui_core/menu.py	2012-10-11 11:08:51 UTC (rev 53359)
@@ -66,7 +66,7 @@
             menu.AppendSeparator()
             return
         
-        if len(gcmd) > 0 and handler in ('OnMenuCmd', 'RunMenuCmd'):
+        if gcmd:
             helpString = gcmd + ' -- ' + help
             if menustyle == 1:
                 label += '   [' + gcmd + ']'

Modified: grass/trunk/gui/wxpython/gui_core/widgets.py
===================================================================
--- grass/trunk/gui/wxpython/gui_core/widgets.py	2012-10-11 10:56:12 UTC (rev 53358)
+++ grass/trunk/gui/wxpython/gui_core/widgets.py	2012-10-11 11:08:51 UTC (rev 53359)
@@ -14,8 +14,9 @@
  - widgets::IntegerValidator
  - widgets::FloatValidator
  - widgets::ItemTree
+ - widgets::GListCtrl
 
-(C) 2008-2011 by the GRASS Development Team
+(C) 2008-2012 by the GRASS Development Team
 
 This program is free software under the GNU General Public License
 (>=v2). Read the file COPYING that comes with GRASS for details.
@@ -30,6 +31,7 @@
 import string
 
 import wx
+import wx.lib.mixins.listctrl as listmix
 import wx.lib.scrolledpanel as SP
 try:
     import wx.lib.agw.flatnotebook   as FN
@@ -641,3 +643,66 @@
         self.selected = True
         self.SetBackgroundColour(self.selectColor)
         
+class GListCtrl(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin, listmix.CheckListCtrlMixin):
+    """!Generic ListCtrl with popup menu to select/deselect all
+    items"""
+    def __init__(self, parent):
+        self.parent = parent
+        
+        wx.ListCtrl.__init__(self, parent, id = wx.ID_ANY,
+                             style = wx.LC_REPORT)
+        listmix.CheckListCtrlMixin.__init__(self)
+        
+        # setup mixins
+        listmix.ListCtrlAutoWidthMixin.__init__(self)
+        
+        self.Bind(wx.EVT_COMMAND_RIGHT_CLICK, self.OnPopupMenu) #wxMSW
+        self.Bind(wx.EVT_RIGHT_UP,            self.OnPopupMenu) #wxGTK
+
+    def LoadData(self):
+        """!Load data into list"""
+        pass
+
+    def OnPopupMenu(self, event):
+        """!Show popup menu"""
+        if self.GetItemCount() < 1:
+            return
+        
+        if not hasattr(self, "popupDataID1"):
+            self.popupDataID1 = wx.NewId()
+            self.popupDataID2 = wx.NewId()
+            
+            self.Bind(wx.EVT_MENU, self.OnSelectAll,  id = self.popupDataID1)
+            self.Bind(wx.EVT_MENU, self.OnSelectNone, id = self.popupDataID2)
+        
+        # generate popup-menu
+        menu = wx.Menu()
+        menu.Append(self.popupDataID1, _("Select all"))
+        menu.Append(self.popupDataID2, _("Deselect all"))
+        
+        self.PopupMenu(menu)
+        menu.Destroy()
+
+    def OnSelectAll(self, event):
+        """!Select all items"""
+        item = -1
+        
+        while True:
+            item = self.GetNextItem(item)
+            if item == -1:
+                break
+            self.CheckItem(item, True)
+        
+        event.Skip()
+        
+    def OnSelectNone(self, event):
+        """!Deselect items"""
+        item = -1
+        
+        while True:
+            item = self.GetNextItem(item, wx.LIST_STATE_SELECTED)
+            if item == -1:
+                break
+            self.CheckItem(item, False)
+        
+        event.Skip()

Modified: grass/trunk/gui/wxpython/modules/extensions.py
===================================================================
--- grass/trunk/gui/wxpython/modules/extensions.py	2012-10-11 10:56:12 UTC (rev 53358)
+++ grass/trunk/gui/wxpython/modules/extensions.py	2012-10-11 11:08:51 UTC (rev 53359)
@@ -9,7 +9,7 @@
  - extensions::UninstallExtensionWindow
  - extensions::CheckListExtension
 
-(C) 2008-2011 by the GRASS Development Team
+(C) 2008-2012 by the GRASS Development Team
 
 This program is free software under the GNU General Public License
 (>=v2). Read the file COPYING that comes with GRASS for details.
@@ -21,7 +21,6 @@
 import sys
 
 import wx
-import wx.lib.mixins.listctrl as listmix
 try:
     import wx.lib.agw.customtreectrl as CT
 except ImportError:
@@ -34,7 +33,7 @@
 from core             import globalvar
 from core.gcmd        import GError, RunCommand
 from gui_core.forms   import GUI
-from gui_core.widgets import ItemTree
+from gui_core.widgets import ItemTree, GListCtrl
 from gui_core.ghelp   import SearchModuleWindow
 
 class InstallExtensionWindow(wx.Frame):
@@ -473,18 +472,12 @@
         """!Shows command dialog"""
         GUI(parent = self).ParseCommand(cmd = ['g.extension'])
 
-class CheckListExtension(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin, listmix.CheckListCtrlMixin):
+class CheckListExtension(GListCtrl):
     """!List of mapset/owner/group"""
     def __init__(self, parent):
-        self.parent = parent
+        GListCtrl.__init__(self, parent)
         
-        wx.ListCtrl.__init__(self, parent, id = wx.ID_ANY,
-                             style = wx.LC_REPORT)
-        listmix.CheckListCtrlMixin.__init__(self)
-        
-        # setup mixins
-        listmix.ListCtrlAutoWidthMixin.__init__(self)
-
+        # load extensions
         self.InsertColumn(0, _('Extension'))
         self.LoadData()
         



More information about the grass-commit mailing list