Mercurial > libervia-web
annotate browser_side/panels.py @ 62:12e889a683ce SàT v0.2.0
server side: misc stuff:
- fixed lot of misuse in callbacks
- chat history fixed
- a visual indicator now appear when we have message waiting from a contact
- fixed About dialog size issue in webkit
- fixed Drag'n'Drop for webkit
- defaut room to join is now libervia@conference.libervia.org
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 31 May 2011 17:06:59 +0200 |
parents | 4fa3d57f72f8 |
children | 9d8e79ac4c9c |
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') |
56
5fa710058e2d
browser side: fixed refactoring issue
Goffi <goffi@goffi.org>
parents:
55
diff
changeset
|
103 _dialog = dialog.GenericDialog("Contrat Social", _frame) |
48
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 :) |
58
4fa3d57f72f8
browser side: microblog entries caching
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
115 <p style='font-size:small;text-align:center'>This project is dedicated to Roger Poisson</p> |
49 | 116 """) |
56
5fa710058e2d
browser side: fixed refactoring issue
Goffi <goffi@goffi.org>
parents:
55
diff
changeset
|
117 _dialog = dialog.GenericDialog("About", _about) |
49 | 118 _dialog.show() |
51 | 119 |
120 #Contact menu | |
121 def onAddContact(self): | |
122 """Q&D contact addition""" | |
52
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
51
diff
changeset
|
123 _dialog = None |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
51
diff
changeset
|
124 edit = TextBox() |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
51
diff
changeset
|
125 |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
51
diff
changeset
|
126 def addContactCb(sender): |
54
f25c4077f6b9
addind contact + subscription management + misc
Goffi <goffi@goffi.org>
parents:
52
diff
changeset
|
127 if not re.match(r'^.+@.+\..+',edit.getText(), re.IGNORECASE): |
f25c4077f6b9
addind contact + subscription management + misc
Goffi <goffi@goffi.org>
parents:
52
diff
changeset
|
128 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
|
129 _dialog.show() |
54
f25c4077f6b9
addind contact + subscription management + misc
Goffi <goffi@goffi.org>
parents:
52
diff
changeset
|
130 else: |
f25c4077f6b9
addind contact + subscription management + misc
Goffi <goffi@goffi.org>
parents:
52
diff
changeset
|
131 self.host.bridge.call('addContact', None, edit.getText(), '', _dialog.getSelectedGroups() ) |
51 | 132 |
52
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
51
diff
changeset
|
133 label = Label("new contact identifier (JID):") |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
51
diff
changeset
|
134 edit.setText('@libervia.org') |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
51
diff
changeset
|
135 edit.setWidth('100%') |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
51
diff
changeset
|
136 _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
|
137 _dialog.setHTML('<b>Adding contact</b>') |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
51
diff
changeset
|
138 _dialog.show() |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
51
diff
changeset
|
139 |
55
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
140 def onUpdateContact(self): |
57
e552a67b933d
Contact update + add dedication in About dialog
Goffi <goffi@goffi.org>
parents:
56
diff
changeset
|
141 _dialog = None |
e552a67b933d
Contact update + add dedication in About dialog
Goffi <goffi@goffi.org>
parents:
56
diff
changeset
|
142 _contacts_list = ListBox() |
e552a67b933d
Contact update + add dedication in About dialog
Goffi <goffi@goffi.org>
parents:
56
diff
changeset
|
143 |
e552a67b933d
Contact update + add dedication in About dialog
Goffi <goffi@goffi.org>
parents:
56
diff
changeset
|
144 def updateContactCb(sender): |
e552a67b933d
Contact update + add dedication in About dialog
Goffi <goffi@goffi.org>
parents:
56
diff
changeset
|
145 _jid = _contacts_list.getValue(_contacts_list.getSelectedIndex()) |
e552a67b933d
Contact update + add dedication in About dialog
Goffi <goffi@goffi.org>
parents:
56
diff
changeset
|
146 self.host.bridge.call('updateContact', None, _jid, '', _dialog.getSelectedGroups()) |
e552a67b933d
Contact update + add dedication in About dialog
Goffi <goffi@goffi.org>
parents:
56
diff
changeset
|
147 |
e552a67b933d
Contact update + add dedication in About dialog
Goffi <goffi@goffi.org>
parents:
56
diff
changeset
|
148 def onContactChange(_list): |
e552a67b933d
Contact update + add dedication in About dialog
Goffi <goffi@goffi.org>
parents:
56
diff
changeset
|
149 _jid = _contacts_list.getValue(_contacts_list.getSelectedIndex()) |
e552a67b933d
Contact update + add dedication in About dialog
Goffi <goffi@goffi.org>
parents:
56
diff
changeset
|
150 groups = self.host.contact_panel.getContactGroups(_jid) |
e552a67b933d
Contact update + add dedication in About dialog
Goffi <goffi@goffi.org>
parents:
56
diff
changeset
|
151 _dialog.setGroupsSelected(groups) |
e552a67b933d
Contact update + add dedication in About dialog
Goffi <goffi@goffi.org>
parents:
56
diff
changeset
|
152 |
e552a67b933d
Contact update + add dedication in About dialog
Goffi <goffi@goffi.org>
parents:
56
diff
changeset
|
153 for contact in self.host.contact_panel.getContacts(): |
e552a67b933d
Contact update + add dedication in About dialog
Goffi <goffi@goffi.org>
parents:
56
diff
changeset
|
154 _contacts_list.addItem(contact) |
e552a67b933d
Contact update + add dedication in About dialog
Goffi <goffi@goffi.org>
parents:
56
diff
changeset
|
155 _contacts_list.addChangeListener(onContactChange) |
e552a67b933d
Contact update + add dedication in About dialog
Goffi <goffi@goffi.org>
parents:
56
diff
changeset
|
156 _jid = _contacts_list.getValue(_contacts_list.getSelectedIndex()) |
e552a67b933d
Contact update + add dedication in About dialog
Goffi <goffi@goffi.org>
parents:
56
diff
changeset
|
157 _selected_groups = self.host.contact_panel.getContactGroups(_jid) |
e552a67b933d
Contact update + add dedication in About dialog
Goffi <goffi@goffi.org>
parents:
56
diff
changeset
|
158 _dialog = dialog.GroupSelector([Label('Which contact do you want to update ?'), _contacts_list], |
e552a67b933d
Contact update + add dedication in About dialog
Goffi <goffi@goffi.org>
parents:
56
diff
changeset
|
159 self.host.contact_panel.getGroups(), _selected_groups, updateContactCb) |
e552a67b933d
Contact update + add dedication in About dialog
Goffi <goffi@goffi.org>
parents:
56
diff
changeset
|
160 _dialog.setHTML('<b>Updating contact</b>') |
e552a67b933d
Contact update + add dedication in About dialog
Goffi <goffi@goffi.org>
parents:
56
diff
changeset
|
161 _dialog.show() |
55
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
162 |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
163 def onRemoveContact(self): |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
164 _dialog = None |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
165 _contacts_list = ListBox() |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
166 |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
167 def secondConfirmCb(confirm): |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
168 if confirm: |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
169 for contact in _contacts_list.getSelectedValues(): |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
170 self.host.bridge.call('delContact', None, contact) |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
171 else: |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
172 _dialog.show() |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
173 |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
174 def dialogCb(confirm): |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
175 if confirm: |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
176 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
|
177 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
|
178 dialog.ConfirmDialog(secondConfirmCb, html_body).show() |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
179 |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
180 for contact in self.host.contact_panel.getContacts(): |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
181 _contacts_list.addItem(contact) |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
182 _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
|
183 _dialog.show() |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
184 |
50 | 185 #Group menu |
186 def onJoinRoom(self): | |
187 _dialog = None | |
188 _edit = None | |
189 | |
190 def onOK(sender): | |
191 if not _edit.getText(): | |
192 Window.alert('You must enter a room jid in the form libervia@conference.libervia.org') | |
193 if self.host.whoami: | |
194 nick = self.host.whoami.node | |
195 self.host.bridge.call('joinMUC', None, _edit.getText(), nick) | |
196 _dialog.hide() | |
197 | |
198 def onCancel(sender): | |
199 _dialog.hide() | |
200 | |
201 _main_panel = VerticalPanel() | |
202 _label = Label("Discussion room:") | |
203 _edit = TextBox() | |
62 | 204 _edit.setText('libervia@conference.libervia.org') |
50 | 205 hpanel = HorizontalPanel() |
206 hpanel.add(_label) | |
207 hpanel.add(_edit) | |
208 _main_panel.add(hpanel) | |
209 button_panel = HorizontalPanel() | |
210 button_panel.add(Button("Join", onOK)) | |
211 button_panel.add(Button("Cancel", onCancel)) | |
212 _main_panel.add(button_panel) | |
213 _dialog = DialogBox(centered=True) | |
214 _dialog.setHTML('<b>Group discussions</b>') | |
215 _dialog.setWidget(_main_panel) | |
216 _dialog.show() | |
217 | |
218 | |
48
153de5d461a4
added Social Contract \o. (in French only so far)
Goffi <goffi@goffi.org>
parents:
43
diff
changeset
|
219 #Game menu |
18
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 onTarotGame(self): |
23 | 222 #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
|
223 #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
|
224 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
|
225 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
|
226 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
|
227 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
228 def onXiangqiGame(self): |
49 | 229 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
|
230 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
231 class DropCell(DropWidget): |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
232 """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
|
233 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
234 def __init__(self): |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
235 DropWidget.__init__(self) |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
236 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
237 def onDragEnter(self, event): |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
238 self.addStyleName('dragover') |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
239 DOM.eventPreventDefault(event) |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
240 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
241 def onDragLeave(self, event): |
33 | 242 if event.clientX <= self.getAbsoluteLeft() or event.clientY <= self.getAbsoluteTop() or\ |
243 event.clientX >= self.getAbsoluteLeft() + self.getOffsetWidth()-1 or event.clientY >= self.getAbsoluteTop() + self.getOffsetHeight()-1: | |
244 #We check that we are inside widget's box, and we don't remove the style in this case because | |
245 #if the mouse is over a widget inside the DropWidget, if will leave the DropWidget, and we | |
246 #don't want that | |
247 self.removeStyleName('dragover') | |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
248 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
249 def onDragOver(self, event): |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
250 DOM.eventPreventDefault(event) |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
251 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
252 def _getCellAndRow(self, grid, event): |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
253 """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
|
254 cell = grid.getEventTargetCell(event) |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
255 row = DOM.getParent(cell) |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
256 return (row.rowIndex, cell.cellIndex) |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
257 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
258 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
259 def onDrop(self, event): |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
260 dt = event.dataTransfer |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
261 #'text', 'text/plain', and 'Text' are equivalent. |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
262 try: |
62 | 263 item, item_type = dt.getData("text/plain").split('\n') #Workaround for webkit, only text/plain seems to be managed |
264 if item_type and item_type[-1] == '\0': #Workaround for what looks like a pyjamas bug: the \0 should not be there, and | |
265 item_type = item_type[:-1] # .strip('\0') and .replace('\0','') don't work. TODO: check this and fill a bug report | |
266 #item_type = dt.getData("type") | |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
267 print "message: %s" % item |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
268 print "type: %s" % item_type |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
269 except: |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
270 print "no message found" |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
271 item=' ' |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
272 item_type = None |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
273 DOM.eventPreventDefault(event) |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
274 if item_type=="GROUP": |
19 | 275 _new_panel = MicroblogPanel(self.host, item) |
276 _new_panel.setAcceptedGroup(item) | |
58
4fa3d57f72f8
browser side: microblog entries caching
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
277 self.host.FillMicroblogPanel(_new_panel) |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
278 elif item_type=="CONTACT": |
19 | 279 _contact = JID(item) |
62 | 280 self.host.contact_panel.setContactMessageWaiting(_contact.bare, False) |
19 | 281 _new_panel = ChatPanel(self.host, _contact) |
282 _new_panel.historyPrint() | |
283 elif item_type=="CONTACT_TITLE": | |
284 _new_panel = MicroblogPanel(self.host, accept_all=True) | |
58
4fa3d57f72f8
browser side: microblog entries caching
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
285 self.host.FillMicroblogPanel(_new_panel) |
39
305e81c7a32c
Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
286 else: |
305e81c7a32c
Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
287 return |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
288 self.host.mpanels.remove(self) |
19 | 289 self.host.mpanels.append(_new_panel) |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
290 grid = self.getParent() |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
291 row_idx, cell_idx = self._getCellAndRow(grid, event) |
19 | 292 if self.host.selected == self: |
293 self.host.select(None) | |
34 | 294 self.removeFromParent() |
19 | 295 grid.setWidget(row_idx, cell_idx, _new_panel) |
34 | 296 _panels = list(grid) #this suppose that we only use 1 row, need to be changed in the futur |
297 _unempty_panels = filter(lambda wid:not isinstance(wid,EmptyPanel),list(grid)) | |
298 _width = 90/float(len(_unempty_panels) or 1) | |
299 #now we resize all the cell of the column | |
300 for panel in _unempty_panels: | |
301 td_elt = panel.getElement().parentNode | |
302 DOM.setStyleAttribute(td_elt, "width", "%s%%" % _width) | |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
303 #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
|
304 |
34 | 305 class ScrollPanelWrapper(SimplePanel): |
306 """Scroll Panel like component, wich use the full available space | |
307 to work around percent size issue, it use some of the ideas found | |
308 here: http://code.google.com/p/google-web-toolkit/issues/detail?id=316 | |
309 specially in code given at comment #46, thanks to Stefan Bachert""" | |
310 | |
311 def __init__(self, *args, **kwargs): | |
312 SimplePanel.__init__(self) | |
313 self.spanel = ScrollPanel(*args, **kwargs) | |
314 SimplePanel.setWidget(self, self.spanel) | |
315 DOM.setStyleAttribute(self.getElement(), "position", "relative") | |
316 DOM.setStyleAttribute(self.getElement(), "top", "0px") | |
317 DOM.setStyleAttribute(self.getElement(), "left", "0px") | |
318 DOM.setStyleAttribute(self.getElement(), "width", "100%") | |
319 DOM.setStyleAttribute(self.getElement(), "height", "100%") | |
320 DOM.setStyleAttribute(self.spanel.getElement(), "position", "absolute") | |
321 DOM.setStyleAttribute(self.spanel.getElement(), "width", "100%") | |
322 DOM.setStyleAttribute(self.spanel.getElement(), "height", "100%") | |
323 | |
324 def setWidget(self, widget): | |
325 self.spanel.setWidget(widget) | |
326 | |
327 def setScrollPosition(self, position): | |
328 self.spanel.setScrollPosition(position) | |
329 | |
330 def scrollToBottom(self): | |
331 self.setScrollPosition(self.spanel.getElement().scrollHeight) | |
332 | |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
333 class EmptyPanel(DropCell, SimplePanel): |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
334 """Empty dropable panel""" |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
335 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
336 def __init__(self, host): |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
337 SimplePanel.__init__(self) |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
338 self.host = host |
34 | 339 _panel = HTMLPanel("") |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
340 self.add(_panel) |
34 | 341 self.setHeight('100%') |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
342 DropCell.__init__(self) |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
343 |
33 | 344 class UniBoxPanel(SimplePanel): |
345 """Panel containing the UniBox""" | |
346 | |
347 def __init__(self, host): | |
348 SimplePanel.__init__(self) | |
349 self.setStyleName('uniBoxPanel') | |
350 self.unibox = UniBox(host) | |
351 self.unibox.setWidth('100%') | |
352 self.add(self.unibox) | |
353 | |
354 class UniBox(AutoCompleteTextBox): | |
355 """This text box is used as a main typing point, for message, microblog, etc""" | |
356 | |
357 def __init__(self, host): | |
358 AutoCompleteTextBox.__init__(self) | |
359 self._popup = None | |
360 self._timer = Timer(notify=self._timeCb) | |
361 self.host = host | |
362 | |
363 def addKey(self, key): | |
364 self.getCompletionItems().completions.append(key) | |
365 | |
55
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
366 def removeKey(self, key): |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
367 try: |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
368 self.getCompletionItems().completions.remove(key) |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
369 except KeyError: |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
370 print "WARNING: trying to remove an unknown key" |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
371 |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
372 |
33 | 373 def showWarning(self, target_data): |
374 type, target = target_data | |
375 if type == "PUBLIC": | |
376 msg = "This message will be PUBLIC and everybody will be able to see it, even people you don't know" | |
377 style = "targetPublic" | |
378 elif type == "GROUP": | |
379 msg = "This message will be published for all the people of the group <span class='warningTarget'>%s</span>" % (target or '') | |
380 style = "targetGroup" | |
381 elif type == "STATUS": | |
382 msg = "This will be your new status message" | |
383 style = "targetStatus" | |
384 elif type == "ONE2ONE": | |
385 msg = "This message will be sent to your contact <span class='warningTarget'>%s</span>" % target | |
386 style = "targetOne2One" | |
387 else: | |
388 print "WARNING: undetermined target for this message" | |
389 return | |
390 contents = HTML(msg) | |
391 | |
48
153de5d461a4
added Social Contract \o. (in French only so far)
Goffi <goffi@goffi.org>
parents:
43
diff
changeset
|
392 self._popup = dialog.PopupPanelWrapper(autoHide=False, modal=False) |
33 | 393 self._popup.target_data = target_data |
394 self._popup.add(contents) | |
395 self._popup.setStyleName("warningPopup") | |
396 if style: | |
397 self._popup.addStyleName(style) | |
398 | |
399 left = 0 | |
400 top = 0 #max(0, self.getAbsoluteTop() - contents.getOffsetHeight() - 2) | |
401 self._popup.setPopupPosition(left, top) | |
402 self._popup.setPopupPosition(left, top) | |
403 self._popup.show() | |
404 | |
405 def _timeCb(self, timer): | |
406 if self._popup: | |
407 self._popup.hide() | |
408 del self._popup | |
409 self._popup = None | |
410 | |
411 def _getTarget(self, txt): | |
412 """Say who will receive the messsage | |
413 Return a tuple (target_type, target info)""" | |
414 type = None | |
415 target = None | |
416 if txt.startswith('@@: '): | |
417 type = "PUBLIC" | |
418 elif txt.startswith('@'): | |
419 type = "GROUP" | |
420 _end = txt.find(': ') | |
421 if _end == -1: | |
422 type = "STATUS" | |
423 else: | |
424 target = txt[1:_end] #only one target group is managed for the moment | |
425 if not target in self.host.contact_panel.getGroups(): | |
426 target = None | |
427 elif self.host.selected == None: | |
428 type = "STATUS" | |
429 elif isinstance(self.host.selected, ChatPanel): | |
430 type = "ONE2ONE" | |
431 target = str(self.host.selected.target) | |
432 else: | |
62 | 433 print "Unknown selected host:",self.host.selected |
33 | 434 type = "UNKNOWN" |
435 return (type, target) | |
436 | |
437 def onKeyPress(self, sender, keycode, modifiers): | |
438 _txt = self.getText() | |
439 if not self._popup: | |
440 self.showWarning(self._getTarget(_txt)) | |
441 else: | |
442 _target = self._getTarget(_txt) | |
443 if _target != self._popup.target_data: | |
444 self._timeCb(None) #we remove the popup | |
445 self.showWarning(_target) | |
446 | |
447 self._timer.schedule(2000) | |
448 | |
449 if keycode == KEY_ENTER and not self.visible: | |
450 if _txt: | |
451 if _txt.startswith('@'): | |
452 self.host.bridge.call('sendMblog', None, self.getText()) | |
453 elif self.host.selected == None: | |
454 self.host.bridge.call('setStatus', None, _txt) | |
455 elif isinstance(self.host.selected, ChatPanel): | |
456 _chat = self.host.selected | |
457 mess_type = "groupchat" if _chat.type=='group' else "chat" | |
458 self.host.bridge.call('sendMessage', None, str(_chat.target), _txt, '', mess_type) | |
459 self.setText('') | |
460 self._timeCb(None) #we remove the popup | |
461 | |
462 def complete(self): | |
463 #self.visible=False #XXX: self.visible is not unset in pyjamas when ENTER is pressed and a completion is done | |
464 #XXX: fixed directly on pyjamas, if the patch is accepted, no need to walk around this | |
465 return AutoCompleteTextBox.complete(self) | |
466 | |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
467 class MicroblogEntry(SimplePanel): |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
468 |
58
4fa3d57f72f8
browser side: microblog entries caching
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
469 def __init__(self, mblog_entry): |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
470 SimplePanel.__init__(self) |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
471 |
58
4fa3d57f72f8
browser side: microblog entries caching
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
472 _datetime = datetime.fromtimestamp(mblog_entry.timestamp) |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
473 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
474 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>" % |
58
4fa3d57f72f8
browser side: microblog entries caching
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
475 {"author": html_sanitize(mblog_entry.author), |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
476 "timestamp": _datetime, |
58
4fa3d57f72f8
browser side: microblog entries caching
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
477 "body": html_sanitize(mblog_entry.content)} |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
478 ) |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
479 panel.setStyleName('microblogEntry') |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
480 self.add(panel) |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
481 |
34 | 482 class MicroblogPanel(DropCell, ScrollPanelWrapper): |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
483 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
484 def __init__(self,host, title=' ', accept_all=False): |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
485 """Panel used to show microblog |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
486 @param title: title of the panel |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
487 @param accept_all: if true, show every message, without filtering jids""" |
34 | 488 ScrollPanelWrapper.__init__(self) |
489 DropCell.__init__(self) | |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
490 self.host = host |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
491 self.accept_all = accept_all |
51 | 492 title=html_sanitize(title) |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
493 self.accepted_groups = [] |
58
4fa3d57f72f8
browser side: microblog entries caching
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
494 self.entries = {} |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
495 _class = ['mb_panel_header'] |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
496 if title == ' ': |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
497 _class.append('empty_header') |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
498 self.vpanel = VerticalPanel() |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
499 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
|
500 self.vpanel.setWidth('100%') |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
501 self.setStyleName('microblogPanel') |
34 | 502 self.setWidget(self.vpanel) |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
503 |
58
4fa3d57f72f8
browser side: microblog entries caching
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
504 def addEntry(self, mblog_entry): |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
505 """Add an entry to the panel |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
506 @param text: main text of the entry |
58
4fa3d57f72f8
browser side: microblog entries caching
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
507 @param id: unique id of the entry |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
508 @param author: who wrote the entry |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
509 @param date: when the entry was written""" |
58
4fa3d57f72f8
browser side: microblog entries caching
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
510 if mblog_entry.id in self.entries: |
4fa3d57f72f8
browser side: microblog entries caching
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
511 return |
4fa3d57f72f8
browser side: microblog entries caching
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
512 _entry = MicroblogEntry(mblog_entry) |
4fa3d57f72f8
browser side: microblog entries caching
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
513 self.entries[mblog_entry.id] = _entry |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
514 self.vpanel.insert(_entry,1) |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
515 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
516 def setAcceptedGroup(self, group): |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
517 """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
|
518 @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
|
519 """ |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
520 if isinstance(group, list): |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
521 self.accepted_groups.extend(group) |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
522 else: |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
523 self.accepted_groups.append(group) |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
524 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
525 def isJidAccepted(self, jid): |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
526 """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
|
527 @param jid: jid |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
528 @return: True if the jid is accepted""" |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
529 if self.accept_all: |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
530 return True |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
531 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
|
532 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
|
533 return True |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
534 return False |
19 | 535 |
20 | 536 class StatusPanel(HTMLPanel, ClickHandler): |
537 def __init__(self, host, status=''): | |
538 self.host = host | |
539 self.status = status or ' ' | |
19 | 540 HTMLPanel.__init__(self, self.__getContent()) |
20 | 541 self.setStyleName('statusPanel') |
542 ClickHandler.__init__(self) | |
543 self.addClickListener(self) | |
19 | 544 |
545 def __getContent(self): | |
51 | 546 return "<span class='status'>%(status)s</span>" % {'status':html_sanitize(self.status)} |
19 | 547 |
548 def changeStatus(self, new_status): | |
20 | 549 self.status = new_status or ' ' |
19 | 550 self.setHTML(self.__getContent()) |
551 | |
62 | 552 def onClick(self, sender): |
20 | 553 #As status is the default target of uniBar, we don't want to select anything if click on it |
554 self.host.select(None) | |
555 | |
19 | 556 class ChatText(HTMLPanel): |
557 | |
558 def __init__(self, timestamp, nick, mymess, msg): | |
559 _date = datetime.fromtimestamp(float(timestamp or time())) | |
560 _msg_class = ["chat_text_msg"] | |
561 if mymess: | |
562 _msg_class.append("chat_text_mymess") | |
563 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>" % | |
564 {"timestamp": _date.strftime("%H:%M"), | |
51 | 565 "nick": "[%s]" % html_sanitize(nick), |
19 | 566 "msg_class": ' '.join(_msg_class), |
51 | 567 "msg": html_sanitize(msg)} |
19 | 568 ) |
569 self.setStyleName('chatText') | |
33 | 570 |
571 class Occupant(HTML): | |
572 """Occupant of a MUC room""" | |
573 | |
574 def __init__(self, nick): | |
575 self.nick = nick | |
35 | 576 HTML.__init__(self, "<div class='occupant'>%s</div>" % html_sanitize(nick)) |
577 | |
578 def __str__(self): | |
579 return nick | |
33 | 580 |
581 class OccupantsList(AbsolutePanel): | |
582 """Panel user to show occupants of a room""" | |
583 | |
584 def __init__(self): | |
585 AbsolutePanel.__init__(self) | |
35 | 586 self.occupants_list = {} |
33 | 587 self.setStyleName('occupantsList') |
588 | |
589 def addOccupant(self, nick): | |
35 | 590 _occupant = Occupant(nick) |
591 self.occupants_list[nick] = _occupant | |
592 self.add(_occupant) | |
33 | 593 |
35 | 594 def removeOccupant(self, nick): |
595 try: | |
596 self.remove(self.occupants_list[nick]) | |
597 except KeyError: | |
598 print "ERROR: trying to remove an unexisting nick" | |
599 | |
600 def clear(self): | |
601 self.occupants_list.clear() | |
602 AbsolutePanel.clear(self) | |
603 | |
604 class ChatPanel(DropCell, ClickHandler, ScrollPanelWrapper): | |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
605 |
19 | 606 def __init__(self, host, target, type='one2one'): |
607 """Panel used for conversation (one 2 one or group chat) | |
608 @param host: SatWebFrontend instance | |
609 @param target: entity (JID) with who we have a conversation (contact's jid for one 2 one chat, or MUC room) | |
610 @param type: one2one for simple conversation, group for MUC""" | |
35 | 611 ScrollPanelWrapper.__init__(self) |
34 | 612 DropCell.__init__(self) |
613 ClickHandler.__init__(self) | |
614 self.vpanel = VerticalPanel() | |
615 self.vpanel.setSize('100%','100%') | |
19 | 616 self.host = host |
33 | 617 self.type = type |
618 self.nick = None | |
19 | 619 if not target: |
620 print "ERROR: Empty target !" | |
621 return | |
622 self.target = target | |
623 title="%s" % target.bare | |
624 _class = ['mb_panel_header'] | |
51 | 625 self.header = HTMLPanel("<div class='%s'>%s</div>" % (','.join(_class),html_sanitize(title))) |
34 | 626 self.header.setStyleName('chatHeader') |
33 | 627 self.body = AbsolutePanel() |
628 self.body.setStyleName('chatPanel_body') | |
629 chat_area = HorizontalPanel() | |
630 chat_area.setStyleName('chatArea') | |
631 if type == 'group': | |
632 self.occupants_list = OccupantsList() | |
633 chat_area.add(self.occupants_list) | |
634 self.body.add(chat_area) | |
635 self.content = AbsolutePanel() | |
636 self.content.setStyleName('chatContent') | |
34 | 637 self.content_scroll = ScrollPanelWrapper(self.content) |
638 chat_area.add(self.content_scroll) | |
639 chat_area.setCellWidth(self.content_scroll, '100%') | |
640 self.vpanel.add(self.header) | |
641 self.vpanel.setCellHeight(self.header, '1%') | |
642 self.vpanel.add(self.body) | |
643 self.setWidget(self.vpanel) | |
19 | 644 self.setStyleName('chatPanel') |
645 self.addClickListener(self) | |
646 | |
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
|
647 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
|
648 #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
|
649 #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
|
650 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
|
651 |
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
|
652 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
|
653 #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
|
654 #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
|
655 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
|
656 |
62 | 657 def onClick(self, sender): |
19 | 658 self.host.select(self) |
659 | |
660 def setUserNick(self, nick): | |
661 """Set the nick of the user, usefull for e.g. change the color of the user""" | |
662 self.nick = nick | |
33 | 663 |
664 def setPresents(self, nicks): | |
665 """Set the users presents in this room | |
666 @param occupants: list of nicks (string)""" | |
35 | 667 self.occupants_list.clear() |
33 | 668 for nick in nicks: |
669 self.occupants_list.addOccupant(nick) | |
670 | |
35 | 671 def userJoined(self, nick, data): |
672 self.occupants_list.addOccupant(nick) | |
673 self.printInfo("=> %s has joined the room" % nick) | |
674 | |
675 def userLeft(self, nick, data): | |
676 self.occupants_list.removeOccupant(nick) | |
677 self.printInfo("<= %s has left the room" % nick) | |
678 | |
19 | 679 def historyPrint(self, size=20): |
680 """Print the initial history""" | |
681 def getHistoryCB(history): | |
682 stamps=history.keys() | |
683 stamps.sort() | |
33 | 684 for stamp in stamps: |
19 | 685 self.printMessage(history[stamp][0], history[stamp][1], stamp) |
62 | 686 self.host.bridge.call('getHistory', getHistoryCB, self.host.whoami.bare, self.target.bare, 20) |
35 | 687 |
688 def printInfo(self, msg, type='normal'): | |
689 """Print general info | |
690 @param msg: message to print | |
691 @type: one of: | |
692 normal: general info like "toto has joined the room" | |
693 me: "/me" information like "/me clenches his fist" ==> "toto clenches his fist" | |
694 """ | |
54
f25c4077f6b9
addind contact + subscription management + misc
Goffi <goffi@goffi.org>
parents:
52
diff
changeset
|
695 _wid = Label(msg) |
35 | 696 if type == 'normal': |
697 _wid.setStyleName('chatTextInfo') | |
698 elif type == 'me': | |
699 _wid.setStyleName('chatTextMe') | |
700 else: | |
701 _wid.setStyleName('chatTextInfo') | |
702 self.content.add(_wid) | |
703 | |
704 | |
19 | 705 def printMessage(self, from_jid, msg, timestamp=None): |
706 """Print message in chat window. Must be implemented by child class""" | |
707 _jid=JID(from_jid) | |
33 | 708 nick = _jid.node if self.type=='one2one' else _jid.resource |
709 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 | 710 if msg.startswith('/me '): |
19 | 711 self.printInfo('* %s %s' % (nick, msg[4:]),type='me') |
35 | 712 return |
19 | 713 self.content.add(ChatText(timestamp, nick, mymess, msg)) |
34 | 714 self.content_scroll.scrollToBottom() |
36 | 715 |
716 def startGame(self, game_type, referee, players): | |
717 """Configure the chat window to start a game""" | |
718 if game_type=="Tarot": | |
719 self.tarot_panel = CardPanel(self, referee, players, self.nick) | |
720 self.vpanel.insert(self.tarot_panel, 1) | |
721 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
|
722 |
b306aa090438
Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
723 def getGame(self, game_type): |
b306aa090438
Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
724 """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
|
725 #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
|
726 if game_type=="Tarot": |
b306aa090438
Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
727 return self.tarot_panel |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
728 |
34 | 729 class MainDiscussionPanel(HorizontalPanel): |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
730 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
731 def __init__(self, host): |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
732 self.host=host |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
733 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
|
734 self._left = self.host.contact_panel |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
735 self._right = Grid(1,3) |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
736 self._right.setWidth('100%') |
34 | 737 self._right.setHeight('100%') |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
738 self.add(self._left) |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
739 self.setCellWidth(self._left, "15%") |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
740 self.add(self._right) |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
741 self.setCellWidth(self._right, "85%") |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
742 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
743 def changePanel(self, idx, panel): |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
744 self._right.setWidget(0,idx,panel) |
34 | 745 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
|
746 |
34 | 747 class MainTabPanel(TabPanel): |
23 | 748 |
749 def __init__(self, host): | |
33 | 750 TabPanel.__init__(self) |
23 | 751 self.host=host |
33 | 752 TabPanel() |
23 | 753 self.tabBar.setVisible(False) |
33 | 754 self.addStyleName('mainTabPanel') |
755 Window.addWindowResizeListener(self) | |
756 | |
757 def onWindowResized(self, width, height): | |
758 tab_panel_elt = self.getElement() | |
759 _elts = doc().getElementsByClassName('gwt-TabBar') | |
760 if not _elts.length: | |
761 print ("ERROR: not TabBar found, it should exist !") | |
762 tab_bar_h = 0 | |
763 else: | |
764 tab_bar_h = _elts.item(0).offsetHeight | |
765 ideal_height = Window.getClientHeight() - tab_panel_elt.offsetTop - tab_bar_h - 5 | |
766 self.setWidth("%s%s" % (width-5, "px")); | |
767 self.setHeight("%s%s" % (ideal_height, "px")); | |
23 | 768 |
769 def add(self, widget, tabText=None, asHTML=False): | |
770 TabPanel.add(self, widget, tabText, asHTML) | |
771 if self.getWidgetCount()>1: | |
772 self.tabBar.setVisible(True) | |
33 | 773 self.host.resize() |
23 | 774 |
33 | 775 class MainPanel(AbsolutePanel): |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
776 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
777 def __init__(self, host): |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
778 self.host=host |
33 | 779 AbsolutePanel.__init__(self) |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
780 |
23 | 781 menu = Menu(host) |
33 | 782 unibox_panel = UniBoxPanel(host) |
783 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
|
784 status = host.status_panel |
34 | 785 self.tab_panel = MainTabPanel(host) |
786 self.discuss_panel = MainDiscussionPanel(self.host) | |
23 | 787 self.tab_panel.add(self.discuss_panel, "Discussions") |
788 self.tab_panel.selectTab(0) | |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
789 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
790 self.add(menu) |
33 | 791 self.add(unibox_panel) |
19 | 792 self.add(status) |
23 | 793 self.add(self.tab_panel) |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
794 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
795 self.setWidth("100%") |
33 | 796 Window.addWindowResizeListener(self) |
797 | |
798 def onWindowResized(self, width, height): | |
799 _elts = doc().getElementsByClassName('gwt-TabBar') | |
800 if not _elts.length: | |
801 tab_bar_h = 0 | |
802 else: | |
803 tab_bar_h = _elts.item(0).offsetHeight | |
804 ideal_height = Window.getClientHeight() - tab_bar_h | |
805 self.setHeight("%s%s" % (ideal_height, "px")); | |
806 |