[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] r8047 - gnuradio/branches/developers/michaelld/wxgui/g
From: |
michaelld |
Subject: |
[Commit-gnuradio] r8047 - gnuradio/branches/developers/michaelld/wxgui/gr-wxgui/src/python |
Date: |
Wed, 19 Mar 2008 09:55:03 -0600 (MDT) |
Author: michaelld
Date: 2008-03-19 09:55:03 -0600 (Wed, 19 Mar 2008)
New Revision: 8047
Modified:
gnuradio/branches/developers/michaelld/wxgui/gr-wxgui/src/python/stdgui2.py
Log:
+ Added lots of comments ;)
+ Added "DoClose" and "DoSetup" methods to all but the stdapp:
* DoClose: sends a "close" command up the chain into the top_block
(inherited through the user's app). Right now, this method does
nothing ... will hook it up next.
* DoSetup: Separate out the "top_block" creation from starting or
stopping it. Allows for the user's app to do post-GUI
configuration, before the top_block is started. Right now, this
method does nothing -- used elsewhere, and important as part
of the UI setup process.
+ Added position, size, usage string, option to create the menu bar or
not, and debugging flag to the stdapp, which are propogated as
appropriate down through the stdframe, stdpanel, and std_top_block.
Modified:
gnuradio/branches/developers/michaelld/wxgui/gr-wxgui/src/python/stdgui2.py
===================================================================
--- gnuradio/branches/developers/michaelld/wxgui/gr-wxgui/src/python/stdgui2.py
2008-03-19 15:46:45 UTC (rev 8046)
+++ gnuradio/branches/developers/michaelld/wxgui/gr-wxgui/src/python/stdgui2.py
2008-03-19 15:55:03 UTC (rev 8047)
@@ -1,5 +1,5 @@
#
-# Copyright 2004 Free Software Foundation, Inc.
+# Copyright 2004, 2008 Free Software Foundation, Inc.
#
# This file is part of GNU Radio
#
@@ -21,72 +21,221 @@
'''A simple wx gui for GNU Radio applications'''
-import wx
-import sys
+import wx, sys
from gnuradio import gr
-
class stdapp (wx.App):
- def __init__ (self, top_block_maker, title="GNU Radio", nstatus=2):
- self.top_block_maker = top_block_maker
- self.title = title
+ def __init__ (self, top_block_maker, title="GNU Radio", nstatus=2,
+ pos=wx.DefaultPosition, size=wx.DefaultSize, usage=None,
+ do_menu_bar=False, debug=False):
+ # Save inputs, to be used in the 'OnInit' method, which is
+ # called from somewhere in the guts of wx.App.__init__ .
+ self._top_block_maker = top_block_maker
+ self._title = title
self._nstatus = nstatus
- # All our initialization must come before calling wx.App.__init__.
- # OnInit is called from somewhere in the guts of __init__.
+ self._do_menu_bar = do_menu_bar
+ self._pos = pos
+ self._size = size
+ self._usage = usage
+ self._debug = debug
+
+ # All the initialization must come before calling wx.App.__init__.
wx.App.__init__ (self, redirect=False)
def OnInit (self):
- frame = stdframe (self.top_block_maker, self.title, self._nstatus)
+ # create the app's frame, using the provided parameters this
+ # will also set up the top_block, but not start it.
+ frame = stdframe (self._top_block_maker, self._title, self._nstatus,
+ self._pos, self._size, self._usage,
+ self._do_menu_bar, self._debug)
+
+ # show the frame
frame.Show (True)
+
+ # set the frame to be the top window
self.SetTopWindow (frame)
+
+ # set up the app, including finally starting the top_block
+ frame.DoSetup ()
return True
-
class stdframe (wx.Frame):
- def __init__ (self, top_block_maker, title="GNU Radio", nstatus=2):
- # print "stdframe.__init__"
- wx.Frame.__init__(self, None, -1, title)
+ def __init__ (self, top_block_maker, title, nstatus, pos, size, usage,
+ do_menu_bar, debug):
+ # init this frame's inherited class
+ wx.Frame.__init__ (self, None, -1, title, pos, size)
- self.CreateStatusBar (nstatus)
- mainmenu = wx.MenuBar ()
+ # store parameters info for later
+ self._debug = debug
+ self._do_menu_bar = do_menu_bar
+ self._nstatus = nstatus
- menu = wx.Menu ()
- item = menu.Append (200, 'E&xit', 'Exit')
- self.Bind (wx.EVT_MENU, self.OnCloseWindow, item)
- mainmenu.Append (menu, "&File")
- self.SetMenuBar (mainmenu)
+ # create a status bar, if requested
+ self._nstatus = nstatus
+ if nstatus is not None:
+ self.CreateStatusBar (nstatus)
- self.Bind (wx.EVT_CLOSE, self.OnCloseWindow)
- self.panel = stdpanel (self, self, top_block_maker)
- vbox = wx.BoxSizer(wx.VERTICAL)
- vbox.Add(self.panel, 1, wx.EXPAND)
- self.SetSizer(vbox)
- self.SetAutoLayout(True)
- vbox.Fit(self)
+ # create a menu bar, if requested
+ if do_menu_bar is True:
+ mainmenu = wx.MenuBar ()
+ menu = wx.Menu ()
+ item = menu.Append (200, 'E&xit', 'Exit')
+ self.Bind (wx.EVT_MENU, self.DoClose, item)
+ mainmenu.Append (menu, "&File")
+ self.SetMenuBar (mainmenu)
- def OnCloseWindow (self, event):
- self.top_block().stop()
+ # bind the frame's close event to the local DoClose method
+ self.Bind (wx.EVT_CLOSE, self.DoClose)
+
+ # create the panel, which in turn will call the user's
+ # code to create the whole GUI & top_block & such
+ self.panel = stdpanel (self, top_block_maker, usage, debug)
+
+ # create the overall frame's vertical (auto) sizer box
+ vbox = wx.BoxSizer (wx.VERTICAL)
+
+ # add the created panel to the vbox
+ vbox.Add (self.panel, 1, wx.EXPAND)
+
+ # set the panel's sizer to this vbox
+ self.SetSizer (vbox)
+
+ # set auto layout for this panel
+ self.SetAutoLayout (True)
+
+ # tell the vbox to fit itself to the panel
+ vbox.Fit (self)
+
+ # if 'pos' is not provided, center this dialog on the screen
+ if pos == wx.DefaultPosition:
+ self.Centre ()
+
+ def DoClose (self, event):
+ """
+ Close this frame. Will tell the panel to close first, then
+ destroy itself (which will also close itself). All incoming
+ events are ignored.
+ """
+ if self._debug:
+ print "stdframe::Close() Starting."
+
+ # tell the panel to close itself
+ self.panel.DoClose ()
+
+ # tell this frame to destroy itself
self.Destroy ()
+ if self._debug:
+ print "stdframe::Close() Returning."
+
+ def set_status_text (self, text, which=0):
+ """
+ Set the status text for bar # 'which' to the provided text.
+ """
+ if self._nstatus is not None:
+ self.GetStatusBar().SetStatusText (text, which)
+
def top_block (self):
+ """
+ Returns the created 'top_block'.
+ Probably never used, but keep for now.
+ """
return self.panel.top_block
-
+
+ def DoSetup (self):
+ """
+ Any application-specific post-GUI layout setup goes here.
+ For now, just tell the created panel to do its setup.
+ """
+ if self._debug:
+ print "stdframe::DoSetup() Starting."
+
+ self.panel.DoSetup ()
+
+ if self._debug:
+ print "stdframe::DoSetup() Returning."
+
class stdpanel (wx.Panel):
- def __init__ (self, parent, frame, top_block_maker):
- # print "stdpanel.__init__"
+ def __init__ (self, parent, top_block_maker, usage, debug):
+ # save parameters
+ self._debug = debug
+ self._parent = parent
+
+ # init this panel
wx.Panel.__init__ (self, parent, -1)
- self.frame = frame
+ # create a vertical (auto) sizer box for placing GUI items
vbox = wx.BoxSizer (wx.VERTICAL)
- self.top_block = top_block_maker (frame, self, vbox, sys.argv)
+
+ # call the method for creating the top_block
+ try:
+ # try the "new" method first
+ self.top_block = top_block_maker (parent, self, vbox, sys.argv,
+ usage, debug)
+ except:
+ # try the "old" method second
+ self.top_block = top_block_maker (parent, self, vbox, sys.argv)
+
self.SetSizer (vbox)
self.SetAutoLayout (True)
vbox.Fit (self)
+ def DoClose (self):
+ if self._debug:
+ print "stdpanel:DoClose() Starting."
+
+ # tell the top_block to close itself
+ self.top_block.DoClose ()
+
+ # stop the top_block
+ self.top_block.stop ()
+
+ if self._debug:
+ print "stdpanel:DoClose() Starting."
+
+ def DoSetup (self):
+ """
+ Set up the application - anything that must be done before
+ starting the top_block running.
+ """
+ if self._debug:
+ print "stdpanel::DoSetup() Starting."
+
+ # set up the top_block (to be overloaded by the user's app)
+ self.top_block.DoSetup ()
+
+ # set the top_block going
self.top_block.start ()
+ if self._debug:
+ print "stdpanel::DoSetup() Returning."
+
+ def set_status_text (self, text, which=0):
+ """
+ Set the status text for bar # 'which' to the provided text.
+ """
+ self._parent.set_status_text (text, which)
+
class std_top_block (gr.top_block):
- def __init__ (self, parent, panel, vbox, argv):
- # Call the hier_block2 constructor
- # Top blocks have no inputs and outputs
- gr.top_block.__init__(self, "std_top_block")
+ def __init__ (self, frame, panel, vbox, argv, usage='', debug=False):
+ # Call the hier_block2 constructor. Top blocks have no inputs
+ # and outputs - they have to be added by the user's App.
+ gr.top_block.__init__ (self, "std_top_block")
+
+ # save some parameters
+ self._parent = panel
+ self._debug = debug
+
+ def DoClose (self):
+ # empty for standard GNU Radio apps
+ pass
+
+ def DoSetup (self):
+ # empty for standard GNU Radio apps
+ pass
+
+ def set_status_text (self, text, which=0):
+ """
+ Set the status text for bar # 'which' to the provided text.
+ """
+ self._parent.set_status_text (text, which)
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Commit-gnuradio] r8047 - gnuradio/branches/developers/michaelld/wxgui/gr-wxgui/src/python,
michaelld <=