Compare commits
2 Commits
develop
...
d6de2a8a4a
| Author | SHA1 | Date | |
|---|---|---|---|
| d6de2a8a4a | |||
| e382f73371 |
@@ -25,6 +25,7 @@ def limit_memory(maxsize):
|
||||
|
||||
def main(args, unknownargs):
|
||||
setproctitle(f'{app_name}')
|
||||
# limit_memory(248 * (1024 * 1024 * 42))
|
||||
|
||||
if args.debug == "true":
|
||||
settings_manager.set_debug(True)
|
||||
@@ -33,9 +34,7 @@ def main(args, unknownargs):
|
||||
settings_manager.set_trace_debug(True)
|
||||
|
||||
settings_manager.do_dirty_start_check()
|
||||
|
||||
app = Application()
|
||||
app.run()
|
||||
Application(args, unknownargs)
|
||||
|
||||
|
||||
|
||||
@@ -53,7 +52,6 @@ if __name__ == "__main__":
|
||||
|
||||
# Read arguments (If any...)
|
||||
args, unknownargs = parser.parse_known_args()
|
||||
settings_manager.set_starting_args( args, unknownargs )
|
||||
|
||||
try:
|
||||
faulthandler.enable() # For better debug info
|
||||
|
||||
@@ -19,48 +19,40 @@ class AppLaunchException(Exception):
|
||||
class Application:
|
||||
""" docstring for Application. """
|
||||
|
||||
def __init__(self):
|
||||
def __init__(self, args, unknownargs):
|
||||
super(Application, self).__init__()
|
||||
|
||||
self.setup_debug_hook()
|
||||
|
||||
|
||||
def run(self):
|
||||
if not settings_manager.is_trace_debug():
|
||||
if not self.load_ipc():
|
||||
return
|
||||
self.load_ipc(args, unknownargs)
|
||||
|
||||
win = Window()
|
||||
win.start()
|
||||
self.setup_debug_hook()
|
||||
Window(args, unknownargs).main()
|
||||
|
||||
def load_ipc(self):
|
||||
args, \
|
||||
unknownargs = settings_manager.get_starting_args()
|
||||
|
||||
def load_ipc(self, args, unknownargs):
|
||||
ipc_server = IPCServer()
|
||||
|
||||
self.ipc_realization_check(ipc_server)
|
||||
if ipc_server.is_ipc_alive:
|
||||
return True
|
||||
|
||||
logger.warning(f"{app_name} IPC Server Exists: Have sent path(s) to it and closing...")
|
||||
if not ipc_server.is_ipc_alive:
|
||||
for arg in unknownargs + [args.new_tab,]:
|
||||
if os.path.isfile(arg):
|
||||
message = f"FILE|{arg}"
|
||||
ipc_server.send_ipc_message(message)
|
||||
|
||||
if os.path.isdir(arg):
|
||||
message = f"DIR|{arg}"
|
||||
ipc_server.send_ipc_message(message)
|
||||
|
||||
return False
|
||||
|
||||
raise AppLaunchException(f"{app_name} IPC Server Exists: Have sent path(s) to it and closing...")
|
||||
|
||||
def ipc_realization_check(self, ipc_server):
|
||||
try:
|
||||
ipc_server.create_ipc_listener()
|
||||
except Exception as e:
|
||||
print(e)
|
||||
ipc_server.send_test_ipc_message()
|
||||
|
||||
try:
|
||||
ipc_server.create_ipc_listener()
|
||||
except Exception as e:
|
||||
...
|
||||
|
||||
def setup_debug_hook(self):
|
||||
try:
|
||||
# kill -SIGUSR2 <pid> from Linux/Unix or SIGBREAK signal from Windows
|
||||
|
||||
@@ -36,14 +36,26 @@ from .ui_mixin import UIMixin
|
||||
class Controller(UIMixin, SignalsMixins, Controller_Data):
|
||||
""" Controller coordinates the mixins and is somewhat the root hub of it all. """
|
||||
|
||||
def __init__(self):
|
||||
def __init__(self, args, unknownargs):
|
||||
self._setup_controller_data()
|
||||
|
||||
self._setup_styling()
|
||||
self._setup_signals()
|
||||
self._subscribe_to_events()
|
||||
self._load_widgets()
|
||||
self._load_plugins_and_files()
|
||||
|
||||
if args.no_plugins == "false":
|
||||
self.plugins_controller.pre_launch_plugins()
|
||||
|
||||
self._generate_file_views(self.fm_controller_data)
|
||||
|
||||
if args.no_plugins == "false":
|
||||
self.plugins_controller.post_launch_plugins()
|
||||
|
||||
for arg in unknownargs + [args.new_tab,]:
|
||||
if os.path.isdir(arg):
|
||||
message = f"FILE|{arg}"
|
||||
event_system.emit("post_file_to_ipc", message)
|
||||
|
||||
|
||||
def _setup_styling(self):
|
||||
@@ -57,7 +69,7 @@ class Controller(UIMixin, SignalsMixins, Controller_Data):
|
||||
|
||||
def _subscribe_to_events(self):
|
||||
event_system.subscribe("shutting_down", self._shutting_down)
|
||||
event_system.subscribe("handle_dir_from_ipc", self.handle_dir_from_ipc)
|
||||
event_system.subscribe("handle_file_from_ipc", self.handle_file_from_ipc)
|
||||
event_system.subscribe("generate_file_views", self._generate_file_views)
|
||||
event_system.subscribe("clear_notebooks", self.clear_notebooks)
|
||||
|
||||
@@ -101,22 +113,6 @@ class Controller(UIMixin, SignalsMixins, Controller_Data):
|
||||
FileExistsWidget()
|
||||
SaveLoadWidget()
|
||||
|
||||
def _load_plugins_and_files(self):
|
||||
args, unknownargs = settings_manager.get_starting_args()
|
||||
|
||||
if args.no_plugins == "false":
|
||||
self.plugins_controller.pre_launch_plugins()
|
||||
|
||||
self._generate_file_views(self.fm_controller_data)
|
||||
|
||||
if args.no_plugins == "false":
|
||||
self.plugins_controller.post_launch_plugins()
|
||||
|
||||
for arg in unknownargs + [args.new_tab,]:
|
||||
if os.path.isdir(arg):
|
||||
message = f"FILE|{arg}"
|
||||
event_system.emit("post_file_to_ipc", message)
|
||||
|
||||
def _shutting_down(self):
|
||||
if not settings_manager.is_trace_debug():
|
||||
self.fm_controller.save_state()
|
||||
|
||||
@@ -47,26 +47,13 @@ class FileActionSignalsMixin:
|
||||
if tab_widget_id in self.soft_update_lock:
|
||||
timeout_id = self.soft_update_lock[tab_widget_id]["timeout_id"]
|
||||
GLib.source_remove(timeout_id)
|
||||
self.soft_update_lock[tab_widget_id]["call_count"] += 1
|
||||
else:
|
||||
self.soft_update_lock[tab_widget_id] = {}
|
||||
self.soft_update_lock[tab_widget_id]["call_count"] = 0
|
||||
|
||||
timeout_id = GLib.timeout_add(
|
||||
500 if self.soft_update_lock[tab_widget_id]["call_count"] <= 5 else 1000,
|
||||
self.update_on_soft_lock_end,
|
||||
tab_widget_id
|
||||
)
|
||||
|
||||
self.soft_update_lock[tab_widget_id]["timeout_id"] = timeout_id
|
||||
timeout_id = GLib.timeout_add(0, self.update_on_soft_lock_end, 600, *(tab_widget_id,))
|
||||
|
||||
|
||||
def update_on_soft_lock_end(self, tab_widget_id):
|
||||
GLib.idle_add(self._update_interface, tab_widget_id)
|
||||
def update_on_soft_lock_end(self, timout_ms, tab_widget_id):
|
||||
self.soft_update_lock.pop(tab_widget_id, None)
|
||||
return False
|
||||
|
||||
def _update_interface(self, tab_widget_id):
|
||||
wid, tid = tab_widget_id.split("|")
|
||||
notebook = self.builder.get_object(f"window_{wid}")
|
||||
tab = self.get_fm_window(wid).get_tab_by_id(tid)
|
||||
@@ -83,6 +70,8 @@ class FileActionSignalsMixin:
|
||||
if [wid, tid] in [state.wid, state.tid]:
|
||||
self.set_bottom_labels(tab)
|
||||
|
||||
return False
|
||||
|
||||
def do_file_search(self, widget, eve = None):
|
||||
if not self.ctrl_down and not self.shift_down and not self.alt_down:
|
||||
target = widget.get_name()
|
||||
|
||||
@@ -13,7 +13,7 @@ class IPCSignalsMixin:
|
||||
def print_to_console(self, message=None):
|
||||
print(message)
|
||||
|
||||
def handle_dir_from_ipc(self, path):
|
||||
def handle_file_from_ipc(self, path):
|
||||
window = self.builder.get_object("main_window")
|
||||
window.deiconify()
|
||||
window.show()
|
||||
|
||||
@@ -22,8 +22,9 @@ class ControllerStartException(Exception):
|
||||
class Window(Gtk.ApplicationWindow):
|
||||
"""docstring for Window."""
|
||||
|
||||
def __init__(self):
|
||||
def __init__(self, args, unknownargs):
|
||||
Gtk.ApplicationWindow.__init__(self)
|
||||
# super(Window, self).__init__()
|
||||
|
||||
settings_manager.set_main_window(self)
|
||||
|
||||
@@ -32,7 +33,7 @@ class Window(Gtk.ApplicationWindow):
|
||||
self._setup_styling()
|
||||
self._setup_signals()
|
||||
self._subscribe_to_events()
|
||||
self._load_widgets()
|
||||
self._load_widgets(args, unknownargs)
|
||||
|
||||
self._set_window_data()
|
||||
self._set_size_constraints()
|
||||
@@ -55,11 +56,11 @@ class Window(Gtk.ApplicationWindow):
|
||||
event_system.subscribe("tear_down", self._tear_down)
|
||||
event_system.subscribe("load_interactive_debug", self._load_interactive_debug)
|
||||
|
||||
def _load_widgets(self):
|
||||
def _load_widgets(self, args, unknownargs):
|
||||
if settings_manager.is_debug():
|
||||
self.set_interactive_debugging(True)
|
||||
|
||||
self._controller = Controller()
|
||||
self._controller = Controller(args, unknownargs)
|
||||
|
||||
if not self._controller:
|
||||
raise ControllerStartException("Controller exited and doesn't exist...")
|
||||
@@ -119,5 +120,5 @@ class Window(Gtk.ApplicationWindow):
|
||||
settings_manager.clear_pid()
|
||||
Gtk.main_quit()
|
||||
|
||||
def start(self):
|
||||
def main(self):
|
||||
Gtk.main()
|
||||
@@ -1,15 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# . CONFIG.sh
|
||||
|
||||
# set -o xtrace ## To debug scripts
|
||||
# set -o errexit ## To exit on error
|
||||
# set -o errunset ## To exit if a variable is referenced but not set
|
||||
|
||||
function main() {
|
||||
cd "$(dirname "")"
|
||||
echo "Working Dir: " $(pwd)
|
||||
|
||||
python3 setup.py build && python3 setup.py install --user
|
||||
}
|
||||
main "$@";
|
||||
@@ -1,59 +0,0 @@
|
||||
#include <Python.h>
|
||||
#include <gtk.h>
|
||||
#include <cairo.h>
|
||||
#include <gdk-pixbuf/gdk-pixbuf.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
// static PyObject* free_pixbuf(PyObject* self, PyObject* args) {
|
||||
static void free_pixbuf(PyObject* self, PyObject* args) {
|
||||
PyObject *py_pixbuf;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "O", &py_pixbuf)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
GdkPixbuf *pixbuf = (GdkPixbuf *) PyLong_AsVoidPtr(py_pixbuf);
|
||||
if (!GDK_IS_PIXBUF(pixbuf)) {
|
||||
PyErr_SetString(PyExc_TypeError, "Invalid GdkPixbuf pointer.");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
g_free(pixbuf);
|
||||
// return PyBytes_FromStringAndSize((const char *) cairo_data, buffer_size);
|
||||
}
|
||||
|
||||
|
||||
static void free_list_store(PyObject* self, PyObject* args) {
|
||||
PyObject *py_list_store;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "O", &py_list_store)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
GtkListStore *list_store = (GtkListStore *) PyLong_AsVoidPtr(py_list_store);
|
||||
if (!GTK_IS_LIST_STORE(list_store)) {
|
||||
PyErr_SetString(PyExc_TypeError, "Invalid Gtk.ListStore pointer.");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
g_object_unref(list_store);
|
||||
}
|
||||
|
||||
|
||||
static PyMethodDef Methods[] = {
|
||||
{"free_pixbuf", free_pixbuf, METH_VARARGS, "Clear GdkPixbuf* ."},
|
||||
{"free_list_store", free_list_store, METH_VARARGS, "Clear GtkListStore* ."},
|
||||
{NULL, NULL, 0, NULL}
|
||||
};
|
||||
|
||||
static struct PyModuleDef moduledef = {
|
||||
PyModuleDef_HEAD_INIT,
|
||||
"gtkmemreaper",
|
||||
NULL,
|
||||
-1,
|
||||
Methods
|
||||
};
|
||||
|
||||
PyMODINIT_FUNC PyInit_gtkmemreaper(void) {
|
||||
return PyModule_Create(&moduledef);
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
# Python imports
|
||||
from setuptools import setup, Extension
|
||||
from subprocess import check_output
|
||||
|
||||
# Lib imports
|
||||
|
||||
# Application imports
|
||||
|
||||
|
||||
|
||||
pkg_config_args = ["gdk-pixbuf-2.0", "cairo", "gtk"]
|
||||
|
||||
def get_pkgconfig_flags(flag_type):
|
||||
return check_output(["pkg-config", flag_type] + pkg_config_args).decode().split()
|
||||
|
||||
ext = Extension(
|
||||
"gtkmemreaper",
|
||||
sources = ["gtkmemreaper.c"],
|
||||
include_dirs = [],
|
||||
extra_compile_args = get_pkgconfig_flags("--cflags"),
|
||||
extra_link_args = get_pkgconfig_flags("--libs")
|
||||
)
|
||||
|
||||
setup(
|
||||
name = "gtkmemreaper",
|
||||
version = "0.1",
|
||||
ext_modules = [ext]
|
||||
)
|
||||
@@ -5,6 +5,7 @@ from multiprocessing.connection import Client
|
||||
from multiprocessing.connection import Listener
|
||||
|
||||
# Lib imports
|
||||
from gi.repository import GLib
|
||||
|
||||
# Application imports
|
||||
from .singleton import Singleton
|
||||
@@ -13,7 +14,7 @@ from .singleton import Singleton
|
||||
|
||||
class IPCServer(Singleton):
|
||||
""" Create a listener so that other SolarFM instances send requests back to existing instance. """
|
||||
def __init__(self, ipc_address: str = '127.0.0.1', conn_type: str = "socket"):
|
||||
def __init__(self, ipc_address: str = '127.0.0.1', conn_type: str = "local_network_unsecured"):
|
||||
self.is_ipc_alive = False
|
||||
self._ipc_port = 0 # Use 0 to let Listener chose port
|
||||
self._ipc_address = ipc_address
|
||||
@@ -42,29 +43,30 @@ class IPCServer(Singleton):
|
||||
if os.path.exists(self._ipc_address) and settings_manager.is_dirty_start():
|
||||
os.unlink(self._ipc_address)
|
||||
|
||||
listener = Listener(self._ipc_address, family = "AF_UNIX", authkey = self._ipc_authkey)
|
||||
listener = Listener(address = self._ipc_address, family = "AF_UNIX", authkey = self._ipc_authkey)
|
||||
|
||||
elif "unsecured" not in self._conn_type:
|
||||
listener = Listener((self._ipc_address, self._ipc_port), authkey = self._ipc_authkey)
|
||||
else:
|
||||
listener = Listener((self._ipc_address, self._ipc_port))
|
||||
|
||||
self.is_ipc_alive = True
|
||||
self._run_ipc_loop(listener)
|
||||
# self._run_ipc_loop(listener)
|
||||
GLib.Thread("", self._run_ipc_loop, listener)
|
||||
|
||||
@daemon_threaded
|
||||
# @daemon_threaded
|
||||
def _run_ipc_loop(self, listener) -> None:
|
||||
while True:
|
||||
try:
|
||||
conn = listener.accept()
|
||||
start_time = time.perf_counter()
|
||||
|
||||
self._handle_ipc_message(conn, start_time)
|
||||
except EOFError as e:
|
||||
logger.debug( repr(e) )
|
||||
GLib.idle_add(self._handle_ipc_message, *(conn, start_time,))
|
||||
|
||||
conn = None
|
||||
start_time = None
|
||||
except Exception as e:
|
||||
logger.debug( repr(e) )
|
||||
finally:
|
||||
conn.close()
|
||||
|
||||
listener.close()
|
||||
|
||||
@@ -78,28 +80,27 @@ class IPCServer(Singleton):
|
||||
if file:
|
||||
event_system.emit_and_await("handle_file_from_ipc", file)
|
||||
|
||||
conn.close()
|
||||
break
|
||||
|
||||
if "DIR|" in msg:
|
||||
file = msg.split("DIR|")[1].strip()
|
||||
if file:
|
||||
event_system.emit_and_await("handle_dir_from_ipc", file)
|
||||
|
||||
msg = None
|
||||
file = None
|
||||
conn.close()
|
||||
break
|
||||
|
||||
|
||||
if msg in ['close connection', 'close server', 'Empty Data...']:
|
||||
if msg in ['close connection', 'close server']:
|
||||
msg = None
|
||||
conn.close()
|
||||
break
|
||||
|
||||
# NOTE: Not perfect but insures we don't lock up the connection for too long.
|
||||
end_time = time.perf_counter()
|
||||
if (end_time - start_time) > self._ipc_timeout:
|
||||
msg = None
|
||||
end_time = None
|
||||
conn.close()
|
||||
break
|
||||
|
||||
return False
|
||||
|
||||
|
||||
def send_ipc_message(self, message: str = "Empty Data...") -> None:
|
||||
try:
|
||||
|
||||
@@ -97,8 +97,7 @@ class SettingsManager(StartCheckMixin, Singleton):
|
||||
self._trace_debug = False
|
||||
self._debug = False
|
||||
self._dirty_start = False
|
||||
self._passed_in_file: bool = False
|
||||
self._starting_files: list = []
|
||||
|
||||
|
||||
def register_signals_to_builder(self, classes=None, builder=None):
|
||||
handlers = {}
|
||||
@@ -144,12 +143,6 @@ class SettingsManager(StartCheckMixin, Singleton):
|
||||
def get_trash_info_path(self) -> str: return self._TRASH_INFO_PATH
|
||||
def get_plugins_path(self) -> str: return self._PLUGINS_PATH
|
||||
|
||||
def get_starting_args(self):
|
||||
return self.args, self.unknownargs
|
||||
|
||||
def set_is_starting_with_file(self, is_passed_in_file: bool = False):
|
||||
self._passed_in_file = is_passed_in_file
|
||||
|
||||
def is_trace_debug(self) -> bool: return self._trace_debug
|
||||
def is_debug(self) -> bool: return self._debug
|
||||
|
||||
@@ -160,10 +153,6 @@ class SettingsManager(StartCheckMixin, Singleton):
|
||||
def set_main_window_min_width(self, width = 720): self.settings.config.main_window_min_width = width
|
||||
def set_main_window_min_height(self, height = 480): self.settings.config.main_window_min_height = height
|
||||
|
||||
def set_starting_args(self, args, unknownargs):
|
||||
self.args = args
|
||||
self.unknownargs = unknownargs
|
||||
|
||||
def set_trace_debug(self, trace_debug: bool):
|
||||
self._trace_debug = trace_debug
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ class StartCheckMixin:
|
||||
pid = f.readline().strip()
|
||||
if pid not in ("", None):
|
||||
if self.is_pid_alive( int(pid) ):
|
||||
print("PID file exists and PID is alive...")
|
||||
print("PID file exists and PID is alive... Letting downstream errors (sans debug args) handle app closure propigation.")
|
||||
return
|
||||
|
||||
self._write_new_pid()
|
||||
|
||||
Reference in New Issue
Block a user