]> git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/wxToolBar.py
A little tweak to the usage text
[wxWidgets.git] / wxPython / demo / wxToolBar.py
1 # 11/21/2003 - Jeff Grimmett (grimmtooth@softhome.net)
2 #
3 # o Updated for wx namespace
4 #
5
6 import wx
7 import images
8
9 #---------------------------------------------------------------------------
10
11 class TestToolBar(wx.Frame):
12 def __init__(self, parent, log):
13 wx.Frame.__init__(self, parent, -1, 'Test ToolBar', size=(500, 300))
14 self.log = log
15 self.timer = None
16 self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
17
18 wx.Window(self, -1).SetBackgroundColour(wx.NamedColour("WHITE"))
19
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
26 )
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)
31 #self.SetToolBar(tb)
32 # But we're doing it a different way here.
33
34 log.write("Default toolbar tool size: %s\n" % tb.GetToolBitmapSize())
35
36 self.CreateStatusBar()
37
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)
42
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)
46
47 tb.AddSeparator()
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)
51
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)
55
56 tb.AddSeparator()
57
58 tool = tb.AddCheckTool(50, images.getTog1Bitmap(),
59 shortHelp="Toggle this")
60 self.Bind(wx.EVT_TOOL, self.OnToolClick, id=50)
61
62 ## tb.AddCheckTool(60, images.getTog1Bitmap(), images.getTog2Bitmap(),
63 ## shortHelp="Toggle with 2 bitmaps")
64 ## self.Bind(EVT_TOOL, self.OnToolClick, id=60)
65
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)
69
70 tb.AddSeparator()
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).
84 tb.Realize()
85
86
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))
91
92 def OnToolRClick(self, event):
93 self.log.WriteText("tool %s right-clicked\n" % event.GetId())
94
95 def OnCombo(self, event):
96 self.log.WriteText("combobox item selected: %s\n" % event.GetString())
97
98 def OnToolEnter(self, event):
99 self.log.WriteText('OnToolEnter: %s, %s\n' % (event.GetId(), event.GetInt()))
100
101 if self.timer is None:
102 self.timer = wx.Timer(self)
103
104 if self.timer.IsRunning():
105 self.timer.Stop()
106
107 self.timer.Start(2000)
108 event.Skip()
109
110
111 def OnClearSB(self, event): # called for the timer event handler
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()
122
123 #---------------------------------------------------------------------------
124
125 def runTest(frame, nb, log):
126 win = TestToolBar(frame, log)
127 frame.otherWin = win
128 win.Show(True)
129
130 #---------------------------------------------------------------------------
131
132
133
134 overview = """\
135
136 """
137
138
139 if __name__ == '__main__':
140 import sys,os
141 import run
142 run.main(['', os.path.basename(sys.argv[0])])
143