Mercurial > libervia-web
annotate browser_side/panels.py @ 55:d5266c41ca24
Roster list update, contact deletion + some refactoring
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 29 May 2011 02:13:53 +0200 |
parents | f25c4077f6b9 |
children | 5fa710058e2d |
rev | line source |
---|---|
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1 #!/usr/bin/python |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
2 # -*- coding: utf-8 -*- |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
3 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
4 """ |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
5 Libervia: a Salut à Toi frontend |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
6 Copyright (C) 2011 Jérôme Poisson (goffi@goffi.org) |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
7 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
8 This program is free software: you can redistribute it and/or modify |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
9 it under the terms of the GNU Affero General Public License as published by |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
10 the Free Software Foundation, either version 3 of the License, or |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
11 (at your option) any later version. |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
12 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
13 This program is distributed in the hope that it will be useful, |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
14 but WITHOUT ANY WARRANTY; without even the implied warranty of |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
16 GNU Affero General Public License for more details. |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
17 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
18 You should have received a copy of the GNU Affero General Public License |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
19 along with this program. If not, see <http://www.gnu.org/licenses/>. |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
20 """ |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
21 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
22 import pyjd # this is dummy in pyjs |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
23 from pyjamas.ui.SimplePanel import SimplePanel |
33 | 24 from pyjamas.ui.FlowPanel import FlowPanel |
25 from pyjamas.ui.AbsolutePanel import AbsolutePanel | |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
26 from pyjamas.ui.VerticalPanel import VerticalPanel |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
27 from pyjamas.ui.HorizontalPanel import HorizontalPanel |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
28 from pyjamas.ui.ScrollPanel import ScrollPanel |
23 | 29 from pyjamas.ui.TabPanel import TabPanel |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
30 from pyjamas.ui.HTMLPanel import HTMLPanel |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
31 from pyjamas.ui.Grid import Grid |
50 | 32 from pyjamas.ui.DialogBox import DialogBox |
33 | 33 from pyjamas.ui.AutoComplete import AutoCompleteTextBox |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
34 from pyjamas.ui.MenuBar import MenuBar |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
35 from pyjamas.ui.MenuItem import MenuItem |
52
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
51
diff
changeset
|
36 from pyjamas.ui.ListBox import ListBox |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
37 from pyjamas.ui.Label import Label |
50 | 38 from pyjamas.ui.TextBox import TextBox |
39 from pyjamas.ui.Button import Button | |
33 | 40 from pyjamas.ui.HTML import HTML |
48
153de5d461a4
added Social Contract \o. (in French only so far)
Goffi <goffi@goffi.org>
parents:
43
diff
changeset
|
41 from pyjamas.ui.Frame import Frame |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
42 from pyjamas.ui.DropWidget import DropWidget |
19 | 43 from pyjamas.ui.ClickListener import ClickHandler |
33 | 44 from pyjamas.ui.KeyboardListener import KEY_ENTER |
45 from pyjamas.Timer import Timer | |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
46 from pyjamas import Window |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
47 from pyjamas import DOM |
33 | 48 from __pyjamas__ import JS, doc |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
49 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
50 from pyjamas.dnd import makeDraggable |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
51 from pyjamas.ui.DragWidget import DragWidget, DragContainer |
36 | 52 from card_game import CardPanel |
19 | 53 from jid import JID |
33 | 54 from tools import html_sanitize |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
55 from datetime import datetime |
19 | 56 from time import time |
48
153de5d461a4
added Social Contract \o. (in French only so far)
Goffi <goffi@goffi.org>
parents:
43
diff
changeset
|
57 import dialog |
54
f25c4077f6b9
addind contact + subscription management + misc
Goffi <goffi@goffi.org>
parents:
52
diff
changeset
|
58 import re |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
59 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
60 class MenuCmd: |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
61 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
62 def __init__(self, object, handler): |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
63 self._object = object |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
64 self._handler = handler |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
65 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
66 def execute(self): |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
67 handler = getattr(self._object, self._handler) |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
68 handler() |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
69 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
70 class Menu(SimplePanel): |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
71 |
23 | 72 def __init__(self, host): |
73 self.host = host | |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
74 SimplePanel.__init__(self) |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
75 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
76 menu_general = MenuBar(vertical=True) |
48
153de5d461a4
added Social Contract \o. (in French only so far)
Goffi <goffi@goffi.org>
parents:
43
diff
changeset
|
77 menu_general.addItem("Social contract", MenuCmd(self, "onSocialContract")) |
153de5d461a4
added Social Contract \o. (in French only so far)
Goffi <goffi@goffi.org>
parents:
43
diff
changeset
|
78 menu_general.addItem("About", MenuCmd(self, "onAbout")) |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
79 |
51 | 80 menu_contacts = MenuBar(vertical=True) |
81 menu_contacts.addItem("add contact", MenuCmd(self, "onAddContact")) | |
55
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
82 menu_contacts.addItem("update contact", MenuCmd(self, "onUpdateContact")) |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
83 menu_contacts.addItem("remove contact", MenuCmd(self, "onRemoveContact")) |
51 | 84 |
50 | 85 menu_group = MenuBar(vertical=True) |
86 menu_group.addItem("join room", MenuCmd(self, "onJoinRoom")) | |
87 | |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
88 menu_games = MenuBar(vertical=True) |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
89 menu_games.addItem("Tarot", MenuCmd(self, "onTarotGame")) |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
90 menu_games.addItem("Xiangqi", MenuCmd(self, "onXiangqiGame")) |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
91 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
92 menubar = MenuBar(vertical=False) |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
93 menubar.addItem(MenuItem("General", menu_general)) |
51 | 94 menubar.addItem(MenuItem("Contacts", menu_contacts)) |
50 | 95 menubar.addItem(MenuItem("Groups", menu_group)) |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
96 menubar.addItem(MenuItem("Games", True, menu_games)) |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
97 self.add(menubar) |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
98 |
48
153de5d461a4
added Social Contract \o. (in French only so far)
Goffi <goffi@goffi.org>
parents:
43
diff
changeset
|
99 #General menu |
153de5d461a4
added Social Contract \o. (in French only so far)
Goffi <goffi@goffi.org>
parents:
43
diff
changeset
|
100 def onSocialContract(self): |
153de5d461a4
added Social Contract \o. (in French only so far)
Goffi <goffi@goffi.org>
parents:
43
diff
changeset
|
101 _frame = Frame('contrat_social.html') |
153de5d461a4
added Social Contract \o. (in French only so far)
Goffi <goffi@goffi.org>
parents:
43
diff
changeset
|
102 _frame.setStyleName('infoFrame') |
153de5d461a4
added Social Contract \o. (in French only so far)
Goffi <goffi@goffi.org>
parents:
43
diff
changeset
|
103 _dialog = dialog.InfoDialog("Contrat Social", _frame) |
153de5d461a4
added Social Contract \o. (in French only so far)
Goffi <goffi@goffi.org>
parents:
43
diff
changeset
|
104 _dialog.setSize('80%', '80%') |
153de5d461a4
added Social Contract \o. (in French only so far)
Goffi <goffi@goffi.org>
parents:
43
diff
changeset
|
105 _dialog.show() |
153de5d461a4
added Social Contract \o. (in French only so far)
Goffi <goffi@goffi.org>
parents:
43
diff
changeset
|
106 |
153de5d461a4
added Social Contract \o. (in French only so far)
Goffi <goffi@goffi.org>
parents:
43
diff
changeset
|
107 def onAbout(self): |
49 | 108 _about = HTML("""<b>Libervia</b>, a Salut à Toi project<br /> |
109 <br /> | |
110 You can contact the author at <a href="mailto:goffi@goffi.org">goffi@goffi.org</a><br /> | |
111 Blog available (mainly in french) at <a href="http://www.goffi.org" target="_blank">http://www.goffi.org</a><br /> | |
112 Project page: <a href="http://wiki.goffi.org/wiki/Salut_à_Toi"target="_blank">http://wiki.goffi.org/wiki/Salut_à_Toi</a><br /> | |
113 <br /> | |
51 | 114 Any help welcome :) |
49 | 115 """) |
116 _dialog = dialog.InfoDialog("About", _about) | |
117 _dialog.show() | |
51 | 118 |
119 #Contact menu | |
120 def onAddContact(self): | |
121 """Q&D contact addition""" | |
52
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
51
diff
changeset
|
122 _dialog = None |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
51
diff
changeset
|
123 edit = TextBox() |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
51
diff
changeset
|
124 |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
51
diff
changeset
|
125 def addContactCb(sender): |
54
f25c4077f6b9
addind contact + subscription management + misc
Goffi <goffi@goffi.org>
parents:
52
diff
changeset
|
126 if not re.match(r'^.+@.+\..+',edit.getText(), re.IGNORECASE): |
f25c4077f6b9
addind contact + subscription management + misc
Goffi <goffi@goffi.org>
parents:
52
diff
changeset
|
127 Window.alert('You must enter a valid contact JID (like "contact@libervia.org")') |
52
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
51
diff
changeset
|
128 _dialog.show() |
54
f25c4077f6b9
addind contact + subscription management + misc
Goffi <goffi@goffi.org>
parents:
52
diff
changeset
|
129 else: |
f25c4077f6b9
addind contact + subscription management + misc
Goffi <goffi@goffi.org>
parents:
52
diff
changeset
|
130 self.host.bridge.call('addContact', None, edit.getText(), '', _dialog.getSelectedGroups() ) |
51 | 131 |
52
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
51
diff
changeset
|
132 label = Label("new contact identifier (JID):") |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
51
diff
changeset
|
133 edit.setText('@libervia.org') |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
51
diff
changeset
|
134 edit.setWidth('100%') |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
51
diff
changeset
|
135 _dialog = dialog.GroupSelector([label, edit], self.host.contact_panel.getGroups(), [], addContactCb) |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
51
diff
changeset
|
136 _dialog.setHTML('<b>Adding contact</b>') |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
51
diff
changeset
|
137 _dialog.show() |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
51
diff
changeset
|
138 |
55
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
139 def onUpdateContact(self): |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
140 pass |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
141 |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
142 def onRemoveContact(self): |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
143 _dialog = None |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
144 _contacts_list = ListBox() |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
145 |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
146 def secondConfirmCb(confirm): |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
147 if confirm: |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
148 for contact in _contacts_list.getSelectedValues(): |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
149 self.host.bridge.call('delContact', None, contact) |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
150 else: |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
151 _dialog.show() |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
152 |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
153 def dialogCb(confirm): |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
154 if confirm: |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
155 html_list = ''.join(['<li>%s</li>' % html_sanitize(contact) for contact in _contacts_list.getSelectedValues()]) |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
156 html_body = "Are you sure to remove the following contacts from your contact list ?<ul>%s</ul>" % html_list |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
157 dialog.ConfirmDialog(secondConfirmCb, html_body).show() |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
158 |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
159 for contact in self.host.contact_panel.getContacts(): |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
160 _contacts_list.addItem(contact) |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
161 _dialog = dialog.GenericConfirmDialog([_contacts_list], dialogCb, "Who do you want to remove from your contacts ?") |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
162 _dialog.show() |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
163 |
50 | 164 #Group menu |
165 def onJoinRoom(self): | |
166 _dialog = None | |
167 _edit = None | |
168 | |
169 def onOK(sender): | |
170 if not _edit.getText(): | |
171 Window.alert('You must enter a room jid in the form libervia@conference.libervia.org') | |
172 if self.host.whoami: | |
173 nick = self.host.whoami.node | |
174 self.host.bridge.call('joinMUC', None, _edit.getText(), nick) | |
175 _dialog.hide() | |
176 | |
177 def onCancel(sender): | |
178 _dialog.hide() | |
179 | |
180 _main_panel = VerticalPanel() | |
181 _label = Label("Discussion room:") | |
182 _edit = TextBox() | |
183 _edit.setText('libervia@conference.tazar.int') | |
184 hpanel = HorizontalPanel() | |
185 hpanel.add(_label) | |
186 hpanel.add(_edit) | |
187 _main_panel.add(hpanel) | |
188 button_panel = HorizontalPanel() | |
189 button_panel.add(Button("Join", onOK)) | |
190 button_panel.add(Button("Cancel", onCancel)) | |
191 _main_panel.add(button_panel) | |
192 _dialog = DialogBox(centered=True) | |
193 _dialog.setHTML('<b>Group discussions</b>') | |
194 _dialog.setWidget(_main_panel) | |
195 _dialog.show() | |
196 | |
197 | |
48
153de5d461a4
added Social Contract \o. (in French only so far)
Goffi <goffi@goffi.org>
parents:
43
diff
changeset
|
198 #Game menu |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
199 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
200 def onTarotGame(self): |
23 | 201 #Window.alert("Tarot selected") |
27
d89982865c57
browser side: ContactsChooser is now used to ask for 3 others players when tarot game is launched + names refactoring
Goffi <goffi@goffi.org>
parents:
23
diff
changeset
|
202 #self.host.tab_panel.add(EmptyPanel(self.host), "Tarot") |
d89982865c57
browser side: ContactsChooser is now used to ask for 3 others players when tarot game is launched + names refactoring
Goffi <goffi@goffi.org>
parents:
23
diff
changeset
|
203 def onPlayersSelected(other_players): |
d89982865c57
browser side: ContactsChooser is now used to ask for 3 others players when tarot game is launched + names refactoring
Goffi <goffi@goffi.org>
parents:
23
diff
changeset
|
204 self.host.bridge.call('launchTarotGame', None, other_players) |
48
153de5d461a4
added Social Contract \o. (in French only so far)
Goffi <goffi@goffi.org>
parents:
43
diff
changeset
|
205 dialog.ContactsChooser(self.host, onPlayersSelected, 3, text="Please select 3 other players").getContacts() |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
206 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
207 def onXiangqiGame(self): |
49 | 208 Window.alert("A Xiangqi game is planed, but not available yet") |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
209 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
210 class DropCell(DropWidget): |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
211 """Cell in the middle grid which replace itself with the dropped widget on DnD""" |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
212 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
213 def __init__(self): |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
214 DropWidget.__init__(self) |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
215 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
216 def onDragEnter(self, event): |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
217 print "drag enter" |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
218 self.addStyleName('dragover') |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
219 DOM.eventPreventDefault(event) |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
220 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
221 def onDragLeave(self, event): |
33 | 222 print "\ndrag leave" |
223 if event.clientX <= self.getAbsoluteLeft() or event.clientY <= self.getAbsoluteTop() or\ | |
224 event.clientX >= self.getAbsoluteLeft() + self.getOffsetWidth()-1 or event.clientY >= self.getAbsoluteTop() + self.getOffsetHeight()-1: | |
225 #We check that we are inside widget's box, and we don't remove the style in this case because | |
226 #if the mouse is over a widget inside the DropWidget, if will leave the DropWidget, and we | |
227 #don't want that | |
228 self.removeStyleName('dragover') | |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
229 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
230 def onDragOver(self, event): |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
231 DOM.eventPreventDefault(event) |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
232 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
233 def _getCellAndRow(self, grid, event): |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
234 """Return cell and row index where the event is occuring""" |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
235 cell = grid.getEventTargetCell(event) |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
236 row = DOM.getParent(cell) |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
237 return (row.rowIndex, cell.cellIndex) |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
238 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
239 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
240 def onDrop(self, event): |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
241 print "Empty Panel: onDrop" |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
242 dt = event.dataTransfer |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
243 #'text', 'text/plain', and 'Text' are equivalent. |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
244 try: |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
245 item = dt.getData("text/plain") |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
246 item_type = dt.getData("type") |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
247 print "message: %s" % item |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
248 print "type: %s" % item_type |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
249 except: |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
250 print "no message found" |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
251 item=' ' |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
252 item_type = None |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
253 DOM.eventPreventDefault(event) |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
254 if item_type=="GROUP": |
19 | 255 _new_panel = MicroblogPanel(self.host, item) |
256 _new_panel.setAcceptedGroup(item) | |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
257 elif item_type=="CONTACT": |
19 | 258 _contact = JID(item) |
259 _new_panel = ChatPanel(self.host, _contact) | |
260 _new_panel.historyPrint() | |
261 elif item_type=="CONTACT_TITLE": | |
262 _new_panel = MicroblogPanel(self.host, accept_all=True) | |
39
305e81c7a32c
Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
263 else: |
305e81c7a32c
Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
264 return |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
265 self.host.mpanels.remove(self) |
19 | 266 self.host.mpanels.append(_new_panel) |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
267 grid = self.getParent() |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
268 row_idx, cell_idx = self._getCellAndRow(grid, event) |
19 | 269 if self.host.selected == self: |
270 self.host.select(None) | |
34 | 271 self.removeFromParent() |
19 | 272 grid.setWidget(row_idx, cell_idx, _new_panel) |
34 | 273 _panels = list(grid) #this suppose that we only use 1 row, need to be changed in the futur |
274 _unempty_panels = filter(lambda wid:not isinstance(wid,EmptyPanel),list(grid)) | |
275 _width = 90/float(len(_unempty_panels) or 1) | |
276 #now we resize all the cell of the column | |
277 for panel in _unempty_panels: | |
278 td_elt = panel.getElement().parentNode | |
279 DOM.setStyleAttribute(td_elt, "width", "%s%%" % _width) | |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
280 #FIXME: delete object ? Check the right way with pyjamas |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
281 |
34 | 282 class ScrollPanelWrapper(SimplePanel): |
283 """Scroll Panel like component, wich use the full available space | |
284 to work around percent size issue, it use some of the ideas found | |
285 here: http://code.google.com/p/google-web-toolkit/issues/detail?id=316 | |
286 specially in code given at comment #46, thanks to Stefan Bachert""" | |
287 | |
288 def __init__(self, *args, **kwargs): | |
289 SimplePanel.__init__(self) | |
290 self.spanel = ScrollPanel(*args, **kwargs) | |
291 SimplePanel.setWidget(self, self.spanel) | |
292 DOM.setStyleAttribute(self.getElement(), "position", "relative") | |
293 DOM.setStyleAttribute(self.getElement(), "top", "0px") | |
294 DOM.setStyleAttribute(self.getElement(), "left", "0px") | |
295 DOM.setStyleAttribute(self.getElement(), "width", "100%") | |
296 DOM.setStyleAttribute(self.getElement(), "height", "100%") | |
297 DOM.setStyleAttribute(self.spanel.getElement(), "position", "absolute") | |
298 DOM.setStyleAttribute(self.spanel.getElement(), "width", "100%") | |
299 DOM.setStyleAttribute(self.spanel.getElement(), "height", "100%") | |
300 | |
301 def setWidget(self, widget): | |
302 self.spanel.setWidget(widget) | |
303 | |
304 def setScrollPosition(self, position): | |
305 self.spanel.setScrollPosition(position) | |
306 | |
307 def scrollToBottom(self): | |
308 self.setScrollPosition(self.spanel.getElement().scrollHeight) | |
309 | |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
310 class EmptyPanel(DropCell, SimplePanel): |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
311 """Empty dropable panel""" |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
312 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
313 def __init__(self, host): |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
314 SimplePanel.__init__(self) |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
315 self.host = host |
34 | 316 _panel = HTMLPanel("") |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
317 self.add(_panel) |
34 | 318 self.setHeight('100%') |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
319 DropCell.__init__(self) |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
320 |
33 | 321 class UniBoxPanel(SimplePanel): |
322 """Panel containing the UniBox""" | |
323 | |
324 def __init__(self, host): | |
325 SimplePanel.__init__(self) | |
326 self.setStyleName('uniBoxPanel') | |
327 self.unibox = UniBox(host) | |
328 self.unibox.setWidth('100%') | |
329 self.add(self.unibox) | |
330 | |
331 class UniBox(AutoCompleteTextBox): | |
332 """This text box is used as a main typing point, for message, microblog, etc""" | |
333 | |
334 def __init__(self, host): | |
335 AutoCompleteTextBox.__init__(self) | |
336 self._popup = None | |
337 self._timer = Timer(notify=self._timeCb) | |
338 self.host = host | |
339 | |
340 def addKey(self, key): | |
341 self.getCompletionItems().completions.append(key) | |
342 | |
55
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
343 def removeKey(self, key): |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
344 try: |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
345 self.getCompletionItems().completions.remove(key) |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
346 except KeyError: |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
347 print "WARNING: trying to remove an unknown key" |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
348 |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
349 |
33 | 350 def showWarning(self, target_data): |
351 type, target = target_data | |
352 if type == "PUBLIC": | |
353 msg = "This message will be PUBLIC and everybody will be able to see it, even people you don't know" | |
354 style = "targetPublic" | |
355 elif type == "GROUP": | |
356 msg = "This message will be published for all the people of the group <span class='warningTarget'>%s</span>" % (target or '') | |
357 style = "targetGroup" | |
358 elif type == "STATUS": | |
359 msg = "This will be your new status message" | |
360 style = "targetStatus" | |
361 elif type == "ONE2ONE": | |
362 msg = "This message will be sent to your contact <span class='warningTarget'>%s</span>" % target | |
363 style = "targetOne2One" | |
364 else: | |
365 print "WARNING: undetermined target for this message" | |
366 return | |
367 contents = HTML(msg) | |
368 | |
48
153de5d461a4
added Social Contract \o. (in French only so far)
Goffi <goffi@goffi.org>
parents:
43
diff
changeset
|
369 self._popup = dialog.PopupPanelWrapper(autoHide=False, modal=False) |
33 | 370 self._popup.target_data = target_data |
371 self._popup.add(contents) | |
372 self._popup.setStyleName("warningPopup") | |
373 if style: | |
374 self._popup.addStyleName(style) | |
375 | |
376 left = 0 | |
377 top = 0 #max(0, self.getAbsoluteTop() - contents.getOffsetHeight() - 2) | |
378 self._popup.setPopupPosition(left, top) | |
379 self._popup.setPopupPosition(left, top) | |
380 self._popup.show() | |
381 | |
382 def _timeCb(self, timer): | |
383 if self._popup: | |
384 self._popup.hide() | |
385 del self._popup | |
386 self._popup = None | |
387 | |
388 def _getTarget(self, txt): | |
389 """Say who will receive the messsage | |
390 Return a tuple (target_type, target info)""" | |
391 type = None | |
392 target = None | |
393 if txt.startswith('@@: '): | |
394 type = "PUBLIC" | |
395 elif txt.startswith('@'): | |
396 type = "GROUP" | |
397 _end = txt.find(': ') | |
398 if _end == -1: | |
399 type = "STATUS" | |
400 else: | |
401 target = txt[1:_end] #only one target group is managed for the moment | |
402 if not target in self.host.contact_panel.getGroups(): | |
403 target = None | |
404 elif self.host.selected == None: | |
405 type = "STATUS" | |
406 elif isinstance(self.host.selected, ChatPanel): | |
407 type = "ONE2ONE" | |
408 target = str(self.host.selected.target) | |
409 else: | |
410 print self.host.selected | |
411 type = "UNKNOWN" | |
412 return (type, target) | |
413 | |
414 def onKeyPress(self, sender, keycode, modifiers): | |
415 _txt = self.getText() | |
416 if not self._popup: | |
417 self.showWarning(self._getTarget(_txt)) | |
418 else: | |
419 _target = self._getTarget(_txt) | |
420 if _target != self._popup.target_data: | |
421 self._timeCb(None) #we remove the popup | |
422 self.showWarning(_target) | |
423 | |
424 self._timer.schedule(2000) | |
425 | |
426 if keycode == KEY_ENTER and not self.visible: | |
427 if _txt: | |
428 if _txt.startswith('@'): | |
429 self.host.bridge.call('sendMblog', None, self.getText()) | |
430 elif self.host.selected == None: | |
431 self.host.bridge.call('setStatus', None, _txt) | |
432 elif isinstance(self.host.selected, ChatPanel): | |
433 _chat = self.host.selected | |
434 mess_type = "groupchat" if _chat.type=='group' else "chat" | |
435 self.host.bridge.call('sendMessage', None, str(_chat.target), _txt, '', mess_type) | |
436 self.setText('') | |
437 self._timeCb(None) #we remove the popup | |
438 | |
439 def complete(self): | |
440 #self.visible=False #XXX: self.visible is not unset in pyjamas when ENTER is pressed and a completion is done | |
441 #XXX: fixed directly on pyjamas, if the patch is accepted, no need to walk around this | |
442 return AutoCompleteTextBox.complete(self) | |
443 | |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
444 class MicroblogEntry(SimplePanel): |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
445 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
446 def __init__(self, body, author, timestamp): |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
447 SimplePanel.__init__(self) |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
448 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
449 _datetime = datetime.fromtimestamp(timestamp) |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
450 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
451 panel = HTMLPanel("<div class='mb_entry_header'><span class='mb_entry_author'>%(author)s</span> on <span class='mb_entry_timestamp'>%(timestamp)s</span></div><div class='mb_entry_body'>%(body)s</div>" % |
51 | 452 {"author": html_sanitize(author), |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
453 "timestamp": _datetime, |
51 | 454 "body": html_sanitize(body)} |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
455 ) |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
456 panel.setStyleName('microblogEntry') |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
457 self.add(panel) |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
458 |
34 | 459 class MicroblogPanel(DropCell, ScrollPanelWrapper): |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
460 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
461 def __init__(self,host, title=' ', accept_all=False): |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
462 """Panel used to show microblog |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
463 @param title: title of the panel |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
464 @param accept_all: if true, show every message, without filtering jids""" |
34 | 465 ScrollPanelWrapper.__init__(self) |
466 DropCell.__init__(self) | |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
467 self.host = host |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
468 self.accept_all = accept_all |
51 | 469 title=html_sanitize(title) |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
470 self.accepted_groups = [] |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
471 _class = ['mb_panel_header'] |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
472 if title == ' ': |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
473 _class.append('empty_header') |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
474 self.vpanel = VerticalPanel() |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
475 self.vpanel.add(HTMLPanel("<div class='%s'>%s</div>" % (','.join(_class),title))) |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
476 self.vpanel.setWidth('100%') |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
477 self.setStyleName('microblogPanel') |
34 | 478 self.setWidget(self.vpanel) |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
479 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
480 def addEntry(self, text, author=None, timestamp=None): |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
481 """Add an entry to the panel |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
482 @param text: main text of the entry |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
483 @param author: who wrote the entry |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
484 @param date: when the entry was written""" |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
485 _entry = MicroblogEntry(text, author, timestamp) |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
486 self.vpanel.insert(_entry,1) |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
487 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
488 def setAcceptedGroup(self, group): |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
489 """Set the group which can be displayed in this panel |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
490 @param group: string of the group, or list of string |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
491 """ |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
492 if isinstance(group, list): |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
493 self.accepted_groups.extend(group) |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
494 else: |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
495 self.accepted_groups.append(group) |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
496 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
497 def isJidAccepted(self, jid): |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
498 """Tell if a jid is actepted and show in this panel |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
499 @param jid: jid |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
500 @return: True if the jid is accepted""" |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
501 if self.accept_all: |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
502 return True |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
503 for group in self.accepted_groups: |
27
d89982865c57
browser side: ContactsChooser is now used to ask for 3 others players when tarot game is launched + names refactoring
Goffi <goffi@goffi.org>
parents:
23
diff
changeset
|
504 if self.host.contact_panel.isContactInGroup(group, jid): |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
505 return True |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
506 return False |
19 | 507 |
20 | 508 class StatusPanel(HTMLPanel, ClickHandler): |
509 def __init__(self, host, status=''): | |
510 self.host = host | |
511 self.status = status or ' ' | |
19 | 512 HTMLPanel.__init__(self, self.__getContent()) |
20 | 513 self.setStyleName('statusPanel') |
514 ClickHandler.__init__(self) | |
515 self.addClickListener(self) | |
19 | 516 |
517 def __getContent(self): | |
51 | 518 return "<span class='status'>%(status)s</span>" % {'status':html_sanitize(self.status)} |
19 | 519 |
520 def changeStatus(self, new_status): | |
20 | 521 self.status = new_status or ' ' |
19 | 522 self.setHTML(self.__getContent()) |
523 | |
20 | 524 def onClick(self, sender, event): |
525 #As status is the default target of uniBar, we don't want to select anything if click on it | |
526 self.host.select(None) | |
527 | |
19 | 528 class ChatText(HTMLPanel): |
529 | |
530 def __init__(self, timestamp, nick, mymess, msg): | |
531 _date = datetime.fromtimestamp(float(timestamp or time())) | |
532 _msg_class = ["chat_text_msg"] | |
533 if mymess: | |
534 _msg_class.append("chat_text_mymess") | |
535 HTMLPanel.__init__(self, "<span class='chat_text_timestamp'>%(timestamp)s</span> <span class='chat_text_nick'>%(nick)s</span> <span class='%(msg_class)s'>%(msg)s</span>" % | |
536 {"timestamp": _date.strftime("%H:%M"), | |
51 | 537 "nick": "[%s]" % html_sanitize(nick), |
19 | 538 "msg_class": ' '.join(_msg_class), |
51 | 539 "msg": html_sanitize(msg)} |
19 | 540 ) |
541 self.setStyleName('chatText') | |
33 | 542 |
543 class Occupant(HTML): | |
544 """Occupant of a MUC room""" | |
545 | |
546 def __init__(self, nick): | |
547 self.nick = nick | |
35 | 548 HTML.__init__(self, "<div class='occupant'>%s</div>" % html_sanitize(nick)) |
549 | |
550 def __str__(self): | |
551 return nick | |
33 | 552 |
553 class OccupantsList(AbsolutePanel): | |
554 """Panel user to show occupants of a room""" | |
555 | |
556 def __init__(self): | |
557 AbsolutePanel.__init__(self) | |
35 | 558 self.occupants_list = {} |
33 | 559 self.setStyleName('occupantsList') |
560 | |
561 def addOccupant(self, nick): | |
35 | 562 _occupant = Occupant(nick) |
563 self.occupants_list[nick] = _occupant | |
564 self.add(_occupant) | |
33 | 565 |
35 | 566 def removeOccupant(self, nick): |
567 try: | |
568 self.remove(self.occupants_list[nick]) | |
569 except KeyError: | |
570 print "ERROR: trying to remove an unexisting nick" | |
571 | |
572 def clear(self): | |
573 self.occupants_list.clear() | |
574 AbsolutePanel.clear(self) | |
575 | |
576 class ChatPanel(DropCell, ClickHandler, ScrollPanelWrapper): | |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
577 |
19 | 578 def __init__(self, host, target, type='one2one'): |
579 """Panel used for conversation (one 2 one or group chat) | |
580 @param host: SatWebFrontend instance | |
581 @param target: entity (JID) with who we have a conversation (contact's jid for one 2 one chat, or MUC room) | |
582 @param type: one2one for simple conversation, group for MUC""" | |
35 | 583 ScrollPanelWrapper.__init__(self) |
34 | 584 DropCell.__init__(self) |
585 ClickHandler.__init__(self) | |
586 self.vpanel = VerticalPanel() | |
587 self.vpanel.setSize('100%','100%') | |
19 | 588 self.host = host |
33 | 589 self.type = type |
590 self.nick = None | |
19 | 591 if not target: |
592 print "ERROR: Empty target !" | |
593 return | |
594 self.target = target | |
595 title="%s" % target.bare | |
596 _class = ['mb_panel_header'] | |
51 | 597 self.header = HTMLPanel("<div class='%s'>%s</div>" % (','.join(_class),html_sanitize(title))) |
34 | 598 self.header.setStyleName('chatHeader') |
33 | 599 self.body = AbsolutePanel() |
600 self.body.setStyleName('chatPanel_body') | |
601 chat_area = HorizontalPanel() | |
602 chat_area.setStyleName('chatArea') | |
603 if type == 'group': | |
604 self.occupants_list = OccupantsList() | |
605 chat_area.add(self.occupants_list) | |
606 self.body.add(chat_area) | |
607 self.content = AbsolutePanel() | |
608 self.content.setStyleName('chatContent') | |
34 | 609 self.content_scroll = ScrollPanelWrapper(self.content) |
610 chat_area.add(self.content_scroll) | |
611 chat_area.setCellWidth(self.content_scroll, '100%') | |
612 self.vpanel.add(self.header) | |
613 self.vpanel.setCellHeight(self.header, '1%') | |
614 self.vpanel.add(self.body) | |
615 self.setWidget(self.vpanel) | |
19 | 616 self.setStyleName('chatPanel') |
617 self.addClickListener(self) | |
618 | |
38
7bea2ae0c4fb
Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents:
37
diff
changeset
|
619 def doDetachChildren(self): |
7bea2ae0c4fb
Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents:
37
diff
changeset
|
620 #We need to force the use of a panel subclass method here, |
7bea2ae0c4fb
Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents:
37
diff
changeset
|
621 #for the same reason as doAttachChildren |
7bea2ae0c4fb
Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents:
37
diff
changeset
|
622 ScrollPanelWrapper.doDetachChildren(self) |
7bea2ae0c4fb
Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents:
37
diff
changeset
|
623 |
7bea2ae0c4fb
Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents:
37
diff
changeset
|
624 def doAttachChildren(self): |
7bea2ae0c4fb
Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents:
37
diff
changeset
|
625 #We need to force the use of a panel subclass method here, else |
7bea2ae0c4fb
Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents:
37
diff
changeset
|
626 #the event will not propagate to children |
7bea2ae0c4fb
Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents:
37
diff
changeset
|
627 ScrollPanelWrapper.doAttachChildren(self) |
7bea2ae0c4fb
Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents:
37
diff
changeset
|
628 |
19 | 629 def onClick(self, sender, event): |
630 self.host.select(self) | |
631 | |
632 def setUserNick(self, nick): | |
633 """Set the nick of the user, usefull for e.g. change the color of the user""" | |
634 self.nick = nick | |
33 | 635 |
636 def setPresents(self, nicks): | |
637 """Set the users presents in this room | |
638 @param occupants: list of nicks (string)""" | |
35 | 639 self.occupants_list.clear() |
33 | 640 for nick in nicks: |
641 self.occupants_list.addOccupant(nick) | |
642 | |
35 | 643 def userJoined(self, nick, data): |
644 print "userJoined:", nick, data | |
645 self.occupants_list.addOccupant(nick) | |
646 self.printInfo("=> %s has joined the room" % nick) | |
647 | |
648 def userLeft(self, nick, data): | |
649 print "userLeft:", nick, data | |
650 self.occupants_list.removeOccupant(nick) | |
651 self.printInfo("<= %s has left the room" % nick) | |
652 | |
19 | 653 def historyPrint(self, size=20): |
654 """Print the initial history""" | |
655 def getHistoryCB(history): | |
656 stamps=history.keys() | |
657 stamps.sort() | |
33 | 658 for stamp in stamps: |
19 | 659 self.printMessage(history[stamp][0], history[stamp][1], stamp) |
660 self.host.bridge.call('getHistory', getHistoryCB, self.host.whoami.bare, str(self.target), 20) | |
35 | 661 |
662 def printInfo(self, msg, type='normal'): | |
663 """Print general info | |
664 @param msg: message to print | |
665 @type: one of: | |
666 normal: general info like "toto has joined the room" | |
667 me: "/me" information like "/me clenches his fist" ==> "toto clenches his fist" | |
668 """ | |
54
f25c4077f6b9
addind contact + subscription management + misc
Goffi <goffi@goffi.org>
parents:
52
diff
changeset
|
669 _wid = Label(msg) |
35 | 670 if type == 'normal': |
671 _wid.setStyleName('chatTextInfo') | |
672 elif type == 'me': | |
673 _wid.setStyleName('chatTextMe') | |
674 else: | |
675 _wid.setStyleName('chatTextInfo') | |
676 self.content.add(_wid) | |
677 | |
678 | |
19 | 679 def printMessage(self, from_jid, msg, timestamp=None): |
680 """Print message in chat window. Must be implemented by child class""" | |
681 _jid=JID(from_jid) | |
33 | 682 nick = _jid.node if self.type=='one2one' else _jid.resource |
683 mymess = _jid.resource == self.nick if self.type == "group" else _jid.bare == self.host.whoami.bare #mymess = True if message comes from local user | |
35 | 684 if msg.startswith('/me '): |
19 | 685 self.printInfo('* %s %s' % (nick, msg[4:]),type='me') |
35 | 686 return |
19 | 687 self.content.add(ChatText(timestamp, nick, mymess, msg)) |
34 | 688 self.content_scroll.scrollToBottom() |
36 | 689 |
690 def startGame(self, game_type, referee, players): | |
691 """Configure the chat window to start a game""" | |
692 if game_type=="Tarot": | |
693 self.tarot_panel = CardPanel(self, referee, players, self.nick) | |
694 self.vpanel.insert(self.tarot_panel, 1) | |
695 self.vpanel.setCellHeight(self.tarot_panel, self.tarot_panel.getHeight()) | |
37
b306aa090438
Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
696 |
b306aa090438
Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
697 def getGame(self, game_type): |
b306aa090438
Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
698 """Return class managing the game type""" |
b306aa090438
Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
699 #TODO: check that the game is launched, and manage errors |
b306aa090438
Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
700 if game_type=="Tarot": |
b306aa090438
Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
701 return self.tarot_panel |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
702 |
34 | 703 class MainDiscussionPanel(HorizontalPanel): |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
704 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
705 def __init__(self, host): |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
706 self.host=host |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
707 HorizontalPanel.__init__(self) |
27
d89982865c57
browser side: ContactsChooser is now used to ask for 3 others players when tarot game is launched + names refactoring
Goffi <goffi@goffi.org>
parents:
23
diff
changeset
|
708 self._left = self.host.contact_panel |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
709 self._right = Grid(1,3) |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
710 self._right.setWidth('100%') |
34 | 711 self._right.setHeight('100%') |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
712 self.add(self._left) |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
713 self.setCellWidth(self._left, "15%") |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
714 self.add(self._right) |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
715 self.setCellWidth(self._right, "85%") |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
716 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
717 def changePanel(self, idx, panel): |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
718 self._right.setWidget(0,idx,panel) |
34 | 719 self._right.getCellFormatter().setWidth(0, idx, '5%' if isinstance(panel, EmptyPanel) else '90%') |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
720 |
34 | 721 class MainTabPanel(TabPanel): |
23 | 722 |
723 def __init__(self, host): | |
33 | 724 TabPanel.__init__(self) |
23 | 725 self.host=host |
33 | 726 TabPanel() |
23 | 727 self.tabBar.setVisible(False) |
33 | 728 self.addStyleName('mainTabPanel') |
729 Window.addWindowResizeListener(self) | |
730 | |
731 def onWindowResized(self, width, height): | |
732 print "onWindowResized" | |
733 tab_panel_elt = self.getElement() | |
734 _elts = doc().getElementsByClassName('gwt-TabBar') | |
735 if not _elts.length: | |
736 print ("ERROR: not TabBar found, it should exist !") | |
737 tab_bar_h = 0 | |
738 else: | |
739 tab_bar_h = _elts.item(0).offsetHeight | |
740 ideal_height = Window.getClientHeight() - tab_panel_elt.offsetTop - tab_bar_h - 5 | |
741 self.setWidth("%s%s" % (width-5, "px")); | |
742 self.setHeight("%s%s" % (ideal_height, "px")); | |
23 | 743 |
744 def add(self, widget, tabText=None, asHTML=False): | |
745 TabPanel.add(self, widget, tabText, asHTML) | |
746 if self.getWidgetCount()>1: | |
747 self.tabBar.setVisible(True) | |
33 | 748 self.host.resize() |
23 | 749 |
33 | 750 class MainPanel(AbsolutePanel): |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
751 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
752 def __init__(self, host): |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
753 self.host=host |
33 | 754 AbsolutePanel.__init__(self) |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
755 |
23 | 756 menu = Menu(host) |
33 | 757 unibox_panel = UniBoxPanel(host) |
758 self.host.setUniBox(unibox_panel.unibox) | |
27
d89982865c57
browser side: ContactsChooser is now used to ask for 3 others players when tarot game is launched + names refactoring
Goffi <goffi@goffi.org>
parents:
23
diff
changeset
|
759 status = host.status_panel |
34 | 760 self.tab_panel = MainTabPanel(host) |
761 self.discuss_panel = MainDiscussionPanel(self.host) | |
23 | 762 self.tab_panel.add(self.discuss_panel, "Discussions") |
763 self.tab_panel.selectTab(0) | |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
764 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
765 self.add(menu) |
33 | 766 self.add(unibox_panel) |
19 | 767 self.add(status) |
23 | 768 self.add(self.tab_panel) |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
769 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
770 self.setWidth("100%") |
33 | 771 Window.addWindowResizeListener(self) |
772 | |
773 def onWindowResized(self, width, height): | |
774 _elts = doc().getElementsByClassName('gwt-TabBar') | |
775 if not _elts.length: | |
776 tab_bar_h = 0 | |
777 else: | |
778 tab_bar_h = _elts.item(0).offsetHeight | |
779 ideal_height = Window.getClientHeight() - tab_bar_h | |
780 self.setHeight("%s%s" % (ideal_height, "px")); | |
781 |