Restructured settings logic and loading

This commit is contained in:
itdominator 2023-07-30 00:36:52 -05:00
parent 1e73236ee8
commit 231eb902e4
25 changed files with 452 additions and 191 deletions

View File

@ -9,7 +9,7 @@ from utils.event_system import EventSystem
from utils.endpoint_registry import EndpointRegistry
from utils.keybindings import Keybindings
from utils.logger import Logger
from utils.settings import Settings
from utils.settings_manager.manager import SettingsManager
@ -33,10 +33,11 @@ builtins.app_name = "<change_me>"
builtins.keybindings = Keybindings()
builtins.event_system = EventSystem()
builtins.endpoint_registry = EndpointRegistry()
builtins.settings = Settings()
builtins.logger = Logger(settings.get_home_config_path(), \
_ch_log_lvl=settings.get_ch_log_lvl(), \
_fh_log_lvl=settings.get_fh_log_lvl()).get_logger()
builtins.settings_manager = SettingsManager()
builtins.settings = settings_manager.settings
builtins.logger = Logger(settings_manager.get_home_config_path(), \
_ch_log_lvl=settings.debugging.ch_log_lvl, \
_fh_log_lvl=settings.debugging.fh_log_lvl).get_logger()
builtins.threaded = threaded_wrapper
builtins.daemon_threaded = daemon_threaded_wrapper

View File

@ -40,12 +40,12 @@ if __name__ == "__main__":
args, unknownargs = parser.parse_known_args()
if args.debug == "true":
settings.set_debug(True)
settings_manager.set_debug(True)
if args.trace_debug == "true":
settings.set_trace_debug(True)
settings_manager.set_trace_debug(True)
settings.do_dirty_start_check()
settings_manager.do_dirty_start_check()
Application(args, unknownargs)
Gtk.main()
except Exception as e:

View File

@ -21,7 +21,7 @@ class Application(IPCServer):
def __init__(self, args, unknownargs):
super(Application, self).__init__()
if not settings.is_trace_debug():
if not settings_manager.is_trace_debug():
try:
self.create_ipc_listener()
except Exception:

View File

@ -6,6 +6,9 @@ gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
# Application imports
from .left_container import LeftContainer
from .center_container import CenterContainer
from .right_container import RightContainer
@ -13,8 +16,6 @@ class BaseContainer(Gtk.Box):
def __init__(self):
super(BaseContainer, self).__init__()
self._builder = settings.get_builder()
self._setup_styling()
self._setup_signals()
self._load_widgets()
@ -24,20 +25,13 @@ class BaseContainer(Gtk.Box):
def _setup_styling(self):
self.set_orientation(Gtk.Orientation.VERTICAL)
ctx = self.get_style_context()
ctx.add_class("base-container")
def _setup_signals(self):
...
def _load_widgets(self):
glade_box = self._builder.get_object("glade_box")
button = Gtk.Button(label="Click Me!")
button.connect("clicked", self._hello_world)
self.add(button)
self.add(glade_box)
def _hello_world(self, widget=None, eve=None):
logger.debug("Hello, World!")
self.add(LeftContainer())
self.add(CenterContainer())
self.add(RightContainer())

View File

@ -0,0 +1,47 @@
# Python imports
# Lib imports
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
# Application imports
class CenterContainer(Gtk.Box):
def __init__(self):
super(CenterContainer, self).__init__()
self._builder = settings_manager.get_builder()
self._setup_styling()
self._setup_signals()
self._subscribe_to_events()
self._load_widgets()
def _setup_styling(self):
self.set_orientation(Gtk.Orientation.VERTICAL)
ctx = self.get_style_context()
ctx.add_class("center-container")
def _setup_signals(self):
...
def _subscribe_to_events(self):
# event_system.subscribe("handle_file_from_ipc", self.handle_file_from_ipc)
...
def _load_widgets(self):
glade_box = self._builder.get_object("glade_box")
button = Gtk.Button(label="Click Me!")
button.connect("clicked", self._hello_world)
self.add(button)
self.add(glade_box)
def _hello_world(self, widget=None, eve=None):
logger.debug("Hello, World!")

View File

