aboutsummaryrefslogtreecommitdiffstats
path: root/solo_tool_qt.py
diff options
context:
space:
mode:
Diffstat (limited to 'solo_tool_qt.py')
-rw-r--r--solo_tool_qt.py40
1 files changed, 33 insertions, 7 deletions
diff --git a/solo_tool_qt.py b/solo_tool_qt.py
index bb4ee76..a6823e0 100644
--- a/solo_tool_qt.py
+++ b/solo_tool_qt.py
@@ -10,6 +10,9 @@ POSITION_FACTOR = 100000
RATE_FACTOR = 10
UI_REFRESH_PERIOD_MS = 500
+CHANGE_GUI = 0
+CHANGE_INTERNAL = 1
+
class PlaylistModel(QAbstractListModel):
def __init__(self, soloTool, *args, **kwargs):
super(PlaylistModel, self).__init__(*args, **kwargs)
@@ -38,6 +41,8 @@ class ABListModel(QAbstractListModel):
return len(self.soloTool.getStoredAbLimits())
class MainWindow(QMainWindow, Ui_MainWindow):
+ songChangeSignal = pyqtSignal()
+
def __init__(self, *args, **kwargs):
super(MainWindow, self).__init__(*args, **kwargs)
self.setupUi(self)
@@ -52,6 +57,9 @@ class MainWindow(QMainWindow, Ui_MainWindow):
self.playlistModel = PlaylistModel(self.soloTool)
self.songListView.setModel(self.playlistModel)
self.songListView.selectionModel().selectionChanged.connect(self.playlistSelectionChanged)
+ self.songChangePending = None
+ self.songChangeSignal.connect(self.currentSongChanged)
+ self.soloTool.registerCurrentSongCallback(self.songChangeSignal.emit)
self.abListModel = ABListModel(self.soloTool)
self.abListView.setModel(self.abListModel)
@@ -136,25 +144,43 @@ class MainWindow(QMainWindow, Ui_MainWindow):
self.soloTool.setPlaybackPosition(position)
self.timer.start()
- def clearAbListSelection(self):
- i = self.abListView.selectionModel().currentIndex()
- self.abListView.selectionModel().select(i, QItemSelectionModel.Deselect)
+ def clearListViewSelection(self, listView):
+ i = listView.selectionModel().currentIndex()
+ listView.selectionModel().select(i, QItemSelectionModel.Deselect)
def abSliderReleased(self):
a = self.aSlider.value() / float(POSITION_FACTOR)
b = self.bSlider.value() / float(POSITION_FACTOR)
self.soloTool.setAbLimits(a, b)
- self.clearAbListSelection()
+ self.clearListViewSelection(self.abListView)
def rateSliderReleased(self):
rate = self.rateSlider.value() / float(RATE_FACTOR)
self.soloTool.setPlaybackRate(rate)
def playlistSelectionChanged(self, i):
- index = i.indexes()[0].row()
- self.soloTool.setSong(index)
+ if self.songChangePending == CHANGE_INTERNAL:
+ self.songChangePending = None
+ else:
+ assert self.songChangePending is None
+ self.songChangePending = CHANGE_GUI
+ index = i.indexes()[0].row()
+ self.soloTool.setSong(index)
+
self.abListModel.layoutChanged.emit()
- self.clearAbListSelection()
+ self.clearListViewSelection(self.abListView)
+
+ def currentSongChanged(self):
+ if self.songChangePending == CHANGE_GUI:
+ self.songChangePending = None
+ else:
+ assert self.songChangePending is None
+ self.songChangePending = CHANGE_INTERNAL
+ # TODO fix this hack
+ songIndex = self.soloTool._playlist.getCurrentSongIndex()
+ print(f"Forcing selection to {songIndex}")
+ i = self.playlistModel.createIndex(songIndex, 0)
+ self.songListView.selectionModel().select(i, QItemSelectionModel.ClearAndSelect)
def abListSelectionChanged(self, i):
if i is not None and not i.isEmpty():