def _createDialog(self): self.dlg = wx.Dialog(None, wx.NewId(), "Create edited Classifier") self.sizer = wx.FlexGridSizer(0, 1, 0, 0) self.dlg.SetSizer(self.sizer) choiceSizer = wx.FlexGridSizer(1, 0, 0, 0) statText = wx.StaticText(self.dlg, wx.NewId(), "Select an Editing Algorithm") choiceSizer.Add(statText, flag = wx.ALIGN_CENTER_VERTICAL | wx.RIGHT, border = 10) choiceId = wx.NewId() choiceControl = wx.Choice(self.dlg, choiceId, choices = self._algoNames()) compat_wx.handle_event_1(self.dlg, wx.EVT_CHOICE, self._choiceCallback, choiceId) choiceSizer.Add(choiceControl, flag = wx.ALIGN_RIGHT) choiceSizer.AddGrowableCol(0) self.sizer.Add(choiceSizer, flag = wx.EXPAND | wx.ALL, border = 10) self.sizer.Add(wx.StaticLine(self.dlg), flag = wx.EXPAND) choiceControl.SetSelection(self.selection) self._replaceArgs() buttons = self.dlg.CreateButtonSizer(wx.OK | wx.CANCEL) #buttons.Realize() # does not work on Windows self.sizer.Add(buttons, flag = wx.ALL, border = 10) self.sizer.Fit(self.dlg) self.sizer.SetSizeHints(self.dlg)
def __init__(self): if not has_gui.has_gui: return main_win = has_gui.gui.TopLevel() if not main_win: return name = self.__class__.__module__.split('.')[-1] if name not in main_win.custom_menus: main_win.custom_menus[name] = None self.shell = main_win.shell self.locals = main_win.shell.locals menu = main_win.toolkit_menus[name] menu.AppendSeparator() if self._items == []: menu.Append(wx.NewId(), "--- empty ---") else: for item in self._items: if item == "-": menu.Break() else: menuID = wx.NewId() menu.Append(menuID, item) compat_wx.handle_event_1( main_win, wx.EVT_MENU, getattr(self, "_On" + util.string2identifier(item)), menuID)
def __init__(self, parent, ID, image_display): wx.GenericDirCtrl.__init__( self, parent, ID, filter="All files (*.*)|*.*|TIFF files (*.tiff,*.tif)|*.tiff,*.tif", style=wx.DIRCTRL_SHOW_FILTERS) # self.SetDefaultPath(config.options.file.default_directory) compat_wx.handle_event_1(self.GetTreeCtrl(), wx.EVT_TREE_ITEM_ACTIVATED, self.OnItemSelected, -1) self.image_display = image_display
def create_extra_methods(self, methods, menu): items = methods.items() items.sort() for key, val in items: if type(val) == dict: id = self.get_id() item = self.create_extra_methods(val, wx.Menu()) menu.AppendMenu(id, key, item) else: id = self.get_id() menu.Append(id, key) compat_wx.handle_event_1(self.parent, wx.EVT_MENU, val, id) return menu
def create_methods(self, methods, menu): items = sorted(methods.items()) for key, val in items: if type(val) == dict: item = self.create_methods(val, wx.Menu()) id = self.get_id() compat_wx.extend_menu(menu, id, key, item) else: id = self.get_id() menu.Append(id, key) compat_wx.handle_event_1(self.parent, wx.EVT_MENU, self.OnPopupFunction, id) self.functions[id] = val return menu
def AddSimpleTool(self, id, bitmap, help_string, callback=None, toggle=0): if not toggle: button = ButtonClass(self, id, bitmap, size=wx.Size(30,30)) else: button = ToggleButtonClass(self, id, bitmap, size=wx.Size(30,30)) button.SetBezelWidth(1) button.SetUseFocusIndicator(False) compat_wx.set_tool_tip(button, help_string) if callback: compat_wx.handle_event_1(self, wx.EVT_BUTTON, callback, id) self.sizer.Add(button, flag=wx.ALIGN_CENTER) self.sizer.SetSizeHints(self) self.controls.append(button) return button
def create_methods(self, methods, menu): items = methods.items() items.sort() for key, val in items: if type(val) == dict: item = self.create_methods(val, wx.Menu()) id = self.get_id() compat_wx.extend_menu(menu, id, key, item) else: id = self.get_id() menu.Append(id, key) compat_wx.handle_event_1(self.parent, wx.EVT_MENU, self.OnPopupFunction, id) self.functions[id] = val return menu
def build_menu(parent, menu_spec): global menu_item_id menu = wx.Menu() for name, func in menu_spec: if util.is_sequence(func): menu_item_id = wx.NewId() compat_wx.extend_menu(menu, menu_item_id, name, build_menu(parent, func)) elif name == None: menu.AppendSeparator() else: menu_item_id = wx.NewId() menu.Append(menu_item_id, name) compat_wx.handle_event_1(parent, wx.EVT_MENU, func, menu_item_id) return menu
def __init__(self, toplevel, parent): self.toplevel = toplevel self.modules = [] self.undo_history = [] self.added = [] self.removed = [] id = wx.NewId() wx.TreeCtrl.__init__(self, parent, id) self.root = self.AddRoot("RuleSets") self.SetItemHasChildren(self.root, True) compat_wx.set_tree_item_data(self, self.root, "") compat_wx.handle_event_1(self, wx.EVT_TREE_ITEM_ACTIVATED, self._OnActivated, id) self.Expand(self.root)
def init_events(self): tID = self.GetId() compat_wx.handle_event_1(self, wx.EVT_LIST_BEGIN_DRAG, self.OnMouseDown, tID) compat_wx.handle_event_0(self, wx.EVT_LEFT_DCLICK, self.OnDoubleClick) compat_wx.handle_event_1(self, wx.EVT_LIST_ITEM_SELECTED, self.OnItemSelected, tID) compat_wx.handle_event_1(self, wx.EVT_LIST_ITEM_ACTIVATED, self.OnItemSelected, tID) compat_wx.handle_event_1(self, wx.EVT_LIST_ITEM_RIGHT_CLICK, self.OnRightClick, tID) compat_wx.handle_event_0(self, wx.EVT_CHAR, self.OnKeyPress)
def get_control(self, parent, locals=None, text=None): if text is None: text = self.default self.control = wx.BoxSizer(wx.HORIZONTAL) self.text = wx.TextCtrl(parent, -1, text, size=wx.Size(200, 24)) browseID = wx.NewId() if wx.Platform == '__WXMAC__' and hasattr(buttons, 'ThemedGenButton'): browse = buttons.ThemedGenButton( parent, browseID, "...", size=wx.Size(24, 24)) else: browse = wx.Button( parent, browseID, "...", size=wx.Size(24, 24)) compat_wx.handle_event_1(browse, wx.EVT_BUTTON, self.OnBrowse, browseID) self.control.Add(self.text, 1, wx.EXPAND) self.control.Add((4, 4), 0) self.control.Add(browse, 0) return self
def AddMenuTool(self, id, text, help_string, callback=None, toggle=0): if not toggle: button = buttons.GenBitmapTextButton( self, id, None, text, size=wx.Size(48, 28)) else: button = buttons.GenBitmapTextToggleButton( self, id, None, text, size=wx.Size(48,28)) button.SetBitmapLabel(gamera_icons.getToolbarMenuBitmap()) button.SetBezelWidth(1) button.SetUseFocusIndicator(False) compat_wx.set_tool_tip(button, help_string) if callback: compat_wx.handle_event_1(self, wx.EVT_BUTTON, callback, id) self.sizer.Add(button, flag=wx.ALIGN_CENTER) self.sizer.SetSizeHints(self) self.controls.append(button) return button
def make_menu(self): self.custom_menus = {} file_menu = gui_util.build_menu( self, (("&Open image...", self._OnFileOpen), ("&Image browser...", self._OnImageBrowser), (None, None), ("Open &XML...", self._OnLoadXML), (None, None), ("Execute &code...", self._OnExecFile), ("&Save history...", self._OnSaveHistory), (None, None), ("&Biollante...", self._OnBiollante), (None, None), ("E&xit...", self._OnCloseWindow))) classify_menu = gui_util.build_menu( self, (("&Interactive classifier", self._OnClassifier),)) toolkits = paths.get_toolkit_names(paths.toolkits) self.import_toolkits = {} self.reload_toolkits = {} self.toolkit_menus = {} toolkits_menu = wx.Menu() if len(toolkits): for toolkit in toolkits: toolkitID = wx.NewId() toolkit_menu = wx.Menu() #style=wxMENU_TEAROFF) toolkit_menu.Append(toolkitID, "Import '%s' toolkit" % toolkit, "Import %s toolkit" % toolkit) compat_wx.handle_event_1(self, wx.EVT_MENU, self._OnImportToolkit, toolkitID) self.import_toolkits[toolkitID] = toolkit toolkitID = wx.NewId() toolkit_menu.Append(toolkitID, "Reload '%s' toolkit" % toolkit, "Reload %s toolkit" % toolkit) compat_wx.handle_event_1(self, wx.EVT_MENU, self._OnReloadToolkit, toolkitID) self.reload_toolkits[toolkitID] = toolkit toolkits_menu.AppendMenu(wx.NewId(), toolkit, toolkit_menu) self.toolkit_menus[toolkit] = toolkit_menu else: toolkits_menu.Append(wx.NewId(), "No toolkits installed.") menubar = wx.MenuBar() menubar.Append(file_menu, "&File") menubar.Append(classify_menu, "&Classify") menubar.Append(toolkits_menu, "&Toolkits") return menubar
def get_control(self, parent, locals=None, text=None): if text is None: text = self.default self.control = wx.BoxSizer(wx.HORIZONTAL) self.text = wx.TextCtrl(parent, -1, text, size=wx.Size(200, 24)) browseID = wx.NewId() if wx.Platform == '__WXMAC__' and hasattr(buttons, 'ThemedGenButton'): browse = buttons.ThemedGenButton(parent, browseID, "...", size=wx.Size(24, 24)) else: browse = wx.Button(parent, browseID, "...", size=wx.Size(24, 24)) compat_wx.handle_event_1(browse, wx.EVT_BUTTON, self.OnBrowse, browseID) self.control.Add(self.text, 1, wx.EXPAND) self.control.Add((4, 4), 0) self.control.Add(browse, 0) return self
def __init__(self): if not has_gui.has_gui: return main_win = has_gui.gui.TopLevel() if not main_win: return name = self.__class__.__module__.split('.')[-1] if not main_win.custom_menus.has_key(name): main_win.custom_menus[name] = None self.shell = main_win.shell self.locals = main_win.shell.locals menu = main_win.toolkit_menus[name] menu.AppendSeparator() if self._items == []: menu.Append(wx.NewId(), "--- empty ---") else: for item in self._items: if item == "-": menu.Break() else: menuID = wx.NewId() menu.Append(menuID, item) compat_wx.handle_event_1(main_win, wx.EVT_MENU, getattr(self, "_On" + util.string2identifier(item)), menuID)
def create_menu(self, members, methods, type, type_name, extra_methods): menu = wx.Menu() # Top line if self.mode == HELP_MODE: menu.Append(0, "Help") id = self.get_id() menu.Append(id, type_name + " Image") menu.AppendSeparator() id = self.get_id() menu.Append(id, "new reference") compat_wx.handle_event_1(self.parent, wx.EVT_MENU, self.OnCreateReference, id) id = self.get_id() menu.Append(id, "new copy") compat_wx.handle_event_1(self.parent, wx.EVT_MENU, self.OnCreateCopy, id) id = self.get_id() menu.Append(id, "delete image") compat_wx.handle_event_1(self.parent, wx.EVT_MENU, self.OnDeleteImage, id) menu.AppendSeparator() info_menu = wx.Menu() id = self.get_id() compat_wx.extend_menu(menu, id, "Info", info_menu) # Variables for member in members: id = self.get_id() info_menu.Append(id, member) # Methods menu.AppendSeparator() self.functions = {} menu = self.create_methods(methods, menu) # Extra methods if len(extra_methods): menu.AppendSeparator() menu = self.create_extra_methods(extra_methods, menu) return menu