edit current, hide 'close' button on osx

This commit is contained in:
Damien Elmes 2011-04-16 03:44:30 +09:00
parent 61cdea4865
commit 9da0a83735
15 changed files with 145 additions and 67 deletions

View file

@ -19,23 +19,27 @@ import aqt.editor, aqt.modelchooser
class AddCards(QDialog): class AddCards(QDialog):
def __init__(self, mw): def __init__(self, mw):
windParent = None
QDialog.__init__(self, mw) QDialog.__init__(self, mw)
self.mw = mw self.mw = mw
self.form = aqt.forms.addcards.Ui_Dialog() self.form = aqt.forms.addcards.Ui_Dialog()
self.form.setupUi(self) self.form.setupUi(self)
self.setWindowModality(Qt.WindowModal) #self.setWindowModality(Qt.WindowModal)
self.setWindowTitle(_("Add")) self.setWindowTitle(_("Add"))
self.setMinimumHeight(400)
self.setMinimumWidth(500)
self.setupChooser() self.setupChooser()
self.setupEditor() self.setupEditor()
self.setupButtons() self.setupButtons()
self.onReset() self.onReset()
self.history = [] self.history = []
self.forceClose = False self.forceClose = False
restoreGeom(self, "add") #restoreGeom(self, "add")
addHook('reset', self.onReset) addHook('reset', self.onReset)
self.setupNewFact() self.setupNewFact()
self.show() self.open()
def focusOutEvent(self, evt):
print "focus lost"
def setupEditor(self): def setupEditor(self):
self.editor = aqt.editor.Editor(self.mw, self.form.fieldsArea) self.editor = aqt.editor.Editor(self.mw, self.form.fieldsArea)

View file

@ -5,6 +5,7 @@ from PyQt4.QtGui import *
from PyQt4.QtCore import * from PyQt4.QtCore import *
import sys, re import sys, re
import aqt import aqt
from aqt.utils import maybeHideClose
class DeckOptions(QDialog): class DeckOptions(QDialog):
@ -22,6 +23,7 @@ class DeckOptions(QDialog):
self.form.buttonBox.button(QDialogButtonBox.Close).setAutoDefault(False) self.form.buttonBox.button(QDialogButtonBox.Close).setAutoDefault(False)
self.connect(self.form.buttonBox, SIGNAL("helpRequested()"), self.connect(self.form.buttonBox, SIGNAL("helpRequested()"),
self.helpRequested) self.helpRequested)
maybeHideClose(self.form.buttonBox)
# syncing # syncing
self.form.doSync.setChecked(self.d.syncingEnabled()) self.form.doSync.setChecked(self.d.syncingEnabled())
self.form.mediaURL.setText(self.d.conf['mediaURL']) self.form.mediaURL.setText(self.d.conf['mediaURL'])

View file

@ -2,44 +2,37 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html # License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
# get a fact for testing from PyQt4.QtGui import *
#fact = self.mw.deck.getFact(3951) from PyQt4.QtCore import *
#self.editor.setFact(fact) import aqt.editor
from aqt.utils import saveGeom, restoreGeom
class EditCurrent(object): class EditCurrent(QDialog):
def __init__(self, mw): def __init__(self, mw):
QDialog.__init__(self, mw)
self.mw = mw self.mw = mw
self.form = aqt.forms.editcurrent.Ui_Dialog()
self.form.setupUi(self)
self.setWindowModality(Qt.WindowModal)
self.setWindowTitle(_("Edit Current"))
self.setMinimumHeight(400)
self.setMinimumWidth(500)
self.connect(self.form.buttonBox.button(QDialogButtonBox.Save),
SIGNAL("clicked()"),
self.onSave)
self.connect(self,
SIGNAL("rejected()"),
self.onSave)
self.editor = aqt.editor.Editor(self.mw, self.form.fieldsArea)
self.editor.setFact(self.mw.reviewer.card.fact())
restoreGeom(self, "editcurrent")
self.show()
def _editCurrentState(self, oldState): def onSave(self):
if self.lastState == "editCurrentFact": self.editor.saveNow()
return self.moveToState("saveEdit") self.editor.setFact(None)
self.form.actionRepeatAudio.setEnabled(False) self.mw.reviewer.card.load()
self.deck.db.flush() self.mw.reviewer.showQuestion()
self.showEditor() saveGeom(self, "editcurrent")
self.close()
def _saveEditState(self, oldState):
self.form.actionRepeatAudio.setEnabled(True)
self.editor.saveFieldsNow()
self.form.buttonStack.show()
return self.reset()
# Edit current fact
##########################################################################
def setupEditor(self):
print "setupeditor"
return
self.editor = aqt.facteditor.FactEditor(
self, self.form.fieldsArea, self.deck)
self.editor.clayout.setShortcut("")
self.editor.resetOnEdit = False
# editor
self.connect(self.form.saveEditorButton, SIGNAL("clicked()"),
lambda: self.moveToState("saveEdit"))
def showEditor(self):
self.form.buttonStack.hide()
self.switchToEditScreen()
self.editor.setFact(self.currentCard.fact)
self.editor.card = self.currentCard

