127 changed files with 4075 additions and 2367 deletions
|
After Width: | Height: | Size: 22 KiB |
@ -0,0 +1,78 @@
|
||||
.. _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 |
||||
============================================================================= |
||||
|
||||
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. |
||||
|
||||
Examples |
||||
======== |
||||
|
||||
Example 1 |
||||
--------- |
||||
|
||||
Following is the code to execute `helloworld.001.py <helloworld/helloworld.001.py>`_ in pyTermTk_: |
||||
|
||||
.. code:: 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 |
||||
|
||||
:: |
||||
|
||||
Hello World |
||||
|
||||
Example 2 - Your first Window |
||||
----------------------------- |
||||
|
||||
Following is the code to execute `helloworld.002.py <helloworld/helloworld.002.py>`_ in pyTermTk_: |
||||
|
||||
.. code:: 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!!!) |
||||
|
||||
:: |
||||
|
||||
╔════════════════════════════╗ |
||||
║ Hello Window ║ |
||||
╟────────────────────────────╢ |
||||
║ ║ |
||||
║ ║ |
||||
║ Hello World ║ |
||||
║ ║ |
||||
║ ║ |
||||
║ ║ |
||||
╚════════════════════════════╝ |
||||
|
||||
@ -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 │ |
||||
│ ││ │ |
||||
╘═══════════╛╘═══════════════════════╛ |
||||
|
||||
@ -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 ║ |
||||
║ ║ |
||||
║ ║ |
||||
║ ║ |
||||
║ ║ |
||||
║ ║ |
||||
║ ║ |
||||
║ ║ |
||||
║ ║ |
||||
║ ║ |
||||
║◀▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓┄┄┄┄┄┄┄┄┄┄┄▶║ |
||||
╚══════════════════════════════════════════════════════════════════════════════╝ |
||||
@ -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 ║ |
||||
║ ║ |
||||
║ ║ |
||||
║ ║ |
||||
║◀▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓┄┄┄┄┄┄┄┄┄┄┄▶║ |
||||
╚══════════════════════════════════════════════════════════════════════════════╝ |
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue