Ejemplo n.º 1
0
    def testToString(self):
        self.assertEqual(HotKeyParser.toString(HotKey(u"A")), u"A")
        self.assertEqual(HotKeyParser.toString(HotKey(u"F1")), u"F1")

        self.assertEqual(HotKeyParser.toString(HotKey(u"A", ctrl=True)),
                         u"Ctrl+A")

        self.assertEqual(HotKeyParser.toString(HotKey(u"A", shift=True)),
                         u"Shift+A")

        self.assertEqual(HotKeyParser.toString(HotKey(u"A", alt=True)),
                         u"Alt+A")

        self.assertEqual(
            HotKeyParser.toString(HotKey(u"A", ctrl=True, alt=True)),
            u"Ctrl+Alt+A")

        self.assertEqual(
            HotKeyParser.toString(HotKey(u"A", ctrl=True, shift=True)),
            u"Ctrl+Shift+A")

        self.assertEqual(
            HotKeyParser.toString(HotKey(u"A", alt=True, shift=True)),
            u"Shift+Alt+A")

        self.assertEqual(
            HotKeyParser.toString(HotKey(u"A", ctrl=True, alt=True,
                                         shift=True)), u"Ctrl+Shift+Alt+A")
Ejemplo n.º 2
0
    def testHotKeyLoadConfig(self):
        action = TestAction()
        hotKeyFromConfig = HotKey("F11")
        HotKeyOption(Application.config, self.actionController.configSection,
                     action.stringId, None).value = hotKeyFromConfig

        self.actionController.register(action, HotKey("F12", ctrl=True))

        self.assertEqual(
            self.actionController.getHotKey(action.stringId).key, "F11")
        self.assertFalse(self.actionController.getHotKey(action.stringId).ctrl)
        self.assertFalse(
            self.actionController.getHotKey(action.stringId).shift)
        self.assertFalse(self.actionController.getHotKey(action.stringId).alt)
Ejemplo n.º 3
0
    def testHotKeys(self):
        hotkey1 = HotKey("F1")
        action1 = ExampleAction()

        hotkey2 = HotKey("F2", ctrl=True)
        action2 = ExampleCheckAction()

        self.actionController.register(action1, hotkey1)
        self.actionController.register(action2, hotkey2)

        self.assertEqual(self.actionController.getHotKey(action1.stringId),
                         hotkey1)
        self.assertEqual(self.actionController.getHotKey(action2.stringId),
                         hotkey2)
Ejemplo n.º 4
0
    def testHotKeySaveConfig2(self):
        action = ExampleAction()
        hotkey = HotKey("F11", ctrl=True)

        self.actionController.register(action, hotkey)
        self.actionController.saveHotKeys()

        otherActionController = ActionController(self.mainWindow, self.application.config)
        otherActionController.register(action, HotKey("F1", shift=True))

        self.assertEqual(otherActionController.getHotKey(action.stringId).key,
                         "F11")
        self.assertTrue(otherActionController.getHotKey(action.stringId).ctrl)
        self.assertFalse(otherActionController.getHotKey(action.stringId).shift)
        self.assertFalse(otherActionController.getHotKey(action.stringId).alt)
Ejemplo n.º 5
0
    def testHotKey5(self):
        hotkey = HotKey(u"F1", ctrl=True, alt=True, shift=True)

        self.assertEqual(hotkey.key, u"F1")
        self.assertTrue(hotkey.ctrl)
        self.assertTrue(hotkey.alt)
        self.assertTrue(hotkey.shift)
Ejemplo n.º 6
0
    def testHotKey4(self):
        hotkey = HotKey(u"F1", shift=True)

        self.assertEqual(hotkey.key, u"F1")
        self.assertFalse(hotkey.ctrl)
        self.assertFalse(hotkey.alt)
        self.assertTrue(hotkey.shift)
Ejemplo n.º 7
0
    def testHotKey2(self):
        hotkey = HotKey("F1", ctrl=True)

        self.assertEqual(hotkey.key, "F1")
        self.assertTrue(hotkey.ctrl)
        self.assertFalse(hotkey.alt)
        self.assertFalse(hotkey.shift)
Ejemplo n.º 8
0
    def testSetHotKey(self):
        action = TestAction()
        self.actionController.register(action, None)

        hotkey = HotKey("F11", ctrl=True)
        self.actionController.setHotKey(action.stringId, hotkey)
        self.assertEqual(self.actionController.getHotKey(action.stringId),
                         hotkey)
Ejemplo n.º 9
0
    def testHotKeyOptionEmptyConfig(self):
        config = Config(self.path)
        hotKeyDefault = HotKey("F11", ctrl=True)
        section = "TestHotKey"
        paramName = "MyHotKey"

        option = HotKeyOption(config, section, paramName, hotKeyDefault)
        self.assertEqual(option.value, hotKeyDefault)
Ejemplo n.º 10
0
    def testSetHotKey(self):
        action = ExampleAction()
        self.actionController.register(action, None)

        hotkey = HotKey("F11", ctrl=True)
        self.actionController.changeHotkeys([(action.stringId, hotkey)])
        self.assertEqual(self.actionController.getHotKey(action.stringId),
                         hotkey)
Ejemplo n.º 11
0
    def getHotkey(self):
        """
        Возвращает установленную горячую клавишу
        """
        if self._key.GetSelection() == 0:
            return None

        return HotKey(self._key.Value, self._ctrl.Value, self._alt.Value,
                      self._shift.Value)
Ejemplo n.º 12
0
    def testHotKeysDefaultMenu(self):
        action = ExampleAction()
        menu = self.fileMenu
        hotkey = HotKey("T", ctrl=True)

        self.actionController.register(action, hotkey=hotkey)
        self.assertEqual(self.actionController.getHotKey(action.stringId),
                         hotkey)

        self.actionController.appendMenuItem(action.stringId, menu)

        self._assertMenuItemExists(menu, action.title, hotkey)
Ejemplo n.º 13
0
    def testDelayChangeHotkeyToolbar(self):
        toolbar = self.wnd.toolbars[self.wnd.PLUGINS_TOOLBAR_STR]
        image = "../test/images/save.png"

        hotkey = HotKey("F11", ctrl=True)

        action = TestAction()
        self.actionController.register(action, HotKey("F11"))

        self.actionController.appendToolbarButton(action.stringId, toolbar,
                                                  image)

        self.actionController.setHotKey(action.stringId, hotkey, False)

        self.assertEqual(self._getToolItemLabel(toolbar, action.stringId),
                         u"{} ({})".format(action.title, "F11"))

        otherActionController = ActionController(self.wnd, Application.config)
        otherActionController.register(action, None)

        self.assertEqual(otherActionController.getHotKey(action.stringId),
                         hotkey)
Ejemplo n.º 14
0
    def testEmpty(self):
        strid = "test_id"
        title = "title"
        description = "description"
        hotkey = HotKey("F1")

        polyaction = PolyAction(self.application, strid, title, description)
        self.actionController.register(polyaction, hotkey)

        self.assertEqual(self.actionController.getAction(strid).title, title)
        self.assertEqual(
            self.actionController.getAction(strid).description, description)

        polyaction.run(None)
Ejemplo n.º 15
0
    def testReadOption4(self):
        with open(self.path, "w") as fp:
            fp.write("""[TestHotKey]
MyHotKey=Ctrl+DEL""")

        config = Config(self.path)
        section = "TestHotKey"
        paramName = "MyHotKey2"
        hotKeyDefault = HotKey("F11", ctrl=True)

        option = HotKeyOption(config, section, paramName, hotKeyDefault)
        result = option.value

        self.assertEqual(result, hotKeyDefault)
Ejemplo n.º 16
0
    def testDelayChangeHotkeyToolbar(self):
        toolbar = self.mainWindow.toolbars[TOOLBAR_PLUGINS]
        image = "testdata/images/save.png"

        hotkey = HotKey("F11", ctrl=True)

        action = ExampleAction()
        self.actionController.register(action, HotKey("F11"))

        self.actionController.appendToolbarButton(action.stringId, toolbar,
                                                  image)

        self.actionController.setHotKey(action.stringId, hotkey, False)

        self.assertEqual(self._getToolItemLabel(toolbar, action.stringId),
                         "{} ({})".format(action.title, "F11"))

        otherActionController = ActionController(self.mainWindow,
                                                 self.application.config)
        otherActionController.register(action, None)

        self.assertEqual(otherActionController.getHotKey(action.stringId),
                         hotkey)
Ejemplo n.º 17
0
    def testChangeHotkeyGuiMenu(self):
        menu = self.fileMenu

        hotkey = HotKey("F11", ctrl=True)

        action = ExampleAction()
        self.actionController.register(action, None)

        self.actionController.appendMenuItem(action.stringId, menu)

        self.actionController.changeHotkeys([(action.stringId, hotkey)])

        self.assertEqual(self._getMenuItem(action.stringId).GetItemLabel(),
                         "{}\t{}".format(action.title, "Ctrl+F11"))
