From 3e997d460e8b6ee322d2ec0e4f0de3d84135b4c5 Mon Sep 17 00:00:00 2001 From: Eugenio Parodi Date: Thu, 22 Feb 2024 14:00:50 +0000 Subject: [PATCH] Doc Updated --- _modules/TermTk/TTkGui/clipboard.html | 258 ++++++++++++++++++ _modules/TermTk/TTkWidgets/window.html | 15 +- _modules/index.html | 1 + .../TermTk.TTkGui.clipboard.rst.txt | 8 + _sources/info/features/index.rst.txt | 4 +- _sources/info/resources/clipboard.rst.txt | 63 ++++- _sources/info/resources/dragdrop.rst.txt | 6 + _sources/info/resources/index.rst.txt | 4 +- autogen.TermTk/TermTk.TTkAbstract.html | 4 +- autogen.TermTk/TermTk.TTkGui.clipboard.html | 37 ++- genindex.html | 10 +- info/features/index.html | 4 +- info/resources/clipboard.html | 75 ++++- info/resources/dragdrop.html | 28 +- info/resources/index.html | 6 +- info/resources/modal.html | 10 +- objects.inv | Bin 28225 -> 28334 bytes searchindex.js | 2 +- 18 files changed, 495 insertions(+), 40 deletions(-) create mode 100644 _modules/TermTk/TTkGui/clipboard.html diff --git a/_modules/TermTk/TTkGui/clipboard.html b/_modules/TermTk/TTkGui/clipboard.html new file mode 100644 index 00000000..20f23ec9 --- /dev/null +++ b/_modules/TermTk/TTkGui/clipboard.html @@ -0,0 +1,258 @@ + + + + + + TermTk.TTkGui.clipboard — pyTermTk 0.38.0-a + documentation + + + + + + + + + + + + + + + + + + +
+ + +
+ +
+
+
+
    +
  • »
  • +
  • Module code »
  • +
  • TermTk.TTkGui.clipboard
  • +
  • +
  • +
+
+
+
+
+ +

Source code for TermTk.TTkGui.clipboard

+# MIT License
+#
+# Copyright (c) 2022 Eugenio Parodi <ceccopierangiolieugenio AT googlemail DOT com>
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in all
+# copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+# SOFTWARE.
+
+__all__ = ['TTkClipboard']
+
+import importlib.util
+from TermTk.TTkCore.log import TTkLog
+
+
[docs]class TTkClipboard(): + '''TTkClipboard + + :ref:`Clipboard` + + Example: + + .. code:: python + + from TermTk import TTkClipboard + + # Initialize the clipboard manager + clipboard = TTkClipboard() + + # Push some text to the clipboard + clipboard.setText("Example") + + # Get the text from the clipboard + text = clipboard.text() + + + ''' + _clipboard = "" + _manager = None + _setText = None + _text = None + + def __init__(self) -> None: + if not TTkClipboard._manager: + TTkClipboard._loadClipboardManager() + + @staticmethod + def _loadClipboardManager(): + try: + if importlib.util.find_spec('copykitten'): + TTkLog.info("Using 'copykitten' as clipboard manager") + import copykitten as _c + TTkClipboard._manager = _c + TTkClipboard._setText = _c.copy + TTkClipboard._text = _c.paste + elif importlib.util.find_spec('pyperclip'): + TTkLog.info("Using 'pyperclip' as clipboard manager") + import pyperclip as _c + TTkClipboard._manager = _c + TTkClipboard._setText = _c.copy + TTkClipboard._text = _c.paste + elif importlib.util.find_spec('pyperclip3'): + TTkLog.info("Using 'pyperclip3' as clipboard manager") + import pyperclip3 as _c + TTkClipboard._manager = _c + TTkClipboard._setText = _c.copy + TTkClipboard._text = _c.paste + elif importlib.util.find_spec('pyclip'): + TTkLog.info("Using 'pyclip' as clipboard manager") + import pyclip as _c + TTkClipboard._manager = _c + TTkClipboard._setText = _c.copy + TTkClipboard._text = _c.paste + elif importlib.util.find_spec('clipboard'): + TTkLog.info("Using 'clipboard' as clipboard manager") + import clipboard as _c + TTkClipboard._manager = _c + TTkClipboard._setText = _c.copy + TTkClipboard._text = _c.paste + else: + TTkLog.info("No clipboard manager found") + TTkClipboard._manager = "Not Found" + except Exception as e: + TTkLog.error("Clipboard error, try to export X11 if you are running this UI via SSH") + for line in str(e).split("\n"): + TTkLog.error(line) + +
[docs] @staticmethod + def setText(text): + '''setText''' + TTkClipboard._clipboard = text + if TTkClipboard._setText: + try: + TTkClipboard._setText(str(text)) + except Exception as e: + TTkLog.error("Clipboard error, try to export X11 if you are running this UI via SSH") + for line in str(e).split("\n"): + TTkLog.error(line)
+ +
[docs] @staticmethod + def text(): + '''text''' + if TTkClipboard._text: + txt = TTkClipboard._text() + if txt == str(TTkClipboard._clipboard): + return TTkClipboard._clipboard + else: + return TTkClipboard._text() + return TTkClipboard._clipboard
+
+ +
+
+
+ +
+ +
+

