Ejemplo n.º 1
0
    def restore_layout(self, data):
        """ Restores saved layout """

        data = json.loads(data.decode("utf-8"))

        # restore keymap
        for l, layer in enumerate(data["layout"]):
            for r, row in enumerate(layer):
                for c, code in enumerate(row):
                    if (l, r, c) in self.layout:
                        self.set_key(l, r, c, Keycode.deserialize(code))

        # restore encoders
        for l, layer in enumerate(data["encoder_layout"]):
            for e, encoder in enumerate(layer):
                self.set_encoder(l, e, 0, Keycode.deserialize(encoder[0]))
                self.set_encoder(l, e, 1, Keycode.deserialize(encoder[1]))

        self.set_layout_options(data["layout_options"])

        # we need to unlock the keyboard before we can restore the macros, lock it afterwards
        # only do that if it's different from current macros
        macro = base64.b64decode(data["macro"])
        if macro != self.macro:
            Unlocker.unlock(self)
            self.set_macro(macro)
            self.lock()
Ejemplo n.º 2
0
    def on_change(self):
        text = self.txt_entry.text()
        value = err = None
        try:
            value = Keycode.deserialize(text, reraise=True)
        except Exception as e:
            err = str(e)

        if not text:
            self.value = -1
            self.lbl_computed.setText(
                tr("AnyKeycodeDialog", "Enter an expression"))
        elif err:
            self.value = -1
            self.lbl_computed.setText(
                tr("AnyKeycodeDialog", "Invalid input: {}").format(err))
        elif isinstance(value, int):
            self.value = value
            self.lbl_computed.setText(
                tr("AnyKeycodeDialog", "Computed value: 0x{:X}").format(value))
        else:
            self.value = -1
            self.lbl_computed.setText(tr("AnyKeycodeDialog", "Invalid input"))

        self.buttons.button(
            QDialogButtonBox.Ok).setEnabled(0 <= self.value < 2**16)
Ejemplo n.º 3
0
 def test_serialize(self):
     # at a minimum, we should be able to deserialize/serialize everything
     for x in range(2**16):
         s = Keycode.serialize(x)
         d = Keycode.deserialize(s)
         self.assertEqual(
             d, x,
             "{} serialized into {} deserialized into {}".format(x, s, d))
Ejemplo n.º 4
0
    def restore_layout(self, data):
        """ Restores saved layout """

        data = json.loads(data.decode("utf-8"))

        # restore keymap
        for l, layer in enumerate(data["layout"]):
            for r, row in enumerate(layer):
                for c, code in enumerate(row):
                    if (l, r, c) in self.layout:
                        self.set_key(l, r, c, Keycode.deserialize(code))

        # restore encoders
        for l, layer in enumerate(data["encoder_layout"]):
            for e, encoder in enumerate(layer):
                self.set_encoder(l, e, 0, Keycode.deserialize(encoder[0]))
                self.set_encoder(l, e, 1, Keycode.deserialize(encoder[1]))

        self.set_layout_options(data["layout_options"])
        self.restore_macros(data.get("macro"))
Ejemplo n.º 5
0
    def restore_layout(self, data):
        """ Restores saved layout """

        data = json.loads(data.decode("utf-8"))

        # restore keymap
        for l, layer in enumerate(data["layout"]):
            for r, row in enumerate(layer):
                for c, code in enumerate(row):
                    if (l, r, c) in self.layout:
                        self.set_key(l, r, c, Keycode.deserialize(code))

        # restore encoders
        for l, layer in enumerate(data["encoder_layout"]):
            for e, encoder in enumerate(layer):
                self.set_encoder(l, e, 0, Keycode.deserialize(encoder[0]))
                self.set_encoder(l, e, 1, Keycode.deserialize(encoder[1]))

        self.set_layout_options(data["layout_options"])
        self.restore_macros(data.get("macro"))

        for x, e in enumerate(data.get("tap_dance", [])):
            if x < self.tap_dance_count:
                e = (Keycode.deserialize(e[0]), Keycode.deserialize(e[1]),
                     Keycode.deserialize(e[2]), Keycode.deserialize(e[3]),
                     e[4])
                self.tap_dance_set(x, e)

        for x, e in enumerate(data.get("combo", [])):
            if x < self.combo_count:
                e = (Keycode.deserialize(e[0]), Keycode.deserialize(e[1]),
                     Keycode.deserialize(e[2]), Keycode.deserialize(e[3]),
                     Keycode.deserialize(e[4]))
                self.combo_set(x, e)

        for qsid, value in data.get("settings", dict()).items():
            from qmk_settings import QmkSettings

            qsid = int(qsid)
            if QmkSettings.is_qsid_supported(qsid):
                self.qmk_settings_set(qsid, value)