Skip to content

Commit

Permalink
Fix Input ( plus lfs shit )
Browse files Browse the repository at this point in the history
  • Loading branch information
pedroCabrera committed Feb 7, 2024
1 parent 19eccb0 commit 551cc22
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 26 deletions.
63 changes: 37 additions & 26 deletions PyFlow/Input.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
## limitations under the License.


from collections import Counter
from collections import defaultdict
from enum import Enum

from Qt import QtCore, QtGui
from qtpy import QtCore, QtGui

from PyFlow.Core.Common import *

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


class InputAction(object):
def __init__(self, name="defaultName", actionType=InputActionType.Keyboard, group="default", mouse=QtCore.Qt.NoButton, key=None, modifiers=QtCore.Qt.NoModifier):
def __init__(
self,
name="defaultName",
actionType=InputActionType.Keyboard,
group="default",
mouse=QtCore.Qt.NoButton,
key=None,
modifiers=QtCore.Qt.NoModifier,
):
self.__actionType = actionType
self._name = name
self._group = group
self.__data = {"mouse": mouse, "key": key, "modifiers": modifiers}

def __str__(self):
return "{0} {1} {2}".format(QtGui.QKeySequence(self.getModifiers()).toString(),
self.getMouseButton().name.decode('utf=8'),
QtGui.QKeySequence(self.getKey()).toString())
return "{0} {1} {2}".format(
QtGui.QKeySequence(self.getModifiers()).toString(),
self.getMouseButton().name.decode("utf=8"),
QtGui.QKeySequence(self.getKey()).toString(),
)

@property
def group(self):
Expand All @@ -53,10 +63,7 @@ def __eq__(self, other):
om = other.getData()["mouse"]
ok = other.getData()["key"]
omod = other.getData()["modifiers"]
smod == omod
return all([sm == om,
sk == ok,
smod == omod])
return all([sm == om, sk == ok, smod == omod])

def __ne__(self, other):
sm = self.__data["mouse"]
Expand All @@ -65,9 +72,7 @@ def __ne__(self, other):
om = other.getData()["mouse"]
ok = other.getData()["key"]
omod = other.getData()["modifiers"]
return not all([sm == om,
sk == ok,
smod == omod])
return not all([sm == om, sk == ok, smod == omod])

def getName(self):
return self._name
Expand All @@ -76,14 +81,16 @@ def getData(self):
return self.__data

def setMouseButton(self, btn):
assert(isinstance(btn, QtCore.Qt.MouseButton))
assert isinstance(btn, QtCore.Qt.MouseButton)
self.__data["mouse"] = btn

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

def setKey(self, key=[]):
assert(isinstance(key, QtCore.Qt.Key))
def setKey(self, key=None):
if key is None:
key = []
assert isinstance(key, QtCore.Qt.Key)
self.__data["key"] = key

def getKey(self):
Expand Down Expand Up @@ -112,24 +119,24 @@ def _modifiersToList(mods):
result.append(QtCore.Qt.GroupSwitchModifier)
return result

def _listOfModifiersToEnum(self, modifiersList):
@staticmethod
def _listOfModifiersToEnum(modifiersList):
result = QtCore.Qt.NoModifier
for mod in modifiersList:
result = result | mod
return result

def toJson(self):
saveData = {}
saveData["name"] = self._name
saveData["group"] = self._group
saveData["mouse"] = int(self.__data["mouse"])
saveData["actionType"] = self.actionType.value

saveData = {"name": self._name,
"group": self._group,
"mouse": int(self.__data["mouse"].value),
"actionType": self.actionType.value}
key = self.__data["key"]
saveData["key"] = int(key) if key is not None else None

modifiersList = self._modifiersToList(self.__data["modifiers"])
saveData["modifiers"] = [int(i) for i in modifiersList]

saveData["modifiers"] = [i.value for i in modifiersList]
return saveData

def fromJson(self, jsonData):
Expand All @@ -138,8 +145,12 @@ def fromJson(self, jsonData):
self._group = jsonData["group"]
self.__data["mouse"] = QtCore.Qt.MouseButton(jsonData["mouse"])
keyJson = jsonData["key"]
self.__data["key"] = QtCore.Qt.Key(keyJson) if isinstance(keyJson, int) else None
self.__data["modifiers"] = self._listOfModifiersToEnum([QtCore.Qt.KeyboardModifier(i) for i in jsonData["modifiers"]])
self.__data["key"] = (
QtCore.Qt.Key(keyJson) if isinstance(keyJson, int) else None
)
self.__data["modifiers"] = self._listOfModifiersToEnum(
[QtCore.Qt.KeyboardModifier(i) for i in jsonData["modifiers"]]
)
self.__actionType = InputActionType(jsonData["actionType"])
return self
except:
Expand Down
3 changes: 3 additions & 0 deletions hooks/post-checkout
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh
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; }
git lfs post-checkout "$@"
3 changes: 3 additions & 0 deletions hooks/post-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh
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; }
git lfs post-commit "$@"
3 changes: 3 additions & 0 deletions hooks/post-merge
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh
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; }
git lfs post-merge "$@"
3 changes: 3 additions & 0 deletions hooks/pre-push
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh
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; }
git lfs pre-push "$@"
Binary file not shown.

0 comments on commit 551cc22

Please sign in to comment.