1 | |
---|
2 | import wx |
---|
3 | from wx import ToolBar as Tbar |
---|
4 | |
---|
5 | UNDO_ID = wx.NewId() |
---|
6 | REDO_ID = wx.NewId() |
---|
7 | BOOKMARK_ID = wx.NewId() |
---|
8 | SAVE_ID = wx.NewId() |
---|
9 | ZOOM_IN_ID = wx.NewId() |
---|
10 | ZOOM_OUT_ID = wx.NewId() |
---|
11 | ZOOM_ID = wx.NewId() |
---|
12 | DRAG_ID = wx.NewId() |
---|
13 | RESET_ID = wx.NewId() |
---|
14 | PREVIEW_ID = wx.NewId() |
---|
15 | PRINT_ID = wx.NewId() |
---|
16 | CURRENT_APPLICATION = wx.NewId() |
---|
17 | |
---|
18 | class ToolBar(Tbar): |
---|
19 | def __init__(self, parent, *args, **kwds): |
---|
20 | Tbar.__init__(self, parent, *args, **kwds) |
---|
21 | self.parent = parent |
---|
22 | self.do_layout() |
---|
23 | self.on_bind_button() |
---|
24 | |
---|
25 | def do_layout(self): |
---|
26 | """ |
---|
27 | """ |
---|
28 | tbar_size = (-1,-1) |
---|
29 | save_bmp = wx.ArtProvider.GetBitmap(wx.ART_FILE_SAVE, wx.ART_TOOLBAR, |
---|
30 | size=tbar_size) |
---|
31 | self.AddLabelTool(SAVE_ID, 'Save', save_bmp, shortHelp='Save') |
---|
32 | |
---|
33 | bookmark_bmp = wx.ArtProvider.GetBitmap(wx.ART_ADD_BOOKMARK, wx.ART_TOOLBAR, |
---|
34 | size=tbar_size) |
---|
35 | self.AddLabelTool(BOOKMARK_ID, 'Bookmark', bookmark_bmp,shortHelp='Bookmark') |
---|
36 | |
---|
37 | zoom_in_bmp = wx.ArtProvider.GetBitmap(wx.ART_GO_UP, wx.ART_TOOLBAR, |
---|
38 | size=tbar_size) |
---|
39 | self.AddLabelTool(ZOOM_IN_ID, 'Zoom in', zoom_in_bmp,shortHelp='Zoom in') |
---|
40 | |
---|
41 | zoom_out_bmp = wx.ArtProvider.GetBitmap(wx.ART_GO_DOWN, wx.ART_TOOLBAR, |
---|
42 | size=tbar_size) |
---|
43 | self.AddLabelTool(ZOOM_OUT_ID,'Zoom out',zoom_out_bmp,shortHelp='Zoom out') |
---|
44 | |
---|
45 | zoom_bmp = wx.ArtProvider.GetBitmap(wx.ART_GO_FORWARD, wx.ART_TOOLBAR, |
---|
46 | size=tbar_size) |
---|
47 | self.AddLabelTool(ZOOM_ID, 'Zoom', zoom_bmp,shortHelp='Zoom') |
---|
48 | |
---|
49 | drag_bmp = wx.ArtProvider.GetBitmap(wx.ART_REMOVABLE, wx.ART_TOOLBAR, |
---|
50 | size=tbar_size) |
---|
51 | self.AddLabelTool(DRAG_ID, 'Drag', drag_bmp,shortHelp='Drag') |
---|
52 | |
---|
53 | preview_bmp = wx.ArtProvider.GetBitmap(wx.ART_REPORT_VIEW, wx.ART_TOOLBAR, |
---|
54 | size=tbar_size) |
---|
55 | self.AddLabelTool(PREVIEW_ID, 'Preview', preview_bmp,shortHelp='Report') |
---|
56 | |
---|
57 | print_bmp = wx.ArtProvider.GetBitmap(wx.ART_PRINT, wx.ART_TOOLBAR, |
---|
58 | size=tbar_size) |
---|
59 | self.AddLabelTool(PRINT_ID, 'Print', print_bmp,shortHelp='Print') |
---|
60 | |
---|
61 | undo_bmp = wx.ArtProvider.GetBitmap(wx.ART_UNDO, wx.ART_TOOLBAR, |
---|
62 | size=tbar_size) |
---|
63 | self.AddLabelTool(UNDO_ID, 'Undo', undo_bmp,shortHelp='Undo') |
---|
64 | |
---|
65 | |
---|
66 | redo_bmp = wx.ArtProvider.GetBitmap(wx.ART_REDO, wx.ART_TOOLBAR, |
---|
67 | size=tbar_size) |
---|
68 | self.AddLabelTool(REDO_ID, 'Redo', redo_bmp,shortHelp='Redo') |
---|
69 | self.button = wx.Button(self, -1, 'Welcome') |
---|
70 | self.button.SetForegroundColour('black') |
---|
71 | self.button.SetBackgroundColour('#1874CD') |
---|
72 | #self.button.Disable() |
---|
73 | self.AddControl(self.button) |
---|
74 | |
---|
75 | self.SetToolBitmapSize(tbar_size) |
---|
76 | self.Realize() |
---|
77 | |
---|
78 | def on_bind_button(self): |
---|
79 | """ |
---|
80 | """ |
---|
81 | if self.parent is not None: |
---|
82 | self.parent.Bind(wx.EVT_TOOL, self.parent.on_redo_panel,id=REDO_ID) |
---|
83 | self.parent.Bind(wx.EVT_TOOL, self.parent.on_undo_panel,id=UNDO_ID) |
---|
84 | self.parent.Bind(wx.EVT_TOOL, self.parent.on_bookmark_panel,id=BOOKMARK_ID) |
---|
85 | self.parent.Bind(wx.EVT_TOOL, self.parent.on_save_panel,id=SAVE_ID) |
---|
86 | self.parent.Bind(wx.EVT_TOOL, self.parent.on_zoom_in_panel,id=ZOOM_IN_ID) |
---|
87 | self.parent.Bind(wx.EVT_TOOL, self.parent.on_zoom_out_panel,id=ZOOM_OUT_ID) |
---|
88 | self.parent.Bind(wx.EVT_TOOL, self.parent.on_zoom_panel,id=ZOOM_ID) |
---|
89 | self.parent.Bind(wx.EVT_TOOL, self.parent.on_drag_panel,id=DRAG_ID) |
---|
90 | self.parent.Bind(wx.EVT_TOOL, self.parent.on_reset_panel,id=RESET_ID) |
---|
91 | self.parent.Bind(wx.EVT_TOOL, self.parent.on_preview_panel,id=PREVIEW_ID) |
---|
92 | self.parent.Bind(wx.EVT_TOOL, self.parent.on_print_panel,id=PRINT_ID) |
---|
93 | |
---|
94 | |
---|
95 | def set_active_perspective(self, name='Welcome'): |
---|
96 | """ |
---|
97 | """ |
---|
98 | print "set button" |
---|
99 | self.button.SetLabel(str(name)) |
---|
100 | |
---|
101 | def update_button(self, panel=None): |
---|
102 | """ |
---|
103 | """ |
---|
104 | if panel is None: |
---|
105 | #self.Disable() |
---|
106 | self.EnableTool(PRINT_ID, False) |
---|
107 | self.EnableTool(UNDO_ID,False) |
---|
108 | self.EnableTool(REDO_ID, False) |
---|
109 | self.EnableTool(ZOOM_ID, False) |
---|
110 | self.EnableTool(ZOOM_IN_ID, False) |
---|
111 | self.EnableTool(ZOOM_OUT_ID, False) |
---|
112 | self.EnableTool(BOOKMARK_ID, False) |
---|
113 | self.EnableTool(PREVIEW_ID, False) |
---|
114 | self.EnableTool(SAVE_ID, False) |
---|
115 | self.EnableTool(DRAG_ID, False) |
---|
116 | self.EnableTool(RESET_ID, False) |
---|
117 | else: |
---|
118 | self.Enable() |
---|
119 | self.EnableTool(PRINT_ID, panel.is_print_enabled()) |
---|
120 | self.EnableTool(UNDO_ID, panel.is_undo_enabled()) |
---|
121 | self.EnableTool(REDO_ID, panel.is_redo_enabled()) |
---|
122 | self.EnableTool(ZOOM_ID, panel.is_zoom_enabled()) |
---|
123 | self.EnableTool(ZOOM_IN_ID, panel.is_zoom_in_enabled()) |
---|
124 | self.EnableTool(ZOOM_OUT_ID, panel.is_zoom_out_enabled()) |
---|
125 | self.EnableTool(BOOKMARK_ID, panel.is_bookmark_enabled()) |
---|
126 | self.EnableTool(PREVIEW_ID, panel.is_preview_enabled()) |
---|
127 | self.EnableTool(SAVE_ID, panel.is_save_enabled()) |
---|
128 | self.EnableTool(DRAG_ID, panel.is_drag_enabled()) |
---|
129 | self.EnableTool(RESET_ID, panel.is_reset_enabled()) |
---|
130 | |
---|
131 | |
---|
132 | |
---|
133 | |
---|