commit-gnuradio
[Top][All Lists]
Advanced

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

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


From: jblum
Subject: [Commit-gnuradio] r8722 - gnuradio/branches/developers/jblum/gr-wxglgui/src/python
Date: Wed, 25 Jun 2008 23:36:32 -0600 (MDT)

Author: jblum
Date: 2008-06-25 23:36:21 -0600 (Wed, 25 Jun 2008)
New Revision: 8722

Modified:
   gnuradio/branches/developers/jblum/gr-wxglgui/src/python/plotter.py
Log:
compiled list, gl command caching

Modified: gnuradio/branches/developers/jblum/gr-wxglgui/src/python/plotter.py
===================================================================
--- gnuradio/branches/developers/jblum/gr-wxglgui/src/python/plotter.py 
2008-06-26 05:34:59 UTC (rev 8721)
+++ gnuradio/branches/developers/jblum/gr-wxglgui/src/python/plotter.py 
2008-06-26 05:36:21 UTC (rev 8722)
@@ -18,37 +18,50 @@
 UNITS_TEXT_COLOR_SPEC = (0, 0, 0, 1) #black
 UNITS_TEXT_FONT_SIZE = 9
 
+GRID_COMPILED_LIST_ID = 1
+
 class _plotter_base(wx.glcanvas.GLCanvas):
+       """!
+       Plotter base class for all plot types.
+       """
        
-       def __init__(self, parent, width, height):
-               
-               self.width = width
-               self.height = height
-               
+       def __init__(self, parent):             
+               """!
+               Create a new plotter base.
+               Initialize GL and register events.
+               @param parent the parent widgit
+               """
                wx.glcanvas.GLCanvas.__init__(self, parent, -1)
                wx.EVT_PAINT(self, self.OnPaint)
+               wx.EVT_SIZE(self, self.OnSize)
                self._gl_init = False
 
-       def OnPaint(self,event):
+       def OnSize(self, event):
+               """!
+               When the window is resized, update the view.
+               """
+               self.width, self.height = self.GetSize()                
+               glViewport(0, 0, self.width, self.height)
+               glMatrixMode(GL_PROJECTION)
+               glLoadIdentity()
+               glOrtho(0, self.width, self.height, 0, 1, 0)            
+               glMatrixMode(GL_MODELVIEW)
+               glLoadIdentity()
+               self._changed = True
+
+       def OnPaint(self, event):
+               """!
+               Respond to paint events, call update.
+               Initialize GL if this is the first paint event.
+               """
                dc = wx.PaintDC(self)
                self.SetCurrent()
                if not self._gl_init:
                        glutInit(len(sys.argv), sys.argv)
-                       glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB)
-                               
+                       glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB)             
                
                        glClearColor(*BACKGROUND_COLOR_SPEC)
-
-                       glViewport(0, 0, self.width, self.height)
-
-                       glMatrixMode(GL_PROJECTION)
-                       glLoadIdentity()
-
-                       glOrtho(0, self.width, self.height, 0, 1, 0)
-                       
-                       glMatrixMode(GL_MODELVIEW)
-                       glLoadIdentity()
-                       self._gl_init = True
-               
+                       self.OnSize(None)
+                       self._gl_init = True            
                self.update()
                return
                
@@ -66,7 +79,7 @@
 
 class grid_plotter(_plotter_base):
        
-       def __init__(self, parent, width, height, units_x, units_y, 
padding_top, padding_right, padding_bottom, padding_left):
+       def __init__(self, parent, units_x, units_y, padding_top, 
padding_right, padding_bottom, padding_left):
                
                self.units_x = units_x
                self.units_y = units_y
@@ -79,9 +92,8 @@
                self.set_grid_x(-1, 1, .2)              
                self.set_grid_y(-1, 1, .4)
                
-               _plotter_base.__init__(self, parent, width, height)
+               _plotter_base.__init__(self, parent)
 
-
        def set_grid_x(self, x_min, x_max, x_step):
                """!
                Set the x grid parameters.
@@ -92,6 +104,7 @@
                self.x_min = float(x_min)
                self.x_max = float(x_max)
                self.x_step = float(x_step)
+               self._changed = True
                
        def set_grid_y(self, y_min, y_max, y_step):
                """!
@@ -103,17 +116,24 @@
                self.y_min = float(y_min)
                self.y_max = float(y_max)
                self.y_step = float(y_step)
+               self._changed = True
        
        def update(self):
-               self.clear()    
-               self._draw_grid()                               
+               self.clear()
+               if self._changed:
+                       glNewList(GRID_COMPILED_LIST_ID, GL_COMPILE)
+                       self._draw_grid()
+                       glEndList()
+                       self._changed = False
+               glCallList(GRID_COMPILED_LIST_ID)
                self.draw()
                return
                                        
        def _draw_grid(self):
                """!
                Draw the border, grid, and units.
-               """             
+               Save the commands to a compiled list.
+               """
                ##################################################
                # Draw Border
                ##################################################
@@ -195,7 +215,7 @@
                #determine the start and stop value
                start = int(math.ceil(min/step))
                stop = int(math.floor(max/step))
-               return [i*step for i in range(start, stop+1)]           
+               return [i*step for i in range(start, stop+1)]
                
        def _draw_line(self, coor1, coor2):
                """!
@@ -211,7 +231,7 @@
 def main():
        app = wx.PySimpleApp()
        frame = wx.Frame(None, -1, 'test', wx.DefaultPosition, wx.Size(700, 
300))
-       canvas = grid_plotter(frame, 700, 300, 'Frequency(Hz)', 
'Amplitude(dB)', 10, 10, 40, 60)
+       canvas = grid_plotter(frame, 'Frequency(Hz)', 'Amplitude(dB)', 10, 10, 
40, 60)
        frame.Show()
        app.MainLoop()
 





reply via email to

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