Closed MayeulC closed 2 years ago
Slightly cleaner (IMO) patch:
diff --git a/libqnotero/qnoteroItemDelegate.py b/libqnotero/qnoteroItemDelegate.py
index 373e167..1e01ff1 100644
--- a/libqnotero/qnoteroItemDelegate.py
+++ b/libqnotero/qnoteroItemDelegate.py
@@ -47,17 +47,17 @@ class QnoteroItemDelegate(QStyledItemDelegate):
self.tagFont = QFont()
self.tagFont.setBold(True)
self.tagFont.setPointSize(self.boldFont.pointSize() - 2)
- self.dy = QFontMetrics(self.boldFont) \
+ self.dy = int(QFontMetrics(self.boldFont) \
.size(Qt.TextSingleLine, u"Dummy").height() \
- *self.qnotero.theme.lineHeight()
- self.margin = 0.5*self.dy
- self._margin = 0.1*self.dy
+ *self.qnotero.theme.lineHeight())
+ self.margin = self.dy//2
+ self._margin = self.dy//10
self.height = 5*self.dy+self._margin
self.noPdfPixmap = self.qnotero.theme.pixmap(u"nopdf")
self.pdfPixmap = self.qnotero.theme.pixmap(u"pdf")
self.aboutPixmap = self.qnotero.theme.pixmap(u"about")
self.notePixmap = self.qnotero.theme.pixmap(u"note")
- self.pixmapSize = self.pdfPixmap.height()+0.5*self.dy
+ self.pixmapSize = int(self.pdfPixmap.height())+self.dy//2
self.roundness = self.qnotero.theme.roundness()
def sizeHint(self, option, index):
@@ -130,15 +130,15 @@ class QnoteroItemDelegate(QStyledItemDelegate):
# Draw icon
_rect = QRect(option.rect)
- _rect.moveBottom(_rect.bottom() + 0.5*self.dy)
- _rect.moveLeft(_rect.left() + 0.5*self.dy)
+ _rect.moveBottom(_rect.bottom() + self.dy//2)
+ _rect.moveLeft(_rect.left() + self.dy//2)
_rect.setHeight(self.pixmapSize)
_rect.setWidth(self.pixmapSize)
painter.drawPixmap(_rect, pixmap)
# Draw the text
painter.save()
- _rect = option.rect.adjusted(self.pixmapSize+0.5*self.dy, 0.5*self.dy,
+ _rect = option.rect.adjusted(self.pixmapSize+self.dy//2, self.dy//2,
-self.dy, 0)
f = [self.tagFont, self.italicFont, self.regularFont,
Thank you for reporting. The problem was that python 3.1 does not perform implicit casting from float to int.
Hi, I just installed qnotero from the AUR under Arch Linux.
The program displayed the first-time configuration window, and now starts minimized to the tray. So far so good.
However, when I call the search popup, entering a search term makes the program crash (shortly after it writes in the search bar "36 results found"). I note that the window is not floating by default, but it still crashes when I make it floating.
Did the Qt API change? Or is it a Python issue? I use Python 3.10.4 and Qt 6.3.0. It seems like you pass floats to functions that expect ints. You also use a lot
0.5*value
or0.1*value
, wherevalue//2
andvalue//10
could work too, not sure if that could help not to generate floats, but I'd expect so.Casting to ints seems to work around the issue, and the program works fine. See the attached patch, but it is probably a bit rough, as I quickly did this to see if it would help.
Execution log, with me reproducing the issue under both x11 and wayland
``` mcantan@leom039 ~ % qnotero Using Python 3.10.4 (main, Mar 23 2022, 23:05:40) [GCC 11.2.0] libqnotero._themes.light.__init__(): using '/usr/share/qnotero/resources/light' qnotero.reInit(): using GnoteProvider libgnote.__init__(): failed to locate Gnote libzotero.__init__(): zotero_path = b'' libzotero.update(): [Errno 2] Aucun fichier ou dossier de ce type: 'zotero.sqlite' saving! org.kde.kf5.kwindowsystem.kwayland: This compositor does not support the Shadow interface org.kde.kf5.kwindowsystem.kwayland: This compositor does not support the Shadow interface org.kde.kf5.kwindowsystem.kwayland: This compositor does not support the Shadow interface libqnotero._themes.light.__init__(): using '/usr/share/qnotero/resources/light' qnotero.reInit(): using GnoteProvider libgnote.__init__(): failed to locate Gnote libzotero.__init__(): zotero_path = b'/home/mcantan/Zotero' libzotero.update(): indexing completed in 0.118s 92 entries processed libzotero.search(): search for 'dummy' completed in 0.000s libzotero.update(): indexing completed in 0.015s 92 entries processed qt.qpa.wayland: Wayland does not support QWindow::requestActivate() libzotero.search(): search for 'ferro' completed in 0.001s Traceback (most recent call last): File "/usr/lib/python3.10/site-packages/libqnotero/qnoteroItemDelegate.py", line 76, in sizeHint return QSize(0, self.height) TypeError: arguments did not match any overloaded call: QSize(): too many arguments QSize(int, int): argument 2 has unexpected type 'float' QSize(QSize): argument 1 has unexpected type 'int' zsh: IOT instruction (core dumped) qnotero mcantan@leom039 ~ % qnotero -platform xcb Using Python 3.10.4 (main, Mar 23 2022, 23:05:40) [GCC 11.2.0] libqnotero._themes.light.__init__(): using '/usr/share/qnotero/resources/light' qnotero.reInit(): using GnoteProvider libgnote.__init__(): failed to locate Gnote libzotero.__init__(): zotero_path = b'/home/mcantan/Zotero' libzotero.update(): indexing completed in 0.013s 92 entries processed libzotero.search(): search for 'dummy' completed in 0.000s libzotero.search(): search for 'ferro' completed in 0.000s Traceback (most recent call last): File "/usr/lib/python3.10/site-packages/libqnotero/qnoteroItemDelegate.py", line 76, in sizeHint return QSize(0, self.height) TypeError: arguments did not match any overloaded call: QSize(): too many arguments QSize(int, int): argument 2 has unexpected type 'float' QSize(QSize): argument 1 has unexpected type 'int' zsh: IOT instruction (core dumped) qnotero -platform xcb mcantan@leom039 ~ % QT_QPA_PLATFORM=xcb qnotero Using Python 3.10.4 (main, Mar 23 2022, 23:05:40) [GCC 11.2.0] libqnotero._themes.light.__init__(): using '/usr/share/qnotero/resources/light' qnotero.reInit(): using GnoteProvider libgnote.__init__(): failed to locate Gnote libzotero.__init__(): zotero_path = b'/home/mcantan/Zotero' libzotero.update(): indexing completed in 0.013s 92 entries processed libzotero.search(): search for 'dummy' completed in 0.000s libzotero.search(): search for 'ferro' completed in 0.001s Traceback (most recent call last): File "/usr/lib/python3.10/site-packages/libqnotero/qnoteroItemDelegate.py", line 76, in sizeHint return QSize(0, self.height) TypeError: arguments did not match any overloaded call: QSize(): too many arguments QSize(int, int): argument 2 has unexpected type 'float' QSize(QSize): argument 1 has unexpected type 'int' zsh: IOT instruction (core dumped) QT_QPA_PLATFORM=xcb qnotero mcantan@leom039 ~ % ```Multiple backtraces while I add `int()` casts to the code
``` % QT_QPA_PLATFORM=xcb qnotero :) Using Python 3.10.4 (main, Mar 23 2022, 23:05:40) [GCC 11.2.0] libqnotero._themes.light.__init__(): using '/usr/share/qnotero/resources/light' qnotero.reInit(): using GnoteProvider libgnote.__init__(): failed to locate Gnote libzotero.__init__(): zotero_path = b'/home/mcantan/Zotero' libzotero.update(): indexing completed in 0.119s 92 entries processed libzotero.search(): search for 'dummy' completed in 0.001s sysTray.activate(): Activating qnotero reason: 3 libzotero.search(): search for 'ferro' completed in 0.001s Traceback (most recent call last): File "/usr/lib/python3.10/site-packages/libqnotero/qnoteroItemDelegate.py", line 119, in paint _rect = option.rect.adjusted(self._margin, self._margin, TypeError: adjusted(self, int, int, int, int): argument 1 has unexpected type 'float' zsh: IOT instruction (core dumped) QT_QPA_PLATFORM=xcb qnotero mcantan@leom039 ~ % QT_QPA_PLATFORM=xcb qnotero134 :( Using Python 3.10.4 (main, Mar 23 2022, 23:05:40) [GCC 11.2.0] libqnotero._themes.light.__init__(): using '/usr/share/qnotero/resources/light' qnotero.reInit(): using GnoteProvider libgnote.__init__(): failed to locate Gnote libzotero.__init__(): zotero_path = b'/home/mcantan/Zotero' libzotero.update(): indexing completed in 0.012s 92 entries processed libzotero.search(): search for 'dummy' completed in 0.000s sysTray.activate(): Activating qnotero reason: 3 libzotero.search(): search for 'fer' completed in 0.001s Traceback (most recent call last): File "/usr/lib/python3.10/site-packages/libqnotero/qnoteroItemDelegate.py", line 133, in paint _rect.moveBottom(_rect.bottom() + 0.5*self.dy) TypeError: moveBottom(self, int): argument 1 has unexpected type 'float' zsh: IOT instruction (core dumped) QT_QPA_PLATFORM=xcb qnotero mcantan@leom039 ~ % QT_QPA_PLATFORM=xcb qnotero134 :( Using Python 3.10.4 (main, Mar 23 2022, 23:05:40) [GCC 11.2.0] libqnotero._themes.light.__init__(): using '/usr/share/qnotero/resources/light' qnotero.reInit(): using GnoteProvider libgnote.__init__(): failed to locate Gnote libzotero.__init__(): zotero_path = b'/home/mcantan/Zotero' libzotero.update(): indexing completed in 0.012s 92 entries processed libzotero.search(): search for 'dummy' completed in 0.000s sysTray.activate(): Activating qnotero reason: 3 libzotero.search(): search for 'fer' completed in 0.000s Traceback (most recent call last): File "/usr/lib/python3.10/site-packages/libqnotero/qnoteroItemDelegate.py", line 134, in paint _rect.moveLeft(_rect.left() + 0.5*self.dy) TypeError: moveLeft(self, int): argument 1 has unexpected type 'float' zsh: IOT instruction (core dumped) QT_QPA_PLATFORM=xcb qnotero mcantan@leom039 ~ % QT_QPA_PLATFORM=xcb qnotero134 :( Using Python 3.10.4 (main, Mar 23 2022, 23:05:40) [GCC 11.2.0] libqnotero._themes.light.__init__(): using '/usr/share/qnotero/resources/light' qnotero.reInit(): using GnoteProvider libgnote.__init__(): failed to locate Gnote libzotero.__init__(): zotero_path = b'/home/mcantan/Zotero' libzotero.update(): indexing completed in 0.012s 92 entries processed libzotero.search(): search for 'dummy' completed in 0.001s sysTray.activate(): Activating qnotero reason: 3 libzotero.search(): search for 'fer' completed in 0.000s Traceback (most recent call last): File "/usr/lib/python3.10/site-packages/libqnotero/qnoteroItemDelegate.py", line 135, in paint _rect.setHeight(self.pixmapSize) TypeError: setHeight(self, int): argument 1 has unexpected type 'float' zsh: IOT instruction (core dumped) QT_QPA_PLATFORM=xcb qnotero mcantan@leom039 ~ % QT_QPA_PLATFORM=xcb qnotero134 :( Using Python 3.10.4 (main, Mar 23 2022, 23:05:40) [GCC 11.2.0] libqnotero._themes.light.__init__(): using '/usr/share/qnotero/resources/light' qnotero.reInit(): using GnoteProvider libgnote.__init__(): failed to locate Gnote libzotero.__init__(): zotero_path = b'/home/mcantan/Zotero' libzotero.update(): indexing completed in 0.012s 92 entries processed libzotero.search(): search for 'dummy' completed in 0.000s sysTray.activate(): Activating qnotero reason: 3 libzotero.search(): search for 'fer' completed in 0.001s Traceback (most recent call last): File "/usr/lib/python3.10/site-packages/libqnotero/qnoteroItemDelegate.py", line 141, in paint _rect = option.rect.adjusted(self.pixmapSize+0.5*self.dy, 0.5*self.dy, TypeError: adjusted(self, int, int, int, int): argument 1 has unexpected type 'float' zsh: IOT instruction (core dumped) QT_QPA_PLATFORM=xcb qnotero mcantan@leom039 ~ % QT_QPA_PLATFORM=xcb qnotero134 :( Using Python 3.10.4 (main, Mar 23 2022, 23:05:40) [GCC 11.2.0] libqnotero._themes.light.__init__(): using '/usr/share/qnotero/resources/light' qnotero.reInit(): using GnoteProvider libgnote.__init__(): failed to locate Gnote libzotero.__init__(): zotero_path = b'/home/mcantan/Zotero' libzotero.update(): indexing completed in 0.012s 92 entries processed libzotero.search(): search for 'dummy' completed in 0.000s sysTray.activate(): Activating qnotero reason: 3 libzotero.search(): search for 'fer' completed in 0.001s Traceback (most recent call last): File "/usr/lib/python3.10/site-packages/libqnotero/qnoteroItemDelegate.py", line 152, in paint _rect = _rect.adjusted(0, self.dy, 0, 0) TypeError: adjusted(self, int, int, int, int): argument 2 has unexpected type 'float' zsh: IOT instruction (core dumped) QT_QPA_PLATFORM=xcb qnotero mcantan@leom039 ~ % QT_QPA_PLATFORM=xcb qnotero134 :( Using Python 3.10.4 (main, Mar 23 2022, 23:05:40) [GCC 11.2.0] libqnotero._themes.light.__init__(): using '/usr/share/qnotero/resources/light' qnotero.reInit(): using GnoteProvider libgnote.__init__(): failed to locate Gnote libzotero.__init__(): zotero_path = b'/home/mcantan/Zotero' libzotero.update(): indexing completed in 0.012s 92 entries processed libzotero.search(): search for 'dummy' completed in 0.000s sysTray.activate(): Activating qnotero reason: 3 libzotero.search(): search for 'fer' completed in 0.001s libzotero.search(): search for 'ferro' completed in 0.000s ```Here is the full backtrace
``` (gdb) bt full #0 0x00007fd4e0b9834c in __pthread_kill_implementation () from /usr/lib/libc.so.6 No symbol table info available. #1 0x00007fd4e0b4b4b8 in raise () from /usr/lib/libc.so.6 No symbol table info available. #2 0x00007fd4e0b35534 in abort () from /usr/lib/libc.so.6 No symbol table info available. #3 0x00007fd4df344ee4 in qt_message_fatal (message=**Patch that works around the issue**
```diff diff --git a/libqnotero/qnoteroItemDelegate.py b/libqnotero/qnoteroItemDelegate.py index 373e167..26a9070 100644 --- a/libqnotero/qnoteroItemDelegate.py +++ b/libqnotero/qnoteroItemDelegate.py @@ -73,7 +73,7 @@ class QnoteroItemDelegate(QStyledItemDelegate): A QSize """ - return QSize(0, self.height) + return QSize(0, int(self.height)) def paint(self, painter, option, index): @@ -116,8 +116,8 @@ class QnoteroItemDelegate(QStyledItemDelegate): foreground = self.palette.WindowText # Draw the frame - _rect = option.rect.adjusted(self._margin, self._margin, - -2*self._margin, -self._margin) + _rect = option.rect.adjusted(int(self._margin), int(self._margin), + int(-2*self._margin), int(-self._margin)) pen = painter.pen() pen.setColor(self.palette.color(background)) painter.setPen(pen) @@ -130,16 +130,16 @@ class QnoteroItemDelegate(QStyledItemDelegate): # Draw icon _rect = QRect(option.rect) - _rect.moveBottom(_rect.bottom() + 0.5*self.dy) - _rect.moveLeft(_rect.left() + 0.5*self.dy) - _rect.setHeight(self.pixmapSize) - _rect.setWidth(self.pixmapSize) + _rect.moveBottom(int(_rect.bottom() + 0.5*self.dy)) + _rect.moveLeft(int(_rect.left() + 0.5*self.dy)) + _rect.setHeight(int(self.pixmapSize)) + _rect.setWidth(int(self.pixmapSize)) painter.drawPixmap(_rect, pixmap) # Draw the text painter.save() - _rect = option.rect.adjusted(self.pixmapSize+0.5*self.dy, 0.5*self.dy, - -self.dy, 0) + _rect = option.rect.adjusted(int(self.pixmapSize+0.5*self.dy), int(0.5*self.dy), + int(-self.dy), 0) f = [self.tagFont, self.italicFont, self.regularFont, self.boldFont] @@ -149,6 +149,6 @@ class QnoteroItemDelegate(QStyledItemDelegate): textRenderer.setHtml(itemText) painter.translate(_rect.topLeft()) textRenderer.documentLayout().draw(painter, context) - _rect = _rect.adjusted(0, self.dy, 0, 0) + _rect = _rect.adjusted(0, int(self.dy), 0, 0) painter.restore() ```