2 # KLL Compiler Containers
4 # Copyright (C) 2014 by Jacob Alexander
6 # This file is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # This file is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this file. If not, see <http://www.gnu.org/licenses/>.
25 ## Print Decorator Variables
26 ERROR = '\033[5;1;31mERROR\033[0m:'
34 # Container for capabilities dictionary and convenience functions
36 self.capabilities = dict()
38 def __getitem__( self, name ):
39 return self.capabilities[ name ]
41 def __setitem__( self, name, contents ):
42 self.capabilities[ name ] = contents
45 return "Capabilities => {0}\nIndexed Capabilities => {1}".format( self.capabilities, sorted( self.capabilities, key = self.capabilities.get ) )
48 # Total bytes needed to store arguments
49 def totalArgBytes( self, name ):
52 # Iterate over the arguments, summing the total bytes
53 for arg in self.capabilities[ name ][1]:
54 totalBytes += int( arg[1] )
58 # Name of the capability function
59 def funcName( self, name ):
60 return self.capabilities[ name ][0]
63 # Only valid while dictionary keys are not added/removed
64 def getIndex( self, name ):
65 return sorted( self.capabilities, key = self.capabilities.get ).index( name )
67 def getName( self, index ):
68 return sorted( self.capabilities, key = self.capabilities.get )[ index ]
71 return sorted( self.capabilities, key = self.capabilities.get )
75 # Container for Trigger Macro : Result Macro correlation
76 # Layer selection for generating TriggerLists
78 # Only convert USB Code list once all the ResultMacros have been accumulated (does a macro reduction; not reversible)
79 # Two staged list for ResultMacros:
80 # 1) USB Code/Non-converted (may contain capabilities)
89 def setLayer( self, layer ):
92 # Use for ScanCode trigger macros
93 def appendScanCode( self, trigger, result ):
94 self.macros[ self.layer ][ trigger ] = result
96 # Use for USBCode trigger macros
97 # An extra lookup is required
98 def appendUSBCode( self, trigger, result ):
101 for macro in self.macros[ self.layer ].keys():
103 if trigger == self.macros[ self.layer ][ macro ]:
104 print ( "USBCode - Replacing '{0}' with '{1}' -> '{2}'".format( trigger, macro, result ) )
105 self.macros[ self.layer ][ macro ] = result
108 # Only show warning if no replacements were done
110 print ( "Warning: '{1}' USB Code not found in layer {1}".format( trigger, self.layer ) )