Example #1
0
    def _bindHelpMenuHandlers(self, containingFrame: Frame,
                              helpMenuHandler: HelpMenuHandler):

        containingFrame.Bind(EVT_MENU, helpMenuHandler.onAbout, id=ID_ABOUT)
        containingFrame.Bind(EVT_MENU,
                             helpMenuHandler.onHelpIndex,
                             id=SharedIdentifiers.ID_MNU_HELP_INDEX)
        containingFrame.Bind(EVT_MENU,
                             helpMenuHandler.onHelpVersion,
                             id=SharedIdentifiers.ID_MNU_HELP_VERSION)
        containingFrame.Bind(EVT_MENU,
                             helpMenuHandler.onHelpWeb,
                             id=SharedIdentifiers.ID_MNU_HELP_WEB)
        containingFrame.Bind(EVT_MENU,
                             helpMenuHandler.onDebug,
                             id=SharedIdentifiers.ID_DEBUG)
Example #2
0
    def __init__(self, frame: wx.Frame, change_callback: typing.Callable):
        self.__view_select_radio = RadioHandler([
            ('Groups', ViewType.GROUPS.value), ('Tree', ViewType.TREE.value)
        ])
        self.__tag_info_radio = RadioHandler([
            ('Tooltips', TagInfo.TOOLTIPS.value),
            ('Labels', TagInfo.LABELS.value)
        ])

        self.__view_menu = wx.Menu()
        self.__view_select_radio.append_menu_items(self.__view_menu,
                                                   ViewType.TREE)
        self.__view_menu.AppendSeparator()
        self.__dark_mode: wx.MenuItem = self.__view_menu.Append(
            wx.ID_ANY, 'Dark mode', kind=wx.ITEM_CHECK)
        self.__view_menu.AppendSeparator()
        tag_info_sub = wx.Menu()
        self.__tag_info_radio.append_menu_items(tag_info_sub, TagInfo.TOOLTIPS)
        self.__view_menu.AppendSubMenu(tag_info_sub, 'Tag information')

        self.__change_callback = change_callback
        frame.Bind(wx.EVT_MENU, self.event_dark_mode, self.__dark_mode)

        self.__view_select_radio.bind(frame, change_callback)
        self.__tag_info_radio.bind(frame, lambda: change_callback(True))
Example #3
0
def frame(element, instance: wx.Frame):
    props = element['props']
    set_basic_props(instance, props)
    if 'title' in props:
        instance.SetTitle(props['title'])
    if 'show' in props:
        instance.Show(props['show'])
    if 'size' in props:
        instance.SetSize(props['size'])
    if 'icon_uri' in props:
        instance.SetIcon(wx.Icon(props['icon_uri']))
    if 'on_close' in props:
        instance.Bind(wx.EVT_CLOSE, props['on_close'])
    else:
        instance.SetIcon(wx.Icon(os.path.join(dirname, 'icon.png')))
    return instance
Example #4
0
 def bind(self, frame: wx.Frame, callback: typing.Callable):
     for menu_item in self.__menu_items.values():
         frame.Bind(wx.EVT_MENU, lambda _: callback(), menu_item)
