|
81 | 81 | if PYSIDE6: |
82 | 82 | from PySide6.QtCore import QMetaObject |
83 | 83 | from PySide6.QtUiTools import QUiLoader |
| 84 | + from PySide6.QtUiTools import loadUiType |
84 | 85 | elif PYSIDE2: |
85 | 86 | from PySide2.QtCore import QMetaObject |
86 | 87 | from PySide2.QtUiTools import QUiLoader |
@@ -245,41 +246,42 @@ def loadUi(uifile, baseinstance=None, workingDirectory=None): |
245 | 246 | QMetaObject.connectSlotsByName(widget) |
246 | 247 | return widget |
247 | 248 |
|
248 | | - def loadUiType(uifile, from_imports=False): |
249 | | - """Load a .ui file and return the generated form class and |
250 | | - the Qt base class. |
| 249 | + if PYSIDE2: |
| 250 | + def loadUiType(uifile, from_imports=False): |
| 251 | + """Load a .ui file and return the generated form class and |
| 252 | + the Qt base class. |
251 | 253 |
|
252 | | - The "loadUiType" command convert the ui file to py code |
253 | | - in-memory first and then execute it in a special frame to |
254 | | - retrieve the form_class. |
| 254 | + The "loadUiType" command convert the ui file to py code |
| 255 | + in-memory first and then execute it in a special frame to |
| 256 | + retrieve the form_class. |
255 | 257 |
|
256 | | - Credit: https://stackoverflow.com/a/14195313/15954282 |
257 | | - """ |
| 258 | + Credit: https://stackoverflow.com/a/14195313/15954282 |
| 259 | + """ |
258 | 260 |
|
259 | | - import sys |
260 | | - from io import StringIO |
261 | | - from xml.etree.ElementTree import ElementTree |
262 | | - |
263 | | - from . import QtWidgets |
| 261 | + import sys |
| 262 | + from io import StringIO |
| 263 | + from xml.etree.ElementTree import ElementTree |
264 | 264 |
|
265 | | - # Parse the UI file |
266 | | - etree = ElementTree() |
267 | | - ui = etree.parse(uifile) |
| 265 | + from . import QtWidgets |
| 266 | + |
| 267 | + # Parse the UI file |
| 268 | + etree = ElementTree() |
| 269 | + ui = etree.parse(uifile) |
268 | 270 |
|
269 | | - widget_class = ui.find('widget').get('class') |
270 | | - form_class = ui.find('class').text |
| 271 | + widget_class = ui.find('widget').get('class') |
| 272 | + form_class = ui.find('class').text |
271 | 273 |
|
272 | | - with open(uifile, encoding="utf-8") as fd: |
273 | | - code_stream = StringIO() |
274 | | - frame = {} |
| 274 | + with open(uifile, encoding="utf-8") as fd: |
| 275 | + code_stream = StringIO() |
| 276 | + frame = {} |
275 | 277 |
|
276 | | - compileUi(fd, code_stream, indent=0, from_imports=from_imports) |
277 | | - pyc = compile(code_stream.getvalue(), '<string>', 'exec') |
278 | | - exec(pyc, frame) |
| 278 | + compileUi(fd, code_stream, indent=0, from_imports=from_imports) |
| 279 | + pyc = compile(code_stream.getvalue(), '<string>', 'exec') |
| 280 | + exec(pyc, frame) |
279 | 281 |
|
280 | | - # Fetch the base_class and form class based on their type in the |
281 | | - # xml from designer |
282 | | - form_class = frame['Ui_%s' % form_class] |
283 | | - base_class = getattr(QtWidgets, widget_class) |
| 282 | + # Fetch the base_class and form class based on their type in the |
| 283 | + # xml from designer |
| 284 | + form_class = frame['Ui_%s' % form_class] |
| 285 | + base_class = getattr(QtWidgets, widget_class) |
284 | 286 |
|
285 | | - return form_class, base_class |
| 287 | + return form_class, base_class |
0 commit comments