annotate src/browser/sat_browser/list_manager.py @ 604:c22b47d63fe2 frontends_multi_profiles

browser_side: fixed DragAutoCompleteTextBox for the list manager
author souliane <souliane@mailoo.org>
date Sat, 07 Feb 2015 20:35:45 +0100
parents 32dbbc941123
children 6d3142b782c3
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
340
ce5b33f499c5 dates update
Goffi <goffi@goffi.org>
parents: 339
diff changeset
5 # Copyright (C) 2013, 2014 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__)
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
22 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
23 from pyjamas.ui.FlowPanel import FlowPanel
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
24 from pyjamas.ui.AutoComplete import AutoCompleteTextBox
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
25 from pyjamas.ui.KeyboardListener import KEY_ENTER
604
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
26 from pyjamas.ui.DragWidget import DragWidget
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
27 from pyjamas.Timer import Timer
323
0b7934e75e76 misc: reorganization of the file panels.py + clean the modules import:
souliane <souliane@mailoo.org>
parents: 279
diff changeset
28
467
97c72fe4a5f2 browser_side: import fixes:
Goffi <goffi@goffi.org>
parents: 449
diff changeset
29 import base_panels
97c72fe4a5f2 browser_side: import fixes:
Goffi <goffi@goffi.org>
parents: 449
diff changeset
30 import base_widget
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
31
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
32 from sat_frontends.tools import jid
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
33
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
34
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
35 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
36
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
37 # HTML content for the removal button (image or text)
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
38 REMOVE_BUTTON = '<span class="itemRemoveIcon">x</span>'
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
39
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
40
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
41 # FIXME: dirty method and magic string to fix ASAP
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
42 def tryJID(obj):
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
43 return jid.JID(obj) if (isinstance(obj, unicode) and not obj.startswith('@')) else obj
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
44
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 class ListManager(object):
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
47 """A base class to manage one or several lists of items."""
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
48
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
49 def __init__(self, container, keys=None, items=None, offsets=None, style=None):
254
28d3315a8003 browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents: 241
diff changeset
50 """
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
51 @param container (FlexTable): FlexTable parent widget
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
52 @param keys (dict{unicode: dict{unicode: unicode}}): dict binding items
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
53 keys to their display config data.
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
54 @param items (list): list of items
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
55 @param offsets (dict): define widgets positions offsets within container:
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
56 - "x_first": the x offset for the first widget's row on the grid
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
57 - "x": the x offset for all widgets rows, except the first one if "x_first" is defined
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
58 - "y": the y offset for all widgets columns on the grid
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
59 @param style (dict): define CSS styles
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
60 """
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
61 self.container = container
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
62 self.keys = {} if keys is None else keys
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
63 self.items = [] if items is None else items
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
64 self.items.sort()
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
65
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
66 # store the list of items that are not assigned yet
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
67 self.items_remaining = [item for item in self.items]
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
68 self.items_remaining_sorted = True
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
69
254
28d3315a8003 browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents: 241
diff changeset
70 self.offsets = {"x_first": 0, "x": 0, "y": 0}
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
71 if offsets is not None:
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
72 if "x" in offsets and "x_first" not in offsets:
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
73 offsets["x_first"] = offsets["x"]
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
74 self.offsets.update(offsets)
241
86055ccf69c3 browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents: 232
diff changeset
75
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
76 self.style = {"keyItem": "itemKey",
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
77 "popupMenuItem": "itemKey",
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
78 "buttonCell": "itemButtonCell",
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
79 "keyPanel": "itemPanel",
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
80 "textBox": "itemTextBox",
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
81 "textBox-invalid": "itemTextBox-invalid",
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
82 "removeButton": "itemRemoveButton",
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
83 }
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
84 if style is not None:
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
85 self.style.update(style)
254
28d3315a8003 browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents: 241
diff changeset
86
28d3315a8003 browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents: 241
diff changeset
87 def createWidgets(self, title_format="%s"):
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
88 """Fill the container widget with one ListPanel per item key (some may be
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
89 hidden during the initialization).
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
90
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
91 @param title_format (unicode): format string for the title
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
92 """
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
93 self.children = {}
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
94 for key in self.keys:
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
95 self.addItemKey(key, title_format=title_format)
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
96
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
97 def addItemKey(self, key, data=None, title_format="%s"):
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
98 """Add to the container a Button and ListPanel for a new item key.
254
28d3315a8003 browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents: 241
diff changeset
99
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
100 @param key (unicode): item key
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
101 @param data (dict{unicode: unicode}): config data
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
102 """
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
103 key_data = self.keys.setdefault(key, {})
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
104 if data is not None:
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
105 key_data.update(data)
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
106 key_data["title"] = key # copy the key to its associated sub-map
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
107
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
108 button = Button(title_format % key)
256
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents: 254
diff changeset
109 button.setStyleName(self.style["keyItem"])
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
110 if hasattr(key_data, "desc"):
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
111 button.setTitle(key_data["desc"])
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
112 if "optional" not in key_data:
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
113 key_data["optional"] = False
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
114 button.setVisible(not key_data["optional"])
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
115 y = len(self.children) + self.offsets["y"]
254
28d3315a8003 browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents: 241
diff changeset
116 x = self.offsets["x_first"] if y == self.offsets["y"] else self.offsets["x"]
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
117
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
118 self.container.insertRow(y)
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
119 self.container.setWidget(y, x, button)
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
120 self.container.getCellFormatter().setStyleName(y, x, self.style["buttonCell"])
254
28d3315a8003 browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents: 241
diff changeset
121
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
122 _child = ListPanel(self, key_data, self.style)
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
123 self.container.setWidget(y, x + 1, _child)
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
124
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
125 self.children[key] = {}
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
126 self.children[key]["button"] = button
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
127 self.children[key]["panel"] = _child
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
128
254
28d3315a8003 browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents: 241
diff changeset
129 if hasattr(self, "popup_menu"):
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
130 # self.registerPopupMenuPanel has been called yet
254
28d3315a8003 browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents: 241
diff changeset
131 self.popup_menu.registerClickSender(button)
28d3315a8003 browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents: 241
diff changeset
132
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
133 def removeItemKey(self, key):
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
134 """Remove from the container a ListPanel representing an item key, and all
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
135 its associated data.
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
136
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
137 @param key (unicode): item key
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
138 """
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
139 items = self.children[key]["panel"].getItems()
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
140 (y, x) = self.container.getIndex(self.children[key]["button"])
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
141 self.container.removeRow(y)
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
142 del self.children[key]
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
143 del self.keys[key]
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
144 self.addToRemainingList(items)
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
145
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
146 def refresh(self, hide_everything=False):
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
147 """Set visible the sub-panels that are non optional or non empty, hide
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
148 the rest. Setting the attribute "hide_everything" to True you can also
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
149 hide everything.
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
150
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
151 @param hide_everything (boolean): set to True to hide everything
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
152 """
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
153 for key in self.children:
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
154 self.setItemPanelVisible(key, False)
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
155 if hide_everything:
348
83454ba70a9c browser_side: added a method setVisible to ListManager
souliane <souliane@mailoo.org>
parents: 340
diff changeset
156 return
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
157 for key, items in self.getItemsByKey().iteritems():
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
158 if len(items) > 0 or not self.keys[key]["optional"]:
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
159 self.setItemPanelVisible(key, True)
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
160
348
83454ba70a9c browser_side: added a method setVisible to ListManager
souliane <souliane@mailoo.org>
parents: 340
diff changeset
161 def setVisible(self, visible):
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
162 self.refresh(not visible)
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
163
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
164 def setItemPanelVisible(self, key, visible=True, sender=None):
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
165 """Set the item key's widgets visibility.
348
83454ba70a9c browser_side: added a method setVisible to ListManager
souliane <souliane@mailoo.org>
parents: 340
diff changeset
166
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
167 @param key (unicode): item key
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
168 @param visible (bool): set to True to display the widgets
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
169 @param sender
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
170 """
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
171 self.children[key]["button"].setVisible(visible)
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
172 self.children[key]["panel"].setVisible(visible)
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
173
254
28d3315a8003 browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents: 241
diff changeset
174 @property
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
175 def items_remaining(self):
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
176 """Return the unused items."""
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
177 if not self.items_remaining_sorted:
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
178 self.items_remaining.sort()
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
179 self.items_remaining_sorted = True
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
180 return self.items_remaining
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
181
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
182 def setRemainingListUnsorted(self):
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
183 """Mark the list of unused items as being unsorted."""
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
184 self.items_remaining_sorted = False
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
185
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
186 def removeFromRemainingList(self, items):
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
187 """Remove some items from the list of unused items.
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
188
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
189 @param items (list): items to be removed
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
190 """
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
191 for item in items:
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
192 if item in self.items_remaining:
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
193 self.items_remaining.remove(item)
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
194
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
195 def addToRemainingList(self, items, ignore_key=None):
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
196 """Add some items to the list of unused items. Check first if the
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
197 items are really not used in any ListPanel.
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
198
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
199 @param items (list): items to be removed
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
200 @param ignore_key (unicode): item key to be ignored while checking
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
201 """
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
202 items_assigned = set()
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
203 for key, current_items in self.getItemsByKey().iteritems():
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
204 if ignore_key is not None and key == ignore_key:
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
205 continue
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
206 items_assigned.update(current_items)
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
207 for item in items:
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
208 if item not in self.items or item in self.items_remaining or item in items_assigned:
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
209 continue
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
210 self.items_remaining.append(item)
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
211 self.setRemainingListUnsorted()
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
212
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
213 def resetItems(self, data={}):
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
214 """Repopulate all the lists (one per item key) with the given items.
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
215
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
216 @param data (dict{unicode: list}): dict binding items keys to items.
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
217 """
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
218 for key in self.keys:
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
219 if key in data:
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
220 self.children[key]["panel"].resetItems(data[key])
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
221 else:
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
222 self.children[key]["panel"].resetItems([])
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
223 self.refresh()
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
224
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
225 def getItemsByKey(self):
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
226 """Get all the items by key.
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
227
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
228 @return: dict{unicode: set}
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
229 """
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
230 return {key: self.children[key]["panel"].getItems() for key in self.children}
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
231
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
232 def getKeysByItem(self):
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
233 """Get all the keys by item.
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
234
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
235 @return: dict{object: set(unicode)}
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
236 """
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
237 result = {}
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
238 for key in self.children:
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
239 for item in self.children[key]["panel"].getItems():
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
240 result.setdefault(item, set()).add(key)
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
241 return result
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
242
254
28d3315a8003 browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents: 241
diff changeset
243 def registerPopupMenuPanel(self, entries, hide, callback):
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
244 """Register a popup menu panel for the item keys buttons.
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
245
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
246 @param entries (dict{unicode: dict{unicode: unicode}}): menu entries
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
247 @param hide (callable): method to call in order to know if a menu item
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
248 should be hidden from the menu. Takes in the button widget and the
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
249 item key and returns a boolean.
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
250 @param callback (callable): common callback for all menu items, takes in
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
251 the button widget and the item key.
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
252 """
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
253 self.popup_menu = base_panels.PopupMenuPanel(entries, hide, callback, style={"item": self.style["popupMenuItem"]})
254
28d3315a8003 browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents: 241
diff changeset
254
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
255
604
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
256 class DragAutoCompleteTextBox(AutoCompleteTextBox, DragWidget):
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
257 """A draggable AutoCompleteTextBox which is used for representing an item."""
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
258
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
259 def __init__(self, list_panel, event_cbs, style):
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
260 """
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
261
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
262 @param list_panel (ListPanel)
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
263 @param event_cbs (list[callable])
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
264 @param style (dict)
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
265 """
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
266 AutoCompleteTextBox.__init__(self)
604
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
267 DragWidget.__init__(self)
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
268 self.list_panel = list_panel
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
269 self.event_cbs = event_cbs
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
270 self.style = style
604
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
271 self.addStyleName(style["textBox"])
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
272 self.reset()
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
273
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
274 # Parent classes already init self as an handler for these events
254
28d3315a8003 browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents: 241
diff changeset
275 self.addMouseListener(self)
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
276 self.addFocusListener(self)
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
277 self.addChangeListener(self)
604
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
278
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
279 def onDragStart(self, event):
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
280 """The user starts dragging the text box."""
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
281 self.list_panel.manager.target_drop_cell = None
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
282 self.setSelectionRange(len(self.getText()), 0)
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
283
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
284 dt = event.dataTransfer
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
285 dt.setData('text/plain', "%s\n%s" % (self.getText(), "CONTACT_TEXTBOX"))
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
286 dt.setDragImage(self.getElement(), 15, 15)
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
287
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
288 def onDragEnd(self, event):
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
289 """The user dropped the text box."""
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
290 target = self.list_panel.manager.target_drop_cell # parent or another ListPanel
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
291 if self.getText() == "" or target is None:
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
292 return
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
293 self.event_cbs["drop"](self, target)
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
294
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
295 def onClick(self, sender):
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
296 """The choices list is clicked"""
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
297 assert sender == self.choices
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
298 AutoCompleteTextBox.onClick(self, sender)
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
299 self.validate()
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
300
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
301 def onChange(self, sender):
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
302 """The list selection or the text has been changed"""
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
303 assert sender == self.choices or sender == self
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
304 if sender == self.choices:
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
305 AutoCompleteTextBox.onChange(self, sender)
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
306 self.validate()
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
307
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
308 def onKeyUp(self, sender, keycode, modifiers):
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
309 """Listen for key stroke"""
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
310 assert sender == self
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
311 AutoCompleteTextBox.onKeyUp(self, sender, keycode, modifiers)
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
312 if keycode == KEY_ENTER:
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
313 self.validate()
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
314
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
315 def onMouseMove(self, sender):
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
316 """Mouse enters the area of a DragAutoCompleteTextBox."""
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
317 assert sender == self
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
318 if hasattr(sender, "remove_btn"):
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
319 sender.remove_btn.setVisible(True)
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
320
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
321 def onMouseLeave(self, sender):
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
322 """Mouse leaves the area of a DragAutoCompleteTextBox."""
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
323 assert sender == self
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
324 if hasattr(sender, "remove_btn"):
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
325 Timer(1500, lambda timer: sender.remove_btn.setVisible(False))
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
326
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
327 def onFocus(self, sender):
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
328 """The DragAutoCompleteTextBox has the focus."""
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
329 assert sender == self
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
330 # FIXME: this raises runtime JS error "Permission denied to access property..." when you drag the object
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
331 #sender.setSelectionRange(0, len(sender.getText()))
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
332 sender.event_cbs["focus"](sender)
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
333
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
334 def reset(self):
604
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
335 """Reset the text box"""
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
336 self.setText("")
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
337 self.setValid()
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
338
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
339 def setValid(self, valid=True):
604
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
340 """Change the style according to the text validity."""
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
341 if self.getText() == "":
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
342 valid = True
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
343 if valid:
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
344 self.removeStyleName(self.style["textBox-invalid"])
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
345 else:
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
346 self.addStyleName(self.style["textBox-invalid"])
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
347 self.valid = valid
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
348
604
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
349 def validate(self):
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
350 """Check if the text is valid, update the style."""
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
351 self.setSelectionRange(len(self.getText()), 0)
604
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
352 self.event_cbs["validate"](self)
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
353
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
354 def setRemoveButton(self):
604
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
355 """Add the remove button after the text box."""
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
356
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
357 def remove_cb(sender):
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
358 """Callback for the button to remove this item."""
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
359 self.list_panel.remove(self)
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
360 self.list_panel.remove(self.remove_btn)
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
361 self.event_cbs["remove"](self)
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
362
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
363 self.remove_btn = Button(REMOVE_BUTTON, remove_cb, Visible=False)
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
364 self.remove_btn.setStyleName(self.style["removeButton"])
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
365 self.list_panel.add(self.remove_btn)
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
366
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
367 def removeOrReset(self):
604
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
368 """Remove the text box if the remove button exists, or reset the text box."""
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
369 if hasattr(self, "remove_btn"):
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
370 self.remove_btn.click()
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
371 else:
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
372 self.reset()
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
373
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
374
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
375 VALID = 1
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
376 INVALID = 2
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
377 DELETE = 3
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
378
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
379
604
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
380 class ListPanel(FlowPanel, base_widget.DropCell):
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
381 """Panel used for listing items sharing the same key. The key is showed as
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
382 a Button to which you can bind a popup menu and the items are represented
604
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
383 with a sequence of DragAutoCompleteTextBox."""
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
384 # XXX: beware that pyjamas.ui.FlowPanel is not fully implemented yet and can not be used with pyjamas.ui.Label
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
385
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
386 def __init__(self, manager, data, style={}):
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
387 """Initialization with a button and a DragAutoCompleteTextBox.
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
388
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
389 @param manager (ListManager)
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
390 @param data (dict{unicode: unicode})
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
391 @param style (dict{unicode: unicode})
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
392 """
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
393 FlowPanel.__init__(self, Visible=(False if data["optional"] else True))
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
394
604
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
395 def setTargetDropCell(host, item):
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
396 self.manager.target_drop_cell = self
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
397
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
398 # FIXME: dirty magic strings '@' and '@@'
604
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
399 drop_cbs = {"GROUP": lambda host, item: self.addItem("@%s" % item),
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
400 "CONTACT": lambda host, item: self.addItem(tryJID(item)),
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
401 "CONTACT_TITLE": lambda host, item: self.addItem('@@'),
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
402 "CONTACT_TEXTBOX": setTargetDropCell
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
403 }
604
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
404 base_widget.DropCell.__init__(self, None)
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
405 self.drop_keys = drop_cbs
254
28d3315a8003 browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents: 241
diff changeset
406 self.style = style
28d3315a8003 browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents: 241
diff changeset
407 self.addStyleName(self.style["keyPanel"])
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
408 self.manager = manager
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
409 self.key = data["title"]
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
410 self._addTextBox()
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
411
604
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
412 def onDrop(self, event):
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
413 try:
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
414 base_widget.DropCell.onDrop(self, event)
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
415 except base_widget.NoLiberviaWidgetException:
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
416 pass
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
417
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
418 def _addTextBox(self, switchPrevious=False):
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
419 """Add an empty text box to the last position.
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
420
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
421 @param switchPrevious (bool): if True, simulate an insertion before the
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
422 current last textbox by switching the texts and valid states
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
423 @return: an DragAutoCompleteTextBox, the created text box or the
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
424 previous one if switchPrevious is True.
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
425 """
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
426 if hasattr(self, "_last_textbox"):
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
427 if self._last_textbox.getText() == "":
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
428 return
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
429 self._last_textbox.setRemoveButton()
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
430 else:
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
431 switchPrevious = False
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
432
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
433 def focus_cb(sender):
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
434 if sender != self._last_textbox:
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
435 # save the current value before it's being modified
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
436 self.manager.addToRemainingList([tryJID(sender.getText())], ignore_key=self.key)
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
437
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
438 items = [unicode(item) for item in self.manager.items_remaining]
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
439 sender.setCompletionItems(items)
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
440
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
441 def add_cb(sender):
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
442 self.addItem(tryJID(sender.getText()), sender)
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
443
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
444 def remove_cb(sender):
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
445 """Callback for the button to remove this item."""
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
446 self.manager.addToRemainingList([tryJID(sender.getText())])
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
447 self.manager.setRemainingListUnsorted()
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
448 self._last_textbox.setFocus(True)
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
449
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
450 def drop_cb(sender, target):
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
451 """Callback when the textbox is drag-n-dropped."""
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
452 list_panel = sender.list_panel
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
453 if target != list_panel and target.addItem(tryJID(sender.getText())):
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
454 sender.removeOrReset()
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
455 else:
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
456 list_panel.manager.removeFromRemainingList([tryJID(sender.getText())])
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
457
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
458 events_cbs = {"focus": focus_cb, "validate": add_cb, "remove": remove_cb, "drop": drop_cb}
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
459 textbox = DragAutoCompleteTextBox(self, events_cbs, self.style)
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
460 self.add(textbox)
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
461 if switchPrevious:
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
462 textbox.setText(self._last_textbox.getText())
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
463 textbox.setValid(self._last_textbox.valid)
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
464 self._last_textbox.reset()
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
465 previous = self._last_textbox
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
466 self._last_textbox = textbox
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
467 return previous if switchPrevious else textbox
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
468
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
469 def _checkItem(self, item, modify):
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
470 """
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
471 @param item (object): the item to check
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
472 @param modify (bool): True if the item is being modified
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
473 @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
474 - VALID if the item is valid
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
475 - INVALID if the item is not valid but can be displayed
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
476 - DELETE if the item should not be displayed at all
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
477 """
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
478 def count(list_, item):
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
479 # XXX: list.count in not implemented by pyjamas
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
480 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
481
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
482 if not item:
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
483 return DELETE
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
484 if count(self.getItems(), item) > (1 if modify else 0):
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
485 return DELETE
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
486 return VALID if item in self.manager.items else INVALID
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
487
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
488 def addItem(self, item, sender=None):
604
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
489 """Try to add an item. It will be added if it's a valid one.
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
490
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
491 @param item (object): item to be added
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
492 @param (DragAutoCompleteTextBox): widget triggering the event
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
493 @param sender: if True, the item will be "written" to the last textbox
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
494 and a new text box will be added afterward.
604
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
495 @return: True if the item has been added.
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
496 """
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
497 valid = self._checkItem(item, sender is not None)
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
498 item_s = unicode(item)
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
499 if sender is None:
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
500 # method has been called not to modify but to add an item
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
501 if valid == VALID:
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
502 # eventually insert before the last textbox if it's not empty
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
503 sender = self._addTextBox(True) if self._last_textbox.getText() != "" else self._last_textbox
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
504 sender.setText(item_s)
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
505 else:
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
506 sender.setValid(valid == VALID)
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
507 if valid != VALID:
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
508 if sender is not None and valid == DELETE:
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
509 sender.removeOrReset()
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
510 return False
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
511 if sender == self._last_textbox:
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
512 self._addTextBox()
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
513 sender.setVisibleLength(len(item_s))
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
514 self.manager.removeFromRemainingList([item])
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
515 self._last_textbox.setFocus(True)
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
516 return True
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
517
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
518 def emptyItems(self):
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
519 """Empty the list of items."""
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
520 for child in self.getChildren():
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
521 if hasattr(child, "remove_btn"):
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
522 child.remove_btn.click()
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
523
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
524 def resetItems(self, items):
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
525 """Repopulate the items.
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
526
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
527 @param items (list): the items to be listed.
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
528 """
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
529 self.emptyItems()
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
530 if isinstance(items, set):
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
531 items = list(items)
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
532 items.sort()
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
533 for item in items:
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
534 self.addItem(item)
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
535
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
536 def getItems(self):
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
537 """Get the listed items.
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
538
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
539 @return: set"""
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
540 items = set()
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
541 for widget in self.getChildren():
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
542 if isinstance(widget, DragAutoCompleteTextBox) and widget.getText() != "":
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
543 items.add(tryJID(widget.getText()))
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
544 return items