# pos=wx.Point(0, 0),\r
# size=wx.Size(150, 90),\r
# style=wx.NO_BORDER|wx.TE_MULTILINE), 'right'),\r
-# ('output', wx.TextCtrl(\r
-# parent=self,\r
-# pos=wx.Point(0, 0),\r
-# size=wx.Size(150, 90),\r
-# style=wx.NO_BORDER|wx.TE_MULTILINE), 'bottom'),\r
+ ('output', panel.PANELS['output'](\r
+ buffer_lines=5,\r
+ parent=self,\r
+ pos=wx.Point(0, 0),\r
+ size=wx.Size(150, 90),\r
+ style=wx.TE_READONLY|wx.NO_BORDER|wx.TE_MULTILINE),\r
+ 'bottom'),\r
# ('results', panel.results.Results(self), 'bottom'),\r
]:\r
self._add_panel(label, p, style)\r
self.Destroy()\r
\r
\r
+\r
# Command handling\r
\r
def _command_by_name(self, name):\r
while True:\r
msg = self.outqueue.get()\r
results.append(msg)\r
- print type(msg), msg\r
if isinstance(msg, Exit):\r
self._on_close()\r
break\r
h.run(self, msg) # TODO: pause for response?\r
continue\r
pp = getattr(\r
- self, '_postprocess_%s' % command.name.replace(' ', '_'), None)\r
- if pp != None:\r
- pp(command=command, results=results)\r
+ self, '_postprocess_%s' % command.name.replace(' ', '_'),\r
+ self._postprocess_text)\r
+ pp(command=command, results=results)\r
return results\r
\r
def _handle_request(self, msg):\r
\r
# Command-specific postprocessing\r
\r
+ def _postprocess_text(self, command, results):\r
+ """Print the string representation of the results to the Results window.\r
+\r
+ This is similar to :class:`~hooke.ui.commandline.DoCommand`'s\r
+ approach, except that :class:`~hooke.ui.commandline.DoCommand`\r
+ doesn't print some internally handled messages\r
+ (e.g. :class:`~hooke.interaction.ReloadUserInterfaceConfig`).\r
+ """\r
+ for result in results:\r
+ if isinstance(result, CommandExit):\r
+ self._c['output'].write(result.__class__.__name__+'\n')\r
+ self._c['output'].write(str(result).rstrip()+'\n')\r
+\r
def _postprocess_get_curve(self, command, results):\r
"""Update `self` to show the curve.\r
"""\r
playlist.reset()\r
self.AddTayliss(playlist)\r
\r
- def AppendToOutput(self, text):\r
- self.panelOutput.AppendText(''.join([text, '\n']))\r
-\r
def AppliesPlotmanipulator(self, name):\r
'''\r
Returns True if the plotmanipulator 'name' is applied, False otherwise\r
--- /dev/null
+# Copyright
+
+"""Scrolling text buffer panel for Hooke.
+"""
+
+import wx
+
+from . import Panel
+
+
+class OutputPanel (Panel, wx.TextCtrl):
+ """Scrolling text buffer panel.
+ """
+ def __init__(self, name=None, callbacks=None, buffer_lines=1000, **kwargs):
+ self._buffer_lines = buffer_lines
+ if (kwargs.get('style') & wx.TE_READONLY == 0):
+ raise NotImplementedError('%s assumes a readonly TextCtrl'
+ % self.__class__.__name__)
+ super(OutputPanel, self).__init__(
+ name='output', callbacks=callbacks, **kwargs)
+
+ def write(self, text):
+ self.AppendText(text)
+ self._limit_to_buffer()
+
+ def _limit_to_buffer(self):
+ """Limit number of lines retained in the buffer to `._buffer_lines`.
+ """
+ num_lines = self.GetNumberOfLines()
+ line_index = num_lines - self._buffer_lines
+ if line_index > 0:
+ first_pos = 0 # character index for the first character to keep
+ for i in range(line_index):
+ first_pos += self.GetLineLength(i) + 1 # +1 for '\n'
+ self.Remove(0, first_pos)
+
+