-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathsmall_add_cards.py
60 lines (51 loc) · 2.02 KB
/
small_add_cards.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# -*- coding: utf-8 -*-
#
# Copyricht © 2012 Roland Sieker, <[email protected]>
#
# License: GNU AGPL, version 3 or later; http://www.gnu.org/copyleft/agpl.html
#
# See the notes in the progress function
from anki.hooks import wrap
from aqt.addcards import AddCards
from aqt.qt import QDialogButtonBox, QWidgetItem, SIGNAL
from anki.lang import _
__version__ = '1.0.1'
def reset_min_size(self):
"""
Undo the setting of the minimun size.
"""
self.setMinimumHeight(0)
self.setMinimumWidth(0)
def more_less_button(self):
bb = self.form.buttonBox
ar = QDialogButtonBox.ActionRole
self.more_less_button = bb.addButton(
_("Show less"), ar)
self.connect(self.more_less_button, SIGNAL("clicked()"),
lambda add_dialog=self: show_more_less(add_dialog))
def show_more_less(add_dialog):
# Use the visibility of (the first of ) the top element(s) to
# decide if we should hide or show.
if add_dialog.form.modelArea.isVisible():
# Here we just set the varible we use below. Should reduce
# code duplication a bit.
new_show_state = False
# But we need this if to change the text. The point is to make
# the window small in this state. So use a short text.
add_dialog.more_less_button.setText("+")
else:
# The other way
new_show_state = True
add_dialog.more_less_button.setText("Show less")
# Now do the un/hiding of the bunch of elements.
add_dialog.form.modelArea.setVisible(new_show_state)
add_dialog.form.deckArea.setVisible(new_show_state)
# Somewhat C++ish. Not very Pythonic. Oh, well.
for i in range(add_dialog.editor.iconsBox.count()):
item = add_dialog.editor.iconsBox.itemAt(i)
if type(item) == QWidgetItem:
# Looks like there isn't much point in this anyway.
pass
# item.widget().setVisible(new_show_state)
AddCards.setupEditor = wrap(AddCards.setupEditor, reset_min_size)
AddCards.setupButtons = wrap(AddCards.setupButtons, more_less_button)