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