From 089f22c1718f9109a2fb73cb55c5084f5312e297 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Sat, 10 Jan 2009 16:53:47 +0900 Subject: [PATCH] simplify preferences, more tweaks to study page --- ankiqt/config.py | 25 -- ankiqt/ui/help.py | 4 +- ankiqt/ui/main.py | 67 ++-- ankiqt/ui/preferences.py | 81 ----- ankiqt/ui/view.py | 34 +-- designer/main.ui | 642 +++++++++++++++++++-------------------- designer/preferences.ui | 286 +++++------------ 7 files changed, 435 insertions(+), 704 deletions(-) diff --git a/ankiqt/config.py b/ankiqt/config.py index f983c0caf..b63db055e 100644 --- a/ankiqt/config.py +++ b/ankiqt/config.py @@ -57,7 +57,6 @@ class Config(dict): 'saveAfterAddingNum': 3, 'saveOnClose': True, 'mainWindowGeom': None, - 'easeButtonHeight': 'standard', 'suppressUpdate': False, 'suppressEstimates': False, 'showLastCardInterval': False, @@ -84,30 +83,6 @@ class Config(dict): # guess interface and target languages (lang, enc) = locale.getdefaultlocale() self['interfaceLang'] = lang - self.initFonts() - - def initFonts(self): - defaultColours = { - 'lastCard': "#0077FF", - 'background': "#FFFFFF", - 'interface': "#000000", - } - defaultSizes = { - 'interface': 12, - 'lastCard': 14, - 'edit': 12, - 'other': 24, - } - # fonts - for n in ("interface", "lastCard", "edit"): - if not self.get(n + "FontFamily", None): - self[n + "FontFamily"] = "Arial" - self[n + "FontSize"] = defaultSizes.get(n, defaultSizes['other']) - # colours - for n in ("interface", "lastCard", "background"): - color = n + "Colour" - if not color in self: - self[color] = defaultColours[n] def getDbPath(self): return os.path.join(self.configPath, self.configDbName) diff --git a/ankiqt/ui/help.py b/ankiqt/ui/help.py index 1ecbc3d79..7c9738f61 100644 --- a/ankiqt/ui/help.py +++ b/ankiqt/ui/help.py @@ -51,8 +51,8 @@ class HelpArea(object): else: font = "arial" # qt seems to ignore font-size on elements like h1 - style = ("\n") % font + style = "" #("\n") % font self.widget.setHtml(style + '
' + self.buffer + '
') diff --git a/ankiqt/ui/main.py b/ankiqt/ui/main.py index 969f544b2..653a976ea 100644 --- a/ankiqt/ui/main.py +++ b/ankiqt/ui/main.py @@ -415,13 +415,10 @@ new: ########################################################################## def setupButtons(self): - if self.config['easeButtonHeight'] == "tall": - self.easeButtonHeight = 50 + if sys.platform.startswith("darwin"): + self.easeButtonHeight = 35 else: - if sys.platform.startswith("darwin"): - self.easeButtonHeight = 35 - else: - self.easeButtonHeight = 25 + self.easeButtonHeight = 25 # ask self.mainWin.showAnswerButton.setFixedHeight(self.easeButtonHeight) self.connect(self.mainWin.showAnswerButton, SIGNAL("clicked()"), @@ -489,20 +486,10 @@ new: if self.config['suppressEstimates']: l.setText("") elif i == 1: - l.setText(self.withInterfaceFont(_("Soon"))) + l.setText(_("Soon")) else: - l.setText(self.withInterfaceFont("" + - self.deck.nextIntervalStr(self.currentCard, i) + "")) - - def withInterfaceFont(self, text): - family = self.config["interfaceFontFamily"] - size = self.config["interfaceFontSize"] - colour = self.config["interfaceColour"] - css = ('.interface {font-family: "%s"; font-size: %spx; color: %s}\n' % - (family, size, colour)) - css = "\n" - text = css + '' + text + "" - return text + l.setText("" + self.deck.nextIntervalStr( + self.currentCard, i) + "") # Deck loading & saving: backend ########################################################################## @@ -967,6 +954,8 @@ To upgrade an old deck, download Anki 0.9.8.7.""")) self.mainWin.optionsBox.setShown(False) self.connect(self.mainWin.minuteLimit, SIGNAL("textChanged(QString)"), self.onMinuteLimitChanged) + self.connect(self.mainWin.newPerDay, + SIGNAL("textChanged(QString)"), self.onNewLimitChanged) def onMinuteLimitChanged(self, qstr): try: @@ -976,6 +965,15 @@ To upgrade an old deck, download Anki 0.9.8.7.""")) pass self.updateStudyStats() + def onNewLimitChanged(self, qstr): + try: + self.deck.newCardsPerDay = int(self.mainWin.newPerDay.text()) + except ValueError: + pass + self.deck.checkDue() + self.statusView.redraw() + self.updateStudyStats() + def updateStudyStats(self): initial = self.deck.sessionStartTime == 0 if initial: @@ -988,7 +986,7 @@ To upgrade an old deck, download Anki 0.9.8.7.""")) # top label h = {} s = self.deck.getStats() - h['ret'] = '%s' % (s['rev']+s['failed']) + h['ret'] = '%s' % (s['rev']+s['failed']) h['new'] = '%s' % s['new'] h['newof'] = '%s' % self.deck.newCount dtoday = s['dTotal'] @@ -1000,8 +998,8 @@ day = :d""", d=yesterday) (dyest, tyest) = res else: dyest = 0; tyest = 0 - h['repsToday'] = '%s' % dtoday - h['repsTodayChg'] = '%s' % dyest + h['repsToday'] = '%s' % dtoday + h['repsTodayChg'] = '%s' % dyest limit = self.deck.sessionTimeLimit start = self.deck.sessionStartTime or time.time() - limit start2 = self.deck.lastSessionStart or start - limit @@ -1012,30 +1010,31 @@ day = :d""", d=yesterday) "select count(*) from reviewHistory where " "time >= :t and time < :t2", t=start2, t2=start) - h['repsInSes'] = '%s' % last10 - h['repsInSesChg'] = '%s' % last20 + h['repsInSes'] = '%s' % last10 + h['repsInSesChg'] = '%s' % last20 ttoday = s['dReviewTime'] - h['timeToday'] = '%s' % ( + h['timeToday'] = '%s' % ( anki.utils.fmtTimeSpan(ttoday, short=True, point=1)) - h['timeTodayChg'] = '%s' % ( + h['timeTodayChg'] = '%s' % ( anki.utils.fmtTimeSpan(tyest, short=True, point=1)) self.mainWin.optionsLabel.setText(top + _("""\

