From 518fcc34424236f244bbbf89ea79fd02ac5bd8c2 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Fri, 21 Nov 2008 20:05:15 +0900 Subject: [PATCH] inline edit, fix images, css, scroll to bottom, status, etc - new edit card inline mode - provide file:// url for images for webkit - look for the css file inside the anki dir - make add cards dialog more compact - launch clicked links in external window --- ankiqt/__init__.py | 2 +- ankiqt/ui/addcards.py | 7 ---- ankiqt/ui/facteditor.py | 4 +- ankiqt/ui/main.py | 59 +++++++++++++++++++++++++++- ankiqt/ui/view.py | 16 +++++--- designer/addcards.ui | 85 +++++++++++++++++++++------------------- designer/main.ui | 58 +++++++++++++++++++++------ icons.qrc | 1 + icons/edit-rename.png | Bin 0 -> 496 bytes 9 files changed, 164 insertions(+), 68 deletions(-) create mode 100644 icons/edit-rename.png diff --git a/ankiqt/__init__.py b/ankiqt/__init__.py index e3428f069..cd8f944d6 100644 --- a/ankiqt/__init__.py +++ b/ankiqt/__init__.py @@ -100,7 +100,7 @@ def run(): ui.dialogs.registerDialogs() mw = ui.main.AnkiQt(app, conf, args) try: - styleFile = open(opts.config + ".css") + styleFile = open(os.path.join(opts.config, "style.css")) mw.setStyleSheet(styleFile.read()) except (IOError, OSError): pass diff --git a/ankiqt/ui/addcards.py b/ankiqt/ui/addcards.py index 3c48d53d8..83fd61dba 100644 --- a/ankiqt/ui/addcards.py +++ b/ankiqt/ui/addcards.py @@ -62,13 +62,6 @@ class AddCards(QDialog): QDialogButtonBox.HelpRole) self.connect(self.helpButton, SIGNAL("clicked()"), self.helpRequested) - def setupStatus(self): - "Make the status background the same colour as the frame." - p = self.dialog.statusGroup.palette() - c = unicode(p.color(QPalette.Window).name()) - self.dialog.status.setStyleSheet( - "* { background: %s; color: #000000; }" % c) - def modelChanged(self, model): oldFact = self.editor.fact # create a new fact diff --git a/ankiqt/ui/facteditor.py b/ankiqt/ui/facteditor.py index 59ad7538d..cce1b0a63 100644 --- a/ankiqt/ui/facteditor.py +++ b/ankiqt/ui/facteditor.py @@ -49,7 +49,7 @@ class FactEditor(object): self.fields = {} # top level vbox self.fieldsBox = QVBoxLayout(self.widget) - self.fieldsBox.setMargin(5) + self.fieldsBox.setMargin(0) self.fieldsBox.setSpacing(3) # icons self.iconsBox = QHBoxLayout() @@ -110,7 +110,7 @@ class FactEditor(object): self.foregroundFrame.setAutoFillBackground(True) hbox = QHBoxLayout() hbox.addWidget(self.foregroundFrame) - hbox.setMargin(5) + hbox.setMargin(0) self.foreground.setLayout(hbox) self.iconsBox.addWidget(self.foreground) self.foreground.setStyle(self.plastiqueStyle) diff --git a/ankiqt/ui/main.py b/ankiqt/ui/main.py index e6797bf5e..069d8f205 100644 --- a/ankiqt/ui/main.py +++ b/ankiqt/ui/main.py @@ -4,6 +4,7 @@ from PyQt4.QtGui import * from PyQt4.QtCore import * +from PyQt4.QtWebKit import QWebPage import os, sys, re, types, gettext, stat, traceback import copy, shutil, time, glob @@ -54,6 +55,9 @@ class AnkiQt(QMainWindow): self.addView(self.bodyView) self.statusView = ui.status.StatusView(self) self.addView(self.statusView) + self.mainWin.welcomeText.hide() + self.mainWin.mainText.hide() + self.setupEditor() self.setupButtons() self.setupAnchors() self.setupToolbar() @@ -110,6 +114,7 @@ class AnkiQt(QMainWindow): # reset current card and load again self.currentCard = None self.lastCard = None + self.editor.deck = self.deck if self.deck: self.mainWin.menu_Lookup.setEnabled(True) self.enableDeckMenuItems() @@ -128,9 +133,11 @@ class AnkiQt(QMainWindow): self.lastState = getattr(self, "state", None) self.state = state self.updateTitleBar() - if 'state' != 'noDeck': + if 'state' != 'noDeck' and state != 'editCurrentFact': self.mainWin.welcomeText.hide() self.mainWin.mainText.show() + self.mainWin.buttonWidget.show() + self.mainWin.fieldsArea.hide() if state == "noDeck": self.mainWin.welcomeText.show() self.mainWin.mainText.hide() @@ -183,6 +190,14 @@ class AnkiQt(QMainWindow): self.resetButtons() self.showEaseButtons() self.enableCardMenuItems() + elif state == "editCurrentFact": + self.resetButtons() + self.showSaveEditorButton() + self.mainWin.mainText.hide() + self.mainWin.fieldsArea.show() + self.editor.setFact(self.currentCard.fact) + elif state == "saveEdit": + return self.moveToState("auto") self.updateViews(state) def keyPressEvent(self, evt): @@ -751,12 +766,19 @@ To upgrade an old deck, download Anki 0.9.8.7.""")) self.onAddCard() def setupAnchors(self): + # welcome self.anchorPrefixes = { 'welcome': self.onWelcomeAnchor, } self.connect(self.mainWin.welcomeText, SIGNAL("anchorClicked(QUrl)"), self.anchorClicked) + # main + self.mainWin.mainText.page().setLinkDelegationPolicy( + QWebPage.DelegateExternalLinks) + self.connect(self.mainWin.mainText, + SIGNAL("linkClicked(QUrl)"), + self.linkClicked) def anchorClicked(self, url): # prevent the link being handled @@ -769,6 +791,36 @@ To upgrade an old deck, download Anki 0.9.8.7.""")) # open in browser QDesktopServices.openUrl(QUrl(url)) + def linkClicked(self, url): + QDesktopServices.openUrl(QUrl(url)) + + # Edit current fact + ########################################################################## + + def setupEditor(self): + self.mainWin.fieldsArea.hide() + self.editor = ui.facteditor.FactEditor( + 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(_("Return (Esc)")) + 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 onFactValid(self, fact): + self.editFactButton.setEnabled(True) + + def onFactInvalid(self, fact): + self.editFactButton.setEnabled(False) + # Toolbar ########################################################################## @@ -783,6 +835,7 @@ To upgrade an old deck, download Anki 0.9.8.7.""")) mw.toolBar.hide() mw.toolBar = QToolBar(self) mw.toolBar.addAction(mw.actionAddcards) + mw.toolBar.addAction(mw.actionEditCurrent) mw.toolBar.addAction(mw.actionEditdeck) mw.toolBar.addAction(mw.actionRepeatAudio) mw.toolBar.addAction(mw.actionMarkCard) @@ -932,6 +985,9 @@ To upgrade an old deck, download Anki 0.9.8.7.""")) def onEditDeck(self): ui.dialogs.get("CardList", self) + def onEditCurrent(self): + self.moveToState("editCurrentFact") + def onDeckProperties(self): self.deckProperties = ui.deckproperties.DeckProperties(self) @@ -1213,6 +1269,7 @@ To upgrade an old deck, download Anki 0.9.8.7.""")) self.connect(m.actionDisplayProperties, s,self.onDisplayProperties) self.connect(m.actionAddcards, s, self.onAddCard) self.connect(m.actionEditdeck, s, self.onEditDeck) + self.connect(m.actionEditCurrent, s, self.onEditCurrent) self.connect(m.actionPreferences, s, self.onPrefs) self.connect(m.actionLookup_es, s, self.onLookupEdictSelection) self.connect(m.actionLookup_esk, s, self.onLookupEdictKanjiSelection) diff --git a/ankiqt/ui/view.py b/ankiqt/ui/view.py index 552c02462..35fce56bd 100644 --- a/ankiqt/ui/view.py +++ b/ankiqt/ui/view.py @@ -4,12 +4,11 @@ from PyQt4.QtGui import * from PyQt4.QtCore import * -from PyQt4.QtWebKit import QWebPage import anki, anki.utils from anki.sound import playFromText, stripSounds from anki.latex import renderLatex, stripLatex from anki.utils import stripHTML -import types, time +import types, time, re, os from ankiqt import ui # Views - define the way a user is prompted for questions, etc @@ -110,19 +109,24 @@ class View(object): # Question and answer ########################################################################## + def munge(self, txt): + txt = renderLatex(self.main.deck, txt) + txt = stripSounds(txt) + txt = re.sub( + 'img src="(.*?)"', 'img src="file://%s/\\1"' % os.getcwd(), txt) + return txt + def drawQuestion(self, nosound=False): "Show the question." q = self.main.currentCard.htmlQuestion() - q = renderLatex(self.main.deck, q) - self.write(stripSounds(q)) + self.write(self.munge(q)) if self.state != self.oldState and not nosound: playFromText(q) def drawAnswer(self): "Show the answer." a = self.main.currentCard.htmlAnswer() - a = renderLatex(self.main.deck, a) - self.write('' + stripSounds(a)) + self.write('' + self.munge(a)) if self.state != self.oldState: playFromText(a) diff --git a/designer/addcards.ui b/designer/addcards.ui index 98049344a..ccd260005 100644 --- a/designer/addcards.ui +++ b/designer/addcards.ui @@ -5,8 +5,8 @@ 0 0 - 505 - 367 + 509 + 381 @@ -21,15 +21,25 @@ - + 0 - + + 4 + + 0 + + + + Qt::Horizontal + + + @@ -41,53 +51,48 @@ 0 - 5 + 10 + + true + - Fields + + + + true - + + + false + - + 0 1 - - Status + + true + + + QFrame::NoFrame + + + Qt::ScrollBarAlwaysOff + + + Qt::ScrollBarAlwaysOff + + + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> +<html><head><meta name="qrichtext" content="1" /><style type="text/css"> +p, li { white-space: pre-wrap; } +</style></head><body style=" font-family:'Arial'; font-size:8pt; font-weight:400; font-style:normal;"> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"></p></body></html> - - - 0 - - - 0 - - - - - false - - - - 0 - 0 - - - - QFrame::NoFrame - - - Qt::ScrollBarAlwaysOff - - - Qt::ScrollBarAlwaysOff - - - - diff --git a/designer/main.ui b/designer/main.ui index cc1bb13d6..96a2cfad6 100644 --- a/designer/main.ui +++ b/designer/main.ui @@ -5,8 +5,8 @@ 0 0 - 532 - 442 + 454 + 504 @@ -27,8 +27,8 @@ 0 69 - 532 - 353 + 454 + 415 @@ -129,6 +129,28 @@ 5 + + + + + 7 + 2 + + + + true + + + + + + true + + + false + + + @@ -351,7 +373,7 @@ 0 0 - 532 + 454 23 @@ -376,6 +398,7 @@ + @@ -487,8 +510,8 @@ 0 - 422 - 532 + 484 + 454 20 @@ -501,7 +524,7 @@ 0 23 - 532 + 454 46 @@ -526,6 +549,7 @@ + @@ -617,7 +641,7 @@ &Add Items.. - Ctrl+A + Alt+Shift+A @@ -626,10 +650,10 @@ :/icons/view_text.png:/icons/view_text.png - &Edit Items.. + Ed&it All.. - Ctrl+E + Alt+Shift+I @@ -999,6 +1023,18 @@ &Get More Decks.. + + + + :/icons/edit-rename.png:/icons/edit-rename.png + + + &Edit Current.. + + + Alt+Shift+E + + diff --git a/icons.qrc b/icons.qrc index 20017ee5b..77e4a4a43 100644 --- a/icons.qrc +++ b/icons.qrc @@ -1,5 +1,6 @@ + icons/edit-rename.png icons/kblogger.png icons/chronometer.png icons/Anki_Card.png diff --git a/icons/edit-rename.png b/icons/edit-rename.png new file mode 100644 index 0000000000000000000000000000000000000000..5f089f5847d1ab3622a7f31a7e6fd1fc622c0967 GIT binary patch literal 496 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE3?yBabR7dy%*9TgAsieWw;%dH0CG7CJR*yM zqGce=SbMeU3{X(A#5JNMI6tkVJh3R1p}f3YFEcN@I61K(RWH9NefB#WDWIYi0X`wF z|Ns97GU*07J3HIKASorGq^!8Ax}u|_qi;g*lxdS^%$RZP*s|8v&0)nDql2X#L@`@^|YU-NWI=Y6& zW|lT~PA+bq@hKPG);9+N^|X1qIEGZ*dOOLG?~nrzOa9yLfJ4>|P5P!D>t zLoH%iH1n=)d2(iHd+OLYnzzghB literal 0 HcmV?d00001