Browse Source

Ported the tutorial from 'md' to 'rst'

pull/12/head
Eugenio Parodi 5 years ago
parent
commit
8de4cf2a8c
  1. 4
      TermTk/TTkCore/signal.py
  2. 2
      TermTk/TTkCore/ttk.py
  3. 3
      TermTk/TTkGui/theme.py
  4. 10
      TermTk/TTkLayouts/boxlayout.py
  5. 5
      TermTk/TTkLayouts/gridlayout.py
  6. 12
      TermTk/TTkLayouts/layout.py
  7. 5
      TermTk/TTkWidgets/TTkPickers/colorpicker.py
  8. 2
      TermTk/TTkWidgets/graph.py
  9. 1
      TermTk/TTkWidgets/widget.py
  10. 1
      docs/requirements.txt
  11. 15
      docs/source/_static/theme_overrides.css
  12. 25
      docs/source/conf.py
  13. 39
      docs/source/index.rst
  14. 1
      docs/source/tutorial
  15. 63
      tutorial/001-helloworld.md
  16. 34
      tutorial/001-helloworld.rst
  17. 327
      tutorial/002-layout.md
  18. 391
      tutorial/002-layout.rst
  19. 115
      tutorial/003-signalslots.md
  20. 157
      tutorial/003-signalslots.rst
  21. 111
      tutorial/004-logging.md
  22. 139
      tutorial/004-logging.rst
  23. 8
      tutorial/README.md
  24. 12
      tutorial/logging/example1.logtofile.py
  25. 12
      tutorial/logging/example2.logtostdout.py
  26. 12
      tutorial/logging/example3.customlogging.py
  27. 12
      tutorial/logging/example4.ttklogviewer.py

4
TermTk/TTkCore/signal.py

@ -28,7 +28,7 @@
'''
Signals & Slots [`Tutorial <https://github.com/ceccopierangiolieugenio/pyTermTk/blob/main/tutorial/003-signalslots.md>`_]
=========================
=========================================================================================================================
Signals and slots are used for communication between objects.
@ -49,7 +49,7 @@ Signal and Slots
| A slot is a function that is called in response to a particular signal.
| `TermTk <https://github.com/ceccopierangiolieugenio/pyTermTk>`_'s :mod:`~TermTk.TTkWidgets` have many predefined signals/slots, but it is possible to subclass any :mod:`~TermTk.TTkWidgets` and add our own signals/slots to them.
.. image:: /../_static/Signal.Slots.001.svg
.. image:: /_static/Signal.Slots.001.svg
Methods
=======

2
TermTk/TTkCore/ttk.py

@ -74,6 +74,7 @@ class TTk(TTkWidget):
self.time = curtime
def mainloop(self):
'''Enters the main event loop and waits until :meth:`~quit` is called or the main widget is destroyed.'''
TTkLog.debug( "" )
TTkLog.debug( " ████████╗ ████████╗ " )
TTkLog.debug( " ╚══██╔══╝ ╚══██╔══╝ " )
@ -189,6 +190,7 @@ class TTk(TTkWidget):
pass
def quit(self):
'''Tells the application to exit with a return code.'''
self.events.put(TTkK.QUIT_EVENT)
TTkTimer.quitAll()
self.running = False

3
TermTk/TTkGui/theme.py

@ -27,6 +27,7 @@ from TermTk.TTkCore.color import TTkColor
class TTkTheme():
''' from: https://en.wikipedia.org/wiki/Box-drawing_character
::
@ -84,6 +85,7 @@ class TTkTheme():
(), # TODO: Grid 10
)
''' Grid Types
::
grid0 grid1 grid2 grid3
@ -143,6 +145,7 @@ class TTkTheme():
'',''
)
''' Tab Examples
::
Label1Label2Label3Label4 Label1Label2Label3Label4

10
TermTk/TTkLayouts/boxlayout.py

@ -31,7 +31,9 @@ from TermTk.TTkLayouts.gridlayout import TTkGridLayout
class TTkHBoxLayout(TTkGridLayout):
''' The TTkHBoxLayout class lines up widgets horizontally
```text
::
TTkHBoxLayout
Widget1 Widget2 Widget3
@ -41,13 +43,14 @@ class TTkHBoxLayout(TTkGridLayout):
```
'''
pass
class TTkVBoxLayout(TTkGridLayout):
''' The TTkVBoxLayout class lines up widgets vertically
```text
::
TTkVBoxLayout
Widget 1
@ -58,7 +61,6 @@ class TTkVBoxLayout(TTkGridLayout):
Widget 4
```
'''
def addItem(self, item):
TTkGridLayout.addItem(self, item, self.count(), 0)

5
TermTk/TTkLayouts/gridlayout.py

@ -35,7 +35,8 @@ class TTkGridLayout(TTkLayout):
The grid layout allows an automatic place all the widgets in a grid, <br/>
the empty rows/cols are resized to the "columnMinHeight,columnMinWidth" parameters
```
::
TTkGridLayout columnMinWidth
Widget1 Widget2 Widget3
@ -48,7 +49,7 @@ class TTkGridLayout(TTkLayout):
Widget5
(3,3)
```
:param int columnMinWidth: the minimum width of the column, optional, defaults to 0
:param int columnMinHeight: the minimum height of the column, optional, defaults to 0
'''

12
TermTk/TTkLayouts/layout.py

@ -112,10 +112,13 @@ class TTkLayoutItem:
class TTkLayout(TTkLayoutItem):
''' The :class:`TTkLayout` class is the base class of geometry managers. <br/>
It allows free placement of the widgets in the layout area. <br/>
Used mainly to have free range moving :class:`~TermTk.TTkWidgets.window.TTkWindow` because the widgets are not automatically rearranged after a layout event
```
'''
| The :class:`TTkLayout` class is the base class of geometry managers. <br/>
| It allows free placement of the widgets in the layout area. <br/>
| Used mainly to have free range moving :class:`~TermTk.TTkWidgets.window.TTkWindow` because the widgets are not automatically rearranged after a layout event
::
pos(4,2)
pos(16,4)
@ -126,7 +129,6 @@ class TTkLayout(TTkLayoutItem):
```
'''
__slots__ = ('_items', '_zSortedItems', '_parent')
def __init__(self, *args, **kwargs):

5
TermTk/TTkWidgets/TTkPickers/colorpicker.py

@ -197,8 +197,9 @@ class _TTkColorButton(TTkButton):
self.colorClicked.emit(self._textColor)
class TTkColorDialogPicker(TTkWindow,TColor):
'''
### Color Picker Layout sizes:
''' Color Picker Layout sizes:
::
Terminal window (More or less, It is too annoying to redraw this)
[Palette][Color]

2
TermTk/TTkWidgets/graph.py

@ -63,6 +63,8 @@ class TTkGraph(TTkWidget, TColor):
i=0
data = self._data[-w*2:]
# TTkLog.debug(data)
# TODO: use deep unpacking technique to grab couples of values
# https://mathspp.com/blog/pydonts/enumerate-me#deep-unpacking
mv = max(max(map(max,data)),-min(map(min,data)))
zoom = 2*h/mv if mv>0 else 1.0
for i in range(len(data)):

1
TermTk/TTkWidgets/widget.py

@ -36,6 +36,7 @@ import TermTk.libbpytop as lbt
class TTkWidget(TMouseEvents,TKeyEvents):
''' Widget Layout sizes:
::
Terminal area (i.e. XTerm)

1
docs/requirements.txt

@ -49,6 +49,7 @@ sphinx-epytext==0.0.4
sphinx-rtd-theme==0.5.1
sphinxcontrib-applehelp==1.0.2
sphinxcontrib-devhelp==1.0.2
sphinxcontrib-fulltoc==1.2.0
sphinxcontrib-htmlhelp==1.0.3
sphinxcontrib-jsmath==1.0.1
sphinxcontrib-qthelp==1.0.3