View file

@ -5,7 +5,7 @@
from PyQt4.QtCore import * from PyQt4.QtCore import *
from PyQt4.QtGui import * from PyQt4.QtGui import *
import aqt import aqt
from aqt.utils import showInfo, getOnlyText from aqt.utils import showInfo, getOnlyText, maybeHideClose
COLNAME = 0 COLNAME = 0
COLOPTS = 1 COLOPTS = 1
@ -78,6 +78,7 @@ class Groups(QDialog):
self.connect(self.form.buttonBox, self.connect(self.form.buttonBox,
SIGNAL("helpRequested()"), SIGNAL("helpRequested()"),
lambda: aqt.openHelp("Groups")) lambda: aqt.openHelp("Groups"))
maybeHideClose(box)
def onSelectAll(self): def onSelectAll(self):
for i in self.items: for i in self.items:

View file

@ -81,7 +81,6 @@ class AnkiQt(QMainWindow):
self.setupDeckBrowser() self.setupDeckBrowser()
self.setupOverview() self.setupOverview()
self.setupReviewer() self.setupReviewer()
self.setupEditor()
# State machine # State machine
########################################################################## ##########################################################################
@ -254,10 +253,6 @@ title="%s">%s</button>''' % (
from aqt.reviewer import Reviewer from aqt.reviewer import Reviewer
self.reviewer = Reviewer(self) self.reviewer = Reviewer(self)
def setupEditor(self):
from aqt.editcurrent import EditCurrent
self.editor = EditCurrent(self)
# Upgrading from previous versions # Upgrading from previous versions
########################################################################## ##########################################################################
@ -671,7 +666,8 @@ Debug info:\n%s""") % traceback.format_exc(), help="DeckErrors")
aqt.dialogs.open("Browser", self) aqt.dialogs.open("Browser", self)
def onEditCurrent(self): def onEditCurrent(self):
self.moveToState("editCurrentFact") from aqt.editcurrent import EditCurrent
EditCurrent(self)
def setupCardStats(self): def setupCardStats(self):
import aqt.stats import aqt.stats

View file

@ -3,7 +3,7 @@
from PyQt4.QtGui import * from PyQt4.QtGui import *
from PyQt4.QtCore import * from PyQt4.QtCore import *
from aqt.utils import showInfo, askUser, getText from aqt.utils import showInfo, askUser, getText, maybeHideClose
import aqt.modelchooser, aqt.clayout import aqt.modelchooser, aqt.clayout
class Models(QDialog): class Models(QDialog):
@ -17,6 +17,7 @@ class Models(QDialog):
self.form.setupUi(self) self.form.setupUi(self)
self.connect(self.form.buttonBox, SIGNAL("helpRequested()"), self.connect(self.form.buttonBox, SIGNAL("helpRequested()"),
lambda: aqt.openHelp("Models")) lambda: aqt.openHelp("Models"))
maybeHideClose(self.form.buttonBox)
self.setupModels() self.setupModels()
self.exec_() self.exec_()

View file

@ -138,12 +138,12 @@ $(".ansbut").focus();
def _initWeb(self): def _initWeb(self):
self.web.stdHtml(self._revHtml % dict( self.web.stdHtml(self._revHtml % dict(
showans=_("Show Answer")), self._styles(), showans=_("Show Answer")), self._styles(),
loadCB=lambda x: self._showQuestion()) loadCB=lambda x: self.showQuestion())
# Showing the question (and preparing answer) # Showing the question (and preparing answer)
########################################################################## ##########################################################################
def _showQuestion(self): def showQuestion(self):
# fixme: timeboxing # fixme: timeboxing
# fixme: timer # fixme: timer
self.state = "question" self.state = "question"

View file

@ -6,7 +6,7 @@ from PyQt4.QtGui import *
from PyQt4.QtCore import * from PyQt4.QtCore import *
import os, tempfile import os, tempfile
from aqt.webview import AnkiWebView from aqt.webview import AnkiWebView
from aqt.utils import saveGeom, restoreGeom from aqt.utils import saveGeom, restoreGeom, maybeHideClose
from anki.hooks import addHook from anki.hooks import addHook
import aqt import aqt
@ -88,6 +88,7 @@ class DeckStats(QDialog):
c(f.year, s, lambda: self.changePeriod(1)) c(f.year, s, lambda: self.changePeriod(1))
c(f.life, s, lambda: self.changePeriod(2)) c(f.life, s, lambda: self.changePeriod(2))
c(f.web, SIGNAL("loadFinished(bool)"), self.loadFin) c(f.web, SIGNAL("loadFinished(bool)"), self.loadFin)
maybeHideClose(self.form.buttonBox)
self.refresh() self.refresh()
self.exec_() self.exec_()

View file

@ -4,6 +4,7 @@
from PyQt4.QtCore import * from PyQt4.QtCore import *
from PyQt4.QtGui import * from PyQt4.QtGui import *
from aqt.utils import maybeHideClose
import datetime, time, aqt import datetime, time, aqt
class StudyOptions(QDialog): class StudyOptions(QDialog):
@ -14,9 +15,6 @@ class StudyOptions(QDialog):
self.form.setupUi(self) self.form.setupUi(self)
self.setup() self.setup()
self.load() self.load()
self.connect(self.form.buttonBox,
SIGNAL("helpRequested()"),
lambda: aqt.openHelp("StudyOptions"))
self.exec_() self.exec_()
def setup(self): def setup(self):
@ -27,6 +25,10 @@ class StudyOptions(QDialog):
0, QStringList(c.newCardSchedulingLabels().values())) 0, QStringList(c.newCardSchedulingLabels().values()))
self.form.revOrder.insertItems( self.form.revOrder.insertItems(
0, QStringList(c.revCardOrderLabels().values())) 0, QStringList(c.revCardOrderLabels().values()))
self.connect(self.form.buttonBox,
SIGNAL("helpRequested()"),
lambda: aqt.openHelp("StudyOptions"))
maybeHideClose(self.form.buttonBox)
def load(self): def load(self):
f = self.form f = self.form

View file

@ -308,5 +308,11 @@ def shortcut(key):
return re.sub("(?i)ctrl", "Command", key) return re.sub("(?i)ctrl", "Command", key)
return key return key
def maybeHideClose(bbox):
if isMac:
b = bbox.button(QDialogButtonBox.Close)
if b:
bbox.removeButton(b)
isMac = sys.platform.startswith("darwin") isMac = sys.platform.startswith("darwin")
isWin = sys.platform.startswith("win32") isWin = sys.platform.startswith("win32")

View file

@ -6,8 +6,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>743</width> <width>453</width>
<height>727</height> <height>366</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">

73
designer/editcurrent.ui Normal file
View file

@ -0,0 +1,73 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Dialog</class>
<widget class="QDialog" name="Dialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
<number>3</number>
</property>
<property name="margin">
<number>12</number>
</property>
<item>
<widget class="QWidget" name="fieldsArea" native="true"/>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Save</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>Dialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>Dialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View file

@ -96,20 +96,20 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="2">
<widget class="QPushButton" name="opts">
<property name="text">
<string>&amp;Options...</string>
</property>
</widget>
</item>
<item row="0" column="3" rowspan="2"> <item row="0" column="3" rowspan="2">
<widget class="QDialogButtonBox" name="buttonBox"> <widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation"> <property name="orientation">
<enum>Qt::Vertical</enum> <enum>Qt::Vertical</enum>
</property> </property>
<property name="standardButtons"> <property name="standardButtons">
<set>QDialogButtonBox::Help|QDialogButtonBox::Ok</set> <set>QDialogButtonBox::Close|QDialogButtonBox::Help</set>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QPushButton" name="opts">
<property name="text">
<string>&amp;Options...</string>
</property> </property>
</widget> </widget>
</item> </item>
@ -123,7 +123,6 @@
<tabstop>selNone</tabstop> <tabstop>selNone</tabstop>
<tabstop>rename</tabstop> <tabstop>rename</tabstop>
<tabstop>delete_2</tabstop> <tabstop>delete_2</tabstop>
<tabstop>opts</tabstop>
<tabstop>buttonBox</tabstop> <tabstop>buttonBox</tabstop>
</tabstops> </tabstops>
<resources/> <resources/>

View file

@ -115,7 +115,7 @@
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
<property name="standardButtons"> <property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> <set>QDialogButtonBox::Close</set>
</property> </property>
</widget> </widget>
</item> </item>

View file

@ -143,7 +143,7 @@
<enum>Qt::Vertical</enum> <enum>Qt::Vertical</enum>
</property> </property>
<property name="standardButtons"> <property name="standardButtons">
<set>QDialogButtonBox::Help|QDialogButtonBox::Ok</set> <set>QDialogButtonBox::Close|QDialogButtonBox::Help</set>
</property> </property>
</widget> </widget>
</item> </item>