Merge Stable Changesto Master #9
|
@ -38,7 +38,6 @@ class Plugin(PluginBase):
|
||||||
self._favorites_dialog = None
|
self._favorites_dialog = None
|
||||||
self._favorites_store = None
|
self._favorites_store = None
|
||||||
self._favorites = None
|
self._favorites = None
|
||||||
self._state = None
|
|
||||||
self._selected = None
|
self._selected = None
|
||||||
|
|
||||||
|
|
||||||
|
@ -48,8 +47,6 @@ class Plugin(PluginBase):
|
||||||
return button
|
return button
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
self._module_event_observer()
|
|
||||||
|
|
||||||
self._builder = Gtk.Builder()
|
self._builder = Gtk.Builder()
|
||||||
self._builder.add_from_file(self._GLADE_FILE)
|
self._builder.add_from_file(self._GLADE_FILE)
|
||||||
|
|
||||||
|
@ -81,19 +78,15 @@ class Plugin(PluginBase):
|
||||||
|
|
||||||
@threaded
|
@threaded
|
||||||
def _get_state(self, widget=None, eve=None):
|
def _get_state(self, widget=None, eve=None):
|
||||||
self._event_system.push_gui_event([self.name, "get_current_state", ()])
|
self._event_system.post_event("get_current_state", None)
|
||||||
self.wait_for_fm_message()
|
|
||||||
|
|
||||||
self._state = self._event_message
|
|
||||||
self._event_message = None
|
|
||||||
|
|
||||||
@threaded
|
@threaded
|
||||||
def _set_current_dir_lbl(self, widget=None, eve=None):
|
def _set_current_dir_lbl(self, widget=None, eve=None):
|
||||||
self.wait_for_state()
|
self._current_dir_lbl.set_label(f"Current Directory:\n{self._fm_state.tab.get_current_directory()}")
|
||||||
self._current_dir_lbl.set_label(f"Current Directory:\n{self._state.tab.get_current_directory()}")
|
|
||||||
|
|
||||||
def _add_to_favorite(self, state):
|
def _add_to_favorite(self, state):
|
||||||
current_directory = self._state.tab.get_current_directory()
|
current_directory = self._fm_state.tab.get_current_directory()
|
||||||
self._favorites_store.append([current_directory])
|
self._favorites_store.append([current_directory])
|
||||||
self._favorites.append(current_directory)
|
self._favorites.append(current_directory)
|
||||||
self._save_favorites()
|
self._save_favorites()
|
||||||
|
@ -111,11 +104,10 @@ class Plugin(PluginBase):
|
||||||
def _set_selected_path(self, widget=None, eve=None):
|
def _set_selected_path(self, widget=None, eve=None):
|
||||||
path = self._favorites_store.get_value(self._selected, 0)
|
path = self._favorites_store.get_value(self._selected, 0)
|
||||||
self._ui_objects[0].set_text(path)
|
self._ui_objects[0].set_text(path)
|
||||||
|
self._set_current_dir_lbl()
|
||||||
|
|
||||||
|
|
||||||
def _show_favorites_menu(self, widget=None, eve=None):
|
def _show_favorites_menu(self, widget=None, eve=None):
|
||||||
self._state = None
|
self._fm_state = None
|
||||||
self._get_state()
|
self._get_state()
|
||||||
self._set_current_dir_lbl()
|
self._set_current_dir_lbl()
|
||||||
self._favorites_dialog.run()
|
self._favorites_dialog.run()
|
||||||
|
@ -127,7 +119,3 @@ class Plugin(PluginBase):
|
||||||
selected = user_data.get_selected()[1]
|
selected = user_data.get_selected()[1]
|
||||||
if selected:
|
if selected:
|
||||||
self._selected = selected
|
self._selected = selected
|
||||||
|
|
||||||
def wait_for_state(self):
|
|
||||||
while not self._state:
|
|
||||||
pass
|
|
||||||
|
|
|
@ -89,8 +89,6 @@ class Plugin(PluginBase):
|
||||||
return button
|
return button
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
self._module_event_observer()
|
|
||||||
|
|
||||||
self._builder = Gtk.Builder()
|
self._builder = Gtk.Builder()
|
||||||
self._builder.add_from_file(self._GLADE_FILE)
|
self._builder.add_from_file(self._GLADE_FILE)
|
||||||
|
|
||||||
|
@ -109,10 +107,9 @@ class Plugin(PluginBase):
|
||||||
|
|
||||||
@threaded
|
@threaded
|
||||||
def _show_properties_page(self, widget=None, eve=None):
|
def _show_properties_page(self, widget=None, eve=None):
|
||||||
self._event_system.push_gui_event([self.name, "get_current_state", ()])
|
event_system.post_event("get_current_state", None)
|
||||||
self.wait_for_fm_message()
|
|
||||||
|
|
||||||
state = self._event_message
|
state = self._fm_state
|
||||||
self._event_message = None
|
self._event_message = None
|
||||||
|
|
||||||
GLib.idle_add(self._process_changes, (state))
|
GLib.idle_add(self._process_changes, (state))
|
||||||
|
|
|
@ -39,7 +39,6 @@ class Plugin(PluginBase):
|
||||||
self._dialog = None
|
self._dialog = None
|
||||||
self._thumbnail_preview_img = None
|
self._thumbnail_preview_img = None
|
||||||
self._tmdb = scraper.get_tmdb_scraper()
|
self._tmdb = scraper.get_tmdb_scraper()
|
||||||
self._state = None
|
|
||||||
self._overview = None
|
self._overview = None
|
||||||
self._file_name = None
|
self._file_name = None
|
||||||
self._file_location = None
|
self._file_location = None
|
||||||
|
@ -53,8 +52,6 @@ class Plugin(PluginBase):
|
||||||
return button
|
return button
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
self._module_event_observer()
|
|
||||||
|
|
||||||
self._builder = Gtk.Builder()
|
self._builder = Gtk.Builder()
|
||||||
self._builder.add_from_file(self._GLADE_FILE)
|
self._builder.add_from_file(self._GLADE_FILE)
|
||||||
|
|
||||||
|
@ -80,19 +77,18 @@ class Plugin(PluginBase):
|
||||||
|
|
||||||
@threaded
|
@threaded
|
||||||
def _show_info_page(self, widget=None, eve=None):
|
def _show_info_page(self, widget=None, eve=None):
|
||||||
self._event_system.push_gui_event([self.name, "get_current_state", ()])
|
self._event_system.post_event("get_current_state", None)
|
||||||
self.wait_for_fm_message()
|
|
||||||
|
|
||||||
state = self._event_message
|
state = self._fm_state
|
||||||
self._event_message = None
|
self._event_message = None
|
||||||
|
|
||||||
GLib.idle_add(self._process_changes, (state))
|
GLib.idle_add(self._process_changes, (state))
|
||||||
|
|
||||||
def _process_changes(self, state):
|
def _process_changes(self, state):
|
||||||
self._state = None
|
self._fm_state = None
|
||||||
|
|
||||||
if len(state.selected_files) == 1:
|
if len(state.selected_files) == 1:
|
||||||
self._state = state
|
self._fm_state = state
|
||||||
self._set_ui_data()
|
self._set_ui_data()
|
||||||
response = self._thumbnailer_dialog.run()
|
response = self._thumbnailer_dialog.run()
|
||||||
if response in [Gtk.ResponseType.CLOSE, Gtk.ResponseType.DELETE_EVENT]:
|
if response in [Gtk.ResponseType.CLOSE, Gtk.ResponseType.DELETE_EVENT]:
|
||||||
|
@ -111,8 +107,8 @@ class Plugin(PluginBase):
|
||||||
print(video_data["videos"]) if not keys in ("", None) and "videos" in keys else ...
|
print(video_data["videos"]) if not keys in ("", None) and "videos" in keys else ...
|
||||||
|
|
||||||
def get_video_data(self):
|
def get_video_data(self):
|
||||||
uri = self._state.selected_files[0]
|
uri = self._fm_state.selected_files[0]
|
||||||
path = self._state.tab.get_current_directory()
|
path = self._fm_state.tab.get_current_directory()
|
||||||
parts = uri.split("/")
|
parts = uri.split("/")
|
||||||
_title = parts[ len(parts) - 1 ]
|
_title = parts[ len(parts) - 1 ]
|
||||||
|
|
||||||
|
|
|
@ -98,8 +98,6 @@ class Plugin(PluginBase):
|
||||||
return button
|
return button
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
self._module_event_observer()
|
|
||||||
|
|
||||||
self._builder = Gtk.Builder()
|
self._builder = Gtk.Builder()
|
||||||
self._builder.add_from_file(self._GLADE_FILE)
|
self._builder.add_from_file(self._GLADE_FILE)
|
||||||
|
|
||||||
|
@ -127,10 +125,9 @@ class Plugin(PluginBase):
|
||||||
|
|
||||||
@daemon_threaded
|
@daemon_threaded
|
||||||
def _show_grep_list_page(self, widget=None, eve=None):
|
def _show_grep_list_page(self, widget=None, eve=None):
|
||||||
self._event_system.push_gui_event([self.name, "get_current_state", ()])
|
self._event_system.post_event("get_current_state", None)
|
||||||
self.wait_for_fm_message()
|
|
||||||
|
|
||||||
state = self._event_message
|
state = self._fm_state
|
||||||
self._event_message = None
|
self._event_message = None
|
||||||
|
|
||||||
GLib.idle_add(self._process_queries, (state))
|
GLib.idle_add(self._process_queries, (state))
|
||||||
|
|
|
@ -39,8 +39,8 @@ class Plugin(PluginBase):
|
||||||
return button
|
return button
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
self._module_event_observer()
|
...
|
||||||
|
|
||||||
def send_message(self, widget=None, eve=None):
|
def send_message(self, widget=None, eve=None):
|
||||||
message = "Hello, World!"
|
message = "Hello, World!"
|
||||||
self._event_system.push_gui_event([self.name, "display_message", ("warning", message, None)])
|
event_system.post_event("display_message", ("warning", message, None))
|
||||||
|
|
|
@ -42,7 +42,6 @@ class Plugin(PluginBase):
|
||||||
self._file_name = None
|
self._file_name = None
|
||||||
self._file_location = None
|
self._file_location = None
|
||||||
self._file_hash = None
|
self._file_hash = None
|
||||||
self._state = None
|
|
||||||
|
|
||||||
|
|
||||||
def get_ui_element(self):
|
def get_ui_element(self):
|
||||||
|
@ -51,8 +50,6 @@ class Plugin(PluginBase):
|
||||||
return button
|
return button
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
self._module_event_observer()
|
|
||||||
|
|
||||||
self._builder = Gtk.Builder()
|
self._builder = Gtk.Builder()
|
||||||
self._builder.add_from_file(self._GLADE_FILE)
|
self._builder.add_from_file(self._GLADE_FILE)
|
||||||
|
|
||||||
|
@ -78,20 +75,19 @@ class Plugin(PluginBase):
|
||||||
|
|
||||||
@threaded
|
@threaded
|
||||||
def _show_thumbnailer_page(self, widget=None, eve=None):
|
def _show_thumbnailer_page(self, widget=None, eve=None):
|
||||||
self._event_system.push_gui_event([self.name, "get_current_state", ()])
|
self._event_system.post_event("get_current_state", None)
|
||||||
self.wait_for_fm_message()
|
|
||||||
|
|
||||||
state = self._event_message
|
state = self._fm_state
|
||||||
self._event_message = None
|
self._event_message = None
|
||||||
|
|
||||||
GLib.idle_add(self._process_changes, (state))
|
GLib.idle_add(self._process_changes, (state))
|
||||||
|
|
||||||
def _process_changes(self, state):
|
def _process_changes(self, state):
|
||||||
self._state = None
|
self._fm_state = None
|
||||||
|
|
||||||
if len(state.selected_files) == 1:
|
if len(state.selected_files) == 1:
|
||||||
if state.selected_files[0].lower().endswith(state.tab.fvideos):
|
if state.selected_files[0].lower().endswith(state.tab.fvideos):
|
||||||
self._state = state
|
self._fm_state = state
|
||||||
self._set_ui_data()
|
self._set_ui_data()
|
||||||
response = self._thumbnailer_dialog.run()
|
response = self._thumbnailer_dialog.run()
|
||||||
if response in [Gtk.ResponseType.CLOSE, Gtk.ResponseType.DELETE_EVENT]:
|
if response in [Gtk.ResponseType.CLOSE, Gtk.ResponseType.DELETE_EVENT]:
|
||||||
|
@ -103,32 +99,32 @@ class Plugin(PluginBase):
|
||||||
file = self._file_name.get_text()
|
file = self._file_name.get_text()
|
||||||
dir = self._file_location.get_text()
|
dir = self._file_location.get_text()
|
||||||
file_hash = self._file_hash.get_text()
|
file_hash = self._file_hash.get_text()
|
||||||
hash_img_pth = f"{self._state.tab.ABS_THUMBS_PTH}/{file_hash}.jpg"
|
hash_img_pth = f"{self._fm_state.tab.ABS_THUMBS_PTH}/{file_hash}.jpg"
|
||||||
|
|
||||||
try:
|
try:
|
||||||
os.remove(hash_img_pth) if os.path.isfile(hash_img_pth) else ...
|
os.remove(hash_img_pth) if os.path.isfile(hash_img_pth) else ...
|
||||||
|
|
||||||
self._state.tab.create_thumbnail(dir, file, f"{scrub_percent}%")
|
self._fm_state.tab.create_thumbnail(dir, file, f"{scrub_percent}%")
|
||||||
preview_pixbuf = GdkPixbuf.Pixbuf.new_from_file(hash_img_pth)
|
preview_pixbuf = GdkPixbuf.Pixbuf.new_from_file(hash_img_pth)
|
||||||
self._thumbnail_preview_img.set_from_pixbuf(preview_pixbuf)
|
self._thumbnail_preview_img.set_from_pixbuf(preview_pixbuf)
|
||||||
|
|
||||||
img_pixbuf = self._state.tab.create_scaled_image(hash_img_pth)
|
img_pixbuf = self._fm_state.tab.create_scaled_image(hash_img_pth)
|
||||||
tree_pth = self._state.icon_grid.get_selected_items()[0]
|
tree_pth = self._fm_state.icon_grid.get_selected_items()[0]
|
||||||
itr = self._state.store.get_iter(tree_pth)
|
itr = self._fm_state.store.get_iter(tree_pth)
|
||||||
pixbuff = self._state.store.get(itr, 0)[0]
|
pixbuff = self._fm_state.store.get(itr, 0)[0]
|
||||||
self._state.store.set(itr, 0, img_pixbuf)
|
self._fm_state.store.set(itr, 0, img_pixbuf)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(repr(e))
|
print(repr(e))
|
||||||
print("Couldn't regenerate thumbnail!")
|
print("Couldn't regenerate thumbnail!")
|
||||||
|
|
||||||
|
|
||||||
def _set_ui_data(self):
|
def _set_ui_data(self):
|
||||||
uri = self._state.selected_files[0]
|
uri = self._fm_state.selected_files[0]
|
||||||
path = self._state.tab.get_current_directory()
|
path = self._fm_state.tab.get_current_directory()
|
||||||
parts = uri.split("/")
|
parts = uri.split("/")
|
||||||
|
|
||||||
file_hash = hashlib.sha256(str.encode(uri)).hexdigest()
|
file_hash = hashlib.sha256(str.encode(uri)).hexdigest()
|
||||||
hash_img_pth = f"{self._state.tab.ABS_THUMBS_PTH}/{file_hash}.jpg"
|
hash_img_pth = f"{self._fm_state.tab.ABS_THUMBS_PTH}/{file_hash}.jpg"
|
||||||
preview_pixbuf = GdkPixbuf.Pixbuf.new_from_file(hash_img_pth)
|
preview_pixbuf = GdkPixbuf.Pixbuf.new_from_file(hash_img_pth)
|
||||||
|
|
||||||
self._thumbnail_preview_img.set_from_pixbuf(preview_pixbuf)
|
self._thumbnail_preview_img.set_from_pixbuf(preview_pixbuf)
|
||||||
|
|
|
@ -40,14 +40,15 @@ class Plugin(PluginBase):
|
||||||
return button
|
return button
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
self._module_event_observer()
|
...
|
||||||
|
|
||||||
|
|
||||||
|
def _do_download(self, widget=None, eve=None):
|
||||||
|
self._event_system.post_event("get_current_state", None)
|
||||||
|
|
||||||
|
dir = self._fm_state.tab.get_current_directory()
|
||||||
|
self._download(dir)
|
||||||
|
|
||||||
@threaded
|
@threaded
|
||||||
def _do_download(self, widget=None, eve=None):
|
def _download(self, dir):
|
||||||
self._event_system.push_gui_event([self.name, "get_current_state", ()])
|
subprocess.Popen([f'{self.path}/download.sh', dir])
|
||||||
self.wait_for_fm_message()
|
|
||||||
|
|
||||||
state = self._event_message
|
|
||||||
subprocess.Popen([f'{self.path}/download.sh' , state.tab.get_current_directory()])
|
|
||||||
self._event_message = None
|
|
||||||
|
|
|
@ -5,6 +5,7 @@ import builtins, threading
|
||||||
|
|
||||||
# Application imports
|
# Application imports
|
||||||
from utils.event_system import EventSystem
|
from utils.event_system import EventSystem
|
||||||
|
from utils.endpoint_registry import EndpointRegistry
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -24,23 +25,6 @@ def daemon_threaded_wrapper(fn):
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class EndpointRegistry():
|
|
||||||
def __init__(self):
|
|
||||||
self._endpoints = {}
|
|
||||||
|
|
||||||
def register(self, rule, **options):
|
|
||||||
def decorator(f):
|
|
||||||
self._endpoints[rule] = f
|
|
||||||
return f
|
|
||||||
|
|
||||||
return decorator
|
|
||||||
|
|
||||||
def get_endpoints(self):
|
|
||||||
return self._endpoints
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# NOTE: Just reminding myself we can add to builtins two different ways...
|
# NOTE: Just reminding myself we can add to builtins two different ways...
|
||||||
# __builtins__.update({"event_system": Builtins()})
|
# __builtins__.update({"event_system": Builtins()})
|
||||||
builtins.app_name = "SolarFM"
|
builtins.app_name = "SolarFM"
|
||||||
|
|
|
@ -28,52 +28,32 @@ class Controller(UIMixin, KeyboardSignalsMixin, IPCSignalsMixin, ExceptionHookMi
|
||||||
if debug:
|
if debug:
|
||||||
self.window.set_interactive_debugging(True)
|
self.window.set_interactive_debugging(True)
|
||||||
|
|
||||||
|
|
||||||
if not trace_debug:
|
if not trace_debug:
|
||||||
self.gui_event_observer()
|
self._subscribe_to_events()
|
||||||
|
|
||||||
if unknownargs:
|
if unknownargs:
|
||||||
for arg in unknownargs:
|
for arg in unknownargs:
|
||||||
if os.path.isdir(arg):
|
if os.path.isdir(arg):
|
||||||
message = f"FILE|{arg}"
|
message = f"FILE|{arg}"
|
||||||
event_system.send_ipc_message(message)
|
event_system.post_event("post_file_to_ipc", message)
|
||||||
|
|
||||||
if args.new_tab and os.path.isdir(args.new_tab):
|
if args.new_tab and os.path.isdir(args.new_tab):
|
||||||
message = f"FILE|{args.new_tab}"
|
message = f"FILE|{args.new_tab}"
|
||||||
event_system.send_ipc_message(message)
|
event_system.post_event("post_file_to_ipc", message)
|
||||||
|
|
||||||
|
|
||||||
|
def _subscribe_to_events(self):
|
||||||
|
event_system.subscribe("handle_file_from_ipc", self.handle_file_from_ipc)
|
||||||
|
event_system.subscribe("get_current_state", self.get_current_state)
|
||||||
|
event_system.subscribe("display_message", self.display_message)
|
||||||
|
|
||||||
def tear_down(self, widget=None, eve=None):
|
def tear_down(self, widget=None, eve=None):
|
||||||
self.fm_controller.save_state()
|
self.fm_controller.save_state()
|
||||||
time.sleep(event_sleep_time)
|
time.sleep(event_sleep_time)
|
||||||
Gtk.main_quit()
|
Gtk.main_quit()
|
||||||
|
|
||||||
|
|
||||||
@daemon_threaded
|
|
||||||
def gui_event_observer(self):
|
|
||||||
while True:
|
|
||||||
time.sleep(event_sleep_time)
|
|
||||||
event = event_system.consume_gui_event()
|
|
||||||
if event:
|
|
||||||
try:
|
|
||||||
sender_id, method_target, parameters = event
|
|
||||||
if sender_id:
|
|
||||||
method = getattr(self.__class__, "handle_gui_event_and_return_message")
|
|
||||||
GLib.idle_add(method, *(self, sender_id, method_target, parameters))
|
|
||||||
else:
|
|
||||||
method = getattr(self.__class__, method_target)
|
|
||||||
GLib.idle_add(method, *(self, *parameters,))
|
|
||||||
except Exception as e:
|
|
||||||
print(repr(e))
|
|
||||||
|
|
||||||
def handle_gui_event_and_return_message(self, sender, method_target, parameters):
|
|
||||||
method = getattr(self.__class__, f"{method_target}")
|
|
||||||
data = method(*(self, *parameters))
|
|
||||||
event_system.push_module_event([sender, None, data])
|
|
||||||
|
|
||||||
def handle_plugin_key_event(self, sender, method_target, parameters=()):
|
|
||||||
event_system.push_module_event([sender, method_target, parameters])
|
|
||||||
|
|
||||||
|
|
||||||
def save_load_session(self, action="save_session"):
|
def save_load_session(self, action="save_session"):
|
||||||
wid, tid = self.fm_controller.get_active_wid_and_tid()
|
wid, tid = self.fm_controller.get_active_wid_and_tid()
|
||||||
tab = self.get_fm_window(wid).get_tab_by_id(tid)
|
tab = self.get_fm_window(wid).get_tab_by_id(tid)
|
||||||
|
|
|
@ -154,6 +154,8 @@ class Controller_Data:
|
||||||
# if self.to_cut_files:
|
# if self.to_cut_files:
|
||||||
# state.to_cut_files = self.format_to_uris(state.store, state.wid, state.tid, self.to_cut_files, True)
|
# state.to_cut_files = self.format_to_uris(state.store, state.wid, state.tid, self.to_cut_files, True)
|
||||||
|
|
||||||
|
event_system.post_event("update_state_info_plugins", state)
|
||||||
|
|
||||||
return state
|
return state
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -13,10 +13,9 @@ class PluginBase:
|
||||||
|
|
||||||
self._builder = None
|
self._builder = None
|
||||||
self._ui_objects = None
|
self._ui_objects = None
|
||||||
|
self._fm_state = None
|
||||||
self._event_system = None
|
self._event_system = None
|
||||||
self._event_sleep_time = .5
|
|
||||||
self._event_message = None
|
|
||||||
|
|
||||||
def set_fm_event_system(self, fm_event_system):
|
def set_fm_event_system(self, fm_event_system):
|
||||||
self._event_system = fm_event_system
|
self._event_system = fm_event_system
|
||||||
|
@ -24,32 +23,14 @@ class PluginBase:
|
||||||
def set_ui_object_collection(self, ui_objects):
|
def set_ui_object_collection(self, ui_objects):
|
||||||
self._ui_objects = ui_objects
|
self._ui_objects = ui_objects
|
||||||
|
|
||||||
def wait_for_fm_message(self):
|
|
||||||
while not self._event_message:
|
|
||||||
pass
|
|
||||||
|
|
||||||
def clear_children(self, widget: type) -> None:
|
def clear_children(self, widget: type) -> None:
|
||||||
''' Clear children of a gtk widget. '''
|
''' Clear children of a gtk widget. '''
|
||||||
for child in widget.get_children():
|
for child in widget.get_children():
|
||||||
widget.remove(child)
|
widget.remove(child)
|
||||||
|
|
||||||
@daemon_threaded
|
def subscribe_to_events(self):
|
||||||
def _module_event_observer(self):
|
self._event_system.subscribe("update_state_info_plugins", self._update_fm_state_info)
|
||||||
while True:
|
|
||||||
time.sleep(self._event_sleep_time)
|
|
||||||
event = self._event_system.read_module_event()
|
|
||||||
if event:
|
|
||||||
try:
|
|
||||||
if event[0] == self.name:
|
|
||||||
target_id, method_target, data = self._event_system.consume_module_event()
|
|
||||||
|
|
||||||
if not method_target:
|
def _update_fm_state_info(self, state):
|
||||||
self._event_message = data
|
self._fm_state = state
|
||||||
else:
|
|
||||||
method = getattr(self.__class__, f"{method_target}")
|
|
||||||
if data:
|
|
||||||
data = method(*(self, *data))
|
|
||||||
else:
|
|
||||||
method(*(self,))
|
|
||||||
except Exception as e:
|
|
||||||
print(repr(e))
|
|
||||||
|
|
|
@ -93,6 +93,7 @@ class PluginsController:
|
||||||
|
|
||||||
if "pass_fm_events" in keys:
|
if "pass_fm_events" in keys:
|
||||||
plugin.reference.set_fm_event_system(event_system)
|
plugin.reference.set_fm_event_system(event_system)
|
||||||
|
plugin.reference.subscribe_to_events()
|
||||||
|
|
||||||
if "bind_keys" in keys:
|
if "bind_keys" in keys:
|
||||||
self._keybindings.append_bindings( loading_data["bind_keys"] )
|
self._keybindings.append_bindings( loading_data["bind_keys"] )
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
# Python imports
|
||||||
|
|
||||||
|
# Lib imports
|
||||||
|
|
||||||
|
# Application imports
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class EndpointRegistry():
|
||||||
|
def __init__(self):
|
||||||
|
self._endpoints = {}
|
||||||
|
|
||||||
|
def register(self, rule, **options):
|
||||||
|
def decorator(f):
|
||||||
|
self._endpoints[rule] = f
|
||||||
|
return f
|
||||||
|
|
||||||
|
return decorator
|
||||||
|
|
||||||
|
def get_endpoints(self):
|
||||||
|
return self._endpoints
|
|
@ -1,4 +1,5 @@
|
||||||
# Python imports
|
# Python imports
|
||||||
|
from collections import defaultdict
|
||||||
|
|
||||||
# Lib imports
|
# Lib imports
|
||||||
|
|
||||||
|
@ -7,57 +8,23 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class EventSystemPushException(Exception):
|
|
||||||
...
|
|
||||||
|
|
||||||
|
|
||||||
class EventSystem:
|
class EventSystem:
|
||||||
""" Inheret IPCServerMixin. Create an pub/sub systems. """
|
""" Create event system. """
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
# NOTE: The format used is list of ['who', target, (data,)] Where:
|
self.subscribers = defaultdict(list)
|
||||||
# who is the sender or target ID and is used for context and control flow,
|
|
||||||
# method_target is the method to call,
|
|
||||||
# data is the method parameters OR message data to give
|
|
||||||
# Where data may be any kind of data
|
|
||||||
self._gui_events = []
|
|
||||||
self._module_events = []
|
|
||||||
|
|
||||||
|
|
||||||
# Makeshift "events" system FIFO
|
def subscribe(self, event_type, fn):
|
||||||
def _pop_gui_event(self) -> None:
|
self.subscribers[event_type].append(fn)
|
||||||
if len(self._gui_events) > 0:
|
|
||||||
return self._gui_events.pop(0)
|
|
||||||
return None
|
|
||||||
|
|
||||||
def _pop_module_event(self) -> None:
|
def post_event(self, event_type, data):
|
||||||
if len(self._module_events) > 0:
|
if event_type in self.subscribers:
|
||||||
return self._module_events.pop(0)
|
for fn in self.subscribers[event_type]:
|
||||||
return None
|
if data:
|
||||||
|
if hasattr(data, '__iter__'):
|
||||||
|
fn(*data)
|
||||||
def push_gui_event(self, event: list) -> None:
|
else:
|
||||||
if len(event) == 3:
|
fn(data)
|
||||||
self._gui_events.append(event)
|
else:
|
||||||
return None
|
fn()
|
||||||
|
|
||||||
raise EventSystemPushException("Invald event format! Please do: ['sender_id': str, method_target: method, (data,): any]")
|
|
||||||
|
|
||||||
def push_module_event(self, event: list) -> None:
|
|
||||||
if len(event) == 3:
|
|
||||||
self._module_events.append(event)
|
|
||||||
return None
|
|
||||||
|
|
||||||
raise EventSystemPushException("Invald event format! Please do: ['target_id': str, method_target: method, (data,): any]")
|
|
||||||
|
|
||||||
def read_gui_event(self) -> list:
|
|
||||||
return self._gui_events[0] if self._gui_events else None
|
|
||||||
|
|
||||||
def read_module_event(self) -> list:
|
|
||||||
return self._module_events[0] if self._module_events else None
|
|
||||||
|
|
||||||
def consume_gui_event(self) -> list:
|
|
||||||
return self._pop_gui_event()
|
|
||||||
|
|
||||||
def consume_module_event(self) -> list:
|
|
||||||
return self._pop_module_event()
|
|
||||||
|
|
|
@ -29,6 +29,11 @@ class IPCServer:
|
||||||
elif conn_type == "local_network_unsecured":
|
elif conn_type == "local_network_unsecured":
|
||||||
self._ipc_authkey = None
|
self._ipc_authkey = None
|
||||||
|
|
||||||
|
self._subscribe_to_events()
|
||||||
|
|
||||||
|
def _subscribe_to_events(self):
|
||||||
|
event_system.subscribe("post_file_to_ipc", self.send_ipc_message)
|
||||||
|
|
||||||
|
|
||||||
@daemon_threaded
|
@daemon_threaded
|
||||||
def create_ipc_listener(self) -> None:
|
def create_ipc_listener(self) -> None:
|
||||||
|
@ -60,7 +65,7 @@ class IPCServer:
|
||||||
if "FILE|" in msg:
|
if "FILE|" in msg:
|
||||||
file = msg.split("FILE|")[1].strip()
|
file = msg.split("FILE|")[1].strip()
|
||||||
if file:
|
if file:
|
||||||
event_system.push_gui_event([None, "handle_file_from_ipc", (file,)])
|
event_system.post_event("handle_file_from_ipc", file)
|
||||||
|
|
||||||
conn.close()
|
conn.close()
|
||||||
break
|
break
|
||||||
|
|
Loading…
Reference in New Issue