From d9744799b7df6c09180778540bf55eb9dc84281b Mon Sep 17 00:00:00 2001 From: jcorgan Date: Fri, 20 Mar 2009 02:16:20 +0000 Subject: Merged r10463:10658 from jblum/gui_guts into trunk. Trunk passes distcheck. git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@10660 221aa14e-8319-0410-a670-987f0aec2ac5 --- gr-wxgui/src/python/histo_window.py | 154 ++++++++++++++++++++++++++++++++++++ 1 file changed, 154 insertions(+) create mode 100644 gr-wxgui/src/python/histo_window.py (limited to 'gr-wxgui/src/python/histo_window.py') diff --git a/gr-wxgui/src/python/histo_window.py b/gr-wxgui/src/python/histo_window.py new file mode 100644 index 000000000..dce52ff9b --- /dev/null +++ b/gr-wxgui/src/python/histo_window.py @@ -0,0 +1,154 @@ +# +# Copyright 2009 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GNU Radio is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Radio; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# + +################################################## +# Imports +################################################## +import plotter +import common +import wx +import numpy +import math +import pubsub +from constants import * +from gnuradio import gr #for gr.prefs + +################################################## +# Constants +################################################## +DEFAULT_WIN_SIZE = (600, 300) + +################################################## +# histo window control panel +################################################## +class control_panel(wx.Panel): + """ + A control panel with wx widgits to control the plotter and histo sink. + """ + + def __init__(self, parent): + """ + Create a new control panel. + @param parent the wx parent window + """ + self.parent = parent + wx.Panel.__init__(self, parent, style=wx.SUNKEN_BORDER) + control_box = wx.BoxSizer(wx.VERTICAL) + SIZE = (100, -1) + control_box.Add(common.LabelText(self, 'Options'), 0, wx.ALIGN_CENTER) + control_box.AddStretchSpacer() + #num bins + def num_bins_cast(num): + num = int(num) + assert num > 1 + return num + num_bins_ctrl = common.TextBoxController(self, parent, NUM_BINS_KEY, cast=num_bins_cast) + control_box.Add(common.LabelBox(self, ' Num Bins ', num_bins_ctrl), 0, wx.EXPAND) + control_box.AddStretchSpacer() + #frame size + frame_size_ctrl = common.TextBoxController(self, parent, FRAME_SIZE_KEY, cast=num_bins_cast) + control_box.Add(common.LabelBox(self, ' Frame Size ', frame_size_ctrl), 0, wx.EXPAND) + control_box.AddStretchSpacer() + #run/stop + self.run_button = common.ToggleButtonController(self, parent, RUNNING_KEY, 'Stop', 'Run') + control_box.Add(self.run_button, 0, wx.EXPAND) + #set sizer + self.SetSizerAndFit(control_box) + +################################################## +# histo window with plotter and control panel +################################################## +class histo_window(wx.Panel, pubsub.pubsub): + def __init__( + self, + parent, + controller, + size, + title, + maximum_key, + minimum_key, + num_bins_key, + frame_size_key, + msg_key, + ): + pubsub.pubsub.__init__(self) + #setup + self.samples = list() + #proxy the keys + self.proxy(MAXIMUM_KEY, controller, maximum_key) + self.proxy(MINIMUM_KEY, controller, minimum_key) + self.proxy(NUM_BINS_KEY, controller, num_bins_key) + self.proxy(FRAME_SIZE_KEY, controller, frame_size_key) + self.proxy(MSG_KEY, controller, msg_key) + #init panel and plot + wx.Panel.__init__(self, parent, style=wx.SIMPLE_BORDER) + self.plotter = plotter.bar_plotter(self) + self.plotter.SetSize(wx.Size(*size)) + self.plotter.set_title(title) + self.plotter.enable_point_label(True) + self.plotter.enable_grid_lines(False) + #setup the box with plot and controls + self.control_panel = control_panel(self) + main_box = wx.BoxSizer(wx.HORIZONTAL) + main_box.Add(self.plotter, 1, wx.EXPAND) + main_box.Add(self.control_panel, 0, wx.EXPAND) + self.SetSizerAndFit(main_box) + #initialize values + self[NUM_BINS_KEY] = self[NUM_BINS_KEY] + self[FRAME_SIZE_KEY] = self[FRAME_SIZE_KEY] + self[RUNNING_KEY] = True + self[X_DIVS_KEY] = 8 + self[Y_DIVS_KEY] = 4 + #register events + self.subscribe(MSG_KEY, self.handle_msg) + self.subscribe(X_DIVS_KEY, self.update_grid) + self.subscribe(Y_DIVS_KEY, self.update_grid) + + def handle_msg(self, msg): + """ + Handle the message from the fft sink message queue. + @param msg the frame as a character array + """ + if not self[RUNNING_KEY]: return + #convert to floating point numbers + self.samples = 100*numpy.fromstring(msg, numpy.float32)[:self[NUM_BINS_KEY]] #only take first frame + self.plotter.set_bars( + bars=self.samples, + bar_width=0.6, + color_spec=(0, 0, 1), + ) + self.update_grid() + + def update_grid(self): + if not len(self.samples): return + #calculate the maximum y value + y_off = math.ceil(numpy.max(self.samples)) + y_off = min(max(y_off, 1.0), 100.0) #between 1% and 100% + #update the x grid + self.plotter.set_x_grid( + self[MINIMUM_KEY], self[MAXIMUM_KEY], + common.get_clean_num((self[MAXIMUM_KEY] - self[MINIMUM_KEY])/self[X_DIVS_KEY]), + ) + self.plotter.set_x_label('Counts') + #update the y grid + self.plotter.set_y_grid(0, y_off, y_off/self[Y_DIVS_KEY]) + self.plotter.set_y_label('Frequency', '%') + self.plotter.update() -- cgit From 51af4269d3eebd3d611be918f8c799c96c650496 Mon Sep 17 00:00:00 2001 From: jblum Date: Sat, 13 Jun 2009 21:26:25 +0000 Subject: Merged wxgui/forms branch r11124:11183 The forms module is set of wxgui forms wrapped in pubsub aware convenience classes. The forms module will be used by the wxgui window classes (fft, scope, waterfall...) The forms module will be used in grc generated flowgraphs. The forms module will be used by future gui apps (usrp siggen...). Tasks: Moved forms module into wxgui. Modified *_window classes to use the forms module. Added features to forms as required. Removed pubsub aware forms in common.py. Switched grc to use the forms module in wxgui. git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@11184 221aa14e-8319-0410-a670-987f0aec2ac5 --- gr-wxgui/src/python/histo_window.py | 43 +++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 18 deletions(-) (limited to 'gr-wxgui/src/python/histo_window.py') diff --git a/gr-wxgui/src/python/histo_window.py b/gr-wxgui/src/python/histo_window.py index dce52ff9b..5f434d70e 100644 --- a/gr-wxgui/src/python/histo_window.py +++ b/gr-wxgui/src/python/histo_window.py @@ -30,6 +30,7 @@ import math import pubsub from constants import * from gnuradio import gr #for gr.prefs +import forms ################################################## # Constants @@ -53,23 +54,31 @@ class control_panel(wx.Panel): wx.Panel.__init__(self, parent, style=wx.SUNKEN_BORDER) control_box = wx.BoxSizer(wx.VERTICAL) SIZE = (100, -1) - control_box.Add(common.LabelText(self, 'Options'), 0, wx.ALIGN_CENTER) - control_box.AddStretchSpacer() + control_box = forms.static_box_sizer( + parent=self, label='Options', + bold=True, orient=wx.VERTICAL, + ) #num bins - def num_bins_cast(num): - num = int(num) - assert num > 1 - return num - num_bins_ctrl = common.TextBoxController(self, parent, NUM_BINS_KEY, cast=num_bins_cast) - control_box.Add(common.LabelBox(self, ' Num Bins ', num_bins_ctrl), 0, wx.EXPAND) control_box.AddStretchSpacer() + forms.text_box( + sizer=control_box, parent=self, label='Num Bins', + converter=forms.int_converter(), + ps=parent, key=NUM_BINS_KEY, + ) #frame size - frame_size_ctrl = common.TextBoxController(self, parent, FRAME_SIZE_KEY, cast=num_bins_cast) - control_box.Add(common.LabelBox(self, ' Frame Size ', frame_size_ctrl), 0, wx.EXPAND) control_box.AddStretchSpacer() + forms.text_box( + sizer=control_box, parent=self, label='Frame Size', + converter=forms.int_converter(), + ps=parent, key=FRAME_SIZE_KEY, + ) #run/stop - self.run_button = common.ToggleButtonController(self, parent, RUNNING_KEY, 'Stop', 'Run') - control_box.Add(self.run_button, 0, wx.EXPAND) + control_box.AddStretchSpacer() + forms.toggle_button( + sizer=control_box, parent=self, + true_label='Stop', false_label='Run', + ps=parent, key=RUNNING_KEY, + ) #set sizer self.SetSizerAndFit(control_box) @@ -98,6 +107,10 @@ class histo_window(wx.Panel, pubsub.pubsub): self.proxy(NUM_BINS_KEY, controller, num_bins_key) self.proxy(FRAME_SIZE_KEY, controller, frame_size_key) self.proxy(MSG_KEY, controller, msg_key) + #initialize values + self[RUNNING_KEY] = True + self[X_DIVS_KEY] = 8 + self[Y_DIVS_KEY] = 4 #init panel and plot wx.Panel.__init__(self, parent, style=wx.SIMPLE_BORDER) self.plotter = plotter.bar_plotter(self) @@ -111,12 +124,6 @@ class histo_window(wx.Panel, pubsub.pubsub): main_box.Add(self.plotter, 1, wx.EXPAND) main_box.Add(self.control_panel, 0, wx.EXPAND) self.SetSizerAndFit(main_box) - #initialize values - self[NUM_BINS_KEY] = self[NUM_BINS_KEY] - self[FRAME_SIZE_KEY] = self[FRAME_SIZE_KEY] - self[RUNNING_KEY] = True - self[X_DIVS_KEY] = 8 - self[Y_DIVS_KEY] = 4 #register events self.subscribe(MSG_KEY, self.handle_msg) self.subscribe(X_DIVS_KEY, self.update_grid) -- cgit From a154cc5c12ccf65b480ae86e0c984c4a66ad69a3 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Fri, 9 Oct 2009 13:41:15 -0700 Subject: registered key to hide/show control panel in wxgui windows --- gr-wxgui/src/python/histo_window.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'gr-wxgui/src/python/histo_window.py') diff --git a/gr-wxgui/src/python/histo_window.py b/gr-wxgui/src/python/histo_window.py index 5f434d70e..a1b520f9c 100644 --- a/gr-wxgui/src/python/histo_window.py +++ b/gr-wxgui/src/python/histo_window.py @@ -52,6 +52,8 @@ class control_panel(wx.Panel): """ self.parent = parent wx.Panel.__init__(self, parent, style=wx.SUNKEN_BORDER) + parent[SHOW_CONTROL_PANEL_KEY] = True + parent.subscribe(SHOW_CONTROL_PANEL_KEY, self.Show) control_box = wx.BoxSizer(wx.VERTICAL) SIZE = (100, -1) control_box = forms.static_box_sizer( -- cgit From 5f0aaf3d5397675d6f87acd7ab20526ac1fb0d4e Mon Sep 17 00:00:00 2001 From: Balint Seeber Date: Thu, 11 Apr 2013 19:49:46 -0700 Subject: wxgui: Fixes to solve issues using GL sinks on OS X plotter/plotter_base.py: Create explicit OpenGL context, check if window is shown before realising context & only create PaintDC is paint triggered by WM message (OS paint event) Added SetSizeHints to WX sink windows so sizing occurs correctly --- gr-wxgui/src/python/histo_window.py | 1 + 1 file changed, 1 insertion(+) (limited to 'gr-wxgui/src/python/histo_window.py') diff --git a/gr-wxgui/src/python/histo_window.py b/gr-wxgui/src/python/histo_window.py index a1b520f9c..e87e97825 100644 --- a/gr-wxgui/src/python/histo_window.py +++ b/gr-wxgui/src/python/histo_window.py @@ -117,6 +117,7 @@ class histo_window(wx.Panel, pubsub.pubsub): wx.Panel.__init__(self, parent, style=wx.SIMPLE_BORDER) self.plotter = plotter.bar_plotter(self) self.plotter.SetSize(wx.Size(*size)) + self.plotter.SetSizeHints(*size) self.plotter.set_title(title) self.plotter.enable_point_label(True) self.plotter.enable_grid_lines(False) -- cgit