KLL Compiler
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

emitters.py 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #!/usr/bin/env python3
  2. '''
  3. KLL Emitters Container Classes
  4. '''
  5. # Copyright (C) 2016 by Jacob Alexander
  6. #
  7. # This file is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation, either version 3 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # This file is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with this file. If not, see <http://www.gnu.org/licenses/>.
  19. ### Imports ###
  20. import emitters.kiibohd.kiibohd as kiibohd
  21. ### Decorators ###
  22. ## Print Decorator Variables
  23. ERROR = '\033[5;1;31mERROR\033[0m:'
  24. WARNING = '\033[5;1;33mWARNING\033[0m:'
  25. ### Classes ###
  26. class Emitters:
  27. '''
  28. Container class for KLL emitters
  29. NOTES: To add a new emitter
  30. - Add a new directory for your emitter (e.g. kiibohd)
  31. - Add at least two files in this directory (<name>.py and __init__.py)
  32. - In <name>.py have one class that inherits the Emitter class from common.emitter
  33. - Add to list of emitters below
  34. - Add import statement to the top of this file
  35. - The control object allows access to the entire set of KLL datastructures
  36. '''
  37. def __init__( self, control ):
  38. '''
  39. Emitter initialization
  40. @param control: ControlStage object, used to access data from other stages
  41. '''
  42. # Default emitter
  43. self.default = "kiibohd"
  44. # Dictionary of Emitters
  45. self.emitters = {
  46. 'kiibohd' : kiibohd.Kiibohd( control )
  47. }
  48. def emitter_default( self ):
  49. '''
  50. Returns string name of default emitter
  51. '''
  52. return self.default
  53. def emitter_list( self ):
  54. '''
  55. List of emitters available
  56. '''
  57. return list( self.emitters.keys() )
  58. def emitter( self, emitter ):
  59. '''
  60. Returns an emitter object
  61. '''
  62. return self.emitters[ emitter ]
  63. def command_line_args( self, args ):
  64. '''
  65. Group parser fan-out for emitter command line arguments
  66. @param args: Name space of processed arguments
  67. '''
  68. # Always process command line args in the same order
  69. for key, emitter in sorted( self.emitters.items(), key=lambda x: x[0] ):
  70. emitter.command_line_args( args )
  71. def command_line_flags( self, parser ):
  72. '''
  73. Group parser fan-out for emitter for command line options
  74. @param parser: argparse setup object
  75. '''
  76. # Always process command line flags in the same order
  77. for key, emitter in sorted( self.emitters.items(), key=lambda x: x[0] ):
  78. emitter.command_line_flags( parser )