def create_popup_menu(self): menu = Menu() self.create_menu_item(menu, self.translate("open", self.lang), self.left_click) menu.AppendSeparator() self.create_menu_item(menu, self.translate("copy_address", self.lang), self.copy_address) menu.AppendSeparator() self.create_menu_item(menu, self.translate("exit", self.lang), self.on_exit) return menu
def create_menubar(self, language_list, style=0): modifier = 'Ctrl' if name == 'nt' else 'Opt' menubar = MenuBar() menubar_file = Menu() menubar_file.Append(ID_FILE_EXPORT, '&Export\t' + modifier + 'E') menubar_file.AppendSeparator() menubar_file.Append(ID_FILE_EXIT, 'E&xit\t' + modifier + 'W') menubar_edit = Menu() menubar_edit_timer = Menu() menubar_edit.AppendSubMenu(menubar_edit_timer, '&Timer') menubar_edit_timer.Append(ID_EDIT_TIMER_START, '&Start\t' + modifier + 'S') menubar_edit_timer.Append(ID_EDIT_TIMER_PAUSE, '&Pause\t' + modifier + 'P') menubar_edit_timer.Append(ID_EDIT_TIMER_RESET, '&Reset\t' + modifier + 'R') menubar_edit_time_stamp = Menu() menubar_edit.AppendSubMenu(menubar_edit_time_stamp, 'Time &Stamp') menubar_edit_time_stamp.Append(ID_EDIT_TIME_STAMP_NEW, '&New\t' + modifier + 'N') menubar_view = Menu() menubar_view.AppendCheckItem(ID_VIEW_SHOW_PREVIEW, 'Show &Preview\t' + modifier + 'Shift+P') menubar_view_language = Menu() language_menu_item_list = [] if language_list is not None: menubar_view_language.Bind(EVT_MENU, lambda x: self.change_language()) menubar_view.AppendSubMenu(menubar_view_language, '&Language') for n in range(len(language_list)): language_menu_item_list.append( menubar_view_language.AppendRadioItem( ID_ANY, language_list[n]['Language Setting'])) menubar_help = Menu() menubar_help.Append(ID_HELP_WELCOME, '&Welcome\t' + modifier + 'Shift+H') menubar_help.AppendSeparator() menubar_help.Append(ID_HELP_VISIT_GITHUB, 'Visit &Github') menubar_help.AppendSeparator() menubar_help.Append(ID_HELP_ABOUT, '&About') menubar.Append(menubar_file, '&File') menubar.Append(menubar_edit, '&Edit') menubar.Append(menubar_view, '&View') menubar.Append(menubar_help, '&Help') return menubar, language_menu_item_list
def register_menu(self, menu: wx.Menu, parent: wx.Window): commands = [cast(CommandPlugin, p) for p in self.plugins if p.ptype == PluginType.COMMAND] windowed = [cast(WindowedPlugin, p) for p in self.plugins if p.ptype == PluginType.WINDOWED] if len(self.plugins) != 0: menu.AppendSeparator() for plugin in commands: id_ = wx.NewIdRef(count=1) item = menu.Append(id_, plugin.metadata.name) menu.Bind(wx.EVT_MENU, self.make_command_callback(plugin), item) if len(commands) != 0 and len(windowed) != 0: menu.AppendSeparator() for plugin in windowed: id_ = wx.NewIdRef(count=1) item = menu.Append(id_, plugin.metadata.name) menu.Bind(wx.EVT_MENU, self.make_windowed_callback(plugin, parent), item)
def CreatePopupMenu(self): menu = Menu() appMenuItem = menu.Append(ID_ANY, "mHosts v" + Settings.version()) if sys.platform != "linux": appMenuItem.Enable(False) appMenuItem.SetBitmap( Bitmap(ResPath("icons/logo.png"), BITMAP_TYPE_PNG)) menu.Append(self.ID_TOGGLE, r"%s主窗口" % ("隐藏" if self.__window.IsShown() else "显示")) menu.AppendSeparator() for hosts in Settings.settings["hosts"]: item = MenuItem(menu, hosts["id"], hosts["name"], kind=ITEM_CHECK) item.Enable(not hosts['alwaysApply']) menu.Append(item) menu.Check(hosts["id"], hosts["active"] or hosts["alwaysApply"]) self.Bind(EVT_MENU, self.__window.OnTaskBarHostsMenuClicked, id=hosts["id"]) newHostMenu = Menu() newHostMenu.Append(self.ID_NEW, "新建") if sys.platform != "linux": newHostMenu.Append(self.ID_IMPORT, "导入").Enable(False) menu.Append(-1, "新建Hosts方案", newHostMenu) menu.AppendSeparator() menu.Append(self.ID_REFRESH_DNS, u"刷新DNS缓存") if os.path.exists(Settings.settings["chromePath"]): chromeMenu = Menu() chromeMenu.Append(self.ID_LUNCH_CHROME, "直接启动") chromeMenu.Append(self.ID_LUNCH_CHROME_CROS, "允许跨域请求") chromeMenu.Append(self.ID_LUNCH_CHROME_NO_PLUGINS, "禁用所有插件") menu.Append(-1, "启动 Google Chrome 浏览器", chromeMenu) menu.AppendSeparator() menu.Append(self.ID_ABOUT, "关于") menu.Append(self.ID_EXIT, "退出") self.menu = menu return menu
def ShowTreeItemMenu(self, event): hosts = self.hostsTree.GetItemData(event.GetItem()) if not hosts: return self.__currentSelectHost = hosts menu = Menu() popMenuActive = menu.Append(TrayIcon.ID_TREE_MENU_SET_ACTIVE, "设置为当前Hosts") if hosts["id"] == ID_SYSTEM_HOSTS or hosts['alwaysApply']: popMenuActive.Enable(False) else: popMenuActive.Enable(not hosts["active"]) menu.AppendSeparator() popMenuEdit = menu.Append(TrayIcon.ID_TREE_MENU_EDIT, "编辑") popMenuEdit.Enable(hosts["id"] != ID_SYSTEM_HOSTS) popMenuDelete = menu.Append(TrayIcon.ID_TREE_MENU_DELETE, "删除") popMenuDelete.Enable(hosts["id"] != ID_SYSTEM_HOSTS) # menu.Append(TrayIcon.ID_TREE_MENU_REFRESH, "刷新") self.hostsTree.PopupMenu(menu, event.GetPoint()) self.hostsTree.Bind(EVT_MENU, self.OnMenuClicked)
class MainFrame(Frame): def __init__(self, parent, dpi=(1, 1)): Frame.__init__(self, parent, id=ID_ANY, title=u" mHosts - v" + Settings.version(), pos=DefaultPosition, size=Size(700 * dpi[0], 500 * dpi[1]), style=DEFAULT_FRAME_STYLE | SYSTEM_MENU | TAB_TRAVERSAL) self.SetIcon(Icon(iconPath, BITMAP_TYPE_ICO)) self.SetSizeHints(Size(500 * dpi[0], 350 * dpi[1])) self.menuBar = MenuBar(0) self.menuFile = Menu() self.menuItemNew = MenuItem(self.menuFile, ID_ANY, u"新建(&N)", EmptyString, ITEM_NORMAL) self.menuItemImport = MenuItem(self.menuFile, ID_ANY, u"导入(&I)", EmptyString, ITEM_NORMAL) if sys.platform != "linux": self.menuItemImport.Enable(False) self.menuFile.Append(self.menuItemNew) self.menuFile.Append(self.menuItemImport) self.menuFile.AppendSeparator() self.menuItemExit = MenuItem(self.menuFile, ID_ANY, u"退出(&Q)", EmptyString, ITEM_NORMAL) self.menuFile.Append(self.menuItemExit) self.menuBar.Append(self.menuFile, u"文件(&F)") self.menuHelp = Menu() self.menuItemSettings = MenuItem(self.menuHelp, ID_ANY, u"首选项(&P)", EmptyString, ITEM_NORMAL) if sys.platform != "linux": self.menuItemSettings.Enable(False) self.menuHelp.Append(self.menuItemSettings) self.menuItemHelpDoc = MenuItem(self.menuHelp, ID_ANY, u"帮助文档(&D)", EmptyString, ITEM_NORMAL) self.menuHelp.Append(self.menuItemHelpDoc) self.menuItemCheckUpdate = MenuItem(self.menuHelp, ID_ANY, u"检查更新(&U)", EmptyString, ITEM_NORMAL) self.menuHelp.Append(self.menuItemCheckUpdate) self.menuItemAbout = MenuItem(self.menuHelp, ID_ANY, u"关于(&A)", EmptyString, ITEM_NORMAL) self.menuHelp.Append(self.menuItemAbout) self.menuBar.Append(self.menuHelp, u"帮助(&H)") self.SetMenuBar(self.menuBar) self.statusBar = StatusBar(self, ID_ANY, STB_SIZEGRIP) statusBarFont = Font(10, FONTFAMILY_DEFAULT, FONTSTYLE_NORMAL, FONTWEIGHT_NORMAL, False, EmptyString) self.statusBar.SetFont(statusBarFont) self.SetStatusBar(self.statusBar) bSizer1 = BoxSizer(HORIZONTAL) self.images = {} self.imageList = ImageList(width=12, height=12) iconList = GetIcons().items() for name, bitmap in iconList: self.images[name] = self.imageList.Add(bitmap) self.hostsTree = TreeCtrl(self, ID_ANY, Point(0, 0), Size(180 * dpi[0], -1), TR_DEFAULT_STYLE) self.hostsTree.SetImageList(self.imageList) bSizer1.Add(self.hostsTree, 0, EXPAND, 5) # self.hostsListView = CheckListBox(self, size=Size(size[0] / 9, -1)) # bSizer1.Add(self.hostsListView, 0, EXPAND, 5) # WARNING: wxPython code generation isn't supported for this widget yet. self.codeEditor = CodeView(self, dpi) bSizer1.Add(self.codeEditor, 1, EXPAND, 5) self.SetSizer(bSizer1) self.Layout() self.Centre(BOTH) # Connect Events self.Bind(EVT_MENU, self.OnMenuClicked, id=self.menuItemNew.GetId()) self.Bind(EVT_MENU, self.OnMenuClicked, id=self.menuItemExit.GetId()) self.Bind(EVT_MENU, self.OnMenuClicked, id=self.menuItemAbout.GetId()) self.Bind(EVT_MENU, self.OnMenuClicked, id=self.menuItemHelpDoc.GetId()) self.Bind(EVT_MENU, self.OnMenuClicked, id=self.menuItemSettings.GetId()) self.Bind(EVT_MENU, self.OnMenuClicked, id=self.menuItemImport.GetId()) self.Bind(EVT_MENU, self.OnMenuClicked, id=self.menuItemCheckUpdate.GetId()) def __del__(self): pass def Destroy(self): self.imageList.Destroy() Frame.Destroy(self) # Virtual event handlers, overide them in your derived class def OnMenuClicked(self, event): event.Skip()
def initMenus(self): self.mnuFileNew = Menu() self.mnuFileNew.Append(SharedIdentifiers.ID_MNUFILENEWPROJECT, _("&New project\tCtrl-N"), _("New project")) self.mnuFileNew.Append(SharedIdentifiers.ID_MNU_FILE_NEW_CLASS_DIAGRAM, _("New c&lass diagram\tCtrl-L"), _("New class diagram")) self.mnuFileNew.Append(SharedIdentifiers.ID_MNU_FILE_NEW_SEQUENCE_DIAGRAM, _("New s&equence diagram\tCtrl-E"), _("New sequence diagram")) self.mnuFileNew.Append(SharedIdentifiers.ID_MNU_FILE_NEW_USECASE_DIAGRAM, _("New &use-case diagram\tCtrl-U"), _("New use-case diagram")) self.fileMenu.Append(NewId(), _("&New"), self.mnuFileNew) self.fileMenu.Append(SharedIdentifiers.ID_MNU_FILE_INSERT_PROJECT, _("&Insert a project...\t"), _("Insert a project in the current project...")) self.fileMenu.Append(SharedIdentifiers.ID_MNU_FILE_OPEN, _("&Open...\tCtrl-O"), _("Open a file...")) self.fileMenu.Append(SharedIdentifiers.ID_MNU_FILE_SAVE, _("&Save\tCtrl-S"), _("Save current data")) self.fileMenu.Append(SharedIdentifiers.ID_MNUFILESAVEAS, _("Save &As...\tCtrl-A"), _("Save current data")) self.fileMenu.Append(SharedIdentifiers.ID_MNU_PROJECT_CLOSE, _("&Close project\tCtrl-W"), _("Close current project")) self.fileMenu.Append(SharedIdentifiers.ID_MNU_FILE_REMOVE_DOCUMENT, _("&Remove document"), _("Remove the document from the project")) self.fileMenu.AppendSeparator() sub = self.makeExportMenu() if sub is None: sub = Menu() if sub is not None: self.fileMenu.Append(NewId(), _("Export"), sub) sub = self.makeImportMenu() if sub is not None: self.fileMenu.Append(NewId(), _("Import"), sub) self.fileMenu.AppendSeparator() self.fileMenu.Append(SharedIdentifiers.ID_MENU_FILE_PYUT_PREFERENCES, _("PyUt P&references"), _("PyUt preferences")) # self.fileMenu.Append(ID_MNU_FILE_DIAGRAM_PROPERTIES,_("&Diagram Properties"), _("Diagram properties")) self.fileMenu.AppendSeparator() self.fileMenu.Append(SharedIdentifiers.ID_MNU_FILE_PRINT_SETUP, _("Print se&tup..."), _("Display the print setup dialog box")) self.fileMenu.Append(SharedIdentifiers.ID_MNU_FILE_PRINT_PREVIEW, _("Print pre&view"), _("Diagram preview before printing")) self.fileMenu.Append(SharedIdentifiers.ID_MNU_FILE_PRINT, _("&Print\tCtrl-P"), _("Print the current diagram")) self.fileMenu.AppendSeparator() # Add Last opened files index = 0 # TODO : does not work ? verify function return... for el in self._prefs.getLastOpenedFilesList(): index += 1 # self.fileMenu.Append(self.lastOpenedFilesID[index - 1], "&" + str(index) + " " + el) lof: str = f"&{str(index)} {el}" self.logger.debug(f'self.lastOpenedFilesID[index - 1]: {self.lastOpenedFilesID[index - 1]} lof: {lof} ') self.fileMenu.Append(self.lastOpenedFilesID[index - 1], lof) for index in range(index, self._prefs.getNbLOF()): # self.fileMenu.Append(self.lastOpenedFilesID[index], "&" + str(index + 1) + " -") lofAgain: str = f"&{str(index + 1)} -" self.fileMenu.Append(self.lastOpenedFilesID[index], lofAgain) self.fileMenu.AppendSeparator() self.fileMenu.Append(SharedIdentifiers.ID_MNU_FILE_EXIT, _("E&xit"), _("Exit PyUt")) mnuEdit = Menu() mnuEdit.Append(SharedIdentifiers.ID_MNU_UNDO, _("&Undo\tCtrl-Z"), _("Undo the last performed action")) mnuEdit.Append(SharedIdentifiers.ID_MNU_REDO, _("&Redo\tCtrl-Y"), _("Redo the last undone action")) mnuEdit.AppendSeparator() mnuEdit.Append(SharedIdentifiers.ID_MNU_EDIT_CUT, _("Cu&t\tCtrl-X"), _("Cut selected data")) mnuEdit.Append(SharedIdentifiers.ID_MNU_EDIT_COPY, _("&Copy\tCtrl-C"), _("Copy selected data")) mnuEdit.Append(SharedIdentifiers.ID_MNU_EDIT_PASTE, _("&Paste\tCtrl-V"), _("Paste selected data")) mnuEdit.AppendSeparator() mnuEdit.Append(SharedIdentifiers.ID_MNU_EDIT_SELECT_ALL, _("&Select all"), _("Select all elements")) mnuEdit.AppendSeparator() mnuEdit.Append(SharedIdentifiers.ID_MNU_ADD_PYUT_HIERARCHY, _("&Add Pyut hierarchy"), _("Add the UML Diagram of Pyut")) mnuEdit.Append(SharedIdentifiers.ID_MNU_ADD_OGL_HIERARCHY, _("Add &Ogl hierarchy"), _("Add the UML Diagram of Pyut - Ogl")) if MenuCreator.DEBUG_ERROR_VIEWS is True: mnuEdit.AppendSeparator() mnuEdit.Append(SharedIdentifiers.ID_MENU_GRAPHIC_ERROR_VIEW, 'Show &Graphic Error View', 'Test graphical error view') mnuEdit.Append(SharedIdentifiers.ID_MENU_TEXT_ERROR_VIEW, 'Show &Text Error View', 'Test text error view') mnuEdit.Append(SharedIdentifiers.ID_MENU_RAISE_ERROR_VIEW, 'Show &Exception Error View', 'Test raising exception') # ----------------- # Tools menu # ----------------- mnuTools = Menu() sub = self.makeToolsMenu() if sub is not None: mnuTools.Append(NewId(), _("Plugins tools"), sub) sub = self.makeToolboxesMenu() if sub is not None: mnuTools.Append(NewId(), _("toolboxes"), sub) mnuHelp = Menu() mnuHelp.Append(SharedIdentifiers.ID_MNU_HELP_INDEX, _("&Index"), _("Display help index")) mnuHelp.AppendSeparator() mnuHelp.Append(SharedIdentifiers.ID_MNU_HELP_VERSION, _("Check for newer versions"), _("Check if a newer version of Pyut exists")) mnuHelp.Append(SharedIdentifiers.ID_MNU_HELP_WEB, _("&Web site"), _("Open PyUt web site")) mnuHelp.Append(SharedIdentifiers.ID_DEBUG, _("&Debug"), _("Open IPython shell")) mnuHelp.AppendSeparator() mnuHelp.Append(SharedIdentifiers.ID_MNU_HELP_ABOUT, _("&About PyUt..."), _("Display the About PyUt dialog box")) mnuBar = MenuBar() mnuBar.Append(self.fileMenu, _("&File")) mnuBar.Append(mnuEdit, _("&Edit")) mnuBar.Append(mnuTools, _("&Tools")) mnuBar.Append(mnuHelp, "&?") containingFrame: Frame = self._containingFrame containingFrame.SetMenuBar(mnuBar) cb: SharedTypes.CallbackMap = self._callbackMap containingFrame.Bind(EVT_MENU, cb[ActionCallbackType.NEW_PROJECT], id=SharedIdentifiers.ID_MNUFILENEWPROJECT) containingFrame.Bind(EVT_MENU, cb[ActionCallbackType.NEW_CLASS_DIAGRAM], id=SharedIdentifiers.ID_MNU_FILE_NEW_CLASS_DIAGRAM) containingFrame.Bind(EVT_MENU, cb[ActionCallbackType.NEW_SEQUENCE_DIAGRAM], id=SharedIdentifiers.ID_MNU_FILE_NEW_SEQUENCE_DIAGRAM) containingFrame.Bind(EVT_MENU, cb[ActionCallbackType.NEW_USE_CASE_DIAGRAM], id=SharedIdentifiers.ID_MNU_FILE_NEW_USECASE_DIAGRAM) containingFrame.Bind(EVT_MENU, cb[ActionCallbackType.INSERT_PROJECT], id=SharedIdentifiers.ID_MNU_FILE_INSERT_PROJECT) containingFrame.Bind(EVT_MENU, cb[ActionCallbackType.FILE_OPEN], id=SharedIdentifiers.ID_MNU_FILE_OPEN) containingFrame.Bind(EVT_MENU, cb[ActionCallbackType.FILE_SAVE], id=SharedIdentifiers.ID_MNU_FILE_SAVE) containingFrame.Bind(EVT_MENU, cb[ActionCallbackType.FILE_SAVE_AS], id=SharedIdentifiers.ID_MNUFILESAVEAS) containingFrame.Bind(EVT_MENU, cb[ActionCallbackType.PROJECT_CLOSE], id=SharedIdentifiers.ID_MNU_PROJECT_CLOSE) containingFrame.Bind(EVT_MENU, cb[ActionCallbackType.REMOVE_DOCUMENT], id=SharedIdentifiers.ID_MNU_FILE_REMOVE_DOCUMENT) containingFrame.Bind(EVT_MENU, cb[ActionCallbackType.PRINT_SETUP], id=SharedIdentifiers.ID_MNU_FILE_PRINT_SETUP) containingFrame.Bind(EVT_MENU, cb[ActionCallbackType.PRINT_PREVIEW], id=SharedIdentifiers.ID_MNU_FILE_PRINT_PREVIEW) containingFrame.Bind(EVT_MENU, cb[ActionCallbackType.PRINT], id=SharedIdentifiers.ID_MNU_FILE_PRINT) containingFrame.Bind(EVT_MENU, cb[ActionCallbackType.PYUT_PREFERENCES], id=SharedIdentifiers.ID_MENU_FILE_PYUT_PREFERENCES) # EVT_MENU(self, ID_MNU_FILE_DIAGRAM_PROPERTIES,self._OnMnuFileDiagramProperties) containingFrame.Bind(EVT_MENU, cb[ActionCallbackType.EXIT_PROGRAM], id=SharedIdentifiers.ID_MNU_FILE_EXIT) containingFrame.Bind(EVT_MENU, cb[ActionCallbackType.PROGRAM_ABOUT], id=SharedIdentifiers.ID_MNU_HELP_ABOUT) containingFrame.Bind(EVT_MENU, cb[ActionCallbackType.HELP_INDEX], id=SharedIdentifiers.ID_MNU_HELP_INDEX) containingFrame.Bind(EVT_MENU, cb[ActionCallbackType.HELP_VERSION], id=SharedIdentifiers.ID_MNU_HELP_VERSION) containingFrame.Bind(EVT_MENU, cb[ActionCallbackType.HELP_WEB], id=SharedIdentifiers.ID_MNU_HELP_WEB) containingFrame.Bind(EVT_MENU, cb[ActionCallbackType.ADD_PYUT_HIERARCHY], id=SharedIdentifiers.ID_MNU_ADD_PYUT_HIERARCHY) containingFrame.Bind(EVT_MENU, cb[ActionCallbackType.ADD_OGL_HIERARCHY], id=SharedIdentifiers.ID_MNU_ADD_OGL_HIERARCHY) if MenuCreator.DEBUG_ERROR_VIEWS is True: from org.pyut.experimental.DebugErrorViews import DebugErrorViews containingFrame.Bind(EVT_MENU, DebugErrorViews.debugGraphicErrorView, id=SharedIdentifiers.ID_MENU_GRAPHIC_ERROR_VIEW) containingFrame.Bind(EVT_MENU, DebugErrorViews.debugTextErrorView, id=SharedIdentifiers.ID_MENU_TEXT_ERROR_VIEW) containingFrame.Bind(EVT_MENU, DebugErrorViews.debugRaiseErrorView, id=SharedIdentifiers.ID_MENU_RAISE_ERROR_VIEW) containingFrame.Bind(EVT_MENU, cb[ActionCallbackType.EDIT_CUT], id=SharedIdentifiers.ID_MNU_EDIT_CUT) containingFrame.Bind(EVT_MENU, cb[ActionCallbackType.EDIT_COPY], id=SharedIdentifiers.ID_MNU_EDIT_COPY) containingFrame.Bind(EVT_MENU, cb[ActionCallbackType.EDIT_PASTE], id=SharedIdentifiers.ID_MNU_EDIT_PASTE) containingFrame.Bind(EVT_MENU, cb[ActionCallbackType.SELECT_ALL], id=SharedIdentifiers.ID_MNU_EDIT_SELECT_ALL) containingFrame.Bind(EVT_MENU, cb[ActionCallbackType.DEBUG], id=SharedIdentifiers.ID_DEBUG) containingFrame.Bind(EVT_MENU, cb[ActionCallbackType.UNDO], id=SharedIdentifiers.ID_MNU_UNDO) containingFrame.Bind(EVT_MENU, cb[ActionCallbackType.REDO], id=SharedIdentifiers.ID_MNU_REDO) for index in range(self._prefs.getNbLOF()): containingFrame.Bind(EVT_MENU, cb[ActionCallbackType.LAST_OPENED_FILES], id=self.lastOpenedFilesID[index]) containingFrame.Bind(EVT_CLOSE, cb[ActionCallbackType.CLOSE])