]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/wxToolBar.py
2 from wxPython
.wx
import *
6 #---------------------------------------------------------------------------
8 class TestToolBar(wxFrame
):
9 def __init__(self
, parent
, log
):
10 wxFrame
.__init
__(self
, parent
, -1, 'Test ToolBar', size
=(500, 300))
13 EVT_CLOSE(self
, self
.OnCloseWindow
)
15 wxWindow(self
, -1).SetBackgroundColour(wxNamedColour("WHITE"))
17 tb
= self
.CreateToolBar( wxTB_HORIZONTAL
22 #tb = wxToolBarSimple(self, -1, wxDefaultPosition, wxDefaultSize,
23 # wxTB_HORIZONTAL | wxNO_BORDER | wxTB_FLAT)
26 log
.write("Default toolbar tool size: %s\n" % tb
.GetToolBitmapSize())
28 self
.CreateStatusBar()
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
)
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
)
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
)
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
)
50 tool
= tb
.AddCheckTool(50, images
.getTog1Bitmap(),
51 shortHelp
="Toggle this")
52 EVT_TOOL(self
, 50, self
.OnToolClick
)
54 ## tb.AddCheckTool(60, images.getTog1Bitmap(), images.getTog2Bitmap(),
55 ## shortHelp="Toggle with 2 bitmaps")
56 ## EVT_TOOL(self, 60, self.OnToolClick)
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
)
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)))
72 def OnToolClick(self
, event
):
73 self
.log
.WriteText("tool %s clicked\n" % event
.GetId())
74 tb
= self
.GetToolBar()
75 tb
.EnableTool(10, not tb
.GetToolEnabled(10))
77 def OnToolRClick(self
, event
):
78 self
.log
.WriteText("tool %s right-clicked\n" % event
.GetId())
80 def OnCombo(self
, event
):
81 self
.log
.WriteText("combobox item selected: %s\n" % event
.GetString())
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
)
87 if self
.timer
.IsRunning():
89 self
.timer
.Start(2000)
93 def OnClearSB(self
, event
): # called for the timer event handler
94 self
.SetStatusText("")
99 def OnCloseWindow(self
, event
):
100 if self
.timer
is not None:
105 #---------------------------------------------------------------------------
107 def runTest(frame
, nb
, log
):
108 win
= TestToolBar(frame
, log
)
112 #---------------------------------------------------------------------------
126 if __name__
== '__main__':
129 run
.main(['', os
.path
.basename(sys
.argv
[0])])