Fixed search failing in some dirs; fixed pathbar autofilling with one found path
This commit is contained in:
parent
b5d1bbeccd
commit
df688d919e
@ -81,6 +81,7 @@ class FileSearchMixin:
|
||||
|
||||
self._list_proc = None
|
||||
|
||||
|
||||
def _exec_find_file_query(self, widget=None, eve=None):
|
||||
query = widget.get_text()
|
||||
|
||||
@ -88,7 +89,9 @@ class FileSearchMixin:
|
||||
self.search_query = query
|
||||
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}"]
|
||||
|
||||
self._spinner.start()
|
||||
|
||||
self._list_proc = subprocess.Popen(command, cwd=self.path, stdin=None, stdout=None, stderr=None)
|
||||
|
||||
|
||||
|
@ -87,12 +87,14 @@ class GrepSearchMixin:
|
||||
|
||||
if not query.strip() in ("", None):
|
||||
self.grep_query = query
|
||||
|
||||
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}"]
|
||||
|
||||
self._spinner.start()
|
||||
|
||||
self._grep_proc = subprocess.Popen(command, cwd=self.path, stdin=None, stdout=None, stderr=None)
|
||||
|
||||
|
||||
def _load_grep_ui(self, data):
|
||||
Gtk.main_iteration()
|
||||
|
||||
|
@ -60,13 +60,6 @@ class IPCServer:
|
||||
msg = conn.recv()
|
||||
|
||||
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:
|
||||
ts, file = msg.split("SEARCH|")[1].strip().split("|", 1)
|
||||
timestamp = float(ts)
|
||||
@ -78,6 +71,10 @@ class IPCServer:
|
||||
timestamp = float(ts)
|
||||
if data and (timestamp > self.grep_time_stamp):
|
||||
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:
|
||||
print( repr(e) )
|
||||
|
||||
|
@ -32,6 +32,10 @@ dt = datetime.now()
|
||||
ts = datetime.timestamp(dt)
|
||||
|
||||
|
||||
def _log(message: str = "No message passed in...") -> None:
|
||||
print(message)
|
||||
|
||||
|
||||
def send_ipc_message(message) -> None:
|
||||
conn = Client(address = _ipc_address, family = "AF_UNIX", authkey = _ipc_authkey)
|
||||
conn.send(message)
|
||||
@ -41,9 +45,11 @@ def send_ipc_message(message) -> None:
|
||||
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:
|
||||
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:
|
||||
if query in file.lower():
|
||||
target = os.path.join(_path, file)
|
||||
@ -54,9 +60,8 @@ def file_search(path, query):
|
||||
traceback.print_exc()
|
||||
|
||||
|
||||
def grep_search(target=None, query=None):
|
||||
if not query or not target:
|
||||
return
|
||||
def grep_search(target: str = None, query: str = None):
|
||||
if not target or not query: return
|
||||
|
||||
# NOTE: -n = provide line numbers, -R = Search recursive in given target
|
||||
# -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:
|
||||
traceback.print_exc()
|
||||
|
||||
proc.terminate()
|
||||
data = f"GREP|{ts}|{json.dumps(collection, separators=(',', ':'), indent=4)}"
|
||||
send_ipc_message(data)
|
||||
collection = {}
|
||||
|
||||
|
||||
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":
|
||||
file_search(args.dir, args.query.lower())
|
||||
file_search(path, args.query.lower())
|
||||
|
||||
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__":
|
||||
|
@ -113,8 +113,7 @@ class Controller(UIMixin, SignalsMixins, Controller_Data):
|
||||
|
||||
|
||||
def do_action_from_menu_controls(self, _action=None, eve=None):
|
||||
if not _action:
|
||||
return
|
||||
if not _action: return
|
||||
|
||||
if not isinstance(_action, str):
|
||||
action = _action.get_name()
|
||||
|
@ -1,18 +1,19 @@
|
||||
# Python imports
|
||||
import os
|
||||
import gc
|
||||
import time
|
||||
|
||||
# Lib imports
|
||||
import gi
|
||||
gi.require_version('Gtk', '3.0')
|
||||
from gi.repository import Gtk
|
||||
from gi.repository import GLib
|
||||
|
||||
# Application imports
|
||||
from .grid_mixin import GridMixin
|
||||
|
||||
|
||||
|
||||
|
||||
class TabMixin(GridMixin):
|
||||
"""docstring for TabMixin"""
|
||||
|
||||
@ -173,8 +174,21 @@ class TabMixin(GridMixin):
|
||||
path = widget.get_text()
|
||||
|
||||
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")
|
||||
query = widget.get_text().replace(dir, "")
|
||||
query = gtk_entry.get_text().replace(dir, "")
|
||||
files = tab.get_files() + tab.get_hidden()
|
||||
|
||||
self.clear_children(path_menu_buttons)
|
||||
@ -192,34 +206,32 @@ class TabMixin(GridMixin):
|
||||
event_system.emit("hide_path_menu")
|
||||
else:
|
||||
event_system.emit("show_path_menu")
|
||||
widget.grab_focus_without_selecting()
|
||||
widget.set_position(-1)
|
||||
buttons = path_menu_buttons.get_children()
|
||||
|
||||
if path.endswith(".") or path == dir:
|
||||
return
|
||||
if len(buttons) == 1:
|
||||
self.slowed_focus(buttons[0])
|
||||
|
||||
if not tab.set_path(path):
|
||||
return
|
||||
@daemon_threaded
|
||||
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}")
|
||||
icon_grid.clear_and_set_new_store()
|
||||
self.update_tab(tab_label, tab, icon_grid.get_store(), wid, tid)
|
||||
|
||||
try:
|
||||
widget.grab_focus_without_selecting()
|
||||
widget.set_position(-1)
|
||||
except Exception as e:
|
||||
pass
|
||||
def do_focused_click(self, button):
|
||||
button.grab_focus()
|
||||
button.clicked()
|
||||
|
||||
def set_path_entry(self, button = None, eve = None):
|
||||
self.path_auto_filled = True
|
||||
state = self.get_current_state()
|
||||
path = f"{state.tab.get_current_directory()}/{button.get_label()}"
|
||||
path_entry = self.builder.get_object("path_entry")
|
||||
|
||||
path_entry.set_text(path)
|
||||
path_entry.grab_focus_without_selecting()
|
||||
path_entry.set_position(-1)
|
||||
event_system.emit("hide_path_menu")
|
||||
|
||||
|
||||
def show_hide_hidden_files(self):
|
||||
wid, tid = self.fm_controller.get_active_wid_and_tid()
|
||||
tab = self.get_fm_window(wid).get_tab_by_id(tid)
|
||||
|
@ -1,17 +1,19 @@
|
||||
# Python imports
|
||||
import os
|
||||
import gc
|
||||
import time
|
||||
|
||||
# Lib imports
|
||||
import gi
|
||||
gi.require_version('Gtk', '3.0')
|
||||
from gi.repository import Gtk
|
||||
from gi.repository import GLib
|
||||
|
||||
# Application imports
|
||||
from .grid_mixin import GridMixin
|
||||
|
||||
|
||||
|
||||
|
||||
class TabMixin(GridMixin):
|
||||
"""docstring for TabMixin"""
|
||||
|
||||
@ -85,6 +87,7 @@ class TabMixin(GridMixin):
|
||||
del watcher
|
||||
del tab
|
||||
|
||||
gc.collect()
|
||||
if not settings_manager.is_trace_debug():
|
||||
self.fm_controller.save_state()
|
||||
|
||||
@ -173,8 +176,21 @@ class TabMixin(GridMixin):
|
||||
path = widget.get_text()
|
||||
|
||||
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")
|
||||
query = widget.get_text().replace(dir, "")
|
||||
query = gtk_entry.get_text().replace(dir, "")
|
||||
files = tab.get_files() + tab.get_hidden()
|
||||
|
||||
self.clear_children(path_menu_buttons)
|
||||
@ -192,27 +208,26 @@ class TabMixin(GridMixin):
|
||||
event_system.emit("hide_path_menu")
|
||||
else:
|
||||
event_system.emit("show_path_menu")
|
||||
widget.grab_focus_without_selecting()
|
||||
widget.set_position(-1)
|
||||
buttons = path_menu_buttons.get_children()
|
||||
|
||||
if path.endswith(".") or path == dir:
|
||||
return
|
||||
if len(buttons) == 1:
|
||||
self.slowed_focus(buttons[0])
|
||||
|
||||
if not tab.set_path(path):
|
||||
return
|
||||
@daemon_threaded
|
||||
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)
|
||||
|
||||
try:
|
||||
widget.grab_focus_without_selecting()
|
||||
widget.set_position(-1)
|
||||
except Exception as e:
|
||||
pass
|
||||
def do_focused_click(self, button):
|
||||
button.grab_focus()
|
||||
button.clicked()
|
||||
|
||||
def set_path_entry(self, button = None, eve = None):
|
||||
self.path_auto_filled = True
|
||||
state = self.get_current_state()
|
||||
path = f"{state.tab.get_current_directory()}/{button.get_label()}"
|
||||
path_entry = self.builder.get_object("path_entry")
|
||||
|
||||
path_entry.set_text(path)
|
||||
path_entry.grab_focus_without_selecting()
|
||||
path_entry.set_position(-1)
|
||||
|
@ -106,7 +106,7 @@ class WindowMixin(TabMixin):
|
||||
|
||||
state = self.get_current_state()
|
||||
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]
|
||||
dir = state.tab.get_current_directory()
|
||||
@ -114,7 +114,8 @@ class WindowMixin(TabMixin):
|
||||
|
||||
if isdir(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:
|
||||
event_system.emit("open_files")
|
||||
except WindowException as e:
|
||||
|
@ -94,4 +94,5 @@ class Window(Gtk.ApplicationWindow):
|
||||
|
||||
settings_manager.clear_pid()
|
||||
time.sleep(event_sleep_time)
|
||||
|
||||
Gtk.main_quit()
|
||||
|
11
src/versions/solarfm-0.0.1/solarfm/data.txt
Normal file
11
src/versions/solarfm-0.0.1/solarfm/data.txt
Normal 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
|
Loading…
Reference in New Issue
Block a user