[Tutor] GUI design
Nicholas Wieland
nicholas_wieland@yahoo.it
Sun Jan 19 10:41:18 2003
Hello,
I'd like some comments and suggestions about my design: personally I
think it's quite horrible and I'm sure it comes from all the bad habits
I learned using C and GTK+ (BTW: I _love_ GTK+, but it's *so*
different...).
I'm using wxPython 2.4.0.1, but I don't think it's important.
I want my classes to be rausable and *clean*.
from wxPython.wx import *
from wxPython.lib.wxPlotCanvas import *
class App( wxApp ):
def OnInit( self ):
frame = Frame()
frame.Show( 1 )
self.SetTopWindow( frame )
return 1
class Frame( wxFrame ):
def __init__( self ):
wxFrame.__init__( self, None, -1, "ToolBar" )
ID_ENTER_M = wxNewId()
ID_EXIT_M = wxNewId()
ID_ENTER_T = wxNewId()
menu_bar = wxMenuBar()
menu_bar.Append( self.G_FileMenu( ID_ENTER_M,
ID_EXIT_M ),
"&File" );
self.SetMenuBar( menu_bar )
self.G_ToolBox( ID_ENTER_T )
def G_FileMenu( self, ID_ENTER_M, ID_EXIT_M ):
menu_file = wxMenu()
menu_file.Append( ID_ENTER_M, "&Enter...",
"Enter a measure" )
EVT_MENU( self, ID_ENTER_M,
self.OnEnter )
menu_file.AppendSeparator()
menu_file.Append( ID_EXIT_M, "E&xit",
"Exit application" )
EVT_MENU( self, ID_EXIT_M, self.OnExit )
return menu_file
def G_ToolBox( self, ID_ENTER_T ):
tb = self.CreateToolBar( wxTB_HORIZONTAL|
wxNO_BORDER|wxTB_FLAT )
meter_icon = wxBitmap( "meter.xpm", wxBITMAP_TYPE_XPM )
tb.AddSimpleTool( ID_ENTER_T, meter_icon,
"Enter...", "Enter a measure..." )
EVT_TOOL( self, ID_ENTER_T, self.OnEnter )
tb.Realize()
def OnEnter( self, event ):
mf = wxMiniFrame( self, -1, "Enter record",
pos = wxDefaultPosition,
size = wxSize( 140, 120 ),
style = wxDEFAULT_FRAME_STYLE )
mf.Show( 1 )
def OnExit( self, event ):
self.Close( 1 )
app = App( 0 )
app.MainLoop()
As you can see I don't like having a lot of stuff in __init__, so I
tried to make the class more modular... but I'm obviously wrong, this
code IS NOT reusable, G_ToolBox and G_FileMenu are a big nonsense. I'm
a little lost :)
Every comment, suggestion, pointers to 'state of the art' code,
flame-war and *PLONK* is greatly appreciated.
TIA,
Nicholas