itom
Loading...
Searching...
No Matches
pythonWorkspace.h
1/* ********************************************************************
2 itom software
3 URL: http://www.uni-stuttgart.de/ito
4 Copyright (C) 2023, Institut für Technische Optik (ITO),
5 Universität 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#pragma once
24
25#ifndef Q_MOC_RUN
26 #define PY_ARRAY_UNIQUE_SYMBOL itom_ARRAY_API //see numpy help ::array api :: Miscellaneous :: Importing the api (this line must before include global.h)
27 #define NO_IMPORT_ARRAY
28
29 #include "pythonWrapper.h"
30#endif
31
32#include "../global.h"
33
34#include <qstring.h>
35#include <qhash.h>
36#include <qmutex.h>
37#include <qchar.h>
38#include <qset.h>
39#include <qstringlist.h>
40#include <qobject.h>
41
42// type of outer container
43#define PY_LIST_TUPLE 'l'
44#define PY_MAPPING 'm'
45#define PY_ATTR 'a'
46#define PY_DICT 'd'
47
48// type of key
49#define PY_NUMBER 'n'
50#define PY_STRING 's'
51#define PY_OBJID 'h' // object id (ptr) as hex for all other objects
52
53namespace ito
54{
55
56class PyWorkspaceItem;
57
58//----------------------------------------------------------------------------------------------------------------------------------
64{
65public:
67 {
68 }
70 PyWorkspaceItem(const PyWorkspaceItem &other);
71
73 {
75 stateChilds = 0x01
76 };
77
78 QString m_name;
79 QString m_key;
80 QString m_type;
81 QString m_value;
82 QString m_extendedValue;
84 bool m_exist;
87 QHash<QString, PyWorkspaceItem*> m_childs;
88};
89
90
91class PyWorkspaceContainer : public QObject //each container has one view
92{
93 Q_OBJECT
94public:
95
96 PyWorkspaceContainer(bool globalNotLocal);
98
99 void clear();
100 void loadDictionary(PyObject *obj, const QString &fullNameParentItem = "");
101
102 inline bool isGlobalWorkspace() const { return m_globalNotLocal; }
103 inline bool isRoot(PyWorkspaceItem *item) const { return item == &m_rootItem; }
104 inline void emitGetChildNodes(PyWorkspaceContainer *container, QString fullNameParentItem) { emit getChildNodes(container,fullNameParentItem); }
105
106 ito::PyWorkspaceItem* getItemByFullName(const QString &fullname);
107
108 QMutex m_accessMutex;
109 QSet<QString> m_expandedFullNames; //this full names are recently expanded in the corresponding view (full name is "." + name + "." + subname + "." + subsubname ...)
110 PyWorkspaceItem m_rootItem;
111
112 static QChar delimiter;
113
114private:
115 void loadDictionaryRec(PyObject *obj, const QString &fullNameParentItem, PyWorkspaceItem *parentItem, QStringList &deletedKeys);
116 void parseSinglePyObject(PyWorkspaceItem *item, PyObject *value, const QString &fullName, QStringList &deletedKeys);
117
118 bool isNotInBlacklist(PyObject *obj) const;
119
121 void appendSlotNamesToList(PyObject *objOrType, PyObject *slotNamesList);
122
124 void initUnicodeConstants();
125
126 bool m_globalNotLocal;
127 PyObject *m_dictUnicode;
128 PyObject *m_slotsUnicode;
129 PyObject *m_mroUnicode;
130
131signals:
132 void updateAvailable(PyWorkspaceItem *rootItem, QString fullNameRoot, QStringList recentlyDeletedFullNames); //TODO
133 void getChildNodes(PyWorkspaceContainer *container, QString fullNameParentItem); //signal caught by python //TODO
134};
135
136} //end namespace ito
Definition pythonWorkspace.h:92
void appendSlotNamesToList(PyObject *objOrType, PyObject *slotNamesList)
initializes some Python unicode constant strings. Requires the GIL to do this.
Definition pythonWorkspace.cpp:160
bool isNotInBlacklist(PyObject *obj) const
appends a possible names in slots attribute of objOrType (object or type object) to pre-defined list ...
Definition pythonWorkspace.cpp:93
every item in the workspace is represented by one PyWorkspaceItem
Definition pythonWorkspace.h:64
bool m_isarrayelement
Definition pythonWorkspace.h:85
int m_compatibleParamBaseType
Definition pythonWorkspace.h:83
QString m_key
Definition pythonWorkspace.h:79
ChildState
Definition pythonWorkspace.h:73
@ stateChilds
Definition pythonWorkspace.h:75
@ stateNoChilds
Definition pythonWorkspace.h:74
QString m_type
Definition pythonWorkspace.h:80
QString m_name
Definition pythonWorkspace.h:78
ChildState m_childState
Definition pythonWorkspace.h:86
Definition apiFunctionsGraph.cpp:40