@ -0,0 +1,35 @@
# Python imports
# Lib imports
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
# Application imports
class LeftContainer(Gtk.Box):
def __init__(self):
super(LeftContainer, self).__init__()
self._setup_styling()
self._setup_signals()
self._subscribe_to_events()
self._load_widgets()
def _setup_styling(self):
self.set_orientation(Gtk.Orientation.VERTICAL)
ctx = self.get_style_context()
ctx.add_class("left-container")
def _setup_signals(self):
...
def _subscribe_to_events(self):
# event_system.subscribe("handle_file_from_ipc", self.handle_file_from_ipc)
...
def _load_widgets(self):
...

View File

@ -0,0 +1,35 @@
# Python imports
# Lib imports
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
# Application imports
class RightContainer(Gtk.Box):
def __init__(self):
super(RightContainer, self).__init__()
self._setup_styling()
self._setup_signals()
self._subscribe_to_events()
self._load_widgets()
def _setup_styling(self):
self.set_orientation(Gtk.Orientation.VERTICAL)
ctx = self.get_style_context()
ctx.add_class("right-container")
def _setup_signals(self):
...
def _subscribe_to_events(self):
# event_system.subscribe("handle_file_from_ipc", self.handle_file_from_ipc)
...
def _load_widgets(self):
...

View File

@ -4,10 +4,7 @@ import os
# Lib imports
import gi
gi.require_version('Gtk', '3.0')
gi.require_version('Gdk', '3.0')
from gi.repository import Gtk
from gi.repository import Gdk
from gi.repository import GLib
# Application imports
from .mixins.signals_mixins import SignalsMixins
@ -60,13 +57,13 @@ class Controller(DummyMixin, SignalsMixins, ControllerData):
def setup_builder_and_container(self):
self.builder = Gtk.Builder()
self.builder.add_from_file(settings.get_glade_file())
self.builder.add_from_file(settings_manager.get_glade_file())
self.builder.expose_object("main_window", self.window)
settings.set_builder(self.builder)
settings_manager.set_builder(self.builder)
self.base_container = BaseContainer()
settings.register_signals_to_builder([self, self.base_container])
settings_manager.register_signals_to_builder([self, self.base_container])
def get_base_container(self):
return self.base_container

View File

@ -13,7 +13,7 @@ class ControllerData:
''' ControllerData contains most of the state of the app at ay given time. It also has some support methods. '''
def setup_controller_data(self) -> None:
self.window = settings.get_main_window()
self.window = settings_manager.get_main_window()
self.builder = None
self.base_container = None
self.was_midified_key = False

View File