© Copyright 2021, Eugenio Parodi.

+
+ + Built with Sphinx using a + theme + provided by Read the Docs. + + +
+
+
+
+
+ + + + \ No newline at end of file diff --git a/_modules/TermTk/TTkWidgets/window.html b/_modules/TermTk/TTkWidgets/window.html index 985f0ff1..da1ebae8 100644 --- a/_modules/TermTk/TTkWidgets/window.html +++ b/_modules/TermTk/TTkWidgets/window.html @@ -211,13 +211,13 @@ self.focusChanged.connect(self._focusChanged) def _maximize(self): - if not (pw := self.parentWidget()): return + if not (pl := self.widgetItem().parent()): return if self._maxBk: self.setGeometry(*self._maxBk) self._maxBk = None else: bk = self.geometry() - maxw,maxh = pw.layout().size() + maxw,maxh = pl.size() self.setGeometry(0,0,maxw,maxh) self._maxBk = bk @@ -231,20 +231,19 @@ self._redBk = bk def _minimize(self): - if not (pw := self.parentWidget()): return + if not (pl := self.widgetItem().parent()): return stack = [] - for li in pw.rootLayout().children(): + for li in pl.children(): if li.layoutItemType() == TTkK.WidgetItem and issubclass(type(w:=li.widget()),_MinimizedButton): stack.append(w.y()) stack = sorted(stack) - lx,ly = pw.layout().pos() - pos = ly + pos = 0 for v in stack: if (pos+2) < v or (v+2) < pos: break pos += 3 - mb = _MinimizedButton(windowWidget=self,text=self._title,border=True,pos=(lx,pos),size=(15,3)) - pw.rootLayout().addWidget(mb) + mb = _MinimizedButton(windowWidget=self,text=self._title,border=True,pos=(0,pos),size=(15,3)) + pl.addWidget(mb) self.hide()
[docs] def windowFlag(self): diff --git a/_modules/index.html b/_modules/index.html index 9bad9e8d..13fa021e 100644 --- a/_modules/index.html +++ b/_modules/index.html @@ -117,6 +117,7 @@
  • TermTk.TTkCore.string
  • TermTk.TTkCore.timer_unix
  • TermTk.TTkCore.ttk
  • +
  • TermTk.TTkGui.clipboard
  • TermTk.TTkGui.textdocument
  • TermTk.TTkLayouts.boxlayout
  • TermTk.TTkLayouts.gridlayout
  • diff --git a/_sources/autogen.TermTk/TermTk.TTkGui.clipboard.rst.txt b/_sources/autogen.TermTk/TermTk.TTkGui.clipboard.rst.txt index 5e4da975..f861983d 100644 --- a/_sources/autogen.TermTk/TermTk.TTkGui.clipboard.rst.txt +++ b/_sources/autogen.TermTk/TermTk.TTkGui.clipboard.rst.txt @@ -6,3 +6,11 @@ TermTk.TTkGui.clipboard .. currentmodule:: TermTk.TTkGui.clipboard + + +TTkClipboard +============ + +.. autoclass:: TTkClipboard + :members: + :inherited-members: diff --git a/_sources/info/features/index.rst.txt b/_sources/info/features/index.rst.txt index 957308f0..bfdc0ecd 100644 --- a/_sources/info/features/index.rst.txt +++ b/_sources/info/features/index.rst.txt @@ -31,9 +31,9 @@ Main features * Input/Mouse/Paste Event handling -* Drag and Drop +* :ref:`Drag and Drop ` -* Clipboard support +* :ref:`Clipboard` support * Drawing primitives diff --git a/_sources/info/resources/clipboard.rst.txt b/_sources/info/resources/clipboard.rst.txt index 2fd9f957..54b42c43 100644 --- a/_sources/info/resources/clipboard.rst.txt +++ b/_sources/info/resources/clipboard.rst.txt @@ -1 +1,62 @@ -TBD \ No newline at end of file +.. _clipboard: + +========= +Clipboard +========= + +.. _pyTermTk: https://github.com/ceccopierangiolieugenio/pyTermTk + + +pyTermTk_ include a clipboard wrapper :class:`~TermTk.TTkGui.clipboard.TTkClipboard`, around any of the following libraries: + +- `copykitten `_ - Robust, dependency-free way to use the system clipboard in Python. +- `pyperclip `_ - Python module for cross-platform clipboard functions. +- `pyperclip3 `_ / `pyclip `_ - Cross-platform Clipboard module for Python with binary support. +- `clipboard `_ - A cross platform clipboard operation library of Python. Works for Windows, Mac and Linux. + +.. raw:: html + + + +The basic pyTermTk_ does not include any of those clipboard managers. +An internal implementation whitin the scope of the app itself is still available. + +If any of the previous listed clipboard managers are installed, pyTermTk_ is able to automatically detect and use them. + +i.e. + +.. code:: bash + + # Assuming no clipboard managers are installed + # you can still copy/paste between editors in this session + # but no text is copied to/from the system clipboard + python3 demo/showcase/textedit.py + + # if pyperclip is installed, + # pyTermTk defaults the clipboard manager to this tool + # any copy/paste is synced with the system clipboard + # it is possible to copy/paste from/to an external editor + pip install pyperclip + python3 demo/showcase/textedit.py + +----- +Usage +----- + +Once initialized the clipboard manager, 2 apis are provided that can be used to access the clipboard (:class:`~TermTk.TTkGui.clipboard.TTkClipboard.setText`, :class:`~TermTk.TTkGui.clipboard.TTkClipboard.text`) + + .. code:: python + + from TermTk import TTkClipboard + + # Initialize the clipboard manager + clipboard = TTkClipboard() + + # Push some text to the clipboard + clipboard.setText("Example") + + # Get the text from the clipboard + text = clipboard.text() \ No newline at end of file diff --git a/_sources/info/resources/dragdrop.rst.txt b/_sources/info/resources/dragdrop.rst.txt index 2fd9f957..90ce027f 100644 --- a/_sources/info/resources/dragdrop.rst.txt +++ b/_sources/info/resources/dragdrop.rst.txt @@ -1 +1,7 @@ +.. _DnD: + +============= +Drag and Drop +============= + TBD \ No newline at end of file diff --git a/_sources/info/resources/index.rst.txt b/_sources/info/resources/index.rst.txt index 1f19488a..7313e546 100644 --- a/_sources/info/resources/index.rst.txt +++ b/_sources/info/resources/index.rst.txt @@ -6,4 +6,6 @@ Resources :maxdepth: 1 :hidden: - modal \ No newline at end of file + clipboard + modal + dragdrop \ No newline at end of file diff --git a/autogen.TermTk/TermTk.TTkAbstract.html b/autogen.TermTk/TermTk.TTkAbstract.html index f1d19d0d..ac995b35 100644 --- a/autogen.TermTk/TermTk.TTkAbstract.html +++ b/autogen.TermTk/TermTk.TTkAbstract.html @@ -24,7 +24,7 @@ - + @@ -137,7 +137,7 @@