Ejemplo n.º 18
0
    def testHotKeyWrite1(self):
        config = Config(self.path)
        hotkey = HotKey("F11", ctrl=True)
        section = "TestHotKey"
        paramName = "MyHotKey"

        option = HotKeyOption(config, section, paramName, None)
        option.value = hotkey

        with open(self.path) as fp:
            resultFile = fp.read()

        self.assertTrue("[TestHotKey]" in resultFile)
        self.assertTrue("myhotkey = Ctrl+F11" in resultFile)
Ejemplo n.º 19
0
    def testHotKeysDefaultToolBar(self):
        action = TestAction()
        hotkey = HotKey("T", ctrl=True)
        toolbar = self.wnd.toolbars[self.wnd.PLUGINS_TOOLBAR_STR]
        image = "../test/images/save.png"

        self.actionController.register(action, hotkey=hotkey)
        self.assertEqual(self.actionController.getHotKey(action.stringId),
                         hotkey)

        self.actionController.appendToolbarButton(action.stringId, toolbar,
                                                  image)

        self.assertEqual(
            self._getToolItemLabel(toolbar, action.stringId),
            u"{0} ({1})".format(action.title, HotKeyParser.toString(hotkey)))
Ejemplo n.º 20
0
    def onKeyPressed(self, event):
        keycode = event.GetKeyCode()
        modifiers = event.GetModifiers()

        if keycode == wx.WXK_TAB and modifiers == 0:
            event.Skip()
            return

        if self._check(event):
            char = self._keycode2str(keycode)
            hotkey = HotKey(char, event.ControlDown(), event.AltDown(),
                            event.ShiftDown())

            if keycode == wx.WXK_BACK and modifiers == 0:
                hotkey = None
            self.SetValue(hotkey)
Ejemplo n.º 21
0
    def testHotKeysDefaultToolBar(self):
        action = ExampleAction()
        hotkey = HotKey("T", ctrl=True)
        toolbar = self.mainWindow.toolbars[TOOLBAR_PLUGINS]
        image = "testdata/images/save.png"

        self.actionController.register(action, hotkey=hotkey)
        self.assertEqual(self.actionController.getHotKey(action.stringId),
                         hotkey)

        self.actionController.appendToolbarButton(action.stringId, toolbar,
                                                  image)

        self.assertEqual(
            self._getToolItemLabel(toolbar, action.stringId),
            "{0} ({1})".format(action.title, HotKeyParser.toString(hotkey)))
Ejemplo n.º 22
0
    def testDisableMenuItem(self):
        action = ExampleAction()
        hotkey = HotKey("T", ctrl=True)
        menu = self.fileMenu

        self.actionController.register(action, hotkey=hotkey)

        self.actionController.appendMenuItem(action.stringId, menu)

        menuItemId = self._getMenuItemId(action.stringId)

        self.actionController.enableTools(action.stringId, False)
        self.assertFalse(menu.IsEnabled(menuItemId))

        self.actionController.enableTools(action.stringId, True)
        self.assertTrue(menu.IsEnabled(menuItemId))
Ejemplo n.º 23
0
    def testHotKeySaveConfig1(self):
        action = TestAction()
        hotkey = HotKey("F11", ctrl=True)

        self.actionController.register(action, hotkey)
        self.actionController.saveHotKeys()

        otherActionController = ActionController(self.wnd, Application.config)
        otherActionController.register(action)

        self.assertEqual(
            otherActionController.getHotKey(action.stringId).key, "F11")
        self.assertTrue(otherActionController.getHotKey(action.stringId).ctrl)
        self.assertFalse(
            otherActionController.getHotKey(action.stringId).shift)
        self.assertFalse(otherActionController.getHotKey(action.stringId).alt)
Ejemplo n.º 24
0
    def __createTestAction(self):
        mainWindow = self._application.mainWindow

        if mainWindow is not None and mainWindow.PLUGINS_TOOLBAR_STR in mainWindow.toolbars:
            action = DebugAction(self._application)
            hotkey = HotKey("T", ctrl=True, shift=True, alt=True)
            toolbar = mainWindow.toolbars[mainWindow.PLUGINS_TOOLBAR_STR]
            image = self.getImagePath("bug.png")

            controller = self._application.actionController

            controller.register(action, hotkey=hotkey)

            controller.appendMenuCheckItem(DebugAction.stringId, self.menu)
            controller.appendToolbarCheckButton(DebugAction.stringId, toolbar,
                                                image)
