Ejemplo n.º 1
0
 def _stir(self, actionname=None):
     if actionname:
         self._changed = True
         self._undo.insert(0, (actionname, self._viewname[:], oskb.oskbCopy(self._previouskbd)))
         self._previouskbd = oskb.oskbCopy(self._kbd)
         while len(self._undo) > MAX_UNDO:
             self._undo.pop(len(self._undo) - 1)
         self._redo = []
     g_oskbwidget.initKeyboards()
     # g_oskbwidget.updateKeyboard()
     self._view_switch(g_oskbwidget.getView())
     self._fixMenu()
Ejemplo n.º 2
0
 def _copyCut(self, cut=False):
     buffer = []
     for ci, ri, ki, keydata in self._reverseIterateKeys():
         if keydata.get("_selected", False):
             buffer.append(oskb.oskbCopy(keydata))
             if cut:
                 del self._view["columns"][ci]["rows"][ri]["keys"][ki]
     return buffer
Ejemplo n.º 3
0
 def __init__(self, widget):
     super().__init__()
     self._backup = oskb.oskbCopy(widget.data)
     self._d = widget.data
     self.ui = Ui_EditKey()
     self.ui.setupUi(self)
     self.setStyleSheet(
         "QLineEdit, QDoubleSpinBox { border: 1px solid #bcbebf; } QComboBox { padding-left: 5px; }"
     )
     # Put in the KeyAction widgets for the three types of keypress
     self.ui.keyactionwidgets = [None, None, None]
     for idx, act in enumerate(["single", "double", "long"]):
         if not widget.data.get(act):
             widget.data[act] = {}
         self.ui.keyactionwidgets[idx] = KeyActions(widget.data[act])
         self.ui.keyactionwidgets[idx].setParent(eval("self.ui." + act))
         # self.ui.keyactionwidgets[idx].setGeometry(10, 10, 560, 290)
     # Stick in the values from the key dictionary
     self.ui.width.setProperty("value", self._d.get("width", 1.0))
     self.ui.width.valueChanged.connect(self._tryItOut)
     self.ui.caption.setText(self._d.get("caption", "").replace("\n", "\\n"))
     self.ui.caption.editingFinished.connect(self._tryItOut)
     self.ui.cssclass.setText(self._d.get("class", ""))
     self.ui.cssclass.editingFinished.connect(self._tryItOut)
     self.ui.style.setPlainText(self._d.get("style", ""))
     self.ui.addcaption.clicked.connect(self._addcaption)
     self.ui.deletecaption.clicked.connect(self._deletecaption)
     for c, t in self._d.get("extracaptions", {}).items():
         rows = self.ui.extracaptions.rowCount()
         self.ui.extracaptions.setRowCount(rows + 1)
         item = QTableWidgetItem()
         item.setText(c)
         self.ui.extracaptions.setItem(rows, 0, item)
         item = QTableWidgetItem()
         item.setText(t.replace("\n", "\\n"))
         self.ui.extracaptions.setItem(rows, 1, item)
Ejemplo n.º 4
0
 def _loadFile(self, f):
     if self._changed and not self._areyousure():
         return False
     if os.path.isfile(f):
         self._savefilename = f
     else:
         self._savefilename = None
     try:
         self._kbdname = g_oskbwidget.readKeyboard(f)
     except:
         QMessageBox.warning(
             self,
             "read failed",
             "File read failed: " + str(sys.exc_info()[1]),
             QMessageBox.Ok,
             QMessageBox.Ok,
         )
         return False
     g_oskbwidget.setKeyboard(self._kbdname)
     self._changed = False
     self._kbds = g_oskbwidget.getRawKbds()
     try:
         del self._kbds["_minimized"]
         del self._kbds["_chooser"]
     except:
         pass
     self._kbd = self._kbds[self._kbdname]
     self._viewname = g_oskbwidget.getView()
     self._view = self._kbd["views"][self._viewname]
     g_oskbwidget.updateKeyboard()
     g_oskbwidget.show()
     self._undo = []
     self._redo = []
     self._previouskbd = oskb.oskbCopy(self._kbd)
     self._stir()
     return True
Ejemplo n.º 5
0
 def reject(self):
     super().reject()
     oskb.oskbCopy(self._backup, self._d)
     g_oskbwidget.initKeyboards()
     g_oskbwidget.updateKeyboard()
Ejemplo n.º 6
0
 def _edit_paste(self, tuple, after=0):
     ci, ri, ki = tuple
     for ins in self._copypaste:
         self._view["columns"][ci]["rows"][ri]["keys"].insert(ki + after, oskb.oskbCopy(ins))
     self._stir("Paste")
Ejemplo n.º 7
0
 def _edit_redo(self):
     actionname, actionview, kbd = self._redo.pop(0)
     self._undo.insert(0, (actionname, self._viewname, oskb.oskbCopy(self._kbd)))
     oskb.oskbCopy(kbd, self._kbd)
     self._stir()
Ejemplo n.º 8
0
 def _saveFile(self, f):
     savecopy = oskb.oskbCopy(self._kbd)
     with open(f, "w") as outfile:
         json.dump(savecopy, outfile, ensure_ascii=False, indent=4)
     self._changed = False