Skip to content

Commit

Permalink
Merge pull request metabrainz#2502 from zas/parents
Browse files Browse the repository at this point in the history
Review and pass proper arguments to parent classes (mainly Qt*)
  • Loading branch information
zas authored May 29, 2024
2 parents 3c052c9 + c796280 commit 7492d60
Show file tree
Hide file tree
Showing 75 changed files with 229 additions and 198 deletions.
5 changes: 2 additions & 3 deletions picard/acoustid/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
FINGERPRINT_MAX_ALLOWED_LENGTH_DIFF_MS = 30000


class Submission(object):
class Submission:

def __init__(self, fingerprint, duration, recordingid=None, metadata=None):
self.fingerprint = fingerprint
Expand Down Expand Up @@ -101,7 +101,7 @@ def args(self):
return args


class AcoustIDManager(QtCore.QObject):
class AcoustIDManager:

# AcoustID has a post limit of around 1 MB.
MAX_PAYLOAD = 1000000
Expand All @@ -112,7 +112,6 @@ class AcoustIDManager(QtCore.QObject):
BATCH_SIZE_REDUCTION_FACTOR = 0.7

def __init__(self, acoustid_api):
super().__init__()
self.tagger = QtCore.QCoreApplication.instance()
self._submissions = {}
self._acoustid_api = acoustid_api
Expand Down
2 changes: 1 addition & 1 deletion picard/browser/filelookup.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
from picard.ui.searchdialog.album import AlbumSearchDialog


class FileLookup(object):
class FileLookup:

RE_MB_ENTITY = re.compile(r"""
\b(?P<entity>area|artist|instrument|label|place|recording|release|release-group|series|track|url|work)?
Expand Down
2 changes: 1 addition & 1 deletion picard/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
user_collections = {}


class Collection(QtCore.QObject):
class Collection:

def __init__(self, collection_id: str, mb_api: MBAPIHelper):
self.tagger = QtCore.QCoreApplication.instance()
Expand Down
2 changes: 1 addition & 1 deletion picard/coverart/providers/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class MyProvider(CoverArtProvider):
PARENT = "cover"

def __init__(self, parent=None):
super().__init__(parent)
super().__init__(parent=parent)
self.ui = self._options_ui()
self.ui.setupUi(self)

Expand Down
3 changes: 1 addition & 2 deletions picard/disc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,9 @@
discid = None


class Disc(QtCore.QObject):
class Disc:

def __init__(self, id=None):
super().__init__()
self.tagger = QtCore.QCoreApplication.instance()
self.id = id
self.mcn = None
Expand Down
2 changes: 1 addition & 1 deletion picard/formats/mutagenext/ac3.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
class AC3Error(MutagenError):
pass

class AC3Info(object):
class AC3Info:

"""AC3 stream information.
Expand Down
2 changes: 1 addition & 1 deletion picard/item.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
from picard.util import IgnoreUpdatesContext


class Item(object):
class Item:

@property
def can_save(self):
Expand Down
2 changes: 1 addition & 1 deletion picard/oauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class OAuthInvalidStateError(Exception):
pass


class OAuthManager(object):
class OAuthManager:

def __init__(self, webservice):
self.webservice = webservice
Expand Down
4 changes: 2 additions & 2 deletions picard/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def _unregister_module_extensions(module):
ep.unregister_module(module)


class ExtensionPoint(object):
class ExtensionPoint:

def __init__(self, label=None):
if label is None:
Expand Down Expand Up @@ -112,7 +112,7 @@ def __repr__(self):
return f"ExtensionPoint(label='{self.label}')"


class PluginShared(object):
class PluginShared:

def __init__(self):
super().__init__()
Expand Down
6 changes: 3 additions & 3 deletions picard/script/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def normalize_tagname(name):
return name


class ScriptVariable(object):
class ScriptVariable:

def __init__(self, name):
self.name = name
Expand All @@ -140,7 +140,7 @@ def eval(self, state):
return state.context.get(normalize_tagname(self.name), "")


class ScriptFunction(object):
class ScriptFunction:

def __init__(self, name, args, parser, column=0, line=0):
self.stackitem = StackItem(line, column, name)
Expand Down Expand Up @@ -201,7 +201,7 @@ def isidentif(ch):
return ch.isalnum() or ch == '_'


class ScriptParser(object):
class ScriptParser:

r"""Tagger script parser.
Expand Down
14 changes: 12 additions & 2 deletions picard/script/serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,12 @@ def export_script(self, parent=None):

dialog_title = _("Export Script File")
dialog_file_types = self._get_dialog_filetypes()
filename, file_type = QtWidgets.QFileDialog.getSaveFileName(parent, dialog_title, default_path, dialog_file_types)
filename, file_type = QtWidgets.QFileDialog.getSaveFileName(
parent=parent,
caption=dialog_title,
directory=default_path,
filter=dialog_file_types,
)
if not filename:
return False
# Fix issue where Qt may set the extension twice
Expand Down Expand Up @@ -259,7 +264,12 @@ def import_script(cls, parent=None):
dialog_title = _("Import Script File")
dialog_file_types = cls._get_dialog_filetypes()
default_script_directory = os.path.normpath(QtCore.QStandardPaths.writableLocation(QtCore.QStandardPaths.StandardLocation.DocumentsLocation))
filename, file_type = QtWidgets.QFileDialog.getOpenFileName(parent, dialog_title, default_script_directory, dialog_file_types)
filename, file_type = QtWidgets.QFileDialog.getOpenFileName(
parent=parent,
caption=dialog_title,
directory=default_script_directory,
filter=dialog_file_types,
)
if not filename:
return None
log.debug("Importing script file: %s", filename)
Expand Down
2 changes: 1 addition & 1 deletion picard/tagger.py
Original file line number Diff line number Diff line change
Expand Up @@ -1201,7 +1201,7 @@ def lookup_cd(self, action):
traceback=self._debug)

def lookup_discid_from_logfile(self):
file_chooser = QtWidgets.QFileDialog(self.window)
file_chooser = QtWidgets.QFileDialog(parent=self.window)
file_chooser.setNameFilters([
_("All supported log files") + " (*.log *.txt)",
_("EAC / XLD / Whipper / fre:ac log files") + " (*.log)",
Expand Down
4 changes: 2 additions & 2 deletions picard/ui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class PreserveGeometry:

defaultsize = None

def __init__(self):
def __init__(self, *args, **kwargs):
Option.add_if_missing('persist', self.opt_name(), QtCore.QByteArray())
Option.add_if_missing('persist', self.splitters_name(), {})
if getattr(self, 'finished', None):
Expand Down Expand Up @@ -183,7 +183,7 @@ class PicardDialog(QtWidgets.QDialog, PreserveGeometry):

def __init__(self, parent=None):
self.tagger = QtCore.QCoreApplication.instance()
super().__init__(parent, self.flags)
super().__init__(parent=parent, f=self.flags)
self.__shown = False
self.ready_for_display.connect(self.restore_geometry)

Expand Down
2 changes: 1 addition & 1 deletion picard/ui/aboutdialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
class AboutDialog(PicardDialog, SingletonDialog):

def __init__(self, parent=None):
super().__init__(parent)
super().__init__(parent=parent)
self.setAttribute(QtCore.Qt.WidgetAttribute.WA_DeleteOnClose)
self.ui = Ui_AboutDialog()
self.ui.setupUi(self)
Expand Down
2 changes: 1 addition & 1 deletion picard/ui/caa_types_selector.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def __init__(
self, parent=None, types_include=None, types_exclude=None,
default_include=None, default_exclude=None, known_types=None
):
super().__init__(parent)
super().__init__(parent=parent)
if types_include is None:
types_include = []
if types_exclude is None:
Expand Down
2 changes: 1 addition & 1 deletion picard/ui/cdlookup.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class CDLookupDialog(PicardDialog):
dialog_header_state = 'cdlookupdialog_header_state'

def __init__(self, releases, disc, parent=None):
super().__init__(parent)
super().__init__(parent=parent)
self.releases = releases
self.disc = disc
self.ui = Ui_CDLookupDialog()
Expand Down
12 changes: 6 additions & 6 deletions picard/ui/collectionmenu.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@

class CollectionMenu(QtWidgets.QMenu):

def __init__(self, albums, *args, **kwargs):
super().__init__(*args, **kwargs)
def __init__(self, albums, title, parent=None):
super().__init__(title, parent=parent)
self.releases = set(a.id for a in albums)
self._ignore_update = False
self._ignore_hover = False
Expand Down Expand Up @@ -94,8 +94,8 @@ def update_active_action_for_widget(self, widget):

class CollectionMenuItem(QtWidgets.QWidget):

def __init__(self, menu, collection, *args, **kwargs):
super().__init__(*args, **kwargs)
def __init__(self, menu, collection, parent=None):
super().__init__(parent=parent)
self.menu = menu
self.active = False
self._setup_layout(menu, collection)
Expand Down Expand Up @@ -144,10 +144,10 @@ def paintEvent(self, e):

class CollectionCheckBox(QtWidgets.QCheckBox):

def __init__(self, menu, collection, *args, **kwargs):
def __init__(self, menu, collection, parent=None):
self.menu = menu
self.collection = collection
super().__init__(self._label(), *args, **kwargs)
super().__init__(self._label(), parent=parent)

releases = collection.releases & menu.releases
if len(releases) == len(menu.releases):
Expand Down
31 changes: 14 additions & 17 deletions picard/ui/coverartbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@
class CoverArtThumbnail(ActiveLabel):
image_dropped = QtCore.pyqtSignal(QtCore.QUrl, bytes)

def __init__(self, active=False, drops=False, pixmap_cache=None, *args, **kwargs):
super().__init__(active, drops, *args, **kwargs)
def __init__(self, active=False, drops=False, pixmap_cache=None, parent=None):
super().__init__(active=active, parent=parent)
self.data = None
self.has_common_images = None
self.release = None
Expand Down Expand Up @@ -377,11 +377,10 @@ def iter_file_parents(file):

class CoverArtBox(QtWidgets.QGroupBox):

def __init__(self, parent):
super().__init__("")
def __init__(self, parent=None):
super().__init__("", parent=parent)
self.layout = QtWidgets.QVBoxLayout()
self.layout.setSpacing(6)
self.parent = parent
self.tagger = QtCore.QCoreApplication.instance()
# Kills off any borders
self.setStyleSheet('''QGroupBox{background-color:none;border:1px;}''')
Expand All @@ -390,11 +389,11 @@ def __init__(self, parent):
self.pixmap_cache = LRUCache(40)
self.cover_art_label = QtWidgets.QLabel('')
self.cover_art_label.setAlignment(QtCore.Qt.AlignmentFlag.AlignTop | QtCore.Qt.AlignmentFlag.AlignHCenter)
self.cover_art = CoverArtThumbnail(False, True, self.pixmap_cache, parent)
self.cover_art = CoverArtThumbnail(drops=True, pixmap_cache=self.pixmap_cache, parent=self)
self.cover_art.image_dropped.connect(self.fetch_remote_image)
spacerItem = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Policy.Minimum, QtWidgets.QSizePolicy.Policy.Expanding)
self.orig_cover_art_label = QtWidgets.QLabel('')
self.orig_cover_art = CoverArtThumbnail(False, False, self.pixmap_cache, parent)
self.orig_cover_art = CoverArtThumbnail(drops=False, pixmap_cache=self.pixmap_cache, parent=self)
self.orig_cover_art_label.setAlignment(QtCore.Qt.AlignmentFlag.AlignTop | QtCore.Qt.AlignmentFlag.AlignHCenter)
self.show_details_button = QtWidgets.QPushButton(_('Show more details'), self)
self.show_details_shortcut = QtGui.QShortcut(QtGui.QKeySequence(_("Ctrl+Shift+I")), self, self.show_cover_art_info)
Expand All @@ -410,7 +409,7 @@ def __init__(self, parent):
self.show_details_button.clicked.connect(self.show_cover_art_info)

def show_cover_art_info(self):
self.parent.view_info(default_tab=1)
self.tagger.window.view_info(default_tab=1)

def update_display(self, force=False):
if self.isHidden():
Expand Down Expand Up @@ -608,7 +607,7 @@ def _try_load_remote_image(self, url, data):
return coverartimage

def choose_local_file(self):
file_chooser = QtWidgets.QFileDialog(self)
file_chooser = QtWidgets.QFileDialog(parent=self)
extensions = ['*' + ext for ext in imageinfo.get_supported_extensions()]
extensions.sort()
file_chooser.setNameFilters([
Expand All @@ -633,39 +632,37 @@ def contextMenuEvent(self, event):
menu = QtWidgets.QMenu(self)
if self.show_details_button.isVisible():
name = _("Show more details…")
show_more_details_action = QtGui.QAction(name, self.parent)
show_more_details_action = QtGui.QAction(name, parent=menu)
show_more_details_action.triggered.connect(self.show_cover_art_info)
menu.addAction(show_more_details_action)

if self.orig_cover_art.isVisible():
name = _("Keep original cover art")
use_orig_value_action = QtGui.QAction(name, self.parent)
use_orig_value_action = QtGui.QAction(name, parent=menu)
use_orig_value_action.triggered.connect(self.keep_original_images)
menu.addAction(use_orig_value_action)

if self.item and self.item.can_show_coverart:
name = _("Choose local file…")
choose_local_file_action = QtGui.QAction(name, self.parent)
choose_local_file_action = QtGui.QAction(name, parent=menu)
choose_local_file_action.triggered.connect(self.choose_local_file)
menu.addAction(choose_local_file_action)

if not menu.isEmpty():
menu.addSeparator()

load_image_behavior_group = QtGui.QActionGroup(self.parent)
action = QtGui.QAction(_("Replace front cover art"), self.parent)
load_image_behavior_group = QtGui.QActionGroup(menu)
action = QtGui.QAction(_("Replace front cover art"), parent=load_image_behavior_group)
action.setCheckable(True)
action.triggered.connect(partial(self.set_load_image_behavior, behavior='replace'))
load_image_behavior_group.addAction(action)
config = get_config()
if config.setting['load_image_behavior'] == 'replace':
action.setChecked(True)
menu.addAction(action)

action = QtGui.QAction(_("Append front cover art"), self.parent)
action = QtGui.QAction(_("Append front cover art"), parent=load_image_behavior_group)
action.setCheckable(True)
action.triggered.connect(partial(self.set_load_image_behavior, behavior='append'))
load_image_behavior_group.addAction(action)
if config.setting['load_image_behavior'] == 'append':
action.setChecked(True)
menu.addAction(action)
Expand Down
10 changes: 5 additions & 5 deletions picard/ui/edittagdialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,13 @@ def get_tag_name(self, index):

class EditTagDialog(PicardDialog):

def __init__(self, window, tag):
super().__init__(window)
def __init__(self, metadata_box, tag):
super().__init__(parent=metadata_box)
self.ui = Ui_EditTagDialog()
self.ui.setupUi(self)
self.window = window
self.value_list = self.ui.value_list
self.metadata_box = window.metadata_box
self.tagger = QtCore.QCoreApplication.instance()
self.metadata_box = metadata_box
self.tag = tag
self.modified_tags = {}
self.is_grouped = False
Expand Down Expand Up @@ -300,7 +300,7 @@ def _modified_tag(self):
list(self.metadata_box.tag_diff.new[self.tag]) or [""])

def accept(self):
with self.window.ignore_selection_changes:
with self.tagger.window.ignore_selection_changes:
for tag, values in self.modified_tags.items():
self.modified_tags[tag] = [v for v in values if v]
modified_tags = self.modified_tags.items()
Expand Down
4 changes: 2 additions & 2 deletions picard/ui/filebrowser.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@

class FileBrowser(QtWidgets.QTreeView):

def __init__(self, parent):
super().__init__(parent)
def __init__(self, parent=None):
super().__init__(parent=parent)
self.tagger = QtCore.QCoreApplication.instance()
self.setSelectionMode(QtWidgets.QAbstractItemView.SelectionMode.ExtendedSelection)
self.setDragEnabled(True)
Expand Down
Loading

0 comments on commit 7492d60

Please sign in to comment.