UI_color.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. # THIS FILE IS A PART OF VCStudio
  2. # PYTHON 3
  3. # This a console project manager.
  4. import os
  5. import math
  6. # GTK module ( Graphical interface
  7. import gi
  8. gi.require_version('Gtk', '3.0')
  9. from gi.repository import Gtk
  10. import cairo
  11. # Own modules
  12. from settings import settings
  13. from settings import talk
  14. def get_table():
  15. # This function will give a whole table of colors from a theme. So there will
  16. # be no need to read from the theme.data file every time we need a color of
  17. # somethings. It would've been stupid. So we load all the colors into RAM
  18. # at this stage. Similar stuff should be done with talk.text() i guess.
  19. # First let's find what is actually the theme we are using.
  20. try:
  21. data = open("settings/themes/"+settings.read("Theme")+"/theme.data")
  22. except:
  23. # If by any change it fails to read the theme from the Theme setting
  24. # it will use the Default theme.
  25. data = open("settings/themes/Default/theme.data")
  26. settings.write("Theme", "Default")
  27. data = data.read()
  28. data = data.split("\n")
  29. # Parsing
  30. ret = {}
  31. for d in data:
  32. if d:
  33. name = d.split(" = ")[0]
  34. color = d.split(" = ")[1].split(",")
  35. c = []
  36. for co in color:
  37. try:
  38. c.append(float(co))
  39. except:
  40. c.append(0.0)
  41. color = c
  42. ret[name] = color
  43. # Returning
  44. return ret
  45. def set(layer, win, color):
  46. # One line code less to setup a color each time LOL
  47. try:
  48. r,g,b,a = win.color[color]
  49. # If blur is off I want the transparent to be less
  50. # noticable. Since blur helped a lot in readability.
  51. # Without blur the same amount of alpha is not going
  52. # to be as readable. So we have to boost it without
  53. # the blur.
  54. if a < 1 and not win.settings["Blur"]:
  55. a = min(0.9, a*2)
  56. layer.set_source_rgba(r,g,b,a)
  57. except:
  58. layer.set_source_rgba(1,0,1,1)