added debug signal caller, updated some prints to logger, added settings option for min win size

This commit is contained in:
itdominator 2023-04-29 09:27:21 -05:00
parent 72b70d28b5
commit f54e767f62
8 changed files with 66 additions and 21 deletions

View File

@ -1,4 +1,5 @@
# Python imports
import signal
import os
# Lib imports
@ -8,16 +9,40 @@ from utils.ipc_server import IPCServer
from core.window import Window
# Break into a Python console upon SIGUSR1 (Linux) or SIGBREAK (Windows:
# CTRL+Pause/Break). To be included in all production code, just in case.
def debug_signal_handler(signal, frame):
del signal
del frame
try:
import rpdb2
logger.debug("\n\nStarting embedded RPDB2 debugger. Password is 'foobar'\n\n")
rpdb2.start_embedded_debugger("foobar", True, True)
rpdb2.setbreak(depth=1)
return
except StandardError:
pass
try:
import code
code.interact()
except StandardError as ex:
logger.debug(f"{ex}, returning to normal program flow...")
class AppLaunchException(Exception):
...
class Application(IPCServer):
""" docstring for Application. """
def __init__(self, args, unknownargs):
super(Application, self).__init__()
if not settings.is_trace_debug():
try:
self.create_ipc_listener()
@ -32,4 +57,13 @@ class Application(IPCServer):
raise AppLaunchException(f"{app_name} IPC Server Exists: Will send path(s) to it and close...")
try:
signal.signal(
vars(signal).get("SIGBREAK") or vars(signal).get("SIGUSR1"),
debug_signal_handler
)
except ValueError:
# Typically: ValueError: signal only works in main thread
...
Window(args, unknownargs)

View File

@ -9,7 +9,6 @@ from gi.repository import Gtk
class BaseContainer(Gtk.Box):
def __init__(self):
super(BaseContainer, self).__init__()
@ -41,4 +40,4 @@ class BaseContainer(Gtk.Box):
def _hello_world(self, widget=None, eve=None):
print("Hello, World!")
logger.debug("Hello, World!")

View File

@ -56,7 +56,7 @@ class Controller(DummyMixin, SignalsMixins, ControllerData):
event_system.subscribe("tggl_top_main_menubar", self._tggl_top_main_menubar)
def _tggl_top_main_menubar(self):
print("_tggl_top_main_menubar > stub...")
logger.debug("_tggl_top_main_menubar > stub...")
def setup_builder_and_container(self):
self.builder = Gtk.Builder()

View File

@ -6,9 +6,8 @@
class DummyMixin:
""" DummyMixin is an example of how mixins are used and structured in a project. """
def print_hello_world(self) -> None:
print("Hello, World!")
logger.debug("Hello, World!")

View File

@ -11,10 +11,10 @@ class IPCSignalsMixin:
""" IPCSignalsMixin handle messages from another starting solarfm process. """
def print_to_console(self, message=None):
print(message)
logger.debug(message)
def handle_file_from_ipc(self, path: str) -> None:
print(f"File From IPC: {path}")
logger.debug(f"File From IPC: {path}")
def handle_dir_from_ipc(self, path: str) -> None:
print(f"Dir From IPC: {path}")
logger.debug(f"Dir From IPC: {path}")

View File

@ -39,6 +39,9 @@ class Window(Gtk.ApplicationWindow):
self.show()
# NOTE: Need to set size after show b/c get_allocation methods are initially incorrect if done beforehand...
self._set_size_constraints()
def _setup_styling(self):
self.set_default_size(settings.get_main_window_width(),
@ -66,6 +69,12 @@ 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())
def _set_window_data(self) -> None:
screen = self.get_screen()
visual = screen.get_rgba_visual()

View File

@ -53,7 +53,7 @@ class PluginsController:
self.reload_plugins(file)
def load_plugins(self, file: str = None) -> None:
print(f"Loading plugins...")
logger.debug(f"Loading plugins...")
parent_path = os.getcwd()
for path, folder in [[join(self._plugins_path, item), item] if os.path.isdir(join(self._plugins_path, item)) else None for item in os.listdir(self._plugins_path)]:
@ -68,8 +68,7 @@ class PluginsController:
module = self.load_plugin_module(path, folder, target)
self.execute_plugin(module, plugin, loading_data)
except Exception as e:
print(f"Malformed Plugin: Not loading -->: '{folder}' !")
traceback.print_exc()
logger.debug(f"Malformed Plugin: Not loading -->: '{folder}' !\n{traceback.print_exc()}")
os.chdir(parent_path)
@ -116,4 +115,4 @@ class PluginsController:
self._plugin_collection.append(plugin)
def reload_plugins(self, file: str = None) -> None:
print(f"Reloading plugins... stub.")
logger.debug(f"Reloading plugins... stub.")

View File

@ -105,15 +105,18 @@ class Settings(StartCheckMixin, Singleton):
print( f"Settings: {self._CONTEXT_MENU}\n\t\t{repr(e)}" )
self._main_window = None
self._main_window_w = 800
self._main_window_h = 600
self._builder = None
self.PAINT_BG_COLOR = (0, 0, 0, 0.54)
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._trace_debug = False
self._debug = False
self._dirty_start = False
self._builder = None
self.PAINT_BG_COLOR = (0, 0, 0, 0.54)
self._trace_debug = False
self._debug = False
self._dirty_start = False
self.load_settings()
@ -147,6 +150,8 @@ class Settings(StartCheckMixin, Singleton):
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