Esempio n. 1
0
    def __init__(self, parent=None):
        super(ReleasesOptionsPage, self).__init__(parent)
        self.ui = Ui_ReleasesOptionsPage()
        self.ui.setupUi(self)
        self.ui.reset_preferred_types_btn.clicked.connect(self.reset_preferred_types)
        self._release_type_sliders["Album"] = self.ui.prefer_album_score
        self._release_type_sliders["Single"] = self.ui.prefer_single_score
        self._release_type_sliders["EP"] = self.ui.prefer_ep_score
        self._release_type_sliders["Compilation"] = self.ui.prefer_compilation_score
        self._release_type_sliders["Soundtrack"] = self.ui.prefer_soundtrack_score
        self._release_type_sliders["Spokenword"] = self.ui.prefer_spokenword_score
        self._release_type_sliders["Interview"] = self.ui.prefer_interview_score
        self._release_type_sliders["Audiobook"] = self.ui.prefer_audiobook_score
        self._release_type_sliders["Live"] = self.ui.prefer_live_score
        self._release_type_sliders["Remix"] = self.ui.prefer_remix_score
        self._release_type_sliders["Other"] = self.ui.prefer_other_score

        self.ui.add_countries.clicked.connect(self.add_preferred_countries)
        self.ui.remove_countries.clicked.connect(self.remove_preferred_countries)
        self.ui.add_formats.clicked.connect(self.add_preferred_formats)
        self.ui.remove_formats.clicked.connect(self.remove_preferred_formats)
        self.ui.country_list.setSelectionMode(QtGui.QAbstractItemView.ExtendedSelection)
        self.ui.preferred_country_list.setSelectionMode(QtGui.QAbstractItemView.ExtendedSelection)
        self.ui.format_list.setSelectionMode(QtGui.QAbstractItemView.ExtendedSelection)
        self.ui.preferred_format_list.setSelectionMode(QtGui.QAbstractItemView.ExtendedSelection)
