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