Compare commits

...

2 Commits

Author SHA1 Message Date
Keith Edmunds
e498457395 Add option to force DEBUG message to stderr
If the default log level for stderr is greater than DEBUG, DEBUG
message won't be shown. The DEBUG(msg) function now takes an optional
Boolean second parameter. If that is True, the DEBUG message is always
sent to stderr.
2021-06-06 10:50:40 +01:00
Keith Edmunds
dbf0c27a09 Set up session before calling DbDialog. Fixes #13 2021-06-06 10:23:27 +01:00
3 changed files with 48 additions and 40 deletions

View File

@ -20,7 +20,7 @@ class Config(object):
ERRORS_TO = ['kae@midnighthax.com'] ERRORS_TO = ['kae@midnighthax.com']
FADE_STEPS = 20 FADE_STEPS = 20
FADE_TIME = 3000 FADE_TIME = 3000
LOG_LEVEL_STDERR = logging.DEBUG LOG_LEVEL_STDERR = logging.INFO
LOG_LEVEL_SYSLOG = logging.DEBUG LOG_LEVEL_SYSLOG = logging.DEBUG
LOG_NAME = "musicmuster" LOG_NAME = "musicmuster"
MAIL_PASSWORD = os.environ.get('MAIL_PASSWORD') MAIL_PASSWORD = os.environ.get('MAIL_PASSWORD')

View File

@ -59,7 +59,19 @@ def log_uncaught_exceptions(ex_cls, ex, tb):
sys.excepthook = log_uncaught_exceptions sys.excepthook = log_uncaught_exceptions
def DEBUG(msg): def DEBUG(msg, force_stderr=False):
"""
Outupt a log message at level DEBUG. If force_stderr is True,
output this message to stderr regardless of default stderr level
setting.
"""
if force_stderr:
old_level = stderr.level
stderr.setLevel(logging.DEBUG)
log.debug(msg)
stderr.setLevel(old_level)
else:
log.debug(msg) log.debug(msg)

View File

@ -402,7 +402,8 @@ class Window(QMainWindow, Ui_MainWindow):
pass pass
def search_database(self): def search_database(self):
dlg = DbDialog(self) with Session() as session:
dlg = DbDialog(self, session)
dlg.exec() dlg.exec()
def open_playlist(self): def open_playlist(self):
@ -626,8 +627,9 @@ class Window(QMainWindow, Ui_MainWindow):
class DbDialog(QDialog): class DbDialog(QDialog):
def __init__(self, parent=None): def __init__(self, parent, session):
super().__init__(parent) super().__init__(parent)
self.session = session
self.ui = Ui_Dialog() self.ui = Ui_Dialog()
self.ui.setupUi(self) self.ui.setupUi(self)
self.ui.searchString.textEdited.connect(self.chars_typed) self.ui.searchString.textEdited.connect(self.chars_typed)
@ -637,22 +639,20 @@ class DbDialog(QDialog):
self.ui.btnClose.clicked.connect(self.close) self.ui.btnClose.clicked.connect(self.close)
self.ui.matchList.itemSelectionChanged.connect(self.selection_changed) self.ui.matchList.itemSelectionChanged.connect(self.selection_changed)
with Session() as session: record = Settings.get_int(self.session, "dbdialog_width")
record = Settings.get_int(session, "dbdialog_width")
width = record.f_int or 800 width = record.f_int or 800
record = Settings.get_int(session, "dbdialog_height") record = Settings.get_int(self.session, "dbdialog_height")
height = record.f_int or 600 height = record.f_int or 600
self.resize(width, height) self.resize(width, height)
def __del__(self): def __del__(self):
with Session() as session: record = Settings.get_int(self.session, "dbdialog_height")
record = Settings.get_int(session, "dbdialog_height")
if record.f_int != self.height(): if record.f_int != self.height():
record.update(session, {'f_int': self.height()}) record.update(self.session, {'f_int': self.height()})
record = Settings.get_int(session, "dbdialog_width") record = Settings.get_int(self.session, "dbdialog_width")
if record.f_int != self.width(): if record.f_int != self.width():
record.update(session, {'f_int': self.width()}) record.update(self.session, {'f_int': self.width()})
def add_selected(self): def add_selected(self):
if not self.ui.matchList.selectedItems(): if not self.ui.matchList.selectedItems():
@ -660,8 +660,7 @@ class DbDialog(QDialog):
item = self.ui.matchList.currentItem() item = self.ui.matchList.currentItem()
track_id = item.data(Qt.UserRole) track_id = item.data(Qt.UserRole)
with Session() as session: self.add_track(track_id)
self.add_track(session, track_id)
def add_selected_and_close(self): def add_selected_and_close(self):
self.add_selected() self.add_selected()
@ -669,8 +668,7 @@ class DbDialog(QDialog):
def chars_typed(self, s): def chars_typed(self, s):
if len(s) > 0: if len(s) > 0:
with Session() as session: matches = Tracks.search_titles(self.session, s)
matches = Tracks.search_titles(session, s)
self.ui.matchList.clear() self.ui.matchList.clear()
if matches: if matches:
for track in matches: for track in matches:
@ -684,14 +682,13 @@ class DbDialog(QDialog):
def double_click(self, entry): def double_click(self, entry):
track_id = entry.data(Qt.UserRole) track_id = entry.data(Qt.UserRole)
with Session() as session: self.add_track(track_id)
self.add_track(session, track_id)
# Select search text to make it easier for next search # Select search text to make it easier for next search
self.select_searchtext() self.select_searchtext()
def add_track(self, session, track_id): def add_track(self, track_id):
track = Tracks.track_from_id(session, track_id) track = Tracks.track_from_id(self.session, track_id)
self.parent().visible_playlist().add_to_playlist(session, track) self.parent().visible_playlist().add_to_playlist(self.session, track)
# Select search text to make it easier for next search # Select search text to make it easier for next search
self.select_searchtext() self.select_searchtext()
@ -705,8 +702,7 @@ class DbDialog(QDialog):
item = self.ui.matchList.currentItem() item = self.ui.matchList.currentItem()
track_id = item.data(Qt.UserRole) track_id = item.data(Qt.UserRole)
with Session() as session: self.ui.dbPath.setText(Tracks.get_path(self.session, track_id))
self.ui.dbPath.setText(Tracks.get_path(session, track_id))
class SelectPlaylistDialog(QDialog): class SelectPlaylistDialog(QDialog):