develop #11

Merged
itdominator merged 36 commits from develop into master 2023-09-19 01:11:24 +00:00
10 changed files with 132 additions and 80 deletions
Showing only changes of commit df688d919e - Show all commits

View File

@ -81,6 +81,7 @@ class FileSearchMixin:
self._list_proc = None self._list_proc = None
def _exec_find_file_query(self, widget=None, eve=None): def _exec_find_file_query(self, widget=None, eve=None):
query = widget.get_text() query = widget.get_text()
@ -88,7 +89,9 @@ class FileSearchMixin:
self.search_query = query self.search_query = query
target_dir = shlex.quote( self._fm_state.tab.get_current_directory() ) target_dir = shlex.quote( self._fm_state.tab.get_current_directory() )
command = ["python", f"{self.path}/utils/search.py", "-t", "file_search", "-d", f"{target_dir}", "-q", f"{query}"] command = ["python", f"{self.path}/utils/search.py", "-t", "file_search", "-d", f"{target_dir}", "-q", f"{query}"]
self._spinner.start() self._spinner.start()
self._list_proc = subprocess.Popen(command, cwd=self.path, stdin=None, stdout=None, stderr=None) self._list_proc = subprocess.Popen(command, cwd=self.path, stdin=None, stdout=None, stderr=None)

View File

@ -87,12 +87,14 @@ class GrepSearchMixin:
if not query.strip() in ("", None): if not query.strip() in ("", None):
self.grep_query = query self.grep_query = query
target_dir = shlex.quote( self._fm_state.tab.get_current_directory() ) target_dir = shlex.quote( self._fm_state.tab.get_current_directory() )
command = ["python", f"{self.path}/utils/search.py", "-t", "grep_search", "-d", f"{target_dir}", "-q", f"{query}"] command = ["python", f"{self.path}/utils/search.py", "-t", "grep_search", "-d", f"{target_dir}", "-q", f"{query}"]
self._spinner.start() self._spinner.start()
self._grep_proc = subprocess.Popen(command, cwd=self.path, stdin=None, stdout=None, stderr=None) self._grep_proc = subprocess.Popen(command, cwd=self.path, stdin=None, stdout=None, stderr=None)
def _load_grep_ui(self, data): def _load_grep_ui(self, data):
Gtk.main_iteration() Gtk.main_iteration()

View File

@ -60,13 +60,6 @@ class IPCServer:
msg = conn.recv() msg = conn.recv()
try: try:
if "SEARCH_DONE|" in msg:
ts, ret_code = msg.split("SEARCH_DONE|")[1].strip().split("|", 1)
timestamp = float(ts)
if self.fsearch_time_stamp or self.grep_time_stamp:
if (timestamp > self.fsearch_time_stamp) or (timestamp > self.grep_time_stamp):
GLib.idle_add(self.stop_spinner, (ret_code,), priority=GLib.PRIORITY_HIGH_IDLE)
if "SEARCH|" in msg: if "SEARCH|" in msg:
ts, file = msg.split("SEARCH|")[1].strip().split("|", 1) ts, file = msg.split("SEARCH|")[1].strip().split("|", 1)
timestamp = float(ts) timestamp = float(ts)
@ -78,6 +71,10 @@ class IPCServer:
timestamp = float(ts) timestamp = float(ts)
if data and (timestamp > self.grep_time_stamp): if data and (timestamp > self.grep_time_stamp):
GLib.idle_add(self._load_grep_ui, data, priority=GLib.PRIORITY_HIGH_IDLE) GLib.idle_add(self._load_grep_ui, data, priority=GLib.PRIORITY_HIGH_IDLE)
if "SEARCH_DONE|" in msg:
ts, ret_code = msg.split("SEARCH_DONE|")[1].strip().split("|", 1)
GLib.idle_add(self.stop_spinner, (ret_code,), priority=GLib.PRIORITY_HIGH_IDLE)
except Exception as e: except Exception as e:
print( repr(e) ) print( repr(e) )

View File

