]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/ToolBar.py
1 # 11/21/2003 - Jeff Grimmett (grimmtooth@softhome.net)
3 # o Updated for wx namespace
9 #---------------------------------------------------------------------------
11 class TestToolBar(wx
.Frame
):
12 def __init__(self
, parent
, log
):
13 wx
.Frame
.__init
__(self
, parent
, -1, 'Test ToolBar', size
=(500, 300))
16 self
.Bind(wx
.EVT_CLOSE
, self
.OnCloseWindow
)
18 wx
.Window(self
, -1).SetBackgroundColour(wx
.NamedColour("WHITE"))
20 # Use the wxFrame internals to create the toolbar and associate it all
21 # in one tidy method call.
22 tb
= self
.CreateToolBar( wx
.TB_HORIZONTAL
28 # Here's a 'simple' toolbar example, and how to bind it using SetToolBar()
29 #tb = wx.ToolBarSimple(self, -1, wx.DefaultPosition, wx.DefaultSize,
30 # wx.TB_HORIZONTAL | wx.NO_BORDER | wx.TB_FLAT)
32 # But we're doing it a different way here.
34 log
.write("Default toolbar tool size: %s\n" % tb
.GetToolBitmapSize())
36 self
.CreateStatusBar()
38 tb
.AddSimpleTool(10, images
.getNewBitmap(), "New", "Long help for 'New'")
39 #tb.AddLabelTool(10, "New", images.getNewBitmap(), shortHelp="New", longHelp="Long help for 'New'")
40 self
.Bind(wx
.EVT_TOOL
, self
.OnToolClick
, id=10)
41 self
.Bind(wx
.EVT_TOOL_RCLICKED
, self
.OnToolRClick
, id=10)
43 tb
.AddSimpleTool(20, images
.getOpenBitmap(), "Open", "Long help for 'Open'")
44 self
.Bind(wx
.EVT_TOOL
, self
.OnToolClick
, id=20)
45 self
.Bind(wx
.EVT_TOOL_RCLICKED
, self
.OnToolRClick
, id=20)
48 tb
.AddSimpleTool(30, images
.getCopyBitmap(), "Copy", "Long help for 'Copy'")
49 self
.Bind(wx
.EVT_TOOL
, self
.OnToolClick
, id=30)
50 self
.Bind(wx
.EVT_TOOL_RCLICKED
, self
.OnToolRClick
, id=30)
52 tb
.AddSimpleTool(40, images
.getPasteBitmap(), "Paste", "Long help for 'Paste'")
53 self
.Bind(wx
.EVT_TOOL
, self
.OnToolClick
, id=40)
54 self
.Bind(wx
.EVT_TOOL_RCLICKED
, self
.OnToolRClick
, id=40)
58 tool
= tb
.AddCheckTool(50, images
.getTog1Bitmap(),
59 shortHelp
="Toggle this")
60 self
.Bind(wx
.EVT_TOOL
, self
.OnToolClick
, id=50)
62 ## tb.AddCheckTool(60, images.getTog1Bitmap(), images.getTog2Bitmap(),
63 ## shortHelp="Toggle with 2 bitmaps")
64 ## self.Bind(EVT_TOOL, self.OnToolClick, id=60)
66 self
.Bind(wx
.EVT_TOOL_ENTER
, self
.OnToolEnter
)
67 self
.Bind(wx
.EVT_TOOL_RCLICKED
, self
.OnToolRClick
) # Match all
68 self
.Bind(wx
.EVT_TIMER
, self
.OnClearSB
)
75 tb
, cbID
, "", choices
=["", "This", "is a", "wxComboBox"],
76 size
=(150,-1), style
=wx
.CB_DROPDOWN
79 self
.Bind(wx
.EVT_COMBOBOX
, self
.OnCombo
, id=cbID
)
80 tb
.AddControl(wx
.TextCtrl(tb
, -1, "Toolbar controls!!", size
=(150, -1)))
82 # Final thing to do for a toolbar is call the Realize() method. This
83 # causes it to render (more or less, that is).
87 def OnToolClick(self
, event
):
88 self
.log
.WriteText("tool %s clicked\n" % event
.GetId())
89 tb
= self
.GetToolBar()
90 tb
.EnableTool(10, not tb
.GetToolEnabled(10))
92 def OnToolRClick(self
, event
):
93 self
.log
.WriteText("tool %s right-clicked\n" % event
.GetId())
95 def OnCombo(self
, event
):
96 self
.log
.WriteText("combobox item selected: %s\n" % event
.GetString())
98 def OnToolEnter(self
, event
):
99 self
.log
.WriteText('OnToolEnter: %s, %s\n' % (event
.GetId(), event
.GetInt()))
101 if self
.timer
is None:
102 self
.timer
= wx
.Timer(self
)
104 if self
.timer
.IsRunning():
107 self
.timer
.Start(2000)
111 def OnClearSB(self
, event
): # called for the timer event handler
112 self
.SetStatusText("")
117 def OnCloseWindow(self
, event
):
118 if self
.timer
is not None:
123 #---------------------------------------------------------------------------
125 def runTest(frame
, nb
, log
):
126 win
= TestToolBar(frame
, log
)
130 #---------------------------------------------------------------------------
139 if __name__
== '__main__':
142 run
.main(['', os
.path
.basename(sys
.argv
[0])])