[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] r9203 - in gnuradio/branches/features/experimental-gui
From: |
jblum |
Subject: |
[Commit-gnuradio] r9203 - in gnuradio/branches/features/experimental-gui: . plotter |
Date: |
Thu, 7 Aug 2008 13:51:50 -0600 (MDT) |
Author: jblum
Date: 2008-08-07 13:51:49 -0600 (Thu, 07 Aug 2008)
New Revision: 9203
Modified:
gnuradio/branches/features/experimental-gui/const_window.py
gnuradio/branches/features/experimental-gui/fft_window.py
gnuradio/branches/features/experimental-gui/plotter/channel_plotter.py
gnuradio/branches/features/experimental-gui/plotter/plotter_base.py
gnuradio/branches/features/experimental-gui/plotter/waterfall_plotter.py
gnuradio/branches/features/experimental-gui/scope_window.py
gnuradio/branches/features/experimental-gui/waterfall_window.py
Log:
pointer label
Modified: gnuradio/branches/features/experimental-gui/const_window.py
===================================================================
--- gnuradio/branches/features/experimental-gui/const_window.py 2008-08-07
17:46:33 UTC (rev 9202)
+++ gnuradio/branches/features/experimental-gui/const_window.py 2008-08-07
19:51:49 UTC (rev 9203)
@@ -122,8 +122,8 @@
self.plotter = plotter.channel_plotter(self)
self.plotter.SetSize(wx.Size(*size))
self.plotter.set_title(title)
- self.plotter.set_x_units('Inphase')
- self.plotter.set_y_units('Quadrature')
+ self.plotter.set_x_label('Inphase')
+ self.plotter.set_y_label('Quadrature')
#setup the box with plot and controls
self.control_panel = control_panel(self)
main_box = wx.BoxSizer(wx.HORIZONTAL)
Modified: gnuradio/branches/features/experimental-gui/fft_window.py
===================================================================
--- gnuradio/branches/features/experimental-gui/fft_window.py 2008-08-07
17:46:33 UTC (rev 9202)
+++ gnuradio/branches/features/experimental-gui/fft_window.py 2008-08-07
19:51:49 UTC (rev 9203)
@@ -205,13 +205,13 @@
else: self.peak_vals = NO_PEAK_VALS
#plot the fft
self.plotter.set_waveform(
- channel=1,
+ channel='FFT',
samples=samples,
color_spec=FFT_PLOT_COLOR_SPEC,
)
#plot the peak hold
self.plotter.set_waveform(
- channel=2,
+ channel='Peak',
samples=self.peak_vals,
color_spec=PEAK_VALS_COLOR_SPEC,
)
@@ -257,10 +257,10 @@
scalar*x_per_div,
)
#update x units
- self.plotter.set_x_units('Frequency (%s)'%x_units)
+ self.plotter.set_x_label('Frequency', x_units)
#update y grid
self.plotter.set_y_grid(ref_level-y_per_div*y_divs, ref_level,
y_per_div)
#update y units
- self.plotter.set_y_units('Amplitude (dB)')
+ self.plotter.set_y_label('Amplitude', 'dB')
#update plotter
self.plotter.update()
Modified: gnuradio/branches/features/experimental-gui/plotter/channel_plotter.py
===================================================================
--- gnuradio/branches/features/experimental-gui/plotter/channel_plotter.py
2008-08-07 17:46:33 UTC (rev 9202)
+++ gnuradio/branches/features/experimental-gui/plotter/channel_plotter.py
2008-08-07 19:51:49 UTC (rev 9203)
@@ -25,6 +25,9 @@
import numpy
import gltext
+POINT_LABEL_FONT_SIZE = 8
+POINT_LABEL_COLOR_SPEC = (1, 1, .5)
+POINT_LABEL_PADDING = 3
LEGEND_TEXT_FONT_SIZE = 8
LEGEND_BOX_WIDTH, LEGEND_BOX_HEIGHT = 26, 20
PADDING = 35, 15, 40, 60 #top, right, bottom, left
@@ -41,8 +44,30 @@
#init
grid_plotter_base.__init__(self, parent, PADDING)
self.channels = dict()
- self.set_legend(False)
+ self.enable_legend(False)
+ self.enable_point_label(True)
+ self._mouse_coordinate = None
+ self.Bind(wx.EVT_MOTION, self._on_motion)
+ self.Bind(wx.EVT_LEAVE_WINDOW, self._on_leave_window)
+ def _on_motion(self, event):
+ """!
+ Mouse motion, record the position X, Y.
+ """
+ self.lock()
+ self._mouse_coordinate = event.GetPosition()
+ self.update()
+ self.unlock()
+
+ def _on_leave_window(self, event):
+ """!
+ Mouse leave window, set the position to None.
+ """
+ self.lock()
+ self._mouse_coordinate = None
+ self.update()
+ self.unlock()
+
def _gl_init(self):
"""!
Run gl initialization tasks.
@@ -50,21 +75,35 @@
glEnableClientState(GL_VERTEX_ARRAY)
self._grid_compiled_list_id = glGenLists(1)
- def set_legend(self, legend):
+ def enable_legend(self, enable=None):
"""!
- Set the legend on/off.
- @param legend true to turn on
+ Enable/disable the legend.
+ @param enable true to enable
+ @return the enable state when None
"""
- self.semaphore.acquire(True)
- self.legend = legend
+ if enable is None: return self._enable_legend
+ self.lock()
+ self._enable_legend = enable
self.changed(True)
- self.semaphore.release()
+ self.unlock()
+ def enable_point_label(self, enable=None):
+ """!
+ Enable/disable the point label.
+ @param enable true to enable
+ @return the enable state when None
+ """
+ if enable is None: return self._enable_point_label
+ self.lock()
+ self._enable_point_label = enable
+ self.changed(True)
+ self.unlock()
+
def draw(self):
"""!
Draw the grid and waveforms.
"""
- self.semaphore.acquire(True)
+ self.lock()
self.clear()
#store the grid drawing operations
if self.changed():
@@ -86,18 +125,16 @@
#draw the waveforms
self._draw_waveforms()
glDisable(GL_SCISSOR_TEST)
+ self._draw_point_label()
#swap buffer into display
self.SwapBuffers()
- self.semaphore.release()
+ self.unlock()
def _draw_waveforms(self):
"""!
Draw the waveforms for each channel.
- Scale the waveform data to the grid using numpy (saves CPU).
+ Scale the waveform data to the grid using gl matrix operations.
"""
- ##################################################
- # Draw Waveforms
- ##################################################
for channel in reversed(sorted(self.channels.keys())):
samples, color_spec, marker = self.channels[channel]
num_samps = len(samples)
@@ -125,25 +162,54 @@
glDrawArrays(marker is None and GL_LINE_STRIP or
GL_POINTS, 0, len(points))
glPopMatrix()
+ def _draw_point_label(self):
+ """!
+ Draw the point label for the last mouse motion coordinate.
+ The mouse coordinate must be an X, Y tuple.
+ The label will be drawn at the X, Y coordinate.
+ The values of the X, Y coordinate will be scaled to the current
X, Y bounds.
+ """
+ if not self.enable_point_label(): return
+ if not self._mouse_coordinate: return
+ x, y = self._mouse_coordinate
+ if x < self.padding_left or x > self.width-self.padding_right:
return
+ if y < self.padding_top or y > self.height-self.padding_bottom:
return
+ #scale to window bounds
+ x_scalar = float(x -
self.padding_left)/(self.width-self.padding_left-self.padding_right)
+ y_scalar = float((self.height - y) -
self.padding_bottom)/(self.height-self.padding_top-self.padding_bottom)
+ #scale to grid bounds
+ x_val = x_scalar*(self.x_max-self.x_min) + self.x_min
+ y_val = y_scalar*(self.y_max-self.y_min) + self.y_min
+ #create text
+ label_str = "%s: %g %s\n%s: %g %s"%(self.x_label, x_val,
self.x_units, self.y_label, y_val, self.y_units)
+ txt = gltext.Text(label_str, font_size=POINT_LABEL_FONT_SIZE)
+ w, h = txt._aloc_text._text_size #FIXME
+ #draw rect + text
+ glColor3f(*POINT_LABEL_COLOR_SPEC)
+ self._draw_rect(x, y-h-2*POINT_LABEL_PADDING,
w+2*POINT_LABEL_PADDING, h+2*POINT_LABEL_PADDING)
+ txt.draw_text(wx.Point(x+POINT_LABEL_PADDING,
y-h-POINT_LABEL_PADDING))
+
def _draw_legend(self):
- ##################################################
- # Draw Legend
- ##################################################
- if self.legend:
- for i, channel in
enumerate(sorted(self.channels.keys())):
- x_off =
1.1*LEGEND_BOX_WIDTH*(len(self.channels) - i - 1) + LEGEND_BOX_WIDTH/2
- color_spec = self.channels[channel][1]
- #draw colored rectangle
- glColor3f(*color_spec)
- self._draw_rect(
- self.width - self.padding_right - x_off
- LEGEND_BOX_WIDTH/2,
-
(self.padding_top-LEGEND_BOX_HEIGHT)/2.0,
- LEGEND_BOX_WIDTH,
- LEGEND_BOX_HEIGHT,
- )
- #draw label text
- txt = gltext.Text('Ch%s'%channel,
font_size=LEGEND_TEXT_FONT_SIZE, centered=True)
- txt.draw_text(wx.Point(self.width -
self.padding_right - x_off, self.padding_top/2.0))
+ """!
+ Draw the legend in the upper right corner.
+ For each channel, draw a rectangle out of the channel color,
+ and overlay the channel text on top of the rectangle.
+ """
+ if not self.enable_legend(): return
+ for i, channel in enumerate(sorted(self.channels.keys())):
+ x_off = 1.1*LEGEND_BOX_WIDTH*(len(self.channels) - i -
1) + LEGEND_BOX_WIDTH/2
+ color_spec = self.channels[channel][1]
+ #draw colored rectangle
+ glColor3f(*color_spec)
+ self._draw_rect(
+ self.width - self.padding_right - x_off -
LEGEND_BOX_WIDTH/2,
+ (self.padding_top-LEGEND_BOX_HEIGHT)/2.0,
+ LEGEND_BOX_WIDTH,
+ LEGEND_BOX_HEIGHT,
+ )
+ #draw label text
+ txt = gltext.Text('Ch%s'%channel,
font_size=LEGEND_TEXT_FONT_SIZE, centered=True)
+ txt.draw_text(wx.Point(self.width - self.padding_right
- x_off, self.padding_top/2.0))
def set_waveform(self, channel, samples, color_spec, marker=None):
"""!
@@ -153,7 +219,9 @@
@param color_spec the 3-tuple for line color
@param marker None for line
"""
+ self.lock()
self.channels[channel] = samples, color_spec, marker
+ self.unlock()
if __name__ == '__main__':
app = wx.PySimpleApp()
Modified: gnuradio/branches/features/experimental-gui/plotter/plotter_base.py
===================================================================
--- gnuradio/branches/features/experimental-gui/plotter/plotter_base.py
2008-08-07 17:46:33 UTC (rev 9202)
+++ gnuradio/branches/features/experimental-gui/plotter/plotter_base.py
2008-08-07 19:51:49 UTC (rev 9203)
@@ -46,14 +46,17 @@
Initialize GL and register events.
@param parent the parent widgit
"""
- self.semaphore = threading.Semaphore(1)
+ self._semaphore = threading.Semaphore(1)
wx.glcanvas.GLCanvas.__init__(self, parent, -1)
self.changed(False)
self._gl_init_flag = False
self._resized_flag = True
- wx.EVT_PAINT(self, self._on_paint)
- wx.EVT_SIZE(self, self._on_size)
+ self.Bind(wx.EVT_PAINT, self._on_paint)
+ self.Bind(wx.EVT_SIZE, self._on_size)
+ def lock(self): self._semaphore.acquire(True)
+ def unlock(self): self._semaphore.release()
+
def _on_size(self, event):
"""!
Flag the resize event.
@@ -74,7 +77,7 @@
self._gl_init_flag = True
#check for a change in window size
if self._resized_flag:
- self.semaphore.acquire(True)
+ self.lock()
self.width, self.height = self.GetSize()
glViewport(0, 0, self.width, self.height)
glMatrixMode(GL_PROJECTION)
@@ -85,7 +88,7 @@
glViewport(0, 0, self.width, self.height)
self._resized_flag = False
self.changed(True)
- self.semaphore.release()
+ self.unlock()
self.draw()
def update(self): wx.PostEvent(self, wx.PaintEvent())
@@ -110,8 +113,8 @@
self.padding_top, self.padding_right, self.padding_bottom,
self.padding_left = padding
#store title and unit strings
self.set_title('Title')
- self.set_x_units('X Units (xx)')
- self.set_y_units('Y Units (yy)')
+ self.set_x_label('X Label')
+ self.set_y_label('Y Label')
#init the grid to some value
self.set_x_grid(-1, 1, 1)
self.set_y_grid(-1, 1, 1)
@@ -121,30 +124,34 @@
Set the title.
@param title the title string
"""
- self.semaphore.acquire(True)
+ self.lock()
self.title = title
self.changed(True)
- self.semaphore.release()
+ self.unlock()
- def set_x_units(self, x_units):
+ def set_x_label(self, x_label, x_units=''):
"""!
- Set the x_units.
- @param x_units the x_units string
+ Set the x label and units.
+ @param x_label the x label string
+ @param x_units the x units string
"""
- self.semaphore.acquire(True)
+ self.lock()
+ self.x_label = x_label
self.x_units = x_units
self.changed(True)
- self.semaphore.release()
+ self.unlock()
- def set_y_units(self, y_units):
+ def set_y_label(self, y_label, y_units=''):
"""!
- Set the y_units.
- @param y_units the y_units string
+ Set the y label and units.
+ @param y_label the y label string
+ @param y_units the y units string
"""
- self.semaphore.acquire(True)
+ self.lock()
+ self.y_label = y_label
self.y_units = y_units
self.changed(True)
- self.semaphore.release()
+ self.unlock()
def set_x_grid(self, x_min, x_max, x_step):
"""!
@@ -153,12 +160,12 @@
@param x_max the right-most value
@param x_step the grid spacing
"""
- self.semaphore.acquire(True)
+ self.lock()
self.x_min = float(x_min)
self.x_max = float(x_max)
self.x_step = float(x_step)
self.changed(True)
- self.semaphore.release()
+ self.unlock()
def set_y_grid(self, y_min, y_max, y_step):
"""!
@@ -167,12 +174,12 @@
@param y_max the top-most value
@param y_step the grid spacing
"""
- self.semaphore.acquire(True)
+ self.lock()
self.y_min = float(y_min)
self.y_max = float(y_max)
self.y_step = float(y_step)
self.changed(True)
- self.semaphore.release()
+ self.unlock()
def _draw_grid(self):
"""!
@@ -221,19 +228,21 @@
txt = gltext.Text(self.title, font=font,
font_size=TITLE_TEXT_FONT_SIZE, centered=True)
txt.draw_text(wx.Point(self.width/2.0, .5*self.padding_top))
##################################################
- # Draw Units
+ # Draw Labels
##################################################
font = wx.SystemSettings.GetFont(wx.SYS_DEFAULT_GUI_FONT)
font.SetWeight(wx.FONTWEIGHT_BOLD)
- #draw x units
- txt = gltext.Text(self.x_units, font=font,
font_size=UNITS_TEXT_FONT_SIZE, centered=True)
+ #draw x labels
+ x_label_str = self.x_units and "%s (%s)"%(self.x_label,
self.x_units) or self.x_label
+ txt = gltext.Text(x_label_str, font=font,
font_size=UNITS_TEXT_FONT_SIZE, centered=True)
txt.draw_text(wx.Point(
(self.width-self.padding_left-self.padding_right)/2.0 + self.padding_left,
self.height-.25*self.padding_bottom,
)
)
- #draw y units
- txt = gltext.Text(self.y_units, font=font,
font_size=UNITS_TEXT_FONT_SIZE, centered=True)
+ #draw y labels
+ y_label_str = self.y_units and "%s (%s)"%(self.y_label,
self.y_units) or self.y_label
+ txt = gltext.Text(y_label_str, font=font,
font_size=UNITS_TEXT_FONT_SIZE, centered=True)
txt.draw_text(wx.Point(
.25*self.padding_left,
(self.height-self.padding_top-self.padding_bottom)/2.0 + self.padding_top,
Modified:
gnuradio/branches/features/experimental-gui/plotter/waterfall_plotter.py
===================================================================
--- gnuradio/branches/features/experimental-gui/plotter/waterfall_plotter.py
2008-08-07 17:46:33 UTC (rev 9202)
+++ gnuradio/branches/features/experimental-gui/plotter/waterfall_plotter.py
2008-08-07 19:51:49 UTC (rev 9203)
@@ -110,7 +110,7 @@
"""!
Draw the grid and waveforms.
"""
- self.semaphore.acquire(True)
+ self.lock()
#resize texture
self._resize_texture()
#store the grid drawing operations
@@ -126,7 +126,7 @@
self._draw_waterfall()
#swap buffer into display
self.SwapBuffers()
- self.semaphore.release()
+ self.unlock()
def _draw_waterfall(self):
"""!
@@ -221,12 +221,12 @@
Old samples will not be recolorized.
@param color_mode the new color mode string
"""
- self.semaphore.acquire(True)
+ self.lock()
if color_mode in COLORS.keys():
self._color_mode = color_mode
self.changed(True)
self.update()
- self.semaphore.release()
+ self.unlock()
def set_num_lines(self, num_lines):
"""!
@@ -234,11 +234,11 @@
Powers of two only.
@param num_lines the new number of lines
"""
- self.semaphore.acquire(True)
+ self.lock()
self._num_lines = num_lines
self._resize_texture(True)
self.update()
- self.semaphore.release()
+ self.unlock()
def set_samples(self, samples, minimum, maximum):
"""!
@@ -248,7 +248,7 @@
@param minimum the minimum value to scale
@param maximum the maximum value to scale
"""
- self.semaphore.acquire(True)
+ self.lock()
#set the min, max values
if self._minimum != minimum or self._maximum != maximum:
self._minimum = minimum
@@ -264,4 +264,4 @@
#convert the samples to RGBA data
data = numpy.choose(samples,
COLORS[self._color_mode]).tostring()
self._buffer.append(data)
- self.semaphore.release()
+ self.unlock()
Modified: gnuradio/branches/features/experimental-gui/scope_window.py
===================================================================
--- gnuradio/branches/features/experimental-gui/scope_window.py 2008-08-07
17:46:33 UTC (rev 9202)
+++ gnuradio/branches/features/experimental-gui/scope_window.py 2008-08-07
19:51:49 UTC (rev 9203)
@@ -199,7 +199,7 @@
self.plotter = plotter.channel_plotter(self)
self.plotter.SetSize(wx.Size(*size))
self.plotter.set_title(title)
- self.plotter.set_legend(self.num_inputs > 1)
+ self.plotter.enable_legend(self.num_inputs > 1)
#setup the box with plot and controls
self.control_panel = control_panel(self)
main_box = wx.BoxSizer(wx.HORIZONTAL)
@@ -312,14 +312,14 @@
elif exp > -5: x_units, scalar = 'ms', 1e3
elif exp > -8: x_units, scalar = 'us', 1e6
else: x_units, scalar = 'ns', 1e9
- self.plotter.set_x_units('Time (%s)'%x_units)
+ self.plotter.set_x_label('Time', x_units)
self.plotter.set_x_grid(
scalar*x_off,
scalar*x_per_div*x_divs + scalar*x_off,
scalar*x_per_div,
)
#update the y axis
- self.plotter.set_y_units('Units')
+ self.plotter.set_y_label('Voltage')
self.plotter.set_y_grid(
-1*y_per_div*y_divs/2.0 + y_off,
y_per_div*y_divs/2.0 + y_off,
Modified: gnuradio/branches/features/experimental-gui/waterfall_window.py
===================================================================
--- gnuradio/branches/features/experimental-gui/waterfall_window.py
2008-08-07 17:46:33 UTC (rev 9202)
+++ gnuradio/branches/features/experimental-gui/waterfall_window.py
2008-08-07 19:51:49 UTC (rev 9203)
@@ -263,12 +263,12 @@
scalar*x_per_div,
)
#update x units
- self.plotter.set_x_units('Frequency (%s)'%x_units)
+ self.plotter.set_x_label('Frequency', x_units)
#update y grid
duration = float(num_lines)/frame_rate
y_per_div = common.get_clean_num(duration/y_divs)
self.plotter.set_y_grid(0, duration, y_per_div)
#update y units
- self.plotter.set_y_units('Time (s)')
+ self.plotter.set_y_label('Time', 's')
#update plotter
self.plotter.update()
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Commit-gnuradio] r9203 - in gnuradio/branches/features/experimental-gui: . plotter,
jblum <=