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