[GRASS-SVN] r31197 - in grass/trunk/gui/wxpython: . gui_modules
svn_grass at osgeo.org
svn_grass at osgeo.org
Thu May 1 12:29:26 EDT 2008
Author: martinl
Date: 2008-05-01 12:29:26 -0400 (Thu, 01 May 2008)
New Revision: 31197
Modified:
grass/trunk/gui/wxpython/gui_modules/gcmd.py
grass/trunk/gui/wxpython/gui_modules/goutput.py
grass/trunk/gui/wxpython/gui_modules/menuform.py
grass/trunk/gui/wxpython/gui_modules/wxgui_utils.py
grass/trunk/gui/wxpython/wxgui.py
Log:
wxGUI: OnRun/OnAbort command-related fixes (sync'ed with develbr6)
Modified: grass/trunk/gui/wxpython/gui_modules/gcmd.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/gcmd.py 2008-05-01 16:27:05 UTC (rev 31196)
+++ grass/trunk/gui/wxpython/gui_modules/gcmd.py 2008-05-01 16:29:26 UTC (rev 31197)
@@ -494,6 +494,8 @@
self.rerr = ''
self._want_abort = False
+ self.aborted = False
+
self.startTime = None
self.setDaemon(True)
@@ -502,7 +504,7 @@
"""Run command"""
if len(self.cmd) == 0:
return
-
+
self.startTime = time.time()
# TODO: wx.Exectute/wx.Process (?)
try:
@@ -558,10 +560,11 @@
while self.module.poll() is None:
time.sleep(.1)
if self._want_abort: # abort running process
+ self.module.kill()
+ self.aborted = True
if hasattr(self.stderr, "gmstc"):
- self.module.kill()
# -> GMConsole
- wx.PostEvent(self.stderr.gmstc.parent, ResultEvent(None))
+ wx.PostEvent(self.stderr.gmstc.parent, ResultEvent(self))
return
if self.stdout:
# line = self.__read_all(self.module.stdout)
@@ -587,10 +590,7 @@
if hasattr(self.stderr, "gmstc"):
# -> GMConsole
- if self._want_abort: # abort running process
- wx.PostEvent(self.stderr.gmstc.parent, ResultEvent(None))
- else:
- wx.PostEvent(self.stderr.gmstc.parent, ResultEvent(self))
+ wx.PostEvent(self.stderr.gmstc.parent, ResultEvent(self))
def abort(self):
"""Abort running process, used by main thread to signal an abort"""
Modified: grass/trunk/gui/wxpython/gui_modules/goutput.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/goutput.py 2008-05-01 16:27:05 UTC (rev 31196)
+++ grass/trunk/gui/wxpython/gui_modules/goutput.py 2008-05-01 16:29:26 UTC (rev 31197)
@@ -35,7 +35,7 @@
Create and manage output console for commands entered on the
GIS Manager command line.
"""
- def __init__(self, parent, id=wx.ID_ANY, margin=False,
+ def __init__(self, parent, id=wx.ID_ANY, margin=False, pageid=0,
pos=wx.DefaultPosition, size=wx.DefaultSize,
style=wx.TAB_TRAVERSAL | wx.FULL_REPAINT_ON_RESIZE):
wx.Panel.__init__(self, parent, id, pos, size, style)
@@ -45,7 +45,8 @@
self.parent = parent # GMFrame
self.cmdThreads = {} # cmdThread : cmdPID
self.lineWidth = 80
-
+ self.pageid = pageid
+
# progress bar
self.console_progressbar = wx.Gauge(parent=self, id=wx.ID_ANY,
range=100, pos=(110, 50), size=(-1, 25),
@@ -60,11 +61,13 @@
### sys.stdout = self.cmd_stdout
self.cmd_stderr = GMStderr(self.cmd_output,
self.console_progressbar,
- self.parent.notebook)
+ self.parent.notebook,
+ pageid)
+
if Debug.get_level() == 0:
# don't redirect when debugging is enabled
sys.stderr = self.cmd_stderr
-
+
# buttons
self.console_clear = wx.Button(parent=self, id=wx.ID_CLEAR)
self.console_save = wx.Button(parent=self, id=wx.ID_SAVE)
@@ -194,10 +197,11 @@
lcmd=cmdlist)
else: # other GRASS commands (r|v|g|...)
- if self.parent.notebook.GetSelection() != 1:
- # select 'Command output' tab
- self.parent.notebook.SetSelection(1)
-
+ if hasattr(self.parent, "curr_page"):
+ # change notebook page only for Layer Manager
+ if self.parent.notebook.GetSelection() != 1:
+ self.parent.notebook.SetSelection(1)
+
# activate computational region (set with g.region)
# for all non-display commands.
tmpreg = os.getenv("GRASS_REGION")
@@ -224,9 +228,10 @@
else:
# Send any other command to the shell. Send output to
# console output window
- if self.parent.notebook.GetSelection() != 1:
- # select 'Command output' tab
- self.parent.notebook.SetSelection(1)
+ if hasattr(self.parent, "curr_page"):
+ # change notebook page only for Layer Manager
+ if self.parent.notebook.GetSelection() != 1:
+ self.parent.notebook.SetSelection(1)
print "$ " + ' '.join(cmdlist)
@@ -287,8 +292,10 @@
def OnResult(self, event):
"""Show result status"""
- if event.cmdThread is None:
+ if event.cmdThread.aborted:
# Thread aborted (using our convention of None return)
+ self.WriteLog(_('Please note that the data are left in incosistent stage '
+ 'and can be corrupted'), self.cmd_output.StyleWarning)
self.WriteCmdLog(_('Command aborted'),
pid=self.cmdThreads[event.cmdThread]['cmdPID'])
else:
@@ -297,8 +304,14 @@
pid=self.cmdThreads[event.cmdThread]['cmdPID'])
self.console_progressbar.SetValue(0) # reset progress bar on '0%'
- if hasattr(self.parent.parent, "btn_run"): # menuform.mainFrame
+
+ # updated command dialog
+ if hasattr(self.parent.parent, "btn_run"):
dialog = self.parent.parent
+
+ if hasattr(self.parent.parent, "btn_abort"):
+ dialog.btn_abort.Enable(False)
+
dialog.btn_run.Enable(True)
if dialog.get_dcmd is None and \
dialog.closebox.IsChecked():
@@ -342,14 +355,17 @@
Copyright: (c) 2005-2007 Jean-Michel Fauth
Licence: GPL
"""
- def __init__(self, gmstc, gmgauge, notebook):
+ def __init__(self, gmstc, gmgauge, notebook, pageid):
self.gmstc = gmstc
self.gmgauge = gmgauge
self.notebook = notebook
+ self.pageid = pageid
def write(self, s):
- if self.notebook.GetSelection() != 1: # command output
- self.notebook.SetSelection(1)
+ if self.pageid > -1:
+ # swith notebook page to 'command output'
+ if self.notebook.GetSelection() != self.pageid:
+ self.notebook.SetSelection(self.pageid)
s = s.replace('\n', os.linesep)
# remove/replace escape sequences '\b' or '\r' from stream
@@ -434,7 +450,7 @@
wx.stc.StyledTextCtrl.__init__(self, parent, id)
self.parent = parent
self.wrap = wrap
-
+
#
# styles
#
Modified: grass/trunk/gui/wxpython/gui_modules/menuform.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/menuform.py 2008-05-01 16:27:05 UTC (rev 31196)
+++ grass/trunk/gui/wxpython/gui_modules/menuform.py 2008-05-01 16:29:26 UTC (rev 31197)
@@ -643,13 +643,13 @@
self.btn_run.SetToolTipString(_("Run the command"))
self.btn_run.SetDefault()
# abort
- btn_abort = wx.Button(parent=self.panel, id=wx.ID_STOP)
- btn_abort.SetToolTipString(_("Abort the running command"))
+ self.btn_abort = wx.Button(parent=self.panel, id=wx.ID_STOP)
+ self.btn_abort.SetToolTipString(_("Abort the running command"))
# copy
btn_clipboard = wx.Button(parent=self.panel, id=wx.ID_COPY)
btn_clipboard.SetToolTipString(_("Copy the current command string to the clipboard"))
- btnsizer.Add(item=btn_abort, proportion=0,
+ btnsizer.Add(item=self.btn_abort, proportion=0,
flag=wx.ALL | wx.ALIGN_CENTER,
border=10)
@@ -662,7 +662,7 @@
border=10)
self.btn_run.Bind(wx.EVT_BUTTON, self.OnRun)
- btn_abort.Bind(wx.EVT_BUTTON, self.OnAbort)
+ self.btn_abort.Bind(wx.EVT_BUTTON, self.OnAbort)
btn_clipboard.Bind(wx.EVT_BUTTON, self.OnCopy)
guisizer.Add(item=btnsizer, proportion=0, flag=wx.ALIGN_CENTER)
@@ -741,6 +741,10 @@
if cmd == [] or cmd == None:
return
+ # change page if needed
+ if self.notebookpanel.notebook.GetSelection() != self.notebookpanel.goutput.pageid:
+ self.notebookpanel.notebook.SetSelection(self.notebookpanel.goutput.pageid)
+
if cmd[0][0:2] != "d.":
# Send any non-display command to parent window (probably wxgui.py)
# put to parents
@@ -753,13 +757,10 @@
else:
gcmd.Command(cmd)
- # if self.standalone:
- # change page if needed
- if self.notebookpanel.notebook.GetSelection() != self.notebookpanel.outpageid:
- self.notebookpanel.notebook.SetSelection(self.notebookpanel.outpageid)
+ # update buttons status
+ self.btn_run.Enable(False)
+ self.btn_abort.Enable(True)
- self.btn_run.Enable(False)
-
def OnAbort(self, event):
"""Abort running command"""
try:
@@ -767,6 +768,9 @@
except IndexError:
pass
+ self.btn_run.Enable(True)
+ self.btn_abort.Enable(False)
+
def OnCopy(self, event):
"""Copy the command"""
cmddata = wx.TextDataObject()
@@ -872,9 +876,9 @@
# are we running from command line?
### add 'command output' tab regardless standalone dialog
if self.parent.get_dcmd is None:
- self.goutput = goutput.GMConsole(parent=self, margin=False)
+ self.goutput = goutput.GMConsole(parent=self, margin=False,
+ pageid=self.notebook.GetPageCount())
self.outpage = self.notebook.AddPage(self.goutput, text=_("Command output") )
- self.outpageid = self.notebook.GetPageCount() - 1
else:
self.goutput = None
@@ -883,7 +887,7 @@
self.notebook.AddPage(self.manual_tab, text=_("Manual"))
self.manual_tab_id = self.notebook.GetPageCount() - 1
- self.notebook.SetSelection(0)
+ wx.CallAfter(self.notebook.SetSelection, 0)
panelsizer.Add(item=self.notebook, proportion=1, flag=wx.EXPAND )
#
Modified: grass/trunk/gui/wxpython/gui_modules/wxgui_utils.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/wxgui_utils.py 2008-05-01 16:27:05 UTC (rev 31196)
+++ grass/trunk/gui/wxpython/gui_modules/wxgui_utils.py 2008-05-01 16:29:26 UTC (rev 31197)
@@ -48,9 +48,6 @@
TREE_ITEM_HEIGHT = 25
-# define event for GRASS console (running GRASS command in separate thread)
-(UpdateGMConsoleEvent, EVT_UPDATE_GMCONSOLE) = wx.lib.newevent.NewEvent()
-
class LayerTree(CT.CustomTreeCtrl):
"""
Creates layer tree structure
@@ -89,7 +86,8 @@
# init associated map display
self.mapdisplay = mapdisp.MapFrame(self,
- id=wx.ID_ANY, pos=wx.DefaultPosition, size=(680, 520),
+ id=wx.ID_ANY, pos=wx.DefaultPosition,
+ size=globalvar.MAP_WINDOW_SIZE,
style=wx.DEFAULT_FRAME_STYLE,
tree=self, notebook=self.notebook,
gismgr=self.gismgr, page=self.treepg,
@@ -1097,9 +1095,6 @@
# item.SetHeight(TREE_ITEM_HEIGHT)
- def setNotebookPage(self,pg):
- self.parent.notebook.SetSelection(pg)
-
def OnCloseWindow(self, event):
pass
# self.Map.Clean()
Modified: grass/trunk/gui/wxpython/wxgui.py
===================================================================
--- grass/trunk/gui/wxpython/wxgui.py 2008-05-01 16:27:05 UTC (rev 31196)
+++ grass/trunk/gui/wxpython/wxgui.py 2008-05-01 16:29:26 UTC (rev 31197)
@@ -117,9 +117,8 @@
self.encoding = 'ISO-8859-1' # default encoding for display fonts
self.workspaceFile = workspace # workspace file
self.menucmd = {} # menuId / cmd
- self.georectifying = False # says whether we're running the georectifier
- self.gr = "" # ID of georectify instance
-
+ self.georectifying = None # reference to GCP class or None
+
# creating widgets
# -> self.notebook, self.goutput, self.outpage
self.notebook = self.__createNoteBook()
@@ -294,7 +293,7 @@
self.notebook.AddPage(self.gm_cb, text=_("Map layers for each display"))
# create command output text area and add it to main notebook page
- self.goutput = goutput.GMConsole(self)
+ self.goutput = goutput.GMConsole(self, pageid=1)
self.outpage = self.notebook.AddPage(self.goutput, text=_("Command output"))
# bingings
@@ -341,8 +340,7 @@
"""
Launch georectifier module
"""
- self.gr = georect.GeorectWizard(self)
- self.georectifying = True
+ georect.GeorectWizard(self)
def OnMapsets(self, event):
"""
@@ -1425,9 +1423,6 @@
# show map display
self.curr_page.maptree.mapdisplay.Show()
- def GetSelectedDisplay(self):
- return self.notebook.GetSelection()
-
def OnDeleteLayer(self, event):
"""
Delete selected map display layer in GIS Manager tree widget
More information about the grass-commit
mailing list