Ejemplo n.º 1
0
 def format_menu_item(self, obj: MenuItem):
     """Formats MenuItem info"""
     lines = [
         "MenuItem:",
         self.Fmt('class', obj.__class__),
         self.Fmt('bases', obj.__class__.__bases__),
         self.Fmt('module', inspect.getmodule(obj)),
         self.Fmt('id', obj.GetId()),
         self.Fmt('label', obj.GetLabel()),
         self.Fmt('kind', obj.GetKind())]
     return lines
Ejemplo n.º 2
0
    def _initializeTriStateDisplayParametersMenuItem(
            self, displayParameters: PyutDisplayParameters,
            itemToggleParameters: MenuItem):

        if displayParameters == PyutDisplayParameters.UNSPECIFIED:
            itemToggleParameters.SetBitmap(
                PyutConstants.unspecifiedDisplayMethodsIcon())
        elif displayParameters == PyutDisplayParameters.DISPLAY:
            itemToggleParameters.SetBitmap(PyutConstants.displayMethodsIcon())
        elif displayParameters == PyutDisplayParameters.DO_NOT_DISPLAY:
            itemToggleParameters.SetBitmap(
                PyutConstants.doNotDisplayMethodsIcon())
        else:
            assert False, 'Unknown display type'
Ejemplo n.º 3
0
    def __init__(self, parent):
        Menu.__init__(self)
        self.parent = parent

        men1 = MenuItem(self, 1, "Copy Address")
        self.Append(men1)
        self.Bind(EVT_MENU, self.parent.copy_account, men1)

        men2 = MenuItem(self, 2, "Open block explorer")
        self.Append(men2)
        self.Bind(EVT_MENU, self.parent.open_explorer, men2)

        men3 = MenuItem(self, 3, "Open in wallet")
        self.Append(men3)
        self.Bind(EVT_MENU, self.parent.open_wallet, men3)
Ejemplo n.º 4
0
 def __create_menu(self, data):
     for text, func in data:
         if type(func) in (list, tuple):
             submenu = Menu()
             for _text, _ in func:
                 _id = self.__text_and_item_data[_text].id
                 sitem = MenuItem(submenu, _id, _text)
                 submenu.AppendItem(sitem)
             self.AppendSubMenu(submenu, text)
         else:
             if text == self.SEPARATOR_TEXT:
                 self.AppendSeparator()
             else:
                 data = self.__text_and_item_data[text]
                 item = MenuItem(self, data.id, text)
                 self.AppendItem(item)
Ejemplo n.º 5
0
    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
Ejemplo n.º 6
0
    def _additem(self,
                 text,
                 bitmap=None,
                 callback=None,
                 kind=ITEM_NORMAL,
                 id=-1,
                 position=None):
        item = MenuItem(self, id, text, kind=kind)
        id = item.Id

        if bitmap is not None:
            self.SetItemBitmap(item, bitmap)

        if callback is not None:
            self.SetCallback(id, callback)

        if position is None:
            return self.AppendItem(item)
        else:
            return self.InsertItem(position, item)
Ejemplo n.º 7
0
    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())
Ejemplo n.º 8
0
    def notifyInApp(self):
        self.setUpdateData()

        if self.newData == None or self.get_update_fail == True:
            return

        update_string = ""
        update_changes = ""

        update_final_ver = self.getUpdateValue("updates", "latest_final_main")
        update_final_build = self.getUpdateValue("updates",
                                                 "latest_final_build")
        update_beta_ver = self.getUpdateValue("updates", "latest_beta_main")
        update_beta_build = self.getUpdateValue("updates", "latest_beta_build")

        if bool(self.getUpdateValue("updates", "update")):
            if bool(self.cur_app_isbeta):
                if decimal.Decimal(update_beta_ver) > decimal.Decimal(
                        self.cur_app_version):
                    update_string = update_beta_ver + "b" + update_beta_build
                    update_changes = self.getUpdateValue(
                        "updates", "beta_changes")

                if decimal.Decimal(update_beta_build) > decimal.Decimal(
                        self.cur_app_build):
                    update_string = update_beta_ver + "b" + update_beta_build
                    update_changes = self.getUpdateValue(
                        "updates", "beta_changes")
            else:
                if decimal.Decimal(update_final_ver) > decimal.Decimal(
                        self.cur_app_version):
                    update_string = update_final_ver + "b" + update_final_build
                    update_changes = self.getUpdateValue(
                        "updates", "final_changes")

                if decimal.Decimal(update_final_build) > decimal.Decimal(
                        self.cur_app_build):
                    update_string = update_final_ver + "b" + update_final_build
                    update_changes = self.getUpdateValue(
                        "updates", "final_changes")

        if bool(self.getUpdateValue("updates", "notification")):
            self.notify_msg = self.getUpdateValue("updates",
                                                  "notification_msg")

        if self.parent.close_after_update:
            self.parent.Destroy()

        if update_string != "":
            from wx import Menu, MenuItem, EVT_MENU

            self.parent.update_ver = update_string + (
                "beta" if self.cur_app_isbeta else "")
            self.parent.update_changes = ("\n".join(
                update_changes.split('\\n')))

            updateMenu = Menu()
            updateMenu.AppendItem(
                MenuItem(updateMenu, 300, 'Version ' + update_string))
            self.parent.Bind(EVT_MENU, self.parent.showUpdate, id=300)
            self.parent.menuBar.Append(updateMenu, "Update Available ")

        if self.parent.close_after_update:
            self.parent.Destroy()
Ejemplo n.º 9
0
 def create_menu_item(menu, label, func):
     item = MenuItem(menu, -1, label)
     menu.Bind(EVT_MENU, func, id=item.GetId())
     menu.Append(item)
     return item
Ejemplo n.º 10
0
 def AddSepAt(self, i):
     return self.InsertItem(i, MenuItem(self))
Ejemplo n.º 11
0
 def AddSep(self):
     return self.AppendItem(MenuItem(self))