[GRASS-SVN] r58038 - in grass/trunk/gui/wxpython: gui_core mapdisp
svn_grass at osgeo.org
svn_grass at osgeo.org
Thu Oct 17 21:38:35 PDT 2013
Author: annakrat
Date: 2013-10-17 21:38:35 -0700 (Thu, 17 Oct 2013)
New Revision: 58038
Modified:
grass/trunk/gui/wxpython/gui_core/query.py
grass/trunk/gui/wxpython/mapdisp/frame.py
Log:
wxGUI/querying: enable to redirect output to console
Modified: grass/trunk/gui/wxpython/gui_core/query.py
===================================================================
--- grass/trunk/gui/wxpython/gui_core/query.py 2013-10-18 04:07:54 UTC (rev 58037)
+++ grass/trunk/gui/wxpython/gui_core/query.py 2013-10-18 04:38:35 UTC (rev 58038)
@@ -26,12 +26,17 @@
from gui_core.treeview import TreeListView
from core.treemodel import TreeModel, DictNode
+from grass.pydispatch.signal import Signal
+
class QueryDialog(wx.Dialog):
def __init__(self, parent, data = None):
wx.Dialog.__init__(self, parent, id = wx.ID_ANY,
title = _("Query results"),
size = (420, 400),
style = wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER)
+ # send query output to console
+ self.redirectOutput = Signal('QueryDialog.redirectOutput')
+
self.data = data
self.panel = wx.Panel(self, id = wx.ID_ANY)
@@ -61,13 +66,17 @@
copy = wx.Button(self.panel, id = wx.ID_ANY, label = _("Copy all to clipboard"))
copy.Bind(wx.EVT_BUTTON, self.Copy)
self.Bind(wx.EVT_CLOSE, self.OnClose)
+ self.redirect = wx.CheckBox(self.panel, label=_("Redirect to console"))
+ self.redirect.SetValue(False)
+ self.redirect.Bind(wx.EVT_CHECKBOX, lambda evt: self._onRedirect(evt.IsChecked()))
hbox = wx.BoxSizer(wx.HORIZONTAL)
+ hbox.Add(item=self.redirect, proportion=0, flag=wx.EXPAND | wx.RIGHT, border=5)
hbox.AddStretchSpacer(1)
- hbox.Add(item = copy, proportion = 0, flag = wx.EXPAND | wx.RIGHT, border = 5)
- hbox.Add(item = close, proportion = 0, flag = wx.EXPAND | wx.ALL, border = 0)
+ hbox.Add(item=copy, proportion=0, flag=wx.EXPAND | wx.RIGHT, border=5)
+ hbox.Add(item=close, proportion=0, flag=wx.EXPAND | wx.ALL, border=0)
- self.mainSizer.Add(item = hbox, proportion = 0, flag = wx.EXPAND | wx.ALL, border = 5)
+ self.mainSizer.Add(item=hbox, proportion=0, flag=wx.EXPAND | wx.ALL, border=5)
self.panel.SetSizer(self.mainSizer)
self.mainSizer.Fit(self.panel)
# for Windows
@@ -80,6 +89,9 @@
self.tree.SetModel(self._model)
self.tree.SetExpansionState(state)
+ if self.redirect.IsChecked():
+ self.redirectOutput.emit(output=self._textToRedirect())
+
def Copy(self, event):
text = printResults(self._model, self._colNames[1])
self._copyText(text)
@@ -127,6 +139,22 @@
for id in ids:
self.Unbind(wx.EVT_MENU, id=id)
+ def _onRedirect(self, redirect):
+ """!Emits instructions to redirect query results.
+
+ @param redirect True to start redirecting, False to stop
+ """
+ if redirect:
+ self.redirectOutput.emit(output=_("Query results:"), style='cmd')
+ self.redirectOutput.emit(output=self._textToRedirect())
+ else:
+ self.redirectOutput.emit(output=_(" "), style='cmd')
+
+ def _textToRedirect(self):
+ text = printResults(self._model, self._colNames[1])
+ text += '\n' + "-"* 50 + '\n'
+ return text
+
def _cutLabel(self, label):
limit = 15
if len(label) > limit:
@@ -143,6 +171,8 @@
wx.TheClipboard.Close()
def OnClose(self, event):
+ if self.redirect.IsChecked():
+ self._onRedirect(False)
self.Destroy()
event.Skip()
@@ -178,7 +208,8 @@
@param valueCol column name with value to be printed
"""
def printTree(node, textList, valueCol, indent=0):
- textList.append(indent*' ' + node.label + ': ' + node.data.get(valueCol, ''))
+ if node.data.get(valueCol, '') or node.children:
+ textList.append(indent*' ' + node.label + ': ' + node.data.get(valueCol, ''))
for child in node.children:
printTree(node=child, textList=textList, valueCol=valueCol, indent=indent + 2)
@@ -194,8 +225,7 @@
Adds coordinates, improves vector results tree structure.
"""
data = []
- data.append({_("east"): coordinates[0]})
- data.append({_("north"): coordinates[1]})
+ data.append({_("east, north"): ", ".join(map(str, coordinates))})
for part in result:
if 'Map' in part:
itemText = part['Map']
Modified: grass/trunk/gui/wxpython/mapdisp/frame.py
===================================================================
--- grass/trunk/gui/wxpython/mapdisp/frame.py 2013-10-18 04:07:54 UTC (rev 58037)
+++ grass/trunk/gui/wxpython/mapdisp/frame.py 2013-10-18 04:38:35 UTC (rev 58038)
@@ -726,12 +726,21 @@
else:
self.dialogs['query'] = QueryDialog(parent = self, data = result)
self.dialogs['query'].Bind(wx.EVT_CLOSE, self._oncloseQueryDialog)
+ self.dialogs['query'].redirectOutput.connect(self._onRedirectQueryOutput)
self.dialogs['query'].Show()
def _oncloseQueryDialog(self, event):
self.dialogs['query'] = None
event.Skip()
+ def _onRedirectQueryOutput(self, output, style='log'):
+ """!Writes query output into console"""
+ # TODO: fix switching tab
+ if style == 'log':
+ self._giface.WriteLog(output)
+ elif style == 'cmd':
+ self._giface.WriteCmdLog(output)
+
def _queryHighlight(self, vectQuery):
"""!Highlight category from query."""
cats = name = None
More information about the grass-commit
mailing list