keyboard_comm: store keyboard UID to the saved layout file
parent
0accc10167
commit
f5d6963cce
|
|
@ -58,6 +58,7 @@ class Keyboard:
|
||||||
self.encoders = []
|
self.encoders = []
|
||||||
self.macro_count = 0
|
self.macro_count = 0
|
||||||
self.macro_memory = 0
|
self.macro_memory = 0
|
||||||
|
self.uid = 0
|
||||||
self.macro = b""
|
self.macro = b""
|
||||||
self.vibl = False
|
self.vibl = False
|
||||||
|
|
||||||
|
|
@ -71,6 +72,7 @@ class Keyboard:
|
||||||
self.layout = dict()
|
self.layout = dict()
|
||||||
self.encoder_layout = dict()
|
self.encoder_layout = dict()
|
||||||
|
|
||||||
|
self.uid = struct.unpack(">Q", self.get_uid())[0]
|
||||||
self.reload_layout(sideload_json)
|
self.reload_layout(sideload_json)
|
||||||
self.reload_layers()
|
self.reload_layers()
|
||||||
self.reload_keymap()
|
self.reload_keymap()
|
||||||
|
|
@ -247,9 +249,7 @@ class Keyboard:
|
||||||
def save_layout(self):
|
def save_layout(self):
|
||||||
""" Serializes current layout to a binary """
|
""" Serializes current layout to a binary """
|
||||||
|
|
||||||
# TODO: increase version before release
|
data = {"version": 1, "uid": self.uid}
|
||||||
# TODO: store keyboard UID here as well
|
|
||||||
data = {"version": 0}
|
|
||||||
|
|
||||||
layout = []
|
layout = []
|
||||||
for l in range(self.layers):
|
for l in range(self.layers):
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,8 @@
|
||||||
# SPDX-License-Identifier: GPL-2.0-or-later
|
# SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
import json
|
||||||
|
|
||||||
from PyQt5.QtCore import pyqtSignal, Qt
|
from PyQt5.QtCore import pyqtSignal, Qt
|
||||||
from PyQt5.QtWidgets import QWidget, QHBoxLayout, QLabel, QVBoxLayout, QPushButton, QApplication
|
from PyQt5.QtWidgets import QWidget, QHBoxLayout, QLabel, QVBoxLayout, QPushButton, QApplication, QMessageBox
|
||||||
from PyQt5.QtGui import QPalette
|
from PyQt5.QtGui import QPalette
|
||||||
|
|
||||||
from clickable_label import ClickableLabel
|
from clickable_label import ClickableLabel
|
||||||
|
|
@ -167,6 +168,12 @@ class KeyboardContainer(QWidget):
|
||||||
return self.keyboard.save_layout()
|
return self.keyboard.save_layout()
|
||||||
|
|
||||||
def restore_layout(self, data):
|
def restore_layout(self, data):
|
||||||
|
if json.loads(data.decode("utf-8")).get("uid") != self.keyboard.uid:
|
||||||
|
ret = QMessageBox.question(self, "", tr("KeyboardContainer", "Saved keymap belongs to a different keyboard,"
|
||||||
|
" are you sure you want to continue?"),
|
||||||
|
QMessageBox.Yes | QMessageBox.No)
|
||||||
|
if ret != QMessageBox.Yes:
|
||||||
|
return
|
||||||
self.keyboard.restore_layout(data)
|
self.keyboard.restore_layout(data)
|
||||||
self.refresh_layer_display()
|
self.refresh_layer_display()
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue