|
|
|
@ -20,7 +20,7 @@ validKeyList = [
|
|
|
|
|
|
|
|
|
|
popErrors = (AttributeError, KeyError, TypeError)
|
|
|
|
|
|
|
|
|
|
class Bind(object):
|
|
|
|
|
class ScriptBind(object):
|
|
|
|
|
'''
|
|
|
|
|
Parent class for all bind types.
|
|
|
|
|
Verifies key, creates local variables
|
|
|
|
@ -47,7 +47,7 @@ class Bind(object):
|
|
|
|
|
# and some other universal fields like alias and finds targetType
|
|
|
|
|
self.verify()
|
|
|
|
|
|
|
|
|
|
if type(self) is Bind:
|
|
|
|
|
if type(self) is ScriptBind:
|
|
|
|
|
# not using isinstance(), because all subclasses are also instances
|
|
|
|
|
# of bind.
|
|
|
|
|
return
|
|
|
|
@ -137,7 +137,7 @@ class Bind(object):
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Impulse(Bind):
|
|
|
|
|
class Impulse(ScriptBind):
|
|
|
|
|
def verify(self):
|
|
|
|
|
self.command: list = None
|
|
|
|
|
if not isinstance(self.fields, dict):
|
|
|
|
@ -231,7 +231,7 @@ class Impulse(Bind):
|
|
|
|
|
return buildingNums.get(building, building)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Hold(Bind):
|
|
|
|
|
class Hold(ScriptBind):
|
|
|
|
|
def verify(self):
|
|
|
|
|
self.press: list = None
|
|
|
|
|
self.release: list = None
|
|
|
|
@ -293,7 +293,7 @@ class Hold(Bind):
|
|
|
|
|
return code
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Toggle(Bind):
|
|
|
|
|
class Toggle(ScriptBind):
|
|
|
|
|
def verify(self):
|
|
|
|
|
self.on : list = None
|
|
|
|
|
self.off: list = None
|
|
|
|
@ -349,7 +349,7 @@ class Toggle(Bind):
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Double(Bind):
|
|
|
|
|
class Double(ScriptBind):
|
|
|
|
|
defaultDict = {}
|
|
|
|
|
condDict = {}
|
|
|
|
|
bindNames = []
|
|
|
|
@ -360,8 +360,8 @@ class Double(Bind):
|
|
|
|
|
self.isToggle = False
|
|
|
|
|
self.cancelBoth = False
|
|
|
|
|
|
|
|
|
|
self.primary: Bind = None
|
|
|
|
|
self.secondary: Bind = None
|
|
|
|
|
self.primary: ScriptBind = None
|
|
|
|
|
self.secondary: ScriptBind = None
|
|
|
|
|
self.condition: str = None
|
|
|
|
|
self.type: str = None
|
|
|
|
|
|
|
|
|
@ -427,9 +427,9 @@ class Double(Bind):
|
|
|
|
|
if self.primary is self.secondary is None:
|
|
|
|
|
self.err('has neither primary nor secondary')
|
|
|
|
|
|
|
|
|
|
def getSection(self, popName, key, /) -> Bind:
|
|
|
|
|
def getSection(self, popName, key, /) -> ScriptBind:
|
|
|
|
|
section = self.fields.pop(popName)
|
|
|
|
|
bind = Bind(f'{self.type} {key}', section)
|
|
|
|
|
bind = ScriptBind(f'{self.type} {key}', section)
|
|
|
|
|
bind = bind.toTargetType()
|
|
|
|
|
|
|
|
|
|
bind.errors.remove(f'invalid key name: "{key}"')
|
|
|
|
@ -543,7 +543,7 @@ class Double(Bind):
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Repeat(Bind):
|
|
|
|
|
class Repeat(ScriptBind):
|
|
|
|
|
def verify(self):
|
|
|
|
|
self.interval = None
|
|
|
|
|
self.command = None
|
|
|
|
@ -573,7 +573,7 @@ class Repeat(Bind):
|
|
|
|
|
return f'// repeat {self.key}\n'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Literal(Bind):
|
|
|
|
|
class Literal(ScriptBind):
|
|
|
|
|
def verify(self):
|
|
|
|
|
self.text = ''
|
|
|
|
|
self.run = False
|
|
|
|
@ -617,8 +617,23 @@ class Literal(Bind):
|
|
|
|
|
result += f'\n{self.key}'
|
|
|
|
|
return result + '\n'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Bind(ScriptBind):
|
|
|
|
|
def verify(self):
|
|
|
|
|
# just set self.text, and if it's not a string, make an error
|
|
|
|
|
self.text = self.fields
|
|
|
|
|
if isinstance(self.text, str):
|
|
|
|
|
# clear self.fields to assure no "extra field" warnings
|
|
|
|
|
self.fields = {}
|
|
|
|
|
else:
|
|
|
|
|
# not passed string ==> error
|
|
|
|
|
self.err('argument must be a string')
|
|
|
|
|
|
|
|
|
|
def toTF2(self) -> str:
|
|
|
|
|
return f'bind {self.key} {self.text}\n'
|
|
|
|
|
|
|
|
|
|
# This is at the bottom because it has to happen after
|
|
|
|
|
# all inheritances have been completed
|
|
|
|
|
|
|
|
|
|
Bind.bindTypes = Bind.__subclasses__()
|
|
|
|
|
Double.bindNames = [ bind.__name__.lower() for bind in Bind.bindTypes ]
|
|
|
|
|
ScriptBind.bindTypes = ScriptBind.__subclasses__()
|
|
|
|
|
Double.bindNames = [ bind.__name__.lower() for bind in ScriptBind.bindTypes ]
|