Esempio n. 2
0
    def __init__(self, parent=None):
        super().__init__(parent)
        self.ui = Ui_ReleasesOptionsPage()
        self.ui.setupUi(self)

        self._release_type_sliders = {}

        def add_slider(name, griditer, context):
            label = pgettext_attributes(context, name)
            self._release_type_sliders[name] = ReleaseTypeScore(
                self.ui.type_group, self.ui.gridLayout, label, next(griditer))

        griditer = RowColIter(
            len(RELEASE_PRIMARY_GROUPS) + len(RELEASE_SECONDARY_GROUPS) +
            1)  # +1 for Reset button
        for name in RELEASE_PRIMARY_GROUPS:
            add_slider(name, griditer, context='release_group_primary_type')
        for name in sorted(RELEASE_SECONDARY_GROUPS,
                           key=lambda v: pgettext_attributes(
                               'release_group_secondary_type', v)):
            add_slider(name, griditer, context='release_group_secondary_type')

        reset_types_btn = QtWidgets.QPushButton(self.ui.type_group)
        reset_types_btn.setText(_("Reset all"))
        sizePolicy = QtWidgets.QSizePolicy(
            QtWidgets.QSizePolicy.Policy.Minimum,
            QtWidgets.QSizePolicy.Policy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(
            reset_types_btn.sizePolicy().hasHeightForWidth())
        reset_types_btn.setSizePolicy(sizePolicy)
        r, c = next(griditer)
        self.ui.gridLayout.addWidget(reset_types_btn, r, c, 1, 2)
        reset_types_btn.clicked.connect(self.reset_preferred_types)

        self.setTabOrder(reset_types_btn, self.ui.country_list)
        self.setTabOrder(self.ui.country_list, self.ui.preferred_country_list)
        self.setTabOrder(self.ui.preferred_country_list, self.ui.add_countries)
        self.setTabOrder(self.ui.add_countries, self.ui.remove_countries)
        self.setTabOrder(self.ui.remove_countries, self.ui.format_list)
        self.setTabOrder(self.ui.format_list, self.ui.preferred_format_list)
        self.setTabOrder(self.ui.preferred_format_list, self.ui.add_formats)
        self.setTabOrder(self.ui.add_formats, self.ui.remove_formats)

        self.ui.add_countries.clicked.connect(self.add_preferred_countries)
        self.ui.remove_countries.clicked.connect(
            self.remove_preferred_countries)
        self.ui.add_formats.clicked.connect(self.add_preferred_formats)
        self.ui.remove_formats.clicked.connect(self.remove_preferred_formats)
        self.ui.country_list.setSelectionMode(
            QtWidgets.QAbstractItemView.SelectionMode.ExtendedSelection)
        self.ui.preferred_country_list.setSelectionMode(
            QtWidgets.QAbstractItemView.SelectionMode.ExtendedSelection)
        self.ui.format_list.setSelectionMode(
            QtWidgets.QAbstractItemView.SelectionMode.ExtendedSelection)
        self.ui.preferred_format_list.setSelectionMode(
            QtWidgets.QAbstractItemView.SelectionMode.ExtendedSelection)
Esempio n. 3
0
    def __init__(self, parent=None):
        super().__init__(parent)
        self.ui = Ui_ReleasesOptionsPage()
        self.ui.setupUi(self)

        self._release_type_sliders = {}

        def add_slider(name, griditer, context):
            label = gettext_attr(name, context)
            self._release_type_sliders[name] = \
                ReleaseTypeScore(self.ui.type_group,
                                 self.ui.gridLayout,
                                 label,
                                 next(griditer))

        griditer = RowColIter(len(RELEASE_PRIMARY_GROUPS)
                              + len(RELEASE_SECONDARY_GROUPS)
                              + 1)  # +1 for Reset button
        for name in RELEASE_PRIMARY_GROUPS:
            add_slider(name, griditer, context='release_group_primary_type')
        for name in sorted(RELEASE_SECONDARY_GROUPS,
                           key=lambda v: gettext_attr(v, 'release_group_secondary_type')):
            add_slider(name, griditer, context='release_group_secondary_type')

        self.reset_preferred_types_btn = QtWidgets.QPushButton(self.ui.type_group)
        self.reset_preferred_types_btn.setText(_("Reset all"))
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.reset_preferred_types_btn.sizePolicy().hasHeightForWidth())
        self.reset_preferred_types_btn.setSizePolicy(sizePolicy)
        r, c = next(griditer)
        self.ui.gridLayout.addWidget(self.reset_preferred_types_btn, r, c, 1, 2)
        self.reset_preferred_types_btn.clicked.connect(self.reset_preferred_types)

        self.ui.add_countries.clicked.connect(self.add_preferred_countries)
        self.ui.remove_countries.clicked.connect(self.remove_preferred_countries)
        self.ui.add_formats.clicked.connect(self.add_preferred_formats)
        self.ui.remove_formats.clicked.connect(self.remove_preferred_formats)
        self.ui.country_list.setSelectionMode(QtWidgets.QAbstractItemView.ExtendedSelection)
        self.ui.preferred_country_list.setSelectionMode(QtWidgets.QAbstractItemView.ExtendedSelection)
        self.ui.format_list.setSelectionMode(QtWidgets.QAbstractItemView.ExtendedSelection)
        self.ui.preferred_format_list.setSelectionMode(QtWidgets.QAbstractItemView.ExtendedSelection)
Esempio n. 4
0
class ReleasesOptionsPage(OptionsPage):

    NAME = "releases"
    TITLE = N_("Preferred Releases")
    PARENT = "metadata"
    SORT_ORDER = 10
    ACTIVE = True
    HELP_URL = '/config/options_releases.html'

    options = [
        config.ListOption("setting", "release_type_scores",
                          _release_type_scores),
        config.ListOption("setting", "preferred_release_countries", []),
        config.ListOption("setting", "preferred_release_formats", []),
    ]

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

        self._release_type_sliders = {}

        def add_slider(name, griditer, context):
            label = pgettext_attributes(context, name)
            self._release_type_sliders[name] = \
                ReleaseTypeScore(self.ui.type_group,
                                 self.ui.gridLayout,
                                 label,
                                 next(griditer))

        griditer = RowColIter(
            len(RELEASE_PRIMARY_GROUPS) + len(RELEASE_SECONDARY_GROUPS) +
            1)  # +1 for Reset button
        for name in RELEASE_PRIMARY_GROUPS:
            add_slider(name, griditer, context='release_group_primary_type')
        for name in sorted(RELEASE_SECONDARY_GROUPS,
                           key=lambda v: pgettext_attributes(
                               'release_group_secondary_type', v)):
            add_slider(name, griditer, context='release_group_secondary_type')

        self.reset_preferred_types_btn = QtWidgets.QPushButton(
            self.ui.type_group)
        self.reset_preferred_types_btn.setText(_("Reset all"))
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Minimum,
                                           QtWidgets.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(
            self.reset_preferred_types_btn.sizePolicy().hasHeightForWidth())
        self.reset_preferred_types_btn.setSizePolicy(sizePolicy)
        r, c = next(griditer)
        self.ui.gridLayout.addWidget(self.reset_preferred_types_btn, r, c, 1,
                                     2)
        self.reset_preferred_types_btn.clicked.connect(
            self.reset_preferred_types)

        self.ui.add_countries.clicked.connect(self.add_preferred_countries)
        self.ui.remove_countries.clicked.connect(
            self.remove_preferred_countries)
        self.ui.add_formats.clicked.connect(self.add_preferred_formats)
        self.ui.remove_formats.clicked.connect(self.remove_preferred_formats)
        self.ui.country_list.setSelectionMode(
            QtWidgets.QAbstractItemView.ExtendedSelection)
        self.ui.preferred_country_list.setSelectionMode(
            QtWidgets.QAbstractItemView.ExtendedSelection)
        self.ui.format_list.setSelectionMode(
            QtWidgets.QAbstractItemView.ExtendedSelection)
        self.ui.preferred_format_list.setSelectionMode(
            QtWidgets.QAbstractItemView.ExtendedSelection)

    def restore_defaults(self):
        # Clear lists
        self.ui.preferred_country_list.clear()
        self.ui.preferred_format_list.clear()
        self.ui.country_list.clear()
        self.ui.format_list.clear()
        super().restore_defaults()

    def load(self):
        scores = dict(config.setting["release_type_scores"])
        for (release_type,
             release_type_slider) in self._release_type_sliders.items():
            release_type_slider.setValue(
                scores.get(release_type, _DEFAULT_SCORE))

        self._load_list_items("preferred_release_countries", RELEASE_COUNTRIES,
                              self.ui.country_list,
                              self.ui.preferred_country_list)
        self._load_list_items("preferred_release_formats", RELEASE_FORMATS,
                              self.ui.format_list,
                              self.ui.preferred_format_list)

    def save(self):
        scores = []
        for (release_type,
             release_type_slider) in self._release_type_sliders.items():
            scores.append((release_type, release_type_slider.value()))
        config.setting["release_type_scores"] = scores

        self._save_list_items("preferred_release_countries",
                              self.ui.preferred_country_list)
        self._save_list_items("preferred_release_formats",
                              self.ui.preferred_format_list)

    def reset_preferred_types(self):
        for release_type_slider in self._release_type_sliders.values():
            release_type_slider.reset()

    def add_preferred_countries(self):
        self._move_selected_items(self.ui.country_list,
                                  self.ui.preferred_country_list)

    def remove_preferred_countries(self):
        self._move_selected_items(self.ui.preferred_country_list,
                                  self.ui.country_list)
        self.ui.country_list.sortItems()

    def add_preferred_formats(self):
        self._move_selected_items(self.ui.format_list,
                                  self.ui.preferred_format_list)

    def remove_preferred_formats(self):
        self._move_selected_items(self.ui.preferred_format_list,
                                  self.ui.format_list)
        self.ui.format_list.sortItems()

    def _move_selected_items(self, list1, list2):
        for item in list1.selectedItems():
            clone = item.clone()
            list2.addItem(clone)
            list1.takeItem(list1.row(item))

    def _load_list_items(self, setting, source, list1, list2):
        if setting == "preferred_release_countries":
            source_list = [(c[0], gettext_countries(c[1]))
                           for c in source.items()]
        elif setting == "preferred_release_formats":
            source_list = [(c[0], pgettext_attributes("medium_format", c[1]))
                           for c in source.items()]
        else:
            source_list = [(c[0], _(c[1])) for c in source.items()]

        def fcmp(x):
            return strxfrm(x[1])

        source_list.sort(key=fcmp)
        saved_data = config.setting[setting]
        move = []
        for data, name in source_list:
            item = QtWidgets.QListWidgetItem(name)
            item.setData(QtCore.Qt.UserRole, data)
            try:
                i = saved_data.index(data)
                move.append((i, item))
            except BaseException:
                list1.addItem(item)
        move.sort(key=itemgetter(0))
        for i, item in move:
            list2.addItem(item)

    def _save_list_items(self, setting, list1):
        data = []
        for i in range(list1.count()):
            item = list1.item(i)
            data.append(item.data(QtCore.Qt.UserRole))
        config.setting[setting] = data
Esempio n. 5
0
class ReleasesOptionsPage(OptionsPage):

    NAME = "releases"
    TITLE = N_("Preferred Releases")
    PARENT = "metadata"
    SORT_ORDER = 10
    ACTIVE = True

    options = [
        config.ListOption("setting", "release_type_scores", _release_type_scores),
        config.ListOption("setting", "preferred_release_countries", []),
        config.ListOption("setting", "preferred_release_formats", []),
    ]

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

        self._release_type_sliders = {}

        def add_slider(name, griditer, context):
            label = ugettext_attr(name, context)
            self._release_type_sliders[name] = \
                ReleaseTypeScore(self.ui.type_group,
                                 self.ui.gridLayout,
                                 label,
                                 griditer.next())

        griditer = RowColIter(len(RELEASE_PRIMARY_GROUPS) +
                              len(RELEASE_SECONDARY_GROUPS) + 1)  # +1 for Reset button
        for name in RELEASE_PRIMARY_GROUPS:
            add_slider(name, griditer, context=u'release_group_primary_type')
        for name in RELEASE_SECONDARY_GROUPS:
            add_slider(name, griditer, context=u'release_group_secondary_type')

        self.reset_preferred_types_btn = QtGui.QPushButton(self.ui.type_group)
        self.reset_preferred_types_btn.setText(_("Reset all"))
        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.reset_preferred_types_btn.sizePolicy().hasHeightForWidth())
        self.reset_preferred_types_btn.setSizePolicy(sizePolicy)
        r, c = griditer.next()
        self.ui.gridLayout.addWidget(self.reset_preferred_types_btn, r, c, 1, 2)
        self.reset_preferred_types_btn.clicked.connect(self.reset_preferred_types)

        self.ui.add_countries.clicked.connect(self.add_preferred_countries)
        self.ui.remove_countries.clicked.connect(self.remove_preferred_countries)
        self.ui.add_formats.clicked.connect(self.add_preferred_formats)
        self.ui.remove_formats.clicked.connect(self.remove_preferred_formats)
        self.ui.country_list.setSelectionMode(QtGui.QAbstractItemView.ExtendedSelection)
        self.ui.preferred_country_list.setSelectionMode(QtGui.QAbstractItemView.ExtendedSelection)
        self.ui.format_list.setSelectionMode(QtGui.QAbstractItemView.ExtendedSelection)
        self.ui.preferred_format_list.setSelectionMode(QtGui.QAbstractItemView.ExtendedSelection)

    def load(self):
        scores = dict(config.setting["release_type_scores"])
        for (release_type, release_type_slider) in self._release_type_sliders.iteritems():
            release_type_slider.setValue(scores.get(release_type,
                                                    _DEFAULT_SCORE))

        self._load_list_items("preferred_release_countries", RELEASE_COUNTRIES,
                              self.ui.country_list, self.ui.preferred_country_list)
        self._load_list_items("preferred_release_formats", RELEASE_FORMATS,
                              self.ui.format_list, self.ui.preferred_format_list)

    def save(self):
        scores = []
        for (release_type, release_type_slider) in self._release_type_sliders.iteritems():
            scores.append((release_type, release_type_slider.value()))
        config.setting["release_type_scores"] = scores

        self._save_list_items("preferred_release_countries", self.ui.preferred_country_list)
        self._save_list_items("preferred_release_formats", self.ui.preferred_format_list)

    def reset_preferred_types(self):
        for release_type_slider in self._release_type_sliders.values():
            release_type_slider.reset()

    def add_preferred_countries(self):
        self._move_selected_items(self.ui.country_list, self.ui.preferred_country_list)

    def remove_preferred_countries(self):
        self._move_selected_items(self.ui.preferred_country_list, self.ui.country_list)
        self.ui.country_list.sortItems()

    def add_preferred_formats(self):
        self._move_selected_items(self.ui.format_list, self.ui.preferred_format_list)

    def remove_preferred_formats(self):
        self._move_selected_items(self.ui.preferred_format_list, self.ui.format_list)
        self.ui.format_list.sortItems()

    def _move_selected_items(self, list1, list2):
        for item in list1.selectedItems():
            clone = item.clone()
            list2.addItem(clone)
            list1.takeItem(list1.row(item))

    def _load_list_items(self, setting, source, list1, list2):
        if setting == "preferred_release_countries":
            source_list = [(c[0], ugettext_countries(c[1])) for c in
                           source.items()]
        elif setting == "preferred_release_formats":
            source_list = [(c[0], ugettext_attr(c[1], u"medium_format")) for c
                           in source.items()]
        else:
            source_list = [(c[0], _(c[1])) for c in source.items()]
        source_list.sort(key=itemgetter(1), cmp=strcoll)
        saved_data = config.setting[setting]
        move = []
        for data, name in source_list:
            item = QtGui.QListWidgetItem(name)
            item.setData(QtCore.Qt.UserRole, data)
            try:
                i = saved_data.index(data)
                move.append((i, item))
            except:
                list1.addItem(item)
        move.sort(key=itemgetter(0))
        for i, item in move:
            list2.addItem(item)

    def _save_list_items(self, setting, list1):
        data = []
        for i in range(list1.count()):
            item = list1.item(i)
            data.append(unicode(item.data(QtCore.Qt.UserRole)))
        config.setting[setting] = data
