[GRASS-SVN] r41892 - grass/trunk/gui/wxpython/gui_modules
svn_grass at osgeo.org
svn_grass at osgeo.org
Fri Apr 16 16:42:09 EDT 2010
Author: martinl
Date: 2010-04-16 16:42:09 -0400 (Fri, 16 Apr 2010)
New Revision: 41892
Modified:
grass/trunk/gui/wxpython/gui_modules/gmodeler.py
grass/trunk/gui/wxpython/gui_modules/preferences.py
Log:
wxGUI/modeler: action color configurable
Modified: grass/trunk/gui/wxpython/gui_modules/gmodeler.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/gmodeler.py 2010-04-16 20:06:55 UTC (rev 41891)
+++ grass/trunk/gui/wxpython/gui_modules/gmodeler.py 2010-04-16 20:42:09 UTC (rev 41892)
@@ -232,6 +232,11 @@
msg += ', '.join(vect)
return rast, vect, rast3d, msg
+
+ def Update(self):
+ """!Update model"""
+ for action in self.actions:
+ action.Update()
class ModelFrame(wx.Frame):
def __init__(self, parent, id = wx.ID_ANY, title = _("Graphical modeler (under development)"), **kwargs):
@@ -253,7 +258,6 @@
"default" : wx.StockCursor(wx.CURSOR_ARROW),
"cross" : wx.StockCursor(wx.CURSOR_CROSS),
}
- self.dialogs = { 'preferences' : None }
wx.Frame.__init__(self, parent = parent, id = id, title = title, **kwargs)
self.SetName("Modeler")
@@ -314,7 +318,15 @@
evthandler.SetShape(item)
evthandler.SetPreviousHandler(item.GetEventHandler())
item.SetEventHandler(evthandler)
-
+
+ def GetCanvas(self):
+ """!Get canvas"""
+ return self.canvas
+
+ def GetModel(self):
+ """!Get model"""
+ return self.model
+
def ModelChanged(self):
"""!Update window title"""
if not self.modelChanged:
@@ -329,12 +341,11 @@
def OnPreferences(self, event):
"""!Open preferences dialog"""
- if not self.dialogs['preferences']:
- dlg = PreferencesDialog(parent = self)
- self.dialogs['preferences'] = dlg
- self.dialogs['preferences'].CenterOnParent()
+ dlg = PreferencesDialog(parent = self)
+ dlg.CenterOnParent()
- self.dialogs['preferences'].ShowModal()
+ dlg.ShowModal()
+ self.canvas.Refresh()
def OnModelProperties(self, event):
"""!Model properties dialog"""
@@ -1017,12 +1028,9 @@
self.id = -1 # used for gxm file
self.data = list() # list of connected data items
-
- # colors
- self.colors = dict()
- self.colors['valid'] = wx.LIGHT_GREY_BRUSH
- self.colors['invalid'] = wx.WHITE_BRUSH
+ self.isValid = False
+
if self.parent.GetCanvas():
ogl.RectangleShape.__init__(self, width, height)
@@ -1030,12 +1038,23 @@
self.SetX(x)
self.SetY(y)
self.SetPen(wx.BLACK_PEN)
- self.SetBrush(self.colors['invalid'])
+ self._setBrush(False)
if self.cmd and len(self.cmd) > 0:
self.AddText(self.cmd[0])
else:
self.AddText('<<module>>')
+ def _setBrush(self, isvalid):
+ """!Set brush"""
+ if isvalid:
+ color = UserSettings.Get(group='modeler', key='action',
+ subkey=('color', 'valid'))
+ else:
+ color = UserSettings.Get(group='modeler', key='action',
+ subkey=('color', 'invalid'))
+ wxColor = wx.Color(color[0], color[1], color[2])
+ self.SetBrush(wx.Brush(wxColor))
+
def GetId(self):
"""!Get id"""
return self.id
@@ -1082,11 +1101,9 @@
def SetValid(self, isvalid):
"""!Set instance to be valid/invalid"""
- if isvalid:
- self.SetBrush(self.colors['valid'])
- else:
- self.SetBrush(self.colors['invalid'])
-
+ self.isValid = isvalid
+ self._setBrush(isvalid)
+
def AddData(self, item):
"""!Register new data item"""
if item not in self.data:
@@ -1100,6 +1117,10 @@
return None
+ def Update(self):
+ """!Update action"""
+ self._setBrush(self.isValid)
+
class ModelData(ogl.EllipseShape):
"""!Data item class"""
def __init__(self, parent, x, y, name = '', value = '', prompt = '', width = 175, height = 50):
@@ -1821,7 +1842,7 @@
colour = self.settings.Get(group='modeler', key='action', subkey=('color', 'valid')),
size = globalvar.DIALOG_COLOR_SIZE)
vColor.SetName('GetColour')
- self.winId['modeler:action:validColor'] = vColor.GetId()
+ self.winId['modeler:action:color:valid'] = vColor.GetId()
gridSizer.Add(item=vColor,
flag=wx.ALIGN_RIGHT |
@@ -1838,7 +1859,7 @@
colour = self.settings.Get(group='modeler', key='action', subkey=('color', 'invalid')),
size = globalvar.DIALOG_COLOR_SIZE)
iColor.SetName('GetColour')
- self.winId['modeler:action:invalidColor'] = iColor.GetId()
+ self.winId['modeler:action:color:invalid'] = iColor.GetId()
gridSizer.Add(item=iColor,
flag=wx.ALIGN_RIGHT |
@@ -1865,6 +1886,13 @@
return panel
+ def OnApply(self, event):
+ """!Button 'Apply' pressed"""
+ PreferencesBaseDialog.OnApply(self, event)
+
+ self.parent.GetModel().Update()
+ self.parent.GetCanvas().Refresh()
+
def main():
app = wx.PySimpleApp()
wx.InitAllImageHandlers()
Modified: grass/trunk/gui/wxpython/gui_modules/preferences.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/preferences.py 2010-04-16 20:06:55 UTC (rev 41891)
+++ grass/trunk/gui/wxpython/gui_modules/preferences.py 2010-04-16 20:42:09 UTC (rev 41892)
@@ -907,23 +907,84 @@
def OnDefault(self, event):
"""!Button 'Set to default' pressed"""
- pass
-
+ self.settings.userSettings = copy.deepcopy(self.settings.defaultSettings)
+
+ # update widgets
+ for gks in self.winId.keys():
+ try:
+ group, key, subkey = gks.split(':')
+ value = self.settings.Get(group, key, subkey)
+ except ValueError:
+ group, key, subkey, subkey1 = gks.split(':')
+ value = self.settings.Get(group, key, [subkey, subkey1])
+ win = self.FindWindowById(self.winId[gks])
+ if win.GetName() in ('GetValue', 'IsChecked'):
+ value = win.SetValue(value)
+ elif win.GetName() == 'GetSelection':
+ value = win.SetSelection(value)
+ elif win.GetName() == 'GetStringSelection':
+ value = win.SetStringSelection(value)
+ else:
+ value = win.SetValue(value)
+
def OnApply(self, event):
"""!Button 'Apply' pressed"""
- pass
+ if self._updateSettings():
+ self.parent.goutput.WriteLog(_('Settings applied to current session but not saved'))
+ self.Close()
- def OnSave(self, event):
- """!Button 'Save' pressed"""
- pass
-
+ def OnCloseWindow(self, event):
+ self.Hide()
+
def OnCancel(self, event):
"""!Button 'Cancel' pressed"""
self.Close()
- def OnCloseWindow(self, event):
- self.Hide()
+ def OnSave(self, event):
+ """!Button 'Save' pressed"""
+ if self._updateSettings():
+ file = self.settings.SaveToFile()
+ self.parent.goutput.WriteLog(_('Settings saved to file \'%s\'.') % file)
+ self.Close()
+ def _updateSettings(self):
+ """!Update user settings"""
+ for item in self.winId.keys():
+ try:
+ group, key, subkey = item.split(':')
+ subkey1 = None
+ except ValueError:
+ group, key, subkey, subkey1 = item.split(':')
+
+ id = self.winId[item]
+ win = self.FindWindowById(id)
+ if win.GetName() == 'GetValue':
+ value = win.GetValue()
+ elif win.GetName() == 'GetSelection':
+ value = win.GetSelection()
+ elif win.GetName() == 'IsChecked':
+ value = win.IsChecked()
+ elif win.GetName() == 'GetStringSelection':
+ value = win.GetStringSelection()
+ elif win.GetName() == 'GetColour':
+ value = tuple(win.GetValue())
+ else:
+ value = win.GetValue()
+
+ if key == 'keycolumn' and value == '':
+ wx.MessageBox(parent=self,
+ message=_("Key column cannot be empty string."),
+ caption=_("Error"), style=wx.OK | wx.ICON_ERROR)
+ win.SetValue(self.settings.Get(group='atm', key='keycolumn', subkey='value'))
+ return False
+
+ if subkey1:
+ self.settings.Set(group, value, key, [subkey, subkey1])
+ else:
+ self.settings.Set(group, value, key, subkey)
+
+ return True
+
class PreferencesDialog(PreferencesBaseDialog):
"""!User preferences dialog"""
def __init__(self, parent, title = _("GUI settings"),
@@ -1832,84 +1893,10 @@
event.Skip()
- def OnSave(self, event):
- """!Button 'Save' pressed"""
- if self._UpdateSettings():
- file = self.settings.SaveToFile()
- self.parent.goutput.WriteLog(_('Settings saved to file \'%s\'.') % file)
- self.Close()
-
- def OnApply(self, event):
- """!Button 'Apply' pressed"""
- if self._UpdateSettings():
- self.parent.goutput.WriteLog(_('Settings applied to current session but not saved'))
- self.Close()
-
- def OnCloseWindow(self, event):
- self.Hide()
-
- def OnCancel(self, event):
- """!Button 'Cancel' pressed"""
- self.Close()
-
- def OnDefault(self, event):
- """!Button 'Set to default' pressed"""
- self.settings.userSettings = copy.deepcopy(self.settings.defaultSettings)
-
- # update widgets
- for gks in self.winId.keys():
- try:
- group, key, subkey = gks.split(':')
- value = self.settings.Get(group, key, subkey)
- except ValueError:
- group, key, subkey, subkey1 = gks.split(':')
- value = self.settings.Get(group, key, [subkey, subkey1])
- win = self.FindWindowById(self.winId[gks])
- if win.GetName() in ('GetValue', 'IsChecked'):
- value = win.SetValue(value)
- elif win.GetName() == 'GetSelection':
- value = win.SetSelection(value)
- elif win.GetName() == 'GetStringSelection':
- value = win.SetStringSelection(value)
- else:
- value = win.SetValue(value)
-
- def _UpdateSettings(self):
+ def _updateSettings(self):
"""!Update user settings"""
- for item in self.winId.keys():
- try:
- group, key, subkey = item.split(':')
- subkey1 = None
- except ValueError:
- group, key, subkey, subkey1 = item.split(':')
-
- id = self.winId[item]
- win = self.FindWindowById(id)
- if win.GetName() == 'GetValue':
- value = win.GetValue()
- elif win.GetName() == 'GetSelection':
- value = win.GetSelection()
- elif win.GetName() == 'IsChecked':
- value = win.IsChecked()
- elif win.GetName() == 'GetStringSelection':
- value = win.GetStringSelection()
- elif win.GetName() == 'GetColour':
- value = tuple(win.GetValue())
- else:
- value = win.GetValue()
-
- if key == 'keycolumn' and value == '':
- wx.MessageBox(parent=self,
- message=_("Key column cannot be empty string."),
- caption=_("Error"), style=wx.OK | wx.ICON_ERROR)
- win.SetValue(self.settings.Get(group='atm', key='keycolumn', subkey='value'))
- return False
-
- if subkey1:
- self.settings.Set(group, value, key, [subkey, subkey1])
- else:
- self.settings.Set(group, value, key, subkey)
-
+ PreferencesBaseDialog._updateSettings(self)
+
#
# update default window dimension
#
More information about the grass-commit
mailing list