Example #1
0
    def askAssignKey(self, configKey, labelString=None):
        if not self.isConfigKey(configKey):
            self.enter = 0
            return

        panel = Panel()
        panel.bg_color = (0.5, 0.5, 0.6, 1.0)

        if labelString is None:
            labelString = _("Press a key to assign to the action \"{0}\"\n\nPress ESC to cancel. Press Shift-ESC to unbind.").format(configKey)
        label = albow.Label(labelString)
        panel.add(label)
        panel.shrink_wrap()

        def panelKeyUp(evt):
            keyname = self.root.getKey(evt)
            panel.dismiss(keyname)

        def panelMouseUp(evt):
            button = remapMouseButton(evt.button)
            if button == 3:
                keyname = "Button 3"
            elif button == 4:
                keyname = "Scroll Up"
            elif button == 5:
                keyname = "Scroll Down"
            elif button == 6:
                keyname = "Button 4"
            elif button == 7:
                keyname = "Button 5"
            if button > 2:
                panel.dismiss(keyname)

        panel.key_up = panelKeyUp
        panel.mouse_up = panelMouseUp

        keyname = panel.present()
        if keyname == "Return" and self.enter == 1:
            self.enter = 0
            self.askAssignKey(configKey, _("Press a key to assign to the action \"{0}\"\n\nPress ESC to cancel. Press Shift-ESC to unbind.").format(configKey))
            return True

        self.enter = 0
        if keyname != "Escape" and keyname != "Shift-Escape" and keyname not in ["Alt-F4","F1","F2","F3","F4","F5","1","2","3","4","5","6","7","8","9","Ctrl-Alt-F9","Ctrl-Alt-F10"]:
            if "Modifier" in configKey and keyname != "Ctrl" and keyname != "Alt" and keyname != "Shift":
                self.askAssignKey(configKey,
                                    _("{0} is not a modifier. "
                                    "Press a new key.\n\n"
                                    "Press ESC to cancel. Press Shift-ESC to unbind.")
                                    .format(keyname))
                return True
            if configKey in ['Down','Up','Back','Forward','Left','Right','Pan Down','Pan Up','Pan Left','Pan Right']:
                if 'Ctrl' in keyname:
                    self.askAssignKey(configKey,
                                    _("Movement keys can't use Ctrl. "
                                    "Press a new key.\n\n"
                                    "Press ESC to cancel. Press Shift-ESC to unbind."))
                    return True
            oldkey = config.keys[config.convert(configKey)].get()
            config.keys[config.convert(configKey)].set(keyname)
            if configKey not in self.changes:
                self.changes[configKey] = oldkey
            self.changesNum = True
        elif keyname == "Shift-Escape":
            config.keys[config.convert(configKey)].set("None")
        elif keyname != "Escape":
            self.askAssignKey(configKey,
                                    _("You can't use the key {0}. "
                                    "Press a new key.\n\n"
                                    "Press ESC to cancel. Press Shift-ESC to unbind.")
                                    .format(keyname))
            return True

        else:
            return True
