UI_color.py 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. ####################################
  2. # #
  3. # COPYRIGHT NOTICE #
  4. # #
  5. # This file is a part of Victori- #
  6. # ous Children Studio Organizer. #
  7. # Or simply VCStudio. Copyright #
  8. # of J.Y.Amihud. But don't be sad #
  9. # because I released the entire #
  10. # project under a GNU GPL license. #
  11. # You may use Version 3 or later. #
  12. # See www.gnu.org/licenses if your #
  13. # copy has no License file. Please #
  14. # note. Ones I used the GPL v2 for #
  15. # it. It's no longer the case. #
  16. # #
  17. ####################################
  18. # This a console project manager.
  19. import os
  20. import math
  21. # GTK module ( Graphical interface
  22. import gi
  23. gi.require_version('Gtk', '3.0')
  24. from gi.repository import Gtk
  25. import cairo
  26. # Own modules
  27. from settings import settings
  28. from settings import talk
  29. def get_table():
  30. # This function will give a whole table of colors from a theme. So there will
  31. # be no need to read from the theme.data file every time we need a color of
  32. # somethings. It would've been stupid. So we load all the colors into RAM
  33. # at this stage. Similar stuff should be done with talk.text() i guess.
  34. # First let's find what is actually the theme we are using.
  35. try:
  36. data = open("settings/themes/"+settings.read("Theme")+"/theme.data")
  37. except:
  38. # If by any change it fails to read the theme from the Theme setting
  39. # it will use the Default theme.
  40. data = open("settings/themes/Default/theme.data")
  41. settings.write("Theme", "Default")
  42. data = data.read()
  43. data = data.split("\n")
  44. # Parsing
  45. ret = {}
  46. for d in data:
  47. if d:
  48. name = d.split(" = ")[0]
  49. color = d.split(" = ")[1].split(",")
  50. c = []
  51. for co in color:
  52. try:
  53. c.append(float(co))
  54. except:
  55. c.append(0.0)
  56. color = c
  57. ret[name] = color
  58. # Returning
  59. return ret
  60. def set(layer, win, color):
  61. # One line code less to setup a color each time LOL
  62. try:
  63. r,g,b,a = win.color[color]
  64. # If blur is off I want the transparent to be less
  65. # noticable. Since blur helped a lot in readability.
  66. # Without blur the same amount of alpha is not going
  67. # to be as readable. So we have to boost it without
  68. # the blur.
  69. if a < 1 and not win.settings["Blur"]:
  70. a = min(0.9, a*2)
  71. layer.set_source_rgba(r,g,b,a)
  72. except:
  73. layer.set_source_rgba(1,0,1,1)