background colour per card, tweak ans buttons

This commit is contained in:
Damien Elmes 2009-01-31 02:21:08 +09:00
parent 85cd67fab4
commit 4945313bfa
5 changed files with 257 additions and 96 deletions

View file

@ -68,7 +68,7 @@ class DisplayProperties(QDialog):
self.main.config['showFontPreview'] = True
else:
self.dialog.previewGroup.hide()
self.setFixedWidth(340)
self.setFixedWidth(380)
self.main.config['showFontPreview'] = False
def setupCards(self):
@ -86,10 +86,18 @@ class DisplayProperties(QDialog):
w.setStyle(self.plastiqueStyle)
self.connect(w,
SIGNAL("clicked()"),
lambda w=w, t=type: self.chooseColour(w, t))
lambda w=w: self.chooseColour(w))
self.connect(self.cwidget("Align", type),
SIGNAL("activated(int)"),
self.saveCard)
# background colour
self.connect(self.dialog.backgroundColour,
SIGNAL("clicked()"),
lambda w=self.dialog.backgroundColour:\
self.chooseColour(w))
if self.plastiqueStyle:
self.dialog.backgroundColour.setStyle(self.plastiqueStyle)
self.drawCards()
def drawCards(self):
@ -119,6 +127,8 @@ class DisplayProperties(QDialog):
getattr(card, type + "FontColour"))))
self.cwidget("Align", type).setCurrentIndex(
getattr(card, type + "Align"))
self.dialog.backgroundColour.setPalette(QPalette(QColor(
getattr(card, "lastFontColour"))))
self.card = card
def saveCard(self):
@ -136,6 +146,8 @@ class DisplayProperties(QDialog):
setattr(self.card, type + "FontColour", unicode(c.name()))
self.card.model.setModified()
self.deck.setModified()
setattr(self.card, "lastFontColour", unicode(
self.dialog.backgroundColour.palette().window().color().name()))
self.drawQuestionAndAnswer()
def cwidget(self, name, type):
@ -167,7 +179,7 @@ class DisplayProperties(QDialog):
w.setStyle(self.plastiqueStyle)
self.connect(w,
SIGNAL("clicked()"),
lambda w=w, t=type: self.chooseColour(w, t))
lambda w=w: self.chooseColour(w))
self.currentField = None
self.drawFields()
@ -260,7 +272,7 @@ class DisplayProperties(QDialog):
self.deck.flushMod()
self.drawQuestionAndAnswer()
def chooseColour(self, button, type):
def chooseColour(self, button):
new = QColorDialog.getColor(button.palette().window().color(), self)
if new.isValid():
button.setPalette(QPalette(new))
@ -275,14 +287,16 @@ class DisplayProperties(QDialog):
f[field.name] = field.name
f.model = self.model
c = Card(f, self.card)
t = "<br><center>" + c.htmlQuestion() + "</center>"
t = "<body><br><center>" + c.htmlQuestion() + "</center></body>"
bg = "body { background-color: %s; }\n" % self.card.lastFontColour
self.dialog.question.setText(
"<style>\n" + self.deck.rebuildCSS() + "</style>\n" + t)
t = "<br><center>" + c.htmlAnswer() + "</center>"
"<style>\n" + bg + self.deck.rebuildCSS() + "</style>\n" + t)
t = "<body><br><center>" + c.htmlAnswer() + "</center></body>"
self.dialog.answer.setText(
"<style>\n" + self.deck.rebuildCSS() + "</style>\n" + t)
"<style>\n" + bg + self.deck.rebuildCSS() + "</style>\n" + t)
self.main.updateViews(self.main.state)
def reject(self):
ui.dialogs.close("DisplayProperties")
QDialog.reject(self)

View file