@ -26,6 +26,7 @@ class Window(Gtk.ApplicationWindow):
def __init__(self, args, unknownargs):
super(Window, self).__init__()
settings_manager.set_main_window(self)
self._controller = None
@ -33,36 +34,29 @@ class Window(Gtk.ApplicationWindow):
self._setup_styling()
self._setup_signals()
self._subscribe_to_events()
settings.set_main_window(self)
self._load_widgets(args, unknownargs)
self.show()
# NOTE: Need to set size after show b/c get_allocation methods are initially incorrect if done beforehand...
self._set_size_constraints()
self.show()
def _setup_styling(self):
self.set_default_size(settings.get_main_window_width(),
settings.get_main_window_height())
self.set_title(f"{app_name}")
self.set_icon_from_file( settings.get_window_icon() )
self.set_icon_from_file( settings_manager.get_window_icon() )
self.set_gravity(5) # 5 = CENTER
self.set_position(1) # 1 = CENTER, 4 = CENTER_ALWAYS
def _setup_signals(self):
self.connect("delete-event", self._tear_down)
GLib.unix_signal_add(GLib.PRIORITY_DEFAULT, signal.SIGINT, self._tear_down)
self.connect("delete-event", self._tear_down)
def _subscribe_to_events(self):
event_system.subscribe("tear_down", self._tear_down)
def _load_widgets(self, args, unknownargs):
if settings.is_debug():
if settings_manager.is_debug():
self.set_interactive_debugging(True)
self._controller = Controller(args, unknownargs)
if not self._controller:
raise ControllerStartException("Controller exited and doesn't exist...")
@ -70,35 +64,50 @@ class Window(Gtk.ApplicationWindow):
self.add( self._controller.get_base_container() )
def _set_size_constraints(self):
self.set_default_size(settings.get_main_window_width(),
settings.get_main_window_height())
self.set_size_request(settings.get_main_window_min_width(),
settings.get_main_window_min_height())
_window_x = settings.config.main_window_x
_window_y = settings.config.main_window_y
_min_width = settings.config.main_window_min_width
_min_height = settings.config.main_window_min_height
_width = settings.config.main_window_width
_height = settings.config.main_window_height
self.move(_window_x, _window_y - 28)
self.set_size_request(_min_width, _min_height)
self.set_default_size(_width, _height)
def _set_window_data(self) -> None:
screen = self.get_screen()
visual = screen.get_rgba_visual()
if visual and screen.is_composited() and settings.make_transparent() == 0:
if visual and screen.is_composited() and settings.config.make_transparent == 0:
self.set_visual(visual)
self.set_app_paintable(True)
self.connect("draw", self._area_draw)
# bind css file
cssProvider = Gtk.CssProvider()
cssProvider.load_from_path( settings.get_css_file() )
cssProvider.load_from_path( settings_manager.get_css_file() )
screen = Gdk.Screen.get_default()
styleContext = Gtk.StyleContext()
styleContext.add_provider_for_screen(screen, cssProvider, Gtk.STYLE_PROVIDER_PRIORITY_USER)
def _area_draw(self, widget: Gtk.ApplicationWindow, cr: cairo.Context) -> None:
cr.set_source_rgba( *settings.get_paint_bg_color() )
cr.set_source_rgba( *settings_manager.get_paint_bg_color() )
cr.set_operator(cairo.OPERATOR_SOURCE)
cr.paint()
cr.set_operator(cairo.OPERATOR_OVER)
def _tear_down(self, widget=None, eve=None):
settings.clear_pid()
def _tear_down(self, widget = None, eve = None):
size = self.get_default_size()
pos = self.get_position()
settings_manager.set_main_window_width(size.width)
settings_manager.set_main_window_height(size.height)
settings_manager.set_main_window_x(pos.root_x)
settings_manager.set_main_window_y(pos.root_y)
settings_manager.save_settings()
settings_manager.clear_pid()
time.sleep(event_sleep_time)
Gtk.main_quit()

View File

@ -30,8 +30,8 @@ class PluginsController:
path = os.path.dirname(os.path.realpath(__file__))
sys.path.insert(0, path) # NOTE: I think I'm not using this correctly...
self._builder = settings.get_builder()
self._plugins_path = settings.get_plugins_path()
self._builder = settings_manager.get_builder()
self._plugins_path = settings_manager.get_plugins_path()
self._plugins_dir_watcher = None
self._plugin_collection = []

View File

@ -19,12 +19,29 @@ def debug_signal_handler(signal, frame):
rpdb2.setbreak(depth=1)
return
except StandardError:
pass
...
try:
from rfoo.utils import rconsole
logger.debug("\n\nStarting embedded rconsole debugger...\n\n")
rconsole.spawn_server()
return
except StandardError as ex:
...
try:
from pudb import set_trace
logger.debug("\n\nStarting PuDB debugger...\n\n")
set_trace(paused = True)
return
except StandardError as ex:
...
try:
import pdb
logger.debug("\n\nStarting embedded PDB debugger...\n\n")
pdb.Pdb(skip=['gi.*']).set_trace()
return
except StandardError as ex:
...

View File

@ -40,7 +40,7 @@ class IPCServer(Singleton):
def create_ipc_listener(self) -> None:
if self._conn_type == "socket":
if os.path.exists(self._ipc_address) and settings.is_dirty_start():
if os.path.exists(self._ipc_address) and settings_manager.is_dirty_start():
os.unlink(self._ipc_address)
listener = Listener(address=self._ipc_address, family="AF_UNIX", authkey=self._ipc_authkey)
@ -69,7 +69,7 @@ class IPCServer(Singleton):
def _handle_ipc_message(self, conn, start_time) -> None:
while True:
msg = conn.recv()
if settings.is_debug():
if settings_manager.is_debug():
print(msg)
if "FILE|" in msg:

View File

@ -1,4 +0,0 @@
"""
Settings module
"""
from .settings import Settings

