View Single Post
Old 01-04-2022, 11:49 AM   #50
un_pogaz
Chalut o/
un_pogaz ought to be getting tired of karma fortunes by now.un_pogaz ought to be getting tired of karma fortunes by now.un_pogaz ought to be getting tired of karma fortunes by now.un_pogaz ought to be getting tired of karma fortunes by now.un_pogaz ought to be getting tired of karma fortunes by now.un_pogaz ought to be getting tired of karma fortunes by now.un_pogaz ought to be getting tired of karma fortunes by now.un_pogaz ought to be getting tired of karma fortunes by now.un_pogaz ought to be getting tired of karma fortunes by now.un_pogaz ought to be getting tired of karma fortunes by now.un_pogaz ought to be getting tired of karma fortunes by now.
 
un_pogaz's Avatar
 
Posts: 447
Karma: 678910
Join Date: Dec 2017
Device: Kobo
Holy moly, it was a bit difficult, but my plugins are Qt6 compatible.
Work, perfectly good. Here my Qt 5-6 compatibility workarounds, I let you judge if it is necessary to add a global retro-compatibility. Ask me for detail.

Code:
try:   ## PyQt6
    QtItemFlags = Qt.ItemFlag
    QPolicy = QSizePolicy.Policy
    QShape = QFrame.Shape
    QShadow = QFrame.Shadow
    QSizeConstraint = QLayout.SizeConstraint
    QTableWidgetType = QTableWidgetItem.ItemType.UserType
    
except:   ## PyQt5
    QtItemFlags = Qt.ItemFlags
    QPolicy = QSizePolicy
    QShape = QFrame
    QShadow = QFrame
    QSizeConstraint = QLayout
    QTableWidgetType = QTableWidgetItem.UserType

QTableWidgetType = 1000
Qt.ItemFlags => Qt.ItemFlag
QSizePolicy => QSizePolicy.Policy ✅ (for enum values: Minimum, Maximum...)
QFrame => QFrame.Shape ✅ (for enum values: NoFrame, HLine...)
QFrame => QFrame.Shadow ✅ (for enum values: Sunken, Plain...)
QLayout => QLayout.SizeConstraint ✅ (for enum values: SetMinimumSize...)

QTableWidgetItem.UserType => QTableWidgetItem.ItemType.UserType

Theoretically, QTableWidgetItem.ItemType.UserType should be the new valid value, but apparently not (throw a error). Fortunately, it's just a numerical constant, so I hard-coded its value to what it should be.
Spoiler:
Error when using QTableWidgetItem.ItemType.UserType
Code:
calibre, version 5.99.1
ERREUR : Exception non gérée: <b>TypeError</b>:QTableWidgetItem(): arguments did not match any overloaded call:
  overload 1: argument 1 has unexpected type 'str'
  overload 2: argument 2 has unexpected type 'ItemType'
  overload 3: argument 1 has unexpected type 'str'
  overload 4: argument 1 has unexpected type 'str'

calibre 5.99.1  embedded-python: True
Windows-10-10.0.19042 Windows ('64bit', 'WindowsPE')
('Windows', '10', '10.0.19042')
Python 3.10.1
Windows: ('10', '10.0.19042', '', 'Multiprocessor Free')
Interface language: fr
Successfully initialized third party plugins: Comments Cleaner (1, 6, 0) && Mass Search-Replace (1, 2, 2)
Traceback (most recent call last):
  File "calibre_plugins.mass_search_replace.action", line 156, in quickSearchReplace
  File "calibre_plugins.mass_search_replace.config", line 946, in __init__
  File "calibre\gui2\widgets2.py", line 223, in __init__
  File "calibre_plugins.mass_search_replace.config", line 966, in setup_ui
  File "calibre_plugins.mass_search_replace.config", line 1129, in __init__
  File "calibre_plugins.mass_search_replace.config", line 1142, in populate_table
  File "calibre_plugins.mass_search_replace.config", line 1152, in populate_table_row
  File "calibre_plugins.mass_search_replace.common_utils", line 305, in __init__
TypeError: QTableWidgetItem(): arguments did not match any overloaded call:
  overload 1: argument 1 has unexpected type 'str'
  overload 2: argument 2 has unexpected type 'ItemType'
  overload 3: argument 1 has unexpected type 'str'
  overload 4: argument 1 has unexpected type 'str'


QTableWidgetType is used in a inherited class from QTableWidgetItem:
Code:
class ReadOnlyTableWidgetItem(QTableWidgetItem):
    def __init__(self, text):
        if text is None:
            text = ''
        QTableWidgetItem.__init__(self, text, QTableWidgetType)
        self.setFlags(Qt.ItemIsSelectable|Qt.ItemIsEnabled)
EDIT:
For fix the QTableWidgetItem.ItemType.UserType issue, use this code:
Code:
try:
    QTableWidgetType = QTableWidgetItem.ItemType.UserType.value
except:
    QTableWidgetType = QTableWidgetItem.UserType
Thanks you @kovidgoyal

Last edited by un_pogaz; 01-04-2022 at 02:00 PM.
un_pogaz is offline   Reply With Quote