[GRASS-SVN] r36993 - grass/trunk/gui/wxpython/gui_modules
svn_grass at osgeo.org
svn_grass at osgeo.org
Mon May 4 14:02:27 EDT 2009
Author: martinl
Date: 2009-05-04 14:02:27 -0400 (Mon, 04 May 2009)
New Revision: 36993
Modified:
grass/trunk/gui/wxpython/gui_modules/menuform.py
Log:
wxGUI: run UpdateSelection() in the thread
Modified: grass/trunk/gui/wxpython/gui_modules/menuform.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/menuform.py 2009-05-04 16:46:39 UTC (rev 36992)
+++ grass/trunk/gui/wxpython/gui_modules/menuform.py 2009-05-04 18:02:27 UTC (rev 36993)
@@ -43,7 +43,7 @@
@todo
- verify option value types
- - use DOM instead of SAX
+ - use DOM instead of SAX (is it really necessary? ML)
"""
import sys
@@ -54,6 +54,7 @@
import time
import copy
import locale
+from threading import Thread
### i18N
import gettext
@@ -64,11 +65,11 @@
globalvar.CheckForWx()
import wx
+import wx.html
import wx.lib.flatnotebook as FN
import wx.lib.colourselect as csel
import wx.lib.filebrowsebutton as filebrowse
from wx.lib.expando import ExpandoTextCtrl, EVT_ETC_LAYOUT_NEEDED
-import wx.html
# Do the python 2.0 standard xml thing and map it on the old names
import xml.sax
@@ -161,6 +162,107 @@
"""Escapes ampersands with additional ampersand for GUI"""
return string.replace(text, "&", "&&")
+class UpdateThread(Thread):
+ """Update dialog widgets in the thread"""
+ def __init__(self, parent, eventId, task):
+ Thread.__init__(self)
+
+ self.parent = parent
+ self.eventId = eventId
+ self.task = task
+ self.setDaemon(True)
+
+ self.start()
+
+ def run(self):
+ # get widget id
+ if not self.eventId:
+ for p in self.task.params:
+ if p.get('gisprompt', False) == False:
+ continue
+ prompt = p.get('element', '')
+ if prompt == 'vector':
+ name = p.get('name', '')
+ if name in ('map', 'input'):
+ eventId = p['wxId']
+ if eventId is None:
+ return
+
+ p = self.task.get_param(self.eventId, element='wxId', raiseError=True)
+
+ if not p or \
+ not p.has_key('wxId-bind'):
+ return
+
+ # get widget prompt
+ pType = p.get('prompt', '')
+ if not pType:
+ return
+
+ # check for map/input parameter
+ pMap = self.task.get_param('map', raiseError=False)
+ if not pMap:
+ pMap = self.task.get_param('input', raiseError=False)
+
+ if pMap:
+ map = pMap.get('value', '')
+ else:
+ map = None
+
+ # avoid multiple updating
+ columns = []
+
+ # update reference widgets
+ for uid in p['wxId-bind']:
+ win = self.parent.FindWindowById(uid)
+ name = win.GetName()
+
+ if name == 'LayerSelect':
+ win.InsertLayers(map)
+
+ elif name == 'TableSelect':
+ pDriver = self.task.get_param('dbdriver', element='prompt', raiseError=False)
+ driver = db = None
+ if pDriver:
+ driver = pDriver['value']
+ pDb = self.task.get_param('dbname', element='prompt', raiseError=False)
+ if pDb:
+ db = pDb['value']
+
+ win.InsertTables(driver, db)
+
+ elif name == 'ColumnSelect':
+ if not columns:
+ pLayer = self.task.get_param('layer', element='element', raiseError=False)
+ if pLayer:
+ if pLayer.get('value', '') != '':
+ layer = int(pLayer.get('value', 1))
+ else:
+ layer = int(pLayer.get('default', 1))
+ else:
+ layer = 1
+
+ if map:
+ win.InsertColumns(map, layer)
+ columns = win.GetItems()
+ else: # table
+ pDriver = self.task.get_param('dbdriver', element='prompt', raiseError=False)
+ if pDriver:
+ driver = pDriver.get('value', None)
+ pDb = self.task.get_param('dbname', element='prompt', raiseError=False)
+ if pDb:
+ db = pDb.get('value', None)
+ pTable = self.task.get_param('dbtable', element='element', raiseError=False)
+ if pTable and \
+ pTable.get('value', '') != '':
+ if driver and db:
+ win.InsertTableColumns(pTable.get('value'), driver, db)
+ else:
+ win.InsertTableColumns(pTable.get('value'))
+ columns = win.GetItems()
+ else:
+ win.SetItems(columns)
+
class testSAXContentHandler(HandlerBase):
# SAX compliant
def characters(self, ch, start, length):
@@ -1533,97 +1635,11 @@
"""
Update dialog (layers, tables, columns, etc.)
"""
- # get widget id
- if not event:
- id = None
- for p in self.task.params:
- if p.get('gisprompt', False) == False:
- continue
- prompt = p.get('element', '')
- if prompt == 'vector':
- name = p.get('name', '')
- if name in ('map', 'input'):
- id = p['wxId']
- if id is None:
- return
+ if event:
+ UpdateThread(self, event.GetId(), self.task)
else:
- id = event.GetId()
+ UpdateThread(self, None, self.task)
- p = self.task.get_param(id, element='wxId', raiseError=False)
-
- if not p or \
- not p.has_key('wxId-bind'):
- return
-
- # get widget prompt
- pType = p.get('prompt', '')
- if not pType:
- return
-
- # check for map/input parameter
- pMap = self.task.get_param('map', raiseError=False)
- if not pMap:
- pMap = self.task.get_param('input', raiseError=False)
-
- if pMap:
- map = pMap.get('value', '')
- else:
- map = None
-
- # avoid multiple updating
- columns = []
-
- # update reference widgets
- for uid in p['wxId-bind']:
- win = self.FindWindowById(uid)
- name = win.GetName()
-
- if name == 'LayerSelect':
- win.InsertLayers(map)
-
- elif name == 'TableSelect':
- pDriver = self.task.get_param('dbdriver', element='prompt', raiseError=False)
- driver = db = None
- if pDriver:
- driver = pDriver['value']
- pDb = self.task.get_param('dbname', element='prompt', raiseError=False)
- if pDb:
- db = pDb['value']
-
- win.InsertTables(driver, db)
-
- elif name == 'ColumnSelect':
- if not columns:
- pLayer = self.task.get_param('layer', element='element', raiseError=False)
- if pLayer:
- if pLayer.get('value', '') != '':
- layer = int(pLayer.get('value', 1))
- else:
- layer = int(pLayer.get('default', 1))
- else:
- layer = 1
-
- if map:
- win.InsertColumns(map, layer)
- columns = win.GetItems()
- else: # table
- pDriver = self.task.get_param('dbdriver', element='prompt', raiseError=False)
- if pDriver:
- driver = pDriver.get('value', None)
- pDb = self.task.get_param('dbname', element='prompt', raiseError=False)
- if pDb:
- db = pDb.get('value', None)
- pTable = self.task.get_param('dbtable', element='element', raiseError=False)
- if pTable and \
- pTable.get('value', '') != '':
- if driver and db:
- win.InsertTableColumns(pTable.get('value'), driver, db)
- else:
- win.InsertTableColumns(pTable.get('value'))
- columns = win.GetItems()
- else:
- win.SetItems(columns)
-
def createCmd( self, ignoreErrors = False ):
"""
Produce a command line string (list) or feeding into GRASS.
More information about the grass-commit
mailing list