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

PySide2-uic adds column numbers to the python file when using ">" in CLI

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P3: Somewhat important
    • None
    • 5.13.2
    • Tooling
    • None
    • Windows
      Pyside2-uic
      Python 3.7
    • Windows

    Description

      Hi,

      I've noticed when converting .ui files that contained QTableWidget (when its columns were specified), that the resultant .py file created using PySide2-uic is incorrect because the column index is printed inside the .py file. If the column index is at the top of the file (like shown below) then the 'setupUI' function will work as expected, however occasionally if the UI form is more complex, the column index would be printed within one of the function (e.g. retranslateUi) and then 'setupUI' would fail. 

      The problem only occurs when using pyside2-uic with the > operator and not the -o option.

      Looking at the source code of the pyside2uic project, I think it is caused by a print statement in the uiparser.py file, function addHeader. Here is a snippet 

       

       

      // ~ around line 650
      ...
      item = self.factory.createQObject("QTableWidgetItem""item",(), False)
      if elem.tag == "column":
          print(self.column_counter)
          w.setHorizontalHeaderItem(self.column_counter, item)
          ...

       

      Here is an example of a UI file that will result in incorrect .py file

      <?xml version="1.0" encoding="UTF-8"?>
      <ui version="4.0">
       <class&amp;amp;gt;Form</class&amp;amp;gt;
       <widget class="QWidget" name="Form">
        <property name="geometry">
         <rect>
          <x>0</x>
          <y>0</y>
          <width>672</width>
          <height>477</height>
         </rect>
        </property>
        <property name="windowTitle">
         <string>Form</string>
        </property>
        <layout class="QHBoxLayout" name="horizontalLayout">
         <item>
          <widget class="QTableWidget" name="review_peaklist">
           <property name="minimumSize">
            <size>
             <width>300</width>
             <height>0</height>
            </size>
           </property>
           <row>
            <property name="text">
             <string>New Row</string>
            </property>
           </row>
           <row>
            <property name="text">
             <string>New Row</string>
            </property>
           </row>
           <column>
            <property name="text">
             <string>New Column</string>
            </property>
           </column>
           <column>
            <property name="text">
             <string>New Column</string>
            </property>
           </column>
          </widget>
         </item>
        </layout>
       </widget>
       <resources/>
       <connections/>
      </ui>
      

      Which produces this code when using

      pyside2-uic.exe .\test.ui > .\ui_test.py

      0
      1
      # -*- coding: utf-8 -*-
      
      # Form implementation generated from reading ui file '.\test.ui',
      # licensing of '.\test.ui' applies.
      #
      # Created: Mon Dec  9 09:15:26 2019
      #      by: pyside2-uic  running on PySide2 5.13.2
      #
      # WARNING! All changes made in this file will be lost!
      
      from PySide2 import QtCore, QtGui, QtWidgets
      
      class Ui_Form(object):
          def setupUi(self, Form):
              Form.setObjectName("Form")
              Form.resize(672, 477)
              self.horizontalLayout = QtWidgets.QHBoxLayout(Form)
              self.horizontalLayout.setObjectName("horizontalLayout")
              self.review_peaklist = QtWidgets.QTableWidget(Form)
              self.review_peaklist.setMinimumSize(QtCore.QSize(300, 0))
              self.review_peaklist.setObjectName("review_peaklist")
              self.review_peaklist.setColumnCount(2)
              self.review_peaklist.setRowCount(2)
              item = QtWidgets.QTableWidgetItem()
              self.review_peaklist.setVerticalHeaderItem(0, item)
              item = QtWidgets.QTableWidgetItem()
              self.review_peaklist.setVerticalHeaderItem(1, item)
              item = QtWidgets.QTableWidgetItem()
              self.review_peaklist.setHorizontalHeaderItem(0, item)
              item = QtWidgets.QTableWidgetItem()
              self.review_peaklist.setHorizontalHeaderItem(1, item)
              self.horizontalLayout.addWidget(self.review_peaklist)
      
              self.retranslateUi(Form)
              QtCore.QMetaObject.connectSlotsByName(Form)
      
          def retranslateUi(self, Form):
              Form.setWindowTitle(QtWidgets.QApplication.translate("Form", "Form", None, -1))
              self.review_peaklist.verticalHeaderItem(0).setText(QtWidgets.QApplication.translate("Form", "New Row", None, -1))
              self.review_peaklist.verticalHeaderItem(1).setText(QtWidgets.QApplication.translate("Form", "New Row", None, -1))
              self.review_peaklist.horizontalHeaderItem(0).setText(QtWidgets.QApplication.translate("Form", "New Column", None, -1))
              self.review_peaklist.horizontalHeaderItem(1).setText(QtWidgets.QApplication.translate("Form", "New Column", None, -1))
      
      
      

      Attachments

        1. test.ui
          1 kB
        2. ui_test-bad.py
          4 kB
        3. ui_test-good.py
          2 kB
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            crmaurei Cristian Maureira-Fredes
            lukasz-migas Lukasz Migas
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes