Small logic fixes

This commit is contained in:
itdominator 2022-02-17 10:13:27 -06:00
parent 07714c9cd4
commit 918eec1053
3 changed files with 49 additions and 13 deletions

View File

@ -82,6 +82,7 @@ class Controller_Data:
self.selected_files = []
self.to_copy_files = []
self.to_cut_files = []
self.soft_update_lock = {}
self.single_click_open = False
self.is_pane1_hidden = False

View File

@ -1,5 +1,5 @@
# Python imports
import os
import os, time, threading
# Lib imports
import gi
@ -9,6 +9,10 @@ from gi.repository import Gtk, GObject, GLib, Gio
# Application imports
def threaded(fn):
def wrapper(*args, **kwargs):
threading.Thread(target=fn, args=args, kwargs=kwargs, daemon=True).start()
return wrapper
class WidgetFileActionMixin:
@ -56,14 +60,41 @@ class WidgetFileActionMixin:
dir_watcher.connect("changed", self.dir_watch_updates, (f"{wid}|{tid}",))
view.set_dir_watcher(dir_watcher)
# NOTE: Too lazy to impliment a proper update handler and so just regen store and update view.
# Use a lock system to prevent too many update calls for certain instances but user can manually refresh if they have urgency
def dir_watch_updates(self, file_monitor, file, other_file=None, eve_type=None, data=None):
if eve_type in [Gio.FileMonitorEvent.CREATED, Gio.FileMonitorEvent.DELETED,
Gio.FileMonitorEvent.RENAMED, Gio.FileMonitorEvent.MOVED_IN,
Gio.FileMonitorEvent.MOVED_OUT]:
Gio.FileMonitorEvent.MOVED_OUT, Gio.FileMonitorEvent.CHANGES_DONE_HINT]:
if debug:
print(eve_type)
wid, tid = data[0].split("|")
if eve_type in [Gio.FileMonitorEvent.MOVED_IN, Gio.FileMonitorEvent.MOVED_OUT]:
self.update_on_end_soft_lock(data[0])
elif data[0] in self.soft_update_lock.keys():
self.soft_update_lock[data[0]]["last_update_time"] = time.time()
else:
self.soft_lock_countdown(data[0])
@threaded
def soft_lock_countdown(self, tab):
self.soft_update_lock[tab] = { "last_update_time": time.time()}
lock = True
while lock:
time.sleep(0.6)
last_update_time = self.soft_update_lock[tab]["last_update_time"]
current_time = time.time()
if (current_time - last_update_time) > 0.6:
lock = False
self.soft_update_lock.pop(tab, None)
GLib.idle_add(self.update_on_end_soft_lock, *(tab,))
def update_on_end_soft_lock(self, tab):
wid, tid = tab.split("|")
notebook = self.builder.get_object(f"window_{wid}")
view = self.get_fm_window(wid).get_view_by_id(tid)
iconview = self.builder.get_object(f"{wid}|{tid}|iconview")
@ -72,9 +103,13 @@ class WidgetFileActionMixin:
view.load_directory()
self.load_store(view, store)
tab_label.set_label(view.get_end_of_path())
self.set_bottom_labels(view)
tab_label.set_label(view.get_end_of_path())
_wid, _tid, _view, _iconview, _store = self.get_current_state()
if [wid, tid] in [_wid, _tid]:
self.set_bottom_labels(view)
def popup_search_files(self, wid, keyname):

View File

@ -146,7 +146,7 @@ class WindowMixin(TabMixin):
ctx.remove_class("notebook-unselected-focus")
ctx.add_class("notebook-selected-focus")
self.window.set_title("SolarFM ~ " + dir)
self.window.set_title(f"SolarFM ~ {dir}")
self.set_bottom_labels(view)
def set_path_text(self, wid, tid):