mirror of
https://github.com/fergalmoran/picard.git
synced 2026-05-03 09:41:19 +00:00
Reduce code redundancy and use starting directory for Add folder action
This commit is contained in:
@@ -37,7 +37,8 @@ from picard.ui.options.dialog import OptionsDialog
|
||||
from picard.ui.infodialog import FileInfoDialog, AlbumInfoDialog
|
||||
from picard.ui.infostatus import InfoStatus
|
||||
from picard.ui.passworddialog import PasswordDialog
|
||||
from picard.util import icontheme, webbrowser2, find_existing_path, throttle, thread
|
||||
from picard.ui.util import find_starting_directory
|
||||
from picard.util import icontheme, webbrowser2, throttle, thread
|
||||
from picard.util.cdrom import discid, get_cdrom_drives
|
||||
from picard.plugin import ExtensionPoint
|
||||
|
||||
@@ -600,8 +601,7 @@ class MainWindow(QtGui.QMainWindow):
|
||||
|
||||
def add_files(self):
|
||||
"""Add files to the tagger."""
|
||||
current_directory = config.persist["current_directory"] or QtCore.QDir.homePath()
|
||||
current_directory = find_existing_path(unicode(current_directory))
|
||||
current_directory = find_starting_directory()
|
||||
formats = []
|
||||
extensions = []
|
||||
for exts, name in supported_formats():
|
||||
@@ -619,8 +619,7 @@ class MainWindow(QtGui.QMainWindow):
|
||||
|
||||
def add_directory(self):
|
||||
"""Add directory to the tagger."""
|
||||
current_directory = config.persist["current_directory"] or QtCore.QDir.homePath()
|
||||
current_directory = find_existing_path(unicode(current_directory))
|
||||
current_directory = find_starting_directory()
|
||||
|
||||
dir_list = []
|
||||
if not config.setting["toolbar_multiselect"]:
|
||||
|
||||
@@ -23,6 +23,7 @@ from PyQt4 import QtCore, QtGui
|
||||
from picard import config
|
||||
from picard.ui.options import OptionsPage, register_options_page
|
||||
from picard.ui.ui_options_interface import Ui_InterfaceOptionsPage
|
||||
from picard.ui.util import enabledSlot
|
||||
from picard.const import UI_LANGUAGES
|
||||
import operator
|
||||
import locale
|
||||
@@ -59,15 +60,6 @@ class InterfaceOptionsPage(OptionsPage):
|
||||
else:
|
||||
name = translation
|
||||
self.ui.ui_language.addItem(name, QtCore.QVariant(lang_code))
|
||||
# The following code is there to fix
|
||||
# http://tickets.musicbrainz.org/browse/PICARD-417
|
||||
# In some older version of PyQt/sip it's impossible to connect a signal
|
||||
# emitting an `int` to a slot expecting a `bool`.
|
||||
# By using `enabledSlot` instead we can force python to do the
|
||||
# conversion from int (`state`) to bool.
|
||||
def enabledSlot(func, state):
|
||||
"""Calls `func` with `state`."""
|
||||
func(state)
|
||||
self.ui.starting_directory.stateChanged.connect(partial(
|
||||
enabledSlot,
|
||||
self.ui.starting_directory_path.setEnabled)
|
||||
|
||||
@@ -27,6 +27,7 @@ from picard.file import File
|
||||
from picard.script import ScriptParser, SyntaxError, UnknownFunction
|
||||
from picard.ui.options import OptionsPage, OptionsCheckError, register_options_page
|
||||
from picard.ui.ui_options_renaming import Ui_RenamingOptionsPage
|
||||
from picard.ui.util import enabledSlot
|
||||
from picard.ui.options.scripting import TaggerScriptSyntaxHighlighter
|
||||
|
||||
|
||||
@@ -61,16 +62,6 @@ class RenamingOptionsPage(OptionsPage):
|
||||
self.ui.move_files.clicked.connect(self.update_examples)
|
||||
self.ui.move_files_to.editingFinished.connect(self.update_examples)
|
||||
|
||||
# The following code is there to fix
|
||||
# http://tickets.musicbrainz.org/browse/PICARD-417
|
||||
# In some older version of PyQt/sip it's impossible to connect a signal
|
||||
# emitting an `int` to a slot expecting a `bool`.
|
||||
# By using `enabledSlot` instead we can force python to do the
|
||||
# conversion from int (`state`) to bool.
|
||||
def enabledSlot(func, state):
|
||||
"""Calls `func` with `state`."""
|
||||
func(state)
|
||||
|
||||
if not sys.platform == "win32":
|
||||
self.ui.rename_files.stateChanged.connect(partial(
|
||||
enabledSlot,
|
||||
|
||||
@@ -19,6 +19,8 @@
|
||||
|
||||
import sys
|
||||
from PyQt4 import QtGui
|
||||
from picard import config
|
||||
from picard.util import find_existing_path
|
||||
|
||||
|
||||
class StandardButton(QtGui.QPushButton):
|
||||
@@ -42,3 +44,22 @@ class StandardButton(QtGui.QPushButton):
|
||||
icon = self.tagger.style().standardIcon(getattr(QtGui.QStyle, iconname))
|
||||
args = [icon, label]
|
||||
QtGui.QPushButton.__init__(self, *args)
|
||||
|
||||
|
||||
# The following code is there to fix
|
||||
# http://tickets.musicbrainz.org/browse/PICARD-417
|
||||
# In some older version of PyQt/sip it's impossible to connect a signal
|
||||
# emitting an `int` to a slot expecting a `bool`.
|
||||
# By using `enabledSlot` instead we can force python to do the
|
||||
# conversion from int (`state`) to bool.
|
||||
def enabledSlot(func, state):
|
||||
"""Calls `func` with `state`."""
|
||||
func(state)
|
||||
|
||||
|
||||
def find_starting_directory():
|
||||
if config.setting["starting_directory"]:
|
||||
path = config.setting["starting_directory_path"]
|
||||
else:
|
||||
path = config.persist["current_directory"] or QtCore.QDir.homePath()
|
||||
return find_existing_path(unicode(path))
|
||||
|
||||
Reference in New Issue
Block a user