tamir_tema.py 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. #!/bin/python3
  2. import configparser
  3. import os
  4. import xml.etree.cElementTree as ET
  5. from gi.repository import Gtk, Gio, GObject, GLib
  6. homedir = os.path.expanduser( '~' )
  7. config_dir = homedir + "/.config/"
  8. # masa.ini
  9. config = configparser.ConfigParser()
  10. config.read(config_dir + "masa.ini")
  11. # GTK
  12. # keyfile tanımlı değilse, sistem ilk açılış
  13. # yedek degerler
  14. _theme = "Arc-Milis-Dark"
  15. _icon = "Papirus-Dark"
  16. _cursor = "volantes_cursors_milis"
  17. _font = "Sans Regular 11"
  18. if not os.path.exists(config_dir + "glib-2.0/settings/keyfile"):
  19. if "theme" in config :
  20. if "name" in config["theme"]:
  21. _theme = config["theme"]["name"]
  22. if "icon" in config["theme"]:
  23. _icon = config["theme"]["icon"]
  24. if "cursor" in config["theme"]:
  25. _cursor = config["theme"]["cursor"]
  26. if "font" in config["theme"]:
  27. _font = config["theme"]["font"]
  28. set_desktop="gsettings set org.gnome.desktop.interface"
  29. set_sound="gsettings set org.gnome.desktop.sound"
  30. os.system("{} {} {}".format(set_desktop,"gtk-theme",_theme))
  31. os.system("{} {} {}".format(set_desktop,"icon-theme",_icon))
  32. os.system("{} {} {}".format(set_desktop,"cursor-theme",_cursor))
  33. os.system("{} {} {}".format(set_desktop,"cursor-size",24))
  34. os.system("{} {} {}".format(set_desktop,"font-name","'"+_font+"'"))
  35. os.system("{} {} {}".format(set_desktop,"toolbar-style", "both-horiz"))
  36. os.system("{} {} {}".format(set_desktop,"toolbar-icons-size", "large"))
  37. os.system("{} {} {}".format(set_desktop,"font-hinting", "slight"))
  38. os.system("{} {} {}".format(set_desktop,"font-antialiasing", "grayscale"))
  39. os.system("{} {} {}".format(set_sound,"event-sounds", "true"))
  40. os.system("{} {} {}".format(set_sound,"input-feedback-sounds", "true"))
  41. # active tema
  42. else:
  43. gio_cfg = Gio.Settings.new("org.gnome.desktop.interface")
  44. _theme = gio_cfg.get_string("gtk-theme")
  45. # Labwc
  46. rc_xml_file = config_dir + "labwc/rc.xml"
  47. if os.path.exists(rc_xml_file):
  48. tree = ET.parse(rc_xml_file)
  49. root = tree.getroot()
  50. for tema in root.findall('theme'):
  51. name = tema.find("name")
  52. name.text = _theme
  53. tree.write(rc_xml_file)
  54. # tema aktif olması için labwc reconfigure gerekli
  55. if os.environ.get("LABWC_PID"):
  56. os.system("labwc -r")
  57. # Geany - .config/geany/color_schemes altındaki *.conf olarak yazılmalı
  58. if "theme" in config and "geany" in config["theme"]:
  59. geany_ini_file = config_dir + "geany/geany.conf"
  60. # geany files bölümünde aynı değere sahip anahtarlar tutuyor - onun için raw
  61. config_g = configparser.RawConfigParser()
  62. config_g.optionxform = lambda option: option
  63. config_g.read(geany_ini_file)
  64. config_g.set('geany', 'color_scheme', config["theme"]["geany"])
  65. with open(geany_ini_file,"w") as g_file:
  66. config_g.write(g_file)
  67. # Swaync
  68. if "theme" in config and "swaync" in config["theme"]:
  69. target_dir = config_dir + "swaync/"
  70. source_file = config["theme"]["swaync"]
  71. os.system("cp -fv {} {}".format(source_file, target_dir+"style.css"))
  72. # nwg
  73. if "theme" in config and "nwg" in config["theme"]:
  74. source_file = config["theme"]["nwg"]
  75. target_dir = config_dir + "nwg-bar/"
  76. os.system("cp -fv {} {}".format(source_file, target_dir+"style.css"))
  77. target_dir = config_dir + "nwg-drawer/"
  78. os.system("cp -fv {} {}".format(source_file, target_dir+"drawer.css"))
  79. # Waybar
  80. if "theme" in config and "waybar" in config["theme"]:
  81. target_dir = config_dir + "waybar/"
  82. source_file = config["theme"]["waybar"]
  83. os.system("cp -fv {} {}".format(source_file, target_dir+"style.css"))
  84. """
  85. import gi
  86. gi.require_version("Gtk","3.0")
  87. from gi.repository import Gtk, Gio, GObject, GLib
  88. config.read(homedir + "/.config/gtk-3.0/settings.ini")
  89. _theme = config["Settings"]["gtk-theme-name"]
  90. _icon = config["Settings"]["gtk-icon-theme-name"]
  91. _cursor = config["Settings"]["gtk-cursor-theme-name"]
  92. _font = config["Settings"]["gtk-font-name"]
  93. gtk_cfg = Gtk.Settings.get_default()
  94. #print(gtk_cfg.get_property("gtk-theme-name"))
  95. gtk_cfg.set_property("gtk-theme-name",_theme)
  96. gtk_cfg.set_property("gtk-icon-theme-name",_icon)
  97. gtk_cfg.set_property("gtk-cursor-theme-name",_cursor)
  98. gtk_cfg.set_property("gtk-font-name",_font)
  99. # gio ayarlarını ayarla
  100. gio_cfg = Gio.Settings.new("org.gnome.desktop.interface")
  101. gio_cfg.set_string("gtk-theme",_theme)
  102. gio_cfg.set_string("icon-theme",_icon)
  103. gio_cfg.set_string("cursor-theme",_cursor)
  104. gio_cfg.set_string("font-name",_font)
  105. #print(gio_cfg.get_string("gtk-theme"))
  106. """