custom apps
This commit is contained in:
parent
5c5fce2581
commit
6366f57d6e
@ -11,6 +11,7 @@ make the configuration way more faster than it's supposed to be
|
|||||||
|
|
||||||
import operator
|
import operator
|
||||||
from collections.abc import Iterator
|
from collections.abc import Iterator
|
||||||
|
from dataclasses import dataclass
|
||||||
from fabric.widgets.box import Box
|
from fabric.widgets.box import Box
|
||||||
from fabric.widgets.label import Label
|
from fabric.widgets.label import Label
|
||||||
from fabric.widgets.button import Button
|
from fabric.widgets.button import Button
|
||||||
@ -19,6 +20,51 @@ from fabric.widgets.entry import Entry
|
|||||||
from fabric.widgets.scrolledwindow import ScrolledWindow
|
from fabric.widgets.scrolledwindow import ScrolledWindow
|
||||||
from fabric.widgets.wayland import WaylandWindow as Window
|
from fabric.widgets.wayland import WaylandWindow as Window
|
||||||
from fabric.utils import DesktopApp, get_desktop_applications, idle_add, remove_handler
|
from fabric.utils import DesktopApp, get_desktop_applications, idle_add, remove_handler
|
||||||
|
import subprocess
|
||||||
|
from time import sleep
|
||||||
|
import threading
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass()
|
||||||
|
class CustomApp:
|
||||||
|
name: str
|
||||||
|
generic_name: str | None
|
||||||
|
display_name: str | None
|
||||||
|
description: str | None
|
||||||
|
executable: str | None
|
||||||
|
command_line: str | None
|
||||||
|
hidden: bool
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
name,
|
||||||
|
display_name=None,
|
||||||
|
executable=None,
|
||||||
|
generic_name=None,
|
||||||
|
description=None,
|
||||||
|
command_line=None,
|
||||||
|
hidden=False,
|
||||||
|
):
|
||||||
|
self.name = name
|
||||||
|
self.generic_name = generic_name
|
||||||
|
self.display_name = display_name
|
||||||
|
self.description = description
|
||||||
|
self.executable = executable
|
||||||
|
self.command_line = command_line
|
||||||
|
self.hidden = hidden
|
||||||
|
|
||||||
|
def launch(self):
|
||||||
|
def background():
|
||||||
|
subprocess.run([self.command_line])
|
||||||
|
|
||||||
|
threading.Thread(target=background, daemon=True).start()
|
||||||
|
|
||||||
|
def get_icon_pixbuf(
|
||||||
|
self,
|
||||||
|
size: int = 48,
|
||||||
|
default_icon: str | None = "image-missing",
|
||||||
|
) -> None:
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
class AppLauncher(Window):
|
class AppLauncher(Window):
|
||||||
@ -34,6 +80,9 @@ class AppLauncher(Window):
|
|||||||
)
|
)
|
||||||
self._arranger_handler: int = 0
|
self._arranger_handler: int = 0
|
||||||
self._all_apps = get_desktop_applications()
|
self._all_apps = get_desktop_applications()
|
||||||
|
self._custom_apps = [
|
||||||
|
CustomApp("Screenshot Clipboard", command_line="grim2clip")
|
||||||
|
]
|
||||||
|
|
||||||
self.viewport = Box(spacing=2, orientation="v")
|
self.viewport = Box(spacing=2, orientation="v")
|
||||||
self.search_entry = Entry(
|
self.search_entry = Entry(
|
||||||
@ -81,11 +130,12 @@ class AppLauncher(Window):
|
|||||||
# remove all children from the viewport
|
# remove all children from the viewport
|
||||||
self.viewport.children = []
|
self.viewport.children = []
|
||||||
|
|
||||||
|
combined_apps = self._all_apps + self._custom_apps
|
||||||
# make a new iterator containing the filtered apps
|
# make a new iterator containing the filtered apps
|
||||||
filtered_apps_iter = iter(
|
filtered_apps_iter = iter(
|
||||||
[
|
[
|
||||||
app
|
app
|
||||||
for app in self._all_apps
|
for app in combined_apps
|
||||||
if query.casefold()
|
if query.casefold()
|
||||||
in (
|
in (
|
||||||
(app.display_name or "")
|
(app.display_name or "")
|
||||||
@ -137,6 +187,6 @@ class AppLauncher(Window):
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
tooltip_text=app.description,
|
tooltip_text=app.description,
|
||||||
on_clicked=lambda *_: (app.launch(), self.hide()),
|
on_clicked=lambda *_: (self.hide(), app.launch()),
|
||||||
**kwargs,
|
**kwargs,
|
||||||
)
|
)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user