[GRASS-SVN] r53921 - in grass/trunk/gui/wxpython: core gui_core lmgr
svn_grass at osgeo.org
svn_grass at osgeo.org
Mon Nov 19 09:57:36 PST 2012
Author: wenzeslaus
Date: 2012-11-19 09:57:36 -0800 (Mon, 19 Nov 2012)
New Revision: 53921
Modified:
grass/trunk/gui/wxpython/core/events.py
grass/trunk/gui/wxpython/gui_core/goutput.py
grass/trunk/gui/wxpython/gui_core/widgets.py
grass/trunk/gui/wxpython/lmgr/frame.py
Log:
wxGUI/GConsole: new event, removing notebook dependecy and related NotebookControler changes (co-author: annakrat)
Modified: grass/trunk/gui/wxpython/core/events.py
===================================================================
--- grass/trunk/gui/wxpython/core/events.py 2012-11-19 17:23:22 UTC (rev 53920)
+++ grass/trunk/gui/wxpython/core/events.py 2012-11-19 17:57:36 UTC (rev 53921)
@@ -20,5 +20,6 @@
# Notification event intended to update statusbar.
+# The message attribute contains the text of the message (plain text)
gShowNotification, EVT_SHOW_NOTIFICATION = NewCommandEvent()
Modified: grass/trunk/gui/wxpython/gui_core/goutput.py
===================================================================
--- grass/trunk/gui/wxpython/gui_core/goutput.py 2012-11-19 17:23:22 UTC (rev 53920)
+++ grass/trunk/gui/wxpython/gui_core/goutput.py 2012-11-19 17:57:36 UTC (rev 53921)
@@ -199,12 +199,23 @@
self.requestCmd.abort()
if self.requestQ.empty():
self._want_abort_all = False
-
+
+
+# Occurs event when some new text appears.
+# Text priority is specified by priority attribute.
+# Priority is 1 (lowest), 2, 3 (highest);
+# value 0 is currently not used and probably will not be used.
+# In theory, it can be used when text is completely uninteresting.
+# It is similar to wx.EVT_TEXT.
+# However, the new text or the whole text are not event attributes.
+gOutputText, EVT_OUTPUT_TEXT = NewEvent()
+
+
class GConsole(wx.SplitterWindow):
"""!Create and manage output console for commands run by GUI.
"""
def __init__(self, parent, id = wx.ID_ANY, margin = False,
- frame = None, notebook = None,
+ frame = None,
style = wx.TAB_TRAVERSAL | wx.FULL_REPAINT_ON_RESIZE,
gcstyle = GC_EMPTY,
**kwargs):
@@ -220,11 +231,6 @@
self.frame = frame
else:
self.frame = parent
-
- if notebook:
- self._notebook = notebook
- else:
- self._notebook = self.parent.notebook
self._gcstyle = gcstyle
self.lineWidth = 80
@@ -453,8 +459,14 @@
self.cmdOutput.SetStyle()
+ # documenting old behavior/implementation:
+ # switch notebook if required
if switchPage:
- self._notebook.SetSelectionByName('output')
+ priority = 2
+ else:
+ priority = 1
+ event = gOutputText(priority = priority)
+ wx.PostEvent(self, event)
if not style:
style = self.cmdOutput.StyleDefault
@@ -622,14 +634,15 @@
except GException, e:
print >> sys.stderr, e
return
-
- # switch to 'Command output' if required
+
+ # documenting old behavior/implementation:
+ # switch and focus if required
+ # TODO: this probably should be run command event
if switchPage:
- self._notebook.SetSelectionByName('output')
-
- self.frame.SetFocus()
- self.frame.Raise()
-
+ priority = 3
+ event = gOutputText(priority = priority)
+ wx.PostEvent(self, event)
+
# activate computational region (set with g.region)
# for all non-display commands.
if compReg:
@@ -739,16 +752,14 @@
"""!Print command output"""
message = event.text
type = event.type
+
self.cmdOutput.AddStyledMessage(message, type)
- if self._notebook.GetSelection() != self._notebook.GetPageIndexByName('output'):
- page = self._notebook.GetPageIndexByName('output')
- textP = self._notebook.GetPageText(page)
- if textP[-1] != ')':
- textP += ' (...)'
- self._notebook.SetPageText(page, textP)
-
-
+ # documenting old behavior/implementation:
+ # add elipses if not active
+ event = gOutputText(priority = 1)
+ wx.PostEvent(self, event)
+
def OnCmdProgress(self, event):
"""!Update progress message info"""
self.progressbar.SetValue(event.value)
@@ -1091,6 +1102,7 @@
# remember position of line begining (used for '\r')
self.linePos = -1
+
#
# styles
#
@@ -1220,7 +1232,7 @@
# reset output window to read only
self.SetReadOnly(True)
-
+
def AddStyledMessage(self, message, style = None):
"""!Add message to text area.
Modified: grass/trunk/gui/wxpython/gui_core/widgets.py
===================================================================
--- grass/trunk/gui/wxpython/gui_core/widgets.py 2012-11-19 17:23:22 UTC (rev 53920)
+++ grass/trunk/gui/wxpython/gui_core/widgets.py 2012-11-19 17:57:36 UTC (rev 53921)
@@ -65,9 +65,15 @@
and other methods can be delegated by @c __getattr__.
"""
def __init__(self, classObject, widget):
+ """!
+ @param classObject notebook class name (object, i.e. FlatNotebook)
+ @param widget notebook instance
+ """
self.notebookPages = {}
self.classObject = classObject
self.widget = widget
+ # TODO: (...) should be only once in wxGUI
+ self.highlightedTextEnd = _(" (...)")
def AddPage(self, **kwargs):
"""!Add a new page
@@ -117,13 +123,20 @@
return False
def SetSelectionByName(self, page):
- """!Set notebook
-
- @param page names, eg. 'layers', 'output', 'search', 'pyshell', 'nviz'
+ """!Set active notebook page.
+
+ @param page name, eg. 'layers', 'output', 'search', 'pyshell', 'nviz'
+ (depends on concrete notebook instance)
"""
idx = self.GetPageIndexByName(page)
if self.classObject.GetSelection(self.widget) != idx:
self.classObject.SetSelection(self.widget, idx)
+ # FIXME: this code was not explicitly tested
+ # FIXME: remove this from function lmgr.frame.Frame.OnPageChanged
+ text = self.classObject.GetPageText(self.widget, idx)
+ if text.endswith(self.highlightedTextEnd):
+ text.replace(self.highlightedTextEnd, '')
+ self.classObject.SetPageText(self.widget, idx, text)
def GetPageIndexByName(self, page):
"""!Get notebook page index
@@ -137,6 +150,17 @@
break
return pageIndex
+ def HighlightPageByName(self, page):
+ pageIndex = self.GetPageIndexByName(page)
+ self.HighlightPage(pageIndex)
+
+ def HighlightPage(self, index):
+ if self.classObject.GetSelection(self.widget) != index:
+ text = self.classObject.GetPageText(self.widget, index)
+ if not text.endswith(self.highlightedTextEnd):
+ text += self.highlightedTextEnd
+ self.classObject.SetPageText(self.widget, index, text)
+
def SetPageImage(self, page, index):
"""!Sets image index for page
@@ -194,10 +218,6 @@
return self.controller.RemovePage(page)
def SetPageImage(self, page, index):
- """! @copydoc NotebookController::SetPageImage()"""
- return self.controller.SetPageImage(page, index)
-
- def SetPageImage(self, page, index):
"""!Does nothing because we don't want images for this style"""
pass
Modified: grass/trunk/gui/wxpython/lmgr/frame.py
===================================================================
--- grass/trunk/gui/wxpython/lmgr/frame.py 2012-11-19 17:23:22 UTC (rev 53920)
+++ grass/trunk/gui/wxpython/lmgr/frame.py 2012-11-19 17:57:36 UTC (rev 53921)
@@ -50,7 +50,7 @@
from modules.mcalc_builder import MapCalcFrame
from dbmgr.manager import AttributeManager
from core.workspace import ProcessWorkspaceFile, ProcessGrcFile, WriteWorkspaceFile
-from gui_core.goutput import GConsole, GC_SEARCH, GC_PROMPT
+from gui_core.goutput import GConsole, GC_SEARCH, GC_PROMPT, EVT_OUTPUT_TEXT
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
@@ -261,6 +261,7 @@
self.goutput = GConsole(self, frame = self,
gcstyle = GC_SEARCH | GC_PROMPT)
self.notebook.AddPage(page = self.goutput, text = _("Command console"), name = 'output')
+ self.goutput.Bind(EVT_OUTPUT_TEXT, self.OnOutputText)
self._setCopyingOfSelectedText()
# create 'search module' notebook page
@@ -523,6 +524,16 @@
event.Skip()
+ def OnOutputText(self, event):
+ """!Manages @c 'output' notebook page according to event priority."""
+ if event.priority == 1:
+ self.notebook.HighlightPageByName('output')
+ if event.priority >= 2:
+ self.notebook.SetSelectionByName('output')
+ if event.priority >= 3:
+ self.SetFocus()
+ self.Raise()
+
def GetLayerNotebook(self):
"""!Get Layers Notebook"""
return self.notebookLayers
More information about the grass-commit
mailing list