diff --git a/TermTk/TTkCore/signal.py b/TermTk/TTkCore/signal.py index 4613dea5..253e6b7d 100644 --- a/TermTk/TTkCore/signal.py +++ b/TermTk/TTkCore/signal.py @@ -28,7 +28,7 @@ ''' Signals & Slots [`Tutorial `_] -========================= +========================================================================================================================= 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 `_'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 ======= diff --git a/TermTk/TTkCore/ttk.py b/TermTk/TTkCore/ttk.py index ed542dd7..d5bbc43f 100644 --- a/TermTk/TTkCore/ttk.py +++ b/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 diff --git a/TermTk/TTkGui/theme.py b/TermTk/TTkGui/theme.py index 7960182b..e10d56e4 100644 --- a/TermTk/TTkGui/theme.py +++ b/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 + :: ┌──────╔══════╗──────┬──────┐ ┌─┌──────╔══════╗──────┬──────┐─┐ │Label1║Label2║Label3│Label4│ │◀│Label1║Label2║Label3│Label4│▶│ diff --git a/TermTk/TTkLayouts/boxlayout.py b/TermTk/TTkLayouts/boxlayout.py index 1efd8d4e..d0f253ed 100644 --- a/TermTk/TTkLayouts/boxlayout.py +++ b/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) diff --git a/TermTk/TTkLayouts/gridlayout.py b/TermTk/TTkLayouts/gridlayout.py index 84e0e610..8eed4399 100644 --- a/TermTk/TTkLayouts/gridlayout.py +++ b/TermTk/TTkLayouts/gridlayout.py @@ -35,7 +35,8 @@ class TTkGridLayout(TTkLayout): The grid layout allows 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 ║ @@ -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 ''' diff --git a/TermTk/TTkLayouts/layout.py b/TermTk/TTkLayouts/layout.py index 53c41a4f..d7b64b6d 100644 --- a/TermTk/TTkLayouts/layout.py +++ b/TermTk/TTkLayouts/layout.py @@ -112,10 +112,13 @@ class TTkLayoutItem: class TTkLayout(TTkLayoutItem): - ''' The :class:`TTkLayout` class is the base class of geometry managers.
- It allows free placement of the widgets in the layout area.
- 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.
+ | It allows free placement of the widgets in the layout area.
+ | 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): diff --git a/TermTk/TTkWidgets/TTkPickers/colorpicker.py b/TermTk/TTkWidgets/TTkPickers/colorpicker.py index f5a380c2..ab4ba54f 100644 --- a/TermTk/TTkWidgets/TTkPickers/colorpicker.py +++ b/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]───────────┐│ diff --git a/TermTk/TTkWidgets/graph.py b/TermTk/TTkWidgets/graph.py index 296922a8..7e3c3cbe 100644 --- a/TermTk/TTkWidgets/graph.py +++ b/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)): diff --git a/TermTk/TTkWidgets/widget.py b/TermTk/TTkWidgets/widget.py index 5b7b57f0..03d16b11 100644 --- a/TermTk/TTkWidgets/widget.py +++ b/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) ┌─────────────────────────────────────────┐ diff --git a/docs/requirements.txt b/docs/requirements.txt index 2f0295b7..b4bc371d 100644 --- a/docs/requirements.txt +++ b/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 diff --git a/docs/source/_static/theme_overrides.css b/docs/source/_static/theme_overrides.css index bb3d4b94..0a5d9ac7 100644 --- a/docs/source/_static/theme_overrides.css +++ b/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; + } } diff --git a/docs/source/conf.py b/docs/source/conf.py index 71732b16..31b31f94 100644 --- a/docs/source/conf.py +++ b/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, } \ No newline at end of file diff --git a/docs/source/index.rst b/docs/source/index.rst index e26505f5..cf9b339d 100644 --- a/docs/source/index.rst +++ b/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 ================== diff --git a/docs/source/tutorial b/docs/source/tutorial new file mode 120000 index 00000000..c06f7b06 --- /dev/null +++ b/docs/source/tutorial @@ -0,0 +1 @@ +../../tutorial/ \ No newline at end of file diff --git a/tutorial/001-helloworld.md b/tutorial/001-helloworld.md deleted file mode 100644 index 3f979142..00000000 --- a/tutorial/001-helloworld.md +++ /dev/null @@ -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 ║ - ║ ║ - ║ ║ - ║ ║ - ╚════════════════════════════╝ - -``` \ No newline at end of file diff --git a/tutorial/001-helloworld.rst b/tutorial/001-helloworld.rst index e413f1ee..45688426 100644 --- a/tutorial/001-helloworld.rst +++ b/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 `_ 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 `_ 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!!!) + :: ╔════════════════════════════╗ diff --git a/tutorial/002-layout.md b/tutorial/002-layout.md deleted file mode 100644 index a1073521..00000000 --- a/tutorial/002-layout.md +++ /dev/null @@ -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 │ -│ ││ │ -╘═══════════╛╘═══════════════════════╛ -``` diff --git a/tutorial/002-layout.rst b/tutorial/002-layout.rst new file mode 100644 index 00000000..354e1787 --- /dev/null +++ b/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 │ + │ ││ │ + ╘═══════════╛╘═══════════════════════╛ + diff --git a/tutorial/003-signalslots.md b/tutorial/003-signalslots.md deleted file mode 100644 index 27a3780b..00000000 --- a/tutorial/003-signalslots.md +++ /dev/null @@ -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.
-A slot is a function that is called in response to a particular signal.
-[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 ║ - ║ ║ - ║ ║ - ║ ║ - ║ ║ - ║ ║ - ║ ║ - ║ ║ - ║ ║ - ║ ║ - ║◀▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓┄┄┄┄┄┄┄┄┄┄┄▶║ - ╚══════════════════════════════════════════════════════════════════════════════╝ -``` \ No newline at end of file diff --git a/tutorial/003-signalslots.rst b/tutorial/003-signalslots.rst new file mode 100644 index 00000000..6c9380e1 --- /dev/null +++ b/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 `_ + +.. 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 `_ + +.. 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 ║ + ║ ║ + ║ ║ + ║ ║ + ║ ║ + ║ ║ + ║ ║ + ║ ║ + ║ ║ + ║ ║ + ║◀▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓┄┄┄┄┄┄┄┄┄┄┄▶║ + ╚══════════════════════════════════════════════════════════════════════════════╝ diff --git a/tutorial/004-logging.md b/tutorial/004-logging.md deleted file mode 100644 index 0482b381..00000000 --- a/tutorial/004-logging.md +++ /dev/null @@ -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 ║ -║ ║ -║ ║ -║ ║ -║◀▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓┄┄┄┄┄┄┄┄┄┄┄▶║ -╚══════════════════════════════════════════════════════════════════════════════╝ -``` \ No newline at end of file diff --git a/tutorial/004-logging.rst b/tutorial/004-logging.rst new file mode 100644 index 00000000..fd71b212 --- /dev/null +++ b/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 `_ + +.. 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 `_ + +.. 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 `_ + +.. 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 `_ + +.. 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 ║ + ║ ║ + ║ ║ + ║ ║ + ║◀▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓┄┄┄┄┄┄┄┄┄┄┄▶║ + ╚══════════════════════════════════════════════════════════════════════════════╝ diff --git a/tutorial/README.md b/tutorial/README.md index c1618d2a..f80f09c0 100644 --- a/tutorial/README.md +++ b/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)** \ No newline at end of file +- **[Hello World](001-helloworld.rst)** +- **[Logging](004-logging.rst)** +- **[Layout](002-layout.rst)** +- **[Signals and Slots](003-signalslots.rst)** \ No newline at end of file diff --git a/tutorial/logging/example1.logtofile.py b/tutorial/logging/example1.logtofile.py index ace9e9df..a2b33702 100755 --- a/tutorial/logging/example1.logtofile.py +++ b/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") diff --git a/tutorial/logging/example2.logtostdout.py b/tutorial/logging/example2.logtostdout.py index c9da164d..668a5cf0 100755 --- a/tutorial/logging/example2.logtostdout.py +++ b/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") diff --git a/tutorial/logging/example3.customlogging.py b/tutorial/logging/example3.customlogging.py index 4d434e3d..4cb42210 100755 --- a/tutorial/logging/example3.customlogging.py +++ b/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") diff --git a/tutorial/logging/example4.ttklogviewer.py b/tutorial/logging/example4.ttklogviewer.py index 36f51999..51f878ab 100755 --- a/tutorial/logging/example4.ttklogviewer.py +++ b/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() \ No newline at end of file