View File

@ -0,0 +1,4 @@
"""
Settings module
"""
from .manager import SettingsManager

View File

@ -4,12 +4,15 @@ import io
import json
import inspect
import zipfile
from dataclasses import asdict
# Lib imports
# Application imports
from ..singleton import Singleton
from .start_check_mixin import StartCheckMixin
from .options.settings import Settings
class MissingConfigError(Exception):
@ -17,7 +20,7 @@ class MissingConfigError(Exception):
class Settings(StartCheckMixin, Singleton):
class SettingsManager(StartCheckMixin, Singleton):
def __init__(self):
self._SCRIPT_PTH = os.path.dirname(os.path.realpath(__file__))
self._USER_HOME = os.path.expanduser('~')
@ -105,12 +108,8 @@ class Settings(StartCheckMixin, Singleton):
print( f"Settings: {self._CONTEXT_MENU}\n\t\t{repr(e)}" )
self.settings: Settings = None
self._main_window = None
self._main_window_w = 800
self._main_window_h = 600
self._main_window_mw = 720
self._main_window_mh = 480
self._builder = None
self.PAINT_BG_COLOR = (0, 0, 0, 0.54)
@ -148,10 +147,6 @@ class Settings(StartCheckMixin, Singleton):
return monitors
def get_main_window(self) -> any: return self._main_window
def get_main_window_width(self) -> any: return self._main_window_w
def get_main_window_height(self) -> any: return self._main_window_h
def get_main_window_min_width(self) -> any: return self._main_window_mw
def get_main_window_min_height(self) -> any: return self._main_window_mh
def get_builder(self) -> any: return self._builder
def get_paint_bg_color(self) -> any: return self.PAINT_BG_COLOR
def get_glade_file(self) -> str: return self._GLADE_FILE
@ -164,25 +159,16 @@ class Settings(StartCheckMixin, Singleton):
def get_home_config_path(self) -> str: return self._HOME_CONFIG_PATH
def get_window_icon(self) -> str: return self._WINDOW_ICON
def get_home_path(self) -> str: return self._USER_HOME
def make_transparent(self) -> int: return self._config["make_transparent"]
# Filter returns
def get_office_filter(self) -> tuple: return tuple(self._settings["filters"]["office"])
def get_vids_filter(self) -> tuple: return tuple(self._settings["filters"]["videos"])
def get_text_filter(self) -> tuple: return tuple(self._settings["filters"]["text"])
def get_music_filter(self) -> tuple: return tuple(self._settings["filters"]["music"])
def get_images_filter(self) -> tuple: return tuple(self._settings["filters"]["images"])
def get_pdf_filter(self) -> tuple: return tuple(self._settings["filters"]["pdf"])
def get_success_color(self) -> str: return self._theming["success_color"]
def get_warning_color(self) -> str: return self._theming["warning_color"]
def get_error_color(self) -> str: return self._theming["error_color"]
def is_trace_debug(self) -> str: return self._trace_debug
def is_debug(self) -> str: return self._debug
def get_ch_log_lvl(self) -> str: return self._settings["debugging"]["ch_log_lvl"]
def get_fh_log_lvl(self) -> str: return self._settings["debugging"]["fh_log_lvl"]
def set_main_window_x(self, x = 0): self.settings.config.window_x = x
def set_main_window_y(self, y = 0): self.settings.config.window_y = y
def set_main_window_width(self, width = 800): self.settings.config.window_width = width
def set_main_window_height(self, height = 600): self.settings.config.window_height = height
def set_main_window_min_width(self, width = 720): self.settings.config.window_min_width = width
def set_main_window_min_height(self, height = 480): self.settings.config.window_min_height = height
def set_trace_debug(self, trace_debug):
self._trace_debug = trace_debug
@ -192,11 +178,10 @@ class Settings(StartCheckMixin, Singleton):
def load_settings(self):
with open(self._CONFIG_FILE) as f:
self._settings = json.load(f)
self._config = self._settings["config"]
self._theming = self._settings["theming"]
with open(self._CONFIG_FILE) as file:
data = json.load(file)
self.settings = Settings(**data)
def save_settings(self):
with open(self._CONFIG_FILE, 'w') as outfile:
json.dump(self._settings, outfile, separators=(',', ':'), indent=4)
json.dump(asdict(self.settings), outfile, separators=(',', ':'), indent=4)

