mirror of
https://github.com/aclist/dztui.git
synced 2026-08-29 11:17:12 +02:00
feat: standalone clipboard utility
This commit is contained in:
parent
68cd567249
commit
a22d1a6324
@ -5,6 +5,7 @@ from typing import TYPE_CHECKING
|
|||||||
from dzgui.const.enum import ContextMenu, Preferences
|
from dzgui.const.enum import ContextMenu, Preferences
|
||||||
from dzgui.managers.thread_man import ThreadingManager
|
from dzgui.managers.thread_man import ThreadingManager
|
||||||
from dzgui.util import strings
|
from dzgui.util import strings
|
||||||
|
from dzgui.util.clip import copy_clipboard
|
||||||
from dzgui.util.open_links import open_workshop_page
|
from dzgui.util.open_links import open_workshop_page
|
||||||
|
|
||||||
gi.require_version("Gtk", "3.0")
|
gi.require_version("Gtk", "3.0")
|
||||||
@ -72,17 +73,13 @@ class ContextMenuManager:
|
|||||||
|
|
||||||
def copy_server_ip(self) -> None:
|
def copy_server_ip(self) -> None:
|
||||||
record = self.treeview.get_simplified_ip()
|
record = self.treeview.get_simplified_ip()
|
||||||
self.copy_clipboard(record)
|
copy_clipboard(record)
|
||||||
|
|
||||||
def copy_clipboard(self, text: str) -> None:
|
|
||||||
self.clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
|
|
||||||
self.clipboard.set_text(text, -1)
|
|
||||||
|
|
||||||
def copy_server_name(self) -> None:
|
def copy_server_name(self) -> None:
|
||||||
name = self.treeview.get_value_at_index(0)
|
name = self.treeview.get_value_at_index(0)
|
||||||
if name is None:
|
if name is None:
|
||||||
return
|
return
|
||||||
self.copy_clipboard(name)
|
copy_clipboard(name)
|
||||||
|
|
||||||
def open_mod_page(self) -> None:
|
def open_mod_page(self) -> None:
|
||||||
mod = self.treeview.get_selected_mod()
|
mod = self.treeview.get_selected_mod()
|
||||||
@ -101,4 +98,4 @@ class ContextMenuManager:
|
|||||||
concat = strings.delimiter.join(r)
|
concat = strings.delimiter.join(r)
|
||||||
final.append(concat)
|
final.append(concat)
|
||||||
text = "\n".join(final)
|
text = "\n".join(final)
|
||||||
self.copy_clipboard(text)
|
copy_clipboard(text)
|
||||||
|
|||||||
10
dzgui/util/clip.py
Normal file
10
dzgui/util/clip.py
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
import gi
|
||||||
|
|
||||||
|
gi.require_version("Gtk", "3.0")
|
||||||
|
from gi.repository.Gdk import SELECTION_CLIPBOARD # noqa E402
|
||||||
|
from gi.repository.Gtk import Clipboard # noqa E402
|
||||||
|
|
||||||
|
|
||||||
|
def copy_clipboard(text: str) -> None:
|
||||||
|
clipboard = Clipboard.get(SELECTION_CLIPBOARD)
|
||||||
|
clipboard.set_text(text, -1)
|
||||||
@ -1,5 +1,6 @@
|
|||||||
from typing import Callable, Literal, Self, TYPE_CHECKING
|
from typing import Callable, Literal, Self, TYPE_CHECKING
|
||||||
|
|
||||||
|
from dzgui.util.clip import copy_clipboard
|
||||||
from dzgui.util.strings import atomic_buttons, connect_panel
|
from dzgui.util.strings import atomic_buttons, connect_panel
|
||||||
from dzgui.const.constants import (
|
from dzgui.const.constants import (
|
||||||
CLIPBOARD,
|
CLIPBOARD,
|
||||||
@ -69,7 +70,7 @@ class ClipboardButton(IconTextButton):
|
|||||||
|
|
||||||
def _on_button_clicked(self, button: Self, func: Callable) -> None:
|
def _on_button_clicked(self, button: Self, func: Callable) -> None:
|
||||||
data = func()
|
data = func()
|
||||||
self.controller.copy_clipboard(data)
|
copy_clipboard(data)
|
||||||
|
|
||||||
|
|
||||||
class WebButton(IconTextButton):
|
class WebButton(IconTextButton):
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user