15
docs/source/_static/theme_overrides.css

@ -1,4 +1,4 @@
/* In a bid to be "mobile-friendly" by default about 1/3 of the horizontal space is wasted;
/* In a bid to be "mobile-friendly" by default about 1/3 of the horizontal space is wasted;
this CSS removes the wasted space. */
.wy-nav-content {
max-width: none;
@ -18,5 +18,18 @@
.wy-table-responsive {
overflow: visible !important;
}
.wy-menu p {
color: #55a5d9;
height: 32px;
line-height: 32px;
padding: 0 1.618em;
margin: 12px 0 0;
display: block;
font-weight: 700;
text-transform: uppercase;
font-size: 85%;
white-space: nowrap;
}
}

25
docs/source/conf.py

@ -39,6 +39,7 @@ extensions = [
'sphinx.ext.autosectionlabel',
'sphinx_epytext',
'sphinxcontrib_autodocgen',
#'sphinxcontrib.fulltoc',
]
# Add any paths that contain templates here, relative to this directory.
@ -81,7 +82,7 @@ html_context = {'css_files': [
'_static/theme_overrides.css', # override wide tables in RTD theme
]}
# html_theme = 'groundwork'
# html_theme = 'bizstyle'
#html_theme_options = {
# "sidebar_width": '240px',
@ -93,16 +94,16 @@ html_context = {'css_files': [
#}
import m2r
def docstring(app, what, name, obj, options, lines):
md = '\n'.join(lines)
rst = m2r.convert(md)
lines.clear()
lines += rst.splitlines()
def setup(app):
app.connect('autodoc-process-docstring', docstring)
# import m2r
#
# def docstring(app, what, name, obj, options, lines):
# md = '\n'.join(lines)
# rst = m2r.convert(md)
# lines.clear()
# lines += rst.splitlines()
#
# def setup(app):
# app.connect('autodoc-process-docstring', docstring)
import TermTk
@ -129,5 +130,5 @@ autodocgen_config = {
},
# choose a different title for specific modules, e.g. the toplevel one
'module_title_decider': lambda modulename: 'API Reference' if modulename=='TermTk' else modulename,
#'module_title_decider': lambda modulename: 'API Reference' if modulename=='TermTk' else modulename,
}

39
docs/source/index.rst

@ -3,14 +3,47 @@
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.
.. _pyTermTk: https://github.com/ceccopierangiolieugenio/pyTermTk
.. _TermTk: https://github.com/ceccopierangiolieugenio/pyTermTk
.. _TUI: https://en.wikipedia.org/wiki/Text-based_user_interface
.. _pyCuT: https://github.com/ceccopierangiolieugenio/pyCuT
.. _Qt5: https://www.riverbankcomputing.com/static/Docs/PyQt5/
.. _GTK: https://pygobject.readthedocs.io/en/latest/
.. _tkinter: https://docs.python.org/3/library/tkinter.html
Welcome to pyTermTk's documentation!
====================================
Intro
-----
pyTermTk_ is a Text-based user interface library (TUI_)
Evolved from the discontinued project pyCuT_ and inspired by a mix of Qt5_, GTK_, and tkinter_ api definition with a touch of personal interpretation
.. toctree::
:maxdepth: 2
:caption: Contents:
:maxdepth: 1
:caption: Tutorials
tutorial/001-helloworld.rst
tutorial/002-layout.rst
tutorial/003-signalslots.rst
tutorial/004-logging.rst
.. toctree::
:maxdepth: 1
:caption: API Reference
autogen.TermTk/TermTk.libbpytop.rst
autogen.TermTk/TermTk.TTkAbstract.rst
autogen.TermTk/TermTk.TTkCore.rst
autogen.TermTk/TermTk.TTkGui.rst
autogen.TermTk/TermTk.TTkLayouts.rst
autogen.TermTk/TermTk.TTkTemplates.rst
autogen.TermTk/TermTk.TTkTestWidgets.rst
autogen.TermTk/TermTk.TTkTypes.rst
autogen.TermTk/TermTk.TTkWidgets.rst
autogen.TermTk/TermTk.rst
Indices and tables
==================

1
docs/source/tutorial

@ -0,0 +1 @@
../../tutorial/

63
tutorial/001-helloworld.md

@ -1,63 +0,0 @@
# [pyTermTk](https://github.com/ceccopierangiolieugenio/pyTermTk) - Hello World
## Intro
- Creating a simple GUI application using [pyTermTk](https://github.com/ceccopierangiolieugenio/pyTermTk) involves the following steps −
- Import TermTk package.
- Create an [TTk](https://ceccopierangiolieugenio.github.io/pyTermTk/TTkCore/ttk.html) object.
- Add a [TTkLabel](https://ceccopierangiolieugenio.github.io/pyTermTk/TTkWidgets/label.html) object in it with the caption "**hello world**" in the position (x=5,y=2).
- Enter the mainloop of application by [mainloop()](https://ceccopierangiolieugenio.github.io/pyTermTk/TTkCore/ttk.html#TermTk.TTkCore.ttk.TTk.mainloop) method.
## Example 1
Following is the code to execute [Hello World program](helloworld/helloworld.001.py) in [pyTermTk](https://github.com/ceccopierangiolieugenio/pyTermTk) −
```python
import TermTk as ttk
root = ttk.TTk()
ttk.TTkLabel(parent=root, pos=(5,2), text="Hello World")
root.mainloop()
```
The above code produces the following output
```text
Hello World
```
## Example 2 - Your first Window
Following is the code to execute [Hello World program](helloworld/helloworld.002.py) in [pyTermTk](https://github.com/ceccopierangiolieugenio/pyTermTk) −
```python
import TermTk as ttk
# Create a root object (it is a widget that represent the terminal)
root = ttk.TTk()
# Create a window and attach it to the root (parent=root)
helloWin = ttk.TTkWindow(parent=root,pos = (1,1), size=(30,10), title="Hello Window", border=True)
# Define the Label and attach it to the window (parent=helloWin)
ttk.TTkLabel(parent=helloWin, pos=(5,5), text="Hello World")
# Start the Main loop
root.mainloop()
```
The above code produces the following output (yuhuuuuu!!!)
```text
╔════════════════════════════╗
║ Hello Window ║
╟────────────────────────────╢
║ ║
║ ║
║ Hello World ║
║ ║
║ ║
║ ║
╚════════════════════════════╝
```

34
tutorial/001-helloworld.rst

@ -1,7 +1,7 @@
.. _pyTermTk: https://github.com/ceccopierangiolieugenio/pyTermTk
.. _TTk: https://ceccopierangiolieugenio.github.io/pyTermTk/TTkCore/ttk.html
.. _TTkLabel: https://ceccopierangiolieugenio.github.io/pyTermTk/TTkWidgets/label.html
.. _mainloop(): https://ceccopierangiolieugenio.github.io/pyTermTk/TTkCore/ttk.html#TermTk.TTkCore.ttk.TTk.mainloop
.. _pyTermTk: https://github.com/ceccopierangiolieugenio/pyTermTk
.. _TTk: https://ceccopierangiolieugenio.github.io/pyTermTk/autogen.TermTk/TermTk.TTkCore.ttk.html#TermTk.TTkCore.ttk.TTk
.. _mainloop(): https://ceccopierangiolieugenio.github.io/pyTermTk/autogen.TermTk/TermTk.TTkCore.ttk.html#TermTk.TTkCore.ttk.TTk.mainloop
.. _TTkLabel: https://ceccopierangiolieugenio.github.io/pyTermTk/autogen.TermTk/TermTk.TTkWidgets.label.html#TermTk.TTkWidgets.label.TTkLabel
=============================================================================
pyTermTk_ - Hello World
@ -12,16 +12,18 @@ Intro
Creating a simple GUI application using pyTermTk_ involves the following steps:
* Import TermTk package.
* Create an TTk_ object.
* Add a TTkLabel_ object in it with the caption "**hello world**" in the position (x=5,y=2).
* Enter the mainloop of application by `mainloop()`_ method.
* pippo :class:`~TermTk.TTkCore.constant.TTkConstant.Alignment`
- Import TermTk package.
- Create an TTk_ object.
- Add a TTkLabel_ object in it with the caption "**hello world**" in the position (x=5,y=2).
- Enter the mainloop of application by `mainloop()`_ method.
Examples
========
Example 1
=========
---------
Following is the code to execute [Hello World program](helloworld/helloworld.001.py) in [pyTermTk](https://github.com/ceccopierangiolieugenio/pyTermTk) −
Following is the code to execute `helloworld.001.py <helloworld/helloworld.001.py>`_ in pyTermTk_:
.. code:: python
@ -31,21 +33,20 @@ Following is the code to execute [Hello World program](helloworld/helloworld.001
ttk.TTkLabel(parent=root, pos=(5,2), text="Hello World")
root.mainloop()
The above code produces the following output
::
Hello World
Example 2 - Your first Window
=============================
-----------------------------
Following is the code to execute [Hello World program](helloworld/helloworld.002.py) in [pyTermTk](https://github.com/ceccopierangiolieugenio/pyTermTk) −
Following is the code to execute `helloworld.002.py <helloworld/helloworld.002.py>`_ in pyTermTk_:
.. code:: python
import TermTk as ttk
import TermTk as ttk
# Create a root object (it is a widget that represent the terminal)
root = ttk.TTk()
@ -61,6 +62,7 @@ Following is the code to execute [Hello World program](helloworld/helloworld.002
The above code produces the following output (yuhuuuuu!!!)
::
╔════════════════════════════╗

327
tutorial/002-layout.md

@ -1,327 +0,0 @@
# [pyTermTk](https://github.com/ceccopierangiolieugenio/pyTermTk) - Hello World
## Intro
[TTkLayouts](https://ceccopierangiolieugenio.github.io/pyTermTk/TTkLayouts/index.html) are specialised classes that allow the placement of the widgets.
### [TTkLayout](https://ceccopierangiolieugenio.github.io/pyTermTk/TTkLayouts/layout.html#TermTk.TTkLayouts.layout.TTkLayout)
This is the base class for all the different layouts.
It allows free placement of the widgets in the layout area.
Used mainly to have free range moving [windows](https://ceccopierangiolieugenio.github.io/pyTermTk/TTkWidgets/window.html) because the widgets are not automatically replaced after a layout event
```text
TTkLayout
╔════════════════════════════╗
║ pos(4,2) ║
║ ┌───────┐ pos(16,4) ║
║ │Widget1│ ┌─────────┐ ║
║ │ │ │ Widget2 │ ║
║ │ │ └─────────┘ ║
║ │ │ ║
║ └───────┘ ║
║ ║
╚════════════════════════════╝
```
### [TTkHBoxLayout](https://ceccopierangiolieugenio.github.io/pyTermTk/TTkLayouts/boxlayout.html#TermTk.TTkLayouts.boxlayout.TTkHBoxLayout)
This layout allow an automatic place all the widgets horizontally
```text
TTkHBoxLayout
╔═════════╤═════════╤═════════╗
║ Widget1 │ Widget2 │ Widget3 ║
║ │ │ ║
║ │ │ ║
║ │ │ ║
║ │ │ ║
║ │ │ ║
╚═════════╧═════════╧═════════╝
```
### [TTkVBoxLayout](https://ceccopierangiolieugenio.github.io/pyTermTk/TTkLayouts/boxlayout.html#TermTk.TTkLayouts.boxlayout.TTkVBoxLayout)
This layout allow an automatic place all the widgets vertically
```text
TTkVBoxLayout
╔═════════════════════════════╗
║ Widget 1 ║
╟─────────────────────────────╢
║ Widget 2 ║
╟─────────────────────────────╢
║ Widget 3 ║
╟─────────────────────────────╢
║ Widget 4 ║
╚═════════════════════════════╝
```
### [TTkGridLayout](https://ceccopierangiolieugenio.github.io/pyTermTk/TTkLayouts/gridlayout.html#TermTk.TTkLayouts.gridlayout.TTkGridLayout)
This layout allow an automatic place all the widgets in a grid
the empty rows/cols are resized to the "columnMinHeight,columnMinWidth" parameters
```
TTkGridLayout ┌┐ columnMinWidth
╔═════════╤═════════╤╤═════════╗
║ Widget1 │ Widget2 ││ Widget3 ║
║ (0,0) │ (0,1) ││ (0,3) ║
╟─────────┼─────────┼┼─────────╢ ┐ columnMinHeight
╟─────────┼─────────┼┼─────────╢ ┘
║ Widget4 │ ││ ║
║ (2,0) │ ││ ║
╟─────────┼─────────┼┼─────────╢
║ │ ││ Widget5 ║
║ │ ││ (3,3) ║
╚═════════╧═════════╧╧═════════╝
```
## Example 1 - Simple [TTkLayout](https://ceccopierangiolieugenio.github.io/pyTermTk/TTkLayouts/layout.html#TermTk.TTkLayouts.layout.TTkLayout)
Following is the code to execute [VBox Example](layout/example1.simple.layout.py) in [pyTermTk](https://github.com/ceccopierangiolieugenio/pyTermTk)
```python
import TermTk as ttk
# TTkLayout is used by default
root = ttk.TTk()
# Attach 4 buttons to the root widget
ttk.TTkButton(parent=root, pos=(0,0), size=(15,5), border=True, text="Button1")
ttk.TTkButton(parent=root, pos=(0,5), size=(10,4), border=True, text="Button2")
ttk.TTkButton(parent=root, pos=(10,6), size=(10,3), border=True, text="Button3")
ttk.TTkButton(parent=root, pos=(13,1), size=(15,3), border=True, text="Button4")
root.mainloop()
```
The above code produces the following output
```text
┌─────────────┐
│ ┌─────────────┐
│ Button1 │ Button4 │
│ ╘═════════════╛
╘═════════════╛
┌────────┐
│Button2 │┌────────┐
│ ││Button3 │
╘════════╛╘════════╛
```
## Example 2 - Simple [TTkVBoxLayout](https://ceccopierangiolieugenio.github.io/pyTermTk/TTkLayouts/boxlayout.html#TermTk.TTkLayouts.boxlayout.TTkVBoxLayout)
Following is the code to execute [VBox Example](layout/example2.simple.vbox.py) in [pyTermTk](https://github.com/ceccopierangiolieugenio/pyTermTk)
```python
import TermTk as ttk
# Set the VBoxLayout as defaut in the terminal widget
root = ttk.TTk(layout=ttk.TTkVBoxLayout())
# Attach 4 buttons to the root widget
ttk.TTkButton(parent=root, border=True, text="Button1")
ttk.TTkButton(parent=root, border=True, text="Button2")
ttk.TTkButton(parent=root, border=True, text="Button3")
ttk.TTkButton(parent=root, border=True, text="Button4")
root.mainloop()
```
The above code produces the following output
```text
┌───────────────────────────────────────────────────────────┐
│ │
│ Button1 │
│ │
╘═══════════════════════════════════════════════════════════╛
┌───────────────────────────────────────────────────────────┐
│ │
│ Button2 │
│ │
╘═══════════════════════════════════════════════════════════╛
┌───────────────────────────────────────────────────────────┐
│ │
│ Button3 │
│ │
╘═══════════════════════════════════════════════════════════╛
┌───────────────────────────────────────────────────────────┐
│ │
│ Button4 │
│ │
╘═══════════════════════════════════════════════════════════╛
```
## Example 3 - Simple [TTkHBoxLayout](https://ceccopierangiolieugenio.github.io/pyTermTk/TTkLayouts/boxlayout.html#TermTk.TTkLayouts.boxlayout.TTkHBoxLayout)
Following is the code to execute [HBox Example](layout/example3.simple.hbox.py) in [pyTermTk](https://github.com/ceccopierangiolieugenio/pyTermTk)
```python
import TermTk as ttk
# Set the HBoxLayout as defaut in the terminal widget
root = ttk.TTk()
root.setLayout(ttk.TTkHBoxLayout())
# Attach 4 buttons to the root widget
ttk.TTkButton(parent=root, border=True, text="Button1")
ttk.TTkButton(parent=root, border=True, text="Button2")
ttk.TTkButton(parent=root, border=True, text="Button3")
ttk.TTkButton(parent=root, border=True, text="Button4")
root.mainloop()
```
The above code produces the following output
```text
┌─────────────┐┌─────────────┐┌─────────────┐┌──────────────┐
│ ││ ││ ││ │
│ ││ ││ ││ │
│ ││ ││ ││ │
│ ││ ││ ││ │
│ ││ ││ ││ │
│ ││ ││ ││ │
│ ││ ││ ││ │
│ ││ ││ ││ │
│ Button1 ││ Button2 ││ Button3 ││ Button4 │
│ ││ ││ ││ │
│ ││ ││ ││ │
│ ││ ││ ││ │
│ ││ ││ ││ │
│ ││ ││ ││ │
│ ││ ││ ││ │
│ ││ ││ ││ │
│ ││ ││ ││ │
│ ││ ││ ││ │
╘═════════════╛╘═════════════╛╘═════════════╛╘══════════════╛
```
## Example 4 - Simple [TTkGridLayout](https://ceccopierangiolieugenio.github.io/pyTermTk/TTkLayouts/gridlayout.html#TermTk.TTkLayouts.gridlayout.TTkGridLayout)
Following is the code to execute [HBox Example](layout/example4.simple.grid.py) in [pyTermTk](https://github.com/ceccopierangiolieugenio/pyTermTk)
```python
import TermTk as ttk
# Set the GridLayout as defaut in the terminal widget
gridLayout = ttk.TTkGridLayout(columnMinHeight=0,columnMinWidth=2)
root = ttk.TTk(layout=gridLayout)
# Attach 2 buttons to the root widget using the default method
# this will append them to the first row
ttk.TTkButton(parent=root, border=True, text="Button1")
ttk.TTkButton(parent=root, border=True, text="Button2")
# Attach 2 buttons to a specific position in the grid
gridLayout.addWidget(ttk.TTkButton(parent=root, border=True, text="Button3"), 1,2)
gridLayout.addWidget(ttk.TTkButton(parent=root, border=True, text="Button4"), 3,4)
root.mainloop()
```
The above code produces the following output
```text
┌───────────┐┌───────────┐
│ ││ │
│ Button1 ││ Button2 │
│ ││ │
╘═══════════╛╘═══════════╛
┌───────────┐
│ │
│ Button3 │
│ │
╘═══════════╛
┌───────────┐
│ │
│ Button4 │
│ │
╘═══════════╛
```
## Example 5 - Nested Layouts
Following is the code to execute [Nested Layouts Example](layout/example5.nested.layouts.py) in [pyTermTk](https://github.com/ceccopierangiolieugenio/pyTermTk)
```python
import TermTk as ttk
# Set the GridLayout as defaut in the terminal widget
root = ttk.TTk()
gridLayout = ttk.TTkGridLayout()
root.setLayout(gridLayout)
# Attach 2 buttons to the root widget using the default method
# this will append them to the first row
# NOTE: it is not recommended to use this legacy method in a gridLayout
ttk.TTkButton(parent=root, border=True, text="Button1")
ttk.TTkButton(parent=root, border=True, text="Button2")
# Attach 2 buttons to a specific position in the grid
gridLayout.addWidget(ttk.TTkButton(border=True, text="Button3"), 1,2)
gridLayout.addWidget(ttk.TTkButton(border=True, text="Button4"), 2,4)
# Create a VBoxLayout and add it to the gridLayout
vboxLayout = ttk.TTkVBoxLayout()
gridLayout.addItem(vboxLayout,1,3)
# Attach 2 buttons to the vBoxLayout
vboxLayout.addWidget(ttk.TTkButton(border=True, text="Button5"))
vboxLayout.addWidget(ttk.TTkButton(border=True, text="Button6"))
root.mainloop()
```
The above code produces the following output
```text
┌─────────┐┌─────────┐
│ ││ │
│ Button1 ││ Button2 │
│ ││ │
╘═════════╛╘═════════╛
┌─────────┐┌─────────┐
│ ││ Button5 │
│ Button3 │╘═════════╛
│ │┌─────────┐
│ ││ Button6 │
╘═════════╛╘═════════╛
┌─────────┐
│ │
│ Button4 │
│ │
╘═════════╛
```
## Example 6 - Rowspan/Colspan in Grid Layout
Following is the code to execute [Nested Layouts Example](layout/example6.grid.span.py) in [pyTermTk](https://github.com/ceccopierangiolieugenio/pyTermTk)
```python
import TermTk as ttk
root = ttk.TTk()
gridLayout = ttk.TTkGridLayout()
root.setLayout(gridLayout)
# | x = 0 | x = 1 | x = 2 |
# | | | |
# ┌────────────────┐┌─────────┐ ──────
# │y=0 x=0 h=1 w=2 ││y=0 x=2 │ y = 0
# │ Button1 ││h=2 w=1 │
# ╘════════════════╛│ │ ──────
# ┌─────────┐ │ Button2 │ y = 1
# │y=1 x=0 │ ╘═════════╛
# │h=2 w=1 │┌────────────────┐ ──────
# │ ││y=2 x=1 h=1 w=2 | y = 2
# │ Button3 ││ Button4 │
# ╘═════════╛╘════════════════╛ ──────
gridLayout.addWidget(ttk.TTkButton(border=True, text="Button1"), 0,0, 1,2)
gridLayout.addWidget(ttk.TTkButton(border=True, text="Button2"), 0,2, 2,1)
gridLayout.addWidget(ttk.TTkButton(border=True, text="Button3"), 1,0, 2,1)
# It is possible to expand the names
gridLayout.addWidget(ttk.TTkButton(border=True, text="Button4"), row=2, col=1, rowspan=1, colspan=2)
root.mainloop()
```
The above code produces the following output
```text
┌───────────────────────┐┌───────────┐
│ ││ │
│ Button1 ││ │
│ ││ │
╘═══════════════════════╛│ Button2 │
┌───────────┐ │ │
│ │ │ │
│ │ │ │
│ │ ╘═══════════╛
│ Button3 │┌───────────────────────┐
│ ││ │
│ ││ Button4 │
│ ││ │
╘═══════════╛╘═══════════════════════╛
```

391
tutorial/002-layout.rst

@ -0,0 +1,391 @@
.. _pyTermTk: https://github.com/ceccopierangiolieugenio/pyTermTk
.. _windows: https://ceccopierangiolieugenio.github.io/pyTermTk/TTkWidgets/window.html
.. _TTkLabel: https://ceccopierangiolieugenio.github.io/pyTermTk/autogen.TermTk/TermTk.TTkWidgets.label.html#TermTk.TTkWidgets.label.TTkLabel
.. _TTkLayouts: https://ceccopierangiolieugenio.github.io/pyTermTk/TTkLayouts/index.html
.. _TTkLayout: https://ceccopierangiolieugenio.github.io/pyTermTk/TTkLayouts/layout.html#TermTk.TTkLayouts.layout.TTkLayout
.. _TTkHBoxLayout: https://ceccopierangiolieugenio.github.io/pyTermTk/TTkLayouts/boxlayout.html#TermTk.TTkLayouts.boxlayout.TTkHBoxLayout
.. _TTkVBoxLayout: https://ceccopierangiolieugenio.github.io/pyTermTk/TTkLayouts/boxlayout.html#TermTk.TTkLayouts.boxlayout.TTkVBoxLayout
.. _TTkGridLayout: https://ceccopierangiolieugenio.github.io/pyTermTk/TTkLayouts/gridlayout.html#TermTk.TTkLayouts.gridlayout.TTkGridLayout
.. _Layout Example: https://github.com/ceccopierangiolieugenio/pyTermTk/blob/main/tutorial/layout/example1.simple.layout.py
.. _VBox Example: https://github.com/ceccopierangiolieugenio/pyTermTk/blob/main/tutorial/layout/example2.simple.vbox.py
.. _HBox Example: https://github.com/ceccopierangiolieugenio/pyTermTk/blob/main/tutorial/layout/example3.simple.hbox.py
.. _Grid Example: https://github.com/ceccopierangiolieugenio/pyTermTk/blob/main/tutorial/layout/example4.simple.grid.py
.. _Nested Layouts Example: https://github.com/ceccopierangiolieugenio/pyTermTk/blob/main/tutorial/layout/example5.nested.layouts.py
.. _`row/colspan Example`: https://github.com/ceccopierangiolieugenio/pyTermTk/blob/main/tutorial/layout/example6.grid.span.py
=============================================================================
pyTermTk_ - Layouts
=============================================================================
Intro
=====
TTkLayouts_ are specialised classes that allow the placement of the widgets.
TTkLayout_
----------
| This is the base class for all the different layouts.
| It allows free placement of the widgets in the layout area.
| Used mainly to have free range moving windows_ because the widgets are not automatically replaced after a layout event
::
TTkLayout
╔════════════════════════════╗
║ pos(4,2) ║
║ ┌───────┐ pos(16,4) ║
║ │Widget1│ ┌─────────┐ ║
║ │ │ │ Widget2 │ ║
║ │ │ └─────────┘ ║
║ │ │ ║
║ └───────┘ ║
║ ║
╚════════════════════════════╝
TTkHBoxLayout_
--------------
This layout allow an automatic place all the widgets horizontally
::
TTkHBoxLayout
╔═════════╤═════════╤═════════╗
║ Widget1 │ Widget2 │ Widget3 ║
║ │ │ ║
║ │ │ ║
║ │ │ ║
║ │ │ ║
║ │ │ ║
╚═════════╧═════════╧═════════╝
TTkVBoxLayout_
--------------
This layout allow an automatic place all the widgets vertically
::
TTkVBoxLayout
╔═════════════════════════════╗
║ Widget 1 ║
╟─────────────────────────────╢
║ Widget 2 ║
╟─────────────────────────────╢
║ Widget 3 ║
╟─────────────────────────────╢
║ Widget 4 ║
╚═════════════════════════════╝
TTkGridLayout_
--------------
This layout allow an automatic place all the widgets in a grid the empty rows/cols are resized to the "columnMinHeight,columnMinWidth" parameters
::
TTkGridLayout ┌┐ columnMinWidth
╔═════════╤═════════╤╤═════════╗
║ Widget1 │ Widget2 ││ Widget3 ║
║ (0,0) │ (0,1) ││ (0,3) ║
╟─────────┼─────────┼┼─────────╢ ┐ columnMinHeight
╟─────────┼─────────┼┼─────────╢ ┘
║ Widget4 │ ││ ║
║ (2,0) │ ││ ║
╟─────────┼─────────┼┼─────────╢
║ │ ││ Widget5 ║
║ │ ││ (3,3) ║
╚═════════╧═════════╧╧═════════╝
Examples
========
1 - Simple TTkLayout_
---------------------
Following is the code to execute `Layout Example`_ in pyTermTk_
.. code:: python
import TermTk as ttk
# TTkLayout is used by default
root = ttk.TTk()
# Attach 4 buttons to the root widget
ttk.TTkButton(parent=root, pos=(0,0), size=(15,5), border=True, text="Button1")
ttk.TTkButton(parent=root, pos=(0,5), size=(10,4), border=True, text="Button2")
ttk.TTkButton(parent=root, pos=(10,6), size=(10,3), border=True, text="Button3")
ttk.TTkButton(parent=root, pos=(13,1), size=(15,3), border=True, text="Button4")
root.mainloop()
The above code produces the following output:
::
┌─────────────┐
│ ┌─────────────┐
│ Button1 │ Button4 │
│ ╘═════════════╛
╘═════════════╛
┌────────┐
│Button2 │┌────────┐
│ ││Button3 │
╘════════╛╘════════╛
2 - Simple TTkVBoxLayout_
-------------------------
Following is the code to execute `VBox Example`_ in pyTermTk_
.. code:: python
import TermTk as ttk
# Set the VBoxLayout as defaut in the terminal widget
root = ttk.TTk(layout=ttk.TTkVBoxLayout())
# Attach 4 buttons to the root widget
ttk.TTkButton(parent=root, border=True, text="Button1")
ttk.TTkButton(parent=root, border=True, text="Button2")
ttk.TTkButton(parent=root, border=True, text="Button3")
ttk.TTkButton(parent=root, border=True, text="Button4")
root.mainloop()
The above code produces the following output:
::
┌───────────────────────────────────────────────────────────┐
│ │
│ Button1 │
│ │
╘═══════════════════════════════════════════════════════════╛
┌───────────────────────────────────────────────────────────┐
│ │
│ Button2 │
│ │
╘═══════════════════════════════════════════════════════════╛
┌───────────────────────────────────────────────────────────┐
│ │
│ Button3 │
│ │
╘═══════════════════════════════════════════════════════════╛
┌───────────────────────────────────────────────────────────┐
│ │
│ Button4 │
│ │
╘═══════════════════════════════════════════════════════════╛
3 - Simple TTkHBoxLayout_
-------------------------
Following is the code to execute `HBox Example`_ in pyTermTk_
.. code:: python
import TermTk as ttk
# Set the HBoxLayout as defaut in the terminal widget
root = ttk.TTk()
root.setLayout(ttk.TTkHBoxLayout())
# Attach 4 buttons to the root widget
ttk.TTkButton(parent=root, border=True, text="Button1")
ttk.TTkButton(parent=root, border=True, text="Button2")
ttk.TTkButton(parent=root, border=True, text="Button3")
ttk.TTkButton(parent=root, border=True, text="Button4")
root.mainloop()
The above code produces the following output
::
┌─────────────┐┌─────────────┐┌─────────────┐┌──────────────┐
│ ││ ││ ││ │
│ ││ ││ ││ │
│ ││ ││ ││ │
│ ││ ││ ││ │
│ ││ ││ ││ │
│ ││ ││ ││ │
│ ││ ││ ││ │
│ ││ ││ ││ │
│ Button1 ││ Button2 ││ Button3 ││ Button4 │
│ ││ ││ ││ │
│ ││ ││ ││ │
│ ││ ││ ││ │
│ ││ ││ ││ │
│ ││ ││ ││ │
│ ││ ││ ││ │
│ ││ ││ ││ │
│ ││ ││ ││ │
│ ││ ││ ││ │
╘═════════════╛╘═════════════╛╘═════════════╛╘══════════════╛
4 - Simple TTkGridLayout_
-------------------------
Following is the code to execute `HBox Example`_ in pyTermTk_
.. code:: python
import TermTk as ttk
# Set the GridLayout as defaut in the terminal widget
gridLayout = ttk.TTkGridLayout(columnMinHeight=0,columnMinWidth=2)
root = ttk.TTk(layout=gridLayout)
# Attach 2 buttons to the root widget using the default method
# this will append them to the first row
ttk.TTkButton(parent=root, border=True, text="Button1")
ttk.TTkButton(parent=root, border=True, text="Button2")
# Attach 2 buttons to a specific position in the grid
gridLayout.addWidget(ttk.TTkButton(parent=root, border=True, text="Button3"), 1,2)
gridLayout.addWidget(ttk.TTkButton(parent=root, border=True, text="Button4"), 3,4)
root.mainloop()
The above code produces the following output
::
┌───────────┐┌───────────┐
│ ││ │
│ Button1 ││ Button2 │
│ ││ │
╘═══════════╛╘═══════════╛
┌───────────┐
│ │
│ Button3 │
│ │
╘═══════════╛
┌───────────┐
│ │
│ Button4 │
│ │
╘═══════════╛
5 - Nested Layouts
------------------
Following is the code to execute `Nested Layouts Example`_ in pyTermTk_
.. code:: python
import TermTk as ttk
# Set the GridLayout as defaut in the terminal widget
root = ttk.TTk()
gridLayout = ttk.TTkGridLayout()
root.setLayout(gridLayout)
# Attach 2 buttons to the root widget using the default method
# this will append them to the first row
# NOTE: it is not recommended to use this legacy method in a gridLayout
ttk.TTkButton(parent=root, border=True, text="Button1")
ttk.TTkButton(parent=root, border=True, text="Button2")
# Attach 2 buttons to a specific position in the grid
gridLayout.addWidget(ttk.TTkButton(border=True, text="Button3"), 1,2)
gridLayout.addWidget(ttk.TTkButton(border=True, text="Button4"), 2,4)
# Create a VBoxLayout and add it to the gridLayout
vboxLayout = ttk.TTkVBoxLayout()
gridLayout.addItem(vboxLayout,1,3)
# Attach 2 buttons to the vBoxLayout
vboxLayout.addWidget(ttk.TTkButton(border=True, text="Button5"))
vboxLayout.addWidget(ttk.TTkButton(border=True, text="Button6"))
root.mainloop()
The above code produces the following output
::
┌─────────┐┌─────────┐
│ ││ │
│ Button1 ││ Button2 │
│ ││ │
╘═════════╛╘═════════╛
┌─────────┐┌─────────┐
│ ││ Button5 │
│ Button3 │╘═════════╛
│ │┌─────────┐
│ ││ Button6 │
╘═════════╛╘═════════╛
┌─────────┐
│ │
│ Button4 │
│ │
╘═════════╛
6 - Rowspan/Colspan in Grid Layout
----------------------------------
Following is the code to execute `row/colspan Example`_ in pyTermTk_
.. code:: python
import TermTk as ttk
root = ttk.TTk()
gridLayout = ttk.TTkGridLayout()
root.setLayout(gridLayout)
# | x = 0 | x = 1 | x = 2 |
# | | | |
# ┌────────────────┐┌─────────┐ ──────
# │y=0 x=0 h=1 w=2 ││y=0 x=2 │ y = 0
# │ Button1 ││h=2 w=1 │
# ╘════════════════╛│ │ ──────
# ┌─────────┐ │ Button2 │ y = 1
# │y=1 x=0 │ ╘═════════╛
# │h=2 w=1 │┌────────────────┐ ──────
# │ ││y=2 x=1 h=1 w=2 | y = 2
# │ Button3 ││ Button4 │
# ╘═════════╛╘════════════════╛ ──────
gridLayout.addWidget(ttk.TTkButton(border=True, text="Button1"), 0,0, 1,2)
gridLayout.addWidget(ttk.TTkButton(border=True, text="Button2"), 0,2, 2,1)
gridLayout.addWidget(ttk.TTkButton(border=True, text="Button3"), 1,0, 2,1)
# It is possible to expand the names
gridLayout.addWidget(ttk.TTkButton(border=True, text="Button4"), row=2, col=1, rowspan=1, colspan=2)
root.mainloop()
The above code produces the following output
::
┌───────────────────────┐┌───────────┐
│ ││ │
│ Button1 ││ │
│ ││ │
╘═══════════════════════╛│ Button2 │
┌───────────┐ │ │
│ │ │ │
│ │ │ │
│ │ ╘═══════════╛
│ Button3 │┌───────────────────────┐
│ ││ │
│ ││ Button4 │
│ ││ │
╘═══════════╛╘═══════════════════════╛

115
tutorial/003-signalslots.md

@ -1,115 +0,0 @@
# [pyTermTk](https://github.com/ceccopierangiolieugenio/pyTermTk) - Signal & Slots
Signals and slots are used for communication between objects.
## Intro
The [TermTk Signal&Slots](https://ceccopierangiolieugenio.github.io/pyTermTk/TTkCore/signal.html) is 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
In GUI programming, when we change one widget, we often want another widget to be notified. More generally, we want objects of any kind to be able to communicate with one another. For example, if a user clicks a Close button, we probably want the window's close() function to be called.
## Signal and Slots
A signal is emitted when a particular event occurs. <br/>
A slot is a function that is called in response to a particular signal. <br/>
[TermTk](https://github.com/ceccopierangiolieugenio/pyTermTk)'s [widgets](https://ceccopierangiolieugenio.github.io/pyTermTk/autogen.TermTk/TermTk.TTkWidgets.html) have many predefined signals/slots, but it is possible to subclass any [widgets](https://ceccopierangiolieugenio.github.io/pyTermTk/autogen.TermTk/TermTk.TTkWidgets.html) and add our own signals/slots to them.
![Signal/Slots](../docs/images/Signal.Slots.001.svg)
## 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 ║
║ ║
║ ║
║ ║
║ ║
║ ║
║ ║
║ ║
║ ║
║ ║
║◀▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓┄┄┄┄┄┄┄┄┄┄┄▶║
╚══════════════════════════════════════════════════════════════════════════════╝
```

157
tutorial/003-signalslots.rst

@ -0,0 +1,157 @@
.. _pyTermTk: https://github.com/ceccopierangiolieugenio/pyTermTk
.. _TermTk: https://github.com/ceccopierangiolieugenio/pyTermTk
.. _`TermTk Signal&Slots`: https://ceccopierangiolieugenio.github.io/pyTermTk/autogen.TermTk/TermTk.TTkCore.signal.html
.. _`Qt5 Signal&Slots`: https://www.riverbankcomputing.com/static/Docs/PyQt5/signals_slots.html
.. _TTkWidgets: https://ceccopierangiolieugenio.github.io/pyTermTk/autogen.TermTk/TermTk.TTkWidgets.html
.. _windows: https://ceccopierangiolieugenio.github.io/pyTermTk/TTkWidgets/window.html
.. _TTkLabel: https://ceccopierangiolieugenio.github.io/pyTermTk/autogen.TermTk/TermTk.TTkWidgets.label.html#TermTk.TTkWidgets.label.TTkLabel
.. _TTkLayouts: https://ceccopierangiolieugenio.github.io/pyTermTk/TTkLayouts/index.html
.. _TTkLayout: https://ceccopierangiolieugenio.github.io/pyTermTk/TTkLayouts/layout.html#TermTk.TTkLayouts.layout.TTkLayout
.. _TTkHBoxLayout: https://ceccopierangiolieugenio.github.io/pyTermTk/TTkLayouts/boxlayout.html#TermTk.TTkLayouts.boxlayout.TTkHBoxLayout
.. _TTkVBoxLayout: https://ceccopierangiolieugenio.github.io/pyTermTk/TTkLayouts/boxlayout.html#TermTk.TTkLayouts.boxlayout.TTkVBoxLayout
.. _TTkGridLayout: https://ceccopierangiolieugenio.github.io/pyTermTk/TTkLayouts/gridlayout.html#TermTk.TTkLayouts.gridlayout.TTkGridLayout
.. _Layout Example: https://github.com/ceccopierangiolieugenio/pyTermTk/blob/main/tutorial/layout/example1.simple.layout.py
.. _VBox Example: https://github.com/ceccopierangiolieugenio/pyTermTk/blob/main/tutorial/layout/example2.simple.vbox.py
.. _HBox Example: https://github.com/ceccopierangiolieugenio/pyTermTk/blob/main/tutorial/layout/example3.simple.hbox.py
.. _Grid Example: https://github.com/ceccopierangiolieugenio/pyTermTk/blob/main/tutorial/layout/example4.simple.grid.py
.. _Nested Layouts Example: https://github.com/ceccopierangiolieugenio/pyTermTk/blob/main/tutorial/layout/example5.nested.layouts.py
.. _`row/colspan Example`: https://github.com/ceccopierangiolieugenio/pyTermTk/blob/main/tutorial/layout/example6.grid.span.py
=============================================================================
pyTermTk_ - Signal & Slots
=============================================================================
Signals and slots are used for communication between objects.
Intro
=====
| The `TermTk Signal&Slots`_ is more than heavily inspired by `Qt5 Signal&Slots`_
| https://doc.qt.io/qt-5/signalsandslots.html
| In GUI programming, when we change one widget, we often want another widget to be notified.
| More generally, we want objects of any kind to be able to communicate with one another.
| For example, if a user clicks a Close button, we probably want the window's close() function to be called.
Signal and Slots
================
| A signal is emitted when a particular event occurs.
| A slot is a function that is called in response to a particular signal.
| TermTk_'s TTkWidgets_ have many predefined signals/slots, but it is possible to subclass any TTkWidgets_ and add our own signals/slots to them.
.. image:: /_static/Signal.Slots.001.svg
Examples
========
Example 1 - basic signal slots
------------------------------
From `example1.basic.signalslots.py <https://github.com/ceccopierangiolieugenio/pyTermTk/blob/main/tutorial/signalslots/example1.basic.signalslots.py>`_
.. code:: 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
::
$ 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 <https://github.com/ceccopierangiolieugenio/pyTermTk/blob/main/tutorial/signalslots/example2.widgets.signalslots.py>`_
.. code:: 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()
A screenshot is totally useless for this example but for the sack of completemess, the above code produces the following output
::
┌────────┐
│ 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 ║
║ ║
║ ║
║ ║
║ ║
║ ║
║ ║
║ ║
║ ║
║ ║
║◀▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓┄┄┄┄┄┄┄┄┄┄┄▶║
╚══════════════════════════════════════════════════════════════════════════════╝

111
tutorial/004-logging.md

@ -1,111 +0,0 @@
# [pyTermTk](https://github.com/ceccopierangiolieugenio/pyTermTk) - Logging
## Intro
The [TTkLog](https://ceccopierangiolieugenio.github.io/pyTermTk/TTkCore/log.html) class provide a set of api to allow and configure the logging.
## Example 1 - Log to file
From [example1.logtofile.py](logging/example1.logtofile.py)
```python
import TermTk as ttk
# session.log is used by default
ttk.TTkLog.use_default_file_logging()
ttk.TTkLog.info( "Test Info Messgae")
ttk.TTkLog.debug( "Test Debug Messgae")
ttk.TTkLog.error( "Test Error Messgae")
ttk.TTkLog.warn( "Test Warning Messgae")
ttk.TTkLog.critical("Test Critical Messgae")
ttk.TTkLog.fatal( "Test Fatal Messgae")
```
## Example 2 - Log to stdout
From [example2.logtostdout.py ](logging/example2.logtostdout.py )
```python
import TermTk as ttk
ttk.TTkLog.use_default_stdout_logging()
ttk.TTkLog.info( "Test Info Messgae")
ttk.TTkLog.debug( "Test Debug Messgae")
ttk.TTkLog.error( "Test Error Messgae")
ttk.TTkLog.warn( "Test Warning Messgae")
ttk.TTkLog.critical("Test Critical Messgae")
ttk.TTkLog.fatal( "Test Fatal Messgae")
```
## Example 3 - custom logging
From [example3.customlogging.py ](logging/example3.customlogging.py )
```python
import TermTk as ttk
# define the callback used to process the log message
def message_handler(mode, context, message):
msgType = "NONE"
if mode == ttk.TTkLog.InfoMsg: msgType = "[INFO]"
elif mode == ttk.TTkLog.WarningMsg: msgType = "[WARNING]"
elif mode == ttk.TTkLog.CriticalMsg: msgType = "[CRITICAL]"
elif mode == ttk.TTkLog.FatalMsg: msgType = "[FATAL]"
elif mode == ttk.TTkLog.ErrorMsg: msgType = "[ERROR]"
print(f"{msgType} {context.file} {message}")
# Register the callback to the message handler
ttk.TTkLog.installMessageHandler(message_handler)
ttk.TTkLog.info( "Test Info Messgae")
ttk.TTkLog.debug( "Test Debug Messgae")
ttk.TTkLog.error( "Test Error Messgae")
ttk.TTkLog.warn( "Test Warning Messgae")
ttk.TTkLog.critical("Test Critical Messgae")
ttk.TTkLog.fatal( "Test Fatal Messgae")
```
## Example 4 - Use [TTkLogViewer](https://ceccopierangiolieugenio.github.io/pyTermTk/TTkTestWidgets/logviewer.html) widget
From [example4.ttklogviewer.py](logging/example4.ttklogviewer.py)
```python
import TermTk as ttk
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())
# Attach the logViewer widget to the window
ttk.TTkLogViewer(parent=logWin)
ttk.TTkLog.info( "Test Info Messgae")
ttk.TTkLog.debug( "Test Debug Messgae")
ttk.TTkLog.error( "Test Error Messgae")
ttk.TTkLog.warn( "Test Warning Messgae")
ttk.TTkLog.critical("Test Critical Messgae")
ttk.TTkLog.fatal( "Test Fatal Messgae")
# Start the Main loop
root.mainloop()
```
The above code produces the following output
```text
╔══════════════════════════════════════════════════════════════════════════════╗
║ LogViewer Window ║
╟──────────────────────────────────────────────────────────────────────────────╢
║ ║
║INFO : tutorial/logging/example4.ttklogviewer.py:36 Test Info Messgae ║
║DEBUG: tutorial/logging/example4.ttklogviewer.py:37 Test Debug Messgae ║
║ERROR: tutorial/logging/example4.ttklogviewer.py:38 Test Error Messgae ║
║WARNING : tutorial/logging/example4.ttklogviewer.py:39 Test Warning Messgae ║
║CRITICAL: tutorial/logging/example4.ttklogviewer.py:40 Test Critical Messgae ║
║FATAL: tutorial/logging/example4.ttklogviewer.py:41 Test Fatal Messgae ║
║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 ║
║ ║
║ ║
║ ║
║◀▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓┄┄┄┄┄┄┄┄┄┄┄▶║
╚══════════════════════════════════════════════════════════════════════════════╝
```

139
tutorial/004-logging.rst

@ -0,0 +1,139 @@
.. _pyTermTk: https://github.com/ceccopierangiolieugenio/pyTermTk
.. _TermTk: https://github.com/ceccopierangiolieugenio/pyTermTk
.. _TTkLog: https://ceccopierangiolieugenio.github.io/pyTermTk/autogen.TermTk/TermTk.TTkCore.log.html
.. _TTlLogViewer: https://ceccopierangiolieugenio.github.io/pyTermTk/autogen.TermTk/TermTk.TTkTestWidgets.logviewer.html
===================
pyTermTk_ - Logging
===================
Intro
=====
The TTkLog_ class provide a set of api to allow and configure the logging.
Examples
========
Example 1 - Log to file
-----------------------
From `example1.logtofile.py <https://github.com/ceccopierangiolieugenio/pyTermTk/blob/main/tutorial/logging/example1.logtofile.py>`_
.. code:: python
import TermTk as ttk
# session.log is used by default
ttk.TTkLog.use_default_file_logging()
# Push some Debug messages
ttk.TTkLog.info( "Test Info Message")
ttk.TTkLog.debug( "Test Debug Message")
ttk.TTkLog.error( "Test Error Message")
ttk.TTkLog.warn( "Test Warning Message")
ttk.TTkLog.critical("Test Critical Message")
Example 2 - Log to stdout
-------------------------
From `example2.logtostdout.py <https://github.com/ceccopierangiolieugenio/pyTermTk/blob/main/tutorial/logging/example2.logtostdout.py>`_
.. code:: python
import TermTk as ttk
ttk.TTkLog.use_default_stdout_logging()
# Push some Debug messages
ttk.TTkLog.info( "Test Info Message")
ttk.TTkLog.debug( "Test Debug Message")
ttk.TTkLog.error( "Test Error Message")
ttk.TTkLog.warn( "Test Warning Message")
ttk.TTkLog.critical("Test Critical Message")
ttk.TTkLog.fatal( "Test Fatal Message")
Example 3 - custom logging
--------------------------
From `example3.customlogging.py <https://github.com/ceccopierangiolieugenio/pyTermTk/blob/main/tutorial/logging/example3.customlogging.py>`_
.. code:: python
import TermTk as ttk
# define the callback used to process the log message
def message_handler(mode, context, message):
msgType = "NONE"
if mode == ttk.TTkLog.InfoMsg: msgType = "[INFO]"
elif mode == ttk.TTkLog.WarningMsg: msgType = "[WARNING]"
elif mode == ttk.TTkLog.CriticalMsg: msgType = "[CRITICAL]"
elif mode == ttk.TTkLog.FatalMsg: msgType = "[FATAL]"
elif mode == ttk.TTkLog.ErrorMsg: msgType = "[ERROR]"
print(f"{msgType} {context.file} {message}")
# Register the callback to the message handler
ttk.TTkLog.installMessageHandler(message_handler)
# Push some Debug messages
ttk.TTkLog.info( "Test Info Message")
ttk.TTkLog.debug( "Test Debug Message")
ttk.TTkLog.error( "Test Error Message")
ttk.TTkLog.warn( "Test Warning Message")
ttk.TTkLog.critical("Test Critical Message")
ttk.TTkLog.fatal( "Test Fatal Message")
Example 4 - Use TTlLogViewer_ widget
--------------------------------------------------
From `example4.ttklogviewer.py <https://github.com/ceccopierangiolieugenio/pyTermTk/blob/main/tutorial/logging/example4.ttklogviewer.py>`_
.. code:: python
import TermTk as ttk
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())
# Attach the logViewer widget to the window
ttk.TTkLogViewer(parent=logWin)
# Push some Debug messages
ttk.TTkLog.info( "Test Info Message")
ttk.TTkLog.debug( "Test Debug Message")
ttk.TTkLog.error( "Test Error Message")
ttk.TTkLog.warn( "Test Warning Message")
ttk.TTkLog.critical("Test Critical Message")
ttk.TTkLog.fatal( "Test Fatal Message")
# Start the Main loop
root.mainloop()
The above code produces the following output
::
╔══════════════════════════════════════════════════════════════════════════════╗
║ LogViewer Window ║
╟──────────────────────────────────────────────────────────────────────────────╢
║ ║
║INFO : tutorial/logging/example4.ttklogviewer.py:36 Test Info Message ║
║DEBUG: tutorial/logging/example4.ttklogviewer.py:37 Test Debug Message ║
║ERROR: tutorial/logging/example4.ttklogviewer.py:38 Test Error Message ║
║WARNING : tutorial/logging/example4.ttklogviewer.py:39 Test Warning Message ║
║CRITICAL: tutorial/logging/example4.ttklogviewer.py:40 Test Critical Message ║
║FATAL: tutorial/logging/example4.ttklogviewer.py:41 Test Fatal Message ║
║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 ║
║ ║
║ ║
║ ║
║◀▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓┄┄┄┄┄┄┄┄┄┄┄▶║
╚══════════════════════════════════════════════════════════════════════════════╝

8
tutorial/README.md

@ -20,7 +20,7 @@ A list of frequently used modules is given below:
- [TTkTestWidgets](https://ceccopierangiolieugenio.github.io/pyTermTk/TTkTestWidgets) − Classes with basic testing widgets
## Tutorials
- **[Hello World](001-helloworld.md)**
- **[Logging](004-logging.md)**
- **[Layout](002-layout.md)**
- **[Signals and Slots](003-signalslots.md)**
- **[Hello World](001-helloworld.rst)**
- **[Logging](004-logging.rst)**
- **[Layout](002-layout.rst)**
- **[Signals and Slots](003-signalslots.rst)**

12
tutorial/logging/example1.logtofile.py

@ -27,10 +27,10 @@ import TermTk as ttk
# session.log is used by default
ttk.TTkLog.use_default_file_logging()
ttk.TTkLog.info( "Test Info Messgae")
ttk.TTkLog.debug( "Test Debug Messgae")
ttk.TTkLog.error( "Test Error Messgae")
ttk.TTkLog.warn( "Test Warning Messgae")
ttk.TTkLog.critical("Test Critical Messgae")
ttk.TTkLog.fatal( "Test Fatal Messgae")
ttk.TTkLog.info( "Test Info Message")
ttk.TTkLog.debug( "Test Debug Message")
ttk.TTkLog.error( "Test Error Message")
ttk.TTkLog.warn( "Test Warning Message")
ttk.TTkLog.critical("Test Critical Message")
ttk.TTkLog.fatal( "Test Fatal Message")

12
tutorial/logging/example2.logtostdout.py

@ -26,9 +26,9 @@ import TermTk as ttk
ttk.TTkLog.use_default_stdout_logging()
ttk.TTkLog.info( "Test Info Messgae")
ttk.TTkLog.debug( "Test Debug Messgae")
ttk.TTkLog.error( "Test Error Messgae")
ttk.TTkLog.warn( "Test Warning Messgae")
ttk.TTkLog.critical("Test Critical Messgae")
ttk.TTkLog.fatal( "Test Fatal Messgae")
ttk.TTkLog.info( "Test Info Message")
ttk.TTkLog.debug( "Test Debug Message")
ttk.TTkLog.error( "Test Error Message")
ttk.TTkLog.warn( "Test Warning Message")
ttk.TTkLog.critical("Test Critical Message")
ttk.TTkLog.fatal( "Test Fatal Message")

12
tutorial/logging/example3.customlogging.py

@ -37,9 +37,9 @@ def message_handler(mode, context, message):
# Register the callback to the message handler
ttk.TTkLog.installMessageHandler(message_handler)
ttk.TTkLog.info( "Test Info Messgae")
ttk.TTkLog.debug( "Test Debug Messgae")
ttk.TTkLog.error( "Test Error Messgae")
ttk.TTkLog.warn( "Test Warning Messgae")
ttk.TTkLog.critical("Test Critical Messgae")
ttk.TTkLog.fatal( "Test Fatal Messgae")
ttk.TTkLog.info( "Test Info Message")
ttk.TTkLog.debug( "Test Debug Message")
ttk.TTkLog.error( "Test Error Message")
ttk.TTkLog.warn( "Test Warning Message")
ttk.TTkLog.critical("Test Critical Message")
ttk.TTkLog.fatal( "Test Fatal Message")

12
tutorial/logging/example4.ttklogviewer.py

@ -32,12 +32,12 @@ logWin = ttk.TTkWindow(parent=root,pos = (1,1), size=(80,20), title="LogViewer W
# Attach the logViewer widget to the window
ttk.TTkLogViewer(parent=logWin)
ttk.TTkLog.info( "Test Info Messgae")
ttk.TTkLog.debug( "Test Debug Messgae")
ttk.TTkLog.error( "Test Error Messgae")
ttk.TTkLog.warn( "Test Warning Messgae")
ttk.TTkLog.critical("Test Critical Messgae")
ttk.TTkLog.fatal( "Test Fatal Messgae")
ttk.TTkLog.info( "Test Info Message")
ttk.TTkLog.debug( "Test Debug Message")
ttk.TTkLog.error( "Test Error Message")
ttk.TTkLog.warn( "Test Warning Message")
ttk.TTkLog.critical("Test Critical Message")
ttk.TTkLog.fatal( "Test Fatal Message")
# Start the Main loop
root.mainloop()
Loading…
Cancel
Save