2 from wxPython
.wx
import *
4 #---------------------------------------------------------------------------
6 class TestToolBar(wxFrame
):
7 def __init__(self
, parent
, log
):
8 wxFrame
.__init
__(self
, parent
, -1, 'Test ToolBar',
9 wxPoint(0,0), wxSize(500, 300))
12 EVT_CLOSE(self
, self
.OnCloseWindow
)
14 wxWindow(self
, -1).SetBackgroundColour(wxNamedColour("WHITE"))
16 tb
= self
.CreateToolBar(wxTB_HORIZONTAL|wxNO_BORDER|wxTB_FLAT
)
17 #tb = wxToolBarSimple(self, -1, wxDefaultPosition, wxDefaultSize,
18 # wxTB_HORIZONTAL | wxNO_BORDER | wxTB_FLAT)
21 self
.CreateStatusBar()
23 tb
.AddSimpleTool(10, wxBitmap('bitmaps/new.bmp', wxBITMAP_TYPE_BMP
),
24 "New", "Long help for 'New'")
25 EVT_TOOL(self
, 10, self
.OnToolClick
)
27 tb
.AddSimpleTool(20, wxBitmap('bitmaps/open.bmp', wxBITMAP_TYPE_BMP
),
28 "Open", "Long help for 'Open'")
29 EVT_TOOL(self
, 20, self
.OnToolClick
)
32 tb
.AddSimpleTool(30, wxBitmap('bitmaps/copy.bmp', wxBITMAP_TYPE_BMP
),
33 "Copy", "Long help for 'Copy'")
34 EVT_TOOL(self
, 30, self
.OnToolClick
)
36 tb
.AddSimpleTool(40, wxBitmap('bitmaps/paste.bmp', wxBITMAP_TYPE_BMP
),
37 "Paste", "Long help for 'Paste'")
38 EVT_TOOL(self
, 40, self
.OnToolClick
)
42 tool
= tb
.AddTool(50, wxBitmap('bitmaps/tog1.bmp', wxBITMAP_TYPE_BMP
),
43 shortHelpString
="Toggle this", isToggle
=true
)
44 EVT_TOOL(self
, 50, self
.OnToolClick
)
46 tb
.AddTool(60, wxBitmap('bitmaps/tog1.bmp', wxBITMAP_TYPE_BMP
),
47 wxBitmap('bitmaps/tog2.bmp', wxBITMAP_TYPE_BMP
),
48 shortHelpString
="Toggle with 2 bitmaps", isToggle
=true
)
49 EVT_TOOL(self
, 60, self
.OnToolClick
)
51 EVT_TOOL_ENTER(self
, -1, self
.OnToolEnter
)
52 EVT_TOOL_RCLICKED(self
, -1, self
.OnToolRClick
) # Match all
53 EVT_TIMER(self
, -1, self
.OnClearSB
)
57 tb
.AddControl(wxComboBox(tb
, cbID
, "", choices
=["", "This", "is a", "wxComboBox"],
58 size
=(150,-1), style
=wxCB_DROPDOWN
))
59 EVT_COMBOBOX(self
, cbID
, self
.OnCombo
)
64 def OnToolClick(self
, event
):
65 self
.log
.WriteText("tool %s clicked\n" % event
.GetId())
67 def OnToolRClick(self
, event
):
68 self
.log
.WriteText("tool %s right-clicked\n" % event
.GetId())
70 def OnCombo(self
, event
):
71 self
.log
.WriteText("combobox item selected: %s\n" % event
.GetString())
73 def OnToolEnter(self
, event
):
74 self
.log
.WriteText('OnToolEnter: %s, %s\n' % (event
.GetId(), event
.GetInt()))
75 if self
.timer
is None:
76 self
.timer
= wxTimer(self
)
77 self
.timer
.Start(2000)
81 def OnClearSB(self
, event
): # called for the timer event handler
82 self
.SetStatusText("")
87 def OnCloseWindow(self
, event
):
88 if self
.timer
is not None:
93 #---------------------------------------------------------------------------
95 def runTest(frame
, nb
, log
):
96 win
= TestToolBar(frame
, log
)
100 #---------------------------------------------------------------------------