Mercurial > libervia-web
annotate browser_side/list_manager.py @ 254:28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
- renamed most occurences of "recipient" to "contact" and "recipient type" to "contact key" or "list"
- data to represent the lists and autocomplete values are parametrized
- UI elements styles are set by default but can be ovewritten by a sub-class
- popup menu for the list Button element has to be set with registerPopupMenuPanel
- richtext UI uses the definitions from sat.tool.frontends.composition
Know issues:
- drag and drop AutoCompleteTextBox corrupts the list of remaining autocomplete values
- selecting an autocomplete value with the mouse and not keybord is not working properly
author | souliane <souliane@mailoo.org> |
---|---|
date | Sat, 09 Nov 2013 09:38:17 +0100 |
parents | browser_side/recipients.py@86055ccf69c3 |
children | 0e7f3944bd27 |
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 |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
4 """ |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
5 Libervia: a Salut à Toi frontend |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
6 Copyright (C) 2013 Adrien Cossa <souliane@mailoo.org> |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
7 |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
8 This program is free software: you can redistribute it and/or modify |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
9 it under the terms of the GNU Affero General Public License as published by |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
10 the Free Software Foundation, either version 3 of the License, or |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
11 (at your option) any later version. |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
12 |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
13 This program is distributed in the hope that it will be useful, |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
14 but WITHOUT ANY WARRANTY; without even the implied warranty of |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
16 GNU Affero General Public License for more details. |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
17 |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
18 You should have received a copy of the GNU Affero General Public License |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
19 along with this program. If not, see <http://www.gnu.org/licenses/>. |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
20 """ |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
21 |
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.Grid import Grid |
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.Button import Button |
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.ListBox import ListBox |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
25 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
|
26 from pyjamas.ui.AutoComplete import AutoCompleteTextBox |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
27 from pyjamas.ui.Label import Label |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
28 from pyjamas.ui.HorizontalPanel import HorizontalPanel |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
29 from pyjamas.ui.VerticalPanel import VerticalPanel |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
30 from pyjamas.ui.DialogBox import DialogBox |
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.KeyboardListener import KEY_ENTER, KeyboardHandler |
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.MouseListener import MouseHandler |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
33 from pyjamas.ui.FocusListener import FocusHandler |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
34 from pyjamas.ui.DropWidget import DropWidget |
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.DragWidget import DragWidget |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
36 |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
37 from pyjamas.Timer import Timer |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
38 from pyjamas import DOM |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
39 |
241
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
232
diff
changeset
|
40 import panels |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
41 from pyjamas.ui import FocusListener, KeyboardListener, MouseListener, Event |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
42 |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
43 # HTML content for the removal button (image or text) |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
44 REMOVE_BUTTON = '<span class="richTextRemoveIcon">x</span>' |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
45 |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
46 # Item to be considered for an empty list box selection. |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
47 # Could be whatever which doesn't look like a JID or a group name. |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
48 EMPTY_SELECTION_ITEM = "" |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
49 |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
50 |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
51 class ListManager(): |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
52 """A manager for sub-panels to assign elements to lists.""" |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
53 |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
54 def __init__(self, parent, keys_dict={}, contact_list=[], offsets={}, style={}): |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
55 """ |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
56 @param parent: FlexTable parent widget for the manager |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
57 @param keys_dict: dict with the contact keys mapped to data |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
58 @param contact_list: list of string (the contact JID userhosts) |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
59 @param offsets: dict to set widget positions offset within parent |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
60 - "x_first": the x offset for the first widget's row on the grid |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
61 - "x": the x offset for all widgets rows, except the first one if "x_first" is defined |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
62 - "y": the y offset for all widgets columns on the grid |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
63 """ |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
64 self.host = parent.host |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
65 self._parent = parent |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
66 if isinstance(keys_dict, set) or isinstance(keys_dict, list): |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
67 tmp = {} |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
68 for key in keys_dict: |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
69 tmp[key] = {} |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
70 keys_dict = tmp |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
71 self.__keys_dict = keys_dict |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
72 if isinstance(contact_list, set): |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
73 contact_list = list(contact_list) |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
74 self.__list = contact_list |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
75 self.__list.sort() |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
76 # store the list of contacts that are not assigned yet |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
77 self.__remaining_list = [] |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
78 self.__remaining_list.extend(self.__list) |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
79 # mark a change to sort the list before it's used |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
80 self.__remaining_list_sorted = True |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
81 |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
82 self.offsets = {"x_first": 0, "x": 0, "y": 0} |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
83 if "x" in offsets and not "x_first" in offsets: |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
84 offsets["x_first"] = offsets["x"] |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
85 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
|
86 |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
87 self.style = { |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
88 "keyItem": "recipientTypeItem", |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
89 "buttonCell": "recipientButtonCell", |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
90 "dragoverPanel": "dragover-recipientPanel", |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
91 "keyPanel": "recipientPanel", |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
92 "textBox": "recipientTextBox", |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
93 "removeButton": "recipientRemoveButton", |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
94 } |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
95 self.style.update(style) |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
96 |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
97 def createWidgets(self, title_format="%s"): |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
98 """Fill the parent grid with all the widgets (some may be 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
|
99 self.__children = {} |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
100 for key in self.__keys_dict: |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
101 self.addContactKey(key, title_format) |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
102 |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
103 def addContactKey(self, key, dict_={}, title_format="%s"): |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
104 if key not in self.__keys_dict: |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
105 self.__keys_dict[key] = dict_ |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
106 # copy the key to its associated sub-map |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
107 self.__keys_dict[key]["title"] = key |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
108 self._addChild(self.__keys_dict[key], title_format) |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
109 |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
110 def _addChild(self, entry, title_format): |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
111 """Add a button and FlowPanel for the corresponding map entry.""" |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
112 button = Button(title_format % entry["title"]) |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
113 button.addStyleName(self.style["keyItem"]) |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
114 if hasattr(entry, "desc"): |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
115 button.setTitle(entry["desc"]) |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
116 if not "optional" in entry: |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
117 entry["optional"] = False |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
118 button.setVisible(not entry["optional"]) |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
119 y = len(self.__children) + self.offsets["y"] |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
120 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
|
121 |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
122 self._parent.setWidget(y, x, button) |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
123 self._parent.getCellFormatter().setStyleName(y, x, self.style["buttonCell"]) |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
124 |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
125 _child = ListPanel(self, entry, self.style) |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
126 self._parent.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
|
127 |
241
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
232
diff
changeset
|
128 self.__children[entry["title"]] = {} |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
232
diff
changeset
|
129 self.__children[entry["title"]]["button"] = button |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
232
diff
changeset
|
130 self.__children[entry["title"]]["panel"] = _child |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
131 |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
132 if hasattr(self, "popup_menu"): |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
133 # this is done if self.registerPopupMenuPanel has been called yet |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
134 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
|
135 |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
136 def _refresh(self): |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
137 """Set visible the sub-panels that are non optional or non empty, hide the rest.""" |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
138 for key in self.__children: |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
139 self.setContactPanelVisible(key, False) |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
140 _map = self.getContacts() |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
141 for key in _map: |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
142 if len(_map[key]) > 0 or not self.__keys_dict[key]["optional"]: |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
143 self.setContactPanelVisible(key, True) |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
144 |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
145 def setContactPanelVisible(self, key, visible=True, sender=None): |
241
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
232
diff
changeset
|
146 """Do not remove the "sender" param as it is needed for the context menu.""" |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
147 self.__children[key]["button"].setVisible(visible) |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
148 self.__children[key]["panel"].setVisible(visible) |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
149 |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
150 @property |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
151 def list(self): |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
152 """Return the full list of potential contacts.""" |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
153 return self.__list |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
154 |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
155 @property |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
156 def keys(self): |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
157 return self.__keys_dict.keys() |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
158 |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
159 @property |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
160 def keys_dict(self): |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
161 return self.__keys_dict |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
162 |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
163 @property |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
164 def remaining_list(self): |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
165 """Return the contacts that have not been selected yet.""" |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
166 if not self.__remaining_list_sorted: |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
167 self.__remaining_list_sorted = True |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
168 self.__remaining_list.sort() |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
169 return self.__remaining_list |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
170 |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
171 def setRemainingListUnsorted(self): |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
172 """Mark a change (deletion) so the list will be sorted before it's used.""" |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
173 self.__remaining_list_sorted = False |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
174 |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
175 def removeFromRemainingList(self, contact_): |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
176 """Remove an available contact after it has been added to a sub-panel.""" |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
177 if contact_ in self.__remaining_list: |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
178 self.__remaining_list.remove(contact_) |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
179 |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
180 def addToRemainingList(self, contact_): |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
181 """Add a contact after it has been removed from a sub-panel.""" |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
182 if contact_ not in self.__list or contact_ in self.__remaining_list: |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
183 return |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
184 self.__remaining_list.append(contact_) |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
185 self.__sort_remaining_list = True |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
186 |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
187 def setContacts(self, _map={}): |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
188 """Set the contacts for each contact key.""" |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
189 for key in self.__keys_dict: |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
190 if key in _map: |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
191 self.__children[key]["panel"].setContacts(_map[key]) |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
192 else: |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
193 self.__children[key]["panel"].setContacts([]) |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
194 self._refresh() |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
195 |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
196 def getContacts(self): |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
197 """Get the contacts for all the lists. |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
198 @return: a mapping between keys and contact lists.""" |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
199 _map = {} |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
200 for key in self.__children: |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
201 _map[key] = self.__children[key]["panel"].getContacts() |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
202 return _map |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
203 |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
204 def setTargetDropCell(self, panel): |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
205 """Used to drag and drop the contacts from one panel to another.""" |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
206 self._target_drop_cell = panel |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
207 |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
208 def getTargetDropCell(self): |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
209 """Used to drag and drop the contacts from one panel to another.""" |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
210 return self._target_drop_cell |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
211 |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
212 def registerPopupMenuPanel(self, entries, hide, callback): |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
213 "Register a popup menu panel that will be bound to all contact keys elements." |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
214 self.popup_menu = panels.PopupMenuPanel(entries=entries, hide=hide, callback=callback, item_style="recipientTypeItem") |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
215 |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
216 |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
217 class DragAutoCompleteTextBox(AutoCompleteTextBox, DragWidget, MouseHandler): |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
218 """A draggable AutoCompleteTextBox which is used for representing a contact. |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
219 This class is NOT generic because of the onDragEnd method which call methods |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
220 from ListPanel. It's probably not reusable for another scenario. |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
221 """ |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
222 |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
223 def __init__(self): |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
224 AutoCompleteTextBox.__init__(self) |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
225 DragWidget.__init__(self) |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
226 self.addMouseListener(self) |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
227 |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
228 def onDragStart(self, event): |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
229 dt = event.dataTransfer |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
230 # The group prefix "@" is already in text so we use only the "CONTACT" type |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
231 dt.setData('text/plain', "%s\n%s" % (self.getText(), "CONTACT_TEXTBOX")) |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
232 |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
233 def onDragEnd(self, event): |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
234 if self.getText() == "": |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
235 return |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
236 # get the ListPanel containing self |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
237 parent = self.getParent() |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
238 while parent is not None and not isinstance(parent, ListPanel): |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
239 parent = parent.getParent() |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
240 if parent is None: |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
241 return |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
242 # it will return parent again or another ListPanel |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
243 target = parent.getTargetDropCell() |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
244 if target == parent: |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
245 return |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
246 target.addContact(self.getText()) |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
247 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
|
248 # self is not the last textbox, just remove it |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
249 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
|
250 else: |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
251 # reset the value of the last textbox |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
252 self.setText("") |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
253 |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
254 def onMouseMove(self, sender): |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
255 """Mouse enters the area of a DragAutoCompleteTextBox.""" |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
256 if hasattr(sender, "remove_btn"): |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
257 sender.remove_btn.setVisible(True) |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
258 |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
259 def onMouseLeave(self, sender): |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
260 """Mouse leaves the area of a DragAutoCompleteTextBox.""" |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
261 if hasattr(sender, "remove_btn"): |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
262 Timer(1500, lambda: sender.remove_btn.setVisible(False)) |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
263 |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
264 |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
265 class DropCell(DropWidget): |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
266 """A cell where you can drop widgets. This class is NOT generic because of |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
267 onDrop which uses methods from ListPanel. It has been created to |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
268 separate the drag and drop methods from the others and add a bit of |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
269 lisibility, but it's probably not reusable for another scenario. |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
270 """ |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
271 |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
272 def __init__(self, host): |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
273 DropWidget.__init__(self) |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
274 |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
275 def onDragEnter(self, event): |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
276 self.addStyleName(self.style["dragoverPanel"]) |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
277 DOM.eventPreventDefault(event) |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
278 |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
279 def onDragLeave(self, event): |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
280 if event.clientX <= self.getAbsoluteLeft() or event.clientY <= self.getAbsoluteTop()\ |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
281 or event.clientX >= self.getAbsoluteLeft() + self.getOffsetWidth() - 1\ |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
282 or event.clientY >= self.getAbsoluteTop() + self.getOffsetHeight() - 1: |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
283 # We check that we are inside widget's box, and we don't remove the style in this case because |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
284 # if the mouse is over a widget inside the DropWidget, we don't want the style to be removed |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
285 self.removeStyleName(self.style["dragoverPanel"]) |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
286 |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
287 def onDragOver(self, event): |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
288 DOM.eventPreventDefault(event) |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
289 |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
290 def onDrop(self, event): |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
291 DOM.eventPreventDefault(event) |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
292 dt = event.dataTransfer |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
293 # 'text', 'text/plain', and 'Text' are equivalent. |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
294 item, item_type = dt.getData("text/plain").split('\n') # Workaround for webkit, only text/plain seems to be managed |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
295 if item_type and item_type[-1] == '\0': # Workaround for what looks like a pyjamas bug: the \0 should not be there, and |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
296 item_type = item_type[:-1] # .strip('\0') and .replace('\0','') don't work. TODO: check this and fill a bug report |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
297 if item_type == "GROUP": |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
298 item = "@%s" % item |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
299 self.addContact(item) |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
300 elif item_type == "CONTACT": |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
301 self.addContact(item) |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
302 elif item_type == "CONTACT_TEXTBOX": |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
303 self._parent.setTargetDropCell(self) |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
304 pass |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
305 else: |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
306 return |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
307 self.removeStyleName(self.style["dragoverPanel"]) |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
308 |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
309 |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
310 class ListPanel(FlowPanel, DropCell, FocusHandler, KeyboardHandler): |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
311 """Sub-panel used for each contact key. Beware that pyjamas.ui.FlowPanel |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
312 is not fully implemented yet and can not be used with pyjamas.ui.Label.""" |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
313 |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
314 def __init__(self, parent, entry, style={}): |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
315 """Initialization with a button and a DragAutoCompleteTextBox.""" |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
316 FlowPanel.__init__(self, Visible=(False if entry["optional"] else True)) |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
317 DropCell.__init__(self) |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
318 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
|
319 self.addStyleName(self.style["keyPanel"]) |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
320 self._parent = parent |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
321 self.host = parent.host |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
322 |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
323 self._last_textbox = None |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
324 self.__remove_cbs = [] |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
325 |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
326 self.__resetLastTextBox() |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
327 |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
328 def __resetLastTextBox(self, setFocus=True): |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
329 """Reset the last input text box with KeyboardListener.""" |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
330 if self._last_textbox is None: |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
331 self._last_textbox = DragAutoCompleteTextBox() |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
332 self._last_textbox.addStyleName(self.style["textBox"]) |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
333 self._last_textbox.addKeyboardListener(self) |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
334 self._last_textbox.addFocusListener(self) |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
335 else: |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
336 # ensure we move it to the last position |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
337 self.remove(self._last_textbox) |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
338 self._last_textbox.setText("") |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
339 self.add(self._last_textbox) |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
340 self._last_textbox.setFocus(setFocus) |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
341 |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
342 def onKeyUp(self, sender, keycode, modifiers): |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
343 """This is called after DragAutoCompleteTextBox.onKeyDown, |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
344 so the completion is done before we reset the text box.""" |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
345 if not isinstance(sender, DragAutoCompleteTextBox): |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
346 return |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
347 if keycode == KEY_ENTER: |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
348 self.onLostFocus(sender) |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
349 self._last_textbox.setFocus(True) |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
350 |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
351 def onFocus(self, sender): |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
352 """A DragAutoCompleteTextBox has the focus.""" |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
353 if not isinstance(sender, DragAutoCompleteTextBox): |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
354 return |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
355 if sender != self._last_textbox: |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
356 # save the current value before it's being modified |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
357 text = sender.getText() |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
358 self._focused_textbox_previous_value = text |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
359 self._parent.addToRemainingList(text) |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
360 sender.setCompletionItems(self._parent.remaining_list) |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
361 |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
362 def onLostFocus(self, sender): |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
363 """A DragAutoCompleteTextBox has lost the focus.""" |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
364 if not isinstance(sender, DragAutoCompleteTextBox): |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
365 return |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
366 self.changeContact(sender) |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
367 |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
368 def changeContact(self, sender): |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
369 """Modify the value of a DragAutoCompleteTextBox.""" |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
370 text = sender.getText() |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
371 if sender == self._last_textbox: |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
372 if text != "": |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
373 # a new box is added and the last textbox is reinitialized |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
374 self.addContact(text, setFocusToLastTextBox=False) |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
375 return |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
376 if text == "": |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
377 sender.remove_btn.click() |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
378 return |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
379 # text = new value needs to be removed 1. if the value is unchanged, because we |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
380 # added it when we took the focus, or 2. if the value is changed (obvious!) |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
381 self._parent.removeFromRemainingList(text) |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
382 if text == self._focused_textbox_previous_value: |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
383 return |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
384 sender.setVisibleLength(len(text)) |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
385 self._parent.addToRemainingList(self._focused_textbox_previous_value) |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
386 |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
387 def addContact(self, contact, resetLastTextBox=True, setFocusToLastTextBox=True): |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
388 """Add a contact and signal it to self._parent panel.""" |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
389 if contact is None or contact == "": |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
390 return |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
391 textbox = DragAutoCompleteTextBox() |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
392 textbox.addStyleName(self.style["textBox"]) |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
393 textbox.setText(contact) |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
394 self.add(textbox) |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
395 try: |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
396 textbox.setVisibleLength(len(str(contact))) |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
397 except: |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
398 #FIXME: . how come could this happen?! len(contact) is sometimes 0 but contact is not empty |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
399 print "len(contact) returns %d where contact == %s..." % (len(str(contact)), str(contact)) |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
400 self._parent.removeFromRemainingList(contact) |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
401 |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
402 remove_btn = Button(REMOVE_BUTTON, Visible=False) |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
403 remove_btn.setStyleName(self.style["removeButton"]) |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
404 |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
405 def remove_cb(sender): |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
406 """Callback for the button to remove this contact.""" |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
407 self.remove(textbox) |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
408 self.remove(remove_btn) |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
409 self._parent.addToRemainingList(contact) |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
410 self._parent.setRemainingListUnsorted() |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
411 |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
412 remove_btn.addClickListener(remove_cb) |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
413 self.__remove_cbs.append(remove_cb) |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
414 self.add(remove_btn) |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
415 self.__resetLastTextBox(setFocus=setFocusToLastTextBox) |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
416 |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
417 textbox.remove_btn = remove_btn |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
418 textbox.addFocusListener(self) |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
419 textbox.addKeyboardListener(self) |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
420 |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
421 def emptyContacts(self): |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
422 """Empty the list of contacts.""" |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
423 for remove_cb in self.__remove_cbs: |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
424 remove_cb() |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
425 self.__remove_cbs = [] |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
426 |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
427 def setContacts(self, tab): |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
428 """Set the contacts.""" |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
429 self.emptyContacts() |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
430 for contact in tab: |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
431 self.addContact(contact, resetLastTextBox=False) |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
432 self.__resetLastTextBox() |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
433 |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
434 def getContacts(self): |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
435 """Get the contacts |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
436 @return: an array of string""" |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
437 tab = [] |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
438 for widget in self.getChildren(): |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
439 if isinstance(widget, DragAutoCompleteTextBox): |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
440 # not to be mixed with EMPTY_SELECTION_ITEM |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
441 if widget.getText() != "": |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
442 tab.append(widget.getText()) |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
443 return tab |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
444 |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
445 def getTargetDropCell(self): |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
446 """Returns self or another panel where something has been dropped.""" |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
447 return self._parent.getTargetDropCell() |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
448 |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
449 |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
450 class ContactChooserPanel(DialogBox): |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
451 """Display the contacts chooser dialog. This has been implemented while |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
452 prototyping and is currently not used. Left for an eventual later use. |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
453 Replaced by the popup menu which allows to add a panel for Cc or Bcc. |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
454 """ |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
455 |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
456 def __init__(self, manager, **kwargs): |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
457 """Display a listbox for each contact key""" |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
458 DialogBox.__init__(self, autoHide=False, centered=True, **kwargs) |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
459 self.setHTML("Select contacts") |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
460 self.manager = manager |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
461 self.listboxes = {} |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
462 self.contacts = manager.getContacts() |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
463 |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
464 container = VerticalPanel(Visible=True) |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
465 container.addStyleName("marginAuto") |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
466 |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
467 grid = Grid(2, len(self.manager.keys_dict)) |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
468 index = -1 |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
469 for key in self.manager.keys_dict: |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
470 index += 1 |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
471 grid.add(Label("%s:" % self.manager.keys_dict[key]["desc"]), 0, index) |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
472 listbox = ListBox() |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
473 listbox.setMultipleSelect(True) |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
474 listbox.setVisibleItemCount(15) |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
475 listbox.addItem(EMPTY_SELECTION_ITEM) |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
476 for element in manager.list: |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
477 listbox.addItem(element) |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
478 self.listboxes[key] = listbox |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
479 grid.add(listbox, 1, index) |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
480 self._reset() |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
481 |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
482 buttons = HorizontalPanel() |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
483 buttons.addStyleName("marginAuto") |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
484 btn_close = Button("Cancel", self.hide) |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
485 buttons.add(btn_close) |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
486 btn_reset = Button("Reset", self._reset) |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
487 buttons.add(btn_reset) |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
488 btn_ok = Button("OK", self._validate) |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
489 buttons.add(btn_ok) |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
490 |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
491 container.add(grid) |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
492 container.add(buttons) |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
493 |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
494 self.add(container) |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
495 self.center() |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
496 |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
497 def _reset(self): |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
498 """Reset the selections.""" |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
499 for key in self.manager.keys_dict: |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
500 listbox = self.listboxes[key] |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
501 for i in xrange(0, listbox.getItemCount()): |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
502 if listbox.getItemText(i) in self.contacts[key]: |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
503 listbox.setItemSelected(i, "selected") |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
504 else: |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
505 listbox.setItemSelected(i, "") |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
506 |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
507 def _validate(self): |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
508 """Sets back the selected contacts to the good sub-panels.""" |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
509 _map = {} |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
510 for key in self.manager.keys_dict: |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
511 selections = self.listboxes[key].getSelectedItemText() |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
512 if EMPTY_SELECTION_ITEM in selections: |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
513 selections.remove(EMPTY_SELECTION_ITEM) |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
514 _map[key] = selections |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
515 self.manager.setContacts(_map) |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
516 self.hide() |