-
- + - + -
Session:  %(repsInSes)s
Session reps:  %(repsInSes)s %(repsInSesChg)s
Day:%(repsToday)s
Day reps:%(repsToday)s %(repsTodayChg)s
Time:%(timeToday)s %(timeTodayChg)s
- - - -
Review: %(ret)s
New today:%(new)s
New total:%(newof)s
""") % h) + +     + + + +
Reviews today:%(ret)s
New today:%(new)s (of %(newof)s)
+""") % h) def showStudyScreen(self): diff --git a/ankiqt/ui/preferences.py b/ankiqt/ui/preferences.py index c396f000c..063912141 100644 --- a/ankiqt/ui/preferences.py +++ b/ankiqt/ui/preferences.py @@ -39,8 +39,6 @@ class Preferences(QDialog): ] self.connect(self.dialog.buttonBox, SIGNAL("helpRequested()"), self.helpRequested) self.setupLang() - self.setupFont() - self.setupColour() self.setupSync() self.setupSave() self.setupAdvanced() @@ -75,66 +73,6 @@ class Preferences(QDialog): self.parent.setLang() self.dialog.retranslateUi(self) - fonts = ( - "interface", - ) - - def loadCurrentFonts(self): - for font in self.fonts: - # family init - getattr(self.dialog, font + "Family").setCurrentFont(QFont( - self.config[font + "FontFamily"])) - # size init - getattr(self.dialog, font + "Size").setValue( - self.config[font + "FontSize"]) - - def setupFont(self): - self.loadCurrentFonts() - for font in self.fonts: - # family change - family = font + "Family" - chngFunc = lambda qfont, type=font: self.familyChanged(qfont, type) - self.connect(getattr(self.dialog, family), - SIGNAL("currentFontChanged(QFont)"), - chngFunc) - - # size change - size = font + "Size" - chngFunc = lambda size, type=font: self.sizeChanged(size, type) - self.connect(getattr(self.dialog, size), - SIGNAL("valueChanged(int)"), - chngFunc) - - def familyChanged(self, qfont, type): - self.config[type + "FontFamily"] = unicode(qfont.family()) - getattr(self.dialog, type + "Family").setFocus() - - def sizeChanged(self, size, type): - self.config[type + "FontSize"] = size - getattr(self.dialog, type + "Size").setFocus() - - def setupColour(self): - self.plastiqueStyle = None - if (sys.platform.startswith("darwin") or - sys.platform.startswith("win32")): - # mac widgets don't show colours - self.plastiqueStyle = QStyleFactory.create("plastique") - for c in ("interface", "background"): - colour = c + "Colour" - button = getattr(self.dialog, colour) - if self.plastiqueStyle: - button.setStyle(self.plastiqueStyle) - button.setPalette(QPalette(QColor( - self.config[colour]))) - self.connect(button, SIGNAL("clicked()"), - lambda b=button, t=c, : self.colourClicked(b, t)) - - def colourClicked(self, button, type): - new = QColorDialog.getColor(button.palette().window().color(), self) - if new.isValid(): - self.config[type + "Colour"] = str(new.name()) - button.setPalette(QPalette(new)) - def setupSync(self): self.dialog.syncOnOpen.setChecked(self.config['syncOnLoad']) self.dialog.syncOnClose.setChecked(self.config['syncOnClose']) @@ -163,46 +101,27 @@ class Preferences(QDialog): def setupAdvanced(self): self.dialog.showToolbar.setChecked(self.config['showToolbar']) - self.dialog.tallButtons.setChecked( - self.config['easeButtonHeight'] != 'standard') self.dialog.showEstimates.setChecked(not self.config['suppressEstimates']) self.dialog.showStudyOptions.setChecked(self.config['showStudyScreen']) - self.dialog.showLastCardInterval.setChecked(self.config['showLastCardInterval']) - self.dialog.showLastCardContent.setChecked(self.config['showLastCardContent']) self.dialog.showTray.setChecked(self.config['showTrayIcon']) self.dialog.showTimer.setChecked(self.config['showTimer']) - self.dialog.simpleToolbar.setChecked(self.config['simpleToolbar']) self.dialog.scrollToAnswer.setChecked(self.config['scrollToAnswer']) self.dialog.showDivider.setChecked(self.config['qaDivider']) self.dialog.splitQA.setChecked(self.config['splitQA']) self.dialog.addZeroSpace.setChecked(self.config['addZeroSpace']) self.dialog.alternativeTheme.setChecked(self.config['alternativeTheme']) - self.dialog.toolbarIconSize.setText(str(self.config['iconSize'])) def updateAdvanced(self): self.config['showToolbar'] = self.dialog.showToolbar.isChecked() - if self.dialog.tallButtons.isChecked(): - self.config['easeButtonHeight'] = 'tall' - else: - self.config['easeButtonHeight'] = 'standard' - self.config['showLastCardInterval'] = self.dialog.showLastCardInterval.isChecked() - self.config['showLastCardContent'] = self.dialog.showLastCardContent.isChecked() self.config['showTrayIcon'] = self.dialog.showTray.isChecked() self.config['showTimer'] = self.dialog.showTimer.isChecked() self.config['suppressEstimates'] = not self.dialog.showEstimates.isChecked() self.config['showStudyScreen'] = self.dialog.showStudyOptions.isChecked() - self.config['simpleToolbar'] = self.dialog.simpleToolbar.isChecked() self.config['scrollToAnswer'] = self.dialog.scrollToAnswer.isChecked() self.config['qaDivider'] = self.dialog.showDivider.isChecked() self.config['splitQA'] = self.dialog.splitQA.isChecked() self.config['addZeroSpace'] = self.dialog.addZeroSpace.isChecked() self.config['alternativeTheme'] = self.dialog.alternativeTheme.isChecked() - i = 32 - try: - i = int(self.dialog.toolbarIconSize.text()) - except: - pass - self.config['iconSize'] = i def codeToIndex(self, code): n = 0 diff --git a/ankiqt/ui/view.py b/ankiqt/ui/view.py index 4c845637b..6704fbff4 100644 --- a/ankiqt/ui/view.py +++ b/ankiqt/ui/view.py @@ -8,6 +8,7 @@ import anki, anki.utils from anki.sound import playFromText, stripSounds from anki.latex import renderLatex, stripLatex from anki.utils import stripHTML +from anki.hooks import runHook import types, time, re, os, urllib, sys from ankiqt import ui from ankiqt.ui.utils import mungeQA @@ -50,7 +51,6 @@ class View(object): if self.state == "noDeck" or self.state == "studyScreen": return self.clearWindow() - self.setBackgroundColour() self.haveTop = (self.main.lastCard and ( self.main.config['showLastCardContent'] or self.main.config['showLastCardInterval'])) @@ -81,16 +81,6 @@ class View(object): s = "" return s @@ -104,24 +94,16 @@ class View(object): def flush(self): "Write the current HTML buffer to the screen." - txt = (self.addStyles() + ''' -

