huge updates but idk what i update
This commit is contained in:
1 parent
5d88e059d9
commit
4350f7459e
19 files changed
+563
-617
No files matched your search
@@ -1,6 +1,7 @@
|
||||
import os
|
||||
import subprocess
|
||||
from typing import List
|
||||
from functools import partial
|
||||
from fabric import Fabricator
|
||||
from fabric.widgets.box import Box
|
||||
from fabric.widgets.button import Button
|
||||
@@ -8,7 +9,7 @@ from fabric.widgets.entry import Entry
|
||||
from fabric.widgets.label import Label
|
||||
from fabric.widgets.scrolledwindow import ScrolledWindow
|
||||
from gi.repository import GLib
|
||||
import snippets.iconss as icons
|
||||
import utils.icons as icons
|
||||
|
||||
|
||||
class Cliphist(Box):
|
||||
@@ -19,15 +20,15 @@ class Cliphist(Box):
|
||||
visible=False,
|
||||
**kwargs,
|
||||
)
|
||||
|
||||
self._arranger_handler = 0
|
||||
self.cliphist_manager = CliphistManager(self)
|
||||
self.viewport = None
|
||||
self.launcher = kwargs["launcher"]
|
||||
|
||||
self.search_entry = Entry(
|
||||
name="search-entry",
|
||||
h_expand=True,
|
||||
on_activate=lambda entry, *_: self.handle_search(entry.get_text()),
|
||||
on_activate=self._on_search_activate,
|
||||
)
|
||||
|
||||
self.header_box = Box(
|
||||
@@ -55,6 +56,9 @@ class Cliphist(Box):
|
||||
|
||||
self.add(self.launcher_box)
|
||||
|
||||
def _on_search_activate(self, entry, *args):
|
||||
self.handle_search(entry.get_text())
|
||||
|
||||
def open_launcher(self):
|
||||
if not self.viewport:
|
||||
self.viewport = Box(name="viewport", spacing=4, orientation="v")
|
||||
@@ -63,7 +67,6 @@ class Cliphist(Box):
|
||||
spacing=10,
|
||||
min_content_size=(-1, -1),
|
||||
h_scrollbar_policy="never",
|
||||
# v_scrollbar_policy="never",
|
||||
child=self.viewport,
|
||||
)
|
||||
self.launcher_box.add(self.scrolled_window)
|
||||
@@ -89,9 +92,10 @@ class CliphistManager:
|
||||
self.wl_paste_watcher = Fabricator(
|
||||
poll_from="wl-paste --watch echo", stream=True, interval=-1
|
||||
)
|
||||
self.wl_paste_watcher.connect(
|
||||
"changed", lambda *_: self.update_cliphist_history()
|
||||
)
|
||||
self.wl_paste_watcher.connect("changed", self._on_wl_paste_changed)
|
||||
|
||||
def _on_wl_paste_changed(self, *args):
|
||||
self.update_cliphist_history()
|
||||
|
||||
def get_clip_history(self) -> List[dict]:
|
||||
try:
|
||||
@@ -118,14 +122,13 @@ class CliphistManager:
|
||||
["cliphist", "decode", clip_id], capture_output=True, check=True
|
||||
)
|
||||
subprocess.run(["wl-copy"], input=decode_result.stdout, check=True)
|
||||
self.launcher.open_launcher()
|
||||
self.launcher.close()
|
||||
except subprocess.CalledProcessError as e:
|
||||
print(f"Error copying clip {clip_id}: {e}")
|
||||
|
||||
def save_image_file(self, clip_id: str) -> str:
|
||||
output_file = f"/tmp/cliphist-{clip_id}.png"
|
||||
os.makedirs("/tmp", exist_ok=True)
|
||||
|
||||
try:
|
||||
decode_result = subprocess.run(
|
||||
["cliphist", "decode", clip_id], capture_output=True, check=True
|
||||
@@ -150,6 +153,9 @@ class CliphistManager:
|
||||
if query.lower() in clip["content"].lower()
|
||||
]
|
||||
|
||||
def _on_clip_clicked(self, clip_id: str, *args):
|
||||
self.copy_clip(clip_id)
|
||||
|
||||
def bake_clip_slot(self, item: dict) -> Button:
|
||||
if "[[ binary data" in item["content"].lower():
|
||||
return self._create_image_button(item)
|
||||
@@ -161,7 +167,7 @@ class CliphistManager:
|
||||
button = Button(
|
||||
h_align="start",
|
||||
name="clip-img-item",
|
||||
on_clicked=lambda _, clip_id=item["id"]: self.copy_clip(clip_id),
|
||||
on_clicked=partial(self._on_clip_clicked, item["id"]),
|
||||
)
|
||||
button.set_style(
|
||||
f"background-image: url('{output_file}'); background-size: cover; background-position: center;"
|
||||
@@ -178,17 +184,15 @@ class CliphistManager:
|
||||
v_align="center",
|
||||
h_align="start",
|
||||
),
|
||||
on_clicked=lambda _, clip_id=item["id"]: self.copy_clip(clip_id),
|
||||
on_clicked=partial(self._on_clip_clicked, item["id"]),
|
||||
name="clip-item",
|
||||
)
|
||||
|
||||
def arrange_viewport(self, query: str = ""):
|
||||
if not self.launcher.viewport:
|
||||
return
|
||||
|
||||
self.launcher.viewport.children = []
|
||||
filtered_clips = self.query_clips(query)
|
||||
|
||||
for clip in filtered_clips:
|
||||
button = self.bake_clip_slot(clip)
|
||||
if button:
|
||||
|
||||
Reference in new issue
Block a user