Python-With-Gtk-Template/src/app.py

60 lines
1.8 KiB
Python
Raw Normal View History

2022-02-25 23:53:58 +00:00
# Python imports
import os, inspect, time
# Lib imports
# Application imports
2022-09-05 23:01:39 +00:00
from __builtins__ import *
from utils.ipc_server import IPCServer
2022-02-25 23:53:58 +00:00
from utils.settings import Settings
from context.controller import Controller
2022-09-05 23:01:39 +00:00
class App_Launch_Exception(Exception):
...
2022-02-25 23:53:58 +00:00
2022-09-05 23:01:39 +00:00
class Controller_Start_Exceptio(Exception):
...
2022-02-25 23:53:58 +00:00
2022-09-05 23:01:39 +00:00
class Application(IPCServer):
2022-02-25 23:53:58 +00:00
''' Create Settings and Controller classes. Bind signal to Builder. Inherit from Builtins to bind global methods and classes.'''
def __init__(self, args, unknownargs):
2022-09-05 23:01:39 +00:00
super(Application, self).__init__()
2022-02-25 23:53:58 +00:00
if not trace_debug:
2022-09-05 23:01:39 +00:00
self.create_ipc_listener()
time.sleep(0.05)
if not self.is_ipc_alive:
2022-02-25 23:53:58 +00:00
if unknownargs:
for arg in unknownargs:
if os.path.isdir(arg):
message = f"FILE|{arg}"
2022-09-05 23:01:39 +00:00
self.send_ipc_message(message)
2022-02-25 23:53:58 +00:00
2022-09-05 23:01:39 +00:00
raise App_Launch_Exception(f"IPC Server Exists: Will send path(s) to it and close...\nNote: If no fm exists, remove /tmp/{app_name}-ipc.sock")
2022-02-25 23:53:58 +00:00
settings = Settings()
settings.create_window()
controller = Controller(settings, args, unknownargs)
if not controller:
2022-09-05 23:01:39 +00:00
raise Controller_Start_Exceptio("Controller exited and doesn't exist...")
2022-02-25 23:53:58 +00:00
# Gets the methods from the classes and sets to handler.
# Then, builder from settings will connect to any signals it needs.
classes = [controller]
handlers = {}
for c in classes:
methods = None
try:
methods = inspect.getmembers(c, predicate=inspect.ismethod)
handlers.update(methods)
except Exception as e:
print(repr(e))
settings.get_builder().connect_signals(handlers)