Example #2
0
    def askAssignKey(self, configKey, labelString=None):
        if not self.isConfigKey(configKey):
            self.enter = 0
            return

        panel = Panel()
        panel.bg_color = (0.5, 0.5, 0.6, 1.0)

        if labelString is None and configKey != "Fast Nudge":
            labelString = _(
                "Press a key to assign to the action \"{0}\"\n\nPress ESC to cancel."
            ).format(_(configKey))
        elif labelString is None:
            labelString = _(
                "Press a key to assign to the action \"{0}\"\nNo key means right click to fast nudge.\nPress ESC to cancel."
            ).format(_(configKey))
        label = albow.Label(labelString)
        unbind_button = Button("Press to unbind", action=self.unbind)
        column = Column((label, unbind_button))
        panel.add(column)
        panel.shrink_wrap()

        def panelKeyUp(evt):
            keyname = self.root.getKey(evt)
            panel.dismiss(keyname)

        def panelMouseUp(evt):
            button = remapMouseButton(evt.button)
            if button == 3:
                keyname = "Button 3"
            elif button == 4:
                keyname = "Scroll Up"
            elif button == 5:
                keyname = "Scroll Down"
            elif button == 6:
                keyname = "Button 4"
            elif button == 7:
                keyname = "Button 5"
            if button > 2:
                panel.dismiss(keyname)

        panel.key_up = panelKeyUp
        panel.mouse_up = panelMouseUp

        self.panel = panel
        keyname = panel.present()
        if type(keyname) is bool:
            return True
        if keyname == "Return" and self.enter == 1:
            self.enter = 0
            self.askAssignKey(configKey)
            return True

        self.enter = 0
        _keyname = _(keyname)
        if keyname != "Escape" and keyname not in [
                "Alt-F4", "F1", "F2", "F3", "F4", "F5", "1", "2", "3", "4",
                "5", "6", "7", "8", "9", "Ctrl-Alt-F9", "Ctrl-Alt-F10"
        ]:
            if "Modifier" in configKey and keyname != "Ctrl" and keyname != "Alt" and keyname != "Shift":
                self.askAssignKey(
                    configKey,
                    _("{0} is not a modifier. Press a new key.\n\nPress ESC to cancel."
                      ).format(_keyname))
                return True
            if configKey in [
                    'Down', 'Up', 'Back', 'Forward', 'Left', 'Right',
                    'Pan Down', 'Pan Up', 'Pan Left', 'Pan Right'
            ]:
                if 'Ctrl' in keyname or '-' in keyname:
                    self.askAssignKey(
                        configKey,
                        "Movement keys can't use Ctrl or be with modifiers. Press a new key.\n\nPress ESC to cancel."
                    )
                    return True
            filter_keys = [
                i for (i, j) in config.config._sections["Filter Keys"].items()
                if j == _keyname
            ]
            if filter_keys:
                self.askAssignKey(
                    configKey,
                    _("Can't bind. {0} is already used by the \"{1}\" filter.\n Press a new key.\n\nPress ESC to cancel."
                      ).format(_keyname, filter_keys[0]))
                return True
            oldkey = config.keys[config.convert(configKey)].get()
            config.keys[config.convert(configKey)].set(keyname)
            if oldkey != keyname and configKey not in self.changes:
                self.changes[configKey] = oldkey
                self.changesNum = True
        elif keyname != "Escape":
            self.askAssignKey(
                configKey,
                _("You can't use the key {0}. Press a new key.\n\nPress ESC to cancel."
                  ).format(_keyname))
            return True

        else:
            return True
Example #3
0
    def bind_key(self, message=None):
        panel = Panel()
        panel.bg_color = (0.5, 0.5, 0.6, 1.0)
        if not message:
            message = _("Press a key to assign to the filter \"{0}\"\n\n"
                        "Press ESC to cancel.").format(self.selectedName)
        label = albow.Label(message)
        unbind_button = Button("Press to unbind", action=self.unbind_key)
        column = Column((label, unbind_button))
        panel.add(column)
        panel.shrink_wrap()

        def panelKeyUp(evt):
            _key_name = self.root.getKey(evt)
            panel.dismiss(_key_name)

        def panelMouseUp(evt):
            button = keys.remapMouseButton(evt.button)
            _key_name = None
            if button == 3:
                _key_name = "Button 3"
            elif button == 4:
                _key_name = "Scroll Up"
            elif button == 5:
                _key_name = "Scroll Down"
            elif button == 6:
                _key_name = "Button 4"
            elif button == 7:
                _key_name = "Button 5"
            if 2 < button < 8:
                panel.dismiss(_key_name)

        panel.key_up = panelKeyUp
        panel.mouse_up = panelMouseUp

        self.keys_panel = panel
        key_name = panel.present()

        if type(key_name) is bool:
            return True
        if key_name != "Escape":
            if key_name in [
                    "Alt-F4", "F1", "F2", "F3", "F4", "F5", "1", "2", "3", "4",
                    "5", "6", "7", "8", "9", "Ctrl-Alt-F9", "Ctrl-Alt-F10"
            ]:
                self.bind_key(
                    _("You can't use the key {0}.\n"
                      "Press a key to assign to the filter \"{1}\"\n\n"
                      ""
                      "Press ESC to cancel.").format(_(key_name),
                                                     self.selectedName))
                return True

            keysUsed = [(j, i) for (j, i) in config.config.items("Keys")
                        if i == key_name]
            if keysUsed:
                self.bind_key(
                    _("Can't bind. {0} is already used by {1}.\n"
                      "Press a key to assign to the filter \"{2}\"\n\n"
                      ""
                      "Press ESC to cancel.").format(_(key_name),
                                                     keysUsed[0][0],
                                                     self.selectedName))
                return True

            filter_keys = [
                i for (i, j) in config.config.items("Filter Keys")
                if j == key_name
            ]
            if filter_keys:
                self.bind_key(
                    _("Can't bind. {0} is already used by the \"{1}\" filter.\n"
                      "Press a new key.\n\n"
                      ""
                      "Press ESC to cancel.").format(_(key_name),
                                                     filter_keys[0]))
                return True
            config.config.set("Filter Keys", self.selectedName.lower(),
                              key_name)
        config.save()
        self.reload()
