]> git.saurik.com Git - wxWidgets.git/blame - wxPython/demo/ToolBar.py
Typo fix
[wxWidgets.git] / wxPython / demo / ToolBar.py
CommitLineData
8fa876ca
RD
1# 11/21/2003 - Jeff Grimmett (grimmtooth@softhome.net)
2#
3# o Updated for wx namespace
4#
cf694132 5
8fa876ca
RD
6import wx
7import images
96bfd053 8
cf694132
RD
9#---------------------------------------------------------------------------
10
8fa876ca 11class TestToolBar(wx.Frame):
cf694132 12 def __init__(self, parent, log):
8fa876ca 13 wx.Frame.__init__(self, parent, -1, 'Test ToolBar', size=(500, 300))
cf694132 14 self.log = log
185d7c3e 15 self.timer = None
8fa876ca 16 self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
cf694132 17
8fa876ca 18 wx.Window(self, -1).SetBackgroundColour(wx.NamedColour("WHITE"))
cf694132 19
8fa876ca
RD
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
23 | wx.NO_BORDER
24 | wx.TB_FLAT
25 | wx.TB_TEXT
1e4a197e 26 )
8fa876ca
RD
27
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)
cf694132 31 #self.SetToolBar(tb)
8fa876ca 32 # But we're doing it a different way here.
cf694132 33
f94e8b87
RD
34 log.write("Default toolbar tool size: %s\n" % tb.GetToolBitmapSize())
35
cf694132
RD
36 self.CreateStatusBar()
37
15030c51 38 tb.AddSimpleTool(10, images.getNewBitmap(), "New", "Long help for 'New'")
1e4a197e 39 #tb.AddLabelTool(10, "New", images.getNewBitmap(), shortHelp="New", longHelp="Long help for 'New'")
8fa876ca
RD
40 self.Bind(wx.EVT_TOOL, self.OnToolClick, id=10)
41 self.Bind(wx.EVT_TOOL_RCLICKED, self.OnToolRClick, id=10)
cf694132 42
15030c51 43 tb.AddSimpleTool(20, images.getOpenBitmap(), "Open", "Long help for 'Open'")
8fa876ca
RD
44 self.Bind(wx.EVT_TOOL, self.OnToolClick, id=20)
45 self.Bind(wx.EVT_TOOL_RCLICKED, self.OnToolRClick, id=20)
cf694132
RD
46
47 tb.AddSeparator()
15030c51 48 tb.AddSimpleTool(30, images.getCopyBitmap(), "Copy", "Long help for 'Copy'")
8fa876ca
RD
49 self.Bind(wx.EVT_TOOL, self.OnToolClick, id=30)
50 self.Bind(wx.EVT_TOOL_RCLICKED, self.OnToolRClick, id=30)
cf694132 51
15030c51 52 tb.AddSimpleTool(40, images.getPasteBitmap(), "Paste", "Long help for 'Paste'")
8fa876ca
RD
53 self.Bind(wx.EVT_TOOL, self.OnToolClick, id=40)
54 self.Bind(wx.EVT_TOOL_RCLICKED, self.OnToolRClick, id=40)
cf694132
RD
55
56 tb.AddSeparator()
57
15030c51 58 tool = tb.AddCheckTool(50, images.getTog1Bitmap(),
c12de7f8 59 shortHelp="Toggle this")
8fa876ca 60 self.Bind(wx.EVT_TOOL, self.OnToolClick, id=50)
cf694132 61
1e4a197e
RD
62## tb.AddCheckTool(60, images.getTog1Bitmap(), images.getTog2Bitmap(),
63## shortHelp="Toggle with 2 bitmaps")
8fa876ca 64## self.Bind(EVT_TOOL, self.OnToolClick, id=60)
cf694132 65
8fa876ca
RD
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)
9b3d3bc4 69
1fded56b 70 tb.AddSeparator()
8fa876ca
RD
71 cbID = wx.NewId()
72
73 tb.AddControl(
74 wx.ComboBox(
75 tb, cbID, "", choices=["", "This", "is a", "wxComboBox"],
76 size=(150,-1), style=wx.CB_DROPDOWN
77 ))
78
79 self.Bind(wx.EVT_COMBOBOX, self.OnCombo, id=cbID)
80 tb.AddControl(wx.TextCtrl(tb, -1, "Toolbar controls!!", size=(150, -1)))
81
82 # Final thing to do for a toolbar is call the Realize() method. This
83 # causes it to render (more or less, that is).
cf694132
RD
84 tb.Realize()
85
86
cf694132
RD
87 def OnToolClick(self, event):
88 self.log.WriteText("tool %s clicked\n" % event.GetId())
62e8fcee
RD
89 tb = self.GetToolBar()
90 tb.EnableTool(10, not tb.GetToolEnabled(10))
cf694132
RD
91
92 def OnToolRClick(self, event):
93 self.log.WriteText("tool %s right-clicked\n" % event.GetId())
94
c368d904
RD
95 def OnCombo(self, event):
96 self.log.WriteText("combobox item selected: %s\n" % event.GetString())
97
185d7c3e
RD
98 def OnToolEnter(self, event):
99 self.log.WriteText('OnToolEnter: %s, %s\n' % (event.GetId(), event.GetInt()))
8fa876ca 100
185d7c3e 101 if self.timer is None:
8fa876ca
RD
102 self.timer = wx.Timer(self)
103
a92edd31
RD
104 if self.timer.IsRunning():
105 self.timer.Stop()
8fa876ca 106
185d7c3e
RD
107 self.timer.Start(2000)
108 event.Skip()
109
110
de20db99 111 def OnClearSB(self, event): # called for the timer event handler
185d7c3e
RD
112 self.SetStatusText("")
113 self.timer.Stop()
114 self.timer = None
115
116
117 def OnCloseWindow(self, event):
118 if self.timer is not None:
119 self.timer.Stop()
120 self.timer = None
121 self.Destroy()
c368d904 122
cf694132
RD
123#---------------------------------------------------------------------------
124
125def runTest(frame, nb, log):
126 win = TestToolBar(frame, log)
127 frame.otherWin = win
1e4a197e 128 win.Show(True)
cf694132
RD
129
130#---------------------------------------------------------------------------
131
132
133
1e4a197e 134overview = """\
cf694132 135
1e4a197e 136"""
cf694132
RD
137
138
1e4a197e
RD
139if __name__ == '__main__':
140 import sys,os
141 import run
142 run.main(['', os.path.basename(sys.argv[0])])
cf694132 143