split _updatePreviewButtons

This will allow to create a hierarchy in this class
This commit is contained in:
Arthur Milchior 2020-03-30 09:56:46 +02:00
parent f42c164999
commit 79dece3124

View file

@ -260,18 +260,24 @@ class BrowserPreviewer(Previewer):
def _updatePreviewButtons(self):
if not self._previewWindow:
return
self._previewPrev.setEnabled(self._should_enable_prev())
self._previewNext.setEnabled(self._should_enable_next())
def _should_enable_prev(self):
current = self.parent.currentRow()
canBack = current > 0 or (
current == 0
and self._previewState == "answer"
and not self._previewBothSides
)
self._previewPrev.setEnabled(bool(self.parent.singleCard and canBack))
return bool(self.parent.singleCard and canBack)
def _should_enable_next(self):
canForward = (
self.parent.currentRow() < self.parent.model.rowCount(None) - 1
or self._previewState == "question"
)
self._previewNext.setEnabled(bool(self.parent.singleCard and canForward))
return bool(self.parent.singleCard and canForward)
def _onClosePreview(self):
super()._onClosePreview()