WIP Query/Search functionality

This commit is contained in:
itdominator 2023-04-10 23:11:32 -05:00
parent fd882743b8
commit ff7a492e35
5 changed files with 113 additions and 10 deletions

View File

@ -12,9 +12,10 @@ from gi.repository import GLib
# Application imports
from .mixins.signals_mixins import SignalsMixins
from .controller_data import ControllerData
from .query_controller import QueryController
from .widgets.create_notebook_widget import CreateNotebookWidget
from .widgets.dialogs.message_widget import MessageWidget
from .widgets.dialogs.section_header_updater_widget import SectionHeaderUpdater
from .widgets.create_notebook_widget import CreateNotebookWidget
from .widgets.sections.sections_widget import Sections
@ -58,6 +59,7 @@ class Controller(SignalsMixins, ControllerData):
event_system.subscribe("load_notebook_data", self._load_notebook_data)
def _load_widgets(self):
QueryController()
CreateNotebookWidget()
MessageWidget()
SectionHeaderUpdater()

View File

@ -0,0 +1,94 @@
# Python imports
# Lib imports
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
# Application imports
class QuerySelectorList(Gtk.Box):
def __init__(self):
super(QuerySelectorList, self).__init__()
self._setup_styling()
self._setup_signals()
def _setup_styling(self):
self.set_orientation(1)
def _setup_signals(self):
...
class QueryController(Gtk.Popover):
def __init__(self):
super(QueryController, self).__init__()
self._query_selector_list = QuerySelectorList()
self.queryable_widgets = []
self._setup_styling()
self._setup_signals()
self._subscribe_to_events()
self._load_widgets()
def _setup_styling(self):
self.set_position(3)
self.set_size_request(256, 480)
def _setup_signals(self):
...
def _subscribe_to_events(self):
event_system.subscribe("register_to_query_controller", self._register_to_query_controller)
event_system.subscribe("handle_search_query", self._handle_search_query)
def _load_widgets(self):
scroll_win = Gtk.ScrolledWindow()
viewport = Gtk.Viewport()
viewport.add(self._query_selector_list)
scroll_win.add(viewport)
self.add(scroll_win)
scroll_win.show_all()
def _register_to_query_controller(self, widget, provider):
self.queryable_widgets.append([widget, provider])
def _handle_search_query(self, widget, query):
self.set_relative_to(widget)
self.clear_children(self._query_selector_list)
for _widget, collector in self.queryable_widgets:
if query.lower() in collector().lower():
path = self.get_path_names(_widget)
button = Gtk.Button(label=path)
button.connect("button-release-event", self._focus_widget, _widget)
self._query_selector_list.add(button)
self._query_selector_list.show_all()
self.show()
def _focus_widget(self, widget = None, eve = None, target_widget = None):
target_widget.show()
target_widget.grab_focus()
def clear_children(self, widget: type) -> None:
for child in widget.get_children():
widget.remove(child)
def get_path_names(self, widget):
i = 0
while i < 15:
i += 1
if "page_widget.Page" in str(widget.__class__):
return f"{widget.get_parent().get_parent()._name} > {widget._name}"
else:
widget = widget.get_parent()
return None

View File

@ -42,16 +42,13 @@ class Pages(Gtk.Notebook):
start_box = Gtk.Box()
end_box = Gtk.Box()
search = Gtk.SearchEntry()
search.set_placeholder_text("Search...")
search.connect("changed", self._text_search)
add_btn = Gtk.Button()
add_btn = Gtk.Button(label="Add Page")
add_btn.set_image( Gtk.Image.new_from_icon_name("add", 4) )
add_btn.set_always_show_image(True)
add_btn.set_hexpand(True)
add_btn.set_size_request(162, -1)
add_btn.connect("released", self.create_page_view)
start_box.add(search)
start_box.add(add_btn)
start_box.show_all()
@ -95,9 +92,6 @@ class Pages(Gtk.Notebook):
data = [parent._manifest_pth, parent._name, parent._date]
event_system.emit("update_section_title", (label, data))
def _text_search(self, widget = None, eve = None):
...
def _load_pages_data(self):
if not self._section_pth:
raise PagesException("No section path provided...")

View File

@ -40,6 +40,10 @@ class Sections(Gtk.Notebook):
start_box = Gtk.Box()
end_box = Gtk.Box()
search = Gtk.SearchEntry()
search.set_placeholder_text("Search...")
search.connect("changed", self._text_search)
add_btn = Gtk.Button()
add_btn.set_image( Gtk.Image.new_from_icon_name("add", 4) )
add_btn.set_always_show_image(True)
@ -56,6 +60,7 @@ class Sections(Gtk.Notebook):
start_box.add(widgets_btn)
end_box.add(add_btn)
end_box.add(search)
start_box.show_all()
end_box.show_all()
@ -64,6 +69,10 @@ class Sections(Gtk.Notebook):
self.set_action_widget(start_box, 0)
self.set_action_widget(end_box, 1)
def _text_search(self, widget = None, eve = None):
query = widget.get_text()
event_system.emit("handle_search_query", (widget, query))
def _close_tab(self, button, pages, eve = None):
if self.get_n_pages() == 1:
return

View File

@ -22,6 +22,7 @@ class TextAreaWidget(WidgetSaveLoadController, GtkSource.View):
self._subscribe_to_events()
self._load_widgets()
event_system.emit("register_to_query_controller", (self, self.get_query_data))
self.show()
@ -44,6 +45,9 @@ class TextAreaWidget(WidgetSaveLoadController, GtkSource.View):
start, end = self.buffer.get_start_iter(), self.buffer.get_end_iter()
return self.buffer.get_slice(start, end, True)
def get_query_data(self):
return self.get_buffer_text()
def get_saveable_data(self):
self.save_collection["data"] = self.get_buffer_text()
self.save_collection["widget_type"] = str(type(self).__name__)