itom  4.1.0
pythonUiTimer.h
1 /* ********************************************************************
2  itom software
3  URL: http://www.uni-stuttgart.de/ito
4  Copyright (C) 2020, Institut fuer Technische Optik (ITO),
5  Universitaet Stuttgart, Germany
6 
7  This file is part of itom.
8 
9  itom is free software; you can redistribute it and/or modify it
10  under the terms of the GNU Library General Public Licence as published by
11  the Free Software Foundation; either version 2 of the Licence, or (at
12  your option) any later version.
13 
14  itom is distributed in the hope that it will be useful, but
15  WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library
17  General Public Licence for more details.
18 
19  You should have received a copy of the GNU Library General Public License
20  along with itom. If not, see <http://www.gnu.org/licenses/>.
21 *********************************************************************** */
22 
23 #ifndef PYTHONUITIMER_H
24 #define PYTHONUITIMER_H
25 
26 #include "pythonCommon.h"
27 
28 #include <qobject.h>
29 #include <qsharedpointer.h>
30 
31 class QTimer; //forward declaration
32 
33 namespace ito
34 {
35 
36 class TimerCallback : public QObject
37 {
38  Q_OBJECT
39  public:
40  TimerCallback();
41  ~TimerCallback();
42 
43  enum class CallableType
44  {
46 
49 
52 
54  Callable_CFunction
55  };
56 
57  /* If the target is a bounded method, this member holds a Python
58  weak reference (new ref) to the method, that acts as slot.
59  m_boundedInstance is != nullptr then.
60 
61  If the target is an unbounded function,
62  this member holds a new reference to the function itself (that acts as slot).
63  m_boundedInstance is nullptr then. */
64  PyObject *m_function;
65 
66  /* weak reference to the python-class instance of the
67  function (if the function is bounded) or nullptr if the function is unbounded*/
68  PyObject *m_boundedInstance;
69 
72 
74  PyObject *m_callbackArgs;
75 
76  public slots:
77  void timeout();
78 };
79 
80 
82 {
83 public:
84 
85  //-------------------------------------------------------------------------------------------------
86  // typedefs
87  //-------------------------------------------------------------------------------------------------
88  typedef struct
89  {
90  PyObject_HEAD
91  QSharedPointer<QTimer> timer;
92  QSharedPointer<TimerCallback> callbackFunc;
93  }
94  PyTimer;
95 
96  //-------------------------------------------------------------------------------------------------
97  // Timer
98  //-------------------------------------------------------------------------------------------------
99  static void PyTimer_dealloc(PyTimer *self);
100  static PyObject *PyTimer_new(PyTypeObject *type, PyObject *args, PyObject *kwds);
101  static int PyTimer_init(PyTimer *self, PyObject *args, PyObject *kwds);
102  static PyObject *PyTimer_repr(PyTimer *self);
103 
104  static PyGetSetDef PyTimer_getseters[];
105  static PyMemberDef PyTimer_members[];
106  static PyMethodDef PyTimer_methods[];
107  static PyTypeObject PyTimerType;
108  static PyModuleDef PyTimerModule;
109  static PyObject *PyTimer_start(PyTimer *self);
110  static PyObject *PyTimer_stop(PyTimer *self);
111  static PyObject *PyTimer_isActive(PyTimer *self);
112  static PyObject *PyTimer_setInterval(PyTimer *self, PyObject *args);
113 
114 };
115 
116 }; //end namespace ito
117 
118 #endif
function, written in C, stored in m_function. m_boundedInstance is NULL, since the potential self obj...
Definition: pythonUiTimer.h:88
CallableType
Definition: pythonUiTimer.h:43
unbounded python method, the function is stored in m_function, m_boundedInstance is NULL ...
Definition: pythonUiTimer.h:36
CallableType m_callableType
new reference to a (empty) tuple with arguments passed to the callable function
Definition: pythonUiTimer.h:71
Definition: apiFunctionsGraph.cpp:39
PyObject * m_boundedInstance
type of the python callable (see CallableType)
Definition: pythonUiTimer.h:68
Definition: pythonUiTimer.h:81