refactor(src/window/panel/components): drop google_lens_indicator and simplify command handling
Refactor ModPopup to use shell -c for commands, adjust icon size default, and improve button click handling. Remove unused GoogleLensIndicator component and related import/usage.
This commit is contained in:
3 files changed
+28
-35
No files matched your search
@@ -79,7 +79,7 @@ class ModPopup(AppletWindow):
|
||||
|
||||
def _run_command(self, cmd):
|
||||
self.close_applet()
|
||||
thread(run_command, cmd.split(), timeout=30)
|
||||
thread(run_command, ["sh", "-c", cmd], timeout=30)
|
||||
|
||||
def toggle(self, pointing_to=None):
|
||||
if pointing_to:
|
||||
@@ -112,11 +112,11 @@ class CustomMods(Box):
|
||||
mods = {}
|
||||
for mod_name, val in data.get("Mods", {}).items():
|
||||
icon = val.get("icon", "")
|
||||
icon_size = val.get("icon-size", 18)
|
||||
icon_size = val.get("icon-size", 16)
|
||||
order = val.get("order", 99)
|
||||
on_clicked = val.get("on-clicked")
|
||||
options = val.get("options", [])
|
||||
mods[mod_name] = {
|
||||
mod_data = {
|
||||
"name": mod_name,
|
||||
"icon": icon,
|
||||
"icon_size": icon_size,
|
||||
@@ -124,12 +124,33 @@ class CustomMods(Box):
|
||||
"on-clicked": on_clicked,
|
||||
"options": options,
|
||||
}
|
||||
for k in ("on-left", "on-middle", "on-right"):
|
||||
v = val.get(k)
|
||||
if v is not None:
|
||||
mod_data[k] = v
|
||||
mods[mod_name] = mod_data
|
||||
|
||||
self._rebuild(mods)
|
||||
|
||||
def _on_btn_press(self, btn, event, mod):
|
||||
button_map = {1: "on-left", 2: "on-middle", 3: "on-right"}
|
||||
button_key = button_map.get(event.button)
|
||||
per_button_cmd = mod.get(button_key) if button_key else None
|
||||
popup = self._mod_popups.get(mod["name"])
|
||||
|
||||
if per_button_cmd is not None:
|
||||
if popup and popup._is_open:
|
||||
popup.toggle()
|
||||
thread(run_command, ["sh", "-c", per_button_cmd], timeout=30)
|
||||
return True
|
||||
|
||||
cmd = mod.get("on-clicked")
|
||||
if cmd:
|
||||
if popup and popup._is_open:
|
||||
popup.toggle()
|
||||
thread(run_command, ["sh", "-c", cmd], timeout=30)
|
||||
return True
|
||||
|
||||
if event.button == 3:
|
||||
if popup:
|
||||
popup.toggle(pointing_to=btn)
|
||||
@@ -140,16 +161,14 @@ class CustomMods(Box):
|
||||
popup.toggle()
|
||||
return True
|
||||
|
||||
cmd = mod.get("on-clicked")
|
||||
if cmd:
|
||||
thread(run_command, cmd.split(), timeout=30)
|
||||
return True
|
||||
|
||||
if popup:
|
||||
popup.toggle(pointing_to=btn)
|
||||
return True
|
||||
|
||||
return False
|
||||
if event.button == 2 and popup:
|
||||
popup.toggle(pointing_to=btn)
|
||||
|
||||
return True
|
||||
|
||||
def _rebuild(self, mods):
|
||||
for child in list(self.get_children()):
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
from fabric.widgets.button import Button
|
||||
|
||||
from services.google_lens import GoogleLens
|
||||
from utils.functions import thread
|
||||
from utils.utils import setup_cursor_hover, svg_file
|
||||
|
||||
|
||||
class GoogleLensIndicator(Button):
|
||||
def __init__(self, **kwargs):
|
||||
super().__init__(name="panel-button", **kwargs)
|
||||
self._lens = GoogleLens.get_initial()
|
||||
|
||||
self.icon = svg_file("google-lens.svg", size=16)
|
||||
self.add(self.icon)
|
||||
|
||||
setup_cursor_hover(self, "pointer")
|
||||
self.connect("clicked", self.on_clicked)
|
||||
|
||||
def on_clicked(self, *_):
|
||||
thread(self._lens.search)
|
||||
@@ -16,7 +16,6 @@ from window.notification.notification_center import NotificationCenter
|
||||
from window.panel.components.enhanced_system_tray import apply_enhanced_system_tray
|
||||
from window.panel.components.globalmenu import GlobalMenu
|
||||
from window.panel.components.custom_mods import CustomMods
|
||||
from window.panel.components.google_lens_indicator import GoogleLensIndicator
|
||||
from window.panel.components.indicators import (
|
||||
BatteryIndicator,
|
||||
BluetoothIndicator,
|
||||
@@ -111,7 +110,6 @@ class Panel(Window):
|
||||
)
|
||||
setup_cursor_hover(self.datetime_btn, "pointer")
|
||||
|
||||
self.google_lens_indicator = GoogleLensIndicator()
|
||||
self.custom_mods = CustomMods(parent_window=self)
|
||||
self.workspace_indicator = WorkspaceIndicator()
|
||||
self.recording_indicator = RecordingIndicator()
|
||||
@@ -241,8 +239,6 @@ class Panel(Window):
|
||||
right_children = []
|
||||
if config_data.get("custom_mods", True):
|
||||
right_children.append(self.custom_mods)
|
||||
if config_data.get("google_lens", True):
|
||||
right_children.append(self.google_lens_indicator)
|
||||
if config_data.get("workspace_indicator", True):
|
||||
right_children.append(self.workspace_indicator)
|
||||
|
||||
@@ -276,7 +272,6 @@ class Panel(Window):
|
||||
keys = {
|
||||
"imac_button",
|
||||
"global_menu",
|
||||
"google_lens",
|
||||
"custom_mods",
|
||||
"workspace_indicator",
|
||||
"systray",
|
||||
@@ -338,7 +333,6 @@ class Panel(Window):
|
||||
# Destroy components
|
||||
for component in [
|
||||
self.globalmenu,
|
||||
self.google_lens_indicator,
|
||||
self.custom_mods,
|
||||
self.workspace_indicator,
|
||||
self.recording_indicator,
|
||||
|
||||
Reference in new issue
Block a user