]> git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/wxToolBar.py
a22833e37ae4fbe8965b8e0cb0081da1089b7ea2
[wxWidgets.git] / wxPython / demo / wxToolBar.py
1
2 from wxPython.wx import *
3
4 import images
5
6 #---------------------------------------------------------------------------
7
8 class TestToolBar(wxFrame):
9 def __init__(self, parent, log):
10 wxFrame.__init__(self, parent, -1, 'Test ToolBar', size=(500, 300))
11 self.log = log
12 self.timer = None
13 EVT_CLOSE(self, self.OnCloseWindow)
14
15 wxWindow(self, -1).SetBackgroundColour(wxNamedColour("WHITE"))
16
17 tb = self.CreateToolBar( wxTB_HORIZONTAL
18 | wxNO_BORDER
19 | wxTB_FLAT
20 | wxTB_TEXT
21 )
22 #tb = wxToolBarSimple(self, -1, wxDefaultPosition, wxDefaultSize,
23 # wxTB_HORIZONTAL | wxNO_BORDER | wxTB_FLAT)
24 #self.SetToolBar(tb)
25
26 log.write("Default toolbar tool size: %s\n" % tb.GetToolBitmapSize())
27
28 self.CreateStatusBar()
29
30 tb.AddSimpleTool(10, images.getNewBitmap(), "New", "Long help for 'New'")
31 #tb.AddLabelTool(10, "New", images.getNewBitmap(), shortHelp="New", longHelp="Long help for 'New'")
32 EVT_TOOL(self, 10, self.OnToolClick)
33 EVT_TOOL_RCLICKED(self, 10, self.OnToolRClick)
34
35 tb.AddSimpleTool(20, images.getOpenBitmap(), "Open", "Long help for 'Open'")
36 EVT_TOOL(self, 20, self.OnToolClick)
37 EVT_TOOL_RCLICKED(self, 20, self.OnToolRClick)
38
39 tb.AddSeparator()
40 tb.AddSimpleTool(30, images.getCopyBitmap(), "Copy", "Long help for 'Copy'")
41 EVT_TOOL(self, 30, self.OnToolClick)
42 EVT_TOOL_RCLICKED(self, 30, self.OnToolRClick)
43
44 tb.AddSimpleTool(40, images.getPasteBitmap(), "Paste", "Long help for 'Paste'")
45 EVT_TOOL(self, 40, self.OnToolClick)
46 EVT_TOOL_RCLICKED(self, 40, self.OnToolRClick)
47
48 tb.AddSeparator()
49
50 tool = tb.AddCheckTool(50, images.getTog1Bitmap(),
51 shortHelp="Toggle this")
52 EVT_TOOL(self, 50, self.OnToolClick)
53
54 ## tb.AddCheckTool(60, images.getTog1Bitmap(), images.getTog2Bitmap(),
55 ## shortHelp="Toggle with 2 bitmaps")
56 ## EVT_TOOL(self, 60, self.OnToolClick)
57
58 EVT_TOOL_ENTER(self, -1, self.OnToolEnter)
59 EVT_TOOL_RCLICKED(self, -1, self.OnToolRClick) # Match all
60 EVT_TIMER(self, -1, self.OnClearSB)
61
62 tb.AddSeparator()
63 cbID = wxNewId()
64 tb.AddControl(wxComboBox(tb, cbID, "", choices=["", "This", "is a", "wxComboBox"],
65 size=(150,-1), style=wxCB_DROPDOWN))
66 EVT_COMBOBOX(self, cbID, self.OnCombo)
67 tb.AddControl(wxTextCtrl(tb, -1, "Toolbar controls!!", size=(150, -1)))
68
69 tb.Realize()
70
71
72 def OnToolClick(self, event):
73 self.log.WriteText("tool %s clicked\n" % event.GetId())
74
75 def OnToolRClick(self, event):
76 self.log.WriteText("tool %s right-clicked\n" % event.GetId())
77
78 def OnCombo(self, event):
79 self.log.WriteText("combobox item selected: %s\n" % event.GetString())
80
81 def OnToolEnter(self, event):
82 self.log.WriteText('OnToolEnter: %s, %s\n' % (event.GetId(), event.GetInt()))
83 if self.timer is None:
84 self.timer = wxTimer(self)
85 if self.timer.IsRunning():
86 self.timer.Stop()
87 self.timer.Start(2000)
88 event.Skip()
89
90
91 def OnClearSB(self, event): # called for the timer event handler
92 self.SetStatusText("")
93 self.timer.Stop()
94 self.timer = None
95
96
97 def OnCloseWindow(self, event):
98 if self.timer is not None:
99 self.timer.Stop()
100 self.timer = None
101 self.Destroy()
102
103 #---------------------------------------------------------------------------
104
105 def runTest(frame, nb, log):
106 win = TestToolBar(frame, log)
107 frame.otherWin = win
108 win.Show(True)
109
110 #---------------------------------------------------------------------------
111
112
113
114
115
116
117 overview = """\
118
119 """
120
121
122
123
124 if __name__ == '__main__':
125 import sys,os
126 import run
127 run.main(['', os.path.basename(sys.argv[0])])
128