RaUtil.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. class RaUtil:
  2. def __init__(self, Components):
  3. self.components = Components
  4. def getColor(self, color):
  5. """
  6. Convertiert einen Wert in eine unterstützte Farbe
  7. :param color: Die angegebene Farbe die Convertiert werden soll
  8. :returns: Gibt die convertierte Farbe zurück
  9. :rtype: list|str
  10. """
  11. if isinstance(color, str):
  12. if "," in color:
  13. c = color.split(",")
  14. if len(c)==3:
  15. return (int(c[0].strip()),int(c[1].strip()),int(c[2].strip()))
  16. elif len(c)==4:
  17. return (int(c[0].strip()),int(c[1].strip()),int(c[2].strip()),int(c[3].strip()))
  18. elif "#" in color:
  19. return self.hex_to_rgb(color)
  20. return color
  21. elif isinstance(color, int):
  22. return color
  23. elif "r" in color and "g" in color and "b" in color:
  24. if "a" in color:
  25. return (color["r"],color["g"],color["b"],color["a"])
  26. else:
  27. return (color["r"],color["g"],color["b"])
  28. def hex_to_rgb(self,value:str):
  29. """
  30. Convertiert Hex zu RGB
  31. :param color: Die angegebene Farbe die Convertiert werden soll
  32. :returns: Gibt die convertierte Farbe zurück
  33. :rtype: list
  34. """
  35. value = value.lstrip('#')
  36. lv = len(value)
  37. return tuple(int(value[i:i + lv // 3], 16) for i in range(0, lv, lv // 3))
  38. def rgb_to_hex(self,rgb):
  39. return '#%02x%02x%02x' % rgb
  40. def ExecuteFunc(self,s : str):
  41. print("Execute: " + s)
  42. if "." in s:
  43. args = []
  44. sp = s.split(".")
  45. c = sp[0].lower().strip()
  46. if "(" in sp[1]:
  47. if ")" in sp[1]:
  48. tmpParam=sp[1].split("(")[1].split(")")[0].strip()
  49. args = tmpParam.split(",")
  50. else:
  51. print("Error Function declation")
  52. func = None
  53. if c=="ramenu":
  54. func = getattr(self.components.Menu,sp[1])
  55. elif c=="radisplay":
  56. func = getattr(self.components.Display,sp[1])
  57. elif c=="ranas":
  58. func = getattr(self.components.Nas,sp[1])
  59. elif c=="rakeypad":
  60. func = getattr(self.components.Keypad,sp[1])
  61. elif c=="rautil":
  62. func = getattr(self.components.Util,sp[1])
  63. elif c=="raaction":
  64. func = getattr(self.components.Action,sp[1])
  65. else:
  66. func = getattr(sp[0],sp[1])
  67. if func is not None:
  68. argc = len(args)
  69. if argc==0:
  70. func()
  71. elif argc==1:
  72. func(args[0])
  73. elif argc==2:
  74. func(args[0],args[1])
  75. elif argc==3:
  76. func(args[0],args[1],args[2])
  77. elif argc==4:
  78. func(args[0],args[1],args[2],args[3])
  79. elif argc==5:
  80. func(args[0],args[1],args[2],args[3],args[4])
  81. elif argc==6:
  82. func(args[0],args[1],args[2],args[3],args[4],args[5])
  83. else:
  84. print(" Function does not exists")
  85. else:
  86. func = getattr(self,s)
  87. if func is not None:
  88. func()
  89. else:
  90. print(" Function does not exists")