| 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 | self.CreateStatusBar() |
| 27 | |
| 28 | tb.AddSimpleTool(10, images.getNewBitmap(), "New", "Long help for 'New'") |
| 29 | #tb.AddLabelTool(10, "New", images.getNewBitmap(), shortHelp="New", longHelp="Long help for 'New'") |
| 30 | EVT_TOOL(self, 10, self.OnToolClick) |
| 31 | EVT_TOOL_RCLICKED(self, 10, self.OnToolRClick) |
| 32 | |
| 33 | tb.AddSimpleTool(20, images.getOpenBitmap(), "Open", "Long help for 'Open'") |
| 34 | EVT_TOOL(self, 20, self.OnToolClick) |
| 35 | EVT_TOOL_RCLICKED(self, 20, self.OnToolRClick) |
| 36 | |
| 37 | tb.AddSeparator() |
| 38 | tb.AddSimpleTool(30, images.getCopyBitmap(), "Copy", "Long help for 'Copy'") |
| 39 | EVT_TOOL(self, 30, self.OnToolClick) |
| 40 | EVT_TOOL_RCLICKED(self, 30, self.OnToolRClick) |
| 41 | |
| 42 | tb.AddSimpleTool(40, images.getPasteBitmap(), "Paste", "Long help for 'Paste'") |
| 43 | EVT_TOOL(self, 40, self.OnToolClick) |
| 44 | EVT_TOOL_RCLICKED(self, 40, self.OnToolRClick) |
| 45 | |
| 46 | tb.AddSeparator() |
| 47 | |
| 48 | tool = tb.AddCheckTool(50, images.getTog1Bitmap(), |
| 49 | shortHelp="Toggle this") |
| 50 | EVT_TOOL(self, 50, self.OnToolClick) |
| 51 | |
| 52 | ## tb.AddCheckTool(60, images.getTog1Bitmap(), images.getTog2Bitmap(), |
| 53 | ## shortHelp="Toggle with 2 bitmaps") |
| 54 | ## EVT_TOOL(self, 60, self.OnToolClick) |
| 55 | |
| 56 | EVT_TOOL_ENTER(self, -1, self.OnToolEnter) |
| 57 | EVT_TOOL_RCLICKED(self, -1, self.OnToolRClick) # Match all |
| 58 | EVT_TIMER(self, -1, self.OnClearSB) |
| 59 | |
| 60 | if wxPlatform != "__WXMAC__": |
| 61 | tb.AddSeparator() |
| 62 | cbID = wxNewId() |
| 63 | tb.AddControl(wxComboBox(tb, cbID, "", choices=["", "This", "is a", "wxComboBox"], |
| 64 | size=(150,-1), style=wxCB_DROPDOWN)) |
| 65 | EVT_COMBOBOX(self, cbID, self.OnCombo) |
| 66 | |
| 67 | tb.Realize() |
| 68 | |
| 69 | |
| 70 | def OnToolClick(self, event): |
| 71 | self.log.WriteText("tool %s clicked\n" % event.GetId()) |
| 72 | |
| 73 | def OnToolRClick(self, event): |
| 74 | self.log.WriteText("tool %s right-clicked\n" % event.GetId()) |
| 75 | |
| 76 | def OnCombo(self, event): |
| 77 | self.log.WriteText("combobox item selected: %s\n" % event.GetString()) |
| 78 | |
| 79 | def OnToolEnter(self, event): |
| 80 | self.log.WriteText('OnToolEnter: %s, %s\n' % (event.GetId(), event.GetInt())) |
| 81 | if self.timer is None: |
| 82 | self.timer = wxTimer(self) |
| 83 | if self.timer.IsRunning(): |
| 84 | self.timer.Stop() |
| 85 | self.timer.Start(2000) |
| 86 | event.Skip() |
| 87 | |
| 88 | |
| 89 | def OnClearSB(self, event): # called for the timer event handler |
| 90 | self.SetStatusText("") |
| 91 | self.timer.Stop() |
| 92 | self.timer = None |
| 93 | |
| 94 | |
| 95 | def OnCloseWindow(self, event): |
| 96 | if self.timer is not None: |
| 97 | self.timer.Stop() |
| 98 | self.timer = None |
| 99 | self.Destroy() |
| 100 | |
| 101 | #--------------------------------------------------------------------------- |
| 102 | |
| 103 | def runTest(frame, nb, log): |
| 104 | win = TestToolBar(frame, log) |
| 105 | frame.otherWin = win |
| 106 | win.Show(True) |
| 107 | |
| 108 | #--------------------------------------------------------------------------- |
| 109 | |
| 110 | |
| 111 | |
| 112 | |
| 113 | |
| 114 | |
| 115 | overview = """\ |
| 116 | |
| 117 | """ |
| 118 | |
| 119 | |
| 120 | |
| 121 | |
| 122 | if __name__ == '__main__': |
| 123 | import sys,os |
| 124 | import run |
| 125 | run.main(['', os.path.basename(sys.argv[0])]) |
| 126 | |