Ejemplo n.º 25
0
    def testChangeHotkeyToolbar(self):
        toolbar = self.mainWindow.toolbars[TOOLBAR_PLUGINS]
        image = "testdata/images/save.png"

        hotkey = HotKey("F11", ctrl=True)

        action = ExampleAction()
        self.actionController.register(action, None)

        self.actionController.appendToolbarButton(action.stringId,
                                                  toolbar,
                                                  image)

        self.actionController.changeHotkeys([(action.stringId, hotkey)])

        self.assertEqual(self._getToolItemLabel(toolbar, action.stringId),
                         "{} ({})".format(action.title, "Ctrl+F11"))
Ejemplo n.º 26
0
    def GetValue(self):
        text = super(HotkeyCtrl, self).GetValue()
        if len(text) == 0:
            return None

        ctrl = u'Ctrl+' in text
        shift = u'Shift+' in text
        alt = u'Alt+' in text

        key = text.replace(u'Ctrl+', u'')
        key = key.replace(u'Shift+', u'')
        key = key.replace(u'Alt+', u'')

        if len(key) == 0:
            return None

        return HotKey(key, ctrl, alt, shift)
Ejemplo n.º 27
0
    def testDisableTools(self):
        action = ExampleAction()
        hotkey = HotKey("T", ctrl=True)
        toolbar = self.mainWindow.toolbars[TOOLBAR_PLUGINS]
        image = "testdata/images/save.png"

        self.actionController.register(action, hotkey=hotkey)

        self.actionController.appendToolbarButton(action.stringId, toolbar,
                                                  image)

        toolid = self._getToolItemId(action.stringId)

        self.actionController.enableTools(action.stringId, False)
        self.assertFalse(toolbar.GetToolEnabled(toolid))

        self.actionController.enableTools(action.stringId, True)
        self.assertTrue(toolbar.GetToolEnabled(toolid))
Ejemplo n.º 28
0
    def testDisableTools(self):
        action = TestAction()
        hotkey = HotKey("T", ctrl=True)
        toolbar = self.wnd.toolbars[self.wnd.PLUGINS_TOOLBAR_STR]
        image = "../test/images/save.png"

        self.actionController.register(action, hotkey=hotkey)

        self.actionController.appendToolbarButton(action.stringId, toolbar,
                                                  image)

        toolid = self._getToolItemId(action.stringId)

        self.actionController.enableTools(action.stringId, False)
        self.assertFalse(toolbar.GetToolEnabled(toolid))

        self.actionController.enableTools(action.stringId, True)
        self.assertTrue(toolbar.GetToolEnabled(toolid))
Ejemplo n.º 29
0
    def testChangeHotkeyGuiChecked1(self):
        menu = self.fileMenu
        toolbar = self.mainWindow.toolbars[TOOLBAR_PLUGINS]
        image = "testdata/images/save.png"

        hotkey = HotKey("F11", ctrl=True)

        action = ExampleCheckAction()
        self.actionController.register(action, None)

        self.actionController.appendMenuCheckItem(action.stringId, menu)
        self.actionController.appendToolbarCheckButton(action.stringId,
                                                       toolbar,
                                                       image)

        self.actionController.changeHotkeys([(action.stringId, hotkey)])

        self.assertEqual(self._getToolItemLabel(toolbar, action.stringId),
                         "{} ({})".format(action.title, "Ctrl+F11"))

        self.assertEqual(self._getMenuItem(action.stringId).GetItemLabel(),
                         "{}\t{}".format(action.title, "Ctrl+F11"))
Ejemplo n.º 30
0
    def testChangeHotkeyGuiChecked2(self):
        menu = self.wnd.mainMenu.fileMenu
        toolbar = self.wnd.toolbars[self.wnd.PLUGINS_TOOLBAR_STR]
        image = "../test/images/save.png"

        hotkey = HotKey("F11", ctrl=True)

        action = TestCheckAction()
        self.actionController.register(action, None)

        self.actionController.appendMenuCheckItem(action.stringId, menu)
        self.actionController.appendToolbarCheckButton(action.stringId,
                                                       toolbar, image)

        menuItem = self._getMenuItem(action.stringId)
        toolItem = self._getToolItem(toolbar, action.stringId)

        self.actionController.setHotKey(action.stringId, hotkey)
        self.actionController.check(action.stringId, True)

        self.assertTrue(menuItem.IsChecked())
        self.assertTrue(toolItem.GetState())