View File

@ -0,0 +1,8 @@
"""
Options module
"""
from .settings import Settings
from .config import Config
from .filters import Filters
from .theming import Theming
from .debugging import Debugging

View File

@ -0,0 +1,35 @@
# Python imports
from dataclasses import dataclass
# Lib imports
# Application imports
@dataclass
class Config:
base_of_home: str
hide_hidden_files: str
thumbnailer_path: str
blender_thumbnailer_path: str
go_past_home: str
lock_folder: str
locked_folders: []
mplayer_options: str
music_app: str
media_app: str
image_app: str
office_app: str
pdf_app: str
code_app: str
text_app: str
file_manager_app: str
terminal_app: str
remux_folder_max_disk_usage: str
make_transparent: int
main_window_x: int
main_window_y: int
main_window_min_width: int
main_window_min_height: int
main_window_width: int
main_window_height: int

View File

@ -0,0 +1,12 @@
# Python imports
from dataclasses import dataclass
# Lib imports
# Application imports
@dataclass
class Debugging:
ch_log_lvl: int
fh_log_lvl: int

View File

@ -0,0 +1,18 @@
# Python imports
from dataclasses import dataclass
# Lib imports
# Application imports
@dataclass
class Filters:
meshs: []
code: []
videos: []
office: []
images: []
text: []
music: []
pdf: []

View File

@ -0,0 +1,24 @@
# Python imports
from dataclasses import dataclass
# Gtk imports
# Application imports
from .config import Config
from .filters import Filters
from .theming import Theming
from .debugging import Debugging
@dataclass
class Settings:
config: Config
filters: Filters
theming: Theming
debugging: Debugging
def __post_init__(self):
self.config = Config(**self.config)
self.filters = Filters(**self.filters)
self.theming = Theming(**self.theming)
self.debugging = Debugging(**self.debugging)

View File

@ -0,0 +1,13 @@
# Python imports
from dataclasses import dataclass
# Lib imports
# Application imports
@dataclass
class Theming:
success_color: str
warning_color: str
error_color: str

View File

@ -41,6 +41,7 @@ class StartCheckMixin:
def _write_new_pid(self):
pid = os.getpid()
self._write_pid(pid)
print(f"{app_name} PID: {pid}")
def _clean_pid(self):
os.unlink(self._PID_FILE)

View File

