[GRASS-SVN] r56786 - grass/trunk/gui/wxpython/gui_core
svn_grass at osgeo.org
svn_grass at osgeo.org
Tue Jun 18 08:04:30 PDT 2013
Author: annakrat
Date: 2013-06-18 08:04:30 -0700 (Tue, 18 Jun 2013)
New Revision: 56786
Modified:
grass/trunk/gui/wxpython/gui_core/forms.py
grass/trunk/gui/wxpython/gui_core/widgets.py
Log:
wxGUI: show color table thumbnails in r.colors combo box
Modified: grass/trunk/gui/wxpython/gui_core/forms.py
===================================================================
--- grass/trunk/gui/wxpython/gui_core/forms.py 2013-06-18 13:54:47 UTC (rev 56785)
+++ grass/trunk/gui/wxpython/gui_core/forms.py 2013-06-18 15:04:30 UTC (rev 56786)
@@ -88,7 +88,7 @@
from grass.script import core as grass
from grass.script import task as gtask
-from gui_core.widgets import StaticWrapText, ScrolledPanel
+from gui_core.widgets import StaticWrapText, ScrolledPanel, ColorTablesComboBox
from gui_core.ghelp import HelpPanel
from gui_core import gselect
from core import gcmd
@@ -1053,9 +1053,14 @@
flag = wx.ADJUST_MINSIZE, border = 0)
else:
# list of values (combo)
- cb = wx.ComboBox(parent = which_panel, id = wx.ID_ANY, value = p.get('default',''),
- size = globalvar.DIALOG_COMBOBOX_SIZE,
- choices = valuelist, style = wx.CB_DROPDOWN)
+ if p['name'] == 'color':
+ cb = ColorTablesComboBox(parent=which_panel, value=p.get('default',''),
+ size=globalvar.DIALOG_COMBOBOX_SIZE,
+ choices=valuelist)
+ else:
+ cb = wx.ComboBox(parent=which_panel, id=wx.ID_ANY, value=p.get('default',''),
+ size=globalvar.DIALOG_COMBOBOX_SIZE,
+ choices=valuelist, style=wx.CB_DROPDOWN)
if value:
cb.SetValue(value) # parameter previously set
which_sizer.Add(item = cb, proportion = 0,
Modified: grass/trunk/gui/wxpython/gui_core/widgets.py
===================================================================
--- grass/trunk/gui/wxpython/gui_core/widgets.py 2013-06-18 13:54:47 UTC (rev 56785)
+++ grass/trunk/gui/wxpython/gui_core/widgets.py 2013-06-18 15:04:30 UTC (rev 56786)
@@ -35,6 +35,7 @@
import wx
import wx.lib.mixins.listctrl as listmix
import wx.lib.scrolledpanel as SP
+import wx.combo
try:
import wx.lib.agw.flatnotebook as FN
except ImportError:
@@ -1196,3 +1197,53 @@
pass
return data
+
+class ColorTablesComboBox(wx.combo.OwnerDrawnComboBox):
+ """!ComboBox with drawn color tables (created by thumbnails.py).
+
+ Used in r(3).colors dialog.
+ """
+ def OnDrawItem(self, dc, rect, item, flags):
+ """!Overridden from OwnerDrawnComboBox.
+
+ Called to draw each item in the list.
+ """
+ if item == wx.NOT_FOUND:
+ # painting the control, but there is no valid item selected yet
+ return
+
+ r = wx.Rect(*rect) # make a copy
+ r.Deflate(3, 5)
+
+ # for painting the items in the popup
+ bitmap = self.GetColorTableBitmap(self.GetString(item))
+ if bitmap:
+ dc.DrawBitmap(bitmap, r.x, r.y + (r.height - bitmap.GetHeight()) / 2)
+ dc.DrawText(self.GetString(item),
+ r.x + bitmap.GetWidth() + 10,
+ (r.y + 0) + (r.height - dc.GetCharHeight()) / 2)
+
+ def OnMeasureItem(self, item):
+ """!Overridden from OwnerDrawnComboBox, should return the height.
+
+ Needed to display an item in the popup, or -1 for default.
+ """
+ return 24
+
+ def GetColorTableBitmap(self, colorTable):
+ """!Returns bitmap with colortable for given nacolor table name.
+
+ @param colorTable name of color table
+ """
+ if not hasattr(self, 'bitmaps'):
+ self.bitmaps = {}
+
+ if colorTable in self.bitmaps:
+ return self.bitmaps[colorTable]
+
+ path = os.path.join(os.getenv("GISBASE"), "docs", "html", "Colortable_%s.png" % colorTable)
+ if os.path.exists(path):
+ bitmap = wx.Bitmap(path)
+ self.bitmaps[colorTable] = bitmap
+ return bitmap
+ return None
More information about the grass-commit
mailing list