annotate src/browser/sat_browser/list_manager.py @ 841:4a01be961fd2

server: removed unused %(url)s for formatting HTTP warning message
author Goffi <goffi@goffi.org>
date Wed, 13 Jan 2016 17:14:04 +0100
parents f8a7a046ff9c
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
818
f8a7a046ff9c copyright update
Goffi <goffi@goffi.org>
parents: 741
diff changeset
5 # Copyright (C) 2013-2016 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
d52f529a6d42 browser side: use of new log system (first draft):
Goffi <goffi@goffi.org>
parents: 422
diff changeset
21 log = getLogger(__name__)
739
4545d48dee60 browser_side: improve ListPanel and TitlePanel
souliane <souliane@mailoo.org>
parents: 736
diff changeset
22 from sat.core.i18n import _
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
739
4545d48dee60 browser_side: improve ListPanel and TitlePanel
souliane <souliane@mailoo.org>
parents: 736
diff changeset
27 from pyjamas.ui.DragHandler import DragHandler
736
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
28 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
29 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
30 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
31 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
32 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
33 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
34 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
35 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
36
648
6d3142b782c3 browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents: 604
diff changeset
37 import base_panel
467
97c72fe4a5f2 browser_side: import fixes:
Goffi <goffi@goffi.org>
parents: 449
diff changeset
38 import base_widget
648
6d3142b782c3 browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents: 604
diff changeset
39 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
40
736
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
41 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
42
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
43
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
44 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
45
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
46
736
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
47 class ListItem(HorizontalPanel):
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
48 """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
49
739
4545d48dee60 browser_side: improve ListPanel and TitlePanel
souliane <souliane@mailoo.org>
parents: 736
diff changeset
50 STYLE = {"listItem": "listItem",
4545d48dee60 browser_side: improve ListPanel and TitlePanel
souliane <souliane@mailoo.org>
parents: 736
diff changeset
51 "listItem-box": "listItem-box",
736
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
52 "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
53 "listItem-button": "listItem-button",
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
54 }
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
55
736
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
56 VALID = 1
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
57 INVALID = 2
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
58 DUPLICATE = 3
241
86055ccf69c3 browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents: 232
diff changeset
59
736
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
60 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
61 """
254
28d3315a8003 browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents: 241
diff changeset
62
736
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
63 @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
64 @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
65 @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
66 """
736
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
67 HorizontalPanel.__init__(self)
739
4545d48dee60 browser_side: improve ListPanel and TitlePanel
souliane <souliane@mailoo.org>
parents: 736
diff changeset
68 self.addStyleName(self.STYLE["listItem"])
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
69
736
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
70 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
71 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
72 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
73 self.add(self.box)
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
74 self.add(self.remove_btn)
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
75
736
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
76 if listener:
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
77 self.box.addFocusListener(listener)
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
78 self.box.addChangeListener(listener)
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
79 self.box.addKeyboardListener(listener)
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
80 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
81 self.remove_btn.addClickListener(listener)
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
82
736
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
83 self.taglist = taglist
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
84 self.validate = validate
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
85 self.last_checked_value = ""
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
86 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
87
254
28d3315a8003 browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents: 241
diff changeset
88 @property
736
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
89 def text(self):
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
90 return self.box.getText()
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
91
736
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
92 def setText(self, text):
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
93 """
736
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
94 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
95
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
96 @param text (unicode): text to set
600
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 self.box.setText(text)
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
99 self.refresh()
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
100
736
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
101 def refresh(self):
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
102 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
103 return
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
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.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
106 self.taglist.untag([self.last_checked_value])
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
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.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
109 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
110
736
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
111 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
112 self.box.removeStyleName(self.STYLE["listItem-box-invalid"])
739
4545d48dee60 browser_side: improve ListPanel and TitlePanel
souliane <souliane@mailoo.org>
parents: 736
diff changeset
113 self.box.setVisibleLength(max(len(self.text), 10))
736
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
114 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
115 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
116 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
117 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
118 return
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
119
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
120 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
121 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
122 self.last_checked_value = self.text
739
4545d48dee60 browser_side: improve ListPanel and TitlePanel
souliane <souliane@mailoo.org>
parents: 736
diff changeset
123 self.box.setSelectionRange(len(self.text), 0)
736
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
124 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
125
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
126 def setFocus(self, focused):
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
127 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
128
736
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
129 def remove(self):
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
130 """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
131 self.removeFromParent()
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
132
736
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
133 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
134 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
135
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
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 class DraggableListItem(ListItem, DragWidget):
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
138 """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
139
736
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
140 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
141 """
736
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
142
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
143 @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
144 @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
145 @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
146 """
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
147 ListItem.__init__(self, listener, taglist, validate)
604
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
148 DragWidget.__init__(self)
736
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
149 self.addDragListener(listener)
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
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
152 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
153 """The user starts dragging the item."""
604
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
154 dt = event.dataTransfer
736
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
155 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
156 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
157
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 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
160 """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
161
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
162 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
163
739
4545d48dee60 browser_side: improve ListPanel and TitlePanel
souliane <souliane@mailoo.org>
parents: 736
diff changeset
164 def __init__(self, taglist):
4545d48dee60 browser_side: improve ListPanel and TitlePanel
souliane <souliane@mailoo.org>
parents: 736
diff changeset
165 """
4545d48dee60 browser_side: improve ListPanel and TitlePanel
souliane <souliane@mailoo.org>
parents: 736
diff changeset
166
4545d48dee60 browser_side: improve ListPanel and TitlePanel
souliane <souliane@mailoo.org>
parents: 736
diff changeset
167 @param taglist (quick_list_manager.QuickTagList): list manager
4545d48dee60 browser_side: improve ListPanel and TitlePanel
souliane <souliane@mailoo.org>
parents: 736
diff changeset
168 """
736
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
169 ClickHandler.__init__(self)
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
170 FocusHandler.__init__(self)
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
171 ChangeHandler.__init__(self)
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
172 KeyboardHandler.__init__(self)
739
4545d48dee60 browser_side: improve ListPanel and TitlePanel
souliane <souliane@mailoo.org>
parents: 736
diff changeset
173 self.taglist = taglist
736
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
174
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
175 def addItem(self, item):
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
176 raise NotImplementedError
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
177
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
178 def removeItem(self, item):
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
179 raise NotImplementedError
604
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
180
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
181 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
182 """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
183 #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
184 if isinstance(sender, Button):
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
185 item = sender.getParent()
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
186 self.removeItem(item)
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
187 elif isinstance(sender, ListBox):
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
188 # 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
189 textbox = sender._clickListeners[0]
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
190 self.checkValue(textbox)
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
191 else:
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
192 raise AssertionError
604
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
193
736
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
194 def onFocus(self, sender):
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
195 """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
196 #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
197 assert isinstance(sender, AutoCompleteTextBox)
739
4545d48dee60 browser_side: improve ListPanel and TitlePanel
souliane <souliane@mailoo.org>
parents: 736
diff changeset
198 sender.setCompletionItems(self.taglist.untagged)
604
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
199
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
200 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
201 """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
202 # 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
203 #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
204 assert isinstance(sender, AutoCompleteTextBox)
604
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
205 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
206 self.checkValue(sender)
604
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
207
736
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
208 def onChange(self, sender):
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
209 """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
210 # 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
211 #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
212 assert isinstance(sender, AutoCompleteTextBox)
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
213 self.checkValue(sender)
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
214
736
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
215 def checkValue(self, textbox):
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
216 """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
217 item = textbox.getParent()
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
218 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
219 # 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
220 return
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
221 item.refresh()
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
222 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
223 self.addItem()
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
224
736
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
225 class DraggableListItemHandler(ListItemHandler, DragHandler):
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
226 """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
227
739
4545d48dee60 browser_side: improve ListPanel and TitlePanel
souliane <souliane@mailoo.org>
parents: 736
diff changeset
228 def __init__(self, manager):
4545d48dee60 browser_side: improve ListPanel and TitlePanel
souliane <souliane@mailoo.org>
parents: 736
diff changeset
229 """
4545d48dee60 browser_side: improve ListPanel and TitlePanel
souliane <souliane@mailoo.org>
parents: 736
diff changeset
230
4545d48dee60 browser_side: improve ListPanel and TitlePanel
souliane <souliane@mailoo.org>
parents: 736
diff changeset
231 @param manager (ListManager): list manager
4545d48dee60 browser_side: improve ListPanel and TitlePanel
souliane <souliane@mailoo.org>
parents: 736
diff changeset
232 """
4545d48dee60 browser_side: improve ListPanel and TitlePanel
souliane <souliane@mailoo.org>
parents: 736
diff changeset
233 ListItemHandler.__init__(self, manager)
736
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
234 DragHandler.__init__(self)
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
235
739
4545d48dee60 browser_side: improve ListPanel and TitlePanel
souliane <souliane@mailoo.org>
parents: 736
diff changeset
236 @property
4545d48dee60 browser_side: improve ListPanel and TitlePanel
souliane <souliane@mailoo.org>
parents: 736
diff changeset
237 def manager(self):
4545d48dee60 browser_side: improve ListPanel and TitlePanel
souliane <souliane@mailoo.org>
parents: 736
diff changeset
238 return self.taglist
4545d48dee60 browser_side: improve ListPanel and TitlePanel
souliane <souliane@mailoo.org>
parents: 736
diff changeset
239
736
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
240 def onDragStart(self, event):
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
241 """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
242 self.manager.drop_target = None
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
243
736
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
244 def onDragEnd(self, event):
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
245 """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
246 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
247 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
248 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
249 return
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
250 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
251 target.addItem(text)
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
252 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
253
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
254
736
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
255 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
256 """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
257 # 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
258 # - 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
259 # - FlowPanel.insert doesn't work
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
260
736
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
261 STYLE = {"listPanel": "listPanel"}
739
4545d48dee60 browser_side: improve ListPanel and TitlePanel
souliane <souliane@mailoo.org>
parents: 736
diff changeset
262 ACCEPT_NEW_ENTRY = False
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
263
739
4545d48dee60 browser_side: improve ListPanel and TitlePanel
souliane <souliane@mailoo.org>
parents: 736
diff changeset
264 def __init__(self, manager, items=None):
736
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
265 """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
266
739
4545d48dee60 browser_side: improve ListPanel and TitlePanel
souliane <souliane@mailoo.org>
parents: 736
diff changeset
267 @param manager (ListManager): list manager
4545d48dee60 browser_side: improve ListPanel and TitlePanel
souliane <souliane@mailoo.org>
parents: 736
diff changeset
268 @param items (list): items to be set
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
269 """
736
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
270 FlowPanel.__init__(self)
739
4545d48dee60 browser_side: improve ListPanel and TitlePanel
souliane <souliane@mailoo.org>
parents: 736
diff changeset
271 DraggableListItemHandler.__init__(self, manager)
736
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
272 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
273 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
274 self.manager = manager
739
4545d48dee60 browser_side: improve ListPanel and TitlePanel
souliane <souliane@mailoo.org>
parents: 736
diff changeset
275 self.resetItems(items)
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
276
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
277 # 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
278 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
279 "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
280 "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
281 "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
282 }
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
283
604
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
284 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
285 """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
286 try:
648
6d3142b782c3 browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents: 604
diff changeset
287 libervia_widget.DropCell.onDrop(self, event)
604
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
288 except base_widget.NoLiberviaWidgetException:
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
289 pass
736
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
290
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
291 def getItem(self, text):
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
292 """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
293
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
294 @param text(unicode): item text
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
295 """
736
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
296 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
297 if child.text == text:
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
298 return child
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
299 return None
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
300
736
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
301 def getItems(self):
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
302 """Get the non empty items.
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
303
736
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
304 @return list(unicode)
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
305 """
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
306 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
307
736
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
308 def validateItem(self, text):
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
309 """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
310
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
311 @param text (unicode): item text to check
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
312 @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
313 - VALID if the item is valid
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
314 - 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
315 - DUPLICATE if the item is a duplicate
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
316 """
736
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
317 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
318 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
319
736
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
320 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
321 return ListItem.DUPLICATE # item already exists in this list so we suggest its deletion
739
4545d48dee60 browser_side: improve ListPanel and TitlePanel
souliane <souliane@mailoo.org>
parents: 736
diff changeset
322 if self.ACCEPT_NEW_ENTRY:
4545d48dee60 browser_side: improve ListPanel and TitlePanel
souliane <souliane@mailoo.org>
parents: 736
diff changeset
323 return ListItem.VALID
736
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
324 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
325
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
326 def addItem(self, text=""):
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
327 """Add an item.
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
328
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
329 @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
330 @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
331 """
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
332 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
333 return
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
334
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
335 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
336 self.add(item)
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
337
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
338 if self.last_item:
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
339 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
340 # 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
341 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
342 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
343 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
344 # 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
345 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
346 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
347 item.setText(text)
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 self.last_item = item
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
350 self.last_item.setFocus(True)
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
351
736
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
352 def removeItem(self, item):
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
353 """Remove an item.
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
354
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
355 @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
356 """
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
357 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
358 self.addItem("")
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
359 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
360
739
4545d48dee60 browser_side: improve ListPanel and TitlePanel
souliane <souliane@mailoo.org>
parents: 736
diff changeset
361 def resetItems(self, items):
4545d48dee60 browser_side: improve ListPanel and TitlePanel
souliane <souliane@mailoo.org>
parents: 736
diff changeset
362 """Reset the items.
4545d48dee60 browser_side: improve ListPanel and TitlePanel
souliane <souliane@mailoo.org>
parents: 736
diff changeset
363
4545d48dee60 browser_side: improve ListPanel and TitlePanel
souliane <souliane@mailoo.org>
parents: 736
diff changeset
364 @param items (list): items to be set
4545d48dee60 browser_side: improve ListPanel and TitlePanel
souliane <souliane@mailoo.org>
parents: 736
diff changeset
365 """
4545d48dee60 browser_side: improve ListPanel and TitlePanel
souliane <souliane@mailoo.org>
parents: 736
diff changeset
366 for child in self.getChildren():
4545d48dee60 browser_side: improve ListPanel and TitlePanel
souliane <souliane@mailoo.org>
parents: 736
diff changeset
367 child.remove()
4545d48dee60 browser_side: improve ListPanel and TitlePanel
souliane <souliane@mailoo.org>
parents: 736
diff changeset
368
4545d48dee60 browser_side: improve ListPanel and TitlePanel
souliane <souliane@mailoo.org>
parents: 736
diff changeset
369 self.addItem()
4545d48dee60 browser_side: improve ListPanel and TitlePanel
souliane <souliane@mailoo.org>
parents: 736
diff changeset
370 if not items:
4545d48dee60 browser_side: improve ListPanel and TitlePanel
souliane <souliane@mailoo.org>
parents: 736
diff changeset
371 return
4545d48dee60 browser_side: improve ListPanel and TitlePanel
souliane <souliane@mailoo.org>
parents: 736
diff changeset
372
4545d48dee60 browser_side: improve ListPanel and TitlePanel
souliane <souliane@mailoo.org>
parents: 736
diff changeset
373 items.sort()
4545d48dee60 browser_side: improve ListPanel and TitlePanel
souliane <souliane@mailoo.org>
parents: 736
diff changeset
374 for item in items:
4545d48dee60 browser_side: improve ListPanel and TitlePanel
souliane <souliane@mailoo.org>
parents: 736
diff changeset
375 self.addItem(unicode(item))
4545d48dee60 browser_side: improve ListPanel and TitlePanel
souliane <souliane@mailoo.org>
parents: 736
diff changeset
376
736
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
377
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
378 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
379 """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
380
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
381 STYLE = {"listManager-button": "group",
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
382 "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
383 }
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
384
736
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
385 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
386 """
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
387 @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
388 @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
389 """
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
390 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
391 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
392 self.lists = {}
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
393
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
394 if data:
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
395 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
396 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
397
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
398 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
399 """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
400
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
401 @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
402 @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
403 """
736
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
404 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
405 return
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 if items is None:
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
408 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 self.lists[key] = {"button": Button(key, Title=key, StyleName=self.STYLE["listManager-button"]),
739
4545d48dee60 browser_side: improve ListPanel and TitlePanel
souliane <souliane@mailoo.org>
parents: 736
diff changeset
411 "panel": ListPanel(self, items)}
736
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
412
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
413 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
414 self.insertRow(y)
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
415 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
416 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
417 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
418
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
419 try:
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
420 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
421 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
422 pass
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
423
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
424 def removeList(self, key):
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
425 """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
426
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
427 @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
428 """
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
429 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
430 (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
431 self.removeRow(y)
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
432 del self.lists[key]
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
433 self.untag(items)
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
434
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
435 def untag(self, items):
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
436 """Untag some items.
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
437
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
438 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
439
736
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
440 @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
441 """
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
442 items_assigned = set()
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
443 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
444 items_assigned.update(values)
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
445 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
446
736
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
447 def getItemsByKey(self):
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
448 """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
449
736
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
450 @return dict{unicode: list}
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
451 """
736
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
452 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
453
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
454 def getKeysByItem(self):
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
455 """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
456
736
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
457 @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
458 """
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
459 result = {}
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
460 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
461 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
462 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
463 return result
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
464
736
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
465 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
466 """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
467
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
468 @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
469 @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
470 - button widget
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
471 - list name (item key)
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
472 """
fe3c2357a8c9 fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 685
diff changeset
473 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
474 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
475 self.popup_menu.registerClickSender(self.lists[key]["button"])
740
b6510fd9ae15 browser_side: implements tags UI
souliane <souliane@mailoo.org>
parents: 739
diff changeset
476
b6510fd9ae15 browser_side: implements tags UI
souliane <souliane@mailoo.org>
parents: 739
diff changeset
477
b6510fd9ae15 browser_side: implements tags UI
souliane <souliane@mailoo.org>
parents: 739
diff changeset
478 class TagsPanel(base_panel.ToggleStackPanel):
b6510fd9ae15 browser_side: implements tags UI
souliane <souliane@mailoo.org>
parents: 739
diff changeset
479 """A toggle panel to set the tags"""
b6510fd9ae15 browser_side: implements tags UI
souliane <souliane@mailoo.org>
parents: 739
diff changeset
480
b6510fd9ae15 browser_side: implements tags UI
souliane <souliane@mailoo.org>
parents: 739
diff changeset
481 TAGS = _("Tags")
b6510fd9ae15 browser_side: implements tags UI
souliane <souliane@mailoo.org>
parents: 739
diff changeset
482
b6510fd9ae15 browser_side: implements tags UI
souliane <souliane@mailoo.org>
parents: 739
diff changeset
483 STYLE = {"main": "tagsPanel-main",
b6510fd9ae15 browser_side: implements tags UI
souliane <souliane@mailoo.org>
parents: 739
diff changeset
484 "tags": "tagsPanel-tags"}
b6510fd9ae15 browser_side: implements tags UI
souliane <souliane@mailoo.org>
parents: 739
diff changeset
485
741
c3cb68227cca browser_side: read and write tags from microblog data:
souliane <souliane@mailoo.org>
parents: 740
diff changeset
486 def __init__(self, suggested_tags, tags=None):
740
b6510fd9ae15 browser_side: implements tags UI
souliane <souliane@mailoo.org>
parents: 739
diff changeset
487 """
b6510fd9ae15 browser_side: implements tags UI
souliane <souliane@mailoo.org>
parents: 739
diff changeset
488
b6510fd9ae15 browser_side: implements tags UI
souliane <souliane@mailoo.org>
parents: 739
diff changeset
489 @param suggested_tags (list[unicode]): list of all suggested tags
b6510fd9ae15 browser_side: implements tags UI
souliane <souliane@mailoo.org>
parents: 739
diff changeset
490 @param tags (list[unicode]): already assigned tags
b6510fd9ae15 browser_side: implements tags UI
souliane <souliane@mailoo.org>
parents: 739
diff changeset
491 """
b6510fd9ae15 browser_side: implements tags UI
souliane <souliane@mailoo.org>
parents: 739
diff changeset
492 base_panel.ToggleStackPanel.__init__(self, Width="100%")
b6510fd9ae15 browser_side: implements tags UI
souliane <souliane@mailoo.org>
parents: 739
diff changeset
493 self.addStyleName(self.STYLE["main"])
741
c3cb68227cca browser_side: read and write tags from microblog data:
souliane <souliane@mailoo.org>
parents: 740
diff changeset
494
c3cb68227cca browser_side: read and write tags from microblog data:
souliane <souliane@mailoo.org>
parents: 740
diff changeset
495 if tags is None:
c3cb68227cca browser_side: read and write tags from microblog data:
souliane <souliane@mailoo.org>
parents: 740
diff changeset
496 tags = []
c3cb68227cca browser_side: read and write tags from microblog data:
souliane <souliane@mailoo.org>
parents: 740
diff changeset
497
740
b6510fd9ae15 browser_side: implements tags UI
souliane <souliane@mailoo.org>
parents: 739
diff changeset
498 self.tags = ListPanel(quick_list_manager.QuickTagList(suggested_tags), tags)
b6510fd9ae15 browser_side: implements tags UI
souliane <souliane@mailoo.org>
parents: 739
diff changeset
499 self.tags.addStyleName(self.STYLE["tags"])
b6510fd9ae15 browser_side: implements tags UI
souliane <souliane@mailoo.org>
parents: 739
diff changeset
500 self.tags.ACCEPT_NEW_ENTRY = True
b6510fd9ae15 browser_side: implements tags UI
souliane <souliane@mailoo.org>
parents: 739
diff changeset
501 self.add(self.tags, self.TAGS)
b6510fd9ae15 browser_side: implements tags UI
souliane <souliane@mailoo.org>
parents: 739
diff changeset
502 self.addStackChangeListener(self)
b6510fd9ae15 browser_side: implements tags UI
souliane <souliane@mailoo.org>
parents: 739
diff changeset
503
b6510fd9ae15 browser_side: implements tags UI
souliane <souliane@mailoo.org>
parents: 739
diff changeset
504 def onStackChanged(self, sender, index, visible=None):
b6510fd9ae15 browser_side: implements tags UI
souliane <souliane@mailoo.org>
parents: 739
diff changeset
505 if visible is None:
b6510fd9ae15 browser_side: implements tags UI
souliane <souliane@mailoo.org>
parents: 739
diff changeset
506 visible = sender.getWidget(index).getVisible()
b6510fd9ae15 browser_side: implements tags UI
souliane <souliane@mailoo.org>
parents: 739
diff changeset
507 text = ", ".join(self.getTags())
b6510fd9ae15 browser_side: implements tags UI
souliane <souliane@mailoo.org>
parents: 739
diff changeset
508 suffix = "" if (visible or not text) else (": %s" % text)
b6510fd9ae15 browser_side: implements tags UI
souliane <souliane@mailoo.org>
parents: 739
diff changeset
509 sender.setStackText(index, self.TAGS + suffix)
b6510fd9ae15 browser_side: implements tags UI
souliane <souliane@mailoo.org>
parents: 739
diff changeset
510
b6510fd9ae15 browser_side: implements tags UI
souliane <souliane@mailoo.org>
parents: 739
diff changeset
511 def getTags(self):
b6510fd9ae15 browser_side: implements tags UI
souliane <souliane@mailoo.org>
parents: 739
diff changeset
512 return self.tags.getItems()
b6510fd9ae15 browser_side: implements tags UI
souliane <souliane@mailoo.org>
parents: 739
diff changeset
513
b6510fd9ae15 browser_side: implements tags UI
souliane <souliane@mailoo.org>
parents: 739
diff changeset
514 def setTags(self, items):
b6510fd9ae15 browser_side: implements tags UI
souliane <souliane@mailoo.org>
parents: 739
diff changeset
515 self.tags.resetItems(items)
b6510fd9ae15 browser_side: implements tags UI
souliane <souliane@mailoo.org>
parents: 739
diff changeset
516