Skip to content

Commit 551cc22

Browse files
committed
Fix Input ( plus lfs shit )
1 parent 19eccb0 commit 551cc22

File tree

6 files changed

+49
-26
lines changed

6 files changed

+49
-26
lines changed

PyFlow/Input.py

Lines changed: 37 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
## limitations under the License.
1414

1515

16-
from collections import Counter
1716
from collections import defaultdict
17+
from enum import Enum
1818

19-
from Qt import QtCore, QtGui
19+
from qtpy import QtCore, QtGui
2020

2121
from PyFlow.Core.Common import *
2222

@@ -27,16 +27,26 @@ class InputActionType(Enum):
2727

2828

2929
class InputAction(object):
30-
def __init__(self, name="defaultName", actionType=InputActionType.Keyboard, group="default", mouse=QtCore.Qt.NoButton, key=None, modifiers=QtCore.Qt.NoModifier):
30+
def __init__(
31+
self,
32+
name="defaultName",
33+
actionType=InputActionType.Keyboard,
34+
group="default",
35+
mouse=QtCore.Qt.NoButton,
36+
key=None,
37+
modifiers=QtCore.Qt.NoModifier,
38+
):
3139
self.__actionType = actionType
3240
self._name = name
3341
self._group = group
3442
self.__data = {"mouse": mouse, "key": key, "modifiers": modifiers}
3543

3644
def __str__(self):
37-
return "{0} {1} {2}".format(QtGui.QKeySequence(self.getModifiers()).toString(),
38-
self.getMouseButton().name.decode('utf=8'),
39-
QtGui.QKeySequence(self.getKey()).toString())
45+
return "{0} {1} {2}".format(
46+
QtGui.QKeySequence(self.getModifiers()).toString(),
47+
self.getMouseButton().name.decode("utf=8"),
48+
QtGui.QKeySequence(self.getKey()).toString(),
49+
)
4050

4151
@property
4252
def group(self):
@@ -53,10 +63,7 @@ def __eq__(self, other):
5363
om = other.getData()["mouse"]
5464
ok = other.getData()["key"]
5565
omod = other.getData()["modifiers"]
56-
smod == omod
57-
return all([sm == om,
58-
sk == ok,
59-
smod == omod])
66+
return all([sm == om, sk == ok, smod == omod])
6067

6168
def __ne__(self, other):
6269
sm = self.__data["mouse"]
@@ -65,9 +72,7 @@ def __ne__(self, other):
6572
om = other.getData()["mouse"]
6673
ok = other.getData()["key"]
6774
omod = other.getData()["modifiers"]
68-
return not all([sm == om,
69-
sk == ok,
70-
smod == omod])
75+
return not all([sm == om, sk == ok, smod == omod])
7176

7277
def getName(self):
7378
return self._name
@@ -76,14 +81,16 @@ def getData(self):
7681
return self.__data
7782

7883
def setMouseButton(self, btn):
79-
assert(isinstance(btn, QtCore.Qt.MouseButton))
84+
assert isinstance(btn, QtCore.Qt.MouseButton)
8085
self.__data["mouse"] = btn
8186

8287
def getMouseButton(self):
8388
return self.__data["mouse"]
8489

85-
def setKey(self, key=[]):
86-
assert(isinstance(key, QtCore.Qt.Key))
90+
def setKey(self, key=None):
91+
if key is None:
92+
key = []
93+
assert isinstance(key, QtCore.Qt.Key)
8794
self.__data["key"] = key
8895

8996
def getKey(self):
@@ -112,24 +119,24 @@ def _modifiersToList(mods):
112119
result.append(QtCore.Qt.GroupSwitchModifier)
113120
return result
114121

115-
def _listOfModifiersToEnum(self, modifiersList):
122+
@staticmethod
123+
def _listOfModifiersToEnum(modifiersList):
116124
result = QtCore.Qt.NoModifier
117125
for mod in modifiersList:
118126
result = result | mod
119127
return result
120128

121129
def toJson(self):
122-
saveData = {}
123-
saveData["name"] = self._name
124-
saveData["group"] = self._group
125-
saveData["mouse"] = int(self.__data["mouse"])
126-
saveData["actionType"] = self.actionType.value
127-
130+
saveData = {"name": self._name,
131+
"group": self._group,
132+
"mouse": int(self.__data["mouse"].value),
133+
"actionType": self.actionType.value}
128134
key = self.__data["key"]
129135
saveData["key"] = int(key) if key is not None else None
130136

131137
modifiersList = self._modifiersToList(self.__data["modifiers"])
132-
saveData["modifiers"] = [int(i) for i in modifiersList]
138+
139+
saveData["modifiers"] = [i.value for i in modifiersList]
133140
return saveData
134141

135142
def fromJson(self, jsonData):
@@ -138,8 +145,12 @@ def fromJson(self, jsonData):
138145
self._group = jsonData["group"]
139146
self.__data["mouse"] = QtCore.Qt.MouseButton(jsonData["mouse"])
140147
keyJson = jsonData["key"]
141-
self.__data["key"] = QtCore.Qt.Key(keyJson) if isinstance(keyJson, int) else None
142-
self.__data["modifiers"] = self._listOfModifiersToEnum([QtCore.Qt.KeyboardModifier(i) for i in jsonData["modifiers"]])
148+
self.__data["key"] = (
149+
QtCore.Qt.Key(keyJson) if isinstance(keyJson, int) else None
150+
)
151+
self.__data["modifiers"] = self._listOfModifiersToEnum(
152+
[QtCore.Qt.KeyboardModifier(i) for i in jsonData["modifiers"]]
153+
)
143154
self.__actionType = InputActionType(jsonData["actionType"])
144155
return self
145156
except:

hooks/post-checkout

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/sh
2+
command -v git-lfs >/dev/null 2>&1 || { echo >&2 "\nThis repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting .git/hooks/post-checkout.\n"; exit 2; }
3+
git lfs post-checkout "$@"

hooks/post-commit

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/sh
2+
command -v git-lfs >/dev/null 2>&1 || { echo >&2 "\nThis repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting .git/hooks/post-commit.\n"; exit 2; }
3+
git lfs post-commit "$@"

hooks/post-merge

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/sh
2+
command -v git-lfs >/dev/null 2>&1 || { echo >&2 "\nThis repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting .git/hooks/post-merge.\n"; exit 2; }
3+
git lfs post-merge "$@"

hooks/pre-push

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/sh
2+
command -v git-lfs >/dev/null 2>&1 || { echo >&2 "\nThis repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting .git/hooks/pre-push.\n"; exit 2; }
3+
git lfs pre-push "$@"

0 commit comments

Comments
 (0)