1 | |
---|
2 | import wx |
---|
3 | import os |
---|
4 | from wx import ToolBar as Tbar |
---|
5 | |
---|
6 | |
---|
7 | from sans.guiframe.gui_style import GUIFRAME_ID |
---|
8 | from sans.guiframe.gui_style import GUIFRAME_ICON |
---|
9 | |
---|
10 | |
---|
11 | def clear_image(image): |
---|
12 | w, h = image.GetSize() |
---|
13 | factor = 155 |
---|
14 | compress = lambda x: int(x * factor/255.) + factor |
---|
15 | for y in range(h): |
---|
16 | for x in range(w): |
---|
17 | grey = compress(image.GetGreen(x, y)) |
---|
18 | image.SetRGB(x, y, grey, grey, grey) |
---|
19 | if image.HasAlpha(): |
---|
20 | image.ConvertAlphaToMask() |
---|
21 | return image |
---|
22 | |
---|
23 | class GUIToolBar(Tbar): |
---|
24 | """ |
---|
25 | Implement toolbar for guiframe |
---|
26 | """ |
---|
27 | def __init__(self, parent, *args, **kwds): |
---|
28 | Tbar.__init__(self, parent, *args, **kwds) |
---|
29 | self.parent = parent |
---|
30 | self.do_layout() |
---|
31 | self.on_bind_button() |
---|
32 | |
---|
33 | def do_layout(self): |
---|
34 | """ |
---|
35 | """ |
---|
36 | tbar_size = (22, 22) |
---|
37 | button_type = wx.ITEM_NORMAL |
---|
38 | save_im = GUIFRAME_ICON.SAVE_ICON |
---|
39 | save_im.Rescale(tbar_size[0], tbar_size[1], wx.IMAGE_QUALITY_HIGH) |
---|
40 | save_bmp = save_im.ConvertToBitmap() |
---|
41 | #disable_save_bmp = clear_image(save_im).ConvertToBitmap() |
---|
42 | disable_save_bmp = wx.NullBitmap |
---|
43 | self.AddLabelTool(GUIFRAME_ID.SAVE_ID, 'Save', save_bmp, |
---|
44 | disable_save_bmp,button_type, shortHelp='Save') |
---|
45 | self.AddSeparator() |
---|
46 | bookmark_im = GUIFRAME_ICON.BOOKMARK_ICON |
---|
47 | bookmark_im.Rescale(tbar_size[0], tbar_size[1], wx.IMAGE_QUALITY_HIGH) |
---|
48 | bookmark_bmp = bookmark_im.ConvertToBitmap() |
---|
49 | #disable_bookmark_bmp = clear_image(bookmark_im).ConvertToBitmap() |
---|
50 | disable_bookmark_bmp = wx.NullBitmap |
---|
51 | self.AddLabelTool(GUIFRAME_ID.BOOKMARK_ID, 'Bookmark', bookmark_bmp, |
---|
52 | disable_bookmark_bmp, button_type,'Bookmark') |
---|
53 | self.AddSeparator() |
---|
54 | zoom_in_im = GUIFRAME_ICON.ZOOM_IN_ICON |
---|
55 | zoom_in_im.Rescale(tbar_size[0], tbar_size[1], wx.IMAGE_QUALITY_HIGH) |
---|
56 | zoom_in_bmp = zoom_in_im.ConvertToBitmap() |
---|
57 | #disable_zoom_in_bmp = clear_image(zoom_in_im).ConvertToBitmap() |
---|
58 | disable_zoom_in_bmp = wx.NullBitmap |
---|
59 | self.AddLabelTool(GUIFRAME_ID.ZOOM_IN_ID, 'Zoom In', zoom_in_bmp, |
---|
60 | disable_zoom_in_bmp, button_type,'Zoom In') |
---|
61 | self.AddSeparator() |
---|
62 | zoom_out_im = GUIFRAME_ICON.ZOOM_OUT_ICON |
---|
63 | zoom_out_im.Rescale(tbar_size[0], tbar_size[1], wx.IMAGE_QUALITY_HIGH) |
---|
64 | zoom_out_bmp = zoom_out_im.ConvertToBitmap() |
---|
65 | #disable_zoom_out_bmp = clear_image(zoom_out_im).ConvertToBitmap() |
---|
66 | disable_zoom_out_bmp = wx.NullBitmap |
---|
67 | self.AddLabelTool(GUIFRAME_ID.ZOOM_OUT_ID, 'Zoom Out', zoom_out_bmp, |
---|
68 | disable_zoom_out_bmp, button_type,'Zoom Out') |
---|
69 | self.AddSeparator() |
---|
70 | zoom_im = GUIFRAME_ICON.ZOOM_ICON |
---|
71 | zoom_im.Rescale(tbar_size[0], tbar_size[1], wx.IMAGE_QUALITY_HIGH) |
---|
72 | zoom_bmp = zoom_im.ConvertToBitmap() |
---|
73 | #disable_zoom_bmp = clear_image(zoom_im).ConvertToBitmap() |
---|
74 | disable_zoom_bmp = wx.NullBitmap |
---|
75 | self.AddLabelTool(GUIFRAME_ID.ZOOM_ID, 'Zoom', zoom_bmp, |
---|
76 | disable_zoom_bmp, button_type,'Zoom In') |
---|
77 | self.AddSeparator() |
---|
78 | drag_im = GUIFRAME_ICON.DRAG_ICON |
---|
79 | drag_im.Rescale(tbar_size[0], tbar_size[1], wx.IMAGE_QUALITY_HIGH) |
---|
80 | drag_bmp = drag_im.ConvertToBitmap() |
---|
81 | #disable_drag_bmp = clear_image(drag_im).ConvertToBitmap() |
---|
82 | disable_drag_bmp = wx.NullBitmap |
---|
83 | self.AddLabelTool(GUIFRAME_ID.DRAG_ID, 'Drag', drag_bmp, |
---|
84 | disable_drag_bmp, button_type,'Drag') |
---|
85 | self.AddSeparator() |
---|
86 | report_im = GUIFRAME_ICON.REPORT_ICON |
---|
87 | report_im.Rescale(tbar_size[0], tbar_size[1], wx.IMAGE_QUALITY_HIGH) |
---|
88 | report_bmp = report_im.ConvertToBitmap() |
---|
89 | #disable_report_bmp = clear_image(report_im).ConvertToBitmap() |
---|
90 | disable_report_bmp = wx.NullBitmap |
---|
91 | self.AddLabelTool(GUIFRAME_ID.PREVIEW_ID, 'Report', report_bmp, |
---|
92 | disable_report_bmp, button_type,'Report') |
---|
93 | self.AddSeparator() |
---|
94 | print_im = GUIFRAME_ICON.PRINT_ICON |
---|
95 | print_im.Rescale(tbar_size[0], tbar_size[1], wx.IMAGE_QUALITY_HIGH) |
---|
96 | print_bmp = print_im.ConvertToBitmap() |
---|
97 | #disable_print_bmp = clear_image(print_im).ConvertToBitmap() |
---|
98 | disable_print_bmp = wx.NullBitmap |
---|
99 | self.AddLabelTool(GUIFRAME_ID.PRINT_ID, 'Print', print_bmp, |
---|
100 | disable_print_bmp, button_type, 'Print') |
---|
101 | self.AddSeparator() |
---|
102 | undo_im = GUIFRAME_ICON.UNDO_ICON |
---|
103 | undo_im.Rescale(tbar_size[0], tbar_size[1], wx.IMAGE_QUALITY_HIGH) |
---|
104 | undo_bmp = undo_im.ConvertToBitmap() |
---|
105 | #disable_undo_bmp = clear_image(undo_im).ConvertToBitmap() |
---|
106 | disable_undo_bmp = wx.NullBitmap |
---|
107 | self.AddLabelTool(GUIFRAME_ID.UNDO_ID, 'Undo', undo_bmp, |
---|
108 | disable_undo_bmp, button_type,'Undo') |
---|
109 | self.AddSeparator() |
---|
110 | redo_im = GUIFRAME_ICON.REDO_ICON |
---|
111 | redo_im.Rescale(tbar_size[0], tbar_size[1], wx.IMAGE_QUALITY_HIGH) |
---|
112 | redo_bmp = redo_im.ConvertToBitmap() |
---|
113 | #disable_redo_bmp = clear_image(redo_im).ConvertToBitmap() |
---|
114 | disable_redo_bmp = wx.NullBitmap |
---|
115 | self.AddLabelTool(GUIFRAME_ID.REDO_ID, 'Redo', redo_bmp, |
---|
116 | disable_redo_bmp, button_type,'Redo') |
---|
117 | self.AddSeparator() |
---|
118 | #add button for the current application |
---|
119 | self.button_application = wx.StaticText(self, -1, 'Welcome') |
---|
120 | self.button_application.SetForegroundColour('black') |
---|
121 | self.button_application.SetBackgroundColour('#1874CD') |
---|
122 | hint = 'Active Application' |
---|
123 | self.button_application.SetToolTipString(hint) |
---|
124 | self.AddControl(self.button_application) |
---|
125 | self.AddSeparator() |
---|
126 | #add button for the panel on focus |
---|
127 | self.button_panel = wx.StaticText(self, -1, 'No Panel') |
---|
128 | self.button_panel.SetForegroundColour('black') |
---|
129 | self.button_panel.SetBackgroundColour('#90EE90') |
---|
130 | hint = 'Panel on Focus' |
---|
131 | self.button_panel.SetToolTipString(hint) |
---|
132 | self.AddControl(self.button_panel) |
---|
133 | |
---|
134 | self.SetToolBitmapSize(tbar_size) |
---|
135 | self.Realize() |
---|
136 | |
---|
137 | def on_bind_button(self): |
---|
138 | """ |
---|
139 | """ |
---|
140 | if self.parent is not None: |
---|
141 | self.parent.Bind(wx.EVT_TOOL, self.parent.on_redo_panel, |
---|
142 | id=GUIFRAME_ID.REDO_ID) |
---|
143 | self.parent.Bind(wx.EVT_TOOL, self.parent.on_undo_panel, |
---|
144 | id=GUIFRAME_ID.UNDO_ID) |
---|
145 | self.parent.Bind(wx.EVT_TOOL, self.parent.on_bookmark_panel, |
---|
146 | id=GUIFRAME_ID.BOOKMARK_ID) |
---|
147 | self.parent.Bind(wx.EVT_TOOL, self.parent.on_save_panel, |
---|
148 | id=GUIFRAME_ID.SAVE_ID) |
---|
149 | self.parent.Bind(wx.EVT_TOOL, self.parent.on_zoom_in_panel, |
---|
150 | id=GUIFRAME_ID.ZOOM_IN_ID) |
---|
151 | self.parent.Bind(wx.EVT_TOOL, self.parent.on_zoom_out_panel, |
---|
152 | id=GUIFRAME_ID.ZOOM_OUT_ID) |
---|
153 | self.parent.Bind(wx.EVT_TOOL, self.parent.on_zoom_panel, |
---|
154 | id=GUIFRAME_ID.ZOOM_ID) |
---|
155 | self.parent.Bind(wx.EVT_TOOL, self.parent.on_drag_panel, |
---|
156 | id=GUIFRAME_ID.DRAG_ID) |
---|
157 | self.parent.Bind(wx.EVT_TOOL, self.parent.on_reset_panel, |
---|
158 | id=GUIFRAME_ID.RESET_ID) |
---|
159 | self.parent.Bind(wx.EVT_TOOL, self.parent.on_preview_panel, |
---|
160 | id=GUIFRAME_ID.PREVIEW_ID) |
---|
161 | self.parent.Bind(wx.EVT_TOOL, self.parent.on_print_panel, |
---|
162 | id=GUIFRAME_ID.PRINT_ID) |
---|
163 | |
---|
164 | def update_button(self, application_name='', panel_name=''): |
---|
165 | """ |
---|
166 | """ |
---|
167 | self.button_application.SetLabel(str(application_name)) |
---|
168 | self.button_panel.SetLabel(str(panel_name)) |
---|
169 | |
---|
170 | def update_toolbar(self, panel=None): |
---|
171 | """ |
---|
172 | """ |
---|
173 | if panel is None: |
---|
174 | self.EnableTool(GUIFRAME_ID.PRINT_ID, False) |
---|
175 | self.EnableTool(GUIFRAME_ID.UNDO_ID,False) |
---|
176 | self.EnableTool(GUIFRAME_ID.REDO_ID, False) |
---|
177 | self.EnableTool(GUIFRAME_ID.ZOOM_ID, False) |
---|
178 | self.EnableTool(GUIFRAME_ID.ZOOM_IN_ID, False) |
---|
179 | self.EnableTool(GUIFRAME_ID.ZOOM_OUT_ID, False) |
---|
180 | self.EnableTool(GUIFRAME_ID.BOOKMARK_ID, False) |
---|
181 | self.EnableTool(GUIFRAME_ID.PREVIEW_ID, False) |
---|
182 | self.EnableTool(GUIFRAME_ID.SAVE_ID, False) |
---|
183 | self.EnableTool(GUIFRAME_ID.DRAG_ID, False) |
---|
184 | self.EnableTool(GUIFRAME_ID.RESET_ID, False) |
---|
185 | else: |
---|
186 | self.EnableTool(GUIFRAME_ID.PRINT_ID, panel.get_print_flag()) |
---|
187 | self.EnableTool(GUIFRAME_ID.UNDO_ID, panel.get_undo_flag()) |
---|
188 | self.EnableTool(GUIFRAME_ID.REDO_ID, panel.get_redo_flag()) |
---|
189 | self.EnableTool(GUIFRAME_ID.ZOOM_ID, panel.get_zoom_flag()) |
---|
190 | self.EnableTool(GUIFRAME_ID.ZOOM_IN_ID, panel.get_zoom_in_flag()) |
---|
191 | self.EnableTool(GUIFRAME_ID.ZOOM_OUT_ID, panel.get_zoom_out_flag()) |
---|
192 | self.EnableTool(GUIFRAME_ID.BOOKMARK_ID, panel.get_bookmark_flag()) |
---|
193 | self.EnableTool(GUIFRAME_ID.PREVIEW_ID, panel.get_preview_flag()) |
---|
194 | self.EnableTool(GUIFRAME_ID.SAVE_ID, panel.get_save_flag()) |
---|
195 | self.EnableTool(GUIFRAME_ID.DRAG_ID, panel.get_drag_flag()) |
---|
196 | self.EnableTool(GUIFRAME_ID.RESET_ID, panel.get_reset_flag()) |
---|
197 | self.Realize() |
---|
198 | |
---|
199 | def enable_undo(self, panel): |
---|
200 | self.EnableTool(GUIFRAME_ID.PRINT_ID, panel.get_print_flag()) |
---|
201 | self.Realize() |
---|
202 | |
---|
203 | def enable_redo(self, panel): |
---|
204 | self.EnableTool(GUIFRAME_ID.REDO_ID, panel.get_redo_flag()) |
---|
205 | self.Realize() |
---|
206 | |
---|
207 | def enable_print(self, panel): |
---|
208 | self.EnableTool(GUIFRAME_ID.PRINT_ID, panel.get_print_flag()) |
---|
209 | self.Realize() |
---|
210 | |
---|
211 | def enable_zoom(self, panel): |
---|
212 | self.EnableTool(GUIFRAME_ID.ZOOM_ID, panel.get_zoom_flag()) |
---|
213 | self.Realize() |
---|
214 | |
---|
215 | def enable_zoom_in(self, panel): |
---|
216 | self.EnableTool(GUIFRAME_ID.ZOOM_IN_ID, panel.get_zoom_in_flag()) |
---|
217 | self.Realize() |
---|
218 | |
---|
219 | def enable_zoom_out(self, panel): |
---|
220 | self.EnableTool(GUIFRAME_ID.ZOOM_OUT_ID, panel.get_zoom_out_flag()) |
---|
221 | self.Realize() |
---|
222 | |
---|
223 | def enable_bookmark(self, panel): |
---|
224 | self.EnableTool(GUIFRAME_ID.BOOKMARK_ID, panel.get_bookmark_flag()) |
---|
225 | self.Realize() |
---|
226 | |
---|
227 | def enable_save(self, panel): |
---|
228 | self.EnableTool(GUIFRAME_ID.SAVE_ID, panel.get_save_flag()) |
---|
229 | self.Realize() |
---|
230 | |
---|
231 | def enable_reset(self, panel): |
---|
232 | self.EnableTool(GUIFRAME_ID.RESET_ID, panel.get_reset_flag()) |
---|
233 | self.Realize() |
---|
234 | |
---|
235 | def enable_preview(self, panel): |
---|
236 | self.EnableTool(GUIFRAME_ID.PREVIEW_ID, panel.get_preview_flag()) |
---|
237 | self.Realize() |
---|
238 | |
---|
239 | |
---|