From ed87c797bae194a78754776f39dffd6a4547e863 Mon Sep 17 00:00:00 2001 From: Dpeta <69427753+Dpeta@users.noreply.github.com> Date: Fri, 17 Feb 2023 19:41:13 +0100 Subject: [PATCH] Fix PyQt5 compatibility --- irc.py | 12 ++++++++---- pesterchum.py | 16 ++++++---------- scripts/ssl_context.py | 2 +- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/irc.py b/irc.py index 64fc0fc..6055ac7 100644 --- a/irc.py +++ b/irc.py @@ -550,10 +550,14 @@ class PesterIRC(QtCore.QThread): mood = Mood(0) self.moodUpdated.emit(nick, mood) elif key.casefold() == "color": - if QtGui.QColor.isValidColorName(value): - color = QtGui.QColor.fromString(value) - else: - color = QtGui.QColor(0, 0, 0) + try: + if QtGui.QColor.isValidColorName(value): + color = QtGui.QColor.fromString(value) + else: + color = QtGui.QColor(0, 0, 0) + except AttributeError: + # PyQt5? + color = QtGui.QColor(value) self.colorUpdated.emit(nick, color) def _tagmsg(self, prefix, tags, *args): diff --git a/pesterchum.py b/pesterchum.py index c0a8c53..9dc911f 100755 --- a/pesterchum.py +++ b/pesterchum.py @@ -2403,16 +2403,14 @@ class PesterWindow(MovingWindow): # Use the class we chose to build the sound set. try: - if "pygame" in sys.modules: + if "pygame" in globals(): if soundclass == pygame.mixer.Sound: self.alarm = soundclass(self.theme["main/sounds/alertsound"]) self.memosound = soundclass(self.theme["main/sounds/memosound"]) self.namesound = soundclass("themes/namealarm.wav") self.ceasesound = soundclass(self.theme["main/sounds/ceasesound"]) self.honksound = soundclass("themes/honk.wav") - if ("PyQt6.QtMultimedia" in sys.modules) or ( - "PyQt5.QtMultimedia" in sys.modules - ): + if "QtMultimedia" in globals(): if soundclass == QtMultimedia.QSoundEffect: self.alarm = soundclass() self.memosound = soundclass() @@ -2459,12 +2457,10 @@ class PesterWindow(MovingWindow): vol = vol_percent / 100.0 for sound in self.sounds: try: - if "pygame" in sys.modules: + if "pygame" in globals(): if self.sound_type == pygame.mixer.Sound: sound.set_volume(vol) - if ("PyQt6.QtMultimedia" in sys.modules) or ( - "PyQt5.QtMultimedia" in sys.modules - ): + if "QtMultimedia" in globals(): if self.sound_type == QtMultimedia.QSoundEffect: sound.setVolume(vol) except Exception as err: @@ -4325,11 +4321,11 @@ class MainProgram(QtCore.QObject): msgbox.exec() # If we're using pygame for sound we need to init - if "pygame" in sys.modules: + if "pygame" in globals(): # we could set the frequency higher but i love how cheesy it sounds try: pygame.mixer.init() - except (pygame.error, Exception) as err: + except Exception as err: print("Warning: No sound! (pygame error: %s)" % err) self.widget = PesterWindow(options, parent=self, app=self.app) diff --git a/scripts/ssl_context.py b/scripts/ssl_context.py index 30938fb..3fac696 100644 --- a/scripts/ssl_context.py +++ b/scripts/ssl_context.py @@ -35,7 +35,7 @@ def get_ssl_context(): the system provided ones, instead relying on a bundle installed with the python installer.""" default_context = ssl.create_default_context() - if "certifi" not in sys.modules: + if "certifi" not in globals(): return default_context # Get age of certifi module