Mercurial > libervia-web
annotate src/browser/sat_browser/list_manager.py @ 736:fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
author | souliane <souliane@mailoo.org> |
---|---|
date | Thu, 19 Nov 2015 11:41:03 +0100 |
parents | 9877607c719a |
children | 4545d48dee60 |
rev | line source |
---|---|
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1 #!/usr/bin/python |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2 # -*- coding: utf-8 -*- |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
3 |
339
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
323
diff
changeset
|
4 # Libervia: a Salut à Toi frontend |
685 | 5 # Copyright (C) 2013, 2014, 2015 Adrien Cossa <souliane@mailoo.org> |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
6 |
339
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
323
diff
changeset
|
7 # This program is free software: you can redistribute it and/or modify |
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
323
diff
changeset
|
8 # it under the terms of the GNU Affero General Public License as published by |
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
323
diff
changeset
|
9 # the Free Software Foundation, either version 3 of the License, or |
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
323
diff
changeset
|
10 # (at your option) any later version. |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
11 |
339
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
323
diff
changeset
|
12 # This program is distributed in the hope that it will be useful, |
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
323
diff
changeset
|
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
323
diff
changeset
|
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
323
diff
changeset
|
15 # GNU Affero General Public License for more details. |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
16 |
339
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
323
diff
changeset
|
17 # You should have received a copy of the GNU Affero General Public License |
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
323
diff
changeset
|
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
19 |
439
d52f529a6d42
browser side: use of new log system (first draft):
Goffi <goffi@goffi.org>
parents:
422
diff
changeset
|
20 from sat.core.log import getLogger |
736
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
21 from pyjamas.ui.DragHandler import DragHandler |
439
d52f529a6d42
browser side: use of new log system (first draft):
Goffi <goffi@goffi.org>
parents:
422
diff
changeset
|
22 log = getLogger(__name__) |
736
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
23 |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
24 from pyjamas.ui.ClickListener import ClickHandler |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
25 from pyjamas.ui.FocusListener import FocusHandler |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
26 from pyjamas.ui.ChangeListener import ChangeHandler |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
27 from pyjamas.ui.KeyboardListener import KeyboardHandler, KEY_ENTER |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
28 from pyjamas.ui.DragWidget import DragWidget |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
29 from pyjamas.ui.ListBox import ListBox |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
30 from pyjamas.ui.Button import Button |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
31 from pyjamas.ui.FlowPanel import FlowPanel |
736
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
32 from pyjamas.ui.HorizontalPanel import HorizontalPanel |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
33 from pyjamas.ui.FlexTable import FlexTable |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
34 from pyjamas.ui.AutoComplete import AutoCompleteTextBox |
323
0b7934e75e76
misc: reorganization of the file panels.py + clean the modules import:
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
35 |
648
6d3142b782c3
browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents:
604
diff
changeset
|
36 import base_panel |
467 | 37 import base_widget |
648
6d3142b782c3
browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents:
604
diff
changeset
|
38 import libervia_widget |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
39 |
736
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
40 from sat_frontends.quick_frontend import quick_list_manager |
600
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
467
diff
changeset
|
41 |
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
467
diff
changeset
|
42 |
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
467
diff
changeset
|
43 unicode = str # FIXME: pyjamas workaround |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
44 |
600
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
467
diff
changeset
|
45 |
736
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
46 class ListItem(HorizontalPanel): |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
47 """This class implements a list item with auto-completion and a delete button.""" |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
48 |
736
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
49 STYLE = {"listItem-box": "listItem-box", |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
50 "listItem-box-invalid": "listItem-box-invalid", |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
51 "listItem-button": "listItem-button", |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
52 } |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
53 |
736
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
54 VALID = 1 |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
55 INVALID = 2 |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
56 DUPLICATE = 3 |
241
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
232
diff
changeset
|
57 |
736
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
58 def __init__(self, listener=None, taglist=None, validate=None): |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
59 """ |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
60 |
736
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
61 @param listener (ListItemHandler): handler for the UI events |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
62 @param taglist (quick_list_manager.QuickTagList): list manager |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
63 @param validate (callable): method returning a bool to validate the entry |
600
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
467
diff
changeset
|
64 """ |
736
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
65 HorizontalPanel.__init__(self) |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
66 |
736
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
67 self.box = AutoCompleteTextBox(StyleName=self.STYLE["listItem-box"]) |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
68 self.remove_btn = Button('<span>x</span>', Visible=False) |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
69 self.remove_btn.setStyleName(self.STYLE["listItem-button"]) |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
70 self.add(self.box) |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
71 self.add(self.remove_btn) |
600
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
467
diff
changeset
|
72 |
736
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
73 if listener: |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
74 self.box.addFocusListener(listener) |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
75 self.box.addChangeListener(listener) |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
76 self.box.addKeyboardListener(listener) |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
77 self.box.choices.addClickListener(listener) |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
78 self.remove_btn.addClickListener(listener) |
600
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
467
diff
changeset
|
79 |
736
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
80 self.taglist = taglist |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
81 self.validate = validate |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
82 self.last_checked_value = "" |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
83 self.last_validity = self.VALID |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
84 |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
85 @property |
736
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
86 def text(self): |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
87 return self.box.getText() |
600
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
467
diff
changeset
|
88 |
736
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
89 def setText(self, text): |
600
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
467
diff
changeset
|
90 """ |
736
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
91 Set the text and refresh the Widget. |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
92 |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
93 @param text (unicode): text to set |
600
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
467
diff
changeset
|
94 """ |
736
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
95 self.box.setText(text) |
600
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
467
diff
changeset
|
96 self.refresh() |
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
467
diff
changeset
|
97 |
736
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
98 def refresh(self): |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
99 if self.last_checked_value == self.text: |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
100 return |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
101 |
736
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
102 if self.taglist and self.last_checked_value: |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
103 self.taglist.untag([self.last_checked_value]) |
600
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
467
diff
changeset
|
104 |
736
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
105 if self.validate: # if None, the state is always valid |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
106 self.last_validity = self.validate(self.text) |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
107 |
736
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
108 if self.last_validity == self.VALID: |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
109 self.box.removeStyleName(self.STYLE["listItem-box-invalid"]) |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
110 elif self.last_validity == self.INVALID: |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
111 self.box.addStyleName(self.STYLE["listItem-box-invalid"]) |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
112 elif self.last_validity == self.DUPLICATE: |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
113 self.remove_btn.click() # this may do more stuff then self.remove() |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
114 return |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
115 |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
116 if self.taglist and self.text: |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
117 self.taglist.tag([self.text]) |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
118 self.last_checked_value = self.text |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
119 self.remove_btn.setVisible(len(self.text) > 0) |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
120 |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
121 def setFocus(self, focused): |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
122 self.box.setFocus(focused) |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
123 |
736
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
124 def remove(self): |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
125 """Remove the list item from its parent.""" |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
126 self.removeFromParent() |
600
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
467
diff
changeset
|
127 |
736
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
128 if self.taglist and self.text: # this must be done after the widget has been removed |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
129 self.taglist.untag([self.text]) |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
130 |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
131 |
736
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
132 class DraggableListItem(ListItem, DragWidget): |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
133 """This class is like ListItem, but in addition it can be dragged.""" |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
134 |
736
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
135 def __init__(self, listener=None, taglist=None, validate=None): |
600
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
467
diff
changeset
|
136 """ |
736
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
137 |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
138 @param listener (ListItemHandler): handler for the UI events |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
139 @param taglist (quick_list_manager.QuickTagList): list manager |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
140 @param validate (callable): method returning a bool to validate the entry |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
141 """ |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
142 ListItem.__init__(self, listener, taglist, validate) |
604
c22b47d63fe2
browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents:
600
diff
changeset
|
143 DragWidget.__init__(self) |
736
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
144 self.addDragListener(listener) |
604
c22b47d63fe2
browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents:
600
diff
changeset
|
145 |
c22b47d63fe2
browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents:
600
diff
changeset
|
146 |
c22b47d63fe2
browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents:
600
diff
changeset
|
147 def onDragStart(self, event): |
736
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
148 """The user starts dragging the item.""" |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
149 self.box.setSelectionRange(len(self.text), 0) |
604
c22b47d63fe2
browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents:
600
diff
changeset
|
150 |
c22b47d63fe2
browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents:
600
diff
changeset
|
151 dt = event.dataTransfer |
736
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
152 dt.setData('text/plain', "%s\n%s" % (self.text, "CONTACT_TEXTBOX")) |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
153 dt.setDragImage(self.box.getElement(), 15, 15) |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
154 |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
155 |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
156 class ListItemHandler(ClickHandler, FocusHandler, KeyboardHandler, ChangeHandler): |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
157 """Implements basic handlers for the ListItem events.""" |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
158 |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
159 last_item = None # the last item is an empty text box for user input |
604
c22b47d63fe2
browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents:
600
diff
changeset
|
160 |
736
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
161 def __init__(self, manager, key): |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
162 ClickHandler.__init__(self) |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
163 FocusHandler.__init__(self) |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
164 ChangeHandler.__init__(self) |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
165 KeyboardHandler.__init__(self) |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
166 self.manager = manager |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
167 self.key = key |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
168 |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
169 def addItem(self, item): |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
170 raise NotImplementedError |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
171 |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
172 def removeItem(self, item): |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
173 raise NotImplementedError |
604
c22b47d63fe2
browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents:
600
diff
changeset
|
174 |
c22b47d63fe2
browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents:
600
diff
changeset
|
175 def onClick(self, sender): |
736
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
176 """The remove button or a suggested completion item has been clicked.""" |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
177 #log.debug("onClick sender type: %s" % type(sender)) |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
178 if isinstance(sender, Button): |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
179 item = sender.getParent() |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
180 self.removeItem(item) |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
181 elif isinstance(sender, ListBox): |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
182 # this is called after onChange when you click a suggested item, and now we get the final value |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
183 textbox = sender._clickListeners[0] |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
184 self.checkValue(textbox) |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
185 else: |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
186 raise AssertionError |
604
c22b47d63fe2
browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents:
600
diff
changeset
|
187 |
736
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
188 def onFocus(self, sender): |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
189 """The text box has the focus.""" |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
190 #log.debug("onFocus sender type: %s" % type(sender)) |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
191 assert isinstance(sender, AutoCompleteTextBox) |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
192 sender.setCompletionItems(self.manager.untagged) |
604
c22b47d63fe2
browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents:
600
diff
changeset
|
193 |
c22b47d63fe2
browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents:
600
diff
changeset
|
194 def onKeyUp(self, sender, keycode, modifiers): |
736
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
195 """The text box is being modified - or ENTER key has been pressed.""" |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
196 # this is called after onChange when you press ENTER, and now we get the final value |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
197 #log.debug("onKeyUp sender type: %s" % type(sender)) |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
198 assert isinstance(sender, AutoCompleteTextBox) |
604
c22b47d63fe2
browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents:
600
diff
changeset
|
199 if keycode == KEY_ENTER: |
736
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
200 self.checkValue(sender) |
604
c22b47d63fe2
browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents:
600
diff
changeset
|
201 |
736
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
202 def onChange(self, sender): |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
203 """The text box has been changed by the user.""" |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
204 # this is called before the completion when you press ENTER or click a suggest item |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
205 #log.debug("onChange sender type: %s" % type(sender)) |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
206 assert isinstance(sender, AutoCompleteTextBox) |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
207 self.checkValue(sender) |
263
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
208 |
736
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
209 def checkValue(self, textbox): |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
210 """Internal handler to call when a new value is submitted by the user.""" |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
211 item = textbox.getParent() |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
212 if item.text == item.last_checked_value: |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
213 # this method has already been called (by self.onChange) and there's nothing new |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
214 return |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
215 item.refresh() |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
216 item.box.setSelectionRange(len(item.text), 0) |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
217 if item == self.last_item and item.last_validity == ListItem.VALID and item.text: |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
218 self.addItem() |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
219 |
736
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
220 class DraggableListItemHandler(ListItemHandler, DragHandler): |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
221 """Implements basic handlers for the DraggableListItem events.""" |
263
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
222 |
736
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
223 def __init__(self, manager, key): |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
224 ListItemHandler.__init__(self, manager, key) |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
225 DragHandler.__init__(self) |
263
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
226 |
736
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
227 def onDragStart(self, event): |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
228 """The user starts dragging the item.""" |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
229 self.manager.drop_target = None |
263
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
230 |
736
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
231 def onDragEnd(self, event): |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
232 """The user dropped the list item.""" |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
233 text, dummy = libervia_widget.eventGetData(event) |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
234 target = self.manager.drop_target # self or another ListPanel |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
235 if text == "" or target is None: |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
236 return |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
237 if target != self: # move the item from self to target |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
238 target.addItem(text) |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
239 self.removeItem(self.getItem(text)) |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
240 |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
241 |
736
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
242 class ListPanel(FlowPanel, DraggableListItemHandler, libervia_widget.DropCell): |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
243 """Implements a list of items.""" |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
244 # XXX: beware that pyjamas.ui.FlowPanel is not fully implemented: |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
245 # - it can not be used with pyjamas.ui.Label |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
246 # - FlowPanel.insert doesn't work |
263
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
247 |
736
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
248 STYLE = {"listPanel": "listPanel"} |
600
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
467
diff
changeset
|
249 |
736
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
250 def __init__(self, manager, key, items): |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
251 """Initialization with a button for the list name (key) and a DraggableListItem. |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
252 |
600
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
467
diff
changeset
|
253 @param manager (ListManager) |
736
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
254 @param key (unicode): list name |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
255 @param items (list): items to append |
600
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
467
diff
changeset
|
256 """ |
736
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
257 FlowPanel.__init__(self) |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
258 DraggableListItemHandler.__init__(self, manager, key) |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
259 libervia_widget.DropCell.__init__(self, None) |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
260 self.addStyleName(self.STYLE["listPanel"]) |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
261 self.manager = manager |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
262 items.sort() |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
263 self.addItem() |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
264 for item in items: |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
265 self.addItem(unicode(item)) |
600
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
467
diff
changeset
|
266 |
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
467
diff
changeset
|
267 # FIXME: dirty magic strings '@' and '@@' |
736
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
268 self.drop_keys = {"GROUP": lambda host, item_s: self.addItem("@%s" % item_s), |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
269 "CONTACT": lambda host, item_s: self.addItem(item_s), |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
270 "CONTACT_TITLE": lambda host, item_s: self.addItem('@@'), |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
271 "CONTACT_TEXTBOX": lambda host, item_s: setattr(self.manager, "drop_target", self), |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
272 } |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
273 |
604
c22b47d63fe2
browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents:
600
diff
changeset
|
274 def onDrop(self, event): |
736
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
275 """Something has been dropped in this ListPanel""" |
604
c22b47d63fe2
browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents:
600
diff
changeset
|
276 try: |
648
6d3142b782c3
browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents:
604
diff
changeset
|
277 libervia_widget.DropCell.onDrop(self, event) |
604
c22b47d63fe2
browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents:
600
diff
changeset
|
278 except base_widget.NoLiberviaWidgetException: |
c22b47d63fe2
browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents:
600
diff
changeset
|
279 pass |
736
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
280 |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
281 def getItem(self, text): |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
282 """Get an item from its text. |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
283 |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
284 @param text(unicode): item text |
263
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
285 """ |
736
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
286 for child in self.getChildren(): |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
287 if child.text == text: |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
288 return child |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
289 return None |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
290 |
736
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
291 def getItems(self): |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
292 """Get the non empty items. |
263
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
293 |
736
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
294 @return list(unicode) |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
295 """ |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
296 return [widget.text for widget in self.getChildren() if isinstance(widget, ListItem) and widget.text] |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
297 |
736
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
298 def validateItem(self, text): |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
299 """Return validation code after the item has been changed. |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
300 |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
301 @param text (unicode): item text to check |
600
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
467
diff
changeset
|
302 @return: int value defined by one of these constants: |
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
467
diff
changeset
|
303 - VALID if the item is valid |
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
467
diff
changeset
|
304 - INVALID if the item is not valid but can be displayed |
736
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
305 - DUPLICATE if the item is a duplicate |
600
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
467
diff
changeset
|
306 """ |
736
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
307 def count(list_, item): # XXX: list.count in not implemented by pyjamas |
600
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
467
diff
changeset
|
308 return len([elt for elt in list_ if elt == item]) |
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
467
diff
changeset
|
309 |
736
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
310 if count(self.getItems(), text) > 1: |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
311 return ListItem.DUPLICATE # item already exists in this list so we suggest its deletion |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
312 return ListItem.VALID if text in self.manager.items or not text else ListItem.INVALID |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
313 |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
314 def addItem(self, text=""): |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
315 """Add an item. |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
316 |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
317 @param text (unicode): text to be set. |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
318 @return: True if the item has been really added or merged. |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
319 """ |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
320 if text in self.getItems(): # avoid duplicate in the same list |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
321 return |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
322 |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
323 item = DraggableListItem(self, self.manager, self.validateItem) |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
324 self.add(item) |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
325 |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
326 if self.last_item: |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
327 if self.last_item.last_validity == ListItem.INVALID: |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
328 # switch the two values so that the invalid one stays in last position |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
329 item.setText(self.last_item.text) |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
330 self.last_item.setText(text) |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
331 elif not self.last_item.text: |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
332 # copy the new value to previous empty item |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
333 self.last_item.setText(text) |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
334 else: # first item of the list, or previous last item has been deleted |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
335 item.setText(text) |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
336 |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
337 self.last_item = item |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
338 self.last_item.setFocus(True) |
600
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
467
diff
changeset
|
339 |
736
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
340 def removeItem(self, item): |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
341 """Remove an item. |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
342 |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
343 @param item(DraggableListItem): item to remove |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
344 """ |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
345 if item == self.last_item: |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
346 self.addItem("") |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
347 item.remove() # this also updates the taglist |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
348 |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
349 |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
350 class ListManager(FlexTable, quick_list_manager.QuickTagList): |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
351 """Implements a table to manage one or several lists of items.""" |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
352 |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
353 STYLE = {"listManager-button": "group", |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
354 "listManager-button-cell": "listManager-button-cell", |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
355 } |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
356 |
736
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
357 def __init__(self, data=None, items=None): |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
358 """ |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
359 @param data (dict{unicode: list}): dict binding keys to tagged items. |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
360 @param items (list): full list of items (tagged and untagged) |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
361 """ |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
362 FlexTable.__init__(self, Width="100%") |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
363 quick_list_manager.QuickTagList.__init__(self, [unicode(item) for item in items]) |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
364 self.lists = {} |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
365 |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
366 if data: |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
367 for key, items in data.iteritems(): |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
368 self.addList(key, [unicode(item) for item in items]) |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
369 |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
370 def addList(self, key, items=None): |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
371 """Add a Button and ListPanel for a new list. |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
372 |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
373 @param key (unicode): list name |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
374 @param items (list): items to append to the new list |
263
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
375 """ |
736
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
376 if key in self.lists: |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
377 return |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
378 |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
379 if items is None: |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
380 items = [] |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
381 |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
382 self.lists[key] = {"button": Button(key, Title=key, StyleName=self.STYLE["listManager-button"]), |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
383 "panel": ListPanel(self, key, items)} |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
384 |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
385 y, x = len(self.lists), 0 |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
386 self.insertRow(y) |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
387 self.setWidget(y, x, self.lists[key]["button"]) |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
388 self.setWidget(y, x + 1, self.lists[key]["panel"]) |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
389 self.getCellFormatter().setStyleName(y, x, self.STYLE["listManager-button-cell"]) |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
390 |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
391 try: |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
392 self.popup_menu.registerClickSender(self.lists[key]["button"]) |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
393 except (AttributeError, TypeError): # self.registerPopupMenuPanel hasn't been called yet |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
394 pass |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
395 |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
396 def removeList(self, key): |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
397 """Remove a ListPanel from this manager. |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
398 |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
399 @param key (unicode): list name |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
400 """ |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
401 items = self.lists[key]["panel"].getItems() |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
402 (y, x) = self.getIndex(self.lists[key]["button"]) |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
403 self.removeRow(y) |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
404 del self.lists[key] |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
405 self.untag(items) |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
406 |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
407 def untag(self, items): |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
408 """Untag some items. |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
409 |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
410 Check first if the items are not used in any panel. |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
411 |
736
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
412 @param items (list): items to be removed |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
413 """ |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
414 items_assigned = set() |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
415 for values in self.getItemsByKey().itervalues(): |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
416 items_assigned.update(values) |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
417 quick_list_manager.QuickTagList.untag(self, [item for item in items if item not in items_assigned]) |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
418 |
736
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
419 def getItemsByKey(self): |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
420 """Get the items grouped by list name. |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
421 |
736
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
422 @return dict{unicode: list} |
600
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
467
diff
changeset
|
423 """ |
736
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
424 return {key: self.lists[key]["panel"].getItems() for key in self.lists} |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
425 |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
426 def getKeysByItem(self): |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
427 """Get the keys groups by item. |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
428 |
736
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
429 @return dict{object: set(unicode)} |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
430 """ |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
431 result = {} |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
432 for key in self.lists: |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
433 for item in self.lists[key]["panel"].getItems(): |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
434 result.setdefault(item, set()).add(key) |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
435 return result |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
436 |
736
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
437 def registerPopupMenuPanel(self, entries, callback): |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
438 """Register a popup menu panel for the list names' buttons. |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
439 |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
440 @param entries (dict{unicode: dict{unicode: unicode}}): menu entries |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
441 @param callback (callable): common callback for all menu items, arguments are: |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
442 - button widget |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
443 - list name (item key) |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
444 """ |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
445 self.popup_menu = base_panel.PopupMenuPanel(entries, callback=callback) |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
446 for key in self.lists: # register click sender for already existing lists |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
447 self.popup_menu.registerClickSender(self.lists[key]["button"]) |