@ -437,12 +437,7 @@ new:
##########################################################################
def setupButtons(self):
if sys.platform.startswith("darwin"):
self.easeButtonHeight = 35
else:
self.easeButtonHeight = 25
# ask
self.mainWin.showAnswerButton.setFixedHeight(self.easeButtonHeight)
self.connect(self.mainWin.showAnswerButton, SIGNAL("clicked()"),
lambda: self.moveToState("showAnswer"))
# answer

View file

@ -64,10 +64,12 @@ class View(object):
if self.haveTop:
self.drawTopSection()
if self.state == "showQuestion":
self.setBackground()
self.drawQuestion()
if self.drawRule:
self.write("<hr>")
elif self.state == "showAnswer":
self.setBackground()
if not self.main.currentCard.cardModel.questionInAnswer:
self.drawQuestion(nosound=True)
if self.drawRule:
@ -92,6 +94,10 @@ class View(object):
self.body.setHtml("")
self.buffer = ""
def setBackground(self):
col = self.main.currentCard.cardModel.lastFontColour
self.write("<style>html { background: %s;}</style>" % col)
# Font properties & output
##########################################################################
@ -131,7 +137,7 @@ class View(object):
self.write(self.center(self.mungeQA(self.main.deck, q), height))
if self.state != self.oldState and not nosound:
playFromText(q)
def correct(self, a, b):
if b == "":
return "";
@ -144,12 +150,12 @@ class View(object):
passedCharColour, sz)
bad = "background: %s; color: #000; font-size: %dpx;" % (
failedCharColour, sz)
for tag, i1, i2, j1, j2 in s.get_opcodes():
if tag == "equal":
ret += ("<span style='%s'>%s</span>" % (ok, b[i1:i2]))
elif tag == "replace":
ret += ("<span style='%s'>%s</span>"
ret += ("<span style='%s'>%s</span>"
% (bad, b[i1:i2] + (" " * ((j2 - j1) - (i2 - i1)))))
elif tag == "delete":
ret += ("<span style='%s'>%s</span>" % (bad, b[i1:i2]))
@ -157,7 +163,6 @@ class View(object):
ret += ("<span style='%s'>%s</span>" % (bad, " " * (j2 - j1)))
return ret
def drawAnswer(self):
"Show the answer."
a = self.main.currentCard.htmlAnswer()
@ -171,7 +176,7 @@ class View(object):
given = unicode(self.main.typeAnswerField.text())
res = self.correct(cor, given)
a = res + "<br>" + a
self.write(self.center('<span id=answer />'
self.write(self.center('<span id=answer />'
+ self.mungeQA(self.main.deck, a)))
if self.state != self.oldState:
playFromText(a)
@ -242,7 +247,7 @@ class View(object):
##########################################################################
def drawWelcomeMessage(self):
self.main.mainWin.welcomeText.setText(_("""
self.main.mainWin.welcomeText.setText(_("""\
<h1>Welcome to Anki!</h1>
<p>
<table>

View file

@ -5,8 +5,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>763</width>
<height>399</height>
<width>818</width>
<height>427</height>
</rect>
</property>
<property name="sizePolicy" >
@ -45,6 +45,18 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize" >
<size>
<width>360</width>
<height>0</height>
</size>
</property>
<property name="maximumSize" >
<size>
<width>360</width>
<height>16777215</height>
</size>
</property>
<property name="frameShape" >
<enum>QFrame::NoFrame</enum>
</property>
@ -84,7 +96,7 @@
<item>
<widget class="QTabWidget" name="tabWidget" >
<property name="sizePolicy" >
<sizepolicy vsizetype="Expanding" hsizetype="Preferred" >
<sizepolicy vsizetype="Expanding" hsizetype="Expanding" >
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
@ -97,8 +109,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>297</width>
<height>289</height>
<width>348</width>
<height>317</height>
</rect>
</property>
<attribute name="title" >
@ -250,20 +262,37 @@
</widget>
</item>
<item row="8" column="0" >
<spacer name="verticalSpacer" >
<property name="orientation" >
<enum>Qt::Vertical</enum>
<widget class="QLabel" name="label_5" >
<property name="text" >
<string>Background colour</string>
</property>
<property name="sizeHint" stdset="0" >
<size>
<width>20</width>
<height>40</height>
</size>
</widget>
</item>
<item row="8" column="1" >
<widget class="QPushButton" name="backgroundColour" >
<property name="text" >
<string/>
</property>
</spacer>
<property name="autoDefault" >
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer" >
<property name="orientation" >
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0" >
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_2" >
@ -271,8 +300,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>297</width>
<height>289</height>
<width>960</width>
<height>480</height>
</rect>
</property>
<attribute name="title" >
@ -558,12 +587,6 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize" >
<size>
<width>400</width>
<height>0</height>
</size>
</property>
<property name="readOnly" >
<bool>true</bool>
</property>

View file

@ -6,7 +6,7 @@
<x>0</x>
<y>0</y>
<width>699</width>
<height>433</height>
<height>446</height>
</rect>
</property>
<property name="sizePolicy" >
@ -23,6 +23,14 @@
<normaloff>:/icons/anki.png</normaloff>:/icons/anki.png</iconset>
</property>
<widget class="QWidget" name="centralwidget" >
<property name="geometry" >
<rect>
<x>0</x>
<y>69</y>
<width>699</width>
<height>357</height>
</rect>
</property>
<property name="sizePolicy" >
<sizepolicy vsizetype="Expanding" hsizetype="Expanding" >
<horstretch>1</horstretch>
@ -115,43 +123,44 @@
<enum>QFrame::Raised</enum>
</property>
<layout class="QGridLayout" name="gridLayout" >
<property name="leftMargin" >
<number>4</number>
</property>
<property name="topMargin" >
<property name="margin" >
<number>0</number>
</property>
<property name="rightMargin" >
<number>4</number>
</property>
<property name="bottomMargin" >
<number>6</number>
</property>
<property name="spacing" >
<number>0</number>
</property>
<item row="1" column="0" >
<widget class="QStackedWidget" name="buttonStack" >
<property name="sizePolicy" >
<sizepolicy vsizetype="Preferred" hsizetype="Preferred" >
<horstretch>0</horstretch>
<verstretch>1</verstretch>
</sizepolicy>
</property>
<property name="currentIndex" >
<number>5</number>
</property>
<widget class="QWidget" name="page1" >
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>422</width>
<height>59</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout" >
<item>
<spacer name="verticalSpacer" >
<property name="orientation" >
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0" >
<size>
<width>20</width>
<height>1</height>
</size>
</property>
</spacer>
</item>
<property name="margin" >
<number>4</number>
</property>
<item>
<widget class="QPushButton" name="showAnswerButton" >
<property name="sizePolicy" >
<sizepolicy vsizetype="Expanding" hsizetype="Minimum" >
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize" >
<size>
<width>0</width>
@ -169,27 +178,29 @@
</layout>
</widget>
<widget class="QWidget" name="page2" >
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>422</width>
<height>53</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3" >
<property name="spacing" >
<number>0</number>
</property>
<property name="leftMargin" >
<number>0</number>
</property>
<property name="topMargin" >
<number>0</number>
<number>4</number>
</property>
<property name="rightMargin" >
<number>0</number>
</property>
<property name="bottomMargin" >
<number>6</number>
<number>4</number>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout" >
<property name="spacing" >
<number>0</number>
</property>
<item>
<spacer name="horizontalSpacer" >
<property name="orientation" >
@ -205,12 +216,22 @@
</item>
<item>
<layout class="QGridLayout" name="gridLayout_2" >
<property name="horizontalSpacing" >
<number>6</number>
</property>
<property name="verticalSpacing" >
<number>0</number>
</property>
<item row="0" column="2" >
<spacer name="verticalSpacer_7" >
<property name="orientation" >
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0" >
<size>
<width>55</width>
<height>13</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="0" >
<widget class="QLabel" name="easeLabel1" >
<property name="text" >
@ -291,19 +312,6 @@
</property>
</widget>
</item>
<item row="0" column="2" >
<spacer name="verticalSpacer_7" >
<property name="orientation" >
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0" >
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
@ -324,6 +332,14 @@
</layout>
</widget>
<widget class="QWidget" name="page3" >
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>422</width>
<height>53</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_4" >
<item>
<spacer name="verticalSpacer_2" >
@ -351,6 +367,14 @@
</layout>
</widget>
<widget class="QWidget" name="page4" >
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>422</width>
<height>53</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_6" >
<item>
<spacer name="verticalSpacer_5" >
@ -385,6 +409,14 @@
</layout>
</widget>
<widget class="QWidget" name="page5" >
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>422</width>
<height>53</height>
</rect>
</property>
<layout class="QVBoxLayout" name="typeAnswerLayout" >
<item>
<spacer name="verticalSpacer_6" >
@ -404,23 +436,52 @@
</item>
</layout>
</widget>
<widget class="QWidget" name="page" />
<widget class="QWidget" name="page" >
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>422</width>
<height>53</height>
</rect>
</property>
</widget>
</widget>
</item>
<item row="0" column="0" >
<widget class="QStackedWidget" name="mainStack" >
<property name="sizePolicy" >
<sizepolicy vsizetype="Expanding" hsizetype="Expanding" >
<sizepolicy vsizetype="Preferred" hsizetype="Expanding" >
<horstretch>0</horstretch>
<verstretch>99</verstretch>
<verstretch>100</verstretch>
</sizepolicy>
</property>
<property name="currentIndex" >
<number>0</number>
<number>4</number>
</property>
<widget class="QWidget" name="blankPage" />
<widget class="QWidget" name="blankPage" >
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>422</width>
<height>304</height>
</rect>
</property>
</widget>
<widget class="QWidget" name="welcomePage" >
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>422</width>
<height>304</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_5" >
<property name="margin" >
<number>6</number>
</property>
<item>
<widget class="QTextBrowser" name="welcomeText" >
<property name="focusPolicy" >
@ -434,6 +495,14 @@
</layout>
</widget>
<widget class="QWidget" name="editPage" >
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>422</width>
<height>304</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2" >
<property name="spacing" >
<number>0</number>
@ -447,6 +516,14 @@
</layout>
</widget>
<widget class="QWidget" name="optionsPage" >
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>422</width>
<height>304</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_3" >
<property name="verticalSpacing" >
<number>0</number>
@ -749,16 +826,46 @@
</layout>
</widget>
<widget class="QWidget" name="congratsPage" >
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>422</width>
<height>304</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_9" >
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3" >
<item>
<layout class="QVBoxLayout" name="verticalLayout_10" >
<property name="leftMargin" >
<number>6</number>
</property>
<item>
<spacer name="verticalSpacer_10" >
<property name="orientation" >
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType" >
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0" >
<size>
<width>20</width>
<height>10</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="congratsLabel" >
<property name="text" >
<string>xxx</string>
</property>
<property name="margin" >
<number>0</number>
</property>
</widget>
</item>
<item>
@ -1029,7 +1136,7 @@
<x>0</x>
<y>0</y>
<width>699</width>
<height>25</height>
<height>23</height>
</rect>
</property>
<widget class="QMenu" name="menuHelp" >
@ -1172,11 +1279,28 @@
<addaction name="menu_Settings" />
<addaction name="menuHelp" />
</widget>
<widget class="QStatusBar" name="statusbar" />
<widget class="QStatusBar" name="statusbar" >
<property name="geometry" >
<rect>
<x>0</x>
<y>426</y>
<width>699</width>
<height>20</height>
</rect>
</property>
</widget>
<widget class="QToolBar" name="toolBar" >
<property name="enabled" >
<bool>true</bool>
</property>
<property name="geometry" >
<rect>
<x>0</x>
<y>23</y>
<width>699</width>
<height>46</height>
</rect>
</property>
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>