From 03d0348fd243acf2ff8bea2e9364ebbbfe148c2c Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Tue, 29 Mar 2011 13:51:01 +0900 Subject: [PATCH] start of group configuration selector --- aqt/groupconfsel.py | 60 +++++++++++++++++++++++++++++++ aqt/groupsel.py | 7 ++-- designer/groupconfsel.ui | 78 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 141 insertions(+), 4 deletions(-) create mode 100644 aqt/groupconfsel.py create mode 100644 designer/groupconfsel.ui diff --git a/aqt/groupconfsel.py b/aqt/groupconfsel.py new file mode 100644 index 000000000..bcce655a3 --- /dev/null +++ b/aqt/groupconfsel.py @@ -0,0 +1,60 @@ +# Copyright: Damien Elmes +# -*- coding: utf-8 -*- +# License: GNU GPL, version 3 or later; http://www.gnu.org/copyleft/gpl.html + +from PyQt4.QtCore import * +from PyQt4.QtGui import * +import aqt +from aqt.utils import showInfo + +class GroupConfSelector(QDialog): + def __init__(self, mw, gids): + QDialog.__init__(self, mw) + self.mw = mw + self.gids = gids + self.form = aqt.forms.groupconfsel.Ui_Dialog() + self.form.setupUi(self) + self.load() + self.addButtons() + self.exec_() + + def load(self): + self.confs = self.mw.deck.groupConfs() + for c in self.confs: + item = QListWidgetItem(c[0]) + item.setFlags(item.flags() | Qt.ItemIsEditable) + self.form.list.addItem(item) + self.connect(self.form.list, SIGNAL("itemChanged(QListWidgetItem*)"), + self.onRename) + + def addButtons(self): + box = self.form.buttonBox + def button(name, func, type=QDialogButtonBox.ActionRole): + b = box.addButton(name, type) + b.connect(b, SIGNAL("clicked()"), func) + return b + button(_("Edit"), self.onEdit) + button(_("Copy"), self.onCopy) + button(_("Delete"), self.onDelete) + + def idx(self): + return self.form.list.currentRow() + + def onRename(self, item): + idx = self.idx() + id = self.confs[idx][1] + self.mw.deck.db.execute("update gconf set name = ? where id = ?", + unicode(item.text()), id) + + def onEdit(self): + pass + + def onCopy(self): + pass + + def onDelete(self): + idx = self.form.list.currentRow() + if self.confs[idx][1] == 1: + showInfo(_("The default configuration can't be removed.")) + return + diff --git a/aqt/groupsel.py b/aqt/groupsel.py index 4b4373b77..61bcc6e74 100644 --- a/aqt/groupsel.py +++ b/aqt/groupsel.py @@ -55,8 +55,7 @@ class GroupSel(QDialog): # selection button(_("Select &All"), self.onSelectAll) button(_("Select &None"), self.onSelectNone) - # edit can only be active if current item has a gid - self.editButton = button(_("&Edit..."), self.onEdit) + button(_("&Config..."), self.onEdit) self.connect(box, SIGNAL("helpRequested()"), lambda: QDesktopServices.openUrl(QUrl( @@ -85,8 +84,8 @@ class GroupSel(QDialog): if gid: gids.append(gid) if gids: - from aqt.groupconf import GroupConf - GroupConf(self.mw, gids) + from aqt.groupconfsel import GroupConfSelector + GroupConfSelector(self.mw, gids) else: showInfo(_("None of the selected items are a group.")) diff --git a/designer/groupconfsel.ui b/designer/groupconfsel.ui new file mode 100644 index 000000000..b0fcba20b --- /dev/null +++ b/designer/groupconfsel.ui @@ -0,0 +1,78 @@ + + + Dialog + + + + 0 + 0 + 573 + 377 + + + + Anki + + + + + + + + Choose configuration for selected groups: + + + + + + + + + + + + Qt::Vertical + + + QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + Dialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + Dialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + +