def make_object_button(widget, icon_path, toplevel=False, tip=None): """Creates a button for the widgets toolbar. Function used by the various widget modules to add a button to the widgets toolbar. Icons with a relative path will be loaded from config.icon_path. widget: (name of) the widget the button will add to the app icon_path: Path to the icon_path used for the button toplevel: True if the widget is a toplevel object (frame, dialog) tip: Tool tip to display return: The newly created wxBitmapButton instance""" if not config.use_gui: return None import wx import misc from tree import WidgetTree if not os.path.isabs(icon_path): icon_path = os.path.join(config.icons_path, icon_path) bmp = misc.get_xpm_bitmap(icon_path) tmp = wx.BitmapButton(palette, -1, bmp, size=(31, 31)) if not toplevel: tmp.Bind(wx.EVT_BUTTON, add_object) else: tmp.Bind(wx.EVT_BUTTON, add_toplevel_object) refs[tmp.GetId()] = widget if not tip: tip = _('Add a %s') % widget.replace(_('Edit'), '') tmp.SetToolTip(wx.ToolTip(tip)) WidgetTree.images[widget] = icon_path return tmp
def create_widget(self): if self.widget: # re-creating -> use old frame win = self.widget.GetTopLevelParent() else: style = wx.DEFAULT_FRAME_STYLE if common.pin_design_window: style |= wx.STAY_ON_TOP win = wx.Frame(common.main, -1, misc.design_title(self.name), size=(400, 300), style=style) import os, compat icon = compat.wx_EmptyIcon() xpm = os.path.join(config.icons_path, 'panel.xpm') icon.CopyFromBitmap(misc.get_xpm_bitmap(xpm)) win.SetIcon(icon) win.Bind( wx.EVT_CLOSE, self.hide_widget) # CLOSE event of the frame, not the panel if wx.Platform == '__WXMSW__': win.CentreOnScreen() if self.scrollable: self.widget = wx.ScrolledWindow(win, self.id, style=0) else: self.widget = wx.Panel(win, self.id, style=0) self.widget.Bind(wx.EVT_ENTER_WINDOW, self.on_enter) self.widget.GetBestSize = self.get_widget_best_size
def create_widget(self): tb_style = wx.TB_HORIZONTAL | self.style if wx.Platform == '__WXGTK__': tb_style |= wx.TB_DOCKABLE | wx.TB_FLAT if self.IS_TOPLEVEL: # "top-level" toolbar self.widget = wx.Frame(None, -1, misc.design_title(self.name)) self.widget.SetClientSize((400, 30)) self._tb = wx.ToolBar(self.widget, -1, style=tb_style) self.widget.SetToolBar(self._tb) self.widget.SetBackgroundColour(self.widget.GetBackgroundColour()) icon = compat.wx_EmptyIcon() xpm = os.path.join(config.icons_path, 'toolbar.xpm') icon.CopyFromBitmap(misc.get_xpm_bitmap(xpm)) self.widget.SetIcon(icon) self.widget.Bind(wx.EVT_CLOSE, lambda e: self.hide_widget()) self.widget.Bind(wx.EVT_LEFT_DOWN, self.on_set_focus) if wx.Platform == '__WXMSW__': # MSW isn't smart enough to avoid overlapping windows, so # at least move it away from the 3 wxGlade frames self.widget.CenterOnScreen() else: # toolbar for a Frame self.widget = self._tb = wx.ToolBar(self.parent.widget, -1, style=tb_style) self.parent.widget.SetToolBar(self.widget) self.widget.Bind(wx.EVT_LEFT_DOWN, self.on_set_focus) # set the various property values self._set_bitmapsize() self._set_margins() self._set_packing() self._set_separation() self._set_tools() # show the menus
def _set_widget_icon(self): if self.icon: bitmap = self.get_preview_obj_bitmap(self.icon.strip()) else: xpm = os.path.join(config.icons_path, 'frame.xpm') bitmap = misc.get_xpm_bitmap(xpm) icon = compat.wx_EmptyIcon() icon.CopyFromBitmap(bitmap) self.widget.SetIcon(icon)
def make_object_button(widget, icon_path, toplevel=False, tip=None): """Creates a button for the widgets toolbar. Function used by the various widget modules to add a button to the widgets toolbar. Icons with a relative path will be loaded from config.icon_path. widget: (name of) the widget the button will add to the app icon_path: Path to the icon_path used for the button toplevel: True if the widget is a toplevel object (frame, dialog) tip: Tool tip to display return: The newly created wxBitmapButton instance""" if not config.use_gui: return None import wx import misc from tree import WidgetTree if not os.path.isabs(icon_path): icon_path = os.path.join(config.icons_path, icon_path) bmp = misc.get_xpm_bitmap(icon_path) label = widget.replace('Edit', '') if compat.version < (3, 0): # old wx version: use BitmapButton tmp = wx.BitmapButton(palette, -1, bmp, size=(31, 31)) if not toplevel: tmp.Bind(wx.EVT_BUTTON, add_object) else: tmp.Bind(wx.EVT_BUTTON, add_toplevel_object) else: # for more recent versions, we support config options to display icons and/or labels if not toplevel: if not config.preferences.show_palette_labels: # icons only -> set size tmp = wx.ToggleButton(palette, -1, size=(31, 31), name=label) else: tmp = wx.ToggleButton(palette, -1, label, name=label) tmp.Bind(wx.EVT_TOGGLEBUTTON, add_object) else: if not config.preferences.show_palette_labels: tmp = wx.Button(palette, -1, size=(31, 31), name=label) else: tmp = wx.Button(palette, -1, label, name=label) tmp.Bind(wx.EVT_BUTTON, add_toplevel_object) if config.preferences.show_palette_icons: tmp.SetBitmap(bmp) refs[tmp.GetId()] = widget if not tip: tip = _('Add a %s') % label tmp.SetToolTip(wx.ToolTip(tip)) WidgetTree.images[widget] = icon_path return tmp
def make_object_button(widget, icon_path, toplevel=False, tip=None): """\ Creates a button for the widgets toolbar. Function used by the various widget modules to add a button to the widgets toolbar. @param widget: (name of) the widget the button will add to the app @param icon_path: path to the icon used for the button @param toplevel: true if the widget is a toplevel object (frame, dialog) @param tip: tool tip to display @return: The newly created wxBitmapButton """ import wx from tree import WidgetTree id = wx.NewId() if not os.path.isabs(icon_path): icon_path = os.path.join(wxglade_path, icon_path) if wx.Platform == '__WXGTK__': style = wx.NO_BORDER else: style = wx.BU_AUTODRAW import misc bmp = misc.get_xpm_bitmap(icon_path) tmp = wx.BitmapButton(palette, id, bmp, size=(31, 31), style=style) if not toplevel: wx.EVT_BUTTON(tmp, id, add_object) else: wx.EVT_BUTTON(tmp, id, add_toplevel_object) refs[id] = widget if not tip: tip = _('Add a %s') % widget.replace(_('Edit'), '') tmp.SetToolTip(wx.ToolTip(tip)) WidgetTree.images[widget] = icon_path # add support for ESC key. We bind the handler to the button, because # (at least on GTK) EVT_CHAR are not generated for wxFrame objects... def on_char(event): #print 'on_char' if event.HasModifiers() or event.GetKeyCode() != wx.WXK_ESCAPE: event.Skip() return global adding_widget, adding_sizer, widget_to_add adding_widget = False adding_sizer = False widget_to_add = None import misc if misc._currently_under_mouse is not None: misc._currently_under_mouse.SetCursor(wx.STANDARD_CURSOR) event.Skip() wx.EVT_CHAR(tmp, on_char) return tmp
def make_object_button(widget, icon_path, toplevel=False, tip=None): """\ creates a button for the widgets toolbar. Params: - widget: (name of) the widget the button will add to the app - icon_path: path to the icon used for the button - toplevel: true if the widget is a toplevel object (frame, dialog) - tip: tool tip to display Returns: the newly created wxBitmapButton """ #from wxPython import wx import wx from tree import WidgetTree id = wx.NewId() if not os.path.isabs(icon_path): icon_path = os.path.join(wxglade_path, icon_path) if wx.Platform == '__WXGTK__': style = wx.NO_BORDER else: style = wx.BU_AUTODRAW import misc bmp = misc.get_xpm_bitmap(icon_path) tmp = wx.BitmapButton(palette, id, bmp, size=(31, 31), style=style) if not toplevel: wx.EVT_BUTTON(tmp, id, add_object) else: wx.EVT_BUTTON(tmp, id, add_toplevel_object) refs[id] = widget if not tip: tip = _('Add a %s') % widget.replace(_('Edit'), '') tmp.SetToolTip(wx.ToolTip(tip)) WidgetTree.images[widget] = icon_path # add support for ESC key. We bind the handler to the button, because # (at least on GTK) EVT_CHAR are not generated for wxFrame objects... def on_char(event): #print 'on_char' if event.HasModifiers() or event.GetKeyCode() != wx.WXK_ESCAPE: event.Skip() return global adding_widget, adding_sizer, widget_to_add adding_widget = False adding_sizer = False widget_to_add = None import misc if misc._currently_under_mouse is not None: misc._currently_under_mouse.SetCursor(wx.STANDARD_CURSOR) event.Skip() wx.EVT_CHAR(tmp, on_char) return tmp
def __init__(self, parent, application): id = wx.NewId() style = wx.TR_DEFAULT_STYLE|wx.TR_HAS_VARIABLE_ROW_HEIGHT if wx.Platform == '__WXGTK__': style |= wx.TR_NO_LINES|wx.TR_FULL_ROW_HIGHLIGHT elif wx.Platform == '__WXMAC__': style &= ~wx.TR_ROW_LINES wx.TreeCtrl.__init__(self, parent, id, style=style) root_node = Tree.Node(application) self.cur_widget = None # reference to the selected widget Tree.__init__(self, root_node, application) image_list = wx.ImageList(21, 21) image_list.Add(wx.Bitmap(os.path.join(common.icons_path, 'application.xpm'), wx.BITMAP_TYPE_XPM)) for w in WidgetTree.images: ## WidgetTree.images[w] = image_list.Add(wx.Bitmap( ## WidgetTree.images[w], wx.BITMAP_TYPE_XPM)) WidgetTree.images[w] = image_list.Add( misc.get_xpm_bitmap(WidgetTree.images[w])) self.AssignImageList(image_list) root_node.item = self.AddRoot(_('Application'), 0) self.SetPyData(root_node.item, root_node) self.skip_select = 0 # necessary to avoid an infinite loop on win32, as # SelectItem fires an EVT_TREE_SEL_CHANGED event self.title = ' ' self.set_title(self.title) self.auto_expand = True # this control the automatic expansion of # nodes: it is set to False during xml loading self._show_menu = misc.wxGladePopupMenu('widget') # popup menu to # show toplevel # widgets SHOW_ID = wx.NewId() self._show_menu.Append(SHOW_ID, _('Show')) wx.EVT_TREE_SEL_CHANGED(self, id, self.on_change_selection) wx.EVT_RIGHT_DOWN(self, self.popup_menu) wx.EVT_LEFT_DCLICK(self, self.show_toplevel) wx.EVT_MENU(self, SHOW_ID, self.show_toplevel) def on_key_down(event): evt_flags = 0 if event.ControlDown(): evt_flags = wx.ACCEL_CTRL evt_key = event.GetKeyCode() for flags, key, function in misc.accel_table: if evt_flags == flags and evt_key == key: wx.CallAfter(function) break event.Skip() wx.EVT_KEY_DOWN(self, on_key_down)
def __init__(self, parent, application): self._logger = logging.getLogger(self.__class__.__name__) style = wx.TR_DEFAULT_STYLE | wx.TR_HAS_VARIABLE_ROW_HEIGHT style |= wx.TR_EDIT_LABELS if wx.Platform == '__WXGTK__': style |= wx.TR_NO_LINES | wx.TR_FULL_ROW_HIGHLIGHT elif wx.Platform == '__WXMAC__': style &= ~wx.TR_ROW_LINES wx.TreeCtrl.__init__(self, parent, -1, style=style) root_node = Node(application) application.node = root_node self.cur_widget = None # reference to the selected widget Tree.__init__(self, root_node, application) image_list = wx.ImageList(21, 21) image_list.Add( wx.Bitmap(os.path.join(config.icons_path, 'application.xpm'), wx.BITMAP_TYPE_XPM)) for w in WidgetTree.images: WidgetTree.images[w] = image_list.Add( misc.get_xpm_bitmap(WidgetTree.images[w])) self.AssignImageList(image_list) root_node.item = self.AddRoot(_('Application'), 0) self._SetItemData(root_node.item, root_node) self.skip_select = 0 # necessary to avoid an infinite loop on win32, as SelectItem fires an # EVT_TREE_SEL_CHANGED event self.title = ' ' self.set_title(self.title) self.drop_target = clipboard.DropTarget(self, toplevel=True) self.SetDropTarget(self.drop_target) self._drag_ongoing = False self.auto_expand = True # this control the automatic expansion of nodes: it is set to False during xml loading self.Bind(wx.EVT_TREE_SEL_CHANGED, self.on_change_selection) self.Bind(wx.EVT_RIGHT_DOWN, self.popup_menu) self.Bind(wx.EVT_LEFT_DCLICK, self.on_left_dclick) self.Bind(wx.EVT_LEFT_DOWN, self.on_left_click) # allow direct placement of widgets self.Bind(wx.EVT_MENU, self.on_menu) # for handling the selection of the first item self._popup_menu_widget = None # the widget for the popup menu self.Bind(wx.EVT_TREE_BEGIN_DRAG, self.begin_drag) self.Bind(wx.EVT_LEAVE_WINDOW, self.on_leave_window) self.Bind(wx.EVT_MOUSE_EVENTS, self.on_mouse_events) self.Bind(wx.EVT_TREE_BEGIN_LABEL_EDIT, self.begin_edit_label) self.Bind(wx.EVT_TREE_END_LABEL_EDIT, self.end_edit_label) #self.Bind(wx.EVT_KEY_DOWN, misc.on_key_down_event) self.Bind(wx.EVT_KEY_DOWN, self.on_key_down_event) self.Bind(wx.EVT_CHAR_HOOK, self.on_char)
def __init__(self, parent, application): id = wx.NewId() style = wx.TR_DEFAULT_STYLE|wx.TR_HAS_VARIABLE_ROW_HEIGHT if wx.Platform == '__WXGTK__': style |= wx.TR_NO_LINES|wx.TR_FULL_ROW_HIGHLIGHT elif wx.Platform == '__WXMAC__': style &= ~wx.TR_ROW_LINES wx.TreeCtrl.__init__(self, parent, id, style=style) root_node = Tree.Node(application) self.cur_widget = None # reference to the selected widget Tree.__init__(self, root_node, application) image_list = wx.ImageList(21, 21) image_list.Add(wx.Bitmap(os.path.join(common.wxglade_path, 'icons/application.xpm'), wx.BITMAP_TYPE_XPM)) for w in WidgetTree.images: ## WidgetTree.images[w] = image_list.Add(wx.Bitmap( ## WidgetTree.images[w], wx.BITMAP_TYPE_XPM)) WidgetTree.images[w] = image_list.Add( misc.get_xpm_bitmap(WidgetTree.images[w])) self.AssignImageList(image_list) root_node.item = self.AddRoot(_('Application'), 0) self.SetPyData(root_node.item, root_node) self.skip_select = 0 # necessary to avoid an infinite loop on win32, as # SelectItem fires an EVT_TREE_SEL_CHANGED event self.title = ' ' self.set_title(self.title) self.auto_expand = True # this control the automatic expansion of # nodes: it is set to False during xml loading self._show_menu = misc.wxGladePopupMenu('widget') # popup menu to # show toplevel # widgets SHOW_ID = wx.NewId() self._show_menu.Append(SHOW_ID, _('Show')) wx.EVT_TREE_SEL_CHANGED(self, id, self.on_change_selection) wx.EVT_RIGHT_DOWN(self, self.popup_menu) wx.EVT_LEFT_DCLICK(self, self.show_toplevel) wx.EVT_MENU(self, SHOW_ID, self.show_toplevel) def on_key_down(event): evt_flags = 0 if event.ControlDown(): evt_flags = wx.ACCEL_CTRL evt_key = event.GetKeyCode() for flags, key, function in misc.accel_table: if evt_flags == flags and evt_key == key: wx.CallAfter(function) break event.Skip() wx.EVT_KEY_DOWN(self, on_key_down)
def _load_images(self): bitmaps = {} for name, path in WidgetTree.images.items(): img = misc.get_xpm_bitmap(path).ConvertToImage() # add 1 white pixel more at top and bottom img.Resize((21, 23), (0, 1), -1, -1, -1) bitmaps[name] = img.ConvertToBitmap() # grid sizer slots: # load template with one active slot and build new images with slot at any position top/left to bottom/right fn = os.path.join( config.icons_path, 'grid_sizer_slot_template.png') # bottom / right in black template = wx.Image(fn, wx.BITMAP_TYPE_PNG) t_empty = template.GetSubImage((0, 0, 7, 7)) # empty slot t_active = template.GetSubImage((0, 7, 7, 7)) # active slot t_bottom = template.GetSubImage( (0, 20, 20, 1)) # typically a black line at bottom t_right = template.GetSubImage( (20, 0, 1, 20)) # typically a black line at right for pos_v in (0, 1, 2): # active slot v for pos_h in (0, 1, 2): # active slot h img = compat.wx_EmptyImage(21, 21) for x in (0, 1, 2): # left, center, right for y in (0, 1, 2): # top, middle, button t = t_active if x == pos_h and y == pos_v else t_empty img.Paste(t, x * 7, y * 7) img.Paste(t_bottom, 0, 20) img.Paste(t_right, 20, 0) # add 1 white pixel more at top and bottom, store; store also -Disabled version img.Resize((21, 23), (0, 1), -1, -1, -1) name = 'EditGridSizerSlot-%d%d' % (pos_h, pos_v) bmp = bitmaps[name] = img.ConvertToBitmap() if hasattr(bmp, "ConvertToDisabled"): bitmaps['%s-Disabled' % name] = bmp.ConvertToDisabled() else: bitmaps['%s-Disabled' % name] = img.AdjustChannels( 1.5, 1.5, 1.5).ConvertToBitmap() # store in the bitmap list image_list = wx.ImageList(21, 23) app_image = wx.Image( os.path.join(config.icons_path, 'application.png'), wx.BITMAP_TYPE_PNG) app_image.Resize((21, 23), (0, 1), -1, -1, -1) image_list.Add(app_image.ConvertToBitmap()) for name, bitmap in bitmaps.items(): WidgetTree.images[name] = image_list.Add(bitmap) self.AssignImageList(image_list)
def create_widget(self): win = wx.Frame(common.palette, -1, misc.design_title(self.name), size=(400, 300)) import os icon = wx.EmptyIcon() xpm = os.path.join(common.wxglade_path, 'icons', 'panel.xpm') icon.CopyFromBitmap(misc.get_xpm_bitmap(xpm)) win.SetIcon(icon) #self.widget = wx.Panel(win, self.id, style=0) self.widget = wx.ScrolledWindow(win, self.id, style=0) wx.EVT_ENTER_WINDOW(self.widget, self.on_enter) self.widget.GetBestSize = self.get_widget_best_size #self.widget.SetSize = win.SetSize wx.EVT_CLOSE(win, self.hide_widget) if wx.Platform == '__WXMSW__': win.CentreOnScreen()
def _load_images(self): image_list = wx.ImageList(21, 21) image_list.Add(wx.Bitmap(os.path.join(config.icons_path, 'application.xpm'), wx.BITMAP_TYPE_XPM)) bitmaps = {} for name, path in WidgetTree.images.items(): bitmaps[name] = misc.get_xpm_bitmap(path) for name in ["EditSizerSlot"]: bmp = bitmaps[name] if hasattr(bitmaps[name], "ConvertToDisabled"): bmp = bmp.ConvertToDisabled() bitmaps[name+"-Disabled"] = bmp for name, bitmap in bitmaps.items(): WidgetTree.images[name] = image_list.Add(bitmap) self.AssignImageList(image_list)
def set_icon(self, value): self.icon = value.strip() if self.widget: if self.icon and not (self.icon.startswith('var:') or self.icon.startswith('code:')): icon = misc.get_relative_path(self.icon) bmp = wx.Bitmap(icon, wx.BITMAP_TYPE_ANY) if not bmp.Ok(): self.set_icon("") else: icon = wx.EmptyIcon() icon.CopyFromBitmap(bmp) self.widget.SetIcon(icon) else: import os icon = wx.EmptyIcon() xpm = os.path.join(common.wxglade_path, 'icons', 'dialog.xpm') icon.CopyFromBitmap(misc.get_xpm_bitmap(xpm)) self.widget.SetIcon(icon)
def set_icon(self, value): self.icon = value.strip() if self.widget: if self.icon and not (self.icon.startswith('var:') or self.icon.startswith('code:')): icon = misc.get_relative_path(self.icon) bmp = wx.Bitmap(icon, wx.BITMAP_TYPE_ANY) if not bmp.Ok(): self.set_icon("") else: icon = wx.EmptyIcon() icon.CopyFromBitmap(bmp) self.widget.SetIcon(icon) else: import os icon = wx.EmptyIcon() xpm = os.path.join(common.icons_path, 'dialog.xpm') icon.CopyFromBitmap(misc.get_xpm_bitmap(xpm)) self.widget.SetIcon(icon)
def create_widget(self): tb_style = wx.TB_HORIZONTAL | self.style if wx.Platform == '__WXGTK__': tb_style |= wx.TB_DOCKABLE | wx.TB_FLAT if self.parent: self.widget = self._tb = wx.ToolBar(self.parent.widget, -1, style=tb_style) self.parent.widget.SetToolBar(self.widget) else: # "top-level" toolbar self.widget = wx.Frame(None, -1, misc.design_title(self.name)) self.widget.SetClientSize((400, 30)) self._tb = wx.ToolBar(self.widget, -1, style=tb_style) self.widget.SetToolBar(self._tb) self.widget.SetBackgroundColour(self._tb.GetBackgroundColour()) import os icon = wx.EmptyIcon() xpm = os.path.join(common.wxglade_path, 'icons', 'toolbar.xpm') icon.CopyFromBitmap(misc.get_xpm_bitmap(xpm)) self.widget.SetIcon(icon) wx.EVT_CLOSE(self.widget, lambda e: self.hide_widget()) wx.EVT_LEFT_DOWN(self._tb, self.on_set_focus) if wx.Platform == '__WXMSW__': # MSW isn't smart enough to avoid overlapping windows, so # at least move it away from the 3 wxGlade frames self.widget.CenterOnScreen() wx.EVT_LEFT_DOWN(self.widget, self.on_set_focus) # set the various property values prop = self.properties if prop['bitmapsize'].is_active(): self.set_bitmapsize(self.bitmapsize, refresh=False) if prop['margins'].is_active(): self.set_margins(self.margins, refresh=False) if prop['packing'].is_active(): self.set_packing(self.packing, refresh=False) if prop['separation'].is_active(): self.set_separation(self.separation, refresh=False) self.set_tools(self.tools) # show the menus
def create_widget(self): if self.IS_TOPLEVEL: # "top-level" menubar self.widget = wx.Frame(None, -1, misc.design_title(self.name)) self.widget.SetClientSize((400, 30)) self._mb = wx.MenuBar() self.widget.SetMenuBar(self._mb) self.widget.SetBackgroundColour(self._mb.GetBackgroundColour()) import os icon = compat.wx_EmptyIcon() xpm = os.path.join(config.icons_path, 'menubar.png') icon.CopyFromBitmap(misc.get_xpm_bitmap(xpm)) self.widget.SetIcon(icon) self.widget.Bind(wx.EVT_CLOSE, lambda e: self.hide_widget()) else: if wx.Platform=="_WXMAC__": return # XXX check how a toplevel menu bar behaves on Mac OS self.widget = self._mb = wx.MenuBar() if self.parent.widget: self.parent.widget.SetMenuBar(self.widget) if wx.Platform == '__WXMSW__' or wx.Platform == '__WXMAC__': self.widget.SetFocus = lambda : None self.widget.Bind(wx.EVT_LEFT_DOWN, self.on_set_focus) self.set_menus() # show the menus
def create_widget(self): tb_style = wx.TB_HORIZONTAL|self.style if wx.Platform == '__WXGTK__': tb_style |= wx.TB_DOCKABLE|wx.TB_FLAT if self.parent: self.widget = self._tb = wx.ToolBar( self.parent.widget, -1, style=tb_style) self.parent.widget.SetToolBar(self.widget) else: # "top-level" toolbar self.widget = wx.Frame(None, -1, misc.design_title(self.name)) self.widget.SetClientSize((400, 30)) self._tb = wx.ToolBar(self.widget, -1, style=tb_style) self.widget.SetToolBar(self._tb) self.widget.SetBackgroundColour(self._tb.GetBackgroundColour()) import os icon = wx.EmptyIcon() xpm = os.path.join(common.wxglade_path, 'icons', 'toolbar.xpm') icon.CopyFromBitmap(misc.get_xpm_bitmap(xpm)) self.widget.SetIcon(icon) wx.EVT_CLOSE(self.widget, lambda e: self.hide_widget()) wx.EVT_LEFT_DOWN(self._tb, self.on_set_focus) if wx.Platform == '__WXMSW__': # MSW isn't smart enough to avoid overlapping windows, so # at least move it away from the 3 wxGlade frames self.widget.CenterOnScreen() wx.EVT_LEFT_DOWN(self.widget, self.on_set_focus) # set the various property values prop = self.properties if prop['bitmapsize'].is_active(): self.set_bitmapsize(self.bitmapsize, refresh=False) if prop['margins'].is_active(): self.set_margins(self.margins, refresh=False) if prop['packing'].is_active(): self.set_packing(self.packing, refresh=False) if prop['separation'].is_active(): self.set_separation(self.separation, refresh=False) self.set_tools(self.tools) # show the menus
def create_widget(self): if wx.Platform == '__WXGTK__' and not EditMenuBar.__hidden_frame: EditMenuBar.__hidden_frame = wx.Frame(common.main, -1, "") EditMenuBar.__hidden_frame.Hide() if self.parent: self.widget = self._mb = wx.MenuBar() if self.parent.widget: self.parent.widget.SetMenuBar(self.widget) if wx.Platform == '__WXMSW__' or wx.Platform == '__WXMAC__': self.widget.SetFocus = lambda: None else: # "top-level" menubar self.widget = wx.Frame(None, -1, misc.design_title(self.name)) self.widget.SetClientSize((400, 30)) self._mb = wx.MenuBar() self.widget.SetMenuBar(self._mb) self.widget.SetBackgroundColour(self._mb.GetBackgroundColour()) import os icon = compat.wx_EmptyIcon() xpm = os.path.join(config.icons_path, 'menubar.xpm') icon.CopyFromBitmap(misc.get_xpm_bitmap(xpm)) self.widget.SetIcon(icon) self.widget.Bind(wx.EVT_CLOSE, lambda e: self.hide_widget()) self.widget.Bind(wx.EVT_LEFT_DOWN, self.on_set_focus) self.set_menus() # show the menus
def create_widget(self): if wx.Platform == '__WXGTK__' and not EditMenuBar.__hidden_frame: EditMenuBar.__hidden_frame = wx.Frame(common.palette, -1, "") EditMenuBar.__hidden_frame.Hide() if self.parent: self.widget = self._mb = wx.MenuBar() if self.parent.widget: self.parent.widget.SetMenuBar(self.widget) if wx.Platform == '__WXMSW__' or wx.Platform == '__WXMAC__': self.widget.SetFocus = lambda : None else: # "top-level" menubar self.widget = wx.Frame(None, -1, misc.design_title(self.name)) self.widget.SetClientSize((400, 30)) self._mb = wx.MenuBar() self.widget.SetMenuBar(self._mb) self.widget.SetBackgroundColour(self._mb.GetBackgroundColour()) import os icon = wx.EmptyIcon() xpm = os.path.join(common.wxglade_path, 'icons', 'menubar.xpm') icon.CopyFromBitmap(misc.get_xpm_bitmap(xpm)) self.widget.SetIcon(icon) wx.EVT_CLOSE(self.widget, lambda e: self.hide_widget()) wx.EVT_LEFT_DOWN(self.widget, self.on_set_focus) self.set_menus(self.menus) # show the menus
def make_object_button(widget, icon_path, toplevel=False, tip=None): """\ Creates a button for the widgets toolbar. Function used by the various widget modules to add a button to the widgets toolbar. Icons with a relative path will be loaded from config.icon_path. @param widget: (name of) the widget the button will add to the app @type widget: str | Unicode @param icon_path: Path to the icon_path used for the button @type icon_path: str | Unicode @param toplevel: True if the widget is a toplevel object (frame, dialog) @type toplevel: bool @param tip: Tool tip to display @type tip: str | Unicode @return: The newly created wxBitmapButton """ import wx import misc from tree import WidgetTree widget_id = wx.NewId() if not os.path.isabs(icon_path): icon_path = os.path.join(config.icons_path, icon_path) if wx.Platform == '__WXGTK__': style = wx.NO_BORDER else: style = wx.BU_AUTODRAW bmp = misc.get_xpm_bitmap(icon_path) tmp = wx.BitmapButton(palette, widget_id, bmp, size=(31, 31), style=style) if not toplevel: wx.EVT_BUTTON(tmp, widget_id, add_object) else: wx.EVT_BUTTON(tmp, widget_id, add_toplevel_object) refs[widget_id] = widget if not tip: tip = _('Add a %s') % widget.replace(_('Edit'), '') tmp.SetToolTip(wx.ToolTip(tip)) WidgetTree.images[widget] = icon_path # add support for ESC key. We bind the handler to the button, because # (at least on GTK) EVT_CHAR are not generated for wxFrame objects... def on_char(event): #logging.debug('on_char') if event.HasModifiers() or event.GetKeyCode() != wx.WXK_ESCAPE: event.Skip() return global adding_widget, adding_sizer, widget_to_add adding_widget = False adding_sizer = False widget_to_add = None import misc if misc.currently_under_mouse is not None: misc.currently_under_mouse.SetCursor(wx.STANDARD_CURSOR) event.Skip() wx.EVT_CHAR(tmp, on_char) return tmp
def make_object_button( widget, icon_path, toplevel = False, tip = None ): import misc if not os.path.isabs( icon_path ): icon_path = os.path.join( wxglade_path, icon_path ) bmp = misc.get_xpm_bitmap( icon_path ) return [ bmp, widget ]