From e0e6979101a3ae0605af62e413f08707733bf70f Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Fri, 28 Nov 2008 23:27:45 +0900 Subject: [PATCH] move to stacked widgets, fix scrollbar display --- ankiqt/ui/cardlist.py | 2 +- ankiqt/ui/facteditor.py | 10 +- ankiqt/ui/main.py | 192 +++++++++---------------- designer/addcards.ui | 25 ++-- designer/cardlist.ui | 20 +-- designer/main.ui | 300 +++++++++++++++++++++++++++++++++++----- 6 files changed, 348 insertions(+), 201 deletions(-) diff --git a/ankiqt/ui/cardlist.py b/ankiqt/ui/cardlist.py index e59f1a7f9..c585d8ce6 100644 --- a/ankiqt/ui/cardlist.py +++ b/ankiqt/ui/cardlist.py @@ -334,7 +334,7 @@ class EditDeck(QMainWindow): self.updateSearch() def updateFilterLabel(self): - self.setWindowTitle(_("Anki - Edit Items (%(cur)d " + self.setWindowTitle(_("Editor (%(cur)d " "of %(tot)d cards shown)") % {"cur": len(self.model.cards), "tot": self.deck.cardCount}) diff --git a/ankiqt/ui/facteditor.py b/ankiqt/ui/facteditor.py index 6abb05b1f..25984777a 100644 --- a/ankiqt/ui/facteditor.py +++ b/ankiqt/ui/facteditor.py @@ -19,11 +19,10 @@ class FactEditor(object): Extra widgets can be added to 'fieldsGrid' to represent card-specific information, etc.""" - def __init__(self, parent, widget, deck=None, colour=""): + def __init__(self, parent, widget, deck=None): self.widget = widget self.parent = parent self.deck = deck - self.colour = colour self.fact = None self.fontChanged = False self.setupFields() @@ -74,9 +73,6 @@ class FactEditor(object): # button styles for mac self.plastiqueStyle = QStyleFactory.create("plastique") self.widget.setStyle(self.plastiqueStyle) - self.widget.setStyleSheet(""" -%s -#fieldsArea { border: 0px; margin-top: 4px; }""" % self.colour) # bold self.bold = QPushButton() self.bold.setCheckable(True) @@ -209,9 +205,7 @@ class FactEditor(object): def _makeGrid(self): "Rebuild the grid to avoid trigging QT bugs." - self.fieldsFrame = QFrame() - self.fieldsFrame.setFrameStyle(0) - self.fieldsFrame.setLineWidth(0) + self.fieldsFrame = QWidget() self.fieldsGrid = QGridLayout(self.fieldsFrame) self.fieldsFrame.setLayout(self.fieldsGrid) self.fieldsGrid.setMargin(0) diff --git a/ankiqt/ui/main.py b/ankiqt/ui/main.py index f2dabf4e4..0006b9aff 100644 --- a/ankiqt/ui/main.py +++ b/ankiqt/ui/main.py @@ -77,14 +77,12 @@ class AnkiQt(QMainWindow): self.mainWin.mainText = ui.view.AnkiWebView(self.mainWin.mainTextFrame) self.mainWin.mainText.setObjectName("mainText") self.mainWin.mainText.setFocusPolicy(Qt.ClickFocus) - self.mainWin.vboxlayout.addWidget(self.mainWin.mainText) - self.mainWin.buttonWidget = QWidget(self.mainWin.mainTextFrame) - self.mainWin.buttonWidget.setObjectName("buttonWidget") - self.mainWin.vboxlayout.addWidget(self.mainWin.buttonWidget) + self.mainWin.mainStack.addWidget(self.mainWin.mainText) self.help = ui.help.HelpArea(self.mainWin.helpFrame, self.config, self) self.mainWin.mainText.pageAction(QWebPage.Reload).setVisible(False) - self.mainWin.welcomeText.hide() - self.mainWin.mainText.hide() + self.mainWin.mainStack.setCurrentIndex(2) + self.mainWin.buttonStack.show() + self.mainWin.buttonStack.setCurrentIndex(1) def setupViews(self): self.bodyView = ui.view.View(self, self.mainWin.mainText, @@ -184,19 +182,14 @@ An error occurred. Please copy the following message into a bug report.\n\n""" + self.state = state self.updateTitleBar() if 'state' != 'noDeck' and state != 'editCurrentFact': - self.mainWin.welcomeText.hide() - self.mainWin.mainText.show() - self.mainWin.buttonWidget.show() - self.mainWin.fieldsArea.hide() + self.showReviewScreen() if state == "noDeck": - self.mainWin.welcomeText.show() - self.mainWin.mainText.hide() + self.showWelcomeScreen() self.help.hide() self.currentCard = None self.lastCard = None self.disableDeckMenuItems() self.updateRecentFilesMenu() - self.resetButtons() # hide all deck-associated dialogs ui.dialogs.closeAll() elif state == "getQuestion": @@ -217,14 +210,12 @@ An error occurred. Please copy the following message into a bug report.\n\n""" + else: return self.moveToState("deckFinished") elif state == "deckEmpty": - self.mainWin.welcomeText.show() - self.mainWin.mainText.hide() - self.resetButtons() + self.showWelcomeScreen() self.disableCardMenuItems() self.mainWin.menu_Lookup.setEnabled(False) elif state == "deckFinished": self.deck.s.flush() - self.resetButtons() + self.hideButtons() self.mainWin.menu_Lookup.setEnabled(False) self.disableCardMenuItems() self.startRefreshTimer() @@ -232,22 +223,16 @@ An error occurred. Please copy the following message into a bug report.\n\n""" + elif state == "showQuestion": if self.deck.mediaDir(): os.chdir(self.deck.mediaDir()) - self.resetButtons() self.showAnswerButton() self.updateMarkAction() self.runHook('showQuestion') elif state == "showAnswer": - self.resetButtons() self.showEaseButtons() self.enableCardMenuItems() elif state == "editCurrentFact": if self.lastState == "editCurrentFact": return self.moveToState("saveEdit") - self.resetButtons() - self.showSaveEditorButton() - self.mainWin.mainText.hide() - self.mainWin.fieldsArea.show() - self.editor.setFact(self.currentCard.fact) + self.showEditor() elif state == "saveEdit": self.editor.saveFieldsNow() self.deck.s.flush() @@ -321,27 +306,23 @@ An error occurred. Please copy the following message into a bug report.\n\n""" + self.refreshTimer.stop() self.refreshTimer = None + # Main stack + ########################################################################## + + def showWelcomeScreen(self): + self.mainWin.mainStack.setCurrentIndex(0) + self.hideButtons() + + def showEditScreen(self): + self.mainWin.mainStack.setCurrentIndex(1) + + def showReviewScreen(self): + self.mainWin.mainStack.setCurrentIndex(2) + # Buttons ########################################################################## def setupButtons(self): - self.outerButtonBox = QHBoxLayout(self.mainWin.buttonWidget) - self.outerButtonBox.setMargin(3) - self.outerButtonBox.setSpacing(0) - self.innerButtonWidget = None - - def resetButtons(self): - # this round-about process is trying to work around a bug in qt - if self.lastState == self.state: - return - if self.innerButtonWidget: - self.outerButtonBox.removeWidget(self.innerButtonWidget) - self.innerButtonWidget.deleteLater() - self.innerButtonWidget = QWidget() - self.outerButtonBox.addWidget(self.innerButtonWidget) - self.buttonBox = QVBoxLayout(self.innerButtonWidget) - self.buttonBox.setSpacing(3) - self.buttonBox.setMargin(3) if self.config['easeButtonHeight'] == "tall": self.easeButtonHeight = 50 else: @@ -349,77 +330,50 @@ An error occurred. Please copy the following message into a bug report.\n\n""" + self.easeButtonHeight = 35 else: self.easeButtonHeight = 25 + # ask + self.connect(self.mainWin.showAnswerButton, SIGNAL("clicked()"), + lambda: self.moveToState("showAnswer")) + # answer + for i in range(1, 5): + b = getattr(self.mainWin, "easeButton%d" % i) + b.setFixedHeight(self.easeButtonHeight) + b.setFixedWidth(100) + self.connect(b, SIGNAL("clicked()"), + lambda i=i: self.cardAnswered(i)) + # editor + self.connect(self.mainWin.saveEditorButton, SIGNAL("clicked()"), + lambda: self.moveToState("saveEdit")) + + def hideButtons(self): + self.mainWin.buttonStack.hide() def showAnswerButton(self): - if self.lastState == self.state: - return - button = QPushButton(_("Show answer")) - button.setFixedHeight(self.easeButtonHeight) - self.buttonBox.addWidget(button) - button.setFocus() - button.setDefault(True) - self.connect(button, SIGNAL("clicked()"), - lambda: self.moveToState("showAnswer")) - - def getSpacer(self, hpolicy=QSizePolicy.Preferred): - return QSpacerItem(20, 20, - hpolicy, - QSizePolicy.Preferred) + self.mainWin.buttonStack.setCurrentIndex(0) + self.mainWin.buttonStack.show() + self.mainWin.showAnswerButton.setFocus() def showEaseButtons(self): - # if the state hasn't changed, do nothing - if self.lastState == self.state: - return - # gather next intervals - nextInts = {} - for i in range(5): - s=self.deck.nextIntervalStr(self.currentCard, i) - nextInts["ease%d" % i] = s - # button grid - grid = QGridLayout() - grid.setSpacing(3) - button3 = self.showCompactEaseButtons(grid, nextInts) - hbox = QHBoxLayout() - hbox.addStretch() - hbox.addLayout(grid) - hbox.addStretch() - self.buttonBox.addLayout(hbox) - button3.setFocus() + self.updateEaseButtons() + self.mainWin.buttonStack.setCurrentIndex(1) + self.mainWin.buttonStack.show() + self.mainWin.easeButton3.setFocus() - def showCompactEaseButtons(self, grid, nextInts): - text = ( - (_("Again"), - _("%(ease1)s"), - _("Relearn (1)
Mark harder and learn again.")), - (_("Hard"), - _("%(ease2)s"), - _("Hard (2)
Wait a little longer next time.")), - (_("Good"), - _("%(ease3)s"), - _("Comfortable (3)
Wait longer next time.")), - (_("Easy"), - _("%(ease4)s"), - _("Easy (4)
Wait a lot longer next time."))) - button3 = None + def showSaveEditorButton(self): + self.mainWin.buttonStack.setCurrentIndex(2) + self.mainWin.buttonStack.show() + + def updateEaseButtons(self): + nextInts = {} for i in range(1, 5): - if not self.config['suppressEstimates']: + l = getattr(self.mainWin, "easeLabel%d" % i) + if self.config['suppressEstimates']: + l.hide() + else: if i == 1: - label = QLabel(self.withInterfaceFont(_("Soon"))) + l.setText(self.withInterfaceFont(_("Soon"))) else: - label = QLabel(self.withInterfaceFont(text[i-1][1] % nextInts)) - label.setAlignment(Qt.AlignHCenter) - grid.addWidget(label, 0, (i*2)+1) - button = QPushButton(text[i-1][0]) - button.setFixedHeight(self.easeButtonHeight) - button.setFixedWidth(100) - button.setToolTip(text[i-1][2]) - self.connect(button, SIGNAL("clicked()"), - lambda i=i: self.cardAnswered(i)) - #button.setFixedWidth(70) - if i == 3: - button3 = button - grid.addWidget(button, 1, (i*2)+1) - return button3 + l.setText(self.withInterfaceFont("" + + self.deck.nextIntervalStr(self.currentCard, i) + "")) def withInterfaceFont(self, text): family = self.config["interfaceFontFamily"] @@ -852,31 +806,21 @@ To upgrade an old deck, download Anki 0.9.8.7.""")) ########################################################################## def setupEditor(self): - self.mainWin.fieldsArea.hide() - self.mainWin.fieldsArea.setFlat(True) self.editor = ui.facteditor.FactEditor( - self, self.mainWin.fieldsArea, self.deck, - colour="* { background-color: #fff; }\n") + self, self.mainWin.fieldsArea, self.deck) self.editor.onFactValid = self.onFactValid self.editor.onFactInvalid = self.onFactInvalid - def showSaveEditorButton(self): - if self.lastState == self.state: - return - self.editFactButton = QPushButton(_("Close")) - self.editFactButton.setToolTip("Hit Esc to return to review.") - self.editFactButton.setFixedHeight(self.easeButtonHeight) - self.editFactButton.setShortcut(_("Esc")) - self.editFactButton.setDefault(False) - self.buttonBox.addWidget(self.editFactButton) - self.connect(self.editFactButton, SIGNAL("clicked()"), - lambda: self.moveToState("saveEdit")) + def showEditor(self): + self.showSaveEditorButton() + self.mainWin.mainStack.setCurrentIndex(1) + self.editor.setFact(self.currentCard.fact) def onFactValid(self, fact): - self.editFactButton.setEnabled(True) + self.mainWin.saveEditorButton.setEnabled(True) def onFactInvalid(self, fact): - self.editFactButton.setEnabled(False) + self.mainWin.saveEditorButton.setEnabled(False) # Toolbar ########################################################################## @@ -1209,9 +1153,7 @@ To upgrade an old deck, download Anki 0.9.8.7.""")) self.connect(self.syncThread, SIGNAL("closeSyncProgress"), self.closeSyncProgress) self.connect(self.syncThread, SIGNAL("updateSyncProgress"), self.updateSyncProgress) self.syncThread.start() - self.mainWin.buttonWidget.hide() - self.mainWin.mainText.hide() - self.mainWin.welcomeText.show() + self.showWelcomeScreen() self.setEnabled(False) while not self.syncThread.isFinished(): self.app.processEvents() @@ -1221,7 +1163,7 @@ To upgrade an old deck, download Anki 0.9.8.7.""")) def syncFinished(self): "Reopen after sync finished." - self.mainWin.buttonWidget.show() + self.mainWin.buttonStack.show() if self.loadAfterSync: self.loadDeck(self.deckPath, sync=False) self.deck.syncName = self.syncName diff --git a/designer/addcards.ui b/designer/addcards.ui index ccd260005..f1d6dab55 100644 --- a/designer/addcards.ui +++ b/designer/addcards.ui @@ -10,7 +10,7 @@ - Anki - Add Items + Add Items @@ -21,15 +21,24 @@ + + 0 + + + 4 + + + 0 + + + 4 + 0 4 - - 0 - @@ -47,7 +56,7 @@ Qt::Vertical - + 0 @@ -57,12 +66,6 @@ true - - - - - true - diff --git a/designer/cardlist.ui b/designer/cardlist.ui index 35cfec9e2..612f8d3f8 100644 --- a/designer/cardlist.ui +++ b/designer/cardlist.ui @@ -18,7 +18,7 @@ 0 23 599 - 559 + 579 @@ -135,19 +135,13 @@ 6 - + 7 2 - - - - - true - @@ -211,16 +205,6 @@ - - - - 0 - 582 - 599 - 20 - - - diff --git a/designer/main.ui b/designer/main.ui index 4ce96565f..a4eb1c72a 100644 --- a/designer/main.ui +++ b/designer/main.ui @@ -5,8 +5,8 @@ 0 0 - 454 - 504 + 655 + 487 @@ -27,8 +27,8 @@ 0 69 - 454 - 415 + 655 + 398 @@ -122,43 +122,267 @@ QFrame::Raised - - - 0 - - - 5 - - - + + + - - 7 - 2 + + 0 + 99 - - true - - - - - - true - - - false + + 1 + + + + 0 + 0 + 370 + 330 + + + + + + + Qt::ClickFocus + + + QFrame::NoFrame + + + + + + + + + 0 + 0 + 370 + 336 + + + + + + + + - - - - Qt::ClickFocus - - - QFrame::NoFrame + + + + 1 + + + + 0 + 0 + 370 + 52 + + + + + + + Qt::Vertical + + + + 20 + 1 + + + + + + + + Show Answer + + + + + + + + + 0 + 0 + 370 + 50 + + + + + 0 + + + 0 + + + 0 + + + 0 + + + 6 + + + + + 0 + + + + + Qt::Horizontal + + + + 40 + 0 + + + + + + + + 6 + + + 0 + + + + + TextLabel + + + Qt::AlignCenter + + + + + + + TextLabel + + + Qt::AlignCenter + + + + + + + TextLabel + + + Qt::AlignCenter + + + + + + + TextLabel + + + Qt::AlignCenter + + + + + + + Again + + + + + + + Hard + + + + + + + Good + + + + + + + Easy + + + + + + + + + Qt::Horizontal + + + + 40 + 0 + + + + + + + + + + + + 0 + 0 + 370 + 44 + + + + + + + Qt::Vertical + + + + 20 + 1 + + + + + + + + Close + + + Esc + + + + + @@ -352,7 +576,7 @@ 0 0 - 454 + 655 23 @@ -489,8 +713,8 @@ 0 - 484 - 454 + 467 + 655 20 @@ -503,7 +727,7 @@ 0 23 - 454 + 655 46