Example #5
0
    def _bindEditMenuHandlers(self, containingFrame: Frame,
                              editMenuHandler: EditMenuHandler):

        containingFrame.Bind(EVT_MENU,
                             editMenuHandler.onUndo,
                             id=SharedIdentifiers.ID_MNU_UNDO)
        containingFrame.Bind(EVT_MENU,
                             editMenuHandler.onRedo,
                             id=SharedIdentifiers.ID_MNU_REDO)

        containingFrame.Bind(EVT_MENU,
                             editMenuHandler.onCut,
                             id=SharedIdentifiers.ID_MNU_EDIT_CUT)
        containingFrame.Bind(EVT_MENU,
                             editMenuHandler.onCopy,
                             id=SharedIdentifiers.ID_MNU_EDIT_COPY)
        containingFrame.Bind(EVT_MENU,
                             editMenuHandler.onPaste,
                             id=SharedIdentifiers.ID_MNU_EDIT_PASTE)

        containingFrame.Bind(EVT_MENU,
                             editMenuHandler.onAddPyut,
                             id=SharedIdentifiers.ID_MNU_ADD_PYUT_HIERARCHY)
        containingFrame.Bind(EVT_MENU,
                             editMenuHandler.onAddOgl,
                             id=SharedIdentifiers.ID_MNU_ADD_OGL_HIERARCHY)

        containingFrame.Bind(EVT_MENU,
                             editMenuHandler.onSelectAll,
                             id=SharedIdentifiers.ID_MNU_EDIT_SELECT_ALL)

        if self._prefs.debugErrorViews 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)
Example #6
0
    def _bindFileMenuHandlers(self, containingFrame: Frame,
                              fileMenuHandler: FileMenuHandler):

        containingFrame.Bind(EVT_MENU,
                             fileMenuHandler.onNewProject,
                             id=SharedIdentifiers.ID_MNUFILENEWPROJECT)
        containingFrame.Bind(
            EVT_MENU,
            fileMenuHandler.onNewClassDiagram,
            id=SharedIdentifiers.ID_MNU_FILE_NEW_CLASS_DIAGRAM)
        containingFrame.Bind(
            EVT_MENU,
            fileMenuHandler.onNewSequenceDiagram,
            id=SharedIdentifiers.ID_MNU_FILE_NEW_SEQUENCE_DIAGRAM)
        containingFrame.Bind(
            EVT_MENU,
            fileMenuHandler.onNewUsecaseDiagram,
            id=SharedIdentifiers.ID_MNU_FILE_NEW_USECASE_DIAGRAM)
        containingFrame.Bind(EVT_MENU,
                             fileMenuHandler.onFileInsertProject,
                             id=SharedIdentifiers.ID_MNU_FILE_INSERT_PROJECT)
        containingFrame.Bind(EVT_MENU,
                             fileMenuHandler.onFileOpen,
                             id=SharedIdentifiers.ID_MNU_FILE_OPEN)
        containingFrame.Bind(EVT_MENU,
                             fileMenuHandler.onFileSave,
                             id=SharedIdentifiers.ID_MNU_FILE_SAVE)
        containingFrame.Bind(EVT_MENU,
                             fileMenuHandler.onFileSaveAs,
                             id=SharedIdentifiers.ID_MNUFILESAVEAS)
        containingFrame.Bind(EVT_MENU,
                             fileMenuHandler.onFileClose,
                             id=SharedIdentifiers.ID_MNU_PROJECT_CLOSE)
        containingFrame.Bind(EVT_MENU,
                             fileMenuHandler.onRemoveDocument,
                             id=SharedIdentifiers.ID_MNU_FILE_REMOVE_DOCUMENT)
        containingFrame.Bind(EVT_MENU,
                             fileMenuHandler.onPrintSetup,
                             id=SharedIdentifiers.ID_MNU_FILE_PRINT_SETUP)
        containingFrame.Bind(EVT_MENU,
                             fileMenuHandler.onPrintPreview,
                             id=SharedIdentifiers.ID_MNU_FILE_PRINT_PREVIEW)
        containingFrame.Bind(EVT_MENU,
                             fileMenuHandler.onPrint,
                             id=SharedIdentifiers.ID_MNU_FILE_PRINT)

        #  EVT_MENU(self, ID_MNU_FILE_DIAGRAM_PROPERTIES,self._OnMnuFileDiagramProperties)

        for index in range(self._prefs.getNbLOF()):
            containingFrame.Bind(EVT_MENU,
                                 fileMenuHandler.onRecentlyOpenedFile,
                                 id=self.lastOpenedFilesID[index])

        containingFrame.Bind(EVT_MENU,
                             fileMenuHandler.onPyutPreferences,
                             id=ID_PREFERENCES)
        containingFrame.Bind(EVT_MENU, fileMenuHandler.onExit, id=ID_EXIT)
