]> git.donarmstrong.com Git - kiibohd-kll.git/blobdiff - kll_lib/containers.py
Merge pull request #2 from mcmasterathl/master
[kiibohd-kll.git] / kll_lib / containers.py
index f732649fb5c2a75148e28757572aefedf4c57d46..2436c7ea930356fd8c00310fa3a938d9e96b9a5e 100644 (file)
@@ -1,7 +1,7 @@
 #!/usr/bin/env python3
 # KLL Compiler Containers
 #
-# Copyright (C) 2014 by Jacob Alexander
+# Copyright (C) 2014-2015 by Jacob Alexander
 #
 # This file is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -159,6 +159,16 @@ class Macros:
                        if usbCode in self.macros[ self.layer ][ macro ]:
                                scanCodeList.append( macro )
 
+               if len(scanCodeList) == 0:
+                       if len(usbCode) > 1 or len(usbCode[0]) > 1:
+                               for combo in usbCode:
+                                       comboCodes = list()
+                                       for key in combo:
+                                               scanCode = self.lookupUSBCodes(((key,),))
+                                               comboCodes.append(scanCode[0][0][0])
+                                       scanCodeList.append(tuple(code for code in comboCodes))
+                               scanCodeList = [tuple(scanCodeList)]
+
                return scanCodeList
 
        # Cache USBCode Assignment
@@ -277,19 +287,69 @@ class Variables:
        # Container for variables
        # Stores three sets of variables, the overall combined set, per layer, and per file
        def __init__( self ):
-               pass
+               # Dictionaries of variables
+               self.baseLayout       = dict()
+               self.fileVariables    = dict()
+               self.layerVariables   = [ dict() ]
+               self.overallVariables = dict()
+               self.defines          = dict()
+
+               self.currentFile = ""
+               self.currentLayer = 0
+               self.baseLayoutEnabled = True
 
-       def baseLayerFinished( self ):
-               pass
+       def baseLayoutFinished( self ):
+               self.baseLayoutEnabled = False
 
        def setCurrentFile( self, name ):
                # Store using filename and current layer
-               pass
+               self.currentFile = name
+               self.fileVariables[ name ] = dict()
+
+               # If still processing BaseLayout
+               if self.baseLayoutEnabled:
+                       if '*LayerFiles' in self.baseLayout.keys():
+                               self.baseLayout['*LayerFiles'] += [ name ]
+                       else:
+                               self.baseLayout['*LayerFiles'] = [ name ]
+               # Set for the current layer
+               else:
+                       if '*LayerFiles' in self.layerVariables[ self.currentLayer ].keys():
+                               self.layerVariables[ self.currentLayer ]['*LayerFiles'] += [ name ]
+                       else:
+                               self.layerVariables[ self.currentLayer ]['*LayerFiles'] = [ name ]
 
-       def setCurrentLayer( self, layer ):
+       def incrementLayer( self ):
                # Store using layer index
-               pass
+               self.currentLayer += 1
+               self.layerVariables.append( dict() )
 
        def assignVariable( self, key, value ):
-               pass
+               # Overall set of variables
+               self.overallVariables[ key ] = value
+
+               # The Name variable is a special accumulation case
+               if key == 'Name':
+                       # BaseLayout still being processed
+                       if self.baseLayoutEnabled:
+                               if '*NameStack' in self.baseLayout.keys():
+                                       self.baseLayout['*NameStack'] += [ value ]
+                               else:
+                                       self.baseLayout['*NameStack'] = [ value ]
+                       # Layers
+                       else:
+                               if '*NameStack' in self.layerVariables[ self.currentLayer ].keys():
+                                       self.layerVariables[ self.currentLayer ]['*NameStack'] += [ value ]
+                               else:
+                                       self.layerVariables[ self.currentLayer ]['*NameStack'] = [ value ]
+
+               # If still processing BaseLayout
+               if self.baseLayoutEnabled:
+                       self.baseLayout[ key ] = value
+               # Set for the current layer
+               else:
+                       self.layerVariables[ self.currentLayer ][ key ] = value
+
+               # File context variables
+               self.fileVariables[ self.currentFile ][ key ] = value