From 6459ed6396b1ae150ef4f52667b4b5da8022b47f Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Thu, 31 Mar 2011 20:49:21 +0900 Subject: [PATCH] move models from deckprops into separate models screen w/ card templates --- aqt/clayout.py | 10 +- aqt/deckopts.py | 74 ------- aqt/{groupman.py => groups.py} | 6 +- aqt/main.py | 13 +- aqt/modelproperties.py | 302 --------------------------- aqt/models.py | 307 ++++++++++++++++++++++++++++ designer/deckopts.ui | 88 ++------ designer/{groupman.ui => groups.ui} | 0 designer/main.ui | 9 + designer/modelproperties.ui | 218 -------------------- designer/models.ui | 294 ++++++++++++++++++++++++++ 11 files changed, 641 insertions(+), 680 deletions(-) rename aqt/{groupman.py => groups.py} (98%) delete mode 100644 aqt/modelproperties.py create mode 100644 aqt/models.py rename designer/{groupman.ui => groups.ui} (100%) delete mode 100644 designer/modelproperties.ui create mode 100644 designer/models.ui diff --git a/aqt/clayout.py b/aqt/clayout.py index aee2f1c4d..4d8464b46 100644 --- a/aqt/clayout.py +++ b/aqt/clayout.py @@ -39,6 +39,8 @@ class CardLayout(QDialog): self.onHelp) self.setupCards() self.setupFields() + self.form.buttonBox.button(QDialogButtonBox.Help).setAutoDefault(False) + self.form.buttonBox.button(QDialogButtonBox.Close).setAutoDefault(False) restoreSplitter(self.form.splitter, "clayout") restoreGeom(self, "CardLayout") self.reload() @@ -62,12 +64,12 @@ class CardLayout(QDialog): self.updatingCards = False self.playedAudio = {} f = self.form - if type == 0: - f.templateType.setText( - _("Templates used by fact:")) - elif type == 1: + if self.type == 0: f.templateType.setText( _("Templates that will be created:")) + elif self.type == 1: + f.templateType.setText( + _("Templates used by fact:")) else: f.templateType.setText( _("All templates:")) diff --git a/aqt/deckopts.py b/aqt/deckopts.py index 4529890b6..5f53ce8e9 100644 --- a/aqt/deckopts.py +++ b/aqt/deckopts.py @@ -20,9 +20,6 @@ class DeckOptions(QDialog): def setup(self): self.form.buttonBox.button(QDialogButtonBox.Help).setAutoDefault(False) self.form.buttonBox.button(QDialogButtonBox.Close).setAutoDefault(False) - self.connect(self.form.modelsAdd, SIGNAL("clicked()"), self.onAdd) - self.connect(self.form.modelsEdit, SIGNAL("clicked()"), self.onEdit) - self.connect(self.form.modelsDelete, SIGNAL("clicked()"), self.onDelete) self.connect(self.form.buttonBox, SIGNAL("helpRequested()"), self.helpRequested) # syncing @@ -31,77 +28,6 @@ class DeckOptions(QDialog): # latex self.form.latexHeader.setText(self.d.conf['latexPre']) self.form.latexFooter.setText(self.d.conf['latexPost']) - # models - self.updateModelsList() - - def updateModelsList(self): - idx = self.form.modelsList.currentRow() - self.form.modelsList.clear() - self.models = [] - for model in self.d.models().values(): - self.models.append((model.name, model)) - self.models.sort() - for (name, model) in self.models: - item = QListWidgetItem(name) - self.form.modelsList.addItem(item) - cm = self.d.currentModel - try: - if aqt.mw.currentCard: - cm = aqt.mw.currentCard.fact.model - except: - # model has been deleted - pass - if model == cm: - self.form.modelsList.setCurrentItem(item) - - def onAdd(self): - m = ui.modelchooser.AddModel(self, self.parent, self.d).getModel() - if m: - self.d.addModel(m) - self.updateModelsList() - - def onEdit(self): - model = self.selectedModel() - if not model: - return - # set to current - self.d.currentModel = model - ui.modelproperties.ModelProperties(self, self.d, model, self.parent, - onFinish=self.updateModelsList) - - def onDelete(self): - model = self.selectedModel() - row = self.form.modelsList.currentRow() - if not model: - return - if len(self.d.models) < 2: - 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( - _("This model is used by %d facts.\n" - "Are you sure you want to delete it?\n" - "If you delete it, these cards will be lost.") - % count, parent=self): - return - self.d.deleteModel(model) - self.updateModelsList() - self.form.modelsList.setCurrentRow(row) - aqt.mw.reset() - - def selectedModel(self): - row = self.form.modelsList.currentRow() - if row == -1: - return None - return self.models[self.form.modelsList.currentRow()][1] def helpRequested(self): aqt.openHelp("DeckOptions") diff --git a/aqt/groupman.py b/aqt/groups.py similarity index 98% rename from aqt/groupman.py rename to aqt/groups.py index 0a72432d0..5bf10a012 100644 --- a/aqt/groupman.py +++ b/aqt/groups.py @@ -15,11 +15,11 @@ COLDUE = 4 COLNEW = 5 GREY = "#777" -class GroupManager(QDialog): +class Groups(QDialog): def __init__(self, mw, parent=None): QDialog.__init__(self, parent or mw) self.mw = mw - self.form = aqt.forms.groupman.Ui_Dialog() + self.form = aqt.forms.groups.Ui_Dialog() self.form.setupUi(self) self.loadTable() self.addButtons() @@ -77,7 +77,7 @@ class GroupManager(QDialog): button(f.delete_2, self.onDelete) self.connect(self.form.buttonBox, SIGNAL("helpRequested()"), - lambda: aqt.openHelp("GroupManager")) + lambda: aqt.openHelp("Groups")) def onSelectAll(self): for i in self.items: diff --git a/aqt/main.py b/aqt/main.py index a964fc35c..0bc2312e2 100755 --- a/aqt/main.py +++ b/aqt/main.py @@ -645,8 +645,8 @@ Debug info:\n%s""") % traceback.format_exc(), help="DeckErrors") self.moveToState("overview") def onGroups(self, parent=None): - from aqt.groupman import GroupManager - g = GroupManager(self, parent) + from aqt.groups import Groups + g = Groups(self, parent) def onCardStats(self): self.cardStats.show() @@ -659,10 +659,14 @@ Debug info:\n%s""") % traceback.format_exc(), help="DeckErrors") CardLayout(self, self.reviewer.card.fact(), type=1, ord=self.reviewer.card.ord) - def onDeckProperties(self): + def onDeckOpts(self): import aqt.deckopts aqt.deckopts.DeckOptions(self) + def onModels(self): + import aqt.models + aqt.models.Models(self) + def onPrefs(self): import aqt.preferences aqt.preferences.Preferences(self) @@ -757,7 +761,8 @@ Please choose a new deck name:""")) self.connect(m.actionClose, s, self.onClose) self.connect(m.actionExit, s, self, SLOT("close()")) #self.connect(m.actionSyncdeck, s, self.syncDeck) - self.connect(m.actionDeckProperties, s, self.onDeckProperties) + self.connect(m.actionDeckProperties, s, self.onDeckOpts) + self.connect(m.actionModels, s, self.onModels) self.connect(m.actionAddcards, s, self.onAddCard) self.connect(m.actionEditdeck, s, self.onEditDeck) self.connect(m.actionEditCurrent, s, self.onEditCurrent) diff --git a/aqt/modelproperties.py b/aqt/modelproperties.py deleted file mode 100644 index d9bc6ba25..000000000 --- a/aqt/modelproperties.py +++ /dev/null @@ -1,302 +0,0 @@ -# Copyright: Damien Elmes -# License: GNU GPL, version 3 or later; http://www.gnu.org/copyleft/gpl.html - -from PyQt4.QtGui import * -from PyQt4.QtCore import * -import sys, re -import aqt.forms -import anki -from aqt import ui - -class ModelProperties(QDialog): - - def __init__(self, parent, deck, model, main=None, onFinish=None): - QDialog.__init__(self, parent, Qt.Window) - if not main: - main = parent - self.parent = main - self.deck = deck - self.origModTime = self.deck.modified - self.m = model - self.needRebuild = False - self.onFinish = onFinish - self.dialog = aqt.forms.modelproperties.Ui_ModelProperties() - self.dialog.setupUi(self) - self.connect(self.dialog.buttonBox, SIGNAL("helpRequested()"), - self.helpRequested) - self.readData() - self.setupCards() - self.show() - self.undoName = _("Model Properties") - self.deck.setUndoStart(self.undoName) - self.exec_() - - def readData(self): - # properties section - self.dialog.name.setText(self.m.name) - - # Cards - ########################################################################## - - def setupCards(self): - self.cardOrdinalUpdatedIds = [] - self.ignoreCardUpdate = False - self.currentCard = None - self.updateCards() - self.readCurrentCard() - self.connect(self.dialog.cardList, SIGNAL("currentRowChanged(int)"), - self.cardRowChanged) - self.connect(self.dialog.cardAdd, SIGNAL("clicked()"), - self.addCard) - self.connect(self.dialog.cardDelete, SIGNAL("clicked()"), - self.deleteCard) - self.connect(self.dialog.cardToggle, SIGNAL("clicked()"), - self.toggleCard) - self.connect(self.dialog.cardUp, SIGNAL("clicked()"), - self.moveCardUp) - self.connect(self.dialog.cardDown, SIGNAL("clicked()"), - self.moveCardDown) - self.connect(self.dialog.cardRename, SIGNAL("clicked()"), - self.renameCard) - self.connect(self.dialog.cardLayout, SIGNAL("clicked()"), - self.cardLayout) - - def cardLayout(self): - # # see if there's an available fact - # id = self.deck.db.scalar( - # "select id from facts where modelId = :id", id=self.model.id) - # if id: - # self.fact = self.deck.db.query(Fact).get(id) - # else: - # # generate a dummy one - # self.fact = self.deck.newFact(self.model) - # for f in self.fact.keys(): - # self.fact[f] = f - - - self.m.currentCard = self.currentCard - ui.clayout.CardLayout(self, None, self.m) - - def renameCard(self): - txt = ui.utils.getText(_("New name?"), parent=self) - if txt[0]: - self.currentCard.name = txt[0] - self.needRebuild = True - self.deck.updateCardTags(self.deck.db.column0( - "select id from cards where cardModelId = :id", - id=self.currentCard.id)) - self.updateCards() - - def updateCards(self, row = None): - oldRow = self.dialog.cardList.currentRow() - if oldRow == -1: - oldRow = 0 - self.dialog.cardList.clear() - n = 1 - for card in self.m.cardModels: - if card.active: - status="" - else: - status=_("; disabled") - cards = self.deck.cardModelUseCount(card) - label = "%(name)s [%(cards)s%(status)s]" % { - 'num': n, - 'name': card.name, - 'status': status, - 'cards': ngettext("%d fact", "%d facts", cards) % cards - } - item = QListWidgetItem(label) - self.dialog.cardList.addItem(item) - n += 1 - count = self.dialog.cardList.count() - if row != None: - self.dialog.cardList.setCurrentRow(row) - else: - while (count > 0 and oldRow > (count - 1)): - oldRow -= 1 - self.dialog.cardList.setCurrentRow(oldRow) - self.enableCardMoveButtons() - - def cardRowChanged(self): - if self.ignoreCardUpdate: - return - self.saveCurrentCard() - self.readCurrentCard() - - def readCurrentCard(self): - if not len(self.m.cardModels): - self.dialog.cardToggle.setEnabled(False) - self.dialog.cardDelete.setEnabled(False) - self.dialog.cardUp.setEnabled(False) - self.dialog.cardDown.setEnabled(False) - return - else: - self.dialog.cardToggle.setEnabled(True) - self.dialog.cardDelete.setEnabled(True) - self.currentCard = self.m.cardModels[self.dialog.cardList.currentRow()] - card = self.currentCard - self.updateToggleButtonText(card) - - def enableCardMoveButtons(self): - row = self.dialog.cardList.currentRow() - if row < 1: - self.dialog.cardUp.setEnabled(False) - else: - self.dialog.cardUp.setEnabled(True) - if row == -1 or row >= (self.dialog.cardList.count() - 1): - self.dialog.cardDown.setEnabled(False) - else: - self.dialog.cardDown.setEnabled(True) - - def updateToggleButtonText(self, card): - if card.active: - self.dialog.cardToggle.setText(_("Disa&ble")) - else: - self.dialog.cardToggle.setText(_("Ena&ble")) - - def saveCurrentCard(self): - if not self.currentCard: - return - card = self.currentCard - self.ignoreCardUpdate = True - self.updateCards() - self.ignoreCardUpdate = False - - def updateField(self, obj, field, value): - if getattr(obj, field) != value: - setattr(obj, field, value) - self.m.setModified() - self.deck.setModified() - return True - return False - - def addCard(self): - cards = len(self.m.cardModels) - name = _("Template_%d") % (cards+1) - fields = self.m.fieldModels - qformat = "{{%s}}" % fields[0].name - if len(fields) > 1: - aformat = "{{%s}}" % fields[1].name - else: - aformat = "" - cm = CardModel(name, qformat, aformat) - self.deck.addCardModel(m, cm) - self.updateCards() - self.dialog.cardList.setCurrentRow(len(self.m.cardModels)-1) - - def deleteCard(self): - row = self.dialog.cardList.currentRow() - if row == -1: - return - if len (self.m.cardModels) < 2: - ui.utils.showWarning( - _("Please add a new template first."), - parent=self) - return - card = self.m.cardModels[row] - count = self.deck.cardModelUseCount(card) - if count: - if not ui.utils.askUser( - _("This template is used by %d cards. If you delete it,\n" - "all the cards will be deleted too. If you just\n" - "want to prevent the creation of future cards with\n" - "this template, please use the 'disable' button\n" - "instead.\n\nReally delete these cards?") % count, - parent=self): - return - self.deck.deleteCardModel(self.m, card) - self.updateCards() - - def toggleCard(self): - row = self.dialog.cardList.currentRow() - if row == -1: - return - card = self.m.cardModels[row] - active = 0 - for c in self.m.cardModels: - if c.active: - active += 1 - if active < 2 and card.active: - ui.utils.showWarning( - _("Please enable a different template first."), - parent=self) - return - card.active = not card.active - self.updateToggleButtonText(card) - self.updateCards() - self.m.setModified() - self.deck.setModified() - - def moveCardUp(self): - row = self.dialog.cardList.currentRow() - if row == -1: - return - if row == 0: - return - card = self.m.cardModels[row] - tCard = self.m.cardModels[row - 1] - self.m.cardModels.remove(card) - self.m.cardModels.insert(row - 1, card) - if card.id not in self.cardOrdinalUpdatedIds: - self.cardOrdinalUpdatedIds.append(card.id) - if tCard.id not in self.cardOrdinalUpdatedIds: - self.cardOrdinalUpdatedIds.append(tCard.id) - self.ignoreCardUpdate = True - self.updateCards(row - 1) - self.ignoreCardUpdate = False - - def moveCardDown(self): - row = self.dialog.cardList.currentRow() - if row == -1: - return - if row == len(self.m.cardModels) - 1: - return - card = self.m.cardModels[row] - tCard = self.m.cardModels[row + 1] - self.m.cardModels.remove(card) - self.m.cardModels.insert(row + 1, card) - if card.id not in self.cardOrdinalUpdatedIds: - self.cardOrdinalUpdatedIds.append(card.id) - if tCard.id not in self.cardOrdinalUpdatedIds: - self.cardOrdinalUpdatedIds.append(tCard.id) - self.ignoreCardUpdate = True - self.updateCards(row + 1) - self.ignoreCardUpdate = False - - def helpRequested(self): - aqt.openHelp("ModelProperties") - - # Cleanup - ########################################################################## - - def reject(self): - "Save user settings on close." - # update properties - self.mw.startProgress() - mname = unicode(self.dialog.name.text()) - if not mname: - mname = _("Model") - self.updateField(self.m, 'name', mname) - self.updateField(self.m, 'tags', mname) - self.saveCurrentCard() - # if changed, reset deck - reset = False - if len(self.cardOrdinalUpdatedIds) > 0: - self.deck.rebuildCardOrdinals(self.cardOrdinalUpdatedIds) - self.m.setModified() - self.deck.setModified() - if self.origModTime != self.deck.modified: - self.deck.updateTagsForModel(self.m) - reset = True - if self.needRebuild: - # need to generate q/a templates - self.deck.updateCardsFromModel(self.m) - reset = True - if reset: - aqt.mw.reset() - if self.onFinish: - self.onFinish() - self.deck.setUndoEnd(self.undoName) - # check again - self.deck.finishProgress() - QDialog.reject(self) diff --git a/aqt/models.py b/aqt/models.py new file mode 100644 index 000000000..0c3973a06 --- /dev/null +++ b/aqt/models.py @@ -0,0 +1,307 @@ +# Copyright: Damien Elmes +# License: GNU GPL, version 3 or later; http://www.gnu.org/copyleft/gpl.html + +from PyQt4.QtGui import * +from PyQt4.QtCore import * +from aqt.utils import showInfo, askUser +import aqt.modelchooser, aqt.clayout + +class Models(QDialog): + def __init__(self, mw, parent=None): + self.mw = mw + self.parent = parent or mw + QDialog.__init__(self, self.parent, Qt.Window) + self.deck = mw.deck + self.deck.save(_("Models")) + #self.m = model + self.form = aqt.forms.models.Ui_Dialog() + self.form.setupUi(self) + self.connect(self.form.buttonBox, SIGNAL("helpRequested()"), + lambda: openHelp("Models")) + self.setupModels() + #self.setupCards() + self.exec_() + + # Models + ########################################################################## + + def setupModels(self): + self.model = None + c = self.connect; f = self.form; s = SIGNAL("clicked()") + c(f.modelsAdd, s, self.onAdd) + c(f.modelsLayout, s, self.onLayout) + c(f.modelsDelete, s, self.onDelete) + self.connect(self.form.modelsList, SIGNAL("currentRowChanged(int)"), + self.modelChanged) + self.updateModelsList() + self.form.modelsList.setCurrentRow(0) + + def updateModelsList(self): + mids = self.deck.db.list("select id from models order by name") + self.models = [self.deck.getModel(mid) for mid in mids] + self.form.modelsList.clear() + for m in self.models: + item = QListWidgetItem(m.name) + self.form.modelsList.addItem(item) + # if foo: + #self.form.modelsList.setCurrentItem(item) + + def modelChanged(self): + print "changed" + if self.model: + self.saveModel() + idx = self.form.modelsList.currentRow() + self.model = self.models[idx] + + def onAdd(self): + m = aqt.modelchooser.AddModel(self, self.parent, self.d).getModel() + if m: + self.deck.addModel(m) + self.updateModelsList() + + def onLayout(self): + # set to current + # # see if there's an available fact + dummy = False + id = self.deck.db.scalar( + "select id from facts where mid = ?", self.model.id) + if id: + fact = self.deck.getFact(id) + else: + # generate a dummy one + self.deck.conf['currentModelId'] = self.model.id + fact = self.deck.newFact() + for f in fact.keys(): + fact[f] = f + self.deck.addFact(fact) + dummy = True + aqt.clayout.CardLayout(self.mw, fact, type=2, parent=self) + if dummy: + self.deck._delFacts([fact.id]) + + def onDelete(self): + if len(self.models) < 2: + showInfo(_("Please add another model first."), + parent=self) + return + if not askUser( + _("Delete this model and all its cards?"), + parent=self): + return + self.deck.delModel(self.model.id) + self.model = None + self.updateModelsList() + + def saveModel(self): + self.model.flush() + + # Cards + ########################################################################## + + def setupCards(self): + self.ignoreCardUpdate = False + self.currentCard = None + self.updateCards() + self.readCurrentCard() + self.connect(self.form.cardList, SIGNAL("currentRowChanged(int)"), + self.cardRowChanged) + self.connect(self.form.cardAdd, SIGNAL("clicked()"), + self.addCard) + self.connect(self.form.cardDelete, SIGNAL("clicked()"), + self.deleteCard) + self.connect(self.form.cardToggle, SIGNAL("clicked()"), + self.toggleCard) + self.connect(self.form.cardUp, SIGNAL("clicked()"), + self.moveCardUp) + self.connect(self.form.cardDown, SIGNAL("clicked()"), + self.moveCardDown) + self.connect(self.form.cardRename, SIGNAL("clicked()"), + self.renameCard) + self.connect(self.form.cardLayout, SIGNAL("clicked()"), + self.cardLayout) + + def renameCard(self): + txt = ui.utils.getText(_("New name?"), parent=self) + if txt[0]: + self.currentCard.name = txt[0] + self.needRebuild = True + self.deck.updateCardTags(self.deck.db.column0( + "select id from cards where cardModelId = :id", + id=self.currentCard.id)) + self.updateCards() + + def updateCards(self, row = None): + oldRow = self.form.cardList.currentRow() + if oldRow == -1: + oldRow = 0 + self.form.cardList.clear() + n = 1 + for card in self.model.cardModels: + if card.active: + status="" + else: + status=_("; disabled") + cards = self.deck.cardModelUseCount(card) + label = "%(name)s [%(cards)s%(status)s]" % { + 'num': n, + 'name': card.name, + 'status': status, + 'cards': ngettext("%d fact", "%d facts", cards) % cards + } + item = QListWidgetItem(label) + self.form.cardList.addItem(item) + n += 1 + count = self.form.cardList.count() + if row != None: + self.form.cardList.setCurrentRow(row) + else: + while (count > 0 and oldRow > (count - 1)): + oldRow -= 1 + self.form.cardList.setCurrentRow(oldRow) + self.enableCardMoveButtons() + + def cardRowChanged(self): + if self.ignoreCardUpdate: + return + self.saveCurrentCard() + self.readCurrentCard() + + def readCurrentCard(self): + if not len(self.model.cardModels): + self.form.cardToggle.setEnabled(False) + self.form.cardDelete.setEnabled(False) + self.form.cardUp.setEnabled(False) + self.form.cardDown.setEnabled(False) + return + else: + self.form.cardToggle.setEnabled(True) + self.form.cardDelete.setEnabled(True) + self.currentCard = self.model.cardModels[self.form.cardList.currentRow()] + card = self.currentCard + self.updateToggleButtonText(card) + + def enableCardMoveButtons(self): + row = self.form.cardList.currentRow() + if row < 1: + self.form.cardUp.setEnabled(False) + else: + self.form.cardUp.setEnabled(True) + if row == -1 or row >= (self.form.cardList.count() - 1): + self.form.cardDown.setEnabled(False) + else: + self.form.cardDown.setEnabled(True) + + def updateToggleButtonText(self, card): + if card.active: + self.form.cardToggle.setText(_("Disa&ble")) + else: + self.form.cardToggle.setText(_("Ena&ble")) + + def saveCurrentCard(self): + if not self.currentCard: + return + card = self.currentCard + self.ignoreCardUpdate = True + self.updateCards() + self.ignoreCardUpdate = False + + def updateField(self, obj, field, value): + if getattr(obj, field) != value: + setattr(obj, field, value) + self.model.setModified() + self.deck.setModified() + return True + return False + + def addCard(self): + cards = len(self.model.cardModels) + name = _("Template_%d") % (cards+1) + fields = self.model.fieldModels + qformat = "{{%s}}" % fields[0].name + if len(fields) > 1: + aformat = "{{%s}}" % fields[1].name + else: + aformat = "" + cm = CardModel(name, qformat, aformat) + self.deck.addCardModel(m, cm) + self.updateCards() + self.form.cardList.setCurrentRow(len(self.model.cardModels)-1) + + def deleteCard(self): + row = self.form.cardList.currentRow() + if row == -1: + return + if len (self.model.cardModels) < 2: + ui.utils.showWarning( + _("Please add a new template first."), + parent=self) + return + card = self.model.cardModels[row] + count = self.deck.cardModelUseCount(card) + if count: + if not ui.utils.askUser( + _("This template is used by %d cards. If you delete it,\n" + "all the cards will be deleted too. If you just\n" + "want to prevent the creation of future cards with\n" + "this template, please use the 'disable' button\n" + "instead.\n\nReally delete these cards?") % count, + parent=self): + return + self.deck.deleteCardModel(self.m, card) + self.updateCards() + + def toggleCard(self): + row = self.form.cardList.currentRow() + if row == -1: + return + card = self.model.cardModels[row] + active = 0 + for c in self.model.cardModels: + if c.active: + active += 1 + if active < 2 and card.active: + ui.utils.showWarning( + _("Please enable a different template first."), + parent=self) + return + card.active = not card.active + self.updateToggleButtonText(card) + self.updateCards() + self.model.setModified() + self.deck.setModified() + + def moveCardUp(self): + row = self.form.cardList.currentRow() + if row == -1: + return + if row == 0: + return + self.mw.progress.start() + self.model.moveTemplate(self.template, row-1) + self.mw.progress.finish() + self.ignoreCardUpdate = True + self.updateCards(row-1) + self.ignoreCardUpdate = False + + def moveCardDown(self): + row = self.form.cardList.currentRow() + if row == -1: + return + if row == len(self.model.cardModels) - 1: + return + self.model.moveTemplate(self.template, row+1) + self.mw.progress.finish() + self.ignoreCardUpdate = True + self.updateCards(row+1) + self.ignoreCardUpdate = False + + # Cleanup + ########################################################################## + + # need to flush model on change or reject + + def reject(self): + #self.saveCurrentCard() + self.saveModel() + self.mw.reset() + QDialog.reject(self) diff --git a/designer/deckopts.ui b/designer/deckopts.ui index b348e3dc2..915fb461a 100644 --- a/designer/deckopts.ui +++ b/designer/deckopts.ui @@ -27,77 +27,6 @@ Basic - - - - <b>Models</b> - - - true - - - - - - - - - - 0 - 0 - - - - - - - - - - &Add - - - false - - - - - - - &Edit - - - false - - - - - - - &Delete - - - false - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - @@ -138,6 +67,19 @@ + + + + Qt::Vertical + + + + 20 + 40 + + + + @@ -193,10 +135,6 @@ qtabwidget doSync mediaURL - modelsList - modelsAdd - modelsEdit - modelsDelete buttonBox latexHeader latexFooter diff --git a/designer/groupman.ui b/designer/groups.ui similarity index 100% rename from designer/groupman.ui rename to designer/groups.ui diff --git a/designer/main.ui b/designer/main.ui index cee35c2b0..3dc1b3754 100644 --- a/designer/main.ui +++ b/designer/main.ui @@ -148,6 +148,7 @@ + @@ -676,6 +677,14 @@ G + + + Models... + + + Ctrl+M + + diff --git a/designer/modelproperties.ui b/designer/modelproperties.ui deleted file mode 100644 index bb40f96dc..000000000 --- a/designer/modelproperties.ui +++ /dev/null @@ -1,218 +0,0 @@ - - - ModelProperties - - - Qt::ApplicationModal - - - - 0 - 0 - 471 - 435 - - - - Model Properties - - - - - - General - - - - - - 4 - - - 4 - - - - - Name - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - - - - - - - - - - - - - - - Card Templates - - - - - - - - - 0 - 1 - - - - - 0 - 60 - - - - - - - - - - &Add - - - - - - - &Rename - - - - - - - Move selected card model up - - - &Up - - - - - - - Move selected card model down - - - Dow&n - - - - - - - - - - - - - - &Delete - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - Card &Layout - - - - :/icons/layout.png:/icons/layout.png - - - - - - - - - - - - - - Qt::Horizontal - - - QDialogButtonBox::Close|QDialogButtonBox::Help - - - - - - - name - cardList - cardAdd - cardRename - cardUp - cardDown - cardToggle - cardDelete - cardLayout - buttonBox - - - - - - - buttonBox - accepted() - ModelProperties - accept() - - - 252 - 513 - - - 157 - 274 - - - - - buttonBox - rejected() - ModelProperties - reject() - - - 320 - 513 - - - 286 - 274 - - - - - diff --git a/designer/models.ui b/designer/models.ui new file mode 100644 index 000000000..cf7744417 --- /dev/null +++ b/designer/models.ui @@ -0,0 +1,294 @@ + + + Dialog + + + Qt::ApplicationModal + + + + 0 + 0 + 425 + 446 + + + + Models + + + + 0 + + + + + 6 + + + + + + 0 + 0 + + + + + + + + 12 + + + + + &Add + + + false + + + + + + + &Delete + + + false + + + + + + + &Layout... + + + + :/icons/layout.png:/icons/layout.png + + + false + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + Qt::Vertical + + + QSizePolicy::Minimum + + + + 20 + 6 + + + + + + + + + 0 + 10 + + + + + + + + + + + + Sort Field + + + + + + + + 0 + 0 + + + + + + + + + + Card Templates + + + + + + + + + 0 + 1 + + + + + 0 + 60 + + + + + + + + + + &Add + + + false + + + + + + + &Up + + + false + + + + + + + Dow&n + + + false + + + + + + + &Delete + + + false + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Close|QDialogButtonBox::Help + + + + + + + modelsList + modelsAdd + modelsDelete + modelsLayout + sortField + cardList + cardAdd + cardUp + cardDown + cardDelete + buttonBox + + + + + + + buttonBox + accepted() + Dialog + accept() + + + 252 + 513 + + + 157 + 274 + + + + + buttonBox + rejected() + Dialog + reject() + + + 320 + 513 + + + 286 + 274 + + + + +