Example #7
0
class MyTaskBarIcon(TaskBarIcon):
    ICON = "logo.ico"  # 图标地址
    ID_ABOUT = NewIdRef()  # 菜单选项“关于”的ID
    ID_EXIT = NewIdRef()  # 菜单选项“退出”的ID
    ID_UPLOAD = NewIdRef()  # 菜单选项“显示页面”的ID
    ID_LOGIN = NewIdRef()  # 菜单选项“显示页面”的ID
    TITLE = "SMPIC"  # 鼠标移动到图标上显示的文字

    def __init__(self):
        TaskBarIcon.__init__(self)
        self.SetIcon(Icon(self.ICON), self.TITLE)  # 设置图标和标题
        self.Bind(EVT_MENU, self.onAbout, id=self.ID_ABOUT)  # 绑定“关于”选项的点击事件
        self.Bind(EVT_MENU, self.onExit, id=self.ID_EXIT)  # 绑定“退出”选项的点击事件
        self.Bind(EVT_MENU, self.onUpload, id=self.ID_UPLOAD)
        self.Bind(EVT_MENU, self.OnLogin, id=self.ID_LOGIN)

        self.frame = Frame(parent=None, title='登录', size=(285, 160))
        self.frame.Bind(EVT_CLOSE, lambda event: self.frame.Show(False))

        panel = Panel(self.frame, -1)
        label_user = StaticText(panel, -1, "账号:", pos=(10, 10))
        label_pass = StaticText(panel, -1, "密码:", pos=(10, 50))

        self.entry_user = TextCtrl(panel, -1, size=(210, 20), pos=(50, 10))
        self.entry_pass = TextCtrl(panel, -1, size=(210, 20), pos=(50, 50), style=TE_PASSWORD)

        self.but_login = Button(panel, -1, "登陆", size=(50, 30), pos=(10, 80))
        self.but_register = Button(panel, -1, "注册SM.MS账号", size=(110, 30), pos=(150, 80))
        self.but_not_login = Button(panel, -1, "免登陆使用", size=(80, 30), pos=(65, 80))

        self.but_login.Bind(EVT_BUTTON, self.on_but_login)
        self.but_register.Bind(EVT_BUTTON, self.on_but_register)
        self.but_not_login.Bind(EVT_BUTTON, self.on_but_not_login)

        self.frame.Center()
        token = init_config()
        if token == '0':
            self.frame.Show(True)
        else:
            self.frame.Show(False)

        self.frame.SetMaxSize((285, 160))
        self.frame.SetMinSize((285, 160))
        ThreadKey(self)

        self.frame2 = Trans(parent=None, title='上传中', size=(50, 20))
        self.frame2.Center()
        self.frame2.Show(False)

        self.frame3 = Trans(parent=None, title='上传成功', size=(50, 20))
        self.frame3.Center()
        self.frame3.Show(False)

        self.frame4 = Trans(parent=None, title='上传失败', size=(50, 20))
        self.frame4.Center()
        self.frame4.Show(False)

        self.frame5 = Trans(parent=None, title='每分钟限制上传20张,请等待冷却', size=(200, 20))
        self.frame5.Center()
        self.frame5.Show(False)

    # “关于”选项的事件处理器
    def onAbout(self, event):
        MessageBox('Author:Jack Wang\nEmail Address:[email protected]\nLatest Update:2019-12-13', "info")

    # “退出”选项的事件处理器
    def onExit(self, event):
        global listener
        listener.stop()
        Exit()

    # “显示页面”选项的事件处理器
    def onUpload(self, event):
        get_pic_from_clipboard(self)

    def OnLogin(self, event):
        self.frame.Show(True)

    # 创建菜单选项
    def CreatePopupMenu(self):
        menu = Menu()
        for mentAttr in self.getMenuAttrs():
            menu.Append(mentAttr[1], mentAttr[0])
        return menu

    # 获取菜单的属性元组
    def getMenuAttrs(self):
        return [('上传剪贴板至SM.MS', self.ID_UPLOAD),
                ('登录', self.ID_LOGIN),
                ('关于', self.ID_ABOUT),
                ('退出', self.ID_EXIT)]

    def on_but_login(self, event):
        username = self.entry_user.GetValue()
        password = self.entry_pass.GetValue()
        try:
            token = Smms.get_token(username, password)
            with open('config.yml', 'r', encoding='utf-8') as f:
                cont = f.read()
                config = yaml.load(cont, Loader=yaml.BaseLoader)
                with open('config.yml', 'w', encoding='utf-8') as f:
                    config['token'] = token
                    yaml.dump(config, f, default_flow_style=False, encoding='utf-8', allow_unicode=True)
            self.frame.Show(False)
            MessageBox('登陆成功!\n'
                       '使用方法:\n1.首先复制一张图片,本地的或者网\n'
                       '页上的,或者使用截图工具截图;\n'
                       '2.随后按' + hotkeys + '上传;\n'
                                           '3.成功后会返回url至你的剪贴板。\n\n提示:\n可编辑config.yml修改快捷键',
                       "温馨提示")
        except KeyError:
            MessageBox('密码或账号错误', "警告")

    def on_but_not_login(self, event):
        try:
            with open('config.yml', 'r', encoding='utf-8') as f:
                cont = f.read()
                config = yaml.load(cont, Loader=yaml.BaseLoader)
                with open('config.yml', 'w', encoding='utf-8') as f:
                    config['token'] = 'not login'
                    yaml.dump(config, f, default_flow_style=False, encoding='utf-8', allow_unicode=True)
            self.frame.Show(False)

            MessageBox(
                '使用方法:\n1.首先复制一张图片,本地的或者网\n'
                '页上的,或者使用截图工具截图;\n'
                '2.随后按' + hotkeys + '上传;\n'
                                    '3.成功后会返回url至你的剪贴板。\n\n提示:\n1.免登录使用将无法在线查看你的全部上\n传记录,仅可查看本IP的上传记录\n2.可编辑config.yml修改快捷键',
                "温馨提示")
        except KeyError:
            MessageBox('出现了未知问题,请提交issue', "警告")

    def on_but_register(self, event):
        openweb('https://sm.ms/register')

    def LoginAgain(self):  # 删除线程
        MessageBox('登录已失效,需重新登录', "警告")
        self.frame.Show(True)

    def Uploading(self):
        pos = GetMousePosition()
        pos = (pos[0] + 15, pos[1])
        self.frame2.SetPosition(pos)
        def timestop():
            self.frame2.Show(False)
            timer.cancel()

        self.frame2.Show(True)
        timer = Timer(2.0, timestop)
        timer.start()

    def UploadSuccess(self):
        pos = GetMousePosition()
        pos = (pos[0] + 15, pos[1])
        self.frame3.SetPosition(pos)
        def timestop():
            self.frame3.Show(False)
            timer.cancel()

        self.frame3.Show(True)
        timer = Timer(2.0, timestop)
        timer.start()

    def UploadFailed(self):
        pos = GetMousePosition()
        pos = (pos[0] + 15, pos[1])
        self.frame4.SetPosition(pos)
        def timestop():
            self.frame4.Show(False)
            timer.cancel()

        self.frame4.Show(True)
        timer = Timer(2.0, timestop)
        timer.start()

    def UploadMax(self):
        pos = GetMousePosition()
        pos = (pos[0]+15,pos[1])
        self.frame5.SetPosition(pos)
        def timestop():
            self.frame5.Show(False)
            timer.cancel()

        self.frame5.Show(True)
        timer = Timer(5.0, timestop)
        timer.start()