ソースを参照

wxGUI: define generic ListCtrl (GListCtrl)

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@53359 15284696-431f-4ddb-bdfa-cd5b030d7da7
Martin Landa 12 年 前
コミット
a9f5b7600e

+ 3 - 55
gui/wxpython/gui_core/dialogs.py

@@ -49,7 +49,7 @@ from core             import globalvar
 from core.gcmd        import GError, RunCommand, GMessage
 from core.gcmd        import GError, RunCommand, GMessage
 from gui_core.gselect import ElementSelect, LocationSelect, MapsetSelect, Select, OgrTypeSelect, GdalSelect, MapsetSelect
 from gui_core.gselect import ElementSelect, LocationSelect, MapsetSelect, Select, OgrTypeSelect, GdalSelect, MapsetSelect
 from gui_core.forms   import GUI
 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.utils       import GetListOfMapsets, GetLayerNameFromCmd, GetValidLayerName
 from core.settings    import UserSettings, GetDisplayVectSettings
 from core.settings    import UserSettings, GetDisplayVectSettings
 from core.debug       import Debug
 from core.debug       import Debug
@@ -2098,19 +2098,14 @@ class DxfImportDialog(ImportDialog):
         """!Show command dialog"""
         """!Show command dialog"""
         GUI(parent = self, modal = True).ParseCommand(cmd = ['v.in.dxf'])
         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...)"""
     """!List of layers to be imported (dxf, shp...)"""
     def __init__(self, parent, columns, log = None):
     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
         self.log = log
         
         
         # setup mixins
         # setup mixins
-        listmix.ListCtrlAutoWidthMixin.__init__(self)
         listmix.TextEditMixin.__init__(self)
         listmix.TextEditMixin.__init__(self)
         
         
         for i in range(len(columns)):
         for i in range(len(columns)):
@@ -2124,9 +2119,6 @@ class LayersList(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin,
         for i in range(len(width)):
         for i in range(len(width)):
             self.SetColumnWidth(col = i, width = width[i])
             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):
     def LoadData(self, data = None):
         """!Load data into list"""
         """!Load data into list"""
         self.DeleteAllItems()
         self.DeleteAllItems()
@@ -2142,50 +2134,6 @@ class LayersList(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin,
         if len(data) == 1:
         if len(data) == 1:
             self.CheckItem(index, True)
             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):
     def OnLeftDown(self, event):
         """!Allow editing only output name
         """!Allow editing only output name
         
         

+ 1 - 1
gui/wxpython/gui_core/menu.py

@@ -66,7 +66,7 @@ class Menu(wx.MenuBar):
             menu.AppendSeparator()
             menu.AppendSeparator()
             return
             return
         
         
-        if len(gcmd) > 0 and handler in ('OnMenuCmd', 'RunMenuCmd'):
+        if gcmd:
             helpString = gcmd + ' -- ' + help
             helpString = gcmd + ' -- ' + help
             if menustyle == 1:
             if menustyle == 1:
                 label += '   [' + gcmd + ']'
                 label += '   [' + gcmd + ']'

+ 66 - 1
gui/wxpython/gui_core/widgets.py

@@ -14,8 +14,9 @@ Classes:
  - widgets::IntegerValidator
  - widgets::IntegerValidator
  - widgets::FloatValidator
  - widgets::FloatValidator
  - widgets::ItemTree
  - 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
 This program is free software under the GNU General Public License
 (>=v2). Read the file COPYING that comes with GRASS for details.
 (>=v2). Read the file COPYING that comes with GRASS for details.
@@ -30,6 +31,7 @@ import sys
 import string
 import string
 
 
 import wx
 import wx
+import wx.lib.mixins.listctrl as listmix
 import wx.lib.scrolledpanel as SP
 import wx.lib.scrolledpanel as SP
 try:
 try:
     import wx.lib.agw.flatnotebook   as FN
     import wx.lib.agw.flatnotebook   as FN
@@ -641,3 +643,66 @@ class SingleSymbolPanel(wx.Panel):
         self.selected = True
         self.selected = True
         self.SetBackgroundColour(self.selectColor)
         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()

+ 5 - 12
gui/wxpython/modules/extensions.py

@@ -9,7 +9,7 @@ Classes:
  - extensions::UninstallExtensionWindow
  - extensions::UninstallExtensionWindow
  - extensions::CheckListExtension
  - 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
 This program is free software under the GNU General Public License
 (>=v2). Read the file COPYING that comes with GRASS for details.
 (>=v2). Read the file COPYING that comes with GRASS for details.
@@ -21,7 +21,6 @@ import os
 import sys
 import sys
 
 
 import wx
 import wx
-import wx.lib.mixins.listctrl as listmix
 try:
 try:
     import wx.lib.agw.customtreectrl as CT
     import wx.lib.agw.customtreectrl as CT
 except ImportError:
 except ImportError:
@@ -34,7 +33,7 @@ from grass.script import task as gtask
 from core             import globalvar
 from core             import globalvar
 from core.gcmd        import GError, RunCommand
 from core.gcmd        import GError, RunCommand
 from gui_core.forms   import GUI
 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
 from gui_core.ghelp   import SearchModuleWindow
 
 
 class InstallExtensionWindow(wx.Frame):
 class InstallExtensionWindow(wx.Frame):
@@ -473,18 +472,12 @@ class UninstallExtensionWindow(wx.Frame):
         """!Shows command dialog"""
         """!Shows command dialog"""
         GUI(parent = self).ParseCommand(cmd = ['g.extension'])
         GUI(parent = self).ParseCommand(cmd = ['g.extension'])
 
 
-class CheckListExtension(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin, listmix.CheckListCtrlMixin):
+class CheckListExtension(GListCtrl):
     """!List of mapset/owner/group"""
     """!List of mapset/owner/group"""
     def __init__(self, parent):
     def __init__(self, parent):
-        self.parent = parent
-        
-        wx.ListCtrl.__init__(self, parent, id = wx.ID_ANY,
-                             style = wx.LC_REPORT)
-        listmix.CheckListCtrlMixin.__init__(self)
+        GListCtrl.__init__(self, parent)
         
         
-        # setup mixins
-        listmix.ListCtrlAutoWidthMixin.__init__(self)
-
+        # load extensions
         self.InsertColumn(0, _('Extension'))
         self.InsertColumn(0, _('Extension'))
         self.LoadData()
         self.LoadData()