Uploaded image for project: 'Qt for Python'
  1. Qt for Python
  2. PYSIDE-2716

Fix-up pyside6-uic

    XMLWordPrintable

Details

    • User Story
    • Resolution: Unresolved
    • P2: Important
    • None
    • None
    • Tooling
    • None
    • All

    Description

      Based on feedback from solution engineering (there are 2 issues reported here):

      Issue 1:

      Compiling .ui files into Python classes provide a number of benefits that I value very highly, but I currently need to do a decent amount of post-processing to get the compiled files to interface well with the rest of my projects. The biggest issue I’ve run into with pyside6-uic is technically an issue with the _feature_ import, but since I only run into the bug when using generated classes I decided to include it here.

      The basic issue is that a project that runs fine using the `pyside6-project run` command raises an AttributeError when compiled. For example, the attached qtest.zip project raises the following error after being compiled using `pyside6-project deploy`:

      •         AttributeError: 'MainWindow' object has no attribute 'objectName'. Did you mean: 'object_name'?

      For more details on this issue, I’d recommend checking out this PyInstaller discussion where the problem was initially reported:

      •         https://github.com/orgs/pyinstaller/discussions/7440

       

      In my case, I simply modified my pyside6-uic wrapper utility to inject the code snippet shown in Figure 1 in-between the PySide6 imports and the generated class definition whenever I recompile my .ui files.  

       

      Figure 1. Workaround for _feature_ Bug in Compiled PySide6 Projects

      import sys
      1. Workaround for https://github.com/orgs/pyinstaller/discussions/7440
        if vars().get("_compiled_", False) or getattr(sys, "frozen", False):
            import shibokensupport.feature
         
            # [-1: Ignore] [0: No Features] [1: Snake Case] [2: True Property]
            shibokensupport.feature.pyside_feature_dict[__name__] = 0

       

       Issue 2:

      The second issue I have with pyside6-uic is related to the import statements that are generated whenever you have a .ui file that references resources from a .qrc file. When running `pyside6-project build` the `pyside6-uic` tool appears to simply generate absolute imports without providing the --python-path option. As a result, I couldn’t find a way to make the import statements resolve correctly without putting every .ui and .qrc file in the same directory. For larger projects this makes it increasingly painful to keep any of these resources organized. I gave up on trying to make these imports work and opted to just remove those imports during post-processing and handle loading the resources elsewhere.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            crmaurei Cristian Maureira-Fredes
            shpremna Shyamnath Premnadh
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes