Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PICARD-2871: Get rid of QtCore.QObject.tagger #2424

Merged
merged 3 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions picard/acoustid/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ class AcoustIDClient(QtCore.QObject):

def __init__(self, acoustid_api: AcoustIdAPIHelper):
super().__init__()
self.tagger = QtCore.QCoreApplication.instance()
self._queue = deque()
self._running = 0
self._acoustid_api = acoustid_api
Expand Down
1 change: 1 addition & 0 deletions picard/acoustid/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ class AcoustIDManager(QtCore.QObject):

def __init__(self, acoustid_api):
super().__init__()
self.tagger = QtCore.QCoreApplication.instance()
self._submissions = {}
self._acoustid_api = acoustid_api

Expand Down
1 change: 1 addition & 0 deletions picard/album.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ class Album(DataObject, Item):

def __init__(self, album_id, discid=None):
DataObject.__init__(self, album_id)
self.tagger = QtCore.QCoreApplication.instance()
self.metadata = Metadata()
self.orig_metadata = Metadata()
self.tracks = []
Expand Down
5 changes: 3 additions & 2 deletions picard/browser/filelookup.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ def __init__(self, parent, server, port, local_port):
self.server = server
self.local_port = int(local_port)
self.port = port
self.tagger = QtCore.QCoreApplication.instance()

def _url(self, path, params=None):
if params is None:
Expand Down Expand Up @@ -137,10 +138,10 @@ def mbid_lookup(self, string, type_=None, mbid_matched_callback=None, browser_fa
if mbid_matched_callback:
mbid_matched_callback(entity, id)
if entity == 'release':
QtCore.QObject.tagger.load_album(id)
self.tagger.load_album(id)
return True
elif entity == 'recording':
QtCore.QObject.tagger.load_nat(id)
self.tagger.load_nat(id)
return True
elif entity == 'release-group':
AlbumSearchDialog.show_releasegroup_search(id)
Expand Down
1 change: 1 addition & 0 deletions picard/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ class Cluster(FileList):

def __init__(self, name, artist="", special=False, related_album=None, hide_if_empty=False):
super().__init__()
self.tagger = QtCore.QCoreApplication.instance()
self.item = None
self.metadata['album'] = name
self.metadata['albumartist'] = artist
Expand Down
6 changes: 4 additions & 2 deletions picard/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
class Collection(QtCore.QObject):

def __init__(self, collection_id: str, mb_api: MBAPIHelper):
self.tagger = QtCore.QCoreApplication.instance()
self.id = collection_id
self.name = ''
self.size = 0
Expand Down Expand Up @@ -122,12 +123,13 @@ def _success(self, count, callback, status_msg, debug_msg):
def get_user_collection(collection_id):
collection = user_collections.get(collection_id)
if collection is None:
collection = user_collections[collection_id] = Collection(collection_id, QtCore.QObject.tagger.mb_api)
tagger = QtCore.QCoreApplication.instance()
collection = user_collections[collection_id] = Collection(collection_id, tagger.mb_api)
return collection


def load_user_collections(callback=None):
tagger = QtCore.QObject.tagger
tagger = QtCore.QCoreApplication.instance()

def request_finished(document, reply, error):
if error:
Expand Down
6 changes: 4 additions & 2 deletions picard/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,9 @@ def convert(self, value):
profiles = None


def setup_config(app, filename=None):
def setup_config(app=None, filename=None):
if app is None:
app = QtCore.QCoreApplication.instance()
global config, setting, persist, profiles
if filename is None:
config = Config.from_app(app)
Expand All @@ -477,5 +479,5 @@ def load_new_config(filename=None):
except OSError:
log.error("Failed restoring config file from %s", filename)
return False
setup_config(QtCore.QObject.tagger, config_file)
setup_config(filename=config_file)
return True
5 changes: 3 additions & 2 deletions picard/coverart/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from functools import partial
import traceback

from PyQt6.QtCore import QObject
from PyQt6 import QtCore

from picard import log
from picard.config import get_config
Expand Down Expand Up @@ -220,7 +220,8 @@ def _queue_new(self):

def _message(self, *args, **kwargs):
"""Display message to status bar"""
QObject.tagger.window.set_statusbar_message(*args, **kwargs)
tagger = QtCore.QCoreApplication.instance()
tagger.window.set_statusbar_message(*args, **kwargs)


def _retrieve_coverart(album, metadata, release):
Expand Down
5 changes: 3 additions & 2 deletions picard/coverart/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@
import shutil
import tempfile

from PyQt6 import QtCore
from PyQt6.QtCore import (
QMutex,
QObject,
QUrl,
)

Expand Down Expand Up @@ -80,7 +80,8 @@ def __init__(self, data, prefix='picard', suffix=''):
self._hash = blake2b(data).hexdigest()
if self._hash not in _datafiles:
(fd, self._filename) = tempfile.mkstemp(prefix=prefix, suffix=suffix)
QObject.tagger.register_cleanup(self.delete_file)
tagger = QtCore.QCoreApplication.instance()
tagger.register_cleanup(self.delete_file)
with os.fdopen(fd, 'wb') as imagefile:
imagefile.write(data)
_datafiles[self._hash] = self._filename
Expand Down
1 change: 1 addition & 0 deletions picard/disc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class Disc(QtCore.QObject):

def __init__(self, id=None):
super().__init__()
self.tagger = QtCore.QCoreApplication.instance()
self.id = id
self.mcn = None
self.tracks = 0
Expand Down
1 change: 1 addition & 0 deletions picard/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ class PreserveTimesUtimeError(Exception):

def __init__(self, filename):
super().__init__()
self.tagger = QtCore.QCoreApplication.instance()
self.filename = filename
self.base_filename = os.path.basename(filename)
self._state = File.UNDEFINED
Expand Down
5 changes: 3 additions & 2 deletions picard/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
)
from functools import partial

