[010c251] | 1 | |
---|
| 2 | import wx |
---|
| 3 | from wx import ToolBar as Tbar |
---|
[f036c692] | 4 | from sans.guiframe.gui_style import GUIFRAME_ID |
---|
[010c251] | 5 | |
---|
| 6 | |
---|
[f036c692] | 7 | class GUIToolBar(Tbar): |
---|
[010c251] | 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) |
---|
[f036c692] | 20 | self.AddLabelTool(GUIFRAME_ID.SAVE_ID, 'Save', save_bmp, shortHelp='Save') |
---|
[73b3ae2] | 21 | self.AddSeparator() |
---|
[010c251] | 22 | |
---|
[93fe7e2] | 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') |
---|
[73b3ae2] | 26 | self.AddSeparator() |
---|
[010c251] | 27 | zoom_in_bmp = wx.ArtProvider.GetBitmap(wx.ART_GO_UP, wx.ART_TOOLBAR, |
---|
| 28 | size=tbar_size) |
---|
[f036c692] | 29 | self.AddLabelTool(GUIFRAME_ID.ZOOM_IN_ID, 'Zoom in', zoom_in_bmp,shortHelp='Zoom in') |
---|
[73b3ae2] | 30 | self.AddSeparator() |
---|
[010c251] | 31 | zoom_out_bmp = wx.ArtProvider.GetBitmap(wx.ART_GO_DOWN, wx.ART_TOOLBAR, |
---|
| 32 | size=tbar_size) |
---|
[f036c692] | 33 | self.AddLabelTool(GUIFRAME_ID.ZOOM_OUT_ID,'Zoom out',zoom_out_bmp,shortHelp='Zoom out') |
---|
[73b3ae2] | 34 | self.AddSeparator() |
---|
[010c251] | 35 | zoom_bmp = wx.ArtProvider.GetBitmap(wx.ART_GO_FORWARD, wx.ART_TOOLBAR, |
---|
| 36 | size=tbar_size) |
---|
[f036c692] | 37 | self.AddLabelTool(GUIFRAME_ID.ZOOM_ID, 'Zoom', zoom_bmp,shortHelp='Zoom') |
---|
[73b3ae2] | 38 | self.AddSeparator() |
---|
[010c251] | 39 | drag_bmp = wx.ArtProvider.GetBitmap(wx.ART_REMOVABLE, wx.ART_TOOLBAR, |
---|
| 40 | size=tbar_size) |
---|
[f036c692] | 41 | self.AddLabelTool(GUIFRAME_ID.DRAG_ID, 'Drag', drag_bmp,shortHelp='Drag') |
---|
[73b3ae2] | 42 | self.AddSeparator() |
---|
[010c251] | 43 | preview_bmp = wx.ArtProvider.GetBitmap(wx.ART_REPORT_VIEW, wx.ART_TOOLBAR, |
---|
| 44 | size=tbar_size) |
---|
[f036c692] | 45 | self.AddLabelTool(GUIFRAME_ID.PREVIEW_ID, 'Preview', preview_bmp,shortHelp='Report') |
---|
[73b3ae2] | 46 | self.AddSeparator() |
---|
[010c251] | 47 | print_bmp = wx.ArtProvider.GetBitmap(wx.ART_PRINT, wx.ART_TOOLBAR, |
---|
| 48 | size=tbar_size) |
---|
[f036c692] | 49 | self.AddLabelTool(GUIFRAME_ID.PRINT_ID, 'Print', print_bmp,shortHelp='Print') |
---|
[73b3ae2] | 50 | self.AddSeparator() |
---|
[010c251] | 51 | undo_bmp = wx.ArtProvider.GetBitmap(wx.ART_UNDO, wx.ART_TOOLBAR, |
---|
| 52 | size=tbar_size) |
---|
[f036c692] | 53 | self.AddLabelTool(GUIFRAME_ID.UNDO_ID, 'Undo', undo_bmp,shortHelp='Undo') |
---|
[73b3ae2] | 54 | self.AddSeparator() |
---|
[010c251] | 55 | redo_bmp = wx.ArtProvider.GetBitmap(wx.ART_REDO, wx.ART_TOOLBAR, |
---|
| 56 | size=tbar_size) |
---|
[f036c692] | 57 | self.AddLabelTool(GUIFRAME_ID.REDO_ID, 'Redo', redo_bmp,shortHelp='Redo') |
---|
[73b3ae2] | 58 | self.AddSeparator() |
---|
[a45037aa] | 59 | #add button for the current application |
---|
[73b3ae2] | 60 | self.button_application = wx.StaticText(self, -1, 'Welcome') |
---|
[a45037aa] | 61 | self.button_application.SetForegroundColour('black') |
---|
| 62 | self.button_application.SetBackgroundColour('#1874CD') |
---|
| 63 | self.AddControl(self.button_application) |
---|
[73b3ae2] | 64 | self.AddSeparator() |
---|
[a45037aa] | 65 | #add button for the panel on focus |
---|
[73b3ae2] | 66 | self.button_panel = wx.StaticText(self, -1, 'No Panel') |
---|
[a45037aa] | 67 | self.button_panel.SetForegroundColour('black') |
---|
| 68 | self.button_panel.SetBackgroundColour('#90EE90') |
---|
| 69 | self.AddControl(self.button_panel) |
---|
[010c251] | 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: |
---|
[f036c692] | 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) |
---|
[010c251] | 100 | |
---|
[a45037aa] | 101 | def update_button(self, application_name='', panel_name=''): |
---|
[010c251] | 102 | """ |
---|
| 103 | """ |
---|
[a45037aa] | 104 | self.button_application.SetLabel(str(application_name)) |
---|
| 105 | self.button_panel.SetLabel(str(panel_name)) |
---|
[93fe7e2] | 106 | print "update_button", application_name, panel_name |
---|
[a45037aa] | 107 | def update_toolbar(self, panel=None): |
---|
[010c251] | 108 | """ |
---|
| 109 | """ |
---|
| 110 | if panel is None: |
---|
[93fe7e2] | 111 | #self.Disable() |
---|
[f036c692] | 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) |
---|
[010c251] | 123 | else: |
---|
| 124 | self.Enable() |
---|
[f036c692] | 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()) |
---|
[010c251] | 136 | |
---|
| 137 | |
---|
| 138 | |
---|
| 139 | |
---|