Esempio n. 6
0
class ReleasesOptionsPage(OptionsPage):

    NAME = "releases"
    TITLE = N_("Preferred Releases")
    PARENT = "metadata"
    SORT_ORDER = 10
    ACTIVE = True

    options = [
        config.TextOption("setting", "release_type_scores", "Album 0.5 Single 0.5 EP 0.5 Compilation 0.5 Soundtrack 0.5 Spokenword 0.5 Interview 0.5 Audiobook 0.5 Live 0.5 Remix 0.5 Other 0.5"),
        config.TextOption("setting", "preferred_release_countries", u""),
        config.TextOption("setting", "preferred_release_formats", u""),
    ]

    _release_type_sliders = {}

    def __init__(self, parent=None):
        super(ReleasesOptionsPage, self).__init__(parent)
        self.ui = Ui_ReleasesOptionsPage()
        self.ui.setupUi(self)
        self.ui.reset_preferred_types_btn.clicked.connect(self.reset_preferred_types)
        self._release_type_sliders["Album"] = self.ui.prefer_album_score
        self._release_type_sliders["Single"] = self.ui.prefer_single_score
        self._release_type_sliders["EP"] = self.ui.prefer_ep_score
        self._release_type_sliders["Compilation"] = self.ui.prefer_compilation_score
        self._release_type_sliders["Soundtrack"] = self.ui.prefer_soundtrack_score
        self._release_type_sliders["Spokenword"] = self.ui.prefer_spokenword_score
        self._release_type_sliders["Interview"] = self.ui.prefer_interview_score
        self._release_type_sliders["Audiobook"] = self.ui.prefer_audiobook_score
        self._release_type_sliders["Live"] = self.ui.prefer_live_score
        self._release_type_sliders["Remix"] = self.ui.prefer_remix_score
        self._release_type_sliders["Other"] = self.ui.prefer_other_score

        self.ui.add_countries.clicked.connect(self.add_preferred_countries)
        self.ui.remove_countries.clicked.connect(self.remove_preferred_countries)
        self.ui.add_formats.clicked.connect(self.add_preferred_formats)
        self.ui.remove_formats.clicked.connect(self.remove_preferred_formats)
        self.ui.country_list.setSelectionMode(QtGui.QAbstractItemView.ExtendedSelection)
        self.ui.preferred_country_list.setSelectionMode(QtGui.QAbstractItemView.ExtendedSelection)
        self.ui.format_list.setSelectionMode(QtGui.QAbstractItemView.ExtendedSelection)
        self.ui.preferred_format_list.setSelectionMode(QtGui.QAbstractItemView.ExtendedSelection)

    def load(self):
        scores = load_release_type_scores(config.setting["release_type_scores"])
        for (release_type, release_type_slider) in self._release_type_sliders.iteritems():
            release_type_slider.setValue(int(scores.get(release_type, 0.5) * 100))

        self._load_list_items("preferred_release_countries", RELEASE_COUNTRIES,
            self.ui.country_list, self.ui.preferred_country_list)
        self._load_list_items("preferred_release_formats", RELEASE_FORMATS,
            self.ui.format_list, self.ui.preferred_format_list)

    def save(self):
        scores = {}
        for (release_type, release_type_slider) in self._release_type_sliders.iteritems():
            scores[release_type] = float(release_type_slider.value()) / 100.0
        config.setting["release_type_scores"] = save_release_type_scores(scores)

        self._save_list_items("preferred_release_countries", self.ui.preferred_country_list)
        self._save_list_items("preferred_release_formats", self.ui.preferred_format_list)

    def reset_preferred_types(self):
        for release_type_slider in self._release_type_sliders.values():
            release_type_slider.setValue(50)

    def add_preferred_countries(self):
        self._move_selected_items(self.ui.country_list, self.ui.preferred_country_list)

    def remove_preferred_countries(self):
        self._move_selected_items(self.ui.preferred_country_list, self.ui.country_list)
        self.ui.country_list.sortItems()

    def add_preferred_formats(self):
        self._move_selected_items(self.ui.format_list, self.ui.preferred_format_list)

    def remove_preferred_formats(self):
        self._move_selected_items(self.ui.preferred_format_list, self.ui.format_list)
        self.ui.format_list.sortItems()

    def _move_selected_items(self, list1, list2):
        for item in list1.selectedItems():
            clone = item.clone()
            list2.addItem(clone)
            list1.takeItem(list1.row(item))

    def _load_list_items(self, setting, source, list1, list2):
        source_list = [(c[0], _(c[1])) for c in source.items()]
        source_list.sort(key=itemgetter(1), cmp=strcoll)
        saved_data = config.setting[setting].split("  ")
        move = []
        for data, name in source_list:
            item = QtGui.QListWidgetItem(name)
            item.setData(QtCore.Qt.UserRole, QtCore.QVariant(data))
            try:
                i = saved_data.index(data)
                move.append((i, item))
            except:
                list1.addItem(item)
        move.sort(key=itemgetter(0))
        for i, item in move:
            list2.addItem(item)

    def _save_list_items(self, setting, list1):
        data = []
        for i in range(list1.count()):
            item = list1.item(i)
            data.append(unicode(item.data(QtCore.Qt.UserRole).toString()))
        config.setting[setting] = "  ".join(data)