123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- #####################################################################
- # #
- # THIS IS A SOURCE CODE FILE FROM A PROGRAM TO INTERACT WITH THE #
- # LBRY PROTOCOL ( lbry.com ). IT WILL USE THE LBRY SDK ( lbrynet ) #
- # FROM THEIR REPOSITORY ( https://github.com/lbryio/lbry-sdk ) #
- # WHICH I GONNA PRESENT TO YOU AS A BINARY. SINCE I DID NOT DEVELOP #
- # IT AND I'M LAZY TO INTEGRATE IN A MORE SMART WAY. THE SOURCE CODE #
- # OF THE SDK IS AVAILABLE IN THE REPOSITORY MENTIONED ABOVE. #
- # #
- # ALL THE CODE IN THIS REPOSITORY INCLUDING THIS FILE IS #
- # (C) J.Y.Amihud and Other Contributors 2021. EXCEPT THE LBRY SDK. #
- # YOU CAN USE THIS FILE AND ANY OTHER FILE IN THIS REPOSITORY UNDER #
- # THE TERMS OF GNU GENERAL PUBLIC LICENSE VERSION 3 OR ANY LATER #
- # VERSION. TO FIND THE FULL TEXT OF THE LICENSE GO TO THE GNU.ORG #
- # WEBSITE AT ( https://www.gnu.org/licenses/gpl-3.0.html ). #
- # #
- # THE LBRY SDK IS UNFORTUNATELY UNDER THE MIT LICENSE. IF YOU ARE #
- # NOT INTENDING TO USE MY CODE AND JUST THE SDK. YOU CAN FIND IT ON #
- # THEIR OFFICIAL REPOSITORY ABOVE. THEIR LICENSE CHOICE DOES NOT #
- # SPREAD ONTO THIS PROJECT. DON'T GET A FALSE ASSUMPTION THAT SINCE #
- # THEY USE A PUSH-OVER LICENSE, I GONNA DO THE SAME. I'M NOT. #
- # #
- # THE LICENSE CHOSEN FOR THIS PROJECT WILL PROTECT THE 4 ESSENTIAL #
- # FREEDOMS OF THE USER FURTHER, BY NOT ALLOWING ANY WHO TO CHANGE #
- # THE LICENSE AT WILL. SO NO PROPRIETARY SOFTWARE DEVELOPER COULD #
- # TAKE THIS CODE AND MAKE THEIR USER-SUBJUGATING SOFTWARE FROM IT. #
- # #
- #####################################################################
- # This file will handle all kinds of settings
- import os
- import json
- from gi.repository import Gtk
- def get_settings_folder(flbry="flbry/"):
- try:
- data_dir = os.environ["XDG_DATA_HOME"] + "/" + flbry # Reducted back since it
- # broke too much and made
- # my settings appear in
- # $XDG_DATA_HOME folder
- # inside the repository.
- # WTF !!!
- except:
- data_dir = os.path.expanduser("~/.local/share/"+flbry)
- try:
- os.makedirs(data_dir)
- except:
- pass
- return data_dir
- def load():
- with open(get_settings_folder()+'config.json') as json_file:
- data = json.load(json_file)
- return data
-
- def save(data):
- with open(get_settings_folder()+'config.json', 'w') as fp:
- json.dump(data, fp, sort_keys=True, indent=4)
- def make_sure_file_exists():
- # Let's make some defaults
- defaults = {
- "GTK_icon_theme":"System Theme"
- }
- # Let's write the Default theme.
- try:
- with open(get_settings_folder()+"config.json") as f:
- data = json.load(f)
- for i in defaults:
- if i not in data:
- data[i] = defaults[i]
- except Exception as e:
- data = defaults
-
- with open(get_settings_folder()+'config.json', 'w') as fp:
- json.dump(data, fp, sort_keys=True, indent=4)
-
- def dialogue(w, win):
- # This is the settings dialogue
- # Configuring the window
-
- dialogWindow = Gtk.Dialog("Settings",
- buttons=(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
- Gtk.STOCK_OK, Gtk.ResponseType.OK),
- )
- box = dialogWindow.get_content_area()
- # Themes
- themes_setting = Gtk.ComboBoxText()
- # Themes are laoded from folder in ./icons
- select = 0
- icon_themes = os.listdir(os.getcwd()+"/icons")
- icon_themes.append("System Theme")
- for n, theme in enumerate(icon_themes):
- themes_setting.append_text( theme )
- if win.settings["GTK_icon_theme"] == theme:
- select = n
-
-
- themes_setting.set_active(select)
- theme_box = Gtk.HBox()
- theme_box.pack_start(Gtk.Label("Icon Theme (requires restart) : "), False, False, False)
- theme_box.pack_start(themes_setting, False, False, False)
- box.pack_start(theme_box, False, False, False)
- # Running the dialog
- box.show_all()
- response = dialogWindow.run()
- if response == Gtk.ResponseType.OK:
- # Here I want to overwrite all the setting to ones
- # chosen by the user.
- win.settings["GTK_icon_theme"] = themes_setting.get_active_text()
- # Then we save everything.
- save(win.settings)
-
- dialogWindow.destroy()
|