From c19271958c7346f317dcc8173b8fe2f254bf79d3 Mon Sep 17 00:00:00 2001 From: Eugenio Parodi Date: Tue, 6 Apr 2021 15:19:28 +0100 Subject: [PATCH] Add basic SignalSlots info --- TermTk/TTkCore/canvas.py | 1 - TermTk/TTkCore/constant.py | 1 - TermTk/TTkCore/signal.py | 30 +++++++++++++++++++++++- TermTk/TTkWidgets/widget.py | 2 +- docs/images/Signal.Slots.001.svg | 3 +++ docs/{ => images}/hld.svg | 0 docs/source/_static/Signal.Slots.001.svg | 1 + docs/source/index.rst | 5 ---- tutorial/003-signalslots.md | 13 +++++++++- 9 files changed, 46 insertions(+), 10 deletions(-) create mode 100644 docs/images/Signal.Slots.001.svg rename docs/{ => images}/hld.svg (100%) create mode 120000 docs/source/_static/Signal.Slots.001.svg diff --git a/TermTk/TTkCore/canvas.py b/TermTk/TTkCore/canvas.py index f44a97c8..7d2107df 100644 --- a/TermTk/TTkCore/canvas.py +++ b/TermTk/TTkCore/canvas.py @@ -45,7 +45,6 @@ class TTkCanvas: '_bufferedData', '_bufferedColors', '_visible', '_doubleBuffer') def __init__(self, *args, **kwargs): - self._widget = kwargs.get('widget', None) self._visible = True self._doubleBuffer = False diff --git a/TermTk/TTkCore/constant.py b/TermTk/TTkCore/constant.py index 893d1bab..d7296f57 100644 --- a/TermTk/TTkCore/constant.py +++ b/TermTk/TTkCore/constant.py @@ -138,7 +138,6 @@ class TTkConstant: RIGHT_ALIGN CENTER_ALIGN JUSTIFY - pippo ''' NONE = 0x0000 ''' No Alignment''' diff --git a/TermTk/TTkCore/signal.py b/TermTk/TTkCore/signal.py index 986cb47d..4613dea5 100644 --- a/TermTk/TTkCore/signal.py +++ b/TermTk/TTkCore/signal.py @@ -27,7 +27,35 @@ # https://github.com/ceccopierangiolieugenio/pyCuT/blob/master/cupy/CuTCore/CuSignal.py ''' -[Tutorial](https://github.com/ceccopierangiolieugenio/pyTermTk/blob/main/tutorial/003-signalslots.md) +Signals & Slots [`Tutorial `_] +========================= + + Signals and slots are used for communication between objects. + +Intro +===== + +| The :mod:`TermTk.TTkCore.signal` 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 `_'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 + +Methods +======= + +.. autofunction:: TermTk.pyTTkSignal +.. autodecorator:: TermTk.pyTTkSlot ''' def pyTTkSlot(*args, **kwargs): def pyTTkSlot_d(func): diff --git a/TermTk/TTkWidgets/widget.py b/TermTk/TTkWidgets/widget.py index c0f69604..5b7b57f0 100644 --- a/TermTk/TTkWidgets/widget.py +++ b/TermTk/TTkWidgets/widget.py @@ -167,7 +167,7 @@ class TTkWidget(TMouseEvents,TKeyEvents): def paintEvent(self): ''' - Pain Event callback, + Paint Event callback, ths need to be overridden in the widget. ''' pass diff --git a/docs/images/Signal.Slots.001.svg b/docs/images/Signal.Slots.001.svg new file mode 100644 index 00000000..23b8c1a9 --- /dev/null +++ b/docs/images/Signal.Slots.001.svg @@ -0,0 +1,3 @@ + + +Object 1Signal_1 (int) Signal_2 (str)Signal_3 (str, int)Slot_1 (int, str)Object 3Signal_1 (int, str)Slot_1 (str, int)
Obj2.Signal_1.connect(Obj4.Slot_1)
Obj4.Signal_1.connect(Obj2.Slot_2)
Obj2.Signal_1.connect(Obj4.Slot_1)...
Object 4Signal_1 (int) Slot_1 (str, str)Slot_2 (str, int)Object 2Signal_1 (str, str)Slot_2 (int)Slot_1 (str)
Obj1.Signal_1.connect(Obj2.Slot_2)
Obj1.Signal_1.connect(Obj2.Slot_2)
Obj1.Signal_2.connect(Obj2.Slot_1)
Obj1.Signal_2.connect(Obj2.Slot_1)
Obj3.Signal_1.connect(Obj1.Slot_1)
Obj3.Signal_1.connect(Obj1.Slot_1)
%3CmxGraphModel%3E%3Croot%3E%3CmxCell%20id%3D%220%22%2F%3E%3CmxCell%20id%3D%221%22%20parent%3D%220%22%2F%3E%3CmxCell%20id%3D%222%22%20value%3D%22Obj1.Signal_2.connect(Obj2.Slot_1)%22%20style%3D%22edgeLabel%3Bhtml%3D1%3Balign%3Dcenter%3BverticalAlign%3Dmiddle%3Bresizable%3D0%3Bpoints%3D%5B%5D%3B%22%20vertex%3D%221%22%20connectable%3D%220%22%20parent%3D%221%22%3E%3CmxGeometry%20x%3D%22257.58790272353417%22%20y%3D%2288.00000000000011%22%20as%3D%22geometry%22%2F%3E%3C%2FmxCell%3E%3C%2Froot%3E%3C%2FmxGraphModel%3E%3CmxGraphModel%3E%3Croot%3E%3CmxCell%20id%3D%220%22%2F%3E%3CmxCell%20id%3D%221%22%20parent%3D%220%22%2F%3E%3CmxCell%20id%3D%222%22%20value%3D%22Obj1.Signal_2.connect(Obj2.Slot_1)%22%20style%3D%22edgeLabel%3Bhtml%3D1%3Balign%3Dcenter%3BverticalAlign%3Dmiddle%3Bresizable%3D0%3Bpoints%3D%5B%5D%3B%22%20vertex%3D%221%22%20connectable%3D%220%22%20parent%3D%221%22%3E%3CmxGeometry%20x%3D%22257.58790272353417%22%20y%3D%2288.00000000000011%22%20as%3D%22geometry%22%2F%3E%3C%2FmxCell%3E%3C%2Froot%3E%3C%2FmxGraphModel%3E
%3CmxGraphModel%3E%3Croot%3E%3CmxCell%20id%3D%220%22%2F%3E%3CmxCell%20id%3D%221%22%20parent%3D%220%22%2F%3E%3CmxCell%20id%3D%222%22%20value%3D%22Obj1.Signal_2.connect(Obj2.Slot_1)%22%20style%3D%22edgeLabel%3Bhtml%3D1%3Balign%3Dcenter%3BverticalAlign%3Dmiddle%3Bresizable%3D0%3Bpoints%3D%5B%5D%3B%22%20vertex%3D%221%22%20connectable%3D%220%22%20parent%3D%221%22%3E%3CmxGeometry%20x%3D%22257.58790272353417%22%20y%3D%2288.00000000000011%22%20as%3D%22geometry%22%2F%3E%3C%2FmxCell%3E%3C%2Froot%3E%3C%2FmxGraphModel%3E%3CmxGraphModel%3E%3Croot%3E%3CmxCell%20id%3D%220%22%2F%3E%3CmxCell%20id%3D%221%22%20parent%3D%220%22%2F%3E%3CmxCell%20id%3D%222%22%20value%3D%22Obj1.Signal_2.connect(Obj2.Slot_1)%22%20style%3D%22edgeLabel%3Bhtml%3D1%3Balign%3Dcenter%3BverticalAlign%3Dmiddle%3Bresizable%3D0%3Bpoints%3D%5B%5D%3B%22%20vertex%3D%221%22%20connectable%3D%220%22%20parent%3D%221%22%3E%3CmxGeometry%20x%3D%22257.58790272353417%22%20y%3D%2288.00000000000011%22%20as%3D%22geometry%22%2F%3E%3C%2FmxCell%3E%3C%2Froot%3E%3C%2FmxGraphModel%3E
Obj1.Signal_3.connect(Obj3.Slot_1)
Obj1.Signal_3.connect(Obj4.Slot_2)
Obj1.Signal_3.connect(Obj3.Slot_1)...
Viewer does not support full SVG 1.1
\ No newline at end of file diff --git a/docs/hld.svg b/docs/images/hld.svg similarity index 100% rename from docs/hld.svg rename to docs/images/hld.svg diff --git a/docs/source/_static/Signal.Slots.001.svg b/docs/source/_static/Signal.Slots.001.svg new file mode 120000 index 00000000..bfc8cfe1 --- /dev/null +++ b/docs/source/_static/Signal.Slots.001.svg @@ -0,0 +1 @@ +../../images/Signal.Slots.001.svg \ No newline at end of file diff --git a/docs/source/index.rst b/docs/source/index.rst index 8387328c..e26505f5 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -12,11 +12,6 @@ Welcome to pyTermTk's documentation! autogen.TermTk/TermTk.rst -TermTk main -=================== -.. autoclass:: TermTk.TTkButton -.. autodecorator:: TermTk.pyTTkSlot - Indices and tables ================== diff --git a/tutorial/003-signalslots.md b/tutorial/003-signalslots.md index 0811d6e3..27a3780b 100644 --- a/tutorial/003-signalslots.md +++ b/tutorial/003-signalslots.md @@ -1,9 +1,20 @@ # [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) and more than heavily inspired by [Qt5 Signal&Slots](https://www.riverbankcomputing.com/static/Docs/PyQt5/signals_slots.html) +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)