@ -32,6 +32,10 @@ dt = datetime.now()
ts = datetime.timestamp(dt) ts = datetime.timestamp(dt)
def _log(message: str = "No message passed in...") -> None:
print(message)
def send_ipc_message(message) -> None: def send_ipc_message(message) -> None:
conn = Client(address = _ipc_address, family = "AF_UNIX", authkey = _ipc_authkey) conn = Client(address = _ipc_address, family = "AF_UNIX", authkey = _ipc_authkey)
conn.send(message) conn.send(message)
@ -41,9 +45,11 @@ def send_ipc_message(message) -> None:
time.sleep(0.05) time.sleep(0.05)
def file_search(path, query): def file_search(path: str = None, query: str = None) -> None:
if not path or not query: return
try: try:
for _path, _dir, _files in os.walk(path, topdown = True): for _path, _dir, _files in os.walk(path, topdown = True, onerror = _log, followlinks = True):
for file in _files: for file in _files:
if query in file.lower(): if query in file.lower():
target = os.path.join(_path, file) target = os.path.join(_path, file)
@ -54,9 +60,8 @@ def file_search(path, query):
traceback.print_exc() traceback.print_exc()
def grep_search(target=None, query=None): def grep_search(target: str = None, query: str = None):
if not query or not target: if not target or not query: return
return
# NOTE: -n = provide line numbers, -R = Search recursive in given target # NOTE: -n = provide line numbers, -R = Search recursive in given target
# -i = insensitive, -F = don't do regex parsing. (Treat as raw string) # -i = insensitive, -F = don't do regex parsing. (Treat as raw string)
@ -85,17 +90,23 @@ def grep_search(target=None, query=None):
except Exception as e: except Exception as e:
traceback.print_exc() traceback.print_exc()
proc.terminate()
data = f"GREP|{ts}|{json.dumps(collection, separators=(',', ':'), indent=4)}" data = f"GREP|{ts}|{json.dumps(collection, separators=(',', ':'), indent=4)}"
send_ipc_message(data) send_ipc_message(data)
collection = {} collection = {}
def search(args): def search(args):
path = args.dir
if (path[0] == "'" and path[-1] == "'") or \
path[0] == '"' and path[-1] == '"':
path = path[1:-1]
if args.type == "file_search": if args.type == "file_search":
file_search(args.dir, args.query.lower()) file_search(path, args.query.lower())
if args.type == "grep_search": if args.type == "grep_search":
grep_search(args.dir, args.query.encode("utf-8")) grep_search(path, args.query.encode("utf-8"))
if __name__ == "__main__": if __name__ == "__main__":

View File

@ -113,8 +113,7 @@ class Controller(UIMixin, SignalsMixins, Controller_Data):
def do_action_from_menu_controls(self, _action=None, eve=None): def do_action_from_menu_controls(self, _action=None, eve=None):
if not _action: if not _action: return
return
if not isinstance(_action, str): if not isinstance(_action, str):
action = _action.get_name() action = _action.get_name()

View File

