annotate libervia.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 0a7c685faa53
children 7325e787c22b
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
2
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents: 1
diff changeset
36 from contact import ContactPanel
0
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
37
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
38
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
39 class LiberviaJsonProxy(JSONProxy):
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
40 def __init__(self, *args, **kwargs):
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
41 JSONProxy.__init__(self, *args, **kwargs)
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
42 self.handler=self
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
43 self.cb={}
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
44
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
45 def call(self, method, cb, *args):
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
46 self.cb[method] = cb
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
47 self.callMethod(method,args)
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
48
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
49 def onRemoteResponse(self, response, request_info):
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
50 if self.cb.has_key(request_info.method):
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
51 self.cb[request_info.method](response)
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
52 del self.cb[request_info.method]
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
53
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
54 def onRemoteError(self, code, errobj, request_info):
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
55 if code != 0:
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
56 Window.alert("Internal server error")
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
57 else:
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
58 if isinstance(errobj['message'],dict):
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
59 Window.alert("Error %s: %s" % (errobj['message']['faultCode'], errobj['message']['faultString']))
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
60 else:
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
61 Window.alert("Error: %s" % errobj['message'])
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
62
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
63 class RegisterCall(LiberviaJsonProxy):
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
64 def __init__(self):
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
65 LiberviaJsonProxy.__init__(self, "/register_api",
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
66 ["isRegistered","isConnected","connect"])
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
67 self.handler=self
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
68 self.cb={}
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
69
2
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents: 1
diff changeset
70 class BridgeCall(LiberviaJsonProxy):
0
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
71 def __init__(self):
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
72 LiberviaJsonProxy.__init__(self, "/json_api",
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
73 ["getContacts"])
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
74
2
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents: 1
diff changeset
75 class BridgeSignals(LiberviaJsonProxy):
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents: 1
diff changeset
76 def __init__(self):
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents: 1
diff changeset
77 LiberviaJsonProxy.__init__(self, "/json_signal_api",
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents: 1
diff changeset
78 ["getSignals"])
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents: 1
diff changeset
79
0
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
80 class MenuCmd:
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
81
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
82 def __init__(self, object, handler):
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
83 self._object = object
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
84 self._handler = handler
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
85
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
86 def execute(self):
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
87 handler = getattr(self._object, self._handler)
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
88 handler()
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
89
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
90 class Menu(SimplePanel):
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
91
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
92 def __init__(self):
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
93 SimplePanel.__init__(self)
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
94
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
95 menu_general = MenuBar(vertical=True)
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
96 menu_general.addItem("Properties", MenuCmd(self, "onProperties"))
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
97
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
98 menu_games = MenuBar(vertical=True)
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
99 menu_games.addItem("Tarot", MenuCmd(self, "onTarotGame"))
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
100 menu_games.addItem("Xiangqi", MenuCmd(self, "onXiangqiGame"))
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
101
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
102 menubar = MenuBar(vertical=False)
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
103 menubar.addItem(MenuItem("General", menu_general))
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
104 menubar.addItem(MenuItem("Games", True, menu_games))
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
105 self.add(menubar)
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
106
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
107 def onProperties(self):
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
108 Window.alert("Properties selected")
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
109
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
110 def onTarotGame(self):
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
111 Window.alert("Tarot selected")
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
112
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
113 def onXiangqiGame(self):
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
114 Window.alert("Xiangqi selected")
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
115
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
116 class MagicBox(AutoCompleteTextBox):
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
117
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
118 def __init__(self):
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
119 AutoCompleteTextBox.__init__(self)
1
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
120
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
121 def addKey(self, key):
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
122 self.getCompletionItems().completions.append(key)
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 def addContact(self, jid, attributes, groups):
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
125 """Add a contact to the panel
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
126 @param jid: jid
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
127 @attributes: cf SàT Bridge API's newContact
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
128 @param groups: list of groups"""
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
129 for group in groups:
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
130 if not self.groups.has_key(group):
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
131 self.groups[group] = set()
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
132 self._groupList.add(group)
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
133 self.host.magicBox.addKey("@%s: " % group)
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
134 self.groups[group].add(jid)
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
135 self._contactList.add(jid)
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
136
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
137 def onMouseMove(self, sender, x, y):
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
138 pass
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
139
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
140 def onMouseDown(self, sender, x, y):
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
141 pass
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
142
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
143 def onMouseUp(self, sender, x, y):
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
144 pass
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 onMouseEnter(self, sender):
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
147 if isinstance(sender, GroupLabel):
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
148 for contact in self._contactList:
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
149 if contact.jid in self.groups[sender.group]:
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
150 contact.addStyleName("selected")
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
151
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
152 def onMouseLeave(self, sender):
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
153 if isinstance(sender, GroupLabel):
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
154 for contact in self._contactList:
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
155 if contact.jid in self.groups[sender.group]:
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
156 contact.removeStyleName("selected")
0
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
157
2
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents: 1
diff changeset
158 class MicroblogEntry(SimplePanel):
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents: 1
diff changeset
159
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents: 1
diff changeset
160 def __init__(self, text):
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents: 1
diff changeset
161 SimplePanel.__init__(self)
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents: 1
diff changeset
162 self._vPanel = VerticalPanel()
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents: 1
diff changeset
163 self._vPanel.setStyleName('microblogEntry')
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents: 1
diff changeset
164 _label = Label(text)
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents: 1
diff changeset
165 self._vPanel.add(_label)
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents: 1
diff changeset
166 self.add(self._vPanel)
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents: 1
diff changeset
167
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents: 1
diff changeset
168
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents: 1
diff changeset
169
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents: 1
diff changeset
170 class MicroblogPanel(VerticalPanel):
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents: 1
diff changeset
171
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents: 1
diff changeset
172 def __init__(self):
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents: 1
diff changeset
173 VerticalPanel.__init__(self)
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents: 1
diff changeset
174 self.setStyleName('microblogPanel')
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents: 1
diff changeset
175
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents: 1
diff changeset
176 def addEntry(self, text, author=None, date=None):
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents: 1
diff changeset
177 """Add an entry to the panel
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents: 1
diff changeset
178 @param text: main text of the entry
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents: 1
diff changeset
179 @param author: who wrote the entry
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents: 1
diff changeset
180 @param date: when the entry was written"""
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents: 1
diff changeset
181 _entry = MicroblogEntry(text)
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents: 1
diff changeset
182 self.add(_entry)
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents: 1
diff changeset
183
0
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
184 class MiddlePannel(HorizontalPanel):
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
185
1
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
186 def __init__(self,host):
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
187 self.host=host
0
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
188 HorizontalPanel.__init__(self)
2
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents: 1
diff changeset
189 self._left = self.host.contactPanel
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents: 1
diff changeset
190 self._right = HorizontalPanel()
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents: 1
diff changeset
191 self._right.setWidth('100%')
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents: 1
diff changeset
192 self._right.setHeight('100%')
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents: 1
diff changeset
193 test = MicroblogPanel()
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents: 1
diff changeset
194 self._right.add(test)
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents: 1
diff changeset
195 test.addEntry("test entry")
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents: 1
diff changeset
196 self.add(self._left)
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents: 1
diff changeset
197 self.setCellWidth(self._left, "15%")
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents: 1
diff changeset
198 self.add(self._right)
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents: 1
diff changeset
199 self.setCellWidth(self._right, "85%")
0
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
200
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
201 class MainPanel(VerticalPanel):
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
202
1
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
203 def __init__(self, host):
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
204 self.host=host
0
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
205 VerticalPanel.__init__(self)
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
206
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
207 self.setHorizontalAlignment(HasAlignment.ALIGN_LEFT)
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
208 self.setVerticalAlignment(HasAlignment.ALIGN_TOP)
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
209
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
210 menu = Menu()
1
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
211 magic_box = host.magicBox
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
212 middle_panel = MiddlePannel(self.host)
2
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents: 1
diff changeset
213 middle_panel.setWidth('100%')
0
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
214
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
215 self.add(menu)
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
216 self.add(magic_box)
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
217 self.add(middle_panel)
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
218
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
219 self.setCellHeight(menu, "5%")
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
220 self.setCellHeight(magic_box, "5%")
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
221 self.setCellVerticalAlignment(magic_box, HasAlignment.ALIGN_CENTER)
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
222 self.setCellHorizontalAlignment(magic_box, HasAlignment.ALIGN_CENTER)
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
223 self.setCellHeight(middle_panel, "90%")
2
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents: 1
diff changeset
224 self.setCellWidth(middle_panel, "100%")
0
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
225
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
226 self.setWidth("100%")
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
227 self.setHeight("100%")
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
228
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
229 class SatWebFrontend:
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
230 def onModuleLoad(self):
1
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
231 self.magicBox = MagicBox()
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
232 self.contactPanel = ContactPanel(self)
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
233 self.panel = MainPanel(self)
0
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
234 self._dialog = None
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
235 RootPanel().add(self.panel)
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
236 self._register = RegisterCall()
1
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
237 self._register.call('isRegistered',self._isRegisteredCB)
0
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
238
1
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
239 def _isRegisteredCB(self, registered):
0
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
240 if not registered:
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
241 self._dialog = RegisterBox(self.logged,centered=True)
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
242 self._dialog.show()
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
243 else:
1
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
244 self._register.call('isConnected', self._isConnectedCB)
0
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
245
1
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
246 def _isConnectedCB(self, connected):
0
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
247 if not connected:
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
248 self._register.call('connect',self.logged)
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
249 else:
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
250 self.logged()
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
251
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
252 def logged(self):
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
253 if self._dialog:
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
254 self._dialog.hide()
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
255 del self._dialog # don't work if self._dialog is None
1
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
256
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
257 #it's time to fill the page
2
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents: 1
diff changeset
258 bridge = BridgeCall()
1
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
259 bridge.call('getContacts', self._getContactsCB)
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
260
2
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents: 1
diff changeset
261 bridge_signals = BridgeSignals()
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents: 1
diff changeset
262 bridge_signals.call('getSignals', self._getSignalsCB)
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents: 1
diff changeset
263
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents: 1
diff changeset
264
1
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
265 def _getContactsCB(self, contacts_data):
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
266 for contact in contacts_data:
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
267 jid, attributes, groups = contact
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
268 self.contactPanel.addContact(jid, attributes, groups)
0
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
269
2
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents: 1
diff changeset
270 def _getSignalsCB(self, signal_data):
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents: 1
diff changeset
271 bridge_signals = BridgeSignals()
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents: 1
diff changeset
272 bridge_signals.call('getSignals', self._getSignalsCB)
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents: 1
diff changeset
273 print('Got signal ==> name: %s, params: %s' % (signal_data[0],signal_data[1]))
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents: 1
diff changeset
274
0
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
275
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
276 if __name__ == '__main__':
1
0a7c685faa53 ContactPanel: first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
277 pyjd.setup("http://localhost:8080/libervia.html")
0
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
278 app = SatWebFrontend()
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
279 app.onModuleLoad()
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
280 pyjd.run()
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
281