@ -1,41 +1,123 @@
{
"config": {
"base_of_home": "",
"hide_hidden_files": "true",
"thumbnailer_path": "ffmpegthumbnailer",
"go_past_home": "true",
"lock_folder": "false",
"locked_folders": "venv::::flasks",
"mplayer_options": "-quiet -really-quiet -xy 1600 -geometry 50%:50%",
"music_app": "/opt/deadbeef/bin/deadbeef",
"media_app": "mpv",
"image_app": "mirage",
"office_app": "libreoffice",
"pdf_app": "evince",
"text_app": "leafpad",
"file_manager_app": "solarfm",
"terminal_app": "terminator",
"remux_folder_max_disk_usage": "8589934592",
"make_transparent": 0
"config":{
"base_of_home":"",
"hide_hidden_files":"true",
"thumbnailer_path":"ffmpegthumbnailer",
"blender_thumbnailer_path":"",
"go_past_home":"true",
"lock_folder":"false",
"locked_folders":[
"venv",
"flasks"
],
"mplayer_options":"-quiet -really-quiet -xy 1600 -geometry 50%:50%",
"music_app":"/opt/deadbeef/bin/deadbeef",
"media_app":"mpv",
"image_app":"mirage",
"office_app":"libreoffice",
"pdf_app":"evince",
"code_app":"atom",
"text_app":"leafpad",
"file_manager_app":"solarfm",
"terminal_app":"terminator",
"remux_folder_max_disk_usage":"8589934592",
"make_transparent":0,
"main_window_x":721,
"main_window_y":465,
"main_window_min_width":720,
"main_window_min_height":480,
"main_window_width":800,
"main_window_height":600
},
"filters": {
"meshs": [".blend", ".dae", ".fbx", ".gltf", ".obj", ".stl"],
"code": [".cpp", ".css", ".c", ".go", ".html", ".htm", ".java", ".js", ".json", ".lua", ".md", ".py", ".rs", ".toml", ".xml", ".pom"],
"videos": [".mkv", ".mp4", ".webm", ".avi", ".mov", ".m4v", ".mpg", ".mpeg", ".wmv", ".flv"],
"office": [".doc", ".docx", ".xls", ".xlsx", ".xlt", ".xltx", ".xlm", ".ppt", ".pptx", ".pps", ".ppsx", ".odt", ".rtf"],
"images": [".png", ".jpg", ".jpeg", ".gif", ".ico", ".tga", ".webp"],
"text": [".txt", ".text", ".sh", ".cfg", ".conf", ".log"],
"music": [".psf", ".mp3", ".ogg", ".flac", ".m4a"],
"pdf": [".pdf"]
"filters":{
"meshs":[
".blend",
".dae",
".fbx",
".gltf",
".obj",
".stl"
],
"code":[
".cpp",
".css",
".c",
".go",
".html",
".htm",
".java",
".js",
".json",
".lua",
".md",
".py",
".rs",
".toml",
".xml",
".pom"
],
"videos":[
".mkv",
".mp4",
".webm",
".avi",
".mov",
".m4v",
".mpg",
".mpeg",
".wmv",
".flv"
],
"office":[
".doc",
".docx",
".xls",
".xlsx",
".xlt",
".xltx",
".xlm",
".ppt",
".pptx",
".pps",
".ppsx",
".odt",
".rtf"
],
"images":[
".png",
".jpg",
".jpeg",
".gif",
".ico",
".tga",
".webp"
],
"text":[
".txt",
".text",
".sh",
".cfg",
".conf",
".log"
],
"music":[
".psf",
".mp3",
".ogg",
".flac",
".m4a"
],
"pdf":[
".pdf"
]
},
"theming":{
"success_color":"#88cc27",
"warning_color":"#ffa800",
"error_color":"#ff0000"
},
"debugging": {
"ch_log_lvl": 10,
"fh_log_lvl": 20
"debugging":{
"ch_log_lvl":10,
"fh_log_lvl":20
}
}

View File

@ -1,69 +1,17 @@
/* Set fm to have transparent window */
box,
iconview,
notebook,
paned,
stack,
scrolledwindow,
treeview.view,
.content-view,
.view {
background: rgba(19, 21, 25, 0.14);
* {
/* background: rgba(0, 0, 0, 0.14); */
color: rgba(255, 255, 255, 1);
border: 2px solid rgba(0, 0, 0, 0.0);
}
notebook > header > tabs > tab:checked {
/* Neon Blue 00e8ff */
background-color: rgba(0, 232, 255, 0.2);
/* Dark Bergundy */
/* background-color: rgba(116, 0, 0, 0.25); */
color: rgba(255, 255, 255, 0.8);
}
#message_view {
font: 16px "Monospace";
}
.view:selected,
.view:selected:hover {
box-shadow: inset 0 0 0 9999px rgba(21, 158, 167, 0.34);
color: rgba(255, 255, 255, 0.5);
}
.alert-border {
border: 2px solid rgba(116, 0, 0, 0.64);
}
.search-border {
border: 2px solid rgba(136, 204, 39, 1);
}
.notebook-selected-focus {
/* Neon Blue 00e8ff border */
border: 2px solid rgba(0, 232, 255, 0.34);
/* Dark Bergundy */
/* border: 2px solid rgba(116, 0, 0, 0.64); */
}
.notebook-unselected-focus {
/* Neon Blue 00e8ff border */
/* border: 2px solid rgba(0, 232, 255, 0.25); */
/* Dark Bergundy */
/* border: 2px solid rgba(116, 0, 0, 0.64); */
/* Snow White */
border: 2px solid rgba(255, 255, 255, 0.24);
.base-container {
margin: 10px;
}
/* * {
background: rgba(0, 0, 0, 0.14);
color: rgba(255, 255, 255, 1);
} */
/* * selection {
background-color: rgba(116, 0, 0, 0.65);
color: rgba(255, 255, 255, 0.5);