@ -1,18 +1,19 @@
# Python imports # Python imports
import os import os
import gc import gc
import time
# Lib imports # Lib imports
import gi import gi
gi.require_version('Gtk', '3.0') gi.require_version('Gtk', '3.0')
from gi.repository import Gtk from gi.repository import Gtk
from gi.repository import GLib
# Application imports # Application imports
from .grid_mixin import GridMixin from .grid_mixin import GridMixin
class TabMixin(GridMixin): class TabMixin(GridMixin):
"""docstring for TabMixin""" """docstring for TabMixin"""
@ -173,8 +174,21 @@ class TabMixin(GridMixin):
path = widget.get_text() path = widget.get_text()
if isinstance(focused_obj, Gtk.Entry): if isinstance(focused_obj, Gtk.Entry):
self.process_path_menu(widget, tab, dir)
if path.endswith(".") or path == dir:
return
if not tab.set_path(path):
return
icon_grid = self.get_icon_grid_from_notebook(notebook, f"{wid}|{tid}")
icon_grid.clear_and_set_new_store()
self.update_tab(tab_label, tab, icon_grid.get_store(), wid, tid)
def process_path_menu(self, gtk_entry, tab, dir):
path_menu_buttons = self.builder.get_object("path_menu_buttons") path_menu_buttons = self.builder.get_object("path_menu_buttons")
query = widget.get_text().replace(dir, "") query = gtk_entry.get_text().replace(dir, "")
files = tab.get_files() + tab.get_hidden() files = tab.get_files() + tab.get_hidden()
self.clear_children(path_menu_buttons) self.clear_children(path_menu_buttons)
@ -192,34 +206,32 @@ class TabMixin(GridMixin):
event_system.emit("hide_path_menu") event_system.emit("hide_path_menu")
else: else:
event_system.emit("show_path_menu") event_system.emit("show_path_menu")
widget.grab_focus_without_selecting() buttons = path_menu_buttons.get_children()
widget.set_position(-1)
if path.endswith(".") or path == dir: if len(buttons) == 1:
return self.slowed_focus(buttons[0])
if not tab.set_path(path): @daemon_threaded
return def slowed_focus(self, button):
time.sleep(0.05)
GLib.idle_add(self.do_focused_click, *(button,))
icon_grid = self.get_icon_grid_from_notebook(notebook, f"{wid}|{tid}") def do_focused_click(self, button):
icon_grid.clear_and_set_new_store() button.grab_focus()
self.update_tab(tab_label, tab, icon_grid.get_store(), wid, tid) button.clicked()
try:
widget.grab_focus_without_selecting()
widget.set_position(-1)
except Exception as e:
pass
def set_path_entry(self, button = None, eve = None): def set_path_entry(self, button = None, eve = None):
self.path_auto_filled = True
state = self.get_current_state() state = self.get_current_state()
path = f"{state.tab.get_current_directory()}/{button.get_label()}" path = f"{state.tab.get_current_directory()}/{button.get_label()}"
path_entry = self.builder.get_object("path_entry") path_entry = self.builder.get_object("path_entry")
path_entry.set_text(path) path_entry.set_text(path)
path_entry.grab_focus_without_selecting() path_entry.grab_focus_without_selecting()
path_entry.set_position(-1) path_entry.set_position(-1)
event_system.emit("hide_path_menu") event_system.emit("hide_path_menu")
def show_hide_hidden_files(self): def show_hide_hidden_files(self):
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)

View File

@ -1,17 +1,19 @@
# Python imports # Python imports
import os import os
import gc
import time
# Lib imports # Lib imports
import gi import gi
gi.require_version('Gtk', '3.0') gi.require_version('Gtk', '3.0')
from gi.repository import Gtk from gi.repository import Gtk
from gi.repository import GLib
# Application imports # Application imports
from .grid_mixin import GridMixin from .grid_mixin import GridMixin
class TabMixin(GridMixin): class TabMixin(GridMixin):
"""docstring for TabMixin""" """docstring for TabMixin"""
@ -85,6 +87,7 @@ class TabMixin(GridMixin):
del watcher del watcher
del tab del tab
gc.collect()
if not settings_manager.is_trace_debug(): if not settings_manager.is_trace_debug():
self.fm_controller.save_state() self.fm_controller.save_state()
@ -173,8 +176,21 @@ class TabMixin(GridMixin):
path = widget.get_text() path = widget.get_text()
if isinstance(focused_obj, Gtk.Entry): if isinstance(focused_obj, Gtk.Entry):
self.process_path_menu(widget, tab, dir)
if path.endswith(".") or path == dir:
return
if not tab.set_path(path):
return
icon_grid = self.get_icon_grid_from_notebook(notebook, f"{wid}|{tid}")
icon_grid.clear_and_set_new_store()
self.update_tab(tab_label, tab, store, wid, tid)
def process_path_menu(self, gtk_entry, tab, dir):
path_menu_buttons = self.builder.get_object("path_menu_buttons") path_menu_buttons = self.builder.get_object("path_menu_buttons")
query = widget.get_text().replace(dir, "") query = gtk_entry.get_text().replace(dir, "")
files = tab.get_files() + tab.get_hidden() files = tab.get_files() + tab.get_hidden()
self.clear_children(path_menu_buttons) self.clear_children(path_menu_buttons)
@ -192,27 +208,26 @@ class TabMixin(GridMixin):
event_system.emit("hide_path_menu") event_system.emit("hide_path_menu")
else: else:
event_system.emit("show_path_menu") event_system.emit("show_path_menu")
widget.grab_focus_without_selecting() buttons = path_menu_buttons.get_children()
widget.set_position(-1)
if path.endswith(".") or path == dir: if len(buttons) == 1:
return self.slowed_focus(buttons[0])
if not tab.set_path(path): @daemon_threaded
return def slowed_focus(self, button):
time.sleep(0.05)
GLib.idle_add(self.do_focused_click, *(button,))
self.update_tab(tab_label, tab, store, wid, tid) def do_focused_click(self, button):
button.grab_focus()
try: button.clicked()
widget.grab_focus_without_selecting()
widget.set_position(-1)
except Exception as e:
pass
def set_path_entry(self, button = None, eve = None): def set_path_entry(self, button = None, eve = None):
self.path_auto_filled = True
state = self.get_current_state() state = self.get_current_state()
path = f"{state.tab.get_current_directory()}/{button.get_label()}" path = f"{state.tab.get_current_directory()}/{button.get_label()}"
path_entry = self.builder.get_object("path_entry") path_entry = self.builder.get_object("path_entry")
path_entry.set_text(path) path_entry.set_text(path)
path_entry.grab_focus_without_selecting() path_entry.grab_focus_without_selecting()
path_entry.set_position(-1) path_entry.set_position(-1)

