From c8a80976737958b7104cccbfe917643c0434562a Mon Sep 17 00:00:00 2001 From: Dpeta Date: Mon, 3 Oct 2022 15:39:13 +0200 Subject: [PATCH] Prefer PyQt6 QtMultimedia as an audio backend + misc. log/comment/doc corrections --- CHANGELOG.md | 10 +++++--- oyoyo/client.py | 4 ++-- parsetools.py | 2 +- pesterchum.py | 63 ++++++++++++++++++++++++++++++------------------- pyquirks.py | 2 +- 5 files changed, 50 insertions(+), 31 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5acaf74..58c364b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,13 +1,17 @@ # Changelog (This document uses YYYY-MM-DD) -## [v2.4.4] - 2022-09-10 +## [v2.4.4] - 2022-10-03 ### Added - Desync check, verify connection is alive when system time changes by multiple minutes. ### Changed - Made outgoing irc.py functions do an extra check if connection/cli exists. + - Slightly less spammy logging. + - Qt6.4 introduced a platform-independent FFmpeg backend for QtMultimedia, which is a useful alternative so GStreamer on Linux. As such, the audio backend/module preference and import attempt order is now: + - Windows/MacOS: PyQt6 QtMultimedia > PyQt5 QtMultimedia > pygame (used to be PyQt6 QtMultimedia > pygame, PyQt5 QtMultimedia was never imported) + - Linux/Unknown: PyQt6 QtMultimedia > pygame > PyQt5 QtMultimedia (used to be pygame > PyQt6 QtMultimedia > PyQt5 QtMultimedia) ### Fixed - The string for the distraughtfirman smilie being ":distraughtfirman" instead of ":distraughtfirman:". @@ -28,7 +32,7 @@ ### Fixed - Error when setting quirk with PyQt5. -### Depreciated +### Deprecated - Disabled the console for now since no one seems to use it and it caused an issue on import. - Logging.config/configparser logging configuration, not aware of anyone that actually used this. Logging level can still be specified with command line arguments. (-l --logging) @@ -63,7 +67,7 @@ ### Deprecated - Removed the weird metadata support timeout thingy, I think ought to just get the full 005 before we try to get moods. - - Replaced instances of socket.error excepts with OSError, since it's depreciated. + - Replaced instances of socket.error excepts with OSError, since it's deprecated. ## [v2.4] - 2022-06-30 diff --git a/oyoyo/client.py b/oyoyo/client.py index 3993e70..d3406bb 100644 --- a/oyoyo/client.py +++ b/oyoyo/client.py @@ -282,11 +282,11 @@ class IRCClient: IndexError, ValueError, Exception) as e: - PchumLog.warning("Unkown error in conn, " + str(e)) + PchumLog.debug("Miscellaneous exception in conn, " + str(e)) if tries >= 9: raise e tries += 1 - PchumLog.warning("Retrying recv. (attempt %s)" % str(tries)) + PchumLog.debug("Possibly retrying recv. (attempt %s)" % str(tries)) time.sleep(0.1) except socket.timeout as e: diff --git a/parsetools.py b/parsetools.py index 7e613a1..d7a46bd 100644 --- a/parsetools.py +++ b/parsetools.py @@ -163,7 +163,7 @@ class hyperlink(lexercon.Chunk): return self.string class hyperlink_lazy(hyperlink): - """Depreciated since it doesn't seem to turn the full url into a link, + """Deprecated since it doesn't seem to turn the full url into a link, probably not required anyway, best to require a protocol prefix.""" def __init__(self, string): self.string = "http://" + string diff --git a/pesterchum.py b/pesterchum.py index 2e053a8..30b301e 100755 --- a/pesterchum.py +++ b/pesterchum.py @@ -133,33 +133,48 @@ QString = str _ARGUMENTS = parser.parse_args() # Import audio module -if ostools.isLinux(): - # QtMultimedia on linux requires GStreamer + a plugin for decoding wave, - # so using pygame is prefered. - # I think Ubuntu does have this out of the box though. - # We could possibly check for the availability of a plugin via the gstreamer python bindings, - # but I'm not sure if that'd be worth it, as that'd introduce another dependency. - try: - import pygame - except ImportError: - print("Failed to import pygame, falling back to QtMultimedia. " - + "This should also work fine, but for QtMultimedia to work " - + "on Linux you need GStreamer" - + " + a plugin for decoding the wave format.") +# Qt6.4's ffmpeg audio backend makes using QtMultimedia on linux less risky +try: + # PyQt6, QtMultimedia is prefered. + from PyQt6 import QtMultimedia + #print("Audio module is PyQt6 QtMultimedia.") +except ImportError: + if ostools.isWin32() or ostools.isOSX(): + # PyQt5 QtMultimedia has native backends for MacOS and Windows try: - from PyQt6 import QtMultimedia + from PyQt5 import QtMultimedia + print("Using PyQt5 QtMultimedia as sound module. (fallback, PyQt6 QtMultimedia not availible)") except ImportError: - print("Failed to import QtMultimedia, no audio module availible.") -else: - # On Mac and Windows, QtMultimedia should be prefered. - try: - from PyQt6 import QtMultimedia - except ImportError: - print("Failed to import QtMultimedia, falling back to pygame.") + try: + try: + # Mute pygame support print + os.environ['PYGAME_HIDE_SUPPORT_PROMPT'] = "hide" + except: + pass + import pygame + print("Using pygame as sound module. (fallback, PyQt6 QtMultimedia and PyQt5 QtMultimedia not availible)") + except ImportError: + print("All possible audio modules failed to import." + "\nPossible audio modules in order of preference (Windows/MacOS): PyQt6 QtMultimedia > PyQt5 QtMultimedia > pygame") + elif ostools.isLinux() or True: + # PyQt5 QtMultimedia needs gstreamer on linux, so pygame is prefered. try: + try: + # Mute pygame support print + os.environ['PYGAME_HIDE_SUPPORT_PROMPT'] = "hide" + except: + pass import pygame + print("Using pygame as sound module. (fallback, PyQt6 QtMultimedia not availible)") except ImportError: - print("Failed to import QtMultimedia, no audio module availible.") + try: + from PyQt5 import QtMultimedia + print("Using PyQt5 QtMultimedia as sound module. (fallback, PyQt6 QtMultimedia and pygame not availible)") + print("PyQt5 Multimedia will silently fail without GStreamer with relevant" + " plugins on Linux, pygame is prefered when using PyQt5.") + except ImportError: + print("All possible audio modules failed to import." + "\nLPossible audio modules in order of preference (Linux/Unknown): PyQt6 QtMultimedia > pygame > PyQt5 QtMultimedia") class waitingMessageHolder(object): def __init__(self, mainwindow, **msgfuncs): @@ -1449,7 +1464,7 @@ class PesterWindow(MovingWindow): self.updatemenu.activateWindow() """ - Depreciated + Deprecated @QtCore.pyqtSlot() def updatePC(self): @@ -1497,7 +1512,7 @@ class PesterWindow(MovingWindow): self.parent.irc.unresponsive = False if hasattr(self, 'loadingscreen'): if self.loadingscreen != None: - PchumLog.warning("Server alive !! :O") + PchumLog.info("Server alive !! :O") self.loadingscreen.done(QtWidgets.QDialog.DialogCode.Accepted) self.loadingscreen = None diff --git a/pyquirks.py b/pyquirks.py index 5690a47..2dd272a 100644 --- a/pyquirks.py +++ b/pyquirks.py @@ -14,7 +14,7 @@ PchumLog = logging.getLogger('pchumLogger') class PythonQuirks(ScriptQuirks): def loadModule(self, name, filename): - # imp is depreciated since Python 3.4 + # imp is deprecated since Python 3.4 #return imp.load_source(name, filename) spec = importlib.util.spec_from_file_location(name, filename)