commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] r8775 - gnuradio/branches/developers/jblum/gr-wxglgui/


From: jblum
Subject: [Commit-gnuradio] r8775 - gnuradio/branches/developers/jblum/gr-wxglgui/src/python
Date: Thu, 3 Jul 2008 17:51:29 -0600 (MDT)

Author: jblum
Date: 2008-07-03 17:51:27 -0600 (Thu, 03 Jul 2008)
New Revision: 8775

Modified:
   gnuradio/branches/developers/jblum/gr-wxglgui/src/python/constsink.py
   gnuradio/branches/developers/jblum/gr-wxglgui/src/python/plotter.py
   gnuradio/branches/developers/jblum/gr-wxglgui/src/python/scopesink.py
Log:
plotter scissor, waveform on top

Modified: gnuradio/branches/developers/jblum/gr-wxglgui/src/python/constsink.py
===================================================================
--- gnuradio/branches/developers/jblum/gr-wxglgui/src/python/constsink.py       
2008-07-03 05:41:15 UTC (rev 8774)
+++ gnuradio/branches/developers/jblum/gr-wxglgui/src/python/constsink.py       
2008-07-03 23:51:27 UTC (rev 8775)
@@ -1,23 +1,23 @@
 #
 # Copyright 2008 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
@@ -35,8 +35,12 @@
 DEFAULT_FRAME_RATE = 5
 DEFAULT_WIN_SIZE = (500, 400)
 DEFAULT_CONST_SIZE = 1024
-CONST_PLOT_COLOR_SPEC = (0, 0, 1) 
-AUTORANGE_UPDATE_RATE = 0.5 #sec
+CONST_PLOT_COLOR_SPEC = (0, 0, 1)
+MARKER_TYPES = (
+       ('Line', None),
+       ('Plus', '+'),
+       ('Dot', '.'),
+)
 
 ##################################################
 # Constellation window control panel
@@ -45,103 +49,83 @@
        """!
        A control panel with wx widgits to control the plotter.
        """
-       def __init__(self, parent):     
+       def __init__(self, parent):
                """!
                Create a new control panel.
                @param parent the wx parent window
                """
                self.parent = parent
-               wx.Panel.__init__(self, parent, -1, style=wx.SUNKEN_BORDER)     
-               control_box = wx.BoxSizer(wx.HORIZONTAL)
-               
+               wx.Panel.__init__(self, parent, -1, style=wx.SUNKEN_BORDER)
+               control_box = wx.BoxSizer(wx.VERTICAL)
+
                #begin control box
                control_box.AddSpacer(2)
+               control_box.Add(common.LabelText(self, 'Options'), 0, 
wx.ALIGN_CENTER)
+               control_box.AddSpacer(2)
                self.run_button = wx.Button(self, -1, '', style=wx.BU_EXACTFIT)
                self.run_button.Bind(wx.EVT_BUTTON, self._on_run)
-               control_box.Add(self.run_button, 0, wx.EXPAND)          
+               control_box.Add(self.run_button, 0, wx.EXPAND)
                #end control box
                control_box.AddSpacer(2)
                #set sizer
                self.SetSizerAndFit(control_box)
                #update
                self.update()
-               
-       def update(self): 
+
+       def update(self):
                #update the run/stop button
                if self.parent.running: self.run_button.SetLabel('Stop')
                else: self.run_button.SetLabel('Run')
-               
+
        ##################################################
        # Event handlers
        ##################################################
        def _on_run(self, event): self.parent.set_run(not self.parent.running)
-               
+
 ##################################################
 # Constellation window with plotter and control panel
 ##################################################
 class const_window(wx.Panel):
        def __init__(
-               self, 
+               self,
                parent,
-               size, 
+               size,
                title,
                frame_rate,
                sample_rate,
-       ):              
+       ):
                #setup
                self.running = True
                self.sample_rate = sample_rate
                self.x_divs = 8
-               self.x_per_div = 1
-               self.x_off = 0
                self.y_divs = 8
-               self.y_per_div = 1
-               self.y_off = 0
-               self.autorange_ts = 0
-               #init panel and plot 
+               #init panel and plot
                wx.Panel.__init__(self, parent, -1, style=wx.SIMPLE_BORDER)
-               self.plotter = plotter.grid_plotter(self)  
+               self.plotter = plotter.grid_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')
                #setup the box with plot and controls
                self.control_panel = control_panel(self)
-               main_box = wx.BoxSizer(wx.VERTICAL)
+               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)
                #update
                self.update()