View File

@ -106,7 +106,7 @@ class WindowMixin(TabMixin):
state = self.get_current_state() state = self.get_current_state()
notebook = self.builder.get_object(f"window_{state.wid}") notebook = self.builder.get_object(f"window_{state.wid}")
tab_label = self.get_tab_label(notebook, icons_grid) tab_label = self.get_tab_label(notebook, state.icon_grid)
fileName = state.store[item][1] fileName = state.store[item][1]
dir = state.tab.get_current_directory() dir = state.tab.get_current_directory()
@ -114,7 +114,8 @@ class WindowMixin(TabMixin):
if isdir(file): if isdir(file):
state.tab.set_path(file) state.tab.set_path(file)
self.update_tab(tab_label, state.tab, state.store, state.wid, state.tid) state.icon_grid.clear_and_set_new_store()
self.update_tab(tab_label, state.tab, state.icon_grid.get_store(), state.wid, state.tid)
else: else:
event_system.emit("open_files") event_system.emit("open_files")
except WindowException as e: except WindowException as e:

View File

@ -94,4 +94,5 @@ class Window(Gtk.ApplicationWindow):
settings_manager.clear_pid() settings_manager.clear_pid()
time.sleep(event_sleep_time) time.sleep(event_sleep_time)
Gtk.main_quit() Gtk.main_quit()

View File

@ -0,0 +1,11 @@
<frozen importlib._bootstrap_external>:672: size=5717 KiB, count=60317, average=97 B
<frozen importlib._bootstrap>:241: size=534 KiB, count=5538, average=99 B
/usr/lib/python3.10/abc.py:106: size=77.9 KiB, count=290, average=275 B
<frozen importlib._bootstrap_external>:128: size=62.1 KiB, count=532, average=119 B
/usr/lib/python3.10/sre_compile.py:804: size=57.7 KiB, count=110, average=537 B
/home/abaddon/Coding/Projects/Active/Python_Projects/000_Usable/gtk/SolarFM/src/versions/solarfm-0.0.1/solarfm/./shellfm/windows/tabs/tab.py:79: size=56.4 KiB, count=875, average=66 B
/usr/lib/python3.10/site-packages/gi/types.py:52: size=54.0 KiB, count=509, average=109 B
/usr/lib/python3.10/site-packages/gi/module.py:207: size=49.6 KiB, count=233, average=218 B
/usr/lib/python3.10/site-packages/gi/types.py:51: size=40.1 KiB, count=733, average=56 B
<frozen importlib._bootstrap>:359: size=38.6 KiB, count=549, average=72 B