Example #4
0
    def bind_key(self, message=None):
        panel = Panel()
        panel.bg_color = (0.5, 0.5, 0.6, 1.0)
        if not message:
            message = _("Press a key to assign to the filter \"{0}\"\n\n"
                        "Press ESC to cancel.").format(self.selectedName)
        label = albow.Label(message)
        unbind_button = Button("Press to unbind", action=self.unbind_key)
        column = Column((label, unbind_button))
        panel.add(column)
        panel.shrink_wrap()

        def panelKeyUp(evt):
            _key_name = self.root.getKey(evt)
            panel.dismiss(_key_name)

        def panelMouseUp(evt):
            button = keys.remapMouseButton(evt.button)
            _key_name = None
            if button == 3:
                _key_name = "Button 3"
            elif button == 4:
                _key_name = "Scroll Up"
            elif button == 5:
                _key_name = "Scroll Down"
            elif button == 6:
                _key_name = "Button 4"
            elif button == 7:
                _key_name = "Button 5"
            if 2 < button < 8:
                panel.dismiss(_key_name)

        panel.key_up = panelKeyUp
        panel.mouse_up = panelMouseUp

        self.keys_panel = panel
        key_name = panel.present()

        if type(key_name) is bool:
            return True
        if key_name != "Escape":
            if key_name in ["Alt-F4", "F1", "F2", "F3", "F4", "F5", "1", "2", "3",
                            "4", "5", "6", "7", "8", "9", "Ctrl-Alt-F9", "Ctrl-Alt-F10"]:
                self.bind_key(_("You can't use the key {0}.\n"
                                "Press a key to assign to the filter \"{1}\"\n\n"
                                ""
                                "Press ESC to cancel.").format(_(key_name), self.selectedName))
                return True

            keysUsed = [(j, i) for (j, i) in config.config.items("Keys") if i == key_name]
            if keysUsed:
                self.bind_key(_("Can't bind. {0} is already used by {1}.\n"
                                "Press a key to assign to the filter \"{2}\"\n\n"
                                ""
                                "Press ESC to cancel.").format(_(key_name), keysUsed[0][0], self.selectedName))
                return True

            filter_keys = [i for (i, j) in config.config.items("Filter Keys") if j == key_name]
            if filter_keys:
                self.bind_key(_("Can't bind. {0} is already used by the \"{1}\" filter.\n"
                                "Press a new key.\n\n"
                                ""
                                "Press ESC to cancel.").format(_(key_name), filter_keys[0]))
                return True
            config.config.set("Filter Keys", self.selectedName.lower(), key_name)
        config.save()
        self.reload()
Example #5
0
    def askAssignKey(self, configKey, labelString=None):
        if not self.isConfigKey(configKey):
            self.enter = 0
            return

        panel = Panel()
        panel.bg_color = (0.5, 0.5, 0.6, 1.0)

        if labelString is None:
            labelString = _(
                "Press a key to assign to the action \"{0}\"\n\nPress ESC to cancel. Press Shift-ESC to unbind."
            ).format(configKey)
        label = albow.Label(labelString)
        panel.add(label)
        panel.shrink_wrap()

        def panelKeyUp(evt):
            keyname = self.root.getKey(evt)
            panel.dismiss(keyname)

        def panelMouseUp(evt):
            button = remapMouseButton(evt.button)
            if button == 3:
                keyname = "Button 3"
            elif button == 4:
                keyname = "Scroll Up"
            elif button == 5:
                keyname = "Scroll Down"
            elif button == 6:
                keyname = "Button 4"
            elif button == 7:
                keyname = "Button 5"
            if button > 2:
                panel.dismiss(keyname)

        panel.key_up = panelKeyUp
        panel.mouse_up = panelMouseUp

        keyname = panel.present()
        if keyname == "Return" and self.enter == 1:
            self.enter = 0
            self.askAssignKey(
                configKey,
                _("Press a key to assign to the action \"{0}\"\n\nPress ESC to cancel. Press Shift-ESC to unbind."
                  ).format(configKey))
            return True

        self.enter = 0
        if keyname != "Escape" and keyname != "Shift-Escape" and keyname not in [
                "Alt-F4", "F1", "F2", "F3", "F4", "F5", "1", "2", "3", "4",
                "5", "6", "7", "8", "9", "Ctrl-Alt-F9", "Ctrl-Alt-F10"
        ]:
            if "Modifier" in configKey and keyname != "Ctrl" and keyname != "Alt" and keyname != "Shift":
                self.askAssignKey(
                    configKey,
                    _("{0} is not a modifier. "
                      "Press a new key.\n\n"
                      "Press ESC to cancel. Press Shift-ESC to unbind.").
                    format(keyname))
                return True
            if configKey in [
                    'Down', 'Up', 'Back', 'Forward', 'Left', 'Right',
                    'Pan Down', 'Pan Up', 'Pan Left', 'Pan Right'
            ]:
                if 'Ctrl' in keyname:
                    self.askAssignKey(
                        configKey,
                        _("Movement keys can't use Ctrl. "
                          "Press a new key.\n\n"
                          "Press ESC to cancel. Press Shift-ESC to unbind."))
                    return True
            oldkey = config.keys[config.convert(configKey)].get()
            config.keys[config.convert(configKey)].set(keyname)
            if configKey not in self.changes:
                self.changes[configKey] = oldkey
            self.changesNum = True
        elif keyname == "Shift-Escape":
            config.keys[config.convert(configKey)].set("None")
        elif keyname != "Escape":
            self.askAssignKey(
                configKey,
                _("You can't use the key {0}. "
                  "Press a new key.\n\n"
                  "Press ESC to cancel. Press Shift-ESC to unbind.").format(
                      keyname))
            return True

        else:
            return True
