[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] r10533 - in gnuradio/branches/developers/jblum/gui_gut
From: |
jblum |
Subject: |
[Commit-gnuradio] r10533 - in gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python: . plotter |
Date: |
Fri, 27 Feb 2009 18:02:23 -0700 (MST) |
Author: jblum
Date: 2009-02-27 18:02:22 -0700 (Fri, 27 Feb 2009)
New Revision: 10533
Modified:
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/common.py
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/fft_window.py
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/plotter/channel_plotter.py
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/plotter/common.py
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/plotter/plotter_base.py
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/plotter/waterfall_plotter.py
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/scope_window.py
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/waterfall_window.py
Log:
Scientific and engineering notation format functions added and or moved to
plotter/common.
Plotters no longer need the common module in wxgui.
Formating and unit prefixing decided in the plotters.
Removed * import usage in plotters.
Modified:
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/common.py
===================================================================
--- gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/common.py
2009-02-27 16:50:28 UTC (rev 10532)
+++ gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/common.py
2009-02-28 01:02:22 UTC (rev 10533)
@@ -281,49 +281,3 @@
min = mean - rms
max = mean + rms
return min, max
-
-def get_si_components(num):
- """
- Get the SI units for the number.
- Extract the coeff and exponent of the number.
- The exponent will be a multiple of 3.
- @param num the floating point number
- @return the tuple coeff, exp, prefix
- """
- exp = get_exp(num)
- exp -= exp%3
- exp = min(max(exp, -24), 24) #bounds on SI table below
- prefix = {
- 24: 'Y', 21: 'Z',
- 18: 'E', 15: 'P',
- 12: 'T', 9: 'G',
- 6: 'M', 3: 'K',
- 0: '',
- -3: 'm', -6: 'u',
- -9: 'n', -12: 'p',
- -15: 'f', -18: 'a',
- -21: 'z', -24: 'y',
- }[exp]
- coeff = num/10**exp
- return coeff, exp, prefix
-
-def label_format(num):
- """
- Format a floating point number into a presentable string.
- If the number has an small enough exponent, use regular decimal.
- Otherwise, format the number with floating point notation.
- Exponents are normalized to multiples of 3.
- In the case where the exponent was found to be -3,
- it is best to display this as a regular decimal, with a 0 to the left.
- @param num the number to format
- @return a label string
- """
- coeff, exp, prefix = get_si_components(num)
- if -3 <= exp < 3: return '%g'%num
- return '%se%d'%('%.3g'%coeff, exp)
-
-if __name__ == '__main__':
- import random
- for i in range(-25, 25):
- num = random.random()*10**i
- print num, ':', get_si_components(num)
Modified:
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/fft_window.py
===================================================================
---
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/fft_window.py
2009-02-27 16:50:28 UTC (rev 10532)
+++
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/fft_window.py
2009-02-28 01:02:22 UTC (rev 10533)
@@ -268,24 +268,21 @@
if self.real: x_width = sample_rate/2.0
else: x_width = sample_rate/1.0
x_per_div = common.get_clean_num(x_width/x_divs)
- coeff, exp, prefix =
common.get_si_components(abs(baseband_freq) + abs(sample_rate/2.0))
#update the x grid
if self.real:
self.plotter.set_x_grid(
baseband_freq,
baseband_freq + sample_rate/2.0,
- x_per_div,
- 10**(-exp),
+ x_per_div, True,
)
else:
self.plotter.set_x_grid(
baseband_freq - sample_rate/2.0,
baseband_freq + sample_rate/2.0,
- x_per_div,
- 10**(-exp),
+ x_per_div, True,
)
#update x units
- self.plotter.set_x_label('Frequency', prefix+'Hz')
+ self.plotter.set_x_label('Frequency', 'Hz')
#update y grid
self.plotter.set_y_grid(ref_level-y_per_div*y_divs, ref_level,
y_per_div)
#update y units
Modified:
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/plotter/channel_plotter.py
===================================================================
---
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/plotter/channel_plotter.py
2009-02-27 16:50:28 UTC (rev 10532)
+++
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/plotter/channel_plotter.py
2009-02-28 01:02:22 UTC (rev 10533)
@@ -21,9 +21,8 @@
import wx
from plotter_base import grid_plotter_base
-from OpenGL.GL import *
-from gnuradio.wxgui import common
-import common as _common
+from OpenGL import GL
+import common
import numpy
import gltext
import math
@@ -49,7 +48,7 @@
#init
grid_plotter_base.__init__(self, parent, PADDING)
#setup legend cache
- self._legend_cache = _common.gl_cache(self._draw_legend)
+ self._legend_cache = common.gl_cache(self._draw_legend)
self.register_init(self._legend_cache.init)
self.register_draw(self._legend_cache.draw)
#setup channel plotter
@@ -62,7 +61,7 @@
"""
Run gl initialization tasks.
"""
- glEnableClientState(GL_VERTEX_ARRAY)
+ GL.glEnableClientState(GL.GL_VERTEX_ARRAY)
def enable_legend(self, enable=None):
"""
@@ -82,8 +81,8 @@
Scale the waveform data to the grid using gl matrix operations.
"""
#use scissor to prevent drawing outside grid
- glEnable(GL_SCISSOR_TEST)
- glScissor(
+ GL.glEnable(GL.GL_SCISSOR_TEST)
+ GL.glScissor(
self.padding_left+1,
self.padding_bottom+1,
self.width-self.padding_left-self.padding_right-1,
@@ -94,34 +93,34 @@
num_samps = len(samples)
if not num_samps: continue
#use opengl to scale the waveform
- glPushMatrix()
- glTranslatef(self.padding_left, self.padding_top, 0)
- glScalef(
+ GL.glPushMatrix()
+ GL.glTranslatef(self.padding_left, self.padding_top, 0)
+ GL.glScalef(
(self.width-self.padding_left-self.padding_right),
(self.height-self.padding_top-self.padding_bottom),
1,
)
- glTranslatef(0, 1, 0)
+ GL.glTranslatef(0, 1, 0)
if isinstance(samples, tuple):
x_scale, x_trans = 1.0/(self.x_max-self.x_min),
-self.x_min
points = zip(*samples)
else:
x_scale, x_trans = 1.0/(num_samps-1),
-self._channels[channel][TRIG_OFF_KEY]
points = zip(numpy.arange(0, num_samps),
samples)
- glScalef(x_scale, -1.0/(self.y_max-self.y_min), 1)
- glTranslatef(x_trans, -self.y_min, 0)
+ GL.glScalef(x_scale, -1.0/(self.y_max-self.y_min), 1)
+ GL.glTranslatef(x_trans, -self.y_min, 0)
#draw the points/lines
- glColor3f(*self._channels[channel][COLOR_SPEC_KEY])
+ GL.glColor3f(*self._channels[channel][COLOR_SPEC_KEY])
marker = self._channels[channel][MARKERY_KEY]
if marker is None:
- glVertexPointerf(points)
- glDrawArrays(GL_LINE_STRIP, 0, len(points))
+ GL.glVertexPointerf(points)
+ GL.glDrawArrays(GL.GL_LINE_STRIP, 0,
len(points))
elif isinstance(marker, (int, float)) and marker > 0:
- glPointSize(marker)
- glVertexPointerf(points)
- glDrawArrays(GL_POINTS, 0, len(points))
- glPopMatrix()
- glDisable(GL_SCISSOR_TEST)
+ GL.glPointSize(marker)
+ GL.glVertexPointerf(points)
+ GL.glDrawArrays(GL.GL_POINTS, 0, len(points))
+ GL.glPopMatrix()
+ GL.glDisable(GL.GL_SCISSOR_TEST)
def _populate_point_label(self, x_val, y_val):
"""
@@ -133,12 +132,9 @@
@return a string with newlines
"""
#create text
- label_str = '%s: %s %s\n%s: %s %s'%(
- self.x_label,
- common.label_format(x_val),
- self.x_units, self.y_label,
- common.label_format(y_val),
- self.y_units,
+ label_str = '%s: %s\n%s: %s'%(
+ self.x_label, common.eng_format(x_val, self.x_units),
+ self.y_label, common.eng_format(y_val, self.y_units),
)
for channel in sorted(self._channels.keys()):
samples = self._channels[channel][SAMPLES_KEY]
@@ -146,12 +142,12 @@
if not num_samps: continue
if isinstance(samples, tuple): continue
#linear interpolation
- x_index =
(num_samps-1)*(x_val/self.x_scalar-self.x_min)/(self.x_max-self.x_min)
+ x_index =
(num_samps-1)*(x_val-self.x_min)/(self.x_max-self.x_min)
x_index_low = int(math.floor(x_index))
x_index_high = int(math.ceil(x_index))
scale = x_index - x_index_low +
self._channels[channel][TRIG_OFF_KEY]
y_value = (samples[x_index_high] -
samples[x_index_low])*scale + samples[x_index_low]
- label_str += '\n%s: %s %s'%(channel,
common.label_format(y_value), self.y_units)
+ label_str += '\n%s: %s'%(channel,
common.eng_format(y_value, self.y_units))
return label_str
def _draw_legend(self):
@@ -169,7 +165,7 @@
txt = gltext.Text(channel,
font_size=LEGEND_TEXT_FONT_SIZE)
w, h = txt.get_size()
#draw rect + text
- glColor3f(*color_spec)
+ GL.glColor3f(*color_spec)
self._draw_rect(
x_off - w - LEGEND_BOX_PADDING,
self.padding_top/2 - h/2 - LEGEND_BOX_PADDING,
Modified:
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/plotter/common.py
===================================================================
---
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/plotter/common.py
2009-02-27 16:50:28 UTC (rev 10532)
+++
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/plotter/common.py
2009-02-28 01:02:22 UTC (rev 10533)
@@ -21,10 +21,69 @@
import threading
import time
+import math
import wx
from OpenGL import GL
##################################################
+# Number formatting
+##################################################
+def get_exp(num):
+ """
+ Get the exponent of the number in base 10.
+ @param num the floating point number
+ @return the exponent as an integer
+ """
+ if num == 0: return 0
+ return int(math.floor(math.log10(abs(num))))
+
+def get_si_components(num):
+ """
+ Get the SI units for the number.
+ Extract the coeff and exponent of the number.
+ The exponent will be a multiple of 3.
+ @param num the floating point number
+ @return the tuple coeff, exp, prefix
+ """
+ num = float(num)
+ exp = get_exp(num)
+ exp -= exp%3
+ exp = min(max(exp, -24), 24) #bounds on SI table below
+ prefix = {
+ 24: 'Y', 21: 'Z',
+ 18: 'E', 15: 'P',
+ 12: 'T', 9: 'G',
+ 6: 'M', 3: 'k',
+ 0: '',
+ -3: 'm', -6: 'u',
+ -9: 'n', -12: 'p',
+ -15: 'f', -18: 'a',
+ -21: 'z', -24: 'y',
+ }[exp]
+ coeff = num/10**exp
+ return coeff, exp, prefix
+
+def sci_format(num):
+ """
+ Format a floating point number into scientific notation.
+ @param num the number to format
+ @return a label string
+ """
+ coeff, exp, prefix = get_si_components(num)
+ if -3 <= exp < 3: return '%g'%num
+ return '%.3ge%d'%(coeff, exp)
+
+def eng_format(num, units=''):
+ """
+ Format a floating point number into engineering notation.
+ @param num the number to format
+ @param units the units to append
+ @return a label string
+ """
+ coeff, exp, prefix = get_si_components(num)
+ return '%g%s%s%s'%(coeff, units and ' ' or '', prefix, units)
+
+##################################################
# Interface with thread safe lock/unlock
##################################################
class mutex(object):
@@ -55,20 +114,21 @@
def run(self):
last_ts = time.time()
last_coor = coor = None
- while True:
- time.sleep(1.0/30.0)
- self.lock()
- #get most recent coor change
- if self._coor_queue:
- coor = self._coor_queue[-1]
- self._coor_queue = list()
- self.unlock()
- #update if coor change, or enough time expired
- if last_coor != coor or (time.time() - last_ts) >
(1.0/2.0):
- try:
self._plotter.set_point_label_coordinate(coor)
- except: return
- last_coor = coor
- last_ts = time.time()
+ try:
+ while True:
+ time.sleep(1.0/30.0)
+ self.lock()
+ #get most recent coor change
+ if self._coor_queue:
+ coor = self._coor_queue[-1]
+ self._coor_queue = list()
+ self.unlock()
+ #update if coor change, or enough time expired
+ if last_coor != coor or (time.time() - last_ts)
> (1.0/2.0):
+
self._plotter.set_point_label_coordinate(coor)
+ last_coor = coor
+ last_ts = time.time()
+ except wx.PyDeadObjectError: pass
##################################################
# GL caching interface
Modified:
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/plotter/plotter_base.py
===================================================================
---
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/plotter/plotter_base.py
2009-02-27 16:50:28 UTC (rev 10532)
+++
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/plotter/plotter_base.py
2009-02-28 01:02:22 UTC (rev 10533)
@@ -21,9 +21,8 @@
import wx
import wx.glcanvas
-from OpenGL.GL import *
-from gnuradio.wxgui import common
-import common as _common
+from OpenGL import GL
+import common
import threading
import gltext
import math
@@ -43,7 +42,7 @@
##################################################
# OpenGL WX Plotter Canvas
##################################################
-class _plotter_base(wx.glcanvas.GLCanvas, _common.mutex):
+class _plotter_base(wx.glcanvas.GLCanvas, common.mutex):
"""
Plotter base class for all plot types.
"""
@@ -93,23 +92,23 @@
self.SetCurrent()
#check if gl was initialized
if not self._gl_init_flag:
- glClearColor(*BACKGROUND_COLOR_SPEC)
+ GL.glClearColor(*BACKGROUND_COLOR_SPEC)
for fcn in self._init_fcns: fcn()
self._gl_init_flag = True
#check for a change in window size
if self._resized_flag:
self.lock()
self.width, self.height = self.GetSize()
- glMatrixMode(GL_PROJECTION)
- glLoadIdentity()
- glOrtho(0, self.width, self.height, 0, 1, 0)
- glMatrixMode(GL_MODELVIEW)
- glLoadIdentity()
- glViewport(0, 0, self.width, self.height)
+ GL.glMatrixMode(GL.GL_PROJECTION)
+ GL.glLoadIdentity()
+ GL.glOrtho(0, self.width, self.height, 0, 1, 0)
+ GL.glMatrixMode(GL.GL_MODELVIEW)
+ GL.glLoadIdentity()
+ GL.glViewport(0, 0, self.width, self.height)
self._resized_flag = False
self.unlock()
#clear, draw functions, swap
- glClear(GL_COLOR_BUFFER_BIT)
+ GL.glClear(GL.GL_COLOR_BUFFER_BIT)
self.lock()
for fcn in self._draw_fcns: fcn[1]()
self.unlock()
@@ -131,7 +130,7 @@
def __init__(self, parent, padding):
_plotter_base.__init__(self, parent)
#setup grid cache
- self._grid_cache = _common.gl_cache(self._draw_grid)
+ self._grid_cache = common.gl_cache(self._draw_grid)
self.register_init(self._grid_cache.init)
self.register_draw(self._grid_cache.draw)
#setup padding
@@ -144,13 +143,13 @@
self.set_x_grid(-1, 1, 1)
self.set_y_grid(-1, 1, 1)
#setup point label cache
- self._point_label_cache =
_common.gl_cache(self._draw_point_label)
+ self._point_label_cache =
common.gl_cache(self._draw_point_label)
self.register_init(self._point_label_cache.init)
self.register_draw(self._point_label_cache.draw, 75)
#setup point label
self.enable_point_label(False)
self.set_point_label_coordinate(None)
- _common.point_label_thread(self)
+ common.point_label_thread(self)
def set_point_label_coordinate(self, coor):
"""
@@ -209,35 +208,47 @@
self._grid_cache.changed(True)
self.unlock()
- def set_x_grid(self, x_min, x_max, x_step, x_scalar=1.0):
+ def set_x_grid(self, minimum, maximum, step, scale=False):
"""
Set the x grid parameters.
- @param x_min the left-most value
- @param x_max the right-most value
- @param x_step the grid spacing
- @param x_scalar the scalar factor
+ @param minimum the left-most value
+ @param maximum the right-most value
+ @param step the grid spacing
+ @param scale true to scale the x grid
"""
self.lock()
- self.x_min = float(x_min)
- self.x_max = float(x_max)
- self.x_step = float(x_step)
- self.x_scalar = float(x_scalar)
+ self.x_min = float(minimum)
+ self.x_max = float(maximum)
+ self.x_step = float(step)
+ if scale:
+ coeff, exp, prefix =
common.get_si_components(max(abs(self.x_min), abs(self.x_max)))
+ self.x_scalar = 10**(-exp)
+ self.x_prefix = prefix
+ else:
+ self.x_scalar = 1.0
+ self.x_prefix = ''
self._grid_cache.changed(True)
self.unlock()
- def set_y_grid(self, y_min, y_max, y_step, y_scalar=1.0):
+ def set_y_grid(self, minimum, maximum, step, scale=False):
"""
Set the y grid parameters.
- @param y_min the bottom-most value
- @param y_max the top-most value
- @param y_step the grid spacing
- @param y_scalar the scalar factor
+ @param minimum the bottom-most value
+ @param maximum the top-most value
+ @param step the grid spacing
+ @param scale true to scale the y grid
"""
self.lock()
- self.y_min = float(y_min)
- self.y_max = float(y_max)
- self.y_step = float(y_step)
- self.y_scalar = float(y_scalar)
+ self.y_min = float(minimum)
+ self.y_max = float(maximum)
+ self.y_step = float(step)
+ if scale:
+ coeff, exp, prefix =
common.get_si_components(max(abs(self.y_min), abs(self.y_max)))
+ self.y_scalar = 10**(-exp)
+ self.y_prefix = prefix
+ else:
+ self.y_scalar = 1.0
+ self.y_prefix = ''
self._grid_cache.changed(True)
self.unlock()
@@ -248,37 +259,35 @@
##################################################
# Draw Grid X
##################################################
- glColor3f(*GRID_LINE_COLOR_SPEC)
+ GL.glColor3f(*GRID_LINE_COLOR_SPEC)
for tick in self._get_ticks(self.x_min, self.x_max,
self.x_step, self.x_scalar):
scaled_tick =
(self.width-self.padding_left-self.padding_right)*\
-
(tick/self.x_scalar-self.x_min)/(self.x_max-self.x_min) + self.padding_left
- glColor3f(*GRID_LINE_COLOR_SPEC)
+
(tick/self.x_scalar-self.x_min)/(self.x_max-self.x_min) + self.padding_left-1
self._draw_dashed_line(
(scaled_tick, self.padding_top),
(scaled_tick, self.height-self.padding_bottom),
)
- txt = self._get_tick_label(tick)
+ txt = self._get_tick_label(tick, self.x_units)
w, h = txt.get_size()
txt.draw_text(wx.Point(scaled_tick-w/2,
self.height-self.padding_bottom+TICK_LABEL_PADDING))
##################################################
# Draw Grid Y
##################################################
- glColor3f(*GRID_LINE_COLOR_SPEC)
+ GL.glColor3f(*GRID_LINE_COLOR_SPEC)
for tick in self._get_ticks(self.y_min, self.y_max,
self.y_step, self.y_scalar):
scaled_tick =
(self.height-self.padding_top-self.padding_bottom)*\
(1 -
(tick/self.y_scalar-self.y_min)/(self.y_max-self.y_min)) + self.padding_top
- glColor3f(*GRID_LINE_COLOR_SPEC)
self._draw_dashed_line(
(self.padding_left, scaled_tick),
(self.width-self.padding_right, scaled_tick),
)
- txt = self._get_tick_label(tick)
+ txt = self._get_tick_label(tick, self.y_units)
w, h = txt.get_size()
txt.draw_text(wx.Point(self.padding_left-w-TICK_LABEL_PADDING, scaled_tick-h/2))
##################################################
# Draw Border
##################################################
- glColor3f(*GRID_BORDER_COLOR_SPEC)
+ GL.glColor3f(*GRID_BORDER_COLOR_SPEC)
self._draw_rect(
self.padding_left,
self.padding_top,
@@ -296,7 +305,7 @@
# Draw Labels
##################################################
#draw x labels
- x_label_str = self.x_units and "%s (%s)"%(self.x_label,
self.x_units) or self.x_label
+ x_label_str = self.x_units and "%s (%s%s)"%(self.x_label,
self.x_prefix, self.x_units) or self.x_label
txt = gltext.Text(x_label_str, bold=True,
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,
@@ -304,7 +313,7 @@
)
)
#draw y labels
- y_label_str = self.y_units and "%s (%s)"%(self.y_label,
self.y_units) or self.y_label
+ y_label_str = self.y_units and "%s (%s%s)"%(self.y_label,
self.y_prefix, self.y_units) or self.y_label
txt = gltext.Text(y_label_str, bold=True,
font_size=UNITS_TEXT_FONT_SIZE, centered=True)
txt.draw_text(wx.Point(
.25*self.padding_left,
@@ -312,13 +321,15 @@
), rotation=90,
)
- def _get_tick_label(self, tick):
+ def _get_tick_label(self, tick, unit):
"""
Format the tick value and create a gl text.
@param tick the floating point tick value
+ @param unit the axis unit
@return the tick label text
"""
- tick_str = common.label_format(tick)
+ if unit: tick_str = common.sci_format(tick)
+ else: tick_str = common.eng_format(tick)
return gltext.Text(tick_str, font_size=TICK_TEXT_FONT_SIZE)
def _get_ticks(self, min, max, step, scalar):
@@ -349,13 +360,13 @@
@param corr1 a tuple of x, y
@param corr2 a tuple of x, y
"""
- glEnable(GL_LINE_STIPPLE)
- glLineStipple(1, int("1110" + "0000" + "1110" + "0000", 2))
- glBegin(GL_LINES)
- glVertex2f(*coor1)
- glVertex2f(*coor2)
- glEnd()
- glDisable(GL_LINE_STIPPLE)
+ GL.glEnable(GL.GL_LINE_STIPPLE)
+ GL.glLineStipple(1, int("1110" + "0000" + "1110" + "0000", 2))
+ GL.glBegin(GL.GL_LINES)
+ GL.glVertex2f(*coor1)
+ GL.glVertex2f(*coor2)
+ GL.glEnd()
+ GL.glDisable(GL.GL_LINE_STIPPLE)
def _draw_rect(self, x, y, width, height, fill=True):
"""
@@ -367,12 +378,12 @@
@param height the height of the rectangle
@param fill true to color inside of rectangle
"""
- glBegin(fill and GL_QUADS or GL_LINE_LOOP)
- glVertex2f(x, y)
- glVertex2f(x+width, y)
- glVertex2f(x+width, y+height)
- glVertex2f(x, y+height)
- glEnd()
+ GL.glBegin(fill and GL.GL_QUADS or GL.GL_LINE_LOOP)
+ GL.glVertex2f(x, y)
+ GL.glVertex2f(x+width, y)
+ GL.glVertex2f(x+width, y+height)
+ GL.glVertex2f(x, y+height)
+ GL.glEnd()
def _draw_point_label(self):
"""
@@ -390,14 +401,14 @@
x_win_scalar = float(x -
self.padding_left)/(self.width-self.padding_left-self.padding_right)
y_win_scalar = float((self.height - y) -
self.padding_bottom)/(self.height-self.padding_top-self.padding_bottom)
#scale to grid bounds
- x_val = self.x_scalar*(x_win_scalar*(self.x_max-self.x_min) +
self.x_min)
- y_val = self.y_scalar*(y_win_scalar*(self.y_max-self.y_min) +
self.y_min)
+ x_val = x_win_scalar*(self.x_max-self.x_min) + self.x_min
+ y_val = y_win_scalar*(self.y_max-self.y_min) + self.y_min
#create text
label_str = self._populate_point_label(x_val, y_val)
txt = gltext.Text(label_str, font_size=POINT_LABEL_FONT_SIZE)
w, h = txt.get_size()
#draw rect + text
- glColor3f(*POINT_LABEL_COLOR_SPEC)
+ GL.glColor3f(*POINT_LABEL_COLOR_SPEC)
if x > self.width/2: x -= w+2*POINT_LABEL_PADDING
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))
Modified:
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/plotter/waterfall_plotter.py
===================================================================
---
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/plotter/waterfall_plotter.py
2009-02-27 16:50:28 UTC (rev 10532)
+++
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/plotter/waterfall_plotter.py
2009-02-28 01:02:22 UTC (rev 10533)
@@ -21,9 +21,8 @@
import wx
from plotter_base import grid_plotter_base
-from OpenGL.GL import *
-from gnuradio.wxgui import common
-import common as _common
+from OpenGL import GL
+import common
import numpy
import gltext
import math
@@ -94,7 +93,7 @@
#init
grid_plotter_base.__init__(self, parent, PADDING)
#setup legend cache
- self._legend_cache = _common.gl_cache(self._draw_legend)
+ self._legend_cache = common.gl_cache(self._draw_legend)
self.register_init(self._legend_cache.init)
self.register_draw(self._legend_cache.draw)
#setup waterfall plotter
@@ -114,7 +113,7 @@
"""
Run gl initialization tasks.
"""
- self._waterfall_texture = glGenTextures(1)
+ self._waterfall_texture = GL.glGenTextures(1)
def _draw_waterfall(self):
"""
@@ -125,41 +124,41 @@
#resize texture
self._resize_texture()
#setup texture
- glBindTexture(GL_TEXTURE_2D, self._waterfall_texture)
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT)
- glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE)
+ GL.glBindTexture(GL.GL_TEXTURE_2D, self._waterfall_texture)
+ GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER,
GL.GL_LINEAR)
+ GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER,
GL.GL_LINEAR)
+ GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T,
GL.GL_REPEAT)
+ GL.glTexEnvi(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE,
GL.GL_REPLACE)
#write the buffer to the texture
while self._buffer:
- glTexSubImage2D(GL_TEXTURE_2D, 0, 0, self._pointer,
self._fft_size, 1, GL_RGBA, GL_UNSIGNED_BYTE, self._buffer.pop(0))
+ GL.glTexSubImage2D(GL.GL_TEXTURE_2D, 0, 0,
self._pointer, self._fft_size, 1, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE,
self._buffer.pop(0))
self._pointer = (self._pointer + 1)%self._num_lines
#begin drawing
- glEnable(GL_TEXTURE_2D)
- glPushMatrix()
+ GL.glEnable(GL.GL_TEXTURE_2D)
+ GL.glPushMatrix()
#matrix scaling
- glTranslatef(self.padding_left, self.padding_top, 0)
- glScalef(
+ GL.glTranslatef(self.padding_left, self.padding_top, 0)
+ GL.glScalef(
float(self.width-self.padding_left-self.padding_right),
float(self.height-self.padding_top-self.padding_bottom),
1.0,
)
#draw texture with wrapping
- glBegin(GL_QUADS)
+ GL.glBegin(GL.GL_QUADS)
prop_y = float(self._pointer)/(self._num_lines-1)
prop_x = float(self._fft_size)/ceil_log2(self._fft_size)
off = 1.0/(self._num_lines-1)
- glTexCoord2f(0, prop_y+1-off)
- glVertex2f(0, 1)
- glTexCoord2f(prop_x, prop_y+1-off)
- glVertex2f(1, 1)
- glTexCoord2f(prop_x, prop_y)
- glVertex2f(1, 0)
- glTexCoord2f(0, prop_y)
- glVertex2f(0, 0)
- glEnd()
- glPopMatrix()
- glDisable(GL_TEXTURE_2D)
+ GL.glTexCoord2f(0, prop_y+1-off)
+ GL.glVertex2f(0, 1)
+ GL.glTexCoord2f(prop_x, prop_y+1-off)
+ GL.glVertex2f(1, 1)
+ GL.glTexCoord2f(prop_x, prop_y)
+ GL.glVertex2f(1, 0)
+ GL.glTexCoord2f(0, prop_y)
+ GL.glVertex2f(0, 0)
+ GL.glEnd()
+ GL.glPopMatrix()
+ GL.glDisable(GL.GL_TEXTURE_2D)
def _populate_point_label(self, x_val, y_val):
"""
@@ -169,7 +168,7 @@
@param y_val the current y value
@return a value string with units
"""
- return '%s: %s %s'%(self.x_label, common.label_format(x_val),
self.x_units)
+ return '%s: %s'%(self.x_label, common.eng_format(x_val,
self.x_units))
def _draw_legend(self):
"""
@@ -182,11 +181,11 @@
x = self.width - self.padding_right + LEGEND_LEFT_PAD
for i in range(LEGEND_NUM_BLOCKS):
color =
COLORS[self._color_mode][int(255*i/float(LEGEND_NUM_BLOCKS-1))]
- glColor4f(*map(lambda c: ord(c)/255.0, color))
+ GL.glColor4f(*map(lambda c: ord(c)/255.0, color))
y = self.height - (i+1)*block_height -
self.padding_bottom
self._draw_rect(x, y, LEGEND_WIDTH, block_height)
#draw rectangle around color scale border
- glColor3f(*LEGEND_BORDER_COLOR_SPEC)
+ GL.glColor3f(*LEGEND_BORDER_COLOR_SPEC)
self._draw_rect(x, self.padding_top, LEGEND_WIDTH,
legend_height, fill=False)
#draw each legend label
label_spacing = float(legend_height)/(LEGEND_NUM_LABELS-1)
@@ -210,9 +209,9 @@
self._buffer = list()
self._pointer = 0
if self._num_lines and self._fft_size:
- glBindTexture(GL_TEXTURE_2D, self._waterfall_texture)
+ GL.glBindTexture(GL.GL_TEXTURE_2D,
self._waterfall_texture)
data = numpy.zeros(self._num_lines*self._fft_size*4,
numpy.uint8).tostring()
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
ceil_log2(self._fft_size), self._num_lines, 0, GL_RGBA, GL_UNSIGNED_BYTE, data)
+ GL.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGBA,
ceil_log2(self._fft_size), self._num_lines, 0, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE,
data)
self._resize_texture_flag = False
def set_color_mode(self, color_mode):
Modified:
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/scope_window.py
===================================================================
---
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/scope_window.py
2009-02-27 16:50:28 UTC (rev 10532)
+++
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/scope_window.py
2009-02-28 01:02:22 UTC (rev 10533)
@@ -524,9 +524,8 @@
self.plotter.set_y_grid(self.get_y_min(),
self.get_y_max(), self[Y_PER_DIV_KEY])
else:
#update the t axis
- coeff, exp, prefix =
common.get_si_components(self.get_t_max())
- self.plotter.set_x_label('Time', prefix+'s')
- self.plotter.set_x_grid(self.get_t_min(),
self.get_t_max(), self[T_PER_DIV_KEY], 10**(-exp))
+ self.plotter.set_x_label('Time', 's')
+ self.plotter.set_x_grid(self.get_t_min(),
self.get_t_max(), self[T_PER_DIV_KEY], True)
#update the y axis
self.plotter.set_y_label('Counts')
self.plotter.set_y_grid(self.get_y_min(),
self.get_y_max(), self[Y_PER_DIV_KEY])
Modified:
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/waterfall_window.py
===================================================================
---
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/waterfall_window.py
2009-02-27 16:50:28 UTC (rev 10532)
+++
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/waterfall_window.py
2009-02-28 01:02:22 UTC (rev 10533)
@@ -270,28 +270,25 @@
if self.real: x_width = sample_rate/2.0
else: x_width = sample_rate/1.0
x_per_div = common.get_clean_num(x_width/x_divs)
- coeff, exp, prefix =
common.get_si_components(abs(baseband_freq) + abs(sample_rate/2.0))
#update the x grid
if self.real:
self.plotter.set_x_grid(
baseband_freq,
baseband_freq + sample_rate/2.0,
- x_per_div,
- 10**(-exp),
+ x_per_div, True,
)
else:
self.plotter.set_x_grid(
baseband_freq - sample_rate/2.0,
baseband_freq + sample_rate/2.0,
- x_per_div,
- 10**(-exp),
+ x_per_div, True,
)
#update x units
- self.plotter.set_x_label('Frequency', prefix+'Hz')
+ self.plotter.set_x_label('Frequency', 'Hz')
#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)
+ self.plotter.set_y_grid(0, duration, y_per_div, True)
#update y units
self.plotter.set_y_label('Time', 's')
#update plotter
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Commit-gnuradio] r10533 - in gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python: . plotter,
jblum <=