annotate libervia.py @ 1:0a7c685faa53

ContactPanel: first draft
author Goffi <goffi@goffi.org>
date Mon, 31 Jan 2011 20:31:25 +0100
parents 140cec48224a
children 669c531a857e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/python
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
3
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
4 """
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
5 Libervia: a Salut à Toi frontend
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
6 Copyright (C) 2011 Jérôme Poisson (goffi@goffi.org)
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
7
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
8 This program is free software: you can redistribute it and/or modify
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
9 it under the terms of the GNU Affero General Public License as published by
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
10 the Free Software Foundation, either version 3 of the License, or
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
11 (at your option) any later version.
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
12
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
13 This program is distributed in the hope that it will be useful,
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
16 GNU Affero General Public License for more details.
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
17
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
18 You should have received a copy of the GNU Affero General Public License
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
20 """
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
21
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
22 import pyjd # this is dummy in pyjs
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
23 from pyjamas.ui.SimplePanel import SimplePanel
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
24 from pyjamas.ui.RootPanel import RootPanel
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
25 from pyjamas.ui.VerticalPanel import VerticalPanel
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
26 from pyjamas.ui.HorizontalPanel import HorizontalPanel
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
27 from pyjamas.ui.Label import Label
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
28 from pyjamas.ui import HasAlignment
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
29 from pyjamas.ui.MenuBar import MenuBar
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
30 from pyjamas.ui.MenuItem import MenuItem
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
31 from pyjamas import Window
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
32 from pyjamas.ui.AutoComplete import AutoCompleteTextBox
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
33 from pyjamas.JSONService import JSONProxy
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
34 from register import RegisterPanel, RegisterBox
1
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
35 from pyjamas import DOM
0
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
36
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
37
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
38 class LiberviaJsonProxy(JSONProxy):
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
39 def __init__(self, *args, **kwargs):
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
40 JSONProxy.__init__(self, *args, **kwargs)
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
41 self.handler=self
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
42 self.cb={}
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
43
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
44 def call(self, method, cb, *args):
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
45 self.cb[method] = cb
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
46 self.callMethod(method,args)
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
47
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
48 def onRemoteResponse(self, response, request_info):
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
49 if self.cb.has_key(request_info.method):
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
50 self.cb[request_info.method](response)
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
51 del self.cb[request_info.method]
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
52
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
53 def onRemoteError(self, code, errobj, request_info):
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
54 if code != 0:
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
55 Window.alert("Internal server error")
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
56 else:
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
57 if isinstance(errobj['message'],dict):
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
58 Window.alert("Error %s: %s" % (errobj['message']['faultCode'], errobj['message']['faultString']))
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
59 else:
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
60 Window.alert("Error: %s" % errobj['message'])
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
61
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
62 class RegisterCall(LiberviaJsonProxy):
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
63 def __init__(self):
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
64 LiberviaJsonProxy.__init__(self, "/register_api",
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
65 ["isRegistered","isConnected","connect"])
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
66 self.handler=self
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
67 self.cb={}
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
68
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
69 class BrigeCall(LiberviaJsonProxy):
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
70 def __init__(self):
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
71 LiberviaJsonProxy.__init__(self, "/json_api",
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
72 ["getContacts"])
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
73
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
74 class MenuCmd:
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
75
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
76 def __init__(self, object, handler):
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
77 self._object = object
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
78 self._handler = handler
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
79
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
80 def execute(self):
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
81 handler = getattr(self._object, self._handler)
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
82 handler()
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
83
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
84 class Menu(SimplePanel):
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
85
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
86 def __init__(self):
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
87 SimplePanel.__init__(self)
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
88
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
89 menu_general = MenuBar(vertical=True)
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
90 menu_general.addItem("Properties", MenuCmd(self, "onProperties"))
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
91
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
92 menu_games = MenuBar(vertical=True)
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
93 menu_games.addItem("Tarot", MenuCmd(self, "onTarotGame"))
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
94 menu_games.addItem("Xiangqi", MenuCmd(self, "onXiangqiGame"))
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
95
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
96 menubar = MenuBar(vertical=False)
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
97 menubar.addItem(MenuItem("General", menu_general))
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
98 menubar.addItem(MenuItem("Games", True, menu_games))
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
99 self.add(menubar)
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
100
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
101 def onProperties(self):
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
102 Window.alert("Properties selected")
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
103
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
104 def onTarotGame(self):
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
105 Window.alert("Tarot selected")
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
106
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
107 def onXiangqiGame(self):
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
108 Window.alert("Xiangqi selected")
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
109
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
110 class MagicBox(AutoCompleteTextBox):
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
111
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
112 def __init__(self):
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
113 AutoCompleteTextBox.__init__(self)
1
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
114
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
115 def addKey(self, key):
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
116 self.getCompletionItems().completions.append(key)
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
117
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
118 class GroupLabel(Label):
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
119 def __init__(self, group):
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
120 Label.__init__(self, group)
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
121 self.group = group
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
122 self.setStyleName('group')
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
123
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
124 class ContactLabel(Label):
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
125 def __init__(self, jid, name=None):
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
126 if not name:
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
127 name=jid
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
128 Label.__init__(self, name)
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
129 self.jid=jid
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
130 self.setStyleName('contact')
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
131
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
132 class GroupList(VerticalPanel):
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
133
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
134 def __init__(self, parent):
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
135 VerticalPanel.__init__(self)
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
136 self._parent = parent
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
137
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
138 def add(self, group):
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
139 _item = GroupLabel(group)
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
140 _item.addMouseListener(self._parent)
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
141 DOM.setStyleAttribute(_item.getElement(), "cursor", "pointer")
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
142 VerticalPanel.add(self, _item)
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
143
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
144 class ContactList(VerticalPanel):
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
145
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
146 def __init__(self):
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
147 VerticalPanel.__init__(self)
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
148 self.contacts=[]
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
149
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
150 def __iter__(self):
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
151 return self.contacts.__iter__()
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
152
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
153 def add(self, jid, name=None):
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
154 _item = ContactLabel(jid, name)
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
155 DOM.setStyleAttribute(_item.getElement(), "cursor", "pointer")
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
156 VerticalPanel.add(self, _item)
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
157 self.contacts.append(_item)
0
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
158
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
159 class ContactPanel(SimplePanel):
1
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
160 """Manage the contacts and groups"""
0
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
161
1
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
162 def __init__(self, host):
0
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
163 SimplePanel.__init__(self)
1
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
164 self.host = host
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
165 self.groups={}
0
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
166
1
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
167 self.vPanel = VerticalPanel()
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
168 _title = Label('Contacts')
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
169 _title.setStyleName('contactTitle')
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
170
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
171 self._contactList = ContactList()
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
172 self._contactList.setStyleName('contactList')
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
173 self._groupList = GroupList(self)
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
174 self._groupList.setStyleName('groupList')
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
175
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
176 self.vPanel.add(_title)
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
177 self.vPanel.add(self._groupList)
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
178 self.vPanel.add(self._contactList)
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
179 self.add(self.vPanel)
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
180 self.setStyleName('contactBox')
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
181
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
182 def addContact(self, jid, attributes, groups):
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
183 """Add a contact to the panel
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
184 @param jid: jid
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
185 @attributes: cf SàT Bridge API's newContact
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
186 @param groups: list of groups"""
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
187 for group in groups:
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
188 if not self.groups.has_key(group):
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
189 self.groups[group] = set()
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
190 self._groupList.add(group)
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
191 self.host.magicBox.addKey("@%s: " % group)
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
192 self.groups[group].add(jid)
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
193 self._contactList.add(jid)
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
194
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
195 def onMouseMove(self, sender, x, y):
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
196 pass
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
197
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
198 def onMouseDown(self, sender, x, y):
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
199 pass
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
200
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
201 def onMouseUp(self, sender, x, y):
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
202 pass
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
203
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
204 def onMouseEnter(self, sender):
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
205 if isinstance(sender, GroupLabel):
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
206 for contact in self._contactList:
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
207 if contact.jid in self.groups[sender.group]:
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
208 contact.addStyleName("selected")
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
209
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
210 def onMouseLeave(self, sender):
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
211 if isinstance(sender, GroupLabel):
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
212 for contact in self._contactList:
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
213 if contact.jid in self.groups[sender.group]:
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
214 contact.removeStyleName("selected")
0
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
215
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
216 class MiddlePannel(HorizontalPanel):
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
217
1
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
218 def __init__(self,host):
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
219 self.host=host
0
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
220 HorizontalPanel.__init__(self)
1
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
221 self.add(self.host.contactPanel)
0
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
222
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
223 class MainPanel(VerticalPanel):
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
224
1
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
225 def __init__(self, host):
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
226 self.host=host
0
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
227 VerticalPanel.__init__(self)
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
228
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
229 self.setHorizontalAlignment(HasAlignment.ALIGN_LEFT)
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
230 self.setVerticalAlignment(HasAlignment.ALIGN_TOP)
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
231
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
232 menu = Menu()
1
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
233 magic_box = host.magicBox
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
234 middle_panel = MiddlePannel(self.host)
0
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
235
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
236 self.add(menu)
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
237 self.add(magic_box)
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
238 self.add(middle_panel)
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
239
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
240 self.setCellHeight(menu, "5%")
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
241 self.setCellHeight(magic_box, "5%")
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
242 self.setCellVerticalAlignment(magic_box, HasAlignment.ALIGN_CENTER)
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
243 self.setCellHorizontalAlignment(magic_box, HasAlignment.ALIGN_CENTER)
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
244 self.setCellHeight(middle_panel, "90%")
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
245
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
246 self.setWidth("100%")
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
247 self.setHeight("100%")
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
248
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
249 class SatWebFrontend:
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
250 def onModuleLoad(self):
1
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
251 self.magicBox = MagicBox()
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
252 self.contactPanel = ContactPanel(self)
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
253 self.panel = MainPanel(self)
0
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
254 self._dialog = None
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
255 RootPanel().add(self.panel)
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
256 self._register = RegisterCall()
1
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
257 self._register.call('isRegistered',self._isRegisteredCB)
0
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
258
1
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
259 def _isRegisteredCB(self, registered):
0
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
260 if not registered:
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
261 self._dialog = RegisterBox(self.logged,centered=True)
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
262 self._dialog.show()
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
263 else:
1
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
264 self._register.call('isConnected', self._isConnectedCB)
0
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
265
1
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
266 def _isConnectedCB(self, connected):
0
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
267 if not connected:
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
268 self._register.call('connect',self.logged)
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
269 else:
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
270 self.logged()
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
271
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
272 def logged(self):
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
273 if self._dialog:
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
274 self._dialog.hide()
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
275 del self._dialog # don't work if self._dialog is None
1
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
276
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
277 #it's time to fill the page
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
278 bridge = BrigeCall()
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
279 bridge.call('getContacts', self._getContactsCB)
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
280
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
281 def _getContactsCB(self, contacts_data):
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
282 for contact in contacts_data:
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
283 jid, attributes, groups = contact
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
284 self.contactPanel.addContact(jid, attributes, groups)
0
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
285
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
286
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
287 if __name__ == '__main__':
1
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
288 pyjd.setup("http://localhost:8080/libervia.html")
0
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
289 app = SatWebFrontend()
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
290 app.onModuleLoad()
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
291 pyjd.run()
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
292