Example #6
0
    def askAssignKey(self, configKey, labelString=None):
        if not self.isConfigKey(configKey):
            self.enter = 0
            return

        panel = Panel(name='Panel.KeyConfigPanel')
        panel.bg_color = (0.3, 0.3, 0.3, 1.0)

        if labelString is None and configKey != "Fast Nudge":
            labelString = _("Press a key to assign to the action \"{0}\"\n\nPress ESC to cancel.").format(_(configKey))
        elif labelString is None:
            labelString = _("Press a key to assign to the action \"{0}\"\nNo key means right click to fast nudge.\nPress ESC to cancel.").format(_(configKey))
        label = albow.Label(labelString)
        unbind_button = Button("Press to unbind", action=self.unbind)
        column = Column((label, unbind_button))
        panel.add(column)
        panel.shrink_wrap()

        def panelKeyUp(evt):
            keyname = self.root.getKey(evt)
            panel.dismiss(keyname)

        def panelMouseUp(evt):
            button = remapMouseButton(evt.button)
            if button == 3:
                keyname = "Button 3"
            elif button == 4:
                keyname = "Scroll Up"
            elif button == 5:
                keyname = "Scroll Down"
            elif button == 6:
                keyname = "Button 4"
            elif button == 7:
                keyname = "Button 5"
            if button > 2:
                panel.dismiss(keyname)

        panel.key_up = panelKeyUp
        panel.mouse_up = panelMouseUp

        self.panel = panel
        keyname = panel.present()
        if isinstance(keyname, bool):
            return True
        if keyname == "Return" and self.enter == 1:
            self.enter = 0
            self.askAssignKey(configKey)
            return True

        self.enter = 0
        _keyname = _(keyname)
        if keyname != "Escape" and keyname not in ("Alt-F4","F1","F2","F3","F4","F5","1","2","3","4","5","6","7","8","9","Ctrl-Alt-F9","Ctrl-Alt-F10"):
            if "Modifier" in configKey and keyname != "Ctrl" and keyname != "Alt" and keyname != "Shift":
                self.askAssignKey(configKey,
                                    _("{0} is not a modifier. Press a new key.\n\nPress ESC to cancel.")
                                    .format(_keyname))
                return True
            if configKey in ('Down','Up','Back','Forward','Left','Right','Pan Down','Pan Up','Pan Left','Pan Right'):
                if 'Ctrl' in keyname or '-' in keyname:
                    self.askAssignKey(configKey,
                                    "Movement keys can't use Ctrl or be with modifiers. Press a new key.\n\nPress ESC to cancel.")
                    return True
            filter_keys = [i for (i, j) in config.config._sections["Filter Keys"].items() if j == _keyname]
            if filter_keys:
                self.askAssignKey(configKey,
                                    _("Can't bind. {0} is already used by the \"{1}\" filter.\n Press a new key.\n\nPress ESC to cancel.").format(_keyname, filter_keys[0]))
                return True
            oldkey = config.keys[config.convert(configKey)].get()
            config.keys[config.convert(configKey)].set(keyname)
            if oldkey != keyname and configKey not in self.changes:
                self.changes[configKey] = oldkey
                self.changesNum = True
        elif keyname != "Escape":
            self.askAssignKey(configKey,
                                    _("You can't use the key {0}. Press a new key.\n\nPress ESC to cancel.")
                                    .format(_keyname))
            return True

        else:
            return True