2022-07-21 04:57:06 +00:00
|
|
|
# Python imports
|
2022-10-04 03:14:18 +00:00
|
|
|
import os, threading, inspect
|
2022-07-21 04:57:06 +00:00
|
|
|
|
|
|
|
# Lib imports
|
|
|
|
import gi
|
|
|
|
gi.require_version('Gtk', '3.0')
|
2022-10-03 05:52:50 +00:00
|
|
|
from gi.repository import Gtk, GLib
|
2022-07-21 04:57:06 +00:00
|
|
|
|
|
|
|
# Application imports
|
2022-09-06 02:21:04 +00:00
|
|
|
from plugins.plugin_base import PluginBase
|
2022-10-04 03:14:18 +00:00
|
|
|
from .mixins.file_search_mixin import FileSearchMixin
|
|
|
|
from .mixins.grep_search_mixin import GrepSearchMixin
|
|
|
|
from .utils.ipc_server import IPCServer
|
2022-07-21 04:57:06 +00:00
|
|
|
|
2022-10-03 05:52:50 +00:00
|
|
|
|
|
|
|
|
2022-07-21 04:57:06 +00:00
|
|
|
# NOTE: Threads WILL NOT die with parent's destruction.
|
|
|
|
def threaded(fn):
|
|
|
|
def wrapper(*args, **kwargs):
|
|
|
|
threading.Thread(target=fn, args=args, kwargs=kwargs, daemon=False).start()
|
|
|
|
return wrapper
|
|
|
|
|
|
|
|
# NOTE: Threads WILL die with parent's destruction.
|
|
|
|
def daemon_threaded(fn):
|
|
|
|
def wrapper(*args, **kwargs):
|
|
|
|
threading.Thread(target=fn, args=args, kwargs=kwargs, daemon=True).start()
|
|
|
|
return wrapper
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2022-10-04 03:14:18 +00:00
|
|
|
class Plugin(IPCServer, FileSearchMixin, GrepSearchMixin, PluginBase):
|
2022-07-21 04:57:06 +00:00
|
|
|
def __init__(self):
|
2022-09-06 02:21:04 +00:00
|
|
|
super().__init__()
|
|
|
|
|
2022-08-13 03:54:16 +00:00
|
|
|
self.path = os.path.dirname(os.path.realpath(__file__))
|
|
|
|
self.name = "Search" # NOTE: Need to remove after establishing private bidirectional 1-1 message bus
|
|
|
|
# where self.name should not be needed for message comms
|
2022-07-21 04:57:06 +00:00
|
|
|
self._GLADE_FILE = f"{self.path}/search_dialog.glade"
|
|
|
|
|
2022-09-06 02:21:04 +00:00
|
|
|
self._search_dialog = None
|
2022-07-21 04:57:06 +00:00
|
|
|
self._active_path = None
|
|
|
|
self._file_list = None
|
|
|
|
self._grep_list = None
|
|
|
|
self._grep_proc = None
|
|
|
|
self._list_proc = None
|
2022-10-04 03:14:18 +00:00
|
|
|
self.pause_fifo_update = False
|
|
|
|
self.update_list_ui_buffer = ()
|
2022-07-21 04:57:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
def get_ui_element(self):
|
2022-09-06 02:21:04 +00:00
|
|
|
button = Gtk.Button(label=self.name)
|
2022-10-04 03:14:18 +00:00
|
|
|
button.connect("button-release-event", self._show_page)
|
2022-09-06 02:21:04 +00:00
|
|
|
return button
|
|
|
|
|
|
|
|
def run(self):
|
2022-07-21 04:57:06 +00:00
|
|
|
self._builder = Gtk.Builder()
|
|
|
|
self._builder.add_from_file(self._GLADE_FILE)
|
|
|
|
|
|
|
|
classes = [self]
|
|
|
|
handlers = {}
|
|
|
|
for c in classes:
|
|
|
|
methods = None
|
|
|
|
try:
|
|
|
|
methods = inspect.getmembers(c, predicate=inspect.ismethod)
|
|
|
|
handlers.update(methods)
|
|
|
|
except Exception as e:
|
|
|
|
print(repr(e))
|
|
|
|
|
|
|
|
self._builder.connect_signals(handlers)
|
|
|
|
|
|
|
|
self._search_dialog = self._builder.get_object("search_dialog")
|
|
|
|
self._grep_list = self._builder.get_object("grep_list")
|
|
|
|
self._file_list = self._builder.get_object("file_list")
|
2022-10-03 05:52:50 +00:00
|
|
|
self.fsearch = self._builder.get_object("fsearch")
|
2022-07-21 04:57:06 +00:00
|
|
|
|
2022-10-03 05:52:50 +00:00
|
|
|
self._event_system.subscribe("update-file-ui", self._load_file_ui)
|
|
|
|
self._event_system.subscribe("update-grep-ui", self._load_grep_ui)
|
2022-07-21 04:57:06 +00:00
|
|
|
|
2022-10-04 01:50:38 +00:00
|
|
|
self.create_ipc_listener()
|
2022-10-03 05:52:50 +00:00
|
|
|
|
|
|
|
|
2022-10-04 03:14:18 +00:00
|
|
|
def _show_page(self, widget=None, eve=None):
|
2022-10-03 05:52:50 +00:00
|
|
|
self._event_system.emit("get_current_state")
|
2022-07-21 04:57:06 +00:00
|
|
|
|
2022-09-29 22:22:33 +00:00
|
|
|
state = self._fm_state
|
2022-07-21 04:57:06 +00:00
|
|
|
self._event_message = None
|
|
|
|
|
|
|
|
self._active_path = state.tab.get_current_directory()
|
|
|
|
response = self._search_dialog.run()
|
|
|
|
self._search_dialog.hide()
|
|
|
|
|
|
|
|
|
2022-10-04 03:14:18 +00:00
|
|
|
def clear_children(self, widget: type) -> None:
|
|
|
|
''' Clear children of a gtk widget. '''
|
|
|
|
for child in widget.get_children():
|
|
|
|
widget.remove(child)
|