Set up session before calling DbDialog. Fixes #13
This commit is contained in:
parent
e1b9dacd34
commit
dbf0c27a09
@ -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):
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user