''' + - self.buffer + '
') - self.body.setHtml(txt) + self.buffer = self.addStyles() + self.buffer + # hook for user css + runHook("preFlushHook") + self.body.setHtml(self.buffer) def write(self, text): if type(text) != types.UnicodeType: text = unicode(text, "utf-8") self.buffer += text - def setBackgroundColour(self): - p = QPalette() - p.setColor(QPalette.Base, QColor(self.main.config['backgroundColour'])) - self.body.setPalette(p) - if self.frame: - p.setColor(QPalette.Background, QColor(self.main.config['backgroundColour'])) - self.frame.setPalette(p) - # Question and answer ########################################################################## @@ -141,7 +123,7 @@ class View(object): if self.haveTop: height = 35 else: - height = 40 + height = 45 self.write(self.center(self.mungeQA(self.main.deck, q), height)) if self.state != self.oldState and not nosound: playFromText(q) @@ -283,6 +265,10 @@ Start adding your own material. class AnkiWebView(QWebView): + def __init__(self, *args): + QWebView.__init__(self, *args) + self.setObjectName("mainText") + def keyPressEvent(self, evt): if evt.matches(QKeySequence.Copy): self.triggerPageAction(QWebPage.Copy) diff --git a/designer/main.ui b/designer/main.ui index 7791aac28..665e5719f 100644 --- a/designer/main.ui +++ b/designer/main.ui @@ -5,8 +5,8 @@ 0 0 - 562 - 469 + 569 + 454 @@ -27,8 +27,8 @@ 0 69 - 562 - 380 + 569 + 365 @@ -154,8 +154,8 @@ 0 0 - 277 - 302 + 284 + 280 @@ -207,304 +207,212 @@ 0 0 - 100 - 30 + 284 + 280 - - - + + + 0 + + + + + 0 + + + 4 + - + + + <h1>Welcome!</h1> + + + Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse + + + + + + + Qt::Vertical + + + QSizePolicy::Fixed + + + + 20 + 6 + + + + + + + + + 400 + 16777215 + + + + Qt::Horizontal + + + + + + + 2 + + + 6 + 0 - - 4 - - - - - <h1>Welcome!</h1> + + + + + 140 + 0 + - - Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse + + <b>Session limit (mins):</b> + + + 4 - - - - Qt::Vertical + + + + + 0 + 0 + - - QSizePolicy::Fixed + + + 50 + 16777215 + + + + + + + + + 140 + 0 + + + + <b>New cards per day:</b> + + + 4 + + + + + + + + 0 + 0 + + + + + 50 + 16777215 + + + + + + + + Qt::Horizontal - 20 - 6 + 40 + 20 - - + + + + + 0 + 0 + + - 400 + 50 16777215 - - Qt::Horizontal + + + + + + <b>Session limit (reps): + + + 4 - - - - + + + + 4 - - true - - - - 0 - - - - - 2 - - - 0 - - - - - - 90 - 0 - - - - <b>Minute limit:</b> - - - - - - - - 0 - 0 - - - - - 50 - 16777215 - - - - - - - - <b>Question limit:</b> - - - - - - - - 0 - 0 - - - - - 50 - 16777215 - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - 90 - 0 - - - - <b>New per day:</b> - - - - - - - - 0 - 0 - - - - - 50 - 16777215 - - - - - - - - Qt::Horizontal - - - QSizePolicy::Preferred - - - - 10 - 20 - - - - - - - - - - - - More>> - - - true - - - false - - - false - - - - - - - Help - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - - - - - 400 - 16777215 - + + + More>> - - - - + true - - - 0 - - - - - - 400 - 16777215 - - - - - - - - - 400 - 16777215 - - - - - - - - - 400 - 16777215 - - - - - - - - Show failed cards last - - - - + + false + + + false + - + + + Help + + + + + - Qt::Vertical + Qt::Horizontal - 20 - 40 + 40 + 20 @@ -514,20 +422,98 @@ - - - Qt::Horizontal - - - - 40 - 20 - - - + + + + + + 4 + + + 2 + + + 4 + + + 0 + + + 0 + + + + + + 250 + 0 + + + + + + + + + 400 + 16777215 + + + + + + + + + 400 + 16777215 + + + + + + + + Show failed cards last + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + Qt::Horizontal + + + QSizePolicy::Expanding + + + + 1000 + 20 + + + + @@ -542,8 +528,8 @@ 0 0 - 277 - 72 + 284 + 89 @@ -583,8 +569,8 @@ 0 0 - 277 - 72 + 284 + 89 @@ -746,8 +732,8 @@ 0 0 - 277 - 72 + 284 + 89 @@ -781,8 +767,8 @@ 0 0 - 277 - 72 + 284 + 89 @@ -823,8 +809,8 @@ 0 0 - 277 - 72 + 284 + 89 @@ -851,8 +837,8 @@ 0 0 - 277 - 72 + 284 + 79 @@ -894,15 +880,6 @@ - - - - 255 - 255 - 255 - - - @@ -914,15 +891,6 @@ - - - - 255 - 255 - 255 - - - @@ -934,15 +902,6 @@ - - - - 255 - 250 - 230 - - - @@ -991,6 +950,15 @@ + + + + 0 + 0 + 0 + + + @@ -1002,6 +970,15 @@ + + + + 0 + 0 + 0 + + + @@ -1013,6 +990,15 @@ + + + + 165 + 164 + 164 + + + @@ -1049,7 +1035,7 @@ 0 0 - 562 + 569 23 @@ -1197,8 +1183,8 @@ 0 - 449 - 562 + 434 + 569 20 @@ -1211,7 +1197,7 @@ 0 23 - 562 + 569 46 @@ -1792,10 +1778,6 @@ - easeButton1 - easeButton2 - easeButton3 - easeButton4 newPerDay minuteLimit questionLimit @@ -1805,6 +1787,10 @@ newCardScheduling revCardOrder delayLapsedCards + easeButton1 + easeButton2 + easeButton3 + easeButton4 startReviewingButton showAnswerButton help @@ -1822,12 +1808,12 @@ setShown(bool) - 87 - 219 + 54 + 202 - 211 - 344 + 53 + 250 diff --git a/designer/preferences.ui b/designer/preferences.ui index 59fa87715..5d99141b1 100644 --- a/designer/preferences.ui +++ b/designer/preferences.ui @@ -5,8 +5,8 @@ 0 0 - 322 - 417 + 320 + 399 @@ -26,8 +26,8 @@ 0 0 - 306 - 351 + 304 + 333 @@ -38,129 +38,43 @@ 6 - - - 6 + + + <h1>Language</h1> - - 0 + + false - - - - <h1>Language</h1> - - - false - - - - - - - - 300 - 0 - - - - - - - - - 0 - 0 - - - - Qt::TabFocus - - - <h1>Main Window</h1> - - - false - - - - - - - 0 - - - 6 - - - - - Interface font - - - - - - - Interface colour - - - - - - - - - - - - - - Background colour - - - - - - - - - - - - - - - - - 140 - 16777215 - - - - - - - - 300 - - - - - - - - - - - 0 - - - 6 - - - - + + + + + + + 300 + 0 + + + + + + + + + 0 + 0 + + + + Qt::TabFocus + + + <h1>Reviewing</h1> + + + false + + @@ -183,13 +97,6 @@ - - - - Show study options on startup - - - @@ -210,8 +117,8 @@ 0 0 - 306 - 351 + 304 + 333 @@ -398,8 +305,8 @@ 0 0 - 306 - 351 + 304 + 333 @@ -408,38 +315,38 @@ - - - - Simple toolbar - - - - <h1>Advanced settings</h1> + <h1>Advanced settings</h1>Some settings require a restart. - + Show timer - - + + - Show last card's question/answer + Show tray icon - - + + - Show last card's interval + Scroll down to the answer when showing answer + + + + + + + Add hidden char to text (fixes Thai on OSX) @@ -450,68 +357,36 @@ - - - - Tall buttons (for touchscreen) + + + + Qt::Vertical - - - - - - Show tray icon + + QSizePolicy::Fixed - - - - - - Scroll down to the answer when showing answer + + + 20 + 10 + - + - - - - Add hidden char to text (fixes Thai on OSX) - - - - + Alternative theme - - - - - - + + - Toolbar icon size + Show study options on startup - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - @@ -547,14 +422,9 @@ tabWidget interfaceLang label_2 - interfaceFamily - interfaceSize - interfaceColour - backgroundColour showDivider splitQA showEstimates - showStudyOptions saveWhenClosing saveAfterEvery saveAfterEveryNum @@ -564,17 +434,13 @@ syncPass syncOnOpen syncOnClose - simpleToolbar + alternativeTheme showTimer - showLastCardContent - showLastCardInterval + showStudyOptions showToolbar - tallButtons showTray scrollToAnswer addZeroSpace - alternativeTheme - toolbarIconSize buttonBox