[GRASS-SVN] r53996 - in grass/trunk/gui/wxpython: core gmodeler gui_core lmgr mapdisp nviz scripts vdigit wxplot
svn_grass at osgeo.org
svn_grass at osgeo.org
Fri Nov 23 10:18:26 PST 2012
Author: wenzeslaus
Date: 2012-11-23 10:18:26 -0800 (Fri, 23 Nov 2012)
New Revision: 53996
Modified:
grass/trunk/gui/wxpython/core/gconsole.py
grass/trunk/gui/wxpython/core/giface.py
grass/trunk/gui/wxpython/core/workspace.py
grass/trunk/gui/wxpython/gmodeler/frame.py
grass/trunk/gui/wxpython/gui_core/forms.py
grass/trunk/gui/wxpython/gui_core/goutput.py
grass/trunk/gui/wxpython/lmgr/frame.py
grass/trunk/gui/wxpython/mapdisp/frame.py
grass/trunk/gui/wxpython/nviz/mapwindow.py
grass/trunk/gui/wxpython/nviz/preferences.py
grass/trunk/gui/wxpython/scripts/vkrige.py
grass/trunk/gui/wxpython/vdigit/preferences.py
grass/trunk/gui/wxpython/wxplot/dialogs.py
Log:
wxGUI/GConsole: fixing usage of goutput, temporary keeping also old interface (co-author: annakrat)
Modified: grass/trunk/gui/wxpython/core/gconsole.py
===================================================================
--- grass/trunk/gui/wxpython/core/gconsole.py 2012-11-23 17:07:19 UTC (rev 53995)
+++ grass/trunk/gui/wxpython/core/gconsole.py 2012-11-23 18:18:26 UTC (rev 53996)
@@ -315,11 +315,18 @@
gWriteWarning, EVT_WRITE_WARNING = NewEvent()
gWriteError, EVT_WRITE_ERROR = NewEvent()
-# Occurs when ignored command is called.
+# Occurs when an ignored command is called.
# Attribute cmd contains command (as a list).
gIgnoredCmdRun, EVT_IGNORED_CMD_RUN = NewEvent()
+# Occurs when important command is called.
+# Determined by switchPage and priority parameters of GConsole.RunCmd()
+# currently used only for Layer Manager
+# because others (forms and gmodeler) just wants to see all commands
+# (because commands are the main part of their work)
+gImportantCmdRun, EVT_IMPORTANT_CMD_RUN = NewEvent()
+
class GConsole(wx.EvtHandler):
"""!
"""
@@ -406,7 +413,7 @@
wx.PostEvent(self, event)
def RunCmd(self, command, compReg=True, switchPage=False, skipInterface=False,
- onDone=None, onPrepare=None, userData=None):
+ onDone=None, onPrepare=None, userData=None, priority=1):
"""!Run command typed into console command prompt (GPrompt).
@todo Document the other event.
@@ -418,11 +425,13 @@
(according to ignoredCmdPattern) is run.
For example, see layer manager which handles d.* on its own.
- @todo all switchPage and priority params are currently broken in this class)
+ @todo replace swichPage and priority by parameter 'silent' or 'important'
+ also possible solution is RunCmdSilently and RunCmdWithoutNotifyingAUser
@param command command given as a list (produced e.g. by utils.split())
@param compReg True use computation region
@param switchPage switch to output page
+ @param priority command importance - possible replacement for switchPage
@param skipInterface True to do not launch GRASS interface
parser when command has no arguments given
@param onDone function to be called when command is finished
@@ -502,8 +511,10 @@
# documenting old behavior/implementation:
# switch and focus if required
- # TODO: this probably should be run command event
- # TODO: this should be solved by the user using userData and onDone
+ # important commad
+ # TODO: add also user data, cmd, ... to the event?
+ importantEvent = gImportantCmdRun()
+ wx.PostEvent(self, importantEvent)
# activate computational region (set with g.region)
# for all non-display commands.
Modified: grass/trunk/gui/wxpython/core/giface.py
===================================================================
--- grass/trunk/gui/wxpython/core/giface.py 2012-11-23 17:07:19 UTC (rev 53995)
+++ grass/trunk/gui/wxpython/core/giface.py 2012-11-23 18:18:26 UTC (rev 53996)
@@ -39,7 +39,7 @@
grass.message(text)
def WriteCmdLog(self, line, pid = None, switchPage = True):
- grass.message(text)
+ grass.message(line)
def WriteWarning(self, line):
grass.warning(line)
Modified: grass/trunk/gui/wxpython/core/workspace.py
===================================================================
--- grass/trunk/gui/wxpython/core/workspace.py 2012-11-23 17:07:19 UTC (rev 53995)
+++ grass/trunk/gui/wxpython/core/workspace.py 2012-11-23 18:18:26 UTC (rev 53996)
@@ -1058,8 +1058,8 @@
"Number of skipped lines: %(line)d") % \
{ 'file' : self.filename, 'line' : self.num_error },
caption=_("Warning"), style=wx.OK | wx.ICON_EXCLAMATION)
- parent.goutput.WriteLog('Map layers loaded from GRC file <%s>' % self.filename)
- parent.goutput.WriteLog('Skipped lines:\n%s' % self.error)
+ parent._gconsole.WriteLog('Map layers loaded from GRC file <%s>' % self.filename)
+ parent._gconsole.WriteLog('Skipped lines:\n%s' % self.error)
return self.layers
Modified: grass/trunk/gui/wxpython/gmodeler/frame.py
===================================================================
--- grass/trunk/gui/wxpython/gmodeler/frame.py 2012-11-23 17:07:19 UTC (rev 53995)
+++ grass/trunk/gui/wxpython/gmodeler/frame.py 2012-11-23 18:18:26 UTC (rev 53996)
@@ -328,11 +328,11 @@
dlg.Destroy()
if rast:
- self.goutput.RunCmd(['g.remove', 'rast=%s' %','.join(rast)])
+ self._gconsole.RunCmd(['g.remove', 'rast=%s' %','.join(rast)])
if rast3d:
- self.goutput.RunCmd(['g.remove', 'rast3d=%s' %','.join(rast3d)])
+ self._gconsole.RunCmd(['g.remove', 'rast3d=%s' %','.join(rast3d)])
if vect:
- self.goutput.RunCmd(['g.remove', 'vect=%s' %','.join(vect)])
+ self._gconsole.RunCmd(['g.remove', 'vect=%s' %','.join(vect)])
self.SetStatusText(_("%d maps deleted from current mapset") % \
int(len(rast) + len(rast3d) + len(vect)))
@@ -1559,8 +1559,8 @@
mode = stat.S_IMODE(os.lstat(self.filename)[stat.ST_MODE])
os.chmod(self.filename, mode | stat.S_IXUSR)
- self.parent.goutput.RunCmd([fd.name], switchPage = True,
- skipInterface = True, onDone = self.OnDone)
+ self.parent._gconsole.RunCmd([fd.name], switchPage = True,
+ skipInterface = True, onDone = self.OnDone)
event.Skip()
Modified: grass/trunk/gui/wxpython/gui_core/forms.py
===================================================================
--- grass/trunk/gui/wxpython/gui_core/forms.py 2012-11-23 17:07:19 UTC (rev 53995)
+++ grass/trunk/gui/wxpython/gui_core/forms.py 2012-11-23 18:18:26 UTC (rev 53996)
@@ -697,9 +697,9 @@
def OnAbort(self, event):
"""!Abort running command"""
- from gui_core.goutput import wxCmdAbort
+ from core.gconsole import wxCmdAbort
event = wxCmdAbort(aborted = True)
- wx.PostEvent(self.goutput, event)
+ wx.PostEvent(self._gconsole, event)
def OnCopy(self, event):
"""!Copy the command"""
Modified: grass/trunk/gui/wxpython/gui_core/goutput.py
===================================================================
--- grass/trunk/gui/wxpython/gui_core/goutput.py 2012-11-23 17:07:19 UTC (rev 53995)
+++ grass/trunk/gui/wxpython/gui_core/goutput.py 2012-11-23 18:18:26 UTC (rev 53996)
@@ -27,6 +27,7 @@
import wx
from wx import stc
+from wx.lib.newevent import NewEvent
from core.gcmd import GError, EncodeString
from core.events import gShowNotification
@@ -44,6 +45,11 @@
GC_PROMPT = 2
+# occurs when a content of console output window was changed
+# some similar event exists in GConsole this will be not neccessary
+gGcContentChanged, EVT_GC_CONTENT_CHANGED = NewEvent()
+
+
class GConsoleWindow(wx.SplitterWindow):
"""!Create and manage output console for commands run by GUI.
"""
@@ -103,6 +109,7 @@
# text control for command output
self.cmdOutput = GStc(parent = self.panelOutput, id = wx.ID_ANY, margin = margin,
wrap = None)
+ self.cmdOutput.Bind(stc.EVT_STC_CHANGE, self.OnStcChanged)
# information about available modules
modulesData = ModulesData()
@@ -472,6 +479,10 @@
self.progressbar.SetValue(0) # reset progress bar on '0%'
event.Skip()
+ def OnStcChanged(self, event):
+ newEvent = gGcContentChanged()
+ wx.PostEvent(self, newEvent)
+
def ResetFocus(self):
"""!Reset focus"""
self.cmdPrompt.SetFocus()
Modified: grass/trunk/gui/wxpython/lmgr/frame.py
===================================================================
--- grass/trunk/gui/wxpython/lmgr/frame.py 2012-11-23 17:07:19 UTC (rev 53995)
+++ grass/trunk/gui/wxpython/lmgr/frame.py 2012-11-23 18:18:26 UTC (rev 53996)
@@ -52,8 +52,9 @@
from dbmgr.manager import AttributeManager
from core.workspace import ProcessWorkspaceFile, ProcessGrcFile, WriteWorkspaceFile
from core.gconsole import GConsole, \
- EVT_CMD_OUTPUT, EVT_CMD_RUN, EVT_CMD_DONE, EVT_IGNORED_CMD_RUN
-from gui_core.goutput import GConsoleWindow, GC_SEARCH, GC_PROMPT
+ EVT_CMD_OUTPUT, EVT_CMD_RUN, EVT_CMD_DONE, \
+ EVT_IGNORED_CMD_RUN, EVT_IMPORTANT_CMD_RUN
+from gui_core.goutput import GConsoleWindow, EVT_GC_CONTENT_CHANGED, GC_SEARCH, GC_PROMPT
from gui_core.dialogs import GdalOutputDialog, DxfImportDialog, GdalImportDialog, MapLayersDialog
from gui_core.dialogs import EVT_APPLY_MAP_LAYERS
from gui_core.dialogs import LocationDialog, MapsetDialog, CreateNewVector, GroupDialog
@@ -270,17 +271,23 @@
self.goutput = GConsoleWindow(parent = self, gconsole = self._gconsole,
gcstyle = GC_SEARCH | GC_PROMPT)
self.notebook.AddPage(page = self.goutput, text = _("Command console"), name = 'output')
+ # EVT_CMD_OUTPUT and EVT_GC_CONTENT_CHANGED are similar but should be distinct
+ # (logging/messages may be splited from GConsole commad running interface)
+ # thus, leaving this bind here
self._gconsole.Bind(EVT_CMD_OUTPUT,
lambda event:
- self._switchPageHandler(event = event, priority = 1))
- self._gconsole.Bind(EVT_CMD_RUN,
- lambda event:
- self._switchPageHandler(event = event, priority = 2))
- self._gconsole.Bind(EVT_CMD_DONE,
- lambda event:
- self._switchPageHandler(event = event, priority = 3))
- self.goutput.Bind(EVT_IGNORED_CMD_RUN,
- lambda event: self.RunSpecialCmd(event.cmd))
+ self._switchPageHandler(event = event, priority = 1))
+ self._gconsole.Bind(EVT_IMPORTANT_CMD_RUN,
+ lambda event:
+ self._switchPageHandler(event = event, priority = 2))
+ self._gconsole.Bind(EVT_IGNORED_CMD_RUN,
+ lambda event: self.RunSpecialCmd(event.cmd))
+ # if you are chnaging GConsoleWindow to GConsole and
+ # EVT_GC_CONTENT_CHANGED to somthing like EVT_LOG_OUTPUT
+ # you are doing right
+ self.goutput.Bind(EVT_GC_CONTENT_CHANGED,
+ lambda event:
+ self._switchPageHandler(event = event, priority = 1))
self._setCopyingOfSelectedText()
# create 'search module' notebook page
@@ -444,7 +451,7 @@
def OnDone(self, cmd, returncode):
"""Command execution finised"""
if hasattr(self, "model"):
- self.model.DeleteIntermediateData(log = self.goutput)
+ self.model.DeleteIntermediateData(log = self._gconsole)
del self.model
self.SetStatusText('')
@@ -463,7 +470,7 @@
self.model = Model()
self.model.LoadModel(filename)
- self.model.Run(log = self.goutput, onDone = self.OnDone, parent = self)
+ self.model.Run(log = self._goutput, onDone = self.OnDone, parent = self)
dlg.Destroy()
@@ -645,8 +652,8 @@
return mlist
def GetLogWindow(self):
- """!Get widget for command output"""
- return self.goutput
+ """!Gets console for command output and messages"""
+ return self._gconsole
def GetToolbar(self, name):
"""!Returns toolbar if exists else None"""
@@ -696,7 +703,7 @@
"""!Run command selected from menu"""
if event:
cmd = self.GetMenuCmd(event)
- self.goutput.RunCmd(cmd)
+ self._gconsole.RunCmd(cmd)
def OnMenuCmd(self, event = None, cmd = []):
"""!Parse command selected from menu"""
@@ -799,8 +806,8 @@
if dlg.ShowModal() == wx.ID_YES:
SetAddOnPath(os.pathsep.join(addonPath), key = 'PATH')
- self.goutput.WriteCmdLog(_("Launching script '%s'...") % filename)
- self.goutput.RunCmd([filename], switchPage = True)
+ self._gconsole.WriteCmdLog(_("Launching script '%s'...") % filename)
+ self._gconsole.RunCmd([filename], switchPage = True)
def OnChangeLocation(self, event):
"""Change current location"""
@@ -881,7 +888,7 @@
def OnNewVector(self, event):
"""!Create new vector map layer"""
- dlg = CreateNewVector(self, log = self.goutput,
+ dlg = CreateNewVector(self, log = self._gconsole,
cmd = (('v.edit',
{ 'tool' : 'create' },
'map')))
@@ -908,8 +915,8 @@
else:
osgeo4w = ''
- self.goutput.WriteCmdLog(_("System Info"))
- self.goutput.WriteLog("%s: %s\n"
+ self._gconsole.WriteCmdLog(_("System Info"))
+ self._gconsole.WriteLog("%s: %s\n"
"%s: %s\n"
"%s: %s (%s)\n"
"GDAL/OGR: %s\n"
@@ -926,7 +933,7 @@
wx.__version__,
_("Platform"), platform.platform(), osgeo4w),
switchPage = True)
- self.goutput.WriteCmdLog(' ')
+ self._gconsole.WriteCmdLog(' ')
def OnAboutGRASS(self, event):
"""!Display 'About GRASS' dialog"""
@@ -1364,7 +1371,7 @@
def OnHelp(self, event):
"""!Show help
"""
- self.goutput.RunCmd(['g.manual','-i'])
+ self._gconsole.RunCmd(['g.manual','-i'])
def OnIClass(self, event):
"""!Start wxIClass tool"""
@@ -1497,14 +1504,14 @@
styles = ','.join(layers[layer])
if styles:
cmd.append('styles=%s' % styles)
- self.goutput.RunCmd(cmd, switchPage = True)
+ self._gconsole.RunCmd(cmd, switchPage = True)
self.GetLayerTree().AddLayer(ltype = 'raster',
lname = layer,
lcmd = ['d.rast', 'map=%s' % layer],
multiple = False)
else:
- self.goutput.WriteWarning(_("Nothing to import. No WMS layer selected."))
+ self._gconsole.WriteWarning(_("Nothing to import. No WMS layer selected."))
dlg.Destroy()
@@ -1546,7 +1553,7 @@
dbmanager = AttributeManager(parent = self, id = wx.ID_ANY,
size = wx.Size(500, 300),
- item = layer, log = self.goutput,
+ item = layer, log = self._gconsole,
selection = selection)
busy.Destroy()
Modified: grass/trunk/gui/wxpython/mapdisp/frame.py
===================================================================
--- grass/trunk/gui/wxpython/mapdisp/frame.py 2012-11-23 17:07:19 UTC (rev 53995)
+++ grass/trunk/gui/wxpython/mapdisp/frame.py 2012-11-23 18:18:26 UTC (rev 53996)
@@ -203,7 +203,7 @@
return
if self._layerManager:
- log = self._layerManager.goutput
+ log = self._layerManager.GetLogWindow()
else:
log = None
@@ -934,11 +934,12 @@
self.MapWindow.SetCursor(self.cursors["pencil"])
# initiating output
- style = self._layerManager.goutput.cmdOutput.StyleWarning
- self._giface.WriteLog(_('Click and drag with left mouse button '
+ # TODO: this should be something like:
+ # write important message or write tip
+ self._giface.WriteWarning(_('Click and drag with left mouse button '
'to measure.%s'
'Double click with left button to clear.') % \
- (os.linesep), style)
+ (os.linesep))
if self.Map.projinfo['proj'] != 'xy':
units = self.Map.projinfo['units']
self._giface.WriteCmdLog(_('Measuring distance') + ' ('
Modified: grass/trunk/gui/wxpython/nviz/mapwindow.py
===================================================================
--- grass/trunk/gui/wxpython/nviz/mapwindow.py 2012-11-23 17:07:19 UTC (rev 53995)
+++ grass/trunk/gui/wxpython/nviz/mapwindow.py 2012-11-23 18:18:26 UTC (rev 53996)
@@ -119,9 +119,9 @@
self.toolWin = None
if self.lmgr:
- self.log = self.lmgr.goutput
- logerr = self.lmgr.goutput.GetLog(err = True)
- logmsg = self.lmgr.goutput.GetLog()
+ self.log = self.lmgr._gconsole
+ logerr = self.lmgr._gconsole.GetLog(err = True)
+ logmsg = self.lmgr._gconsole.GetLog()
else:
self.log = logmsg = sys.stdout
logerr = sys.stderr
Modified: grass/trunk/gui/wxpython/nviz/preferences.py
===================================================================
--- grass/trunk/gui/wxpython/nviz/preferences.py 2012-11-23 17:07:19 UTC (rev 53995)
+++ grass/trunk/gui/wxpython/nviz/preferences.py 2012-11-23 18:18:26 UTC (rev 53996)
@@ -624,7 +624,7 @@
fileSettings['nviz'] = UserSettings.Get(group = 'nviz')
UserSettings.SaveToFile(fileSettings)
- self.parent.goutput.WriteLog(
+ self.parent._gconsole.WriteLog(
_('3D view settings saved to file <%s>.') % UserSettings.filePath)
self.Destroy()
Modified: grass/trunk/gui/wxpython/scripts/vkrige.py
===================================================================
--- grass/trunk/gui/wxpython/scripts/vkrige.py 2012-11-23 17:07:19 UTC (rev 53995)
+++ grass/trunk/gui/wxpython/scripts/vkrige.py 2012-11-23 18:18:26 UTC (rev 53996)
@@ -99,7 +99,9 @@
self.CreatePage(package = Rpackage, Rinstance = Rinstance, controller = controller)
## Command output. From menuform module, cmdPanel class
- self.goutput = goutput.GConsole(parent = self, margin = False)
+ self._console = gconsole.GConsole(guiparent = self, lmgr = None)
+ self.goutput = goutput.GConsoleWindow(parent = self, gconsole = self._gconsole, margin = False,
+ gcstyle = goutput.GC_SEARCH | goutput.GC_PROMPT)
self.goutputId = self.RPackagesBook.GetPageCount()
self.outpage = self.RPackagesBook.AddPage(page = self.goutput, text = _("Command output"), name = 'output')
self._gconsole.Bind(gconsole.EVT_CMD_RUN,
@@ -229,7 +231,7 @@
SelectedPanel = self.RPackagesBook.GetCurrentPage()
if self.RPackagesBook.GetPageText(self.RPackagesBook.GetSelection()) == 'Command output':
- self.goutput.WriteError("No parameters for running. Please select \"gstat\" tab, check parameters and re-run.")
+ self._gconsole.WriteError("No parameters for running. Please select \"gstat\" tab, check parameters and re-run.")
return False # no break invoked by above function
# mount command string as it would have been written on CLI
@@ -255,7 +257,7 @@
# give it to the output console
#@FIXME: it runs the command as a NEW instance. Reimports data, recalculates variogram fit..
#otherwise I can use Controller() and mimic RunCmd behaviour.
- self.goutput.RunCmd(command, switchPage = True)
+ self._gconsole.RunCmd(command, switchPage = True)
def OnVarianceCBChecked(self, event):
self.OutputVarianceMapName.Enable(event.IsChecked())
Modified: grass/trunk/gui/wxpython/vdigit/preferences.py
===================================================================
--- grass/trunk/gui/wxpython/vdigit/preferences.py 2012-11-23 17:07:19 UTC (rev 53995)
+++ grass/trunk/gui/wxpython/vdigit/preferences.py 2012-11-23 18:18:26 UTC (rev 53996)
@@ -651,7 +651,7 @@
fileSettings['vdigit'] = UserSettings.Get(group = 'vdigit')
file = UserSettings.SaveToFile(fileSettings)
- self.parent.GetLayerManager().goutput.WriteLog(_('Vector digitizer settings saved to file <%s>.') % file)
+ self.parent.GetLayerManager().GetLogWindow().WriteLog(_('Vector digitizer settings saved to file <%s>.') % file)
self.Destroy()
Modified: grass/trunk/gui/wxpython/wxplot/dialogs.py
===================================================================
--- grass/trunk/gui/wxpython/wxplot/dialogs.py 2012-11-23 17:07:19 UTC (rev 53995)
+++ grass/trunk/gui/wxpython/wxplot/dialogs.py 2012-11-23 18:18:26 UTC (rev 53996)
@@ -721,7 +721,7 @@
UserSettings.ReadSettingsFile(settings = fileSettings)
fileSettings[self.plottype] = UserSettings.Get(group = self.plottype)
UserSettings.SaveToFile(fileSettings)
- self.parent.parent.GetLayerManager().goutput.WriteLog(_('Plot text sizes saved to file \'%s\'.') % UserSettings.filePath)
+ self.parent.parent.GetLayerManager().GetLogWindow().WriteLog(_('Plot text sizes saved to file \'%s\'.') % UserSettings.filePath)
self.EndModal(wx.ID_OK)
def OnApply(self, event):
@@ -1222,7 +1222,7 @@
UserSettings.ReadSettingsFile(settings = fileSettings)
fileSettings[self.plottype] = UserSettings.Get(group = self.plottype)
UserSettings.SaveToFile(fileSettings)
- self.parent.parent.GetLayerManager().goutput.WriteLog(_('Plot settings saved to file \'%s\'.') % UserSettings.filePath)
+ self.parent.parent.GetLayerManager().GetLogWindow().WriteLog(_('Plot settings saved to file \'%s\'.') % UserSettings.filePath)
self.Close()
def OnApply(self, event):
More information about the grass-commit
mailing list