-               
+
        def plot(self, samples):
                """!
                Plot the samples onto the complex grid.
                @param samples the array of complex samples
-               """     
+               """
                if not self.running: return
                real = numpy.real(samples)
                imag = numpy.imag(samples)
-               #update autorange
-               if time.time() - self.autorange_ts > AUTORANGE_UPDATE_RATE:
-                       #adjust the x per div
-                       min, max = common.get_min_max(real)
-                       x_per_div = common.get_clean_num((max-min)/self.x_divs) 
                                
-                       if self.x_per_div != x_per_div: 
self.set_x_per_div(x_per_div)
-                       #adjust the x offset
-                       x_off = self.x_per_div*round((max+min)/2/self.x_per_div)
-                       if self.x_off != x_off: self.set_x_off(x_off)   
-                       #adjust the y per div           
-                       min, max = common.get_min_max(imag)
-                       y_per_div = common.get_clean_num((max-min)/self.y_divs) 
                                
-                       if self.y_per_div != y_per_div: 
self.set_y_per_div(y_per_div)
-                       #adjust the y offset
-                       y_off = self.y_per_div*round((max+min)/2/self.y_per_div)
-                       if self.y_off != y_off: self.set_y_off(y_off)           
                        
-                       self.autorange_ts = time.time()
                #plot
                self.plotter.set_waveform(
-                       channel=0, 
+                       channel=0,
                        samples=(real, imag),
                        color_spec=CONST_PLOT_COLOR_SPEC,
                        marker='+',
@@ -149,23 +133,15 @@
                #update the plotter
                self.plotter.update()
 
-       def update(self): 
+       def update(self):
                #update the x axis
-               self.plotter.set_x_grid(
-                       -1*self.x_per_div*self.x_divs/2.0 + self.x_off, 
-                       self.x_per_div*self.x_divs/2.0 + self.x_off, 
-                       self.x_per_div,
-               )
+               self.plotter.set_x_grid(-1, 1, 
common.get_clean_num(2.0/self.x_divs))
                #update the y axis
-               self.plotter.set_y_grid(
-                       -1*self.y_per_div*self.y_divs/2.0 + self.y_off, 
-                       self.y_per_div*self.y_divs/2.0 + self.y_off, 
-                       self.y_per_div,
-               )
+               self.plotter.set_y_grid(-1, 1, 
common.get_clean_num(2.0/self.y_divs))
                #update control panel and plotter
                self.control_panel.update()
                self.plotter.update()
-               
+
        ##################################################
        # Set parameters on-the-fly
        ##################################################
@@ -187,16 +163,16 @@
 
 ##################################################
 # Constellation sink block
-##################################################     
+##################################################
 class const_sink_c(gr.hier_block2):
        """!
        A constellation block with a gui window.
        """
-       
+
        def __init__(
-               self, 
+               self,
                parent,
-               title='', 
+               title='',
                sample_rate=1,
                size=DEFAULT_WIN_SIZE,
                frame_rate=DEFAULT_FRAME_RATE,
@@ -204,7 +180,7 @@
        ):
                #init
                gr.hier_block2.__init__(
-                       self, 
+                       self,
                        "const_sink",
                        gr.io_signature(1, 1, gr.sizeof_gr_complex),
                        gr.io_signature(0, 0, 0),
@@ -222,7 +198,7 @@
                self.connect(self, sd, sink)
                #create window
                self.win = const_window(
-                       parent=parent, 
+                       parent=parent,
                        size=size,
                        title=title,
                        frame_rate=frame_rate,
@@ -232,7 +208,7 @@
                self.set_sample_rate = sd.set_sample_rate
                #setup the input watcher
                common.input_watcher(msgq, self._handle_msg)
-               
+
        def _handle_msg(self, msg):
                itemsize = int(msg.arg1())
                nitems = int(msg.arg2())
@@ -241,7 +217,7 @@
                # If so, we take only the last one
                if nitems > 1:
                        start = itemsize * (nitems - 1)
-                       s = s[start:start+itemsize]             
+                       s = s[start:start+itemsize]
                #convert to complex floating point numbers
                samples = numpy.fromstring(s, numpy.complex64)
                self.win.plot(samples)

Modified: gnuradio/branches/developers/jblum/gr-wxglgui/src/python/plotter.py
===================================================================
--- gnuradio/branches/developers/jblum/gr-wxglgui/src/python/plotter.py 
2008-07-03 05:41:15 UTC (rev 8774)
+++ gnuradio/branches/developers/jblum/gr-wxglgui/src/python/plotter.py 
2008-07-03 23:51:27 UTC (rev 8775)
@@ -192,10 +192,20 @@
                        self._draw_grid()
                        glEndList()
                        self._changed = False
-               self._draw_waveforms()
                #draw the grid
                glCallList(self.grid_compiled_list_id)
-               glFlush()
+               #use scissor to prevent drawing outside grid
+               glEnable(GL_SCISSOR_TEST)
+               glScissor(
+                       self.padding_left+1, 
+                       self.padding_bottom+1, 
+                       self.width-self.padding_left-self.padding_right-1, 
+                       self.height-self.padding_top-self.padding_bottom-1,
+               )
+               #draw the waveforms
+               self._draw_waveforms()
+               glDisable(GL_SCISSOR_TEST)
+               #swap buffer into display
                self.SwapBuffers()
                self.semaphore.release()
 
@@ -229,8 +239,16 @@
                        glTranslatef(x_trans, -self.y_min, 0)
                        #draw the points/lines
                        glColor3f(*color_spec)
-                       #if marker == '+': #TODO make a texture?
-                       #        points = numpy.concatenate([((x, y+4), (x, 
y-4), (x+4, y), (x-4, y)) for x, y in points])
+                       if marker == '+': #TODO slow, slow, slow
+                               points_4 = numpy.array(zip(points, points, 
points, points))
+                               points_4 = points_4 + .01*numpy.array([
+                                               ((self.x_max-self.x_min), 0), 
+                                               (-(self.x_max-self.x_min), 0), 
+                                               (0, (self.y_max-self.y_min)), 
+                                               (0, -(self.y_max-self.y_min)),
+                                       ]
+                               )
+                               points = points_4.reshape(len(points)*4, 2)
                        glVertexPointer(2, GL_FLOAT, 0, points)
                        glDrawArrays({None: GL_LINE_STRIP, '.': GL_POINTS, '+': 
GL_LINES}[marker], 0, len(points))
                        glPopMatrix()
@@ -241,17 +259,8 @@
                Save the commands to a compiled list.
                """
                ##################################################
-               # Clear Around Border
+               # Draw Border
                ##################################################
-               glColor4f(*BACKGROUND_COLOR_SPEC)
-               self._draw_rect(0, 0, self.width, self.padding_top)
-               self._draw_rect(self.width-self.padding_right, 0, 
self.padding_right, self.height)
-               self._draw_rect(0, self.height-self.padding_bottom, self.width, 
self.padding_bottom)
-               self._draw_rect(0, 0, self.padding_left, self.height)
-
-               ##################################################
-               # Draw Inner Border
-               ##################################################
                glColor3f(*GRID_LINE_COLOR_SPEC)
                glBegin(GL_LINE_LOOP)
                glVertex3f(self.padding_left, self.padding_top, 0)

Modified: gnuradio/branches/developers/jblum/gr-wxglgui/src/python/scopesink.py
===================================================================
--- gnuradio/branches/developers/jblum/gr-wxglgui/src/python/scopesink.py       
2008-07-03 05:41:15 UTC (rev 8774)
+++ gnuradio/branches/developers/jblum/gr-wxglgui/src/python/scopesink.py       
2008-07-03 23:51:27 UTC (rev 8775)
@@ -118,14 +118,14 @@
                hbox = wx.BoxSizer(wx.HORIZONTAL)
                control_box.Add(hbox, 1, wx.EXPAND)
                hbox.Add(wx.StaticText(self, -1, ' Units/Div '), 1, 
wx.ALIGN_CENTER_VERTICAL)
-               self.y_buttons = common.IncrDecrButtons(self, 
self._on_incr_x_divs, self._on_decr_x_divs)
+               self.y_buttons = common.IncrDecrButtons(self, 
self._on_incr_y_divs, self._on_decr_y_divs)
                hbox.Add(self.y_buttons, 0, wx.ALIGN_CENTER_VERTICAL)
                hbox.AddSpacer(SPACING)
                #y axis ref lvl
                hbox = wx.BoxSizer(wx.HORIZONTAL)
                control_box.Add(hbox, 1, wx.EXPAND)
                hbox.Add(wx.StaticText(self, -1, ' Y Offset '), 1, 
wx.ALIGN_CENTER_VERTICAL)
-               self.y_off_buttons = common.IncrDecrButtons(self, 
self._on_incr_x_divs, self._on_decr_x_divs)
+               self.y_off_buttons = common.IncrDecrButtons(self, 
self._on_incr_y_off, self._on_decr_y_off)
                hbox.Add(self.y_off_buttons, 0, wx.ALIGN_CENTER_VERTICAL)
                hbox.AddSpacer(SPACING)
                





reply via email to

[Prev in Thread] Current Thread [Next in Thread]