from PyQt6.QtCore import QObject
from PyQt6 import QtCore

from picard.config import get_config
from picard.mbjson import (
Expand Down Expand Up @@ -346,7 +346,8 @@ def compare_to_release_parts(self, release, weights):
weights['releasetype'])

if 'release-group' in release:
rg = QObject.tagger.get_release_group_by_id(release['release-group']['id'])
tagger = QtCore.QCoreApplication.instance()
rg = tagger.get_release_group_by_id(release['release-group']['id'])
if release['id'] in rg.loaded_albums:
parts.append((1.0, 6))

Expand Down
1 change: 1 addition & 0 deletions picard/pluginmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ class PluginManager(QtCore.QObject):

def __init__(self, plugins_directory=None):
super().__init__()
self.tagger = QtCore.QCoreApplication.instance()
self.plugins = []
self._available_plugins = None # None=never loaded, [] = empty
if plugins_directory is None:
Expand Down
3 changes: 3 additions & 0 deletions picard/releasegroup.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
from itertools import combinations
import traceback

from PyQt6 import QtCore

from picard import log
from picard.dataobj import DataObject
from picard.i18n import (
Expand Down Expand Up @@ -108,6 +110,7 @@ class ReleaseGroup(DataObject):

def __init__(self, rg_id):
super().__init__(rg_id)
self.tagger = QtCore.QCoreApplication.instance()
self.metadata = Metadata()
self.loaded = False
self.versions = []
Expand Down
3 changes: 1 addition & 2 deletions picard/tagger.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ def __init__(self, picard_args, localedir, autoupdate, pipe_handler=None):

super().__init__(sys.argv)
self.__class__.__instance = self
setup_config(self, picard_args.config_file)
setup_config(app=self, filename=picard_args.config_file)
config = get_config()
theme.setup(self)

Expand Down Expand Up @@ -332,7 +332,6 @@ def __init__(self, picard_args, localedir, autoupdate, pipe_handler=None):
log.debug("Qt Env.: %s", " ".join("%s=%r" % (k, v) for k, v in os.environ.items() if k.startswith('QT_')))

# for compatibility with pre-1.3 plugins
QtCore.QObject.tagger = self
QtCore.QObject.config = config
QtCore.QObject.log = log

Expand Down
1 change: 1 addition & 0 deletions picard/track.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@ def _convert_folksonomy_tags_to_genre(self):
class NonAlbumTrack(Track):

def __init__(self, nat_id):
self.tagger = QtCore.QCoreApplication.instance()
super().__init__(nat_id, self.tagger.nats)
self.callback = None
self.loaded = False
Expand Down
1 change: 1 addition & 0 deletions picard/ui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ class PicardDialog(QtWidgets.QDialog, PreserveGeometry):
ready_for_display = QtCore.pyqtSignal()

def __init__(self, parent=None):
self.tagger = QtCore.QCoreApplication.instance()
super().__init__(parent, self.flags)
self.__shown = False
self.ready_for_display.connect(self.restore_geometry)
Expand Down
5 changes: 3 additions & 2 deletions picard/ui/filebrowser.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ class FileBrowser(QtWidgets.QTreeView):

def __init__(self, parent):
super().__init__(parent)
self.tagger = QtCore.QCoreApplication.instance()
self.setSelectionMode(QtWidgets.QAbstractItemView.SelectionMode.ExtendedSelection)
self.setDragEnabled(True)
self.load_selected_files_action = QtGui.QAction(_("&Load selected files"), self)
Expand Down Expand Up @@ -226,7 +227,7 @@ def _get_destination_from_path(self, path):
def load_file_for_item(self, index):
model = self.model()
if not model.isDir(index):
QtCore.QObject.tagger.add_paths([
self.tagger.add_paths([
model.filePath(index)
])

Expand All @@ -235,7 +236,7 @@ def load_selected_files(self):
if not indexes:
return
paths = set(self.model().filePath(index) for index in indexes)
QtCore.QObject.tagger.add_paths(paths)
self.tagger.add_paths(paths)

def move_files_here(self):
indexes = self.selectedIndexes()
Expand Down
6 changes: 4 additions & 2 deletions picard/ui/itemviews.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,7 @@ class BaseTreeView(QtWidgets.QTreeWidget):

def __init__(self, window, parent=None):
super().__init__(parent)
self.tagger = QtCore.QCoreApplication.instance()
self.setHeader(ConfigurableColumnsHeader(self))
self.window = window
self.panel = parent
Expand Down Expand Up @@ -760,7 +761,7 @@ def scrollTo(self, index, scrolltype=QtWidgets.QAbstractItemView.ScrollHint.Ensu
def drop_urls(urls, target, move_to_multi_tracks=True):
files = []
new_paths = []
tagger = QtCore.QObject.tagger
tagger = QtCore.QCoreApplication.instance()
for url in urls:
log.debug("Dropped the URL: %r", url.toString(QtCore.QUrl.UrlFormattingOption.RemoveUserInfo))
if url.scheme() == 'file' or not url.scheme():
Expand Down Expand Up @@ -1208,7 +1209,8 @@ def decide_file_icon_info(file):
@staticmethod
def decide_fingerprint_icon_info(file):
if getattr(file, 'acoustid_fingerprint', None):
if QtCore.QObject.tagger.acoustidmanager.is_submitted(file):
tagger = QtCore.QCoreApplication.instance()
if tagger.acoustidmanager.is_submitted(file):
icon = FileItem.icon_fingerprint_gray
tooltip = _("Fingerprint has already been submitted")
else:
Expand Down
3 changes: 2 additions & 1 deletion picard/ui/logview.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,8 @@ def _verbosity_changed(self, level):
config.setting['log_verbosity'] = level
self.verbosity = level
self._update_verbosity_label()
QtCore.QObject.tagger.set_log_level(level)
tagger = QtCore.QCoreApplication.instance()
tagger.set_log_level(level)
self.display(clear=True)

def _update_verbosity_label(self):
Expand Down
4 changes: 2 additions & 2 deletions picard/ui/mainwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,8 @@ def __init__(self, parent=None, disable_player=False):
super().__init__(parent)
self.setAttribute(QtCore.Qt.WidgetAttribute.WA_NativeWindow)
self.__shown = False
app = QtCore.QCoreApplication.instance()
self._is_wayland = app.is_wayland
self.tagger = QtCore.QCoreApplication.instance()
self._is_wayland = self.tagger.is_wayland
self.selected_objects = []
self.ignore_selection_changes = IgnoreUpdatesContext(self.update_selection)
self.toolbar = None
Expand Down
1 change: 1 addition & 0 deletions picard/ui/metadatabox.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ class MetadataBox(QtWidgets.QTableWidget):

def __init__(self, parent):
super().__init__(parent)
self.tagger = QtCore.QCoreApplication.instance()
config = get_config()
self.parent = parent
self.setAccessibleName(_("metadata view"))
Expand Down
6 changes: 5 additions & 1 deletion picard/ui/options/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@

import re

from PyQt6 import QtWidgets
from PyQt6 import (
QtCore,
QtWidgets,
)

from picard import log
from picard.config import get_config
Expand All @@ -51,6 +54,7 @@ class OptionsPage(QtWidgets.QWidget):

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.tagger = QtCore.QCoreApplication.instance()
self.setStyleSheet(self.STYLESHEET)

# Keep track whether the options page has been destroyed to avoid
Expand Down
3 changes: 2 additions & 1 deletion picard/ui/searchdialog/album.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,9 @@ def __init__(self, parent, force_advanced_search=None, existing_album=None):

@staticmethod
def show_releasegroup_search(releasegroup_id, existing_album=None):
tagger = QtCore.QCoreApplication.instance()
dialog = AlbumSearchDialog(
QtCore.QObject.tagger.window,
tagger.window,
force_advanced_search=True,
existing_album=existing_album)
dialog.search("rgid:{0}".format(releasegroup_id))
Expand Down
2 changes: 1 addition & 1 deletion picard/ui/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def __init__(self, btntype):
if not IS_WIN and not IS_MACOS:
iconname = self.__types[btntype][1]
if hasattr(QtWidgets.QStyle, iconname):
icon = self.tagger.style().standardIcon(getattr(QtWidgets.QStyle, iconname))
icon = QtCore.QCoreApplication.instance().style().standardIcon(getattr(QtWidgets.QStyle, iconname))
args = [icon, label]
super().__init__(*args)

Expand Down
3 changes: 2 additions & 1 deletion picard/util/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -844,7 +844,8 @@ def parse_json(reply):

def restore_method(func):
def func_wrapper(*args, **kwargs):
if not QtCore.QObject.tagger._no_restore:
tagger = QtCore.QCoreApplication.instance()
if not tagger._no_restore:
return func(*args, **kwargs)
return func_wrapper

Expand Down
1 change: 1 addition & 0 deletions picard/util/checkupdate.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class UpdateCheckManager(QtCore.QObject):

def __init__(self, parent=None):
super().__init__(parent=parent)
self.tagger = QtCore.QCoreApplication.instance()
self._parent = parent
self._available_versions = {}
self._show_always = False
Expand Down
1 change: 1 addition & 0 deletions picard/webservice/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ class WebService(QtCore.QObject):

def __init__(self, parent=None):
super().__init__(parent)
self.tagger = QtCore.QCoreApplication.instance()
self.manager = QtNetwork.QNetworkAccessManager()
self.manager.sslErrors.connect(self.ssl_errors)
self.oauth_manager = OAuthManager(self)
Expand Down
1 change: 0 additions & 1 deletion test/picardtestcase.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ def setUp(self):
log.set_level(logging.DEBUG)
setup_gettext(None, 'C')
self.tagger = FakeTagger()
QtCore.QObject.tagger = self.tagger
QtCore.QCoreApplication.instance = lambda: self.tagger
self.addCleanup(self.tagger.run_cleanup)
self.init_config()
Expand Down
Loading
Loading