any_keycode_dialog: support bit ops
parent
19895d280c
commit
98a4052673
|
|
@ -1,9 +1,10 @@
|
||||||
# SPDX-License-Identifier: GPL-2.0-or-later
|
# SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
import ast
|
||||||
|
|
||||||
|
import simpleeval
|
||||||
|
import operator
|
||||||
from PyQt5.QtWidgets import QDialog, QDialogButtonBox, QVBoxLayout, QLineEdit, QLabel
|
from PyQt5.QtWidgets import QDialog, QDialogButtonBox, QVBoxLayout, QLineEdit, QLabel
|
||||||
|
|
||||||
from simpleeval import simple_eval
|
|
||||||
|
|
||||||
from keycodes import KEYCODES_SPECIAL, KEYCODES_BASIC, KEYCODES_SHIFTED, KEYCODES_ISO, KEYCODES_BACKLIGHT, \
|
from keycodes import KEYCODES_SPECIAL, KEYCODES_BASIC, KEYCODES_SHIFTED, KEYCODES_ISO, KEYCODES_BACKLIGHT, \
|
||||||
KEYCODES_MEDIA, KEYCODES_USER, QK_LCTL, QK_LSFT, QK_LALT, QK_LGUI, QK_RCTL, QK_RSFT, QK_RALT, QK_RGUI, QK_LAYER_TAP
|
KEYCODES_MEDIA, KEYCODES_USER, QK_LCTL, QK_LSFT, QK_LALT, QK_LGUI, QK_RCTL, QK_RSFT, QK_RALT, QK_RGUI, QK_LAYER_TAP
|
||||||
from util import tr
|
from util import tr
|
||||||
|
|
@ -119,6 +120,12 @@ class AnyKeycodeDialog(QDialog):
|
||||||
self.layout.addWidget(self.buttons)
|
self.layout.addWidget(self.buttons)
|
||||||
self.setLayout(self.layout)
|
self.setLayout(self.layout)
|
||||||
|
|
||||||
|
self.ops = simpleeval.DEFAULT_OPERATORS.copy()
|
||||||
|
self.ops.update({
|
||||||
|
ast.BitOr: operator.or_,
|
||||||
|
ast.BitXor: operator.xor,
|
||||||
|
ast.BitAnd: operator.and_,
|
||||||
|
})
|
||||||
self.names = dict()
|
self.names = dict()
|
||||||
self.prepare_names()
|
self.prepare_names()
|
||||||
|
|
||||||
|
|
@ -144,7 +151,7 @@ class AnyKeycodeDialog(QDialog):
|
||||||
text = self.txt_entry.text()
|
text = self.txt_entry.text()
|
||||||
value = err = None
|
value = err = None
|
||||||
try:
|
try:
|
||||||
value = simple_eval(text, names=self.names, functions=functions)
|
value = simpleeval.simple_eval(text, names=self.names, functions=functions, operators=self.ops)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
err = str(e)
|
err = str(e)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue