evilsocket / opensnitch

OpenSnitch is a GNU/Linux interactive application firewall inspired by Little Snitch.
GNU General Public License v3.0
9.88k stars 490 forks source link

[BUG] GUI crash on start due to module 'PyQt5.Qt' has no attribute 'QItemDelegate' #821

Closed darkfishy closed 1 year ago

darkfishy commented 1 year ago

Describe the bug opensnitch-ui version 1.5.3 crashes on start with latest pyqt5 version 5.15.8

Include the following information:

To Reproduce Upgrade/Install system Python PyQt5 package from version 5.15.7 to version 5.15.8.

Steps to reproduce the behaviour:

  1. Open opensnitch-ui from a terminal
  2. Application crashes with Python AttributeError for module PyQt5.Qt
  3. See error below

Post error logs: Crash of the GUI:

Traceback (most recent call last):
  File "/usr/bin/opensnitch-ui", line 23, in <module>
    from opensnitch.service import UIService
  File "/usr/lib/python3.10/site-packages/opensnitch/service.py", line 17, in <module>
    from opensnitch.dialogs.stats import StatsDialog
  File "/usr/lib/python3.10/site-packages/opensnitch/dialogs/stats.py", line 18, in <module>
    from opensnitch.customwidgets.main import ColorizedDelegate, ConnectionsTableModel
  File "/usr/lib/python3.10/site-packages/opensnitch/customwidgets/main.py", line 11, in <module>
    class ColorizedDelegate(Qt.QItemDelegate):
AttributeError: module 'PyQt5.Qt' has no attribute 'QItemDelegate'

Expected behavior (optional) GUI starts with no error

Additional context PyQt5 seems to have changed their module structure and now certain widgets aren't available from the Qt module. Instead they are now under QtWidgets module. However, I couldn't find a reference to this change under release notes.

Patch

diff --unified --recursive --text opensnitch.orig/customwidgets/main.py opensnitch.new/customwidgets/main.py
--- opensnitch.orig/customwidgets/main.py   2023-01-29 16:48:01.639124253 +1100
+++ opensnitch.new/customwidgets/main.py    2023-01-29 16:47:35.660013547 +1100
@@ -1,16 +1,16 @@
 from PyQt5 import Qt, QtCore
 from PyQt5.QtGui import QColor, QStandardItemModel, QStandardItem
 from PyQt5.QtSql import QSqlQueryModel, QSqlQuery, QSql
-from PyQt5.QtWidgets import QTableView
+from PyQt5.QtWidgets import QTableView, QItemDelegate, QStyle
 from PyQt5.QtCore import QItemSelectionModel, pyqtSignal, QEvent
 import time
 import math

 from PyQt5.QtCore import QCoreApplication as QC

-class ColorizedDelegate(Qt.QItemDelegate):
+class ColorizedDelegate(QItemDelegate):
     def __init__(self, parent=None, *args, config=None):
-        Qt.QItemDelegate.__init__(self, parent, *args)
+        QItemDelegate.__init__(self, parent, *args)
         self._config = config
         self._alignment = QtCore.Qt.AlignLeft | QtCore.Qt.AlignHCenter

@@ -29,7 +29,7 @@
                 if 'alignment' in self._config:
                     self._alignment = self._config['alignment']

-                if option.state & Qt.QStyle.State_Selected:
+                if option.state & QStyle.State_Selected:
                     painter.setBrush(painter.brush())
                     painter.setPen(painter.pen())
                 painter.drawText(option.rect, self._alignment, value)
UffeJakobsen commented 1 year ago

Just to chime in here - I see exact the same problem with opensnitch-git 1.6.0rc2.r22.acac681-1 opensnitch-ebpf-module-git 1.6.0rc3.r31.276966a-1

Also on archlinux

gustavo-iniguez-goya commented 1 year ago

Thank you @darkfishy @uffejakobsen !!

I think this is fixed now, could you confirm that it's working now?

bingobr commented 1 year ago

Thank you @darkfishy @uffejakobsen !!

I think this is fixed now, could you confirm that it's working now?

the latest commit solved the issue for me. I was wondering why a fresh install was not working. all good now.

gustavo-iniguez-goya commented 1 year ago

update: There's a message on the PyQt mailing list, stating that SIP seems to be broken: " When PyQt5 is built with sip 6.7.6, the PyQt5.Qt class is empty: (...) Works fine after reverting to sip 6.7.5"

https://www.riverbankcomputing.com/pipermail/pyqt/2023-January/045137.html

darkfishy commented 1 year ago

update: There's a message on the PyQt mailing list, stating that SIP seems to be broken:

Thanks @gustavo-iniguez-goya Just saw this message on commit history of PyQt5 package on Archlinux from the maintainer (author of mailing list post). Rebuilt PyQt5 does fix the issue without requiring any changes to opensnitch-ui.

Said so, I think it might still be prudent to keep your changes. I have also verified your changes with version 1.5.3 and it works.

gustavo-iniguez-goya commented 1 year ago

thank you! I'll keep an eye on the mailinglist thread to see if this problem was intended or not.

UffeJakobsen commented 1 year ago

I can confirm that my existing opensnitch installations on archlinux works again after updating to python-pyqt5-5.15.8_2 (defect package was python-pyqt5-5.15.8_1)

Thanks :-) :+1: