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