From ab901e7d4cb6e5e8b1b46dac8a7af74acf72cb8c Mon Sep 17 00:00:00 2001 From: Johnathan Corgan Date: Wed, 21 Oct 2009 17:11:03 -0700 Subject: Basic terminal window that takes raw text on input msgq and appends it Works, but needs "--line-buffered" mode for GR buffering between blocks --- gr-wxgui/src/python/term_window.py | 29 +++++++++++++++++++++++++---- gr-wxgui/src/python/termsink.py | 26 ++++++++++++++------------ grc/blocks/wxgui_termsink.xml | 25 ++++++++++++++++++++++++- 3 files changed, 63 insertions(+), 17 deletions(-) diff --git a/gr-wxgui/src/python/term_window.py b/gr-wxgui/src/python/term_window.py index 8658e54a6..77270b1f3 100644 --- a/gr-wxgui/src/python/term_window.py +++ b/gr-wxgui/src/python/term_window.py @@ -20,17 +20,27 @@ # import wx -import pubsub DEFAULT_WIN_SIZE = (600, 300) +APPEND_EVENT = wx.NewEventType() +EVT_APPEND_EVENT = wx.PyEventBinder(APPEND_EVENT, 0) -class term_window(wx.Panel, pubsub.pubsub): +class AppendEvent(wx.PyEvent): + def __init__(self, text): + wx.PyEvent.__init__(self) + self.SetEventType(APPEND_EVENT) + self.text = text + + def Clone(self): + self.__class__(self.GetId()) + + +class term_window(wx.Panel): def __init__(self, parent, size, ): - pubsub.pubsub.__init__(self) wx.Panel.__init__(self, parent, size=size, @@ -39,7 +49,7 @@ class term_window(wx.Panel, pubsub.pubsub): self.text_ctrl = wx.TextCtrl(self, wx.ID_ANY, - value="BOO", + value="", size=size, style=wx.TE_MULTILINE|wx.TE_READONLY, ) @@ -47,3 +57,14 @@ class term_window(wx.Panel, pubsub.pubsub): main_sizer = wx.BoxSizer(wx.VERTICAL) main_sizer.Add(self.text_ctrl, 1, wx.EXPAND) self.SetSizerAndFit(main_sizer) + + EVT_APPEND_EVENT(self, self.evt_append) + + def append_text(self, text): + evt = AppendEvent(text) + wx.PostEvent(self, evt) + del evt + + def evt_append(self, evt): + print "appending", len(evt.text), "bytes" + self.text_ctrl.AppendText(evt.text) diff --git a/gr-wxgui/src/python/termsink.py b/gr-wxgui/src/python/termsink.py index 2c583b115..addfa5810 100644 --- a/gr-wxgui/src/python/termsink.py +++ b/gr-wxgui/src/python/termsink.py @@ -20,22 +20,24 @@ # import term_window -import common -from gnuradio import gr +from gnuradio import gru -class termsink(gr.hier_block2, common.wxgui_hb): +class termsink(object): def __init__(self, parent, + msgq, + size=term_window.DEFAULT_WIN_SIZE, ): - - gr.hier_block2.__init__( - self, - "termsink", - gr.io_signature(0, 0, 0), - gr.io_signature(0, 0, 0), - ) - + self.win = term_window.term_window( parent=parent, - size=term_window.DEFAULT_WIN_SIZE, + size=size, ) + + self.runner = gru.msgq_runner(msgq, self.handle_msg) + + def handle_msg(self, msg): + # Just append text for now + text = msg.to_string() + print "handle_msg: received", len(text), "bytes" + self.win.append_text(text) diff --git a/grc/blocks/wxgui_termsink.xml b/grc/blocks/wxgui_termsink.xml index e1d52cd17..fce7577de 100644 --- a/grc/blocks/wxgui_termsink.xml +++ b/grc/blocks/wxgui_termsink.xml @@ -7,26 +7,49 @@ Terminal Sink wxgui_termsink + from gnuradio.wxgui import termsink + #set $parent = $notebook() and 'self.%s.GetPage(%s)'%$notebook() or 'self' termsink.termsink( - $(parent).GetWin(), + parent=$(parent).GetWin(), +#if $win_size() + size=$win_size, +#end if + msgq=$(id)_msgq, ) #if not $grid_pos() $(parent).Add(self.$(id).win) #else $(parent).GridAdd(self.$(id).win, $(', '.join(map(str, $grid_pos())))) #end if + + + Window Size + win_size + + int_vector + #if $win_size() then 'none' else 'part'# + Grid Position grid_pos grid_pos + Notebook notebook notebook + + not $win_size or len($win_size) == 2 + + + in + msg + + -- cgit