Success !!!
uiFileName = self.get_uiFileName(config)
with importlib.resources.path('nvfieldcap.resources.ui',
uiFileName) as uifilename:
uifilename = uifilename.as_posix()
class Filename_Folder_Widget(QtWidgets.QTabWidget,
pg.Qt.loadUiType(uifilename)[0]):
def __init__(self, parent=None):
super().__init__(parent)
self.setupUi(self)
if 'PySide2' in sys.modules:
self.FileNamingWidget = Filename_Folder_Widget()
Probably also works with PyQt5 too. Haven't tested that yet.
Thanks for all your help!
On Monday, February 1, 2021 at 11:56:33 AM UTC-5 [email protected] wrote:
> Thanks. Working on that now. The latest version for PySide2 on conda is at
> 5.13.2 (at least that's what I'm finding - need to check my channel order)
> My python version is at 3.7.8 for other reasons. I'm current trying out a
> venv and have pip installed PySide2 v5.15.2.
>
> Still in debugger, but...
>
> from PySide2.QtUiTools import loadUiType as ps2_loadUiType
>
> (PySide2)
> ps2_loadUiType(uifilename.as_posix())
> (<class '__main__.Ui_Filename_Folder_Widget'>, <class
> 'PySide2.QtWidgets.QTabWidget'>)
>
> pyqtgraph
> pg.Qt.loadUiType(uifilename.as_posix())
> (<class 'Ui_Filename_Folder_Widget'>, <class
> 'PySide2.QtWidgets.QTabWidget'>)
>
> I haven't finished stepping through the debugger, but I'm hopeful.
>
> On Monday, February 1, 2021 at 11:35:41 AM UTC-5 [email protected]
> wrote:
>
>> On pyside2 5.14.0-5.14.2.1 there were pyuic issues, would recommend going
>> to 5.15.0+ or 5.14.2.2.
>>
>> On Mon, Feb 1, 2021 at 08:32 [email protected] <[email protected]> wrote:
>>
>>> pyqtgraph issue #1102
>>> <https://github.com/pyqtgraph/pyqtgraph/issues/1102>
>>>
>>> On Monday, February 1, 2021 at 11:28:10 AM UTC-5 [email protected]
>>> wrote:
>>>
>>>> I'm starting to think my problem is with the version of PySide2 on my
>>>> conda environment. I went to compare pyqtgraph.Qt.loadUiType with
>>>> PySide2.QtUiTools.loadUiType. It's not there:
>>>>
>>>> from PySide2.QtUiTools import loadUiType
>>>> Traceback (most recent call last):
>>>> File "C:\Program Files\JetBrains\PyCharm Community Edition
>>>> 2020.1\plugins\python-ce\helpers\pydev\_pydevd_bundle\pydevd_exec2.py",
>>>> line 3, in Exec
>>>> exec(exp, global_vars, local_vars)
>>>> File "<input>", line 1, in <module>
>>>> ImportError: cannot import name 'loadUiType' from 'PySide2.QtUiTools'
>>>> (D:\anaconda3\envs\fieldcapenv_pyside\lib\site-packages\PySide2\QtUiTools.cp37-win_amd64.pyd)
>>>>
>>>> PySide2.__version__
>>>> '5.13.2'
>>>>
>>>> I need to be at 5.14.
>>>> On Monday, February 1, 2021 at 9:07:27 AM UTC-5 [email protected]
>>>> wrote:
>>>>
>>>>> Patrick,
>>>>>
>>>>> (Commenting embedded in your reply)
>>>>>
>>>>> On Sunday, January 31, 2021 at 8:31:17 PM UTC-5 Patrick wrote:
>>>>>
>>>>>> It could be that with this code:
>>>>>>
>>>>>> Template, BaseClass = pg.Qt.loadUiType(uifilename.as_posix())
>>>>>> self.FileNamingWidget = Template()
>>>>>> widget = BaseClass()
>>>>>> self.FileNamingWidget.setupUi(widget)
>>>>>>
>>>>>> then "self.FileNamingWidget" and "widget" are different objects,
>>>>>> while defining a new class with:
>>>>>>
>>>>>> class DataPanel(QtWidgets.QWidget,
>>>>>> loadUiType(__file__.split(".py")[0] + ".ui")[0]):
>>>>>>
>>>>>> then an instance of DataPanel is both a subclass of QWidget *and*
>>>>>> whatever loadUiType()[0] returns through multiple inheritance. The type
>>>>>> returned by the loadUiType(...)[0] magic lets the QWidget use the
>>>>>> setupUi()
>>>>>> method as if it were "derived from user interface descriptions created
>>>>>> using uic" as described in the QWidget.setupUi() method documentation.
>>>>>>
>>>>>>
>>>>> The __file__.split(".py")[0] + ".ui")[0]) is what threw me on my
>>>>> misunderstanding on using pysideuic. Your
>>>>> loadUiType(__file__.split(".py")[0]
>>>>> + ".ui")[0] is basically my Template, and I think your QtWidgets.QWidget
>>>>> is my BaseClass
>>>>>
>>>>> I was trying to follow the examples on loadUiType() that returns a
>>>>> form and base class and trying also to use pyqtgraph's Qt.py to handle
>>>>> supporting PyQt5 and PySide2. My MainWIndow gets created fine following
>>>>> the
>>>>> designerExample.py
>>>>> <https://github.com/pyqtgraph/pyqtgraph/blob/master/examples/designerExample.py>
>>>>> :
>>>>>
>>>>> with importlib.resources.path('nvfieldcap.resources.ui',
>>>>> 'NVFieldCap.ui') as uiFile:
>>>>> WindowTemplate, TemplateBaseClass = pg.Qt.loadUiType(uiFile.as_posix())
>>>>>
>>>>> class MainWindow(TemplateBaseClass):
>>>>>
>>>>> def __init__(self, config=None):
>>>>> TemplateBaseClass.__init__(self)
>>>>> # Create the main window
>>>>> self.ui = WindowTemplate()
>>>>> self.ui.setupUi(self)
>>>>>
>>>>> (uiFileName = 'FileNamingWidget.ui' )
>>>>> uiFileName = self.get_uiFileName(config)
>>>>> with importlib.resources.path('nvfieldcap.resources.ui', uiFileName)
>>>>> as uifilename:
>>>>> if 'PySide2' in sys.modules:
>>>>> Template, BaseClass = pg.Qt.loadUiType(uifilename.as_posix())
>>>>>
>>>>> Template and BaseClass are both classes
>>>>> Template,BaseClass
>>>>> (<class 'Ui_Filename_Folder_Widget'>, <class
>>>>> 'PySide2.QtWidgets.QTabWidget'>)
>>>>> Looking at your code again though, I think I should be doing something
>>>>> like
>>>>>
>>>>> Template, BaseClass =
>>>>> QtWidgets.QTabWidget.loadUiType(uifilename.as_posix())
>>>>>
>>>>> My "FileNamingWidget.ui" file starts with:
>>>>>
>>>>> <?xml version="1.0" encoding="UTF-8"?>
>>>>> <ui version="4.0">
>>>>> <class>Filename_Folder_Widget</class>
>>>>> <widget class="QTabWidget" name="Filename_Folder_Widget">
>>>>>
>>>>> *Ok, so QTabWidget doesn't have a loadUiType(). Scratch that.* I'm
>>>>> reading this uifile inside my MainWIndow.__init__ , so I don't know what
>>>>> my
>>>>> class is yet. (Well, I guess I do know it's a QTabWidget.)
>>>>>
>>>>> And no, I don't use the command line uic/pysideuic tools to generate
>>>>>> python files from the .ui, I just build them in QtDesigner and use the
>>>>>> loadUiType(...) method. If I have a subwidget which is inserted
>>>>>> programmatically into a larger form, then I'll have a small class
>>>>>> definition though. So something like this:
>>>>>>
>>>>>> from PySide2 import QtCore, QtGui, QtWidgets
>>>>>> from PySide2.QtUiTools import loadUiType
>>>>>>
>>>>>> class MainPanel(QtWidgets.QWidget, loadUiType("mainpanel.ui")[0]):
>>>>>> def __init__(self, parent=None):
>>>>>> super().__init__(parent)
>>>>>> self.setupUi(self)
>>>>>> # ...
>>>>>> self.subPanel = SubPanel()
>>>>>> self.layout().addItem(self.subPanel)
>>>>>> # ...
>>>>>> # dynamic ui setup for SubPanelWidget, connect signals etc
>>>>>> # ...
>>>>>> class SubPanel(QtWidgets.QFrame, loadUiType("subpanel.ui")[0]):
>>>>>> def __init__(self, parent=None):
>>>>>> super().__init__(parent)
>>>>>> self.setupUi(self)
>>>>>> # ...
>>>>>> # other boilerplate ui setup for SubPanelWidget
>>>>>>
>>>>>> It's not as nice as being able to use the uic.load() method, but this
>>>>>> was the first/only way I got dynamic ui loading with PySide2, so stopped
>>>>>> messing around trying to figure out why load() was giving so much
>>>>>> trouble.
>>>>>>
>>>>>>
>>>>> I'll look over this more and see if I can follow your pattern. Thanks.
>>>>>
>>>>>
>>>>>> (snip)
>>>>>>>>>>>
>>>>>>>>>>> TIm
>>>>>
>>>>>
>>>>>
>>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "pyqtgraph" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to [email protected].
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/pyqtgraph/2db65699-7066-4807-985e-d1bdec077998n%40googlegroups.com
>>>
>>> <https://groups.google.com/d/msgid/pyqtgraph/2db65699-7066-4807-985e-d1bdec077998n%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>>
--
You received this message because you are subscribed to the Google Groups
"pyqtgraph" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/pyqtgraph/657d9021-459f-4b60-acfd-6a5e736cfcc3n%40googlegroups.com.