diff --git a/README.md b/README.md index fdae5205..6796c2e0 100644 --- a/README.md +++ b/README.md @@ -34,17 +34,17 @@ clone git@github.com:ceccopierangiolieugenio/pyTermTk.git cd pyTermTk ``` -#### Run Basic input test +#### Run Basic (non ui) input test ```shell python3 tests/test.input.py ``` -#### Run Terminal resize test +#### Run demo ```shell # Press CTRL-C to exit # the logs are written to "session.log" make runDemo -# or + # or python3 demo/demo.py -f # Try gittk diff --git a/demo/demo.py b/demo/demo.py index cdcaace9..cfe709f2 100755 --- a/demo/demo.py +++ b/demo/demo.py @@ -41,6 +41,12 @@ from showcase.scrollarea import demoScrollArea from showcase.list import demoList from showcase.menubar import demoMenuBar +words = ["Lorem", "ipsum", "dolor", "sit", "amet,", "consectetur", "adipiscing", "elit,", "sed", "do", "eiusmod", "tempor", "incididunt", "ut", "labore", "et", "dolore", "magna", "aliqua.", "Ut", "enim", "ad", "minim", "veniam,", "quis", "nostrud", "exercitation", "ullamco", "laboris", "nisi", "ut", "aliquip", "ex", "ea", "commodo", "consequat.", "Duis", "aute", "irure", "dolor", "in", "reprehenderit", "in", "voluptate", "velit", "esse", "cillum", "dolore", "eu", "fugiat", "nulla", "pariatur.", "Excepteur", "sint", "occaecat", "cupidatat", "non", "proident,", "sunt", "in", "culpa", "qui", "officia", "deserunt", "mollit", "anim", "id", "est", "laborum."] +def getWord(): + return random.choice(words) +def getSentence(a,b): + return " ".join([getWord() for i in range(0,random.randint(a,b))]) + def demoShowcase(root= None, border=True): tabWidget1 = ttk.TTkTabWidget(parent=root, border=border) tabWidget1.addTab(ttk.TTkTestWidgetSizes(border=True, title="Frame1.1"), " Label 1.1 ") @@ -57,6 +63,8 @@ def demoShowcase(root= None, border=True): tabWidget1.addTab(demoWindows(), " Windows Test ") tabWidget1.addTab(demoTab(), " Tab Test ") tabWidget1.addTab(demoScrollArea(), " Scroll Area ") + + return tabWidget1 def main(): @@ -75,6 +83,69 @@ def main(): winTabbed1 = ttk.TTkWindow(parent=root,pos=(0,0), size=(120,40), title="Test Tab", border=True, layout=ttk.TTkGridLayout()) border = True demoShowcase(winTabbed1, border) + + + win_table1 = ttk.TTkWindow(parent=root,pos = (3,3), size=(150,40), title="Test Table 1", layout=ttk.TTkHBoxLayout(), border=True) + table1 = ttk.TTkTable(parent=win_table1, selectColor=ttk.TTkColor.bg('#882200')) + + win_table2 = ttk.TTkWindow(parent=root,pos = (15,5), size=(100,30), title="Test Table 2 Default", layout=ttk.TTkHBoxLayout(), border=True) + table2 = ttk.TTkTable(parent=win_table2) + + win_table3 = ttk.TTkWindow(parent=root,pos = (15,5), size=(130,40), title="Test Table 2 Default", layout=ttk.TTkHBoxLayout(), border=True) + table3 = ttk.TTkTable(parent=win_table3, showHeader=False) + + table1.setColumnSize((5,10,-1,10,20)) + table1.setAlignment(( + ttk.TTkK.LEFT_ALIGN, + ttk.TTkK.RIGHT_ALIGN, + ttk.TTkK.LEFT_ALIGN, + ttk.TTkK.LEFT_ALIGN, + ttk.TTkK.CENTER_ALIGN + )) + table1.setHeader(("id","Name","Sentence","Word","center")) + table1.setColumnColors(( + ttk.TTkColor.fg('#888800', modifier=ttk.TTkColorGradient(increment=6)), + ttk.TTkColor.RST, + ttk.TTkColor.fg('#00dddd', modifier=ttk.TTkColorGradient(increment=-4)), + ttk.TTkColor.RST, + ttk.TTkColor.fg('#cccccc', modifier=ttk.TTkColorGradient(increment=-2)) + )) + + table2.setColumnSize((5,10,-1,10,20)) + table2.setHeader(("id","Name","Sentence","Word","")) + + table3.setColumnSize((5,10,-1,10,20)) + table3.setAlignment(( + ttk.TTkK.LEFT_ALIGN, + ttk.TTkK.RIGHT_ALIGN, + ttk.TTkK.LEFT_ALIGN, + ttk.TTkK.LEFT_ALIGN, + ttk.TTkK.CENTER_ALIGN + )) + table3.setHeader(("id","Name","Sentence","Word","center")) + table3.setColumnColors(( + ttk.TTkColor.fg('#ffff00', modifier=ttk.TTkColorGradient(increment=6)), + ttk.TTkColor.fg('#ff0000', modifier=ttk.TTkColorGradient(increment=6)), + ttk.TTkColor.fg('#00ffff', modifier=ttk.TTkColorGradient(increment=-8)), + ttk.TTkColor.fg('#00ff00', modifier=ttk.TTkColorGradient(increment=-4)), + ttk.TTkColor.fg('#cccccc', modifier=ttk.TTkColorGradient(increment=-2)) + )) + + + table3.appendItem((" - ","","You see it's all clear, You were meant to be here, From the beginning","","")) + for i in range(0, 5): + table1.appendItem((str(i), getWord(), getSentence(8,30), getWord(), getWord())) + for i in range(0, 5): + table2.appendItem((str(i), getWord(), getSentence(8,30), getWord(), getWord())) + for i in range(0, 35): + table3.appendItem((str(i), getWord(), getSentence(8,30), getWord(), getWord())) + + table3.appendItem((" - ","This is the end", "Beautiful friend, This is the end My only friend", "the end", "...")) + + + + + root.mainloop() if __name__ == "__main__": diff --git a/tutorial/003-signalslots.md b/tutorial/003-signalslots.md index e69de29b..0811d6e3 100644 --- a/tutorial/003-signalslots.md +++ b/tutorial/003-signalslots.md @@ -0,0 +1,104 @@ +# [pyTermTk](https://github.com/ceccopierangiolieugenio/pyTermTk) - Signal & Slots + +## Intro +The [TermTk Signal&Slots](https://ceccopierangiolieugenio.github.io/pyTermTk/TTkCore/signal.html) and more than heavily inspired by [Qt5 Signal&Slots](https://www.riverbankcomputing.com/static/Docs/PyQt5/signals_slots.html) +https://doc.qt.io/qt-5/signalsandslots.html + + +## Example 1 - basic signal slots +From [example1.basic.signalslots.py](signalslots/example1.basic.signalslots.py) +```python +import TermTk as ttk + +ttk.TTkLog.use_default_stdout_logging() + + # define 2 signals with different signatures +signal = ttk.pyTTkSignal() +otherSignal = ttk.pyTTkSignal(int) + + + # Define a slot with no input as signature +@ttk.pyTTkSlot() +def slot(): + ttk.TTkLog.debug("Received a simple signal") + + # Define 2 slots with "int" as input signature +@ttk.pyTTkSlot(int) +def otherSlot(val): + ttk.TTkLog.debug(f"[otherSlot] Received a valued signal, val:{val}") + +@ttk.pyTTkSlot(int) +def anotherSlot(val): + ttk.TTkLog.debug(f"[anootherSlot] Received a valued signal, val:{val}") + + + # connect the signals to the proper slot +signal.connect(slot) +otherSignal.connect(otherSlot) +otherSignal.connect(anotherSlot) + + # Test the signals +ttk.TTkLog.debug("Emit a simple signal") +signal.emit() +ttk.TTkLog.debug("Emit a valued signal") +otherSignal.emit(123) +``` +The above code produces the following output + +```text + $ tutorial/signalslots/example1.basic.signalslots.py +DEBUG:(MainThread) tutorial/signalslots/example1.basic.signalslots.py:54 Emit a simple signal +DEBUG:(MainThread) tutorial/signalslots/example1.basic.signalslots.py:37 Received a simple signal +DEBUG:(MainThread) tutorial/signalslots/example1.basic.signalslots.py:56 Emit a valued signal +DEBUG:(MainThread) tutorial/signalslots/example1.basic.signalslots.py:42 [otherSlot] Received a valued signal, val:123 +DEBUG:(MainThread) tutorial/signalslots/example1.basic.signalslots.py:45 [anootherSlot] Received a valued signal, val:123 +``` + +## Example 2 - Use widgets signals and slots +From [example2.widgets.signalslots.py](signalslots/example2.widgets.signalslots.py) +```python +import TermTk as ttk + +root = ttk.TTk() + + # Create a window with a logviewer +logWin = ttk.TTkWindow(parent=root,pos = (10,2), size=(80,20), title="LogViewer Window", border=True, layout=ttk.TTkVBoxLayout()) +ttk.TTkLogViewer(parent=logWin) + + # Create 2 buttons +btnShow = ttk.TTkButton(parent=root, text="Show", pos=(0,0), size=(10,3), border=True) +btnHide = ttk.TTkButton(parent=root, text="Hide", pos=(0,3), size=(10,3), border=True) + + # Connect the btnShow's "clicked" signal with the window's "show" slot +btnShow.clicked.connect(logWin.show) + # Connect the btnHide's "clicked" signal with the window's "hide" slot +btnHide.clicked.connect(logWin.hide) + +root.mainloop() +``` +It is totally useless for this example but the above code produces the following output + +```text +┌────────┐ +│ Show │ +╘════════╛╔══════════════════════════════════════════════════════════════════════════════╗ +┌────────┐║ LogViewer Window ║ +│ Hide │╟──────────────────────────────────────────────────────────────────────────────╢ +╘════════╛║ ║ + ║DEBUG: _/.venv/lib/python3.8/site-packages/TermTk/TTkCore/ttk.py:70 Starting M║ + ║DEBUG: _/.venv/lib/python3.8/site-packages/TermTk/TTkCore/ttk.py:80 Signal Eve║ + ║DEBUG: _/.venv/lib/python3.8/site-packages/TermTk/TTkCore/ttk.py:65 fps: 33 ║ + ║DEBUG: _/.venv/lib/python3.8/site-packages/TermTk/TTkCore/ttk.py:65 fps: 34 ║ + ║DEBUG: _/.venv/lib/python3.8/site-packages/TermTk/TTkCore/ttk.py:65 fps: 34 ║ + ║ ║ + ║ ║ + ║ ║ + ║ ║ + ║ ║ + ║ ║ + ║ ║ + ║ ║ + ║ ║ + ║◀▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓┄┄┄┄┄┄┄┄┄┄┄▶║ + ╚══════════════════════════════════════════════════════════════════════════════╝ +``` \ No newline at end of file diff --git a/tutorial/004-logging.md b/tutorial/004-logging.md index c401417e..0482b381 100644 --- a/tutorial/004-logging.md +++ b/tutorial/004-logging.md @@ -72,7 +72,7 @@ root = ttk.TTk() # Create a window and attach it to the root (parent=root) logWin = ttk.TTkWindow(parent=root,pos = (1,1), size=(80,20), title="LogViewer Window", border=True, layout=ttk.TTkVBoxLayout()) - # Define the Label and attach it to the window (parent=helloWin) + # Attach the logViewer widget to the window ttk.TTkLogViewer(parent=logWin) ttk.TTkLog.info( "Test Info Messgae") diff --git a/tutorial/logging/example4.ttklogviewer.py b/tutorial/logging/example4.ttklogviewer.py index 80713fdb..36f51999 100755 --- a/tutorial/logging/example4.ttklogviewer.py +++ b/tutorial/logging/example4.ttklogviewer.py @@ -29,7 +29,7 @@ root = ttk.TTk() # Create a window and attach it to the root (parent=root) logWin = ttk.TTkWindow(parent=root,pos = (1,1), size=(80,20), title="LogViewer Window", border=True, layout=ttk.TTkVBoxLayout()) - # Define the Label and attach it to the window (parent=helloWin) + # Attach the logViewer widget to the window ttk.TTkLogViewer(parent=logWin) ttk.TTkLog.info( "Test Info Messgae") diff --git a/tutorial/signalslots/example1.basic.signalslots.py b/tutorial/signalslots/example1.basic.signalslots.py new file mode 100755 index 00000000..7295a48d --- /dev/null +++ b/tutorial/signalslots/example1.basic.signalslots.py @@ -0,0 +1,58 @@ +#!/usr/bin/env python3 + +# MIT License +# +# Copyright (c) 2021 Eugenio Parodi +# +# 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. + +import TermTk as ttk + +ttk.TTkLog.use_default_stdout_logging() + + # define 2 signals with different signatures +signal = ttk.pyTTkSignal() +otherSignal = ttk.pyTTkSignal(int) + + + # Define a slot with no input as signature +@ttk.pyTTkSlot() +def slot(): + ttk.TTkLog.debug("Received a simple signal") + + # Define 2 slots with "int" as input signature +@ttk.pyTTkSlot(int) +def otherSlot(val): + ttk.TTkLog.debug(f"[otherSlot] Received a valued signal, val:{val}") + +@ttk.pyTTkSlot(int) +def anotherSlot(val): + ttk.TTkLog.debug(f"[anootherSlot] Received a valued signal, val:{val}") + + + # connect the signals to the proper slot +signal.connect(slot) +otherSignal.connect(otherSlot) +otherSignal.connect(anotherSlot) + + # Test the signals +ttk.TTkLog.debug("Emit a simple signal") +signal.emit() +ttk.TTkLog.debug("Emit a valued signal") +otherSignal.emit(123) \ No newline at end of file diff --git a/tutorial/signalslots/example2.widgets.signalslots.py b/tutorial/signalslots/example2.widgets.signalslots.py new file mode 100755 index 00000000..274e5f1d --- /dev/null +++ b/tutorial/signalslots/example2.widgets.signalslots.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python3 + +# MIT License +# +# Copyright (c) 2021 Eugenio Parodi +# +# 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. + +import TermTk as ttk + +root = ttk.TTk() + + # Create a window with a logviewer +logWin = ttk.TTkWindow(parent=root,pos = (10,2), size=(80,20), title="LogViewer Window", border=True, layout=ttk.TTkVBoxLayout()) +ttk.TTkLogViewer(parent=logWin) + + # Create 2 buttons +btnShow = ttk.TTkButton(parent=root, text="Show", pos=(0,0), size=(10,3), border=True) +btnHide = ttk.TTkButton(parent=root, text="Hide", pos=(0,3), size=(10,3), border=True) + + # Connect the btnShow's "clicked" signal with the window's "show" slot +btnShow.clicked.connect(logWin.show) + # Connect the btnHide's "clicked" signal with the window's "hide" slot +btnHide.clicked.connect(logWin.hide) + +root.mainloop() \ No newline at end of file