Mercurial > libervia-web
comparison contact.py @ 2:669c531a857e
signals handling and first draft of microblogging
- server side: signal handling throught json_signal_api page
- browser side: - signal handling throught a json rpc call loop
- first draft of microblog panel
- ContactPanel put in a separate module
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 08 Feb 2011 21:18:31 +0100 |
parents | |
children | a663b9955cf3 |
comparison
equal
deleted
inserted
replaced
1:0a7c685faa53 | 2:669c531a857e |
---|---|
1 #!/usr/bin/python | |
2 # -*- coding: utf-8 -*- | |
3 | |
4 """ | |
5 Libervia: a Salut à Toi frontend | |
6 Copyright (C) 2011 Jérôme Poisson (goffi@goffi.org) | |
7 | |
8 This program is free software: you can redistribute it and/or modify | |
9 it under the terms of the GNU Affero General Public License as published by | |
10 the Free Software Foundation, either version 3 of the License, or | |
11 (at your option) any later version. | |
12 | |
13 This program is distributed in the hope that it will be useful, | |
14 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 GNU Affero General Public License for more details. | |
17 | |
18 You should have received a copy of the GNU Affero General Public License | |
19 along with this program. If not, see <http://www.gnu.org/licenses/>. | |
20 """ | |
21 | |
22 import pyjd # this is dummy in pyjs | |
23 from pyjamas.ui.SimplePanel import SimplePanel | |
24 from pyjamas.ui.VerticalPanel import VerticalPanel | |
25 from pyjamas.ui.HorizontalPanel import HorizontalPanel | |
26 from pyjamas.ui.Label import Label | |
27 from pyjamas import Window | |
28 from pyjamas import DOM | |
29 | |
30 | |
31 class GroupLabel(Label): | |
32 def __init__(self, group): | |
33 Label.__init__(self, group) | |
34 self.group = group | |
35 self.setStyleName('group') | |
36 | |
37 class ContactLabel(Label): | |
38 def __init__(self, jid, name=None): | |
39 if not name: | |
40 name=jid | |
41 Label.__init__(self, name) | |
42 self.jid=jid | |
43 self.setStyleName('contact') | |
44 | |
45 class GroupList(VerticalPanel): | |
46 | |
47 def __init__(self, parent): | |
48 VerticalPanel.__init__(self) | |
49 self._parent = parent | |
50 | |
51 def add(self, group): | |
52 _item = GroupLabel(group) | |
53 _item.addMouseListener(self._parent) | |
54 DOM.setStyleAttribute(_item.getElement(), "cursor", "pointer") | |
55 VerticalPanel.add(self, _item) | |
56 | |
57 class ContactList(VerticalPanel): | |
58 | |
59 def __init__(self): | |
60 VerticalPanel.__init__(self) | |
61 self.contacts=[] | |
62 | |
63 def __iter__(self): | |
64 return self.contacts.__iter__() | |
65 | |
66 def add(self, jid, name=None): | |
67 _item = ContactLabel(jid, name) | |
68 DOM.setStyleAttribute(_item.getElement(), "cursor", "pointer") | |
69 VerticalPanel.add(self, _item) | |
70 self.contacts.append(_item) | |
71 | |
72 class ContactPanel(SimplePanel): | |
73 """Manage the contacts and groups""" | |
74 | |
75 def __init__(self, host): | |
76 SimplePanel.__init__(self) | |
77 self.host = host | |
78 self.groups={} | |
79 | |
80 self.vPanel = VerticalPanel() | |
81 _title = Label('Contacts') | |
82 _title.setStyleName('contactTitle') | |
83 | |
84 self._contactList = ContactList() | |
85 self._contactList.setStyleName('contactList') | |
86 self._groupList = GroupList(self) | |
87 self._groupList.setStyleName('groupList') | |
88 | |
89 self.vPanel.add(_title) | |
90 self.vPanel.add(self._groupList) | |
91 self.vPanel.add(self._contactList) | |
92 self.add(self.vPanel) | |
93 self.setStyleName('contactBox') | |
94 | |
95 def addContact(self, jid, attributes, groups): | |
96 """Add a contact to the panel | |
97 @param jid: jid | |
98 @attributes: cf SàT Bridge API's newContact | |
99 @param groups: list of groups""" | |
100 for group in groups: | |
101 if not self.groups.has_key(group): | |
102 self.groups[group] = set() | |
103 self._groupList.add(group) | |
104 self.host.magicBox.addKey("@%s: " % group) | |
105 self.groups[group].add(jid) | |
106 self._contactList.add(jid) | |
107 | |
108 def onMouseMove(self, sender, x, y): | |
109 pass | |
110 | |
111 def onMouseDown(self, sender, x, y): | |
112 pass | |
113 | |
114 def onMouseUp(self, sender, x, y): | |
115 pass | |
116 | |
117 def onMouseEnter(self, sender): | |
118 if isinstance(sender, GroupLabel): | |
119 for contact in self._contactList: | |
120 if contact.jid in self.groups[sender.group]: | |
121 contact.addStyleName("selected") | |
122 | |
123 def onMouseLeave(self, sender): | |
124 if isinstance(sender, GroupLabel): | |
125 for contact in self._contactList: | |
126 if contact.jid in self.groups[sender.group]: | |
127 contact.removeStyleName("selected") |