save geometry of other windows, prevent deletion of shared models

This commit is contained in:
Damien Elmes 2008-10-12 02:54:19 +09:00
parent ec932d6f39
commit ea666975f9
7 changed files with 41 additions and 7 deletions

View file

@ -5,6 +5,7 @@ from PyQt4.QtGui import *
from PyQt4.QtCore import *
import ankiqt
from anki.utils import parseTags, joinTags
from ankiqt.ui.utils import saveGeom, restoreGeom
class ActiveTagsChooser(QDialog):
@ -16,7 +17,7 @@ class ActiveTagsChooser(QDialog):
self.connect(self.dialog.buttonBox, SIGNAL("helpRequested()"),
self.onHelp)
self.rebuildTagList()
restoreGeom(self, "activeTags")
def rebuildTagList(self):
self.tags = self.parent.deck.allTags()
@ -47,6 +48,7 @@ class ActiveTagsChooser(QDialog):
self.parent.deck.suspended = joinTags(suspended + ["Suspended"])
self.parent.deck.setModified()
self.parent.reset()
saveGeom(self, "activeTags")
QDialog.accept(self)
def onHelp(self):

View file

@ -9,6 +9,7 @@ import anki
from anki.facts import Fact
from anki.errors import *
from anki.utils import stripHTML
from ankiqt.ui.utils import saveGeom, restoreGeom
from ankiqt import ui
class AddCards(QDialog):
@ -25,6 +26,7 @@ class AddCards(QDialog):
self.setupStatus()
self.modelChanged(self.parent.deck.currentModel)
self.addedItems = 0
restoreGeom(self, "add")
self.show()
ui.dialogs.open("AddCards", self)
@ -117,6 +119,7 @@ class AddCards(QDialog):
ui.dialogs.close("AddCards")
self.parent.deck.s.flush()
self.parent.moveToState("auto")
saveGeom(self, "add")
return True
else:
return False

View file

@ -12,6 +12,7 @@ from anki.cards import cardsTable, Card
from anki.facts import factsTable, fieldsTable, Fact
from anki.utils import fmtTimeSpan, parseTags, findTag, addTags, deleteTags, \
stripHTML
from ankiqt.ui.utils import saveGeom, restoreGeom
from anki.errors import *
from anki.db import *
@ -249,6 +250,7 @@ class EditDeck(QDialog):
ui.dialogs.open("CardList", self)
self.drawTags()
self.updateFilterLabel()
restoreGeom(self, "editor")
self.show()
self.selectLastCard()
@ -638,4 +640,5 @@ where id in (%s)""" % ",".join([
QDialog.accept(self)
def reject(self):
saveGeom(self, "editor")
self.accept()

View file

@ -143,6 +143,12 @@ class DeckProperties(QDialog):
ui.utils.showWarning(_("Please add another model first."),
parent=self)
return
if self.d.s.scalar("select 1 from sources where id=:id",
id=model.source):
ui.utils.showWarning(_("This model is used by deck source:\n"
"%s\nYou will need to remove the source "
"first.") % hexifyID(model.source))
return
count = self.d.modelUseCount(model)
if count:
if not ui.utils.askUser(

View file

@ -6,12 +6,13 @@ from PyQt4.QtCore import *
import sys
import anki, anki.graphs, anki.utils
from ankiqt import ui
from ankiqt.ui.utils import saveGeom, restoreGeom
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib import rc
rc('font', **{'sans-serif': 'Arial',
'serif': 'Arial',
'size': 20.0})
'size': 14.0})
rc('legend', fontsize=14.0)
class AnkiFigureCanvas (FigureCanvas):
@ -29,7 +30,7 @@ class AnkiFigureCanvas (FigureCanvas):
def sizeHint(self):
w, h = self.get_width_height()
return QSize(w, h)
return QSize(w+30, h+30)
def minimumSizeHint(self):
return QSize(10, 10)
@ -123,6 +124,7 @@ class IntervalGraph(QDialog):
self.setAttribute(Qt.WA_DeleteOnClose)
def reject(self):
saveGeom(self, "graphs")
ui.dialogs.close("Graphs")
QDialog.reject(self)
@ -130,11 +132,14 @@ def intervalGraph(parent, deck):
dg = anki.graphs.DeckGraphs(deck)
# dialog setup
d = IntervalGraph(parent)
d.setWindowTitle(_("Deck graphs"))
if sys.platform.startswith("darwin"):
d.setMinimumSize(740, 680)
d.setWindowTitle(_("Deck Graphs"))
if parent.config.get('graphsGeom'):
restoreGeom(d, "graphs")
else:
d.setMinimumSize(670, 715)
if sys.platform.startswith("darwin"):
d.setMinimumSize(740, 680)
else:
d.setMinimumSize(670, 715)
scroll = QScrollArea(d)
topBox = QVBoxLayout(d)
topBox.addWidget(scroll)

View file

@ -65,3 +65,12 @@ def getSaveFile(parent, title, dir, key, ext):
parent):
return None
return file
def saveGeom(widget, key):
key += "Geom"
ankiqt.mw.config[key] = widget.saveGeometry()
def restoreGeom(widget, key):
key += "Geom"
if ankiqt.mw.config.get(key):
widget.restoreGeometry(ankiqt.mw.config[key])

View file

@ -86,6 +86,9 @@ p, li { white-space: pre-wrap; }
<property name="text" >
<string>&amp;Add Source</string>
</property>
<property name="autoDefault" >
<bool>false</bool>
</property>
</widget>
</item>
<item>
@ -93,6 +96,9 @@ p, li { white-space: pre-wrap; }
<property name="text" >
<string>&amp;Delete Source</string>
</property>
<property name="autoDefault" >
<bool>false</bool>
</property>
</widget>
</item>
</layout>