Skip to content

Commit

Permalink
Merge pull request metabrainz#288 from zas/debug_mode
Browse files Browse the repository at this point in the history
Allow user to toggle debug mode from log dialog at runtime
  • Loading branch information
zas committed Apr 15, 2014
2 parents 7d0ccd0 + 95d3648 commit e48ef80
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
15 changes: 13 additions & 2 deletions picard/tagger.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ def __init__(self, args, localedir, autoupdate, debug=False):

self._args = args
self._autoupdate = autoupdate
self._debug = False

# FIXME: Figure out what's wrong with QThreadPool.globalInstance().
# It's a valid reference, but its start() method doesn't work.
Expand Down Expand Up @@ -134,8 +135,7 @@ def __init__(self, args, localedir, autoupdate, debug=False):
signal.signal(signal.SIGTERM, self.signal)

# Setup logging
if debug or "PICARD_DEBUG" in os.environ:
log.log_levels = log.log_levels | log.LOG_DEBUG
self.debug(debug or "PICARD_DEBUG" in os.environ)
log.debug("Starting Picard %s from %r", picard.__version__, os.path.abspath(__file__))
log.debug("Platform: %s %s %s", platform.platform(),
platform.python_implementation(), platform.python_version())
Expand Down Expand Up @@ -200,6 +200,17 @@ def __init__(self, args, localedir, autoupdate, debug=False):
self.nats = None
self.window = MainWindow()

def debug(self, debug):
if self._debug == debug:
return
if debug:
log.log_levels = log.log_levels | log.LOG_DEBUG
log.debug("Debug mode on")
else:
log.debug("Debug mode off")
log.log_levels = log.log_levels & ~log.LOG_DEBUG
self._debug = debug

def move_files_to_album(self, files, albumid=None, album=None):
"""Move `files` to tracks on album `albumid`."""
if album is None:
Expand Down
10 changes: 8 additions & 2 deletions picard/ui/logview.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ def __init__(self, title, logger, w=740, h=340, parent=None):
self.textCursor = QtGui.QTextCursor(self.doc)
self.browser = QtGui.QTextBrowser(self)
self.browser.setDocument(self.doc)
vbox = QtGui.QHBoxLayout(self)
vbox.addWidget(self.browser)
self.vbox = QtGui.QVBoxLayout(self)
self.vbox.addWidget(self.browser)
self._display()

def _setup_formats(self):
Expand Down Expand Up @@ -92,7 +92,13 @@ def __init__(self, parent=None):
title = _("Log")
logger = log.main_logger
LogViewCommon.__init__(self, title, logger, parent=parent)
cb = QtGui.QCheckBox(_('Debug mode'), self)
cb.setChecked(QtCore.QObject.tagger._debug)
cb.stateChanged.connect(self.toggleDebug)
self.vbox.addWidget(cb)

def toggleDebug(self, state):
QtCore.QObject.tagger.debug(state == QtCore.Qt.Checked)

class HistoryView(LogViewCommon):

Expand Down

0 comments on commit e48ef80

Please sign in to comment.