Added searchCommand entry plus fixed clock not updating properly
This commit is contained in:
@@ -6,6 +6,7 @@ gi.require_version('Gtk', '3.0')
|
|||||||
from gi.repository import Gtk
|
from gi.repository import Gtk
|
||||||
|
|
||||||
# Application imports
|
# Application imports
|
||||||
|
from ..widgets.search_command_widget import SearchCommandWidget
|
||||||
from ..widgets.tab_widget import TabWidget
|
from ..widgets.tab_widget import TabWidget
|
||||||
|
|
||||||
|
|
||||||
@@ -40,4 +41,5 @@ class CenterContainer(Gtk.Box):
|
|||||||
...
|
...
|
||||||
|
|
||||||
def _load_widgets(self):
|
def _load_widgets(self):
|
||||||
|
self.add(SearchCommandWidget())
|
||||||
self.add(TabWidget())
|
self.add(TabWidget())
|
||||||
|
|||||||
@@ -19,10 +19,7 @@ class CategoryListWidget(Gtk.ButtonBox):
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
super(CategoryListWidget, self).__init__()
|
super(CategoryListWidget, self).__init__()
|
||||||
|
|
||||||
self.ctx = self.get_style_context()
|
self.active_category = None
|
||||||
self.dir_watchers: [] = []
|
|
||||||
|
|
||||||
self.active_category: str = 'Accessories'
|
|
||||||
self.category_dict: {} = {
|
self.category_dict: {} = {
|
||||||
"Accessories": [],
|
"Accessories": [],
|
||||||
"Multimedia": [],
|
"Multimedia": [],
|
||||||
@@ -37,33 +34,44 @@ class CategoryListWidget(Gtk.ButtonBox):
|
|||||||
"Other": []
|
"Other": []
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.dir_watchers: [] = []
|
||||||
|
|
||||||
self._setup_styling()
|
self._setup_styling()
|
||||||
self._setup_signals()
|
self._setup_signals()
|
||||||
self._subscribe_to_events()
|
self._subscribe_to_events()
|
||||||
self._load_widgets()
|
self._load_widgets()
|
||||||
self.fill_menu_objects()
|
self._fill_menu_objects()
|
||||||
|
|
||||||
self.show_all()
|
self.show_all()
|
||||||
|
|
||||||
|
|
||||||
def _setup_styling(self):
|
def _setup_styling(self):
|
||||||
self.set_orientation(Gtk.Orientation.VERTICAL)
|
self.set_orientation(Gtk.Orientation.VERTICAL)
|
||||||
self.ctx.add_class("category-list-widget")
|
ctx = self.get_style_context()
|
||||||
|
ctx.add_class("category-list-widget")
|
||||||
|
|
||||||
def _setup_signals(self):
|
def _setup_signals(self):
|
||||||
self._load_dir_watchers()
|
self._load_dir_watchers()
|
||||||
|
|
||||||
def _subscribe_to_events(self):
|
def _subscribe_to_events(self):
|
||||||
|
event_system.subscribe("get-active-category", self.get_active_category)
|
||||||
event_system.subscribe("refresh-active-category", self.refresh_active_category)
|
event_system.subscribe("refresh-active-category", self.refresh_active_category)
|
||||||
|
event_system.subscribe("query-all-categories", self.query_all_categories)
|
||||||
|
|
||||||
def _load_widgets(self):
|
def _load_widgets(self):
|
||||||
for category in self.category_dict.keys():
|
for category in self.category_dict.keys():
|
||||||
button = Gtk.Button(label = category)
|
button = Gtk.Button(label = category)
|
||||||
button.connect("clicked", self.set_active_category)
|
button.connect("clicked", self._set_active_category)
|
||||||
button.show()
|
button.show()
|
||||||
|
|
||||||
self.add(button)
|
self.add(button)
|
||||||
|
|
||||||
|
if category == "Accessories":
|
||||||
|
self.active_category = button
|
||||||
|
self.active_category.get_style_context().add_class("active-category")
|
||||||
|
|
||||||
|
self.category_dict["All"] = []
|
||||||
|
|
||||||
def _reset_dir_watchers(self):
|
def _reset_dir_watchers(self):
|
||||||
self._clear_dir_watchers()
|
self._clear_dir_watchers()
|
||||||
self._load_dir_watchers()
|
self._load_dir_watchers()
|
||||||
@@ -99,16 +107,16 @@ class CategoryListWidget(Gtk.ButtonBox):
|
|||||||
GLib.idle_add(self._reload_meu)
|
GLib.idle_add(self._reload_meu)
|
||||||
|
|
||||||
def _reload_meu(self):
|
def _reload_meu(self):
|
||||||
for group in self.category_dict:
|
for category in self.category_dict:
|
||||||
self.category_dict[group].clear()
|
self.category_dict[category].clear()
|
||||||
|
|
||||||
self.fill_menu_objects()
|
self._fill_menu_objects()
|
||||||
event_system.emit(
|
event_system.emit(
|
||||||
"load-active-category",
|
"load-active-category",
|
||||||
(self.category_dict[ self.active_category ],)
|
(self.category_dict[ self.active_category.get_label() ],)
|
||||||
)
|
)
|
||||||
|
|
||||||
def fill_menu_objects(self, apps: [] = []):
|
def _fill_menu_objects(self, apps: [] = []):
|
||||||
if not apps:
|
if not apps:
|
||||||
apps = find_apps()
|
apps = find_apps()
|
||||||
|
|
||||||
@@ -147,29 +155,49 @@ class CategoryListWidget(Gtk.ButtonBox):
|
|||||||
else:
|
else:
|
||||||
group = "Other"
|
group = "Other"
|
||||||
|
|
||||||
self.category_dict[group].append(
|
entry = {
|
||||||
{
|
"title": title,
|
||||||
"title": title,
|
"groups": groups,
|
||||||
"groups": groups,
|
"comment": comment,
|
||||||
"comment": comment,
|
"exec": mainExec,
|
||||||
"exec": mainExec,
|
"tryExec": tryExec,
|
||||||
"tryExec": tryExec,
|
"fileName": fPath.split("/")[-1],
|
||||||
"fileName": fPath.split("/")[-1],
|
"filePath": fPath,
|
||||||
"filePath": fPath,
|
"icon": icon
|
||||||
"icon": icon
|
}
|
||||||
}
|
|
||||||
)
|
self.category_dict["All"].append(entry)
|
||||||
|
self.category_dict[group].append(entry)
|
||||||
|
|
||||||
|
def _set_active_category(self, button):
|
||||||
|
self.active_category.get_style_context().remove_class("active-category")
|
||||||
|
self.active_category = button
|
||||||
|
self.active_category.get_style_context().add_class("active-category")
|
||||||
|
|
||||||
def set_active_category(self, button):
|
|
||||||
self.active_category = button.get_label()
|
|
||||||
event_system.emit(
|
event_system.emit(
|
||||||
"load-active-category",
|
"load-active-category",
|
||||||
(self.category_dict[ self.active_category ],)
|
(self.category_dict[ self.active_category.get_label() ],)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def query_all_categories(self, query: str):
|
||||||
|
self.active_category.get_style_context().remove_class("active-category")
|
||||||
|
|
||||||
|
filtered_group = []
|
||||||
|
for app in self.category_dict["All"]:
|
||||||
|
if (
|
||||||
|
query in app["title"].lower()or \
|
||||||
|
query in app["comment"].lower()
|
||||||
|
):
|
||||||
|
filtered_group.append(app)
|
||||||
|
|
||||||
|
event_system.emit("load-active-category", (filtered_group,))
|
||||||
|
|
||||||
|
def get_active_category(self):
|
||||||
|
return self.active_category
|
||||||
|
|
||||||
def refresh_active_category(self):
|
def refresh_active_category(self):
|
||||||
|
self.active_category.get_style_context().add_class("active-category")
|
||||||
event_system.emit(
|
event_system.emit(
|
||||||
"load-active-category",
|
"load-active-category",
|
||||||
(self.category_dict[ self.active_category ],)
|
(self.category_dict[ self.active_category.get_label() ],)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ from datetime import datetime
|
|||||||
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 GObject
|
from gi.repository import GLib
|
||||||
|
|
||||||
# Application imports
|
# Application imports
|
||||||
|
|
||||||
@@ -77,7 +77,7 @@ class ClockWidget(Gtk.EventBox):
|
|||||||
self._update_face()
|
self._update_face()
|
||||||
self.add(self.label)
|
self.add(self.label)
|
||||||
|
|
||||||
GObject.timeout_add(59000, self._update_face)
|
GLib.timeout_add(59000 , self._update_face)
|
||||||
|
|
||||||
def _update_face(self):
|
def _update_face(self):
|
||||||
dt_now = datetime.now()
|
dt_now = datetime.now()
|
||||||
@@ -87,6 +87,8 @@ class ClockWidget(Gtk.EventBox):
|
|||||||
|
|
||||||
self.label.set_label(time_str)
|
self.label.set_label(time_str)
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
def _toggle_cal_popover(self, widget, eve):
|
def _toggle_cal_popover(self, widget, eve):
|
||||||
if (self.calendar.get_visible() == True):
|
if (self.calendar.get_visible() == True):
|
||||||
self.calendar.popdown()
|
self.calendar.popdown()
|
||||||
|
|||||||
86
src/core/widgets/search_command_widget.py
Normal file
86
src/core/widgets/search_command_widget.py
Normal file
@@ -0,0 +1,86 @@
|
|||||||
|
# Python imports
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
# Lib imports
|
||||||
|
import gi
|
||||||
|
gi.require_version('Gtk', '3.0')
|
||||||
|
from gi.repository import Gtk
|
||||||
|
from gi.repository import GLib
|
||||||
|
|
||||||
|
# Application imports
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class SearchCommandWidget(Gtk.SearchEntry):
|
||||||
|
def __init__(self):
|
||||||
|
super(SearchCommandWidget, self).__init__()
|
||||||
|
|
||||||
|
self.mode = ""
|
||||||
|
self.timeout_id = None
|
||||||
|
|
||||||
|
self._setup_styling()
|
||||||
|
self._setup_signals()
|
||||||
|
self._subscribe_to_events()
|
||||||
|
self._load_widgets()
|
||||||
|
|
||||||
|
self.show()
|
||||||
|
|
||||||
|
|
||||||
|
def _setup_styling(self):
|
||||||
|
self.set_placeholder_text("Apps /a | Search /s | Command /c ...")
|
||||||
|
|
||||||
|
def _setup_signals(self):
|
||||||
|
self.connect("search-changed", self._search_changed)
|
||||||
|
self.connect("activate", self._handle_enter)
|
||||||
|
|
||||||
|
def _subscribe_to_events(self):
|
||||||
|
event_system.subscribe("focus-search", self._focus_search)
|
||||||
|
|
||||||
|
def _load_widgets(self):
|
||||||
|
...
|
||||||
|
|
||||||
|
def _focus_search(self):
|
||||||
|
self.grab_focus()
|
||||||
|
|
||||||
|
def _search_changed(self, widget):
|
||||||
|
if self.timeout_id:
|
||||||
|
GLib.source_remove(self.timeout_id)
|
||||||
|
self.timeout_id = None
|
||||||
|
|
||||||
|
entry = widget.get_text().strip()
|
||||||
|
if not entry or len(entry) <= 3:
|
||||||
|
self.mode = ""
|
||||||
|
self.request = ""
|
||||||
|
|
||||||
|
event_system.emit("refresh-active-category")
|
||||||
|
return
|
||||||
|
|
||||||
|
self.mode = entry[0:2]
|
||||||
|
self.request = entry[2:].strip()
|
||||||
|
self.timeout_id = GLib.timeout_add(600, self._match_mode)
|
||||||
|
|
||||||
|
def _match_mode(self):
|
||||||
|
GLib.source_remove(self.timeout_id)
|
||||||
|
self.timeout_id = None
|
||||||
|
|
||||||
|
match self.mode:
|
||||||
|
case "/a":
|
||||||
|
self.query_all_categories()
|
||||||
|
case "/s":
|
||||||
|
sub_mode = self.request[0:2]
|
||||||
|
match sub_mode:
|
||||||
|
case "/f ":
|
||||||
|
...
|
||||||
|
case "/d":
|
||||||
|
...
|
||||||
|
case _:
|
||||||
|
...
|
||||||
|
...
|
||||||
|
case _:
|
||||||
|
...
|
||||||
|
|
||||||
|
def _handle_enter(self, widget):
|
||||||
|
if self.mode != "/c": return
|
||||||
|
|
||||||
|
def query_all_categories(self):
|
||||||
|
event_system.emit("query-all-categories", (self.request,))
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
"keybindings": {
|
"keybindings": {
|
||||||
"help" : "F1",
|
"help" : "F1",
|
||||||
"guake_key" : "<Shift><Control>KP_Insert",
|
"guake_key" : "<Shift><Control>KP_Insert",
|
||||||
|
"focus-search" : "<Control>s",
|
||||||
"focus-apps" : "<Control>a",
|
"focus-apps" : "<Control>a",
|
||||||
"focus-terminal" : "<Control>t"
|
"focus-terminal" : "<Control>t"
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user