mirror of
https://github.com/aclist/dztui.git
synced 2026-10-30 14:42:54 +01:00
feat: dynamic update on clipboard button click
This commit is contained in:
1 parent
ec7828df85
commit
52ab81f4ec
2 files changed
+17
-1
No files matched your search
@@ -1,4 +1,4 @@
|
|||||||
from typing import Callable, Self, TYPE_CHECKING, Union
|
from typing import Callable, Literal, Self, TYPE_CHECKING, Union
|
||||||
|
|
||||||
from dzgui.util.clip import copy_clipboard
|
from dzgui.util.clip import copy_clipboard
|
||||||
from dzgui.util.format import pluralize
|
from dzgui.util.format import pluralize
|
||||||
@@ -66,6 +66,15 @@ class IconButton(Gtk.Button):
|
|||||||
# self.set_image_position(Gtk.PositionType.RIGHT)
|
# self.set_image_position(Gtk.PositionType.RIGHT)
|
||||||
self.set_focus_on_click(False)
|
self.set_focus_on_click(False)
|
||||||
|
|
||||||
|
def swap_icon(self, icon: str) -> None:
|
||||||
|
start = self.icon.get_margin_start()
|
||||||
|
end = self.icon.get_margin_end()
|
||||||
|
alt_icon = Icon(icon, margin_start=start, margin_end=end)
|
||||||
|
self.set_image(alt_icon)
|
||||||
|
|
||||||
|
def revert_icon(self) -> None:
|
||||||
|
self.set_image(self.icon)
|
||||||
|
|
||||||
|
|
||||||
class IconTextButton(IconButton):
|
class IconTextButton(IconButton):
|
||||||
def __init__(
|
def __init__(
|
||||||
@@ -99,8 +108,14 @@ class ClipboardButton(IconTextButton):
|
|||||||
self.set_tooltip_text("Copy to clipboard")
|
self.set_tooltip_text("Copy to clipboard")
|
||||||
|
|
||||||
def _on_button_clicked(self, button: Self, func: Callable) -> None:
|
def _on_button_clicked(self, button: Self, func: Callable) -> None:
|
||||||
|
def revert() -> Literal[False]:
|
||||||
|
self.revert_icon()
|
||||||
|
return False
|
||||||
|
|
||||||
|
self.swap_icon("object-select-symbolic")
|
||||||
data = func()
|
data = func()
|
||||||
copy_clipboard(data)
|
copy_clipboard(data)
|
||||||
|
GLib.timeout_add(600, revert)
|
||||||
|
|
||||||
|
|
||||||
# TODO: determine when controller would be passed to this button or drop
|
# TODO: determine when controller would be passed to this button or drop
|
||||||
|
|||||||
@@ -131,6 +131,7 @@ class RightPanel(Gtk.Box):
|
|||||||
return
|
return
|
||||||
self.copying = True
|
self.copying = True
|
||||||
version = self.version_label.get_text()
|
version = self.version_label.get_text()
|
||||||
|
# TODO: strings
|
||||||
self.version_label.set_text("Copied!")
|
self.version_label.set_text("Copied!")
|
||||||
copy_clipboard(version)
|
copy_clipboard(version)
|
||||||
GLib.timeout_add_seconds(1, revert)
|
GLib.timeout_add_seconds(1, revert)
|
||||||
Reference in new issue
Block a user