Mercurial > libervia-web
annotate browser_side/list_manager.py @ 380:5e0e2032928c
browser_side: bug fixes microblogs:
- currently selected panel is taken in account when the unibox is toggled on
- sending message to restricted groups from the editor that is integrated into MicroblogPanel now works
author | souliane <souliane@mailoo.org> |
---|---|
date | Tue, 25 Feb 2014 12:41:31 +0100 |
parents | 83454ba70a9c |
children | a71fcc27f231 |
rev | line source |
---|---|
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1 #!/usr/bin/python |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2 # -*- coding: utf-8 -*- |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
3 |
339
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
323
diff
changeset
|
4 # Libervia: a Salut à Toi frontend |
340 | 5 # Copyright (C) 2013, 2014 Adrien Cossa <souliane@mailoo.org> |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
6 |
339
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
323
diff
changeset
|
7 # This program is free software: you can redistribute it and/or modify |
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
323
diff
changeset
|
8 # it under the terms of the GNU Affero General Public License as published by |
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
323
diff
changeset
|
9 # the Free Software Foundation, either version 3 of the License, or |
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
323
diff
changeset
|
10 # (at your option) any later version. |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
11 |
339
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
323
diff
changeset
|
12 # This program is distributed in the hope that it will be useful, |
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
323
diff
changeset
|
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
323
diff
changeset
|
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
323
diff
changeset
|
15 # GNU Affero General Public License for more details. |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
16 |
339
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
323
diff
changeset
|
17 # You should have received a copy of the GNU Affero General Public License |
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
323
diff
changeset
|
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
19 |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
20 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
|
21 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
|
22 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
|
23 from pyjamas.ui.FlowPanel import FlowPanel |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
24 from pyjamas.ui.AutoComplete import AutoCompleteTextBox |
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.Label import Label |
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.HorizontalPanel import HorizontalPanel |
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.VerticalPanel import VerticalPanel |
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.DialogBox import DialogBox |
263
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
29 from pyjamas.ui.KeyboardListener import KEY_ENTER |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
30 from pyjamas.ui.MouseListener import MouseHandler |
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.FocusListener import FocusHandler |
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.DropWidget import DropWidget |
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.DragWidget import DragWidget |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
34 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
|
35 from pyjamas import DOM |
323
0b7934e75e76
misc: reorganization of the file panels.py + clean the modules import:
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
36 |
0b7934e75e76
misc: reorganization of the file panels.py + clean the modules import:
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
37 from base_panels import PopupMenuPanel |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
38 |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
39 |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
40 # HTML content for the removal button (image or text) |
348
83454ba70a9c
browser_side: added a method setVisible to ListManager
souliane <souliane@mailoo.org>
parents:
340
diff
changeset
|
41 REMOVE_BUTTON = '<span class="recipientRemoveIcon">x</span>' |
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 # 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
|
44 # 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
|
45 EMPTY_SELECTION_ITEM = "" |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
46 |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
47 |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
48 class ListManager(): |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
49 """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
|
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 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
|
52 """ |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
53 @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
|
54 @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
|
55 @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
|
56 @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
|
57 - "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
|
58 - "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
|
59 - "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
|
60 """ |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
61 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
|
62 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
|
63 tmp = {} |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
64 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
|
65 tmp[key] = {} |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
66 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
|
67 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
|
68 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
|
69 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
|
70 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
|
71 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
|
72 # 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
|
73 self.__remaining_list = [] |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
74 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
|
75 # 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
|
76 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
|
77 |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
78 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
|
79 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
|
80 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
|
81 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
|
82 |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
83 self.style = { |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
84 "keyItem": "recipientTypeItem", |
256
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
254
diff
changeset
|
85 "popupMenuItem": "recipientTypeItem", |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
86 "buttonCell": "recipientButtonCell", |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
87 "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
|
88 "keyPanel": "recipientPanel", |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
89 "textBox": "recipientTextBox", |
263
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
90 "textBox-invalid": "recipientTextBox-invalid", |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
91 "removeButton": "recipientRemoveButton", |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
92 } |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
93 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
|
94 |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
95 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
|
96 """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
|
97 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
|
98 for key in self.__keys_dict: |
263
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
99 self.addContactKey(key, title_format=title_format) |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
100 |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
101 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
|
102 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
|
103 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
|
104 # 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
|
105 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
|
106 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
|
107 |
263
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
108 def removeContactKey(self, key): |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
109 """Remove a list panel and all its associated data.""" |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
110 contacts = self.__children[key]["panel"].getContacts() |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
111 (y, x) = self._parent.getIndex(self.__children[key]["button"]) |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
112 self._parent.removeRow(y) |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
113 del self.__children[key] |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
114 del self.__keys_dict[key] |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
115 self.addToRemainingList(contacts) |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
116 |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
117 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
|
118 """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
|
119 button = Button(title_format % entry["title"]) |
256
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
254
diff
changeset
|
120 button.setStyleName(self.style["keyItem"]) |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
121 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
|
122 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
|
123 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
|
124 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
|
125 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
|
126 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
|
127 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
|
128 |
263
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
129 self._parent.insertRow(y) |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
130 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
|
131 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
|
132 |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
133 _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
|
134 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
|
135 |
241
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
232
diff
changeset
|
136 self.__children[entry["title"]] = {} |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
232
diff
changeset
|
137 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
|
138 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
|
139 |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
140 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
|
141 # 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
|
142 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
|
143 |
348
83454ba70a9c
browser_side: added a method setVisible to ListManager
souliane <souliane@mailoo.org>
parents:
340
diff
changeset
|
144 def _refresh(self, visible=True): |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
145 """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
|
146 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
|
147 self.setContactPanelVisible(key, False) |
348
83454ba70a9c
browser_side: added a method setVisible to ListManager
souliane <souliane@mailoo.org>
parents:
340
diff
changeset
|
148 if not visible: |
83454ba70a9c
browser_side: added a method setVisible to ListManager
souliane <souliane@mailoo.org>
parents:
340
diff
changeset
|
149 return |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
150 _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
|
151 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
|
152 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
|
153 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
|
154 |
348
83454ba70a9c
browser_side: added a method setVisible to ListManager
souliane <souliane@mailoo.org>
parents:
340
diff
changeset
|
155 def setVisible(self, visible): |
83454ba70a9c
browser_side: added a method setVisible to ListManager
souliane <souliane@mailoo.org>
parents:
340
diff
changeset
|
156 self._refresh(visible) |
83454ba70a9c
browser_side: added a method setVisible to ListManager
souliane <souliane@mailoo.org>
parents:
340
diff
changeset
|
157 |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
158 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
|
159 """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
|
160 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
|
161 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
|
162 |
254
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 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 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
|
166 return self.__list |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
167 |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
168 @property |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
169 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
|
170 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
|
171 |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
172 @property |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
173 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
|
174 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
|
175 |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
176 @property |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
177 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
|
178 """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
|
179 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
|
180 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
|
181 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
|
182 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
|
183 |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
184 def setRemainingListUnsorted(self): |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
185 """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
|
186 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
|
187 |
263
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
188 def removeFromRemainingList(self, contacts): |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
189 """Remove contacts after they have been added to a sub-panel.""" |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
190 if not isinstance(contacts, list): |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
191 contacts = [contacts] |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
192 for contact_ in contacts: |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
193 if contact_ in self.__remaining_list: |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
194 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
|
195 |
263
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
196 def addToRemainingList(self, contacts, ignore_key=None): |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
197 """Add contacts after they have been removed from a sub-panel.""" |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
198 if not isinstance(contacts, list): |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
199 contacts = [contacts] |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
200 assigned_contacts = set() |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
201 assigned_map = self.getContacts() |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
202 for key_ in assigned_map.keys(): |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
203 if ignore_key is not None and key_ == ignore_key: |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
204 continue |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
205 assigned_contacts.update(assigned_map[key_]) |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
206 for contact_ in contacts: |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
207 if contact_ not in self.__list or contact_ in self.__remaining_list: |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
208 continue |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
209 if contact_ in assigned_contacts: |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
210 continue # the contact is assigned somewhere else |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
211 self.__remaining_list.append(contact_) |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
212 self.setRemainingListUnsorted() |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
213 |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
214 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
|
215 """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
|
216 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
|
217 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
|
218 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
|
219 else: |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
220 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
|
221 self._refresh() |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
222 |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
223 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
|
224 """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
|
225 @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
|
226 _map = {} |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
227 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
|
228 _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
|
229 return _map |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
230 |
263
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
231 @property |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
232 def target_drop_cell(self): |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
233 """@return: the panel where something has been dropped.""" |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
234 return self.target_drop_cell |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
235 |
263
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
236 @target_drop_cell.setter |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
237 def target_drop_cell(self, target_drop_cell): |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
238 """@param: target_drop_cell: the panel where something has been dropped.""" |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
239 self.target_drop_cell = target_drop_cell |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
240 |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
241 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
|
242 "Register a popup menu panel that will be bound to all contact keys elements." |
323
0b7934e75e76
misc: reorganization of the file panels.py + clean the modules import:
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
243 self.popup_menu = PopupMenuPanel(entries=entries, hide=hide, callback=callback, style={"item": self.style["popupMenuItem"]}) |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
244 |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
245 |
263
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
246 class DragAutoCompleteTextBox(AutoCompleteTextBox, DragWidget, MouseHandler, FocusHandler): |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
247 """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
|
248 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
|
249 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
|
250 """ |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
251 |
263
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
252 def __init__(self, parent, event_cbs, style): |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
253 AutoCompleteTextBox.__init__(self) |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
254 DragWidget.__init__(self) |
263
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
255 self._parent = parent |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
256 self.event_cbs = event_cbs |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
257 self.style = style |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
258 self.addMouseListener(self) |
263
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
259 self.addFocusListener(self) |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
260 self.addChangeListener(self) |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
261 self.addStyleName(style["textBox"]) |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
262 self.reset() |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
263 |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
264 def reset(self): |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
265 self.setText("") |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
266 self.setValid() |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
267 |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
268 def setValid(self, valid=True): |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
269 if self.getText() == "": |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
270 valid = True |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
271 if valid: |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
272 self.removeStyleName(self.style["textBox-invalid"]) |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
273 else: |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
274 self.addStyleName(self.style["textBox-invalid"]) |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
275 self.valid = valid |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
276 |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
277 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
|
278 dt = event.dataTransfer |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
279 # 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
|
280 dt.setData('text/plain', "%s\n%s" % (self.getText(), "CONTACT_TEXTBOX")) |
263
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
281 self.setSelectionRange(len(self.getText()), 0) |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
282 |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
283 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
|
284 if self.getText() == "": |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
285 return |
263
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
286 target = self._parent.target_drop_cell # parent or another ListPanel |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
287 self.event_cbs["drop"](self, target) |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
288 |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
289 def setRemoveButton(self): |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
290 |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
291 def remove_cb(sender): |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
292 """Callback for the button to remove this contact.""" |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
293 self._parent.remove(self) |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
294 self._parent.remove(self.remove_btn) |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
295 self.event_cbs["remove"](self) |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
296 |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
297 self.remove_btn = Button(REMOVE_BUTTON, remove_cb, Visible=False) |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
298 self.remove_btn.setStyleName(self.style["removeButton"]) |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
299 self._parent.add(self.remove_btn) |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
300 |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
301 def removeOrReset(self): |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
302 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
|
303 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
|
304 else: |
263
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
305 self.reset() |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
306 |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
307 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
|
308 """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
|
309 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
|
310 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
|
311 |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
312 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
|
313 """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
|
314 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
|
315 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
|
316 |
263
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
317 def onFocus(self, sender): |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
318 sender.setSelectionRange(0, len(self.getText())) |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
319 self.event_cbs["focus"](sender) |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
320 |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
321 def validate(self): |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
322 self.setSelectionRange(len(self.getText()), 0) |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
323 self.event_cbs["validate"](self) |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
324 |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
325 def onChange(self, sender): |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
326 """The textbox or list selection is changed""" |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
327 if isinstance(sender, ListBox): |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
328 AutoCompleteTextBox.onChange(self, sender) |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
329 self.validate() |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
330 |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
331 def onClick(self, sender): |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
332 """The list is clicked""" |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
333 AutoCompleteTextBox.onClick(self, sender) |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
334 self.validate() |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
335 |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
336 def onKeyUp(self, sender, keycode, modifiers): |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
337 """Listen for ENTER key stroke""" |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
338 AutoCompleteTextBox.onKeyUp(self, sender, keycode, modifiers) |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
339 if keycode == KEY_ENTER: |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
340 self.validate() |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
341 |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
342 |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
343 class DropCell(DropWidget): |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
344 """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
|
345 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
|
346 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
|
347 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
|
348 """ |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
349 |
263
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
350 def __init__(self, drop_cbs): |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
351 DropWidget.__init__(self) |
263
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
352 self.drop_cbs = drop_cbs |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
353 |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
354 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
|
355 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
|
356 DOM.eventPreventDefault(event) |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
357 |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
358 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
|
359 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
|
360 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
|
361 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
|
362 # 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
|
363 # 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
|
364 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
|
365 |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
366 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
|
367 DOM.eventPreventDefault(event) |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
368 |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
369 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
|
370 DOM.eventPreventDefault(event) |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
371 dt = event.dataTransfer |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
372 # '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
|
373 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
|
374 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
|
375 item_type = item_type[:-1] # .strip('\0') and .replace('\0','') don't work. TODO: check this and fill a bug report |
263
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
376 if item_type in self.drop_cbs.keys(): |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
377 self.drop_cbs[item_type](self, item) |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
378 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
|
379 |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
380 |
263
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
381 VALID = 1 |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
382 INVALID = 2 |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
383 DELETE = 3 |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
384 |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
385 |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
386 class ListPanel(FlowPanel, DropCell): |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
387 """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
|
388 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
|
389 |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
390 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
|
391 """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
|
392 FlowPanel.__init__(self, Visible=(False if entry["optional"] else True)) |
263
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
393 drop_cbs = {"GROUP": lambda panel, item: self.addContact("@%s" % item), |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
394 "CONTACT": lambda panel, item: self.addContact(item), |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
395 "CONTACT_TEXTBOX": lambda panel, item: self.setTargetDropCell(panel) |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
396 } |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
397 DropCell.__init__(self, drop_cbs) |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
398 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
|
399 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
|
400 self._parent = parent |
263
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
401 self.key = entry["title"] |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
402 self._addTextBox() |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
403 |
263
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
404 def _addTextBox(self, switchPrevious=False): |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
405 """Add a text box to the last position. If switchPrevious is True, simulate |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
406 an insertion before the current last textbox by copying the text and valid state. |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
407 @return: the created textbox or the previous one if switchPrevious is True. |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
408 """ |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
409 if hasattr(self, "_last_textbox"): |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
410 if self._last_textbox.getText() == "": |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
411 return |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
412 self._last_textbox.setRemoveButton() |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
413 else: |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
414 switchPrevious = False |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
415 |
263
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
416 def focus_cb(sender): |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
417 if sender != self._last_textbox: |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
418 # save the current value before it's being modified |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
419 self._parent.addToRemainingList(sender.getText(), ignore_key=self.key) |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
420 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
|
421 |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
422 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
|
423 """Callback for the button to remove this contact.""" |
263
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
424 self._parent.addToRemainingList(sender.getText()) |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
425 self._parent.setRemainingListUnsorted() |
263
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
426 self._last_textbox.setFocus(True) |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
427 |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
428 def drop_cb(sender, target): |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
429 """Callback when the textbox is drag-n-dropped.""" |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
430 parent = sender._parent |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
431 if target != parent and target.addContact(sender.getText()): |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
432 sender.removeOrReset() |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
433 else: |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
434 parent._parent.removeFromRemainingList(sender.getText()) |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
435 |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
436 events_cbs = {"focus": focus_cb, "validate": self.addContact, "remove": remove_cb, "drop": drop_cb} |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
437 textbox = DragAutoCompleteTextBox(self, events_cbs, self.style) |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
438 self.add(textbox) |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
439 if switchPrevious: |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
440 textbox.setText(self._last_textbox.getText()) |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
441 textbox.setValid(self._last_textbox.valid) |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
442 self._last_textbox.reset() |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
443 previous = self._last_textbox |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
444 self._last_textbox = textbox |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
445 return previous if switchPrevious else textbox |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
446 |
263
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
447 def _checkContact(self, contact, modify): |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
448 """ |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
449 @param contact: the contact to check |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
450 @param modify: True if the contact is being modified |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
451 @return: |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
452 - VALID if the contact is valid |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
453 - INVALID if the contact is not valid but can be displayed |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
454 - DELETE if the contact should not be displayed at all |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
455 """ |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
456 def countItemInList(list_, item): |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
457 """For some reason the built-in count function doesn't work...""" |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
458 count = 0 |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
459 for elem in list_: |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
460 if elem == item: |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
461 count += 1 |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
462 return count |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
463 if contact is None or contact == "": |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
464 return DELETE |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
465 if countItemInList(self.getContacts(), contact) > (1 if modify else 0): |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
466 return DELETE |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
467 return VALID if contact in self._parent.list else INVALID |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
468 |
263
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
469 def addContact(self, contact, sender=None): |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
470 """The first parameter type is checked, so it is also possible to call addContact(sender). |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
471 If contact is not defined, sender.getText() is used. If sender is not defined, contact will |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
472 be written to the last textbox and a new textbox is added afterward. |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
473 @param contact: unicode |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
474 @param sender: DragAutoCompleteTextBox instance |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
475 """ |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
476 if isinstance(contact, DragAutoCompleteTextBox): |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
477 sender = contact |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
478 contact = sender.getText() |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
479 valid = self._checkContact(contact, sender is not None) |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
480 if sender is None: |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
481 # method has been called to modify but to add a contact |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
482 if valid == VALID: |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
483 # eventually insert before the last textbox if it's not empty |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
484 sender = self._addTextBox(True) if self._last_textbox.getText() != "" else self._last_textbox |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
485 sender.setText(contact) |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
486 else: |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
487 sender.setValid(valid == VALID) |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
488 if valid != VALID: |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
489 if sender is not None and valid == DELETE: |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
490 sender.removeOrReset() |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
491 return False |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
492 if sender == self._last_textbox: |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
493 self._addTextBox() |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
494 try: |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
495 sender.setVisibleLength(len(contact)) |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
496 except: |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
497 # IndexSizeError: Index or size is negative or greater than the allowed amount |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
498 print "FIXME: len(%s) returns %d... javascript bug?" % (contact, len(contact)) |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
499 self._parent.removeFromRemainingList(contact) |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
500 self._last_textbox.setFocus(True) |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
501 return True |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
502 |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
503 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
|
504 """Empty the list of contacts.""" |
263
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
505 for child in self.getChildren(): |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
506 if hasattr(child, "remove_btn"): |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
507 child.remove_btn.click() |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
508 |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
509 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
|
510 """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
|
511 self.emptyContacts() |
256
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
254
diff
changeset
|
512 if isinstance(tab, set): |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
254
diff
changeset
|
513 tab = list(tab) |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
254
diff
changeset
|
514 tab.sort() |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
515 for contact in tab: |
263
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
516 self.addContact(contact) |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
517 |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
518 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
|
519 """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
|
520 @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
|
521 tab = [] |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
522 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
|
523 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
|
524 # 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
|
525 if widget.getText() != "": |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
526 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
|
527 return tab |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
528 |
263
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
529 @property |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
530 def target_drop_cell(self): |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
531 """@return: the panel where something has been dropped.""" |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
532 return self._parent.target_drop_cell |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
533 |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
534 @target_drop_cell.setter |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
535 def target_drop_cell(self, target_drop_cell): |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
536 """@param target_drop_cell: the panel where something has been dropped.""" |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
537 self.setTargetDropCell(target_drop_cell) |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
538 |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
539 def setTargetDropCell(self, target_drop_cell): |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
540 self._parent.target_drop_cell = target_drop_cell |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
541 |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
542 |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
543 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
|
544 """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
|
545 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
|
546 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
|
547 """ |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
548 |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
549 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
|
550 """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
|
551 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
|
552 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
|
553 self.manager = manager |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
554 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
|
555 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
|
556 |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
557 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
|
558 container.addStyleName("marginAuto") |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
559 |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
560 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
|
561 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
|
562 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
|
563 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
|
564 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
|
565 listbox = ListBox() |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
566 listbox.setMultipleSelect(True) |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
567 listbox.setVisibleItemCount(15) |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
568 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
|
569 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
|
570 listbox.addItem(element) |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
571 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
|
572 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
|
573 self._reset() |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
574 |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
575 buttons = HorizontalPanel() |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
576 buttons.addStyleName("marginAuto") |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
577 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
|
578 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
|
579 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
|
580 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
|
581 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
|
582 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
|
583 |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
584 container.add(grid) |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
585 container.add(buttons) |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
586 |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
587 self.add(container) |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
588 self.center() |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
589 |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
590 def _reset(self): |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
591 """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
|
592 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
|
593 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
|
594 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
|
595 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
|
596 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
|
597 else: |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
598 listbox.setItemSelected(i, "") |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
599 |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
600 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
|
601 """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
|
602 _map = {} |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
603 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
|
604 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
|
605 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
|
606 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
|
607 _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
|
608 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
|
609 self.hide() |