aboutsummaryrefslogtreecommitdiffstats
path: root/sources/pyside2/PySide2/QtUiTools/typesystem_uitools.xml
blob: 2ca12e788eec8d36fb2185cd95196dff8cb69ffe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
<?xml version="1.0" encoding="UTF-8"?>
<!--
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt for Python.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 3 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL3 included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 3 requirements
** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 2.0 or (at your option) the GNU General
** Public license version 3 or any later version approved by the KDE Free
** Qt Foundation. The licenses are as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-2.0.html and
** https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/
-->

<typesystem package="PySide2.QtUiTools">
    <load-typesystem name="QtWidgets/typesystem_widgets.xml" generate="no"/>
    <load-typesystem name="QtXml/typesystem_xml.xml" generate="no"/>

    <object-type name="QUiLoader">
      <extra-includes>
        <include file-name="glue/plugins.h" location="local"/>
      </extra-includes>
      <inject-code class="native" position="beginning" file="../glue/qtuitools.cpp" snippet="uitools-loadui"/>
      <inject-code file="../glue/qtuitools.cpp" snippet="quiloader"/>
      <add-function signature="registerCustomWidget(PyObject*)" return-type="void">
         <modify-argument index="1">
            <rename to="customWidgetType"/>
         </modify-argument>
         <inject-documentation format="target" mode="append">
         Registers a Python created custom widget to QUiLoader, so it can be recognized when
         loading a `.ui` file. The custom widget type is passed via the ``customWidgetType`` argument.
         This is needed when you want to override a virtual method of some widget in the interface,
         since duck punching will not work with widgets created by QUiLoader based on the contents
         of the `.ui` file.

         (Remember that `duck punching virtual methods is an invitation for your own demise!
         &lt;https://doc.qt.io/qtforpython/shiboken2/wordsofadvice.html#duck-punching-and-virtual-methods>`_)

         Let's see an obvious example. If you want to create a new widget it's probable you'll end up
         overriding :class:`~PySide2.QtGui.QWidget`'s :meth:`~PySide2.QtGui.QWidget.paintEvent` method.

         .. code-block:: python

            class Circle(QWidget):
                def paintEvent(self, event):
                    painter = QPainter(self)
                    painter.setPen(self.pen)
                    painter.setBrush(QBrush(self.color))
                    painter.drawEllipse(event.rect().center(), 20, 20)

            # ...

            loader = QUiLoader()
            loader.registerCustomWidget(Circle)
            circle = loader.load('circle.ui')
            circle.show()

            # ...
         </inject-documentation>
         <inject-code class="target" position="beginning" file="../glue/qtuitools.cpp" snippet="quiloader-registercustomwidget"/>
      </add-function>
      <modify-function signature="createAction(QObject*,const QString&amp;)">
        <modify-argument index="return">
          <parent index="1" action="add"/>
          <define-ownership class="target" owner="default"/>
        </modify-argument>
      </modify-function>

      <modify-function signature="createActionGroup(QObject*,const QString&amp;)">
        <modify-argument index="return">
          <parent index="1" action="add"/>
          <define-ownership class="target" owner="default"/>
        </modify-argument>
      </modify-function>

      <modify-function signature="createLayout(const QString&amp;,QObject*,const QString&amp;)">
        <modify-argument index="return">
          <parent index="2" action="add"/>
          <define-ownership class="target" owner="default"/>
        </modify-argument>
      </modify-function>

      <modify-function signature="createWidget(const QString&amp;,QWidget*,const QString&amp;)">
        <modify-argument index="return">
            <parent index="2" action="add"/>
            <define-ownership class="target" owner="default"/>
        </modify-argument>
      </modify-function>

      <modify-function signature="load(QIODevice*,QWidget*)">
        <modify-argument index="2">
          <replace-default-expression with="0"/>
          <rename to="parentWidget"/>
        </modify-argument>
        <modify-argument index="return">
           <define-ownership class="target" owner="target"/>
        </modify-argument>
        <inject-code file="../glue/qtuitools.cpp" snippet="quiloader-load-1"/>
     </modify-function>

      <!-- Syntax sugar -->
      <add-function signature="load(QString,QWidget*)" return-type="QWidget*">
        <modify-argument index="2">
          <replace-default-expression with="0"/>
          <rename to="parentWidget"/>
        </modify-argument>
        <modify-argument index="return">
          <define-ownership class="target" owner="target"/>
        </modify-argument>
        <inject-code file="../glue/qtuitools.cpp" snippet="quiloader-load-2"/>
      </add-function>
    </object-type>

    <!--
    After the removal of the 'pysideuic' Python module, many users were unable to generate and
    load UI classes dynamically.
    This function was created to provide an equivalent solution to the 'loadUiType' function from
    Riverbank's PyQt.
    -->
    <add-function signature="loadUiType(const QString&amp; @uifile@)" return-type="PyObject*">
      <inject-documentation format="target" mode="append">
      This function will allow users to generate and load a `.ui` file at runtime, and it returns
      a `tuple` containing the reference to the Python class, and the base class.

      We don't recommend this approach since the workflow should be to generate a Python file
      from the `.ui` file, and then import and load it to use it, but we do understand that
      there are some corner cases when such functionality is required.

      The internal process relies on `uic` being in the PATH, which is the same requirement for
      the new `pyside2-uic` to work (which is just a wrapper around `uic -g python`)

      A Simple use can be:

      .. code-block:: python

        from PySide2.QtUiTools import loadUiType

        generated_class, base_class = loadUiType("themewidget.ui")
        # the values will be:
        #  (&lt;class '__main__.Ui_ThemeWidgetForm'&gt;, &lt;class 'PySide2.QtWidgets.QWidget'&gt;)


      In that case, `generated_class` will be a reference to the Python class,
      and `base_class` will be a reference to the base class.
      </inject-documentation>
      <inject-code file="../glue/qtuitools.cpp" snippet="loaduitype"/>
    </add-function>


</typesystem>