mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 06:22:22 -04:00
start of group configuration selector
This commit is contained in:
parent
61043f7ca9
commit
03d0348fd2
3 changed files with 141 additions and 4 deletions
60
aqt/groupconfsel.py
Normal file
60
aqt/groupconfsel.py
Normal file
|
@ -0,0 +1,60 @@
|
|||
# Copyright: Damien Elmes <anki@ichi2.net>
|
||||
# -*- 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
|
||||
|
|
@ -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."))
|
||||
|
||||
|
|
78
designer/groupconfsel.ui
Normal file
78
designer/groupconfsel.ui
Normal file
|
@ -0,0 +1,78 @@
|
|||
<?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>573</width>
|
||||
<height>377</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Anki</string>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Choose configuration for selected groups:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QListWidget" name="list"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Ok</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>
|
Loading…
Reference in a new issue