annotate browser_side/panels.py @ 287:7a1dc69112b8

browser_side (plugin radiocol): send the current queue to new players
author souliane <souliane@mailoo.org>
date Thu, 28 Nov 2013 21:43:12 +0100
parents 4f0c2fea358a
children 20a9aedc60b5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
165
9763dec220ed dates update
Goffi <goffi@goffi.org>
parents: 163
diff changeset
6 Copyright (C) 2011, 2012, 2013 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
226
744426c2b699 browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 223
diff changeset
22 import pyjd # this is dummy in pyjs
18
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
23 from pyjamas.ui.SimplePanel import SimplePanel
33
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
24 from pyjamas.ui.AbsolutePanel import AbsolutePanel
18
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
25 from pyjamas.ui.VerticalPanel import VerticalPanel
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
26 from pyjamas.ui.HorizontalPanel import HorizontalPanel
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
27 from pyjamas.ui.HTMLPanel import HTMLPanel
181
c0b78a3af06d browser side: web widget first draft
Goffi <goffi@goffi.org>
parents: 179
diff changeset
28 from pyjamas.ui.Frame import Frame
73
447dc8ac181b Adrien's uniBox design integration + lastPopup style
Goffi <goffi@goffi.org>
parents: 71
diff changeset
29 from pyjamas.ui.TextArea import TextArea
18
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
30 from pyjamas.ui.Label import Label
83
68d360caeecb New widget system: first draft
Goffi <goffi@goffi.org>
parents: 78
diff changeset
31 from pyjamas.ui.Button import Button
33
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
32 from pyjamas.ui.HTML import HTML
83
68d360caeecb New widget system: first draft
Goffi <goffi@goffi.org>
parents: 78
diff changeset
33 from pyjamas.ui.Image import Image
241
86055ccf69c3 browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents: 239
diff changeset
34 from pyjamas.ui.PopupPanel import PopupPanel
264
2a93f8e6f989 browser_side: added class ToggleStackPanel
souliane <souliane@mailoo.org>
parents: 261
diff changeset
35 from pyjamas.ui.StackPanel import StackPanel
19
e8e3704eb97f Added basic chat panel
Goffi <goffi@goffi.org>
parents: 18
diff changeset
36 from pyjamas.ui.ClickListener import ClickHandler
282
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
37 from pyjamas.ui.KeyboardListener import KEY_ENTER, KEY_UP, KEY_DOWN, KeyboardHandler
241
86055ccf69c3 browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents: 239
diff changeset
38 from pyjamas.ui.Event import BUTTON_LEFT, BUTTON_MIDDLE, BUTTON_RIGHT
186
72bb1d845b6a browser side: global resize on UniBox resize
Goffi <goffi@goffi.org>
parents: 185
diff changeset
39 from pyjamas.ui.MouseListener import MouseHandler
33
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
40 from pyjamas.Timer import Timer
18
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
41 from pyjamas import DOM
78
12680e220b35 browser side: refactoring: menu is now in its own module
Goffi <goffi@goffi.org>
parents: 75
diff changeset
42 from card_game import CardPanel
127
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents: 123
diff changeset
43 from radiocol import RadioColPanel
78
12680e220b35 browser side: refactoring: menu is now in its own module
Goffi <goffi@goffi.org>
parents: 75
diff changeset
44 from menu import Menu
19
e8e3704eb97f Added basic chat panel
Goffi <goffi@goffi.org>
parents: 18
diff changeset
45 from jid import JID
279
2d6bd975a72d browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents: 276
diff changeset
46 from tools import html_sanitize, addURLToText, inlineRoot, setPresenceStyle
18
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
47 from datetime import datetime
19
e8e3704eb97f Added basic chat panel
Goffi <goffi@goffi.org>
parents: 18
diff changeset
48 from time import time
48
153de5d461a4 added Social Contract \o. (in French only so far)
Goffi <goffi@goffi.org>
parents: 43
diff changeset
49 import dialog
195
dd27072d8ae0 browser side: widgets refactoring:
Goffi <goffi@goffi.org>
parents: 194
diff changeset
50 import base_widget
282
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
51 from dialog import ConfirmDialog
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
52 import richtext
223
624a87377412 browser_side, plugin XEP-0085: limit the number of bridge methods calls for "chatStateComposing".
souliane <souliane@mailoo.org>
parents: 218
diff changeset
53 from plugin_xep_0085 import ChatStateMachine
195
dd27072d8ae0 browser side: widgets refactoring:
Goffi <goffi@goffi.org>
parents: 194
diff changeset
54 from pyjamas import Window
78
12680e220b35 browser side: refactoring: menu is now in its own module
Goffi <goffi@goffi.org>
parents: 75
diff changeset
55 from __pyjamas__ import doc
276
aebb96bfa8d1 frontends tools: moved src/tools/frontends to frontends/src/tools
souliane <souliane@mailoo.org>
parents: 275
diff changeset
56 from sat_frontends.tools.games import SYMBOLS
279
2d6bd975a72d browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents: 276
diff changeset
57 from sat_frontends import constants
282
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
58 from pyjamas.ui.FocusListener import FocusHandler
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
59 import logging
279
2d6bd975a72d browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents: 276
diff changeset
60
2d6bd975a72d browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents: 276
diff changeset
61
2d6bd975a72d browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents: 276
diff changeset
62 const = constants.Const # to directly import 'const' doesn't work
18
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
63
210
3092f6b1710c browser side: make the OK button title for group selector configureable + few "cosmetic" changes (PEP 8...)
souliane <souliane@mailoo.org>
parents: 206
diff changeset
64
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents: 231
diff changeset
65 class UniBoxPanel(HorizontalPanel):
33
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
66 """Panel containing the UniBox"""
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
67
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
68 def __init__(self, host):
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents: 231
diff changeset
69 HorizontalPanel.__init__(self)
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents: 231
diff changeset
70 self.host = host
33
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
71 self.setStyleName('uniBoxPanel')
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents: 231
diff changeset
72
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents: 231
diff changeset
73 self.button = Button ('<img src="media/icons/tango/actions/32/format-text-italic.png" class="richTextIcon"/>')
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents: 231
diff changeset
74 self.button.setTitle('Open the rich text editor')
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents: 231
diff changeset
75 self.button.addStyleName('uniBoxButton')
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents: 231
diff changeset
76 self.add(self.button)
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents: 231
diff changeset
77
33
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
78 self.unibox = UniBox(host)
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
79 self.add(self.unibox)
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents: 231
diff changeset
80 self.setCellWidth(self.unibox, '100%')
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents: 231
diff changeset
81
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents: 231
diff changeset
82 self.button.addClickListener(self.openRichTextEditor)
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents: 231
diff changeset
83 self.unibox.addDoubleClickListener(self.openRichTextEditor)
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents: 231
diff changeset
84
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents: 231
diff changeset
85 def openRichTextEditor(self):
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents: 231
diff changeset
86 """Open the rich text editor."""
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents: 231
diff changeset
87 self.button.setVisible(False)
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents: 231
diff changeset
88 self.unibox.setVisible(False)
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents: 231
diff changeset
89 self.setCellWidth(self.unibox, '0px')
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents: 231
diff changeset
90 self.host.panel._contactsMove(self)
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents: 231
diff changeset
91
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents: 231
diff changeset
92 def onCloseCallback():
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents: 231
diff changeset
93 self.host.panel._contactsMove(self.host.panel._hpanel)
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents: 231
diff changeset
94 self.setCellWidth(self.unibox, '100%')
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents: 231
diff changeset
95 self.button.setVisible(True)
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents: 231
diff changeset
96 self.unibox.setVisible(True)
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents: 231
diff changeset
97 self.host.resize()
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents: 231
diff changeset
98
282
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
99 richtext.RichTextEditor.getOrCreate(self.host, self, onCloseCallback)
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents: 231
diff changeset
100 self.host.resize()
33
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
101
210
3092f6b1710c browser side: make the OK button title for group selector configureable + few "cosmetic" changes (PEP 8...)
souliane <souliane@mailoo.org>
parents: 206
diff changeset
102
186
72bb1d845b6a browser side: global resize on UniBox resize
Goffi <goffi@goffi.org>
parents: 185
diff changeset
103 class UniBox(TextArea, MouseHandler): #AutoCompleteTextBox):
33
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
104 """This text box is used as a main typing point, for message, microblog, etc"""
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
105
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
106 def __init__(self, host):
73
447dc8ac181b Adrien's uniBox design integration + lastPopup style
Goffi <goffi@goffi.org>
parents: 71
diff changeset
107 TextArea.__init__(self)
447dc8ac181b Adrien's uniBox design integration + lastPopup style
Goffi <goffi@goffi.org>
parents: 71
diff changeset
108 #AutoCompleteTextBox.__init__(self)
210
3092f6b1710c browser side: make the OK button title for group selector configureable + few "cosmetic" changes (PEP 8...)
souliane <souliane@mailoo.org>
parents: 206
diff changeset
109 self.__size = (0, 0)
33
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
110 self._popup = None
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
111 self._timer = Timer(notify=self._timeCb)
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
112 self.host = host
73
447dc8ac181b Adrien's uniBox design integration + lastPopup style
Goffi <goffi@goffi.org>
parents: 71
diff changeset
113 self.setStyleName('uniBox')
83
68d360caeecb New widget system: first draft
Goffi <goffi@goffi.org>
parents: 78
diff changeset
114 self.addKeyboardListener(self)
186
72bb1d845b6a browser side: global resize on UniBox resize
Goffi <goffi@goffi.org>
parents: 185
diff changeset
115 MouseHandler.__init__(self)
72bb1d845b6a browser side: global resize on UniBox resize
Goffi <goffi@goffi.org>
parents: 185
diff changeset
116 self.addMouseListener(self)
193
f2ae8e170c49 browser side: selected widget caching in UniBox, to avoid to ask the getter at each key pressed, which make the box very slow.
Goffi <goffi@goffi.org>
parents: 192
diff changeset
117 self._selected_cache = None
f2ae8e170c49 browser side: selected widget caching in UniBox, to avoid to ask the getter at each key pressed, which make the box very slow.
Goffi <goffi@goffi.org>
parents: 192
diff changeset
118 host.addSelectedListener(self.onSelectedChange)
33
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
119
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
120 def addKey(self, key):
73
447dc8ac181b Adrien's uniBox design integration + lastPopup style
Goffi <goffi@goffi.org>
parents: 71
diff changeset
121 return
447dc8ac181b Adrien's uniBox design integration + lastPopup style
Goffi <goffi@goffi.org>
parents: 71
diff changeset
122 #self.getCompletionItems().completions.append(key)
33
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
123
55
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
124 def removeKey(self, key):
255
da0487f0a2e7 browser_side: small changes to prepare the contact group manager:
souliane <souliane@mailoo.org>
parents: 249
diff changeset
125 return
da0487f0a2e7 browser_side: small changes to prepare the contact group manager:
souliane <souliane@mailoo.org>
parents: 249
diff changeset
126 # TODO: investigate why AutoCompleteTextBox doesn't work here,
da0487f0a2e7 browser_side: small changes to prepare the contact group manager:
souliane <souliane@mailoo.org>
parents: 249
diff changeset
127 # maybe it can work on a TextBox but no TextArea. Remove addKey
da0487f0a2e7 browser_side: small changes to prepare the contact group manager:
souliane <souliane@mailoo.org>
parents: 249
diff changeset
128 # and removeKey methods if they don't serve anymore.
55
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
129 try:
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
130 self.getCompletionItems().completions.remove(key)
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
131 except KeyError:
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
132 print "WARNING: trying to remove an unknown key"
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
133
33
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
134 def showWarning(self, target_data):
201
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
135 target_hook, _type, msg = target_data
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
136 if _type == "NONE":
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
137 return
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
138 if not msg:
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
139 print "WARNING: no msg set uniBox warning"
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
140 return
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
141 if _type == "PUBLIC":
33
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
142 style = "targetPublic"
201
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
143 elif _type == "GROUP":
33
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
144 style = "targetGroup"
201
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
145 elif _type == "STATUS":
33
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
146 msg = "This will be your new status message"
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
147 style = "targetStatus"
201
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
148 elif _type == "ONE2ONE":
33
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
149 style = "targetOne2One"
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
150 else:
201
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
151 print "ERROR: unknown message type"
33
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
152 return
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
153 contents = HTML(msg)
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
154
48
153de5d461a4 added Social Contract \o. (in French only so far)
Goffi <goffi@goffi.org>
parents: 43
diff changeset
155 self._popup = dialog.PopupPanelWrapper(autoHide=False, modal=False)
33
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
156 self._popup.target_data = target_data
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
157 self._popup.add(contents)
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
158 self._popup.setStyleName("warningPopup")
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
159 if style:
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
160 self._popup.addStyleName(style)
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
161
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
162 left = 0
226
744426c2b699 browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 223
diff changeset
163 top = 0 # max(0, self.getAbsoluteTop() - contents.getOffsetHeight() - 2)
33
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
164 self._popup.setPopupPosition(left, top)
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
165 self._popup.show()
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
166
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
167 def _timeCb(self, timer):
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
168 if self._popup:
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
169 self._popup.hide()
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
170 del self._popup
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
171 self._popup = None
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
172
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
173 def _getTarget(self, txt):
201
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
174 """ Say who will receive the messsage
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
175 @return: a tuple (selected, target_type, target info) with:
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
176 - target_hook: None if we use the selected widget, (msg, data) if we have a hook (e.g. "@@: " for a public blog), where msg is the parsed message (i.e. without the "hook key: "@@: bla" become ("bla", None))
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
177 - target_type: one of PUBLIC, GROUP, ONE2ONE, STATUS, MISC
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
178 - msg: HTML message which will appear in the privacy warning banner """
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
179 target = self._selected_cache
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
180
201
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
181 def getSelectedOrStatus():
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
182 if target:
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
183 _type, msg = target.getWarningData()
226
744426c2b699 browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 223
diff changeset
184 target_hook = None # we use the selected widget, not a hook
201
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
185 else:
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
186 _type, msg = "STATUS", "This will be your new status message"
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
187 target_hook = (txt, None)
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
188 return (target_hook, _type, msg)
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
189
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
190 if not txt.startswith('@'):
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
191 target_hook, _type, msg = getSelectedOrStatus()
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
192 elif txt.startswith('@@: '):
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
193 _type = "PUBLIC"
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
194 msg = MicroblogPanel.warning_msg_public
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
195 target_hook = (txt[4:], None)
33
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
196 elif txt.startswith('@'):
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
197 _end = txt.find(': ')
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
198 if _end == -1:
201
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
199 target_hook, _type, msg = getSelectedOrStatus()
33
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
200 else:
226
744426c2b699 browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 223
diff changeset
201 group = txt[1:_end] # only one target group is managed for the moment
201
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
202 if not group or not group in self.host.contact_panel.getGroups():
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
203 # the group doesn't exists, we ignore the key
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
204 group = None
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
205 target_hook, _type, msg = getSelectedOrStatus()
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
206 else:
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
207 _type = "GROUP"
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
208 msg = MicroblogPanel.warning_msg_group % group
226
744426c2b699 browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 223
diff changeset
209 target_hook = (txt[_end + 2:], group)
33
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
210 else:
201
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
211 print "ERROR: Unknown target"
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
212 target_hook, _type, msg = getSelectedOrStatus()
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
213
201
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
214 return (target_hook, _type, msg)
33
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
215
174
d97b0cba8b04 browser side: fix the line jump in unibox after entering something (work around a pyjamas bug)
Goffi <goffi@goffi.org>
parents: 167
diff changeset
216 def onBrowserEvent(self, event):
226
744426c2b699 browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 223
diff changeset
217 # XXX: woraroung a pyjamas bug: self.currentEvent is not set
174
d97b0cba8b04 browser side: fix the line jump in unibox after entering something (work around a pyjamas bug)
Goffi <goffi@goffi.org>
parents: 167
diff changeset
218 # so the TextBox's cancelKey doens't work. This is a workaround
d97b0cba8b04 browser side: fix the line jump in unibox after entering something (work around a pyjamas bug)
Goffi <goffi@goffi.org>
parents: 167
diff changeset
219 # FIXME: fix the bug upstream
d97b0cba8b04 browser side: fix the line jump in unibox after entering something (work around a pyjamas bug)
Goffi <goffi@goffi.org>
parents: 167
diff changeset
220 self.currentEvent = event
d97b0cba8b04 browser side: fix the line jump in unibox after entering something (work around a pyjamas bug)
Goffi <goffi@goffi.org>
parents: 167
diff changeset
221 TextArea.onBrowserEvent(self, event)
d97b0cba8b04 browser side: fix the line jump in unibox after entering something (work around a pyjamas bug)
Goffi <goffi@goffi.org>
parents: 167
diff changeset
222
33
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
223 def onKeyPress(self, sender, keycode, modifiers):
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
224 _txt = self.getText()
201
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
225 target = self._getTarget(_txt)
33
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
226 if not self._popup:
201
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
227 self.showWarning(target)
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
228 elif target != self._popup.target_data:
226
744426c2b699 browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 223
diff changeset
229 self._timeCb(None) # we remove the popup
201
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
230 self.showWarning(target)
33
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
231
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
232 self._timer.schedule(2000)
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
233
239
b911f2b43fd4 browser_side: added input history in the unibox:
souliane <souliane@mailoo.org>
parents: 235
diff changeset
234 def history_cb(text):
b911f2b43fd4 browser_side: added input history in the unibox:
souliane <souliane@mailoo.org>
parents: 235
diff changeset
235 self.setText(text)
249
c24715dcd2f6 browser_side: set the "workaround" timers to 5 ms instead of 10:
souliane <souliane@mailoo.org>
parents: 246
diff changeset
236 Timer(5, lambda: self.setCursorPos(len(text)))
239
b911f2b43fd4 browser_side: added input history in the unibox:
souliane <souliane@mailoo.org>
parents: 235
diff changeset
237
226
744426c2b699 browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 223
diff changeset
238 # if keycode == KEY_ENTER and not self.visible:
83
68d360caeecb New widget system: first draft
Goffi <goffi@goffi.org>
parents: 78
diff changeset
239 if keycode == KEY_ENTER:
33
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
240 if _txt:
269
9eb9c7d41bdc browser_side: added generic method "send" in SatWebFrontend
souliane <souliane@mailoo.org>
parents: 267
diff changeset
241 target_hook, type_, msg = target
201
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
242 if target_hook:
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
243 parsed_txt, data = target_hook
269
9eb9c7d41bdc browser_side: added generic method "send" in SatWebFrontend
souliane <souliane@mailoo.org>
parents: 267
diff changeset
244 self.host.send([(type_, data)], parsed_txt)
226
744426c2b699 browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 223
diff changeset
245 else: # we send the message to the selected target
201
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
246 self._selected_cache.onTextEntered(_txt)
239
b911f2b43fd4 browser_side: added input history in the unibox:
souliane <souliane@mailoo.org>
parents: 235
diff changeset
247 self.host._updateInputHistory(_txt)
33
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
248 self.setText('')
226
744426c2b699 browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 223
diff changeset
249 self._timeCb(None) # we remove the popup
174
d97b0cba8b04 browser side: fix the line jump in unibox after entering something (work around a pyjamas bug)
Goffi <goffi@goffi.org>
parents: 167
diff changeset
250 sender.cancelKey()
239
b911f2b43fd4 browser_side: added input history in the unibox:
souliane <souliane@mailoo.org>
parents: 235
diff changeset
251 elif keycode == KEY_UP:
b911f2b43fd4 browser_side: added input history in the unibox:
souliane <souliane@mailoo.org>
parents: 235
diff changeset
252 self.host._updateInputHistory(_txt, -1, history_cb)
b911f2b43fd4 browser_side: added input history in the unibox:
souliane <souliane@mailoo.org>
parents: 235
diff changeset
253 elif keycode == KEY_DOWN:
b911f2b43fd4 browser_side: added input history in the unibox:
souliane <souliane@mailoo.org>
parents: 235
diff changeset
254 self.host._updateInputHistory(_txt, +1, history_cb)
214
7b26be266ab1 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents: 213
diff changeset
255 else:
7b26be266ab1 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents: 213
diff changeset
256 self.__onComposing()
7b26be266ab1 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents: 213
diff changeset
257
231
fab7aa366576 browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents: 230
diff changeset
258 def getTargetAndData(self):
fab7aa366576 browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents: 230
diff changeset
259 """For external use, to get information about the (hypothetical) message
fab7aa366576 browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents: 230
diff changeset
260 that would be sent if we press Enter right now in the unibox.
fab7aa366576 browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents: 230
diff changeset
261 @return a tuple (target, data) with:
fab7aa366576 browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents: 230
diff changeset
262 - data: what would be the content of the message (body)
fab7aa366576 browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents: 230
diff changeset
263 - target: JID, group with the prefix "@" or the public entity "@@"
fab7aa366576 browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents: 230
diff changeset
264 """
fab7aa366576 browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents: 230
diff changeset
265 _txt = self.getText()
fab7aa366576 browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents: 230
diff changeset
266 target_hook, _type, _msg = self._getTarget(_txt)
fab7aa366576 browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents: 230
diff changeset
267 if target_hook:
fab7aa366576 browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents: 230
diff changeset
268 data, target = target_hook
fab7aa366576 browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents: 230
diff changeset
269 if target is None:
fab7aa366576 browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents: 230
diff changeset
270 return target_hook
fab7aa366576 browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents: 230
diff changeset
271 return (data, "@%s" % (target if target != "" else "@"))
fab7aa366576 browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents: 230
diff changeset
272 if isinstance(self._selected_cache, MicroblogPanel):
fab7aa366576 browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents: 230
diff changeset
273 groups = self._selected_cache.accepted_groups
fab7aa366576 browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents: 230
diff changeset
274 target = "@%s" % (groups[0] if len(groups) > 0 else "@")
fab7aa366576 browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents: 230
diff changeset
275 if len(groups) > 1:
fab7aa366576 browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents: 230
diff changeset
276 Window.alert("Sole the first group of the selected panel is taken in consideration: '%s'" % groups[0])
fab7aa366576 browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents: 230
diff changeset
277 elif isinstance(self._selected_cache, ChatPanel):
fab7aa366576 browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents: 230
diff changeset
278 target = self._selected_cache.target
fab7aa366576 browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents: 230
diff changeset
279 return (_txt, target)
fab7aa366576 browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents: 230
diff changeset
280
214
7b26be266ab1 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents: 213
diff changeset
281 def __onComposing(self):
7b26be266ab1 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents: 213
diff changeset
282 """Callback when the user is composing a text."""
7b26be266ab1 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents: 213
diff changeset
283 if hasattr(self._selected_cache, "target"):
223
624a87377412 browser_side, plugin XEP-0085: limit the number of bridge methods calls for "chatStateComposing".
souliane <souliane@mailoo.org>
parents: 218
diff changeset
284 self._selected_cache.state_machine._onEvent("composing")
33
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
285
186
72bb1d845b6a browser side: global resize on UniBox resize
Goffi <goffi@goffi.org>
parents: 185
diff changeset
286 def onMouseUp(self, sender, x, y):
72bb1d845b6a browser side: global resize on UniBox resize
Goffi <goffi@goffi.org>
parents: 185
diff changeset
287 size = (self.getOffsetWidth(), self.getOffsetHeight())
72bb1d845b6a browser side: global resize on UniBox resize
Goffi <goffi@goffi.org>
parents: 185
diff changeset
288 if size != self.__size:
72bb1d845b6a browser side: global resize on UniBox resize
Goffi <goffi@goffi.org>
parents: 185
diff changeset
289 self.__size = size
193
f2ae8e170c49 browser side: selected widget caching in UniBox, to avoid to ask the getter at each key pressed, which make the box very slow.
Goffi <goffi@goffi.org>
parents: 192
diff changeset
290 self.host.resize()
f2ae8e170c49 browser side: selected widget caching in UniBox, to avoid to ask the getter at each key pressed, which make the box very slow.
Goffi <goffi@goffi.org>
parents: 192
diff changeset
291
f2ae8e170c49 browser side: selected widget caching in UniBox, to avoid to ask the getter at each key pressed, which make the box very slow.
Goffi <goffi@goffi.org>
parents: 192
diff changeset
292 def onSelectedChange(self, selected):
f2ae8e170c49 browser side: selected widget caching in UniBox, to avoid to ask the getter at each key pressed, which make the box very slow.
Goffi <goffi@goffi.org>
parents: 192
diff changeset
293 self._selected_cache = selected
186
72bb1d845b6a browser side: global resize on UniBox resize
Goffi <goffi@goffi.org>
parents: 185
diff changeset
294
73
447dc8ac181b Adrien's uniBox design integration + lastPopup style
Goffi <goffi@goffi.org>
parents: 71
diff changeset
295 """def complete(self):
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
296
33
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
297 #self.visible=False #XXX: self.visible is not unset in pyjamas when ENTER is pressed and a completion is done
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
298 #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
299 return AutoCompleteTextBox.complete(self)"""
33
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
300
210
3092f6b1710c browser side: make the OK button title for group selector configureable + few "cosmetic" changes (PEP 8...)
souliane <souliane@mailoo.org>
parents: 206
diff changeset
301
132
30d8e328559b server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents: 131
diff changeset
302 class MicroblogItem():
226
744426c2b699 browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 223
diff changeset
303 # XXX: should be moved in a separated module
132
30d8e328559b server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents: 131
diff changeset
304
30d8e328559b server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents: 131
diff changeset
305 def __init__(self, data):
30d8e328559b server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents: 131
diff changeset
306 self.id = data['id']
210
3092f6b1710c browser side: make the OK button title for group selector configureable + few "cosmetic" changes (PEP 8...)
souliane <souliane@mailoo.org>
parents: 206
diff changeset
307 self.type = data.get('type', 'main_item')
132
30d8e328559b server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents: 131
diff changeset
308 self.content = data['content']
260
533d68585866 browser side: if 'xhtml' key is present in microblog data, rich content is displayed
Goffi <goffi@goffi.org>
parents: 255
diff changeset
309 self.xhtml = data.get('xhtml')
132
30d8e328559b server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents: 131
diff changeset
310 self.author = data['author']
226
744426c2b699 browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 223
diff changeset
311 self.timestamp = float(data.get('timestamp', 0)) # XXX: int doesn't work here
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
312 self.comments = data.get('comments', False)
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
313 if self.comments:
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
314 try:
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
315 self.comments_hash = (data['comments_service'], data['comments_node'])
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
316 self.comments_service = data['comments_service']
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
317 self.comments_node = data['comments_node']
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
318 except KeyError:
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
319 print "Warning: can't manage comment [%s], some keys are missing in microblog data (%s)" % (data["comments"], data.keys())
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
320 self.comments = False
226
744426c2b699 browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 223
diff changeset
321 if set(("service", "node")).issubset(data.keys()):
282
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
322 # comment item
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
323 self.service = data["service"]
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
324 self.node = data["node"]
282
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
325 else:
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
326 # main item
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
327 try:
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
328 self.service = data['comments_service']
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
329 self.node = data['comments_node']
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
330 except KeyError:
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
331 logging.error("Main item %s is missing its comments information!" % self.id)
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
332 self.hash = (self.service, self.node)
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
333
210
3092f6b1710c browser side: make the OK button title for group selector configureable + few "cosmetic" changes (PEP 8...)
souliane <souliane@mailoo.org>
parents: 206
diff changeset
334
282
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
335 class MicroblogEntry(SimplePanel, ClickHandler, FocusHandler, KeyboardHandler):
18
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
336
199
39311c7dad77 browser side: it is now possible to select a microblog panel or an entry inside it
Goffi <goffi@goffi.org>
parents: 195
diff changeset
337 def __init__(self, blog_panel, mblog_entry):
18
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
338 SimplePanel.__init__(self)
199
39311c7dad77 browser side: it is now possible to select a microblog panel or an entry inside it
Goffi <goffi@goffi.org>
parents: 195
diff changeset
339 self._blog_panel = blog_panel
18
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
340
282
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
341 self.entry = mblog_entry
119
a8d11fdea090 microblog avatar update
Goffi <goffi@goffi.org>
parents: 114
diff changeset
342 self.author = mblog_entry.author
135
ceef355156de server + browser side: groupblog subscription + fixed blog insertion order
Goffi <goffi@goffi.org>
parents: 132
diff changeset
343 self.timestamp = mblog_entry.timestamp
58
4fa3d57f72f8 browser side: microblog entries caching
Goffi <goffi@goffi.org>
parents: 57
diff changeset
344 _datetime = datetime.fromtimestamp(mblog_entry.timestamp)
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
345 self.comments = mblog_entry.comments
282
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
346 self.pub_data = (mblog_entry.hash[0], mblog_entry.hash[1], mblog_entry.id)
18
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
347
282
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
348 self.editable_content = (mblog_entry.xhtml, const._SYNTAX_XHTML) if mblog_entry.xhtml else (mblog_entry.content, None)
119
a8d11fdea090 microblog avatar update
Goffi <goffi@goffi.org>
parents: 114
diff changeset
349 self.panel = HTMLPanel("""
120
054b7b3424a3 browser side: microblog's entry header with pseudo and timestamp
Goffi <goffi@goffi.org>
parents: 119
diff changeset
350 <div class='mb_entry_header'><span class='mb_entry_author'>%(author)s</span> on <span class='mb_entry_timestamp'>%(timestamp)s</span></div>
282
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
351 <div class='mb_entry_delete_update'>
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
352 <div id="id_delete"></div>
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
353 <div id="id_update"></div>
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
354 </div>
119
a8d11fdea090 microblog avatar update
Goffi <goffi@goffi.org>
parents: 114
diff changeset
355 <div class="mb_entry_avatar" id='id_avatar'></div>
282
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
356 <div class="mb_entry_dialog" id='id_entry_dialog'></div>
114
c64b00f31461 browser side: microblog entries
Adrien Vigneron <adrienvigneron@mailoo.org>
parents: 109
diff changeset
357 </div>
119
a8d11fdea090 microblog avatar update
Goffi <goffi@goffi.org>
parents: 114
diff changeset
358 """ % {"author": html_sanitize(self.author),
282
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
359 "timestamp": _datetime
114
c64b00f31461 browser side: microblog entries
Adrien Vigneron <adrienvigneron@mailoo.org>
parents: 109
diff changeset
360 })
199
39311c7dad77 browser side: it is now possible to select a microblog panel or an entry inside it
Goffi <goffi@goffi.org>
parents: 195
diff changeset
361 self.avatar = Image(blog_panel.host.getAvatar(self.author))
119
a8d11fdea090 microblog avatar update
Goffi <goffi@goffi.org>
parents: 114
diff changeset
362 self.panel.add(self.avatar, "id_avatar")
282
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
363 body = addURLToText(html_sanitize(mblog_entry.content)) if not mblog_entry.xhtml else mblog_entry.xhtml
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
364 self.bubble = HTML(body)
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
365 self.bubble.setStyleName("bubble")
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
366 self.panel.add(self.bubble, "id_entry_dialog")
119
a8d11fdea090 microblog avatar update
Goffi <goffi@goffi.org>
parents: 114
diff changeset
367 self.panel.setStyleName('mb_entry')
282
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
368 if self.author == blog_panel.host.whoami.bare:
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
369 self.delete_label = Label(u"✗")
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
370 self.delete_label.setTitle("Delete this message")
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
371 self.panel.add(self.delete_label, "id_delete")
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
372 self.update_label = Label(u"✍")
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
373 self.update_label.setTitle("Edit this message")
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
374 self.panel.add(self.update_label, "id_update")
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
375 self.delete_label.addClickListener(self)
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
376 self.update_label.addClickListener(self)
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
377 else:
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
378 self.modify_label = self.delete_label = None
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
379 self.editbox = None
119
a8d11fdea090 microblog avatar update
Goffi <goffi@goffi.org>
parents: 114
diff changeset
380 self.add(self.panel)
199
39311c7dad77 browser side: it is now possible to select a microblog panel or an entry inside it
Goffi <goffi@goffi.org>
parents: 195
diff changeset
381 ClickHandler.__init__(self)
39311c7dad77 browser side: it is now possible to select a microblog panel or an entry inside it
Goffi <goffi@goffi.org>
parents: 195
diff changeset
382 self.addClickListener(self)
119
a8d11fdea090 microblog avatar update
Goffi <goffi@goffi.org>
parents: 114
diff changeset
383
a8d11fdea090 microblog avatar update
Goffi <goffi@goffi.org>
parents: 114
diff changeset
384 def updateAvatar(self, new_avatar):
a8d11fdea090 microblog avatar update
Goffi <goffi@goffi.org>
parents: 114
diff changeset
385 """Change the avatar of the entry
a8d11fdea090 microblog avatar update
Goffi <goffi@goffi.org>
parents: 114
diff changeset
386 @param new_avatar: path to the new image"""
a8d11fdea090 microblog avatar update
Goffi <goffi@goffi.org>
parents: 114
diff changeset
387 self.avatar.setUrl(new_avatar)
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
388
199
39311c7dad77 browser side: it is now possible to select a microblog panel or an entry inside it
Goffi <goffi@goffi.org>
parents: 195
diff changeset
389 def onClick(self, sender):
282
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
390 if sender == self:
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
391 self._blog_panel.setSelectedEntry(self if self.comments else None)
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
392 elif sender == self.update_label:
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
393 self._update()
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
394 elif sender == self.delete_label:
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
395 self._delete()
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
396
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
397 def onKeyUp(self, sender, keycode, modifiers):
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
398 """Update is done when ENTER key is pressed within the raw editbox"""
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
399 if sender != self.editbox or not self.editbox.getVisible():
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
400 return
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
401 if keycode == KEY_ENTER:
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
402 self.updateContent()
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
403
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
404 def onLostFocus(self, sender):
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
405 """Update is done when the focus leaves the raw editbox"""
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
406 if sender != self.editbox or not self.editbox.getVisible():
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
407 return
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
408 self.updateContent()
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
409
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
410 def updateContent(self, cancel=False):
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
411 """Send the new content to the backend"""
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
412 if not self.editbox or not self.editbox.getVisible():
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
413 return
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
414 self.panel.remove(self.edit_panel)
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
415 self.panel.add(self.bubble, "id_entry_dialog")
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
416 new_text = self.editbox.getText().strip()
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
417 self.edit_panel = self.editbox = None
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
418 if cancel or new_text == self.editable_content[0] or new_text == "":
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
419 return
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
420 self.editable_content[0] = new_text
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
421 self._blog_panel.host.bridge.call('updateMblog', None, self.pub_data, self.comments, new_text,
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
422 {'rich': new_text} if self.entry.xhtml else {})
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
423
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
424 def _update(self):
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
425 """Change the bubble to an editbox"""
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
426 if self.editbox and self.editbox.getVisible():
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
427 return
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
428
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
429 def setOriginalText(text, container):
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
430 text = text.strip()
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
431 container.original_text = text
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
432 self.editbox.setWidth('100%')
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
433 self.editbox.setText(text)
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
434 panel = SimplePanel()
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
435 panel.add(container)
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
436 panel.setStyleName("bubble")
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
437 panel.addStyleName('bubble-editbox')
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
438 self.bubble.removeFromParent()
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
439 self.panel.add(panel, "id_entry_dialog")
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
440 self.editbox.setFocus(True)
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
441 self.editbox.setSelectionRange(len(text), 0)
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
442 self.edit_panel = panel
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
443 self.editable_content = (text, container.format if isinstance(container, richtext.RichTextEditor) else None)
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
444
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
445 if self.entry.xhtml:
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
446 options = ('no_recipient', 'no_sync_unibox', 'no_style', 'update_msg', 'no_close')
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
447
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
448 def cb(result):
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
449 self.updateContent(result == richtext.CANCEL)
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
450
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
451 editor = richtext.RichTextEditor(self._blog_panel.host, self.panel, cb, options=options)
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
452 editor.setVisible(True) # needed to build the toolbar
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
453 self.editbox = editor.textarea
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
454 self._blog_panel.host.bridge.call('syntaxConvert', lambda d: setOriginalText(d, editor),
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
455 self.editable_content[0], self.editable_content[1])
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
456 else:
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
457 self.editbox = TextArea()
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
458 self.editbox.addFocusListener(self)
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
459 self.editbox.addKeyboardListener(self)
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
460 setOriginalText(self.editable_content[0], self.editbox)
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
461
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
462 def _delete(self):
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
463 """Ask confirmation for deletion"""
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
464 def confirm_cb(answer):
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
465 if answer:
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
466 self._blog_panel.host.bridge.call('deleteMblog', None, self.pub_data, self.comments)
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
467
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
468 target = 'message and all its comments' if self.comments else 'comment'
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
469 _dialog = ConfirmDialog(confirm_cb, text="Do you really want to delete this %s?" % target)
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
470 _dialog.show()
119
a8d11fdea090 microblog avatar update
Goffi <goffi@goffi.org>
parents: 114
diff changeset
471
18
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
472
195
dd27072d8ae0 browser side: widgets refactoring:
Goffi <goffi@goffi.org>
parents: 194
diff changeset
473 class MicroblogPanel(base_widget.LiberviaWidget):
201
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
474 warning_msg_public = "This message will be PUBLIC and everybody will be able to see it, even people you don't know"
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
475 warning_msg_group = "This message will be published for all the people of the group <span class='warningTarget'>%s</span>"
18
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
476
132
30d8e328559b server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents: 131
diff changeset
477 def __init__(self, host, accepted_groups):
18
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
478 """Panel used to show microblog
132
30d8e328559b server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents: 131
diff changeset
479 @param accepted_groups: groups displayed in this panel, if empty, show all microblogs from all contacts
30d8e328559b server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents: 131
diff changeset
480 """
230
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
481 base_widget.LiberviaWidget.__init__(self, host, ", ".join(accepted_groups), selectable=True)
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
482 self.setAcceptedGroup(accepted_groups)
58
4fa3d57f72f8 browser side: microblog entries caching
Goffi <goffi@goffi.org>
parents: 57
diff changeset
483 self.entries = {}
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
484 self.comments = {}
199
39311c7dad77 browser side: it is now possible to select a microblog panel or an entry inside it
Goffi <goffi@goffi.org>
parents: 195
diff changeset
485 self.selected_entry = None
18
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
486 self.vpanel = VerticalPanel()
83
68d360caeecb New widget system: first draft
Goffi <goffi@goffi.org>
parents: 78
diff changeset
487 self.vpanel.setStyleName('microblogPanel')
34
ed935f763cc8 browser side: misc css/layout fixes
Goffi <goffi@goffi.org>
parents: 33
diff changeset
488 self.setWidget(self.vpanel)
18
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
489
195
dd27072d8ae0 browser side: widgets refactoring:
Goffi <goffi@goffi.org>
parents: 194
diff changeset
490 @classmethod
dd27072d8ae0 browser side: widgets refactoring:
Goffi <goffi@goffi.org>
parents: 194
diff changeset
491 def registerClass(cls):
230
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
492 base_widget.LiberviaWidget.addDropKey("GROUP", cls.createPanel)
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
493 base_widget.LiberviaWidget.addDropKey("CONTACT_TITLE", cls.createMetaPanel)
195
dd27072d8ae0 browser side: widgets refactoring:
Goffi <goffi@goffi.org>
parents: 194
diff changeset
494
dd27072d8ae0 browser side: widgets refactoring:
Goffi <goffi@goffi.org>
parents: 194
diff changeset
495 @classmethod
230
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
496 def createPanel(cls, host, item):
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
497 """Generic panel creation for one, several or all groups (meta).
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
498 @parem host: the SatWebFrontend instance
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
499 @param item: single group as a string, list of groups
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
500 (as an array) or None (for the meta group = "all groups")
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
501 @return: the created MicroblogPanel
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
502 """
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
503 _items = item if isinstance(item, list) else ([] if item is None else [item])
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
504 _type = 'ALL' if _items == [] else 'GROUP'
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
505 # XXX: pyjamas doesn't support use of cls directly
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
506 _new_panel = MicroblogPanel(host, _items)
195
dd27072d8ae0 browser side: widgets refactoring:
Goffi <goffi@goffi.org>
parents: 194
diff changeset
507 host.FillMicroblogPanel(_new_panel)
230
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
508 host.bridge.call('getMassiveLastMblogs', _new_panel.massiveInsert, _type, _items, 10)
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
509 host.setSelected(_new_panel)
195
dd27072d8ae0 browser side: widgets refactoring:
Goffi <goffi@goffi.org>
parents: 194
diff changeset
510 return _new_panel
dd27072d8ae0 browser side: widgets refactoring:
Goffi <goffi@goffi.org>
parents: 194
diff changeset
511
dd27072d8ae0 browser side: widgets refactoring:
Goffi <goffi@goffi.org>
parents: 194
diff changeset
512 @classmethod
230
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
513 def createMetaPanel(cls, host, item):
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
514 """Needed for the drop keys to not be mixed between meta panel and panel for "Contacts" group"""
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
515 return MicroblogPanel.createPanel(host, None)
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
516
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
517 @property
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
518 def accepted_groups(self):
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
519 return self._accepted_groups
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
520
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
521 def matchEntity(self, entity):
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
522 """
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
523 @param entity: single group as a string, list of groups
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
524 (as an array) or None (for the meta group = "all groups")
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
525 @return: True if self matches the given entity
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
526 """
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
527 entity = entity if isinstance(entity, list) else ([] if entity is None else [entity])
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
528 entity.sort() # sort() do not return the sorted list: do it here, not on the "return" line
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
529 return self.accepted_groups == entity
195
dd27072d8ae0 browser side: widgets refactoring:
Goffi <goffi@goffi.org>
parents: 194
diff changeset
530
201
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
531 def getWarningData(self):
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
532 if self.selected_entry:
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
533 if not self.selected_entry.comments:
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
534 print ("ERROR: an item without comment is selected")
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
535 return ("NONE", None)
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
536 return ("PUBLIC", "This is a <span class='warningTarget'>comment</span> and keep the initial post visibility, so it is potentialy public")
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
537
230
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
538 elif not self._accepted_groups:
201
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
539 # we have a meta MicroblogPanel, we publish publicly
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
540 return ("PUBLIC", self.warning_msg_public)
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
541 else:
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
542 # we only accept one group at the moment
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
543 # FIXME: manage several groups
230
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
544 return ("GROUP", self.warning_msg_group % self._accepted_groups[0])
201
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
545
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
546 def onTextEntered(self, text):
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
547 if self.selected_entry:
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
548 # we are entering a comment
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
549 comments_node = self.selected_entry.comments
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
550 if not comments_node:
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
551 raise Exception("ERROR: comments node is empty")
269
9eb9c7d41bdc browser_side: added generic method "send" in SatWebFrontend
souliane <souliane@mailoo.org>
parents: 267
diff changeset
552 target = ("COMMENT", comments_node)
230
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
553 elif not self._accepted_groups:
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
554 # we are entering a public microblog
269
9eb9c7d41bdc browser_side: added generic method "send" in SatWebFrontend
souliane <souliane@mailoo.org>
parents: 267
diff changeset
555 target = ("PUBLIC", None)
201
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
556 else:
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
557 # we are entering a microblog restricted to a group
201
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
558 # FIXME: manage several groups
269
9eb9c7d41bdc browser_side: added generic method "send" in SatWebFrontend
souliane <souliane@mailoo.org>
parents: 267
diff changeset
559 target = ("GROUP", self._accepted_groups[0])
9eb9c7d41bdc browser_side: added generic method "send" in SatWebFrontend
souliane <souliane@mailoo.org>
parents: 267
diff changeset
560 self.host.send([target], text)
201
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
561
132
30d8e328559b server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents: 131
diff changeset
562 def accept_all(self):
230
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
563 return not self._accepted_groups # we accept every microblog only if we are not filtering by groups
132
30d8e328559b server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents: 131
diff changeset
564
30d8e328559b server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents: 131
diff changeset
565 def getEntries(self):
30d8e328559b server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents: 131
diff changeset
566 """Ask all the entries for the currenly accepted groups,
30d8e328559b server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents: 131
diff changeset
567 and fill the panel"""
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
568
132
30d8e328559b server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents: 131
diff changeset
569 def massiveInsert(self, mblogs):
30d8e328559b server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents: 131
diff changeset
570 """Insert several microblogs at once
30d8e328559b server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents: 131
diff changeset
571 @param mblogs: dictionary of microblogs, as the result of getMassiveLastGroupBlogs
30d8e328559b server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents: 131
diff changeset
572 """
242
a25aa882e09a browser_side: add context menu for contact:
souliane <souliane@mailoo.org>
parents: 241
diff changeset
573 print "Massive insertion of %d microblogs" % len(mblogs)
132
30d8e328559b server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents: 131
diff changeset
574 for publisher in mblogs:
30d8e328559b server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents: 131
diff changeset
575 print "adding blogs for [%s]" % publisher
30d8e328559b server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents: 131
diff changeset
576 for mblog in mblogs[publisher]:
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
577 if not "content" in mblog:
132
30d8e328559b server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents: 131
diff changeset
578 print ("WARNING: No content found in microblog [%s]", mblog)
30d8e328559b server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents: 131
diff changeset
579 continue
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
580 mblog_item = MicroblogItem(mblog)
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
581 self.addEntry(mblog_item)
132
30d8e328559b server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents: 131
diff changeset
582
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
583 def mblogsInsert(self, mblogs):
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
584 """ Insert several microblogs at once
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
585 @param mblogs: list of microblogs
132
30d8e328559b server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents: 131
diff changeset
586 """
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
587 for mblog in mblogs:
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
588 if not "content" in mblog:
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
589 print ("WARNING: No content found in microblog [%s]", mblog)
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
590 continue
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
591 mblog_item = MicroblogItem(mblog)
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
592 self.addEntry(mblog_item)
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
593
210
3092f6b1710c browser side: make the OK button title for group selector configureable + few "cosmetic" changes (PEP 8...)
souliane <souliane@mailoo.org>
parents: 206
diff changeset
594 def _chronoInsert(self, vpanel, entry, reverse=True):
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
595 """ Insert an entry in chronological order
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
596 @param vpanel: VerticalPanel instance
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
597 @param entry: MicroblogEntry
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
598 @param reverse: more recent entry on top if True, chronological order else"""
135
ceef355156de server + browser side: groupblog subscription + fixed blog insertion order
Goffi <goffi@goffi.org>
parents: 132
diff changeset
599 # we look for the right index to insert our entry:
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
600 # if reversed, we insert the entry above the first entry
135
ceef355156de server + browser side: groupblog subscription + fixed blog insertion order
Goffi <goffi@goffi.org>
parents: 132
diff changeset
601 # in the past
ceef355156de server + browser side: groupblog subscription + fixed blog insertion order
Goffi <goffi@goffi.org>
parents: 132
diff changeset
602 idx = 0
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
603
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
604 for child in vpanel.children:
135
ceef355156de server + browser side: groupblog subscription + fixed blog insertion order
Goffi <goffi@goffi.org>
parents: 132
diff changeset
605 if not isinstance(child, MicroblogEntry):
210
3092f6b1710c browser side: make the OK button title for group selector configureable + few "cosmetic" changes (PEP 8...)
souliane <souliane@mailoo.org>
parents: 206
diff changeset
606 idx += 1
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
607 continue
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
608 if reverse:
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
609 if child.timestamp < entry.timestamp:
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
610 break
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
611 else:
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
612 if child.timestamp > entry.timestamp:
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
613 break
210
3092f6b1710c browser side: make the OK button title for group selector configureable + few "cosmetic" changes (PEP 8...)
souliane <souliane@mailoo.org>
parents: 206
diff changeset
614 idx += 1
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
615
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
616 vpanel.insert(entry, idx)
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
617
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
618 def addEntry(self, mblog_item):
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
619 """Add an entry to the panel
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
620 @param mblog_item: MicroblogItem instance
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
621 """
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
622 if mblog_item.type == "comment":
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
623 if not mblog_item.hash in self.comments:
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
624 # The comments node is not known in this panel
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
625 return
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
626 _entry = MicroblogEntry(self, mblog_item)
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
627 parent = self.comments[mblog_item.hash]
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
628 parent_idx = self.vpanel.getWidgetIndex(parent)
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
629 # we find or create the panel where the comment must be inserted
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
630 try:
226
744426c2b699 browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 223
diff changeset
631 sub_panel = self.vpanel.getWidget(parent_idx + 1)
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
632 except IndexError:
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
633 sub_panel = None
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
634 if not sub_panel or not isinstance(sub_panel, VerticalPanel):
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
635 sub_panel = VerticalPanel()
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
636 sub_panel.setStyleName('microblogPanel')
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
637 sub_panel.addStyleName('subPanel')
226
744426c2b699 browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 223
diff changeset
638 self.vpanel.insert(sub_panel, parent_idx + 1)
282
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
639 for idx in xrange(0, len(sub_panel.getChildren())):
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
640 comment = sub_panel.getIndexedChild(idx)
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
641 if comment.pub_data[2] == mblog_item.id:
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
642 # update an existing comment
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
643 sub_panel.remove(comment)
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
644 sub_panel.insert(_entry, idx)
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
645 return
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
646 # we want comments to be inserted in chronological order
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
647 self._chronoInsert(sub_panel, _entry, reverse=False)
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
648 return
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
649
282
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
650 update = mblog_item.id in self.entries
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
651 _entry = MicroblogEntry(self, mblog_item)
282
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
652 if update:
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
653 idx = self.vpanel.getWidgetIndex(self.entries[mblog_item.id])
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
654 self.vpanel.remove(self.entries[mblog_item.id])
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
655 self.vpanel.insert(_entry, idx)
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
656 else:
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
657 self._chronoInsert(self.vpanel, _entry)
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
658 self.entries[mblog_item.id] = _entry
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
659
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
660 if mblog_item.comments:
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
661 # entry has comments, we keep the comment node as a reference
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
662 self.comments[mblog_item.comments_hash] = _entry
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
663 self.host.bridge.call('getMblogComments', self.mblogsInsert, mblog_item.comments_service, mblog_item.comments_node)
18
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
664
282
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
665 def removeEntry(self, type_, id_):
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
666 """Remove an entry from the panel
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
667 @param type_: entry type ('main_item' or 'comment')
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
668 @param id_: entry id
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
669 """
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
670 for child in self.vpanel.getChildren():
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
671 if isinstance(child, MicroblogEntry) and type_ == 'main_item':
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
672 print child.pub_data
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
673 if child.pub_data[2] == id_:
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
674 main_idx = self.vpanel.getWidgetIndex(child)
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
675 try:
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
676 sub_panel = self.vpanel.getWidget(main_idx + 1)
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
677 if isinstance(sub_panel, VerticalPanel):
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
678 sub_panel.removeFromParent()
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
679 except IndexError:
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
680 pass
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
681 child.removeFromParent()
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
682 self.selected_entry = None
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
683 break
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
684 elif isinstance(child, VerticalPanel) and type_ == 'comment':
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
685 for comment in child.getChildren():
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
686 if comment.pub_data[2] == id_:
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
687 comment.removeFromParent()
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
688 self.selected_entry = None
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
689 break
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
690
199
39311c7dad77 browser side: it is now possible to select a microblog panel or an entry inside it
Goffi <goffi@goffi.org>
parents: 195
diff changeset
691 def setSelectedEntry(self, entry):
39311c7dad77 browser side: it is now possible to select a microblog panel or an entry inside it
Goffi <goffi@goffi.org>
parents: 195
diff changeset
692 if self.selected_entry == entry:
39311c7dad77 browser side: it is now possible to select a microblog panel or an entry inside it
Goffi <goffi@goffi.org>
parents: 195
diff changeset
693 entry = None
39311c7dad77 browser side: it is now possible to select a microblog panel or an entry inside it
Goffi <goffi@goffi.org>
parents: 195
diff changeset
694 if self.selected_entry:
39311c7dad77 browser side: it is now possible to select a microblog panel or an entry inside it
Goffi <goffi@goffi.org>
parents: 195
diff changeset
695 self.selected_entry.removeStyleName('selected_entry')
39311c7dad77 browser side: it is now possible to select a microblog panel or an entry inside it
Goffi <goffi@goffi.org>
parents: 195
diff changeset
696 if entry:
282
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
697 print "microblog entry selected (author=%s)" % entry.author
199
39311c7dad77 browser side: it is now possible to select a microblog panel or an entry inside it
Goffi <goffi@goffi.org>
parents: 195
diff changeset
698 entry.addStyleName('selected_entry')
39311c7dad77 browser side: it is now possible to select a microblog panel or an entry inside it
Goffi <goffi@goffi.org>
parents: 195
diff changeset
699 self.selected_entry = entry
39311c7dad77 browser side: it is now possible to select a microblog panel or an entry inside it
Goffi <goffi@goffi.org>
parents: 195
diff changeset
700
241
86055ccf69c3 browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents: 239
diff changeset
701 def updateValue(self, type_, jid, value):
119
a8d11fdea090 microblog avatar update
Goffi <goffi@goffi.org>
parents: 114
diff changeset
702 """Update a jid value in entries
241
86055ccf69c3 browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents: 239
diff changeset
703 @param type_: one of 'avatar', 'nick'
119
a8d11fdea090 microblog avatar update
Goffi <goffi@goffi.org>
parents: 114
diff changeset
704 @param jid: jid concerned
a8d11fdea090 microblog avatar update
Goffi <goffi@goffi.org>
parents: 114
diff changeset
705 @param value: new value"""
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
706 def updateVPanel(vpanel):
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
707 for child in vpanel.children:
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
708 if isinstance(child, MicroblogEntry) and child.author == jid:
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
709 child.updateAvatar(value)
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
710 elif isinstance(child, VerticalPanel):
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
711 updateVPanel(child)
241
86055ccf69c3 browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents: 239
diff changeset
712 if type_ == 'avatar':
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
713 updateVPanel(self.vpanel)
119
a8d11fdea090 microblog avatar update
Goffi <goffi@goffi.org>
parents: 114
diff changeset
714
18
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
715 def setAcceptedGroup(self, group):
230
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
716 """Add one or more group(s) which can be displayed in this panel.
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
717 Prevent from duplicate values and keep the list sorted.
18
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
718 @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
719 """
230
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
720 if not hasattr(self, "_accepted_groups"):
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
721 self._accepted_groups = []
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
722 groups = group if isinstance(group, list) else [group]
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
723 for _group in groups:
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
724 if _group not in self._accepted_groups:
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
725 self._accepted_groups.append(_group)
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
726 self._accepted_groups.sort()
18
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
727
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
728 def isJidAccepted(self, jid):
163
b887186e8fc8 browser side: get entity's microblogs for newly added contacts
Goffi <goffi@goffi.org>
parents: 148
diff changeset
729 """Tell if a jid is actepted and shown in this panel
18
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
730 @param jid: jid
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
731 @return: True if the jid is accepted"""
132
30d8e328559b server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents: 131
diff changeset
732 if self.accept_all():
18
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
733 return True
230
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
734 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
735 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
736 return True
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
737 return False
19
e8e3704eb97f Added basic chat panel
Goffi <goffi@goffi.org>
parents: 18
diff changeset
738
210
3092f6b1710c browser side: make the OK button title for group selector configureable + few "cosmetic" changes (PEP 8...)
souliane <souliane@mailoo.org>
parents: 206
diff changeset
739
279
2d6bd975a72d browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents: 276
diff changeset
740 class StatusPanel(HTMLPanel):
20
8f4b1a8914c3 - User status is now updated
Goffi <goffi@goffi.org>
parents: 19
diff changeset
741 def __init__(self, host, status=''):
8f4b1a8914c3 - User status is now updated
Goffi <goffi@goffi.org>
parents: 19
diff changeset
742 self.host = host
8f4b1a8914c3 - User status is now updated
Goffi <goffi@goffi.org>
parents: 19
diff changeset
743 self.status = status or '&nbsp;'
19
e8e3704eb97f Added basic chat panel
Goffi <goffi@goffi.org>
parents: 18
diff changeset
744 HTMLPanel.__init__(self, self.__getContent())
20
8f4b1a8914c3 - User status is now updated
Goffi <goffi@goffi.org>
parents: 19
diff changeset
745 self.setStyleName('statusPanel')
19
e8e3704eb97f Added basic chat panel
Goffi <goffi@goffi.org>
parents: 18
diff changeset
746
e8e3704eb97f Added basic chat panel
Goffi <goffi@goffi.org>
parents: 18
diff changeset
747 def __getContent(self):
210
3092f6b1710c browser side: make the OK button title for group selector configureable + few "cosmetic" changes (PEP 8...)
souliane <souliane@mailoo.org>
parents: 206
diff changeset
748 return "<span class='status'>%(status)s</span>" % {'status': html_sanitize(self.status)}
19
e8e3704eb97f Added basic chat panel
Goffi <goffi@goffi.org>
parents: 18
diff changeset
749
e8e3704eb97f Added basic chat panel
Goffi <goffi@goffi.org>
parents: 18
diff changeset
750 def changeStatus(self, new_status):
20
8f4b1a8914c3 - User status is now updated
Goffi <goffi@goffi.org>
parents: 19
diff changeset
751 self.status = new_status or '&nbsp;'
19
e8e3704eb97f Added basic chat panel
Goffi <goffi@goffi.org>
parents: 18
diff changeset
752 self.setHTML(self.__getContent())
e8e3704eb97f Added basic chat panel
Goffi <goffi@goffi.org>
parents: 18
diff changeset
753
279
2d6bd975a72d browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents: 276
diff changeset
754
2d6bd975a72d browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents: 276
diff changeset
755 class PresenceStatusPanel(HorizontalPanel, ClickHandler):
2d6bd975a72d browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents: 276
diff changeset
756
2d6bd975a72d browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents: 276
diff changeset
757 def __init__(self, host, presence="", status=""):
2d6bd975a72d browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents: 276
diff changeset
758 self.host = host
2d6bd975a72d browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents: 276
diff changeset
759 HorizontalPanel.__init__(self, Width='100%')
2d6bd975a72d browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents: 276
diff changeset
760 self.presence_button = Label(u"◉")
2d6bd975a72d browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents: 276
diff changeset
761 self.presence_button.setStyleName("presence-button")
2d6bd975a72d browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents: 276
diff changeset
762 self.status_panel = StatusPanel(host, status=status)
2d6bd975a72d browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents: 276
diff changeset
763 self.setPresence(presence)
2d6bd975a72d browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents: 276
diff changeset
764 entries = {}
2d6bd975a72d browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents: 276
diff changeset
765 for value in const.PRESENCE.keys():
2d6bd975a72d browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents: 276
diff changeset
766 entries.update({const.PRESENCE[value]: {"value": value}})
2d6bd975a72d browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents: 276
diff changeset
767
2d6bd975a72d browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents: 276
diff changeset
768 def callback(sender, key):
2d6bd975a72d browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents: 276
diff changeset
769 self.setPresence(entries[key]["value"]) # order matters
2d6bd975a72d browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents: 276
diff changeset
770 self.host.send([("STATUS", None)], self.status_panel.status)
2d6bd975a72d browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents: 276
diff changeset
771
2d6bd975a72d browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents: 276
diff changeset
772 self.presence_list = PopupMenuPanel(entries, callback=callback, style={"menu": "gwt-ListBox"})
2d6bd975a72d browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents: 276
diff changeset
773 self.presence_list.registerClickSender(self.presence_button)
2d6bd975a72d browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents: 276
diff changeset
774
2d6bd975a72d browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents: 276
diff changeset
775 panel = HorizontalPanel()
2d6bd975a72d browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents: 276
diff changeset
776 panel.add(self.presence_button)
2d6bd975a72d browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents: 276
diff changeset
777 panel.add(self.status_panel)
2d6bd975a72d browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents: 276
diff changeset
778 panel.setStyleName("marginAuto")
2d6bd975a72d browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents: 276
diff changeset
779 self.add(panel)
2d6bd975a72d browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents: 276
diff changeset
780
2d6bd975a72d browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents: 276
diff changeset
781 ClickHandler.__init__(self)
2d6bd975a72d browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents: 276
diff changeset
782 self.addClickListener(self)
2d6bd975a72d browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents: 276
diff changeset
783
2d6bd975a72d browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents: 276
diff changeset
784 def getPresence(self):
2d6bd975a72d browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents: 276
diff changeset
785 return self.presence
2d6bd975a72d browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents: 276
diff changeset
786
2d6bd975a72d browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents: 276
diff changeset
787 def setPresence(self, presence):
2d6bd975a72d browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents: 276
diff changeset
788 status = self.status_panel.status
2d6bd975a72d browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents: 276
diff changeset
789 if not status.strip() or status == "&nbsp;" or status == const.PRESENCE[self.presence]:
2d6bd975a72d browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents: 276
diff changeset
790 self.changeStatus(const.PRESENCE[presence])
2d6bd975a72d browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents: 276
diff changeset
791 self.presence = presence
2d6bd975a72d browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents: 276
diff changeset
792 setPresenceStyle(self.presence_button, self.presence)
2d6bd975a72d browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents: 276
diff changeset
793
2d6bd975a72d browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents: 276
diff changeset
794 def changeStatus(self, new_status):
2d6bd975a72d browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents: 276
diff changeset
795 self.status_panel.changeStatus(new_status)
2d6bd975a72d browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents: 276
diff changeset
796
62
12e889a683ce server side: misc stuff:
Goffi <goffi@goffi.org>
parents: 58
diff changeset
797 def onClick(self, sender):
226
744426c2b699 browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 223
diff changeset
798 # As status is the default target of uniBar, we don't want to select anything if click on it
192
cf5c83e7d515 browser side: per tab selected widget management
Goffi <goffi@goffi.org>
parents: 191
diff changeset
799 self.host.setSelected(None)
20
8f4b1a8914c3 - User status is now updated
Goffi <goffi@goffi.org>
parents: 19
diff changeset
800
210
3092f6b1710c browser side: make the OK button title for group selector configureable + few "cosmetic" changes (PEP 8...)
souliane <souliane@mailoo.org>
parents: 206
diff changeset
801
19
e8e3704eb97f Added basic chat panel
Goffi <goffi@goffi.org>
parents: 18
diff changeset
802 class ChatText(HTMLPanel):
e8e3704eb97f Added basic chat panel
Goffi <goffi@goffi.org>
parents: 18
diff changeset
803
235
b304cdf13a3b browser and server side: XHTML handling, first draft:
Goffi <goffi@goffi.org>
parents: 232
diff changeset
804 def __init__(self, timestamp, nick, mymess, msg, xhtml = None):
19
e8e3704eb97f Added basic chat panel
Goffi <goffi@goffi.org>
parents: 18
diff changeset
805 _date = datetime.fromtimestamp(float(timestamp or time()))
e8e3704eb97f Added basic chat panel
Goffi <goffi@goffi.org>
parents: 18
diff changeset
806 _msg_class = ["chat_text_msg"]
e8e3704eb97f Added basic chat panel
Goffi <goffi@goffi.org>
parents: 18
diff changeset
807 if mymess:
e8e3704eb97f Added basic chat panel
Goffi <goffi@goffi.org>
parents: 18
diff changeset
808 _msg_class.append("chat_text_mymess")
e8e3704eb97f Added basic chat panel
Goffi <goffi@goffi.org>
parents: 18
diff changeset
809 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>" %
210
3092f6b1710c browser side: make the OK button title for group selector configureable + few "cosmetic" changes (PEP 8...)
souliane <souliane@mailoo.org>
parents: 206
diff changeset
810 {"timestamp": _date.strftime("%H:%M"),
3092f6b1710c browser side: make the OK button title for group selector configureable + few "cosmetic" changes (PEP 8...)
souliane <souliane@mailoo.org>
parents: 206
diff changeset
811 "nick": "[%s]" % html_sanitize(nick),
3092f6b1710c browser side: make the OK button title for group selector configureable + few "cosmetic" changes (PEP 8...)
souliane <souliane@mailoo.org>
parents: 206
diff changeset
812 "msg_class": ' '.join(_msg_class),
246
d7c41c84d062 browser side: use of inlineRoot to display XHTML chat text
Goffi <goffi@goffi.org>
parents: 242
diff changeset
813 "msg": addURLToText(html_sanitize(msg)) if not xhtml else inlineRoot(xhtml)} #FIXME: images and external links must be removed according to preferences
210
3092f6b1710c browser side: make the OK button title for group selector configureable + few "cosmetic" changes (PEP 8...)
souliane <souliane@mailoo.org>
parents: 206
diff changeset
814 )
19
e8e3704eb97f Added basic chat panel
Goffi <goffi@goffi.org>
parents: 18
diff changeset
815 self.setStyleName('chatText')
33
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
816
210
3092f6b1710c browser side: make the OK button title for group selector configureable + few "cosmetic" changes (PEP 8...)
souliane <souliane@mailoo.org>
parents: 206
diff changeset
817
33
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
818 class Occupant(HTML):
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
819 """Occupant of a MUC room"""
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
820
273
11718798ab8a browser_side: can identify muc members with symbols
souliane <souliane@mailoo.org>
parents: 269
diff changeset
821 def __init__(self, nick, special=""):
11718798ab8a browser_side: can identify muc members with symbols
souliane <souliane@mailoo.org>
parents: 269
diff changeset
822 HTML.__init__(self)
33
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
823 self.nick = nick
273
11718798ab8a browser_side: can identify muc members with symbols
souliane <souliane@mailoo.org>
parents: 269
diff changeset
824 self.special = special
11718798ab8a browser_side: can identify muc members with symbols
souliane <souliane@mailoo.org>
parents: 269
diff changeset
825 self._refresh()
35
d43d6e4b9dc8 room user joining/leaving
Goffi <goffi@goffi.org>
parents: 34
diff changeset
826
d43d6e4b9dc8 room user joining/leaving
Goffi <goffi@goffi.org>
parents: 34
diff changeset
827 def __str__(self):
181
c0b78a3af06d browser side: web widget first draft
Goffi <goffi@goffi.org>
parents: 179
diff changeset
828 return self.nick
33
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
829
273
11718798ab8a browser_side: can identify muc members with symbols
souliane <souliane@mailoo.org>
parents: 269
diff changeset
830 def addSpecial(self, special=""):
11718798ab8a browser_side: can identify muc members with symbols
souliane <souliane@mailoo.org>
parents: 269
diff changeset
831 if special not in self.special:
11718798ab8a browser_side: can identify muc members with symbols
souliane <souliane@mailoo.org>
parents: 269
diff changeset
832 self.special += special
11718798ab8a browser_side: can identify muc members with symbols
souliane <souliane@mailoo.org>
parents: 269
diff changeset
833 self._refresh()
11718798ab8a browser_side: can identify muc members with symbols
souliane <souliane@mailoo.org>
parents: 269
diff changeset
834
11718798ab8a browser_side: can identify muc members with symbols
souliane <souliane@mailoo.org>
parents: 269
diff changeset
835 def _refresh(self):
11718798ab8a browser_side: can identify muc members with symbols
souliane <souliane@mailoo.org>
parents: 269
diff changeset
836 special = "" if len(self.special) == 0 else " %s" % self.special
11718798ab8a browser_side: can identify muc members with symbols
souliane <souliane@mailoo.org>
parents: 269
diff changeset
837 self.setHTML("<div class='occupant'>%s%s</div>" % (html_sanitize(self.nick), special))
11718798ab8a browser_side: can identify muc members with symbols
souliane <souliane@mailoo.org>
parents: 269
diff changeset
838
210
3092f6b1710c browser side: make the OK button title for group selector configureable + few "cosmetic" changes (PEP 8...)
souliane <souliane@mailoo.org>
parents: 206
diff changeset
839
33
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
840 class OccupantsList(AbsolutePanel):
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
841 """Panel user to show occupants of a room"""
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
842
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
843 def __init__(self):
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
844 AbsolutePanel.__init__(self)
35
d43d6e4b9dc8 room user joining/leaving
Goffi <goffi@goffi.org>
parents: 34
diff changeset
845 self.occupants_list = {}
33
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
846 self.setStyleName('occupantsList')
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
847
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
848 def addOccupant(self, nick):
35
d43d6e4b9dc8 room user joining/leaving
Goffi <goffi@goffi.org>
parents: 34
diff changeset
849 _occupant = Occupant(nick)
d43d6e4b9dc8 room user joining/leaving
Goffi <goffi@goffi.org>
parents: 34
diff changeset
850 self.occupants_list[nick] = _occupant
d43d6e4b9dc8 room user joining/leaving
Goffi <goffi@goffi.org>
parents: 34
diff changeset
851 self.add(_occupant)
33
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
852
35
d43d6e4b9dc8 room user joining/leaving
Goffi <goffi@goffi.org>
parents: 34
diff changeset
853 def removeOccupant(self, nick):
d43d6e4b9dc8 room user joining/leaving
Goffi <goffi@goffi.org>
parents: 34
diff changeset
854 try:
d43d6e4b9dc8 room user joining/leaving
Goffi <goffi@goffi.org>
parents: 34
diff changeset
855 self.remove(self.occupants_list[nick])
d43d6e4b9dc8 room user joining/leaving
Goffi <goffi@goffi.org>
parents: 34
diff changeset
856 except KeyError:
d43d6e4b9dc8 room user joining/leaving
Goffi <goffi@goffi.org>
parents: 34
diff changeset
857 print "ERROR: trying to remove an unexisting nick"
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
858
35
d43d6e4b9dc8 room user joining/leaving
Goffi <goffi@goffi.org>
parents: 34
diff changeset
859 def clear(self):
d43d6e4b9dc8 room user joining/leaving
Goffi <goffi@goffi.org>
parents: 34
diff changeset
860 self.occupants_list.clear()
d43d6e4b9dc8 room user joining/leaving
Goffi <goffi@goffi.org>
parents: 34
diff changeset
861 AbsolutePanel.clear(self)
d43d6e4b9dc8 room user joining/leaving
Goffi <goffi@goffi.org>
parents: 34
diff changeset
862
273
11718798ab8a browser_side: can identify muc members with symbols
souliane <souliane@mailoo.org>
parents: 269
diff changeset
863 def addSpecials(self, occupants=[], html=""):
11718798ab8a browser_side: can identify muc members with symbols
souliane <souliane@mailoo.org>
parents: 269
diff changeset
864 index = 0
11718798ab8a browser_side: can identify muc members with symbols
souliane <souliane@mailoo.org>
parents: 269
diff changeset
865 special = html
11718798ab8a browser_side: can identify muc members with symbols
souliane <souliane@mailoo.org>
parents: 269
diff changeset
866 for occupant in occupants:
11718798ab8a browser_side: can identify muc members with symbols
souliane <souliane@mailoo.org>
parents: 269
diff changeset
867 if occupant in self.occupants_list.keys():
11718798ab8a browser_side: can identify muc members with symbols
souliane <souliane@mailoo.org>
parents: 269
diff changeset
868 if isinstance(html, list):
11718798ab8a browser_side: can identify muc members with symbols
souliane <souliane@mailoo.org>
parents: 269
diff changeset
869 special = html[index]
11718798ab8a browser_side: can identify muc members with symbols
souliane <souliane@mailoo.org>
parents: 269
diff changeset
870 index = (index + 1) % len(html)
11718798ab8a browser_side: can identify muc members with symbols
souliane <souliane@mailoo.org>
parents: 269
diff changeset
871 self.occupants_list[occupant].addSpecial(special)
11718798ab8a browser_side: can identify muc members with symbols
souliane <souliane@mailoo.org>
parents: 269
diff changeset
872
210
3092f6b1710c browser side: make the OK button title for group selector configureable + few "cosmetic" changes (PEP 8...)
souliane <souliane@mailoo.org>
parents: 206
diff changeset
873
195
dd27072d8ae0 browser side: widgets refactoring:
Goffi <goffi@goffi.org>
parents: 194
diff changeset
874 class ChatPanel(base_widget.LiberviaWidget):
18
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
875
179
8475a29d7214 closing a group chat widget now leave the muc room (bug 11)
Goffi <goffi@goffi.org>
parents: 178
diff changeset
876 def __init__(self, host, target, type_='one2one'):
19
e8e3704eb97f Added basic chat panel
Goffi <goffi@goffi.org>
parents: 18
diff changeset
877 """Panel used for conversation (one 2 one or group chat)
e8e3704eb97f Added basic chat panel
Goffi <goffi@goffi.org>
parents: 18
diff changeset
878 @param host: SatWebFrontend instance
e8e3704eb97f Added basic chat panel
Goffi <goffi@goffi.org>
parents: 18
diff changeset
879 @param target: entity (JID) with who we have a conversation (contact's jid for one 2 one chat, or MUC room)
e8e3704eb97f Added basic chat panel
Goffi <goffi@goffi.org>
parents: 18
diff changeset
880 @param type: one2one for simple conversation, group for MUC"""
210
3092f6b1710c browser side: make the OK button title for group selector configureable + few "cosmetic" changes (PEP 8...)
souliane <souliane@mailoo.org>
parents: 206
diff changeset
881 base_widget.LiberviaWidget.__init__(self, host, target.bare, selectable=True)
34
ed935f763cc8 browser side: misc css/layout fixes
Goffi <goffi@goffi.org>
parents: 33
diff changeset
882 self.vpanel = VerticalPanel()
210
3092f6b1710c browser side: make the OK button title for group selector configureable + few "cosmetic" changes (PEP 8...)
souliane <souliane@mailoo.org>
parents: 206
diff changeset
883 self.vpanel.setSize('100%', '100%')
179
8475a29d7214 closing a group chat widget now leave the muc room (bug 11)
Goffi <goffi@goffi.org>
parents: 178
diff changeset
884 self.type = type_
33
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
885 self.nick = None
19
e8e3704eb97f Added basic chat panel
Goffi <goffi@goffi.org>
parents: 18
diff changeset
886 if not target:
e8e3704eb97f Added basic chat panel
Goffi <goffi@goffi.org>
parents: 18
diff changeset
887 print "ERROR: Empty target !"
e8e3704eb97f Added basic chat panel
Goffi <goffi@goffi.org>
parents: 18
diff changeset
888 return
e8e3704eb97f Added basic chat panel
Goffi <goffi@goffi.org>
parents: 18
diff changeset
889 self.target = target
84
8f35e9970e7f browser side: new widget handling:
Goffi <goffi@goffi.org>
parents: 83
diff changeset
890 self.__body = AbsolutePanel()
8f35e9970e7f browser side: new widget handling:
Goffi <goffi@goffi.org>
parents: 83
diff changeset
891 self.__body.setStyleName('chatPanel_body')
33
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
892 chat_area = HorizontalPanel()
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
893 chat_area.setStyleName('chatArea')
179
8475a29d7214 closing a group chat widget now leave the muc room (bug 11)
Goffi <goffi@goffi.org>
parents: 178
diff changeset
894 if type_ == 'group':
33
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
895 self.occupants_list = OccupantsList()
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
896 chat_area.add(self.occupants_list)
84
8f35e9970e7f browser side: new widget handling:
Goffi <goffi@goffi.org>
parents: 83
diff changeset
897 self.__body.add(chat_area)
33
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
898 self.content = AbsolutePanel()
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
899 self.content.setStyleName('chatContent')
195
dd27072d8ae0 browser side: widgets refactoring:
Goffi <goffi@goffi.org>
parents: 194
diff changeset
900 self.content_scroll = base_widget.ScrollPanelWrapper(self.content)
34
ed935f763cc8 browser side: misc css/layout fixes
Goffi <goffi@goffi.org>
parents: 33
diff changeset
901 chat_area.add(self.content_scroll)
ed935f763cc8 browser side: misc css/layout fixes
Goffi <goffi@goffi.org>
parents: 33
diff changeset
902 chat_area.setCellWidth(self.content_scroll, '100%')
84
8f35e9970e7f browser side: new widget handling:
Goffi <goffi@goffi.org>
parents: 83
diff changeset
903 self.vpanel.add(self.__body)
8f35e9970e7f browser side: new widget handling:
Goffi <goffi@goffi.org>
parents: 83
diff changeset
904 self.addStyleName('chatPanel')
34
ed935f763cc8 browser side: misc css/layout fixes
Goffi <goffi@goffi.org>
parents: 33
diff changeset
905 self.setWidget(self.vpanel)
223
624a87377412 browser_side, plugin XEP-0085: limit the number of bridge methods calls for "chatStateComposing".
souliane <souliane@mailoo.org>
parents: 218
diff changeset
906 self.state_machine = ChatStateMachine(self.host, str(self.target))
19
e8e3704eb97f Added basic chat panel
Goffi <goffi@goffi.org>
parents: 18
diff changeset
907
84
8f35e9970e7f browser side: new widget handling:
Goffi <goffi@goffi.org>
parents: 83
diff changeset
908 """def doDetachChildren(self):
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
909 #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
910 #for the same reason as doAttachChildren
195
dd27072d8ae0 browser side: widgets refactoring:
Goffi <goffi@goffi.org>
parents: 194
diff changeset
911 base_widget.ScrollPanelWrapper.doDetachChildren(self)
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
912
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
913 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
914 #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
915 #the event will not propagate to children
195
dd27072d8ae0 browser side: widgets refactoring:
Goffi <goffi@goffi.org>
parents: 194
diff changeset
916 base_widget.ScrollPanelWrapper.doAttachChildren(self)"""
dd27072d8ae0 browser side: widgets refactoring:
Goffi <goffi@goffi.org>
parents: 194
diff changeset
917
dd27072d8ae0 browser side: widgets refactoring:
Goffi <goffi@goffi.org>
parents: 194
diff changeset
918 @classmethod
dd27072d8ae0 browser side: widgets refactoring:
Goffi <goffi@goffi.org>
parents: 194
diff changeset
919 def registerClass(cls):
230
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
920 base_widget.LiberviaWidget.addDropKey("CONTACT", cls.createPanel)
195
dd27072d8ae0 browser side: widgets refactoring:
Goffi <goffi@goffi.org>
parents: 194
diff changeset
921
dd27072d8ae0 browser side: widgets refactoring:
Goffi <goffi@goffi.org>
parents: 194
diff changeset
922 @classmethod
230
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
923 def createPanel(cls, host, item):
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
924 _contact = item if isinstance(item, JID) else JID(item)
195
dd27072d8ae0 browser side: widgets refactoring:
Goffi <goffi@goffi.org>
parents: 194
diff changeset
925 host.contact_panel.setContactMessageWaiting(_contact.bare, False)
226
744426c2b699 browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 223
diff changeset
926 _new_panel = ChatPanel(host, _contact) # XXX: pyjamas doesn't seems to support creating with cls directly
195
dd27072d8ae0 browser side: widgets refactoring:
Goffi <goffi@goffi.org>
parents: 194
diff changeset
927 _new_panel.historyPrint()
230
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
928 host.setSelected(_new_panel)
195
dd27072d8ae0 browser side: widgets refactoring:
Goffi <goffi@goffi.org>
parents: 194
diff changeset
929 return _new_panel
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
930
230
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
931 def refresh(self):
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
932 """Refresh the display of this widget."""
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
933 self.host.contact_panel.setContactMessageWaiting(self.target.bare, False)
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
934 self.content_scroll.scrollToBottom()
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
935
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
936 def matchEntity(self, entity):
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
937 """
267
a76243c02074 browser_side: changes regarding widgets and tabs:
souliane <souliane@mailoo.org>
parents: 264
diff changeset
938 @param entity: target jid as a string or JID instance.
a76243c02074 browser_side: changes regarding widgets and tabs:
souliane <souliane@mailoo.org>
parents: 264
diff changeset
939 Could also be a couple with a type in the second element.
230
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
940 @return: True if self matches the given entity
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
941 """
267
a76243c02074 browser_side: changes regarding widgets and tabs:
souliane <souliane@mailoo.org>
parents: 264
diff changeset
942 if isinstance(entity, tuple):
a76243c02074 browser_side: changes regarding widgets and tabs:
souliane <souliane@mailoo.org>
parents: 264
diff changeset
943 entity, type_ = entity if len(entity) > 1 else (entity[0], self.type)
a76243c02074 browser_side: changes regarding widgets and tabs:
souliane <souliane@mailoo.org>
parents: 264
diff changeset
944 else:
a76243c02074 browser_side: changes regarding widgets and tabs:
souliane <souliane@mailoo.org>
parents: 264
diff changeset
945 type_ = self.type
230
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
946 entity = entity if isinstance(entity, JID) else JID(entity)
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
947 try:
267
a76243c02074 browser_side: changes regarding widgets and tabs:
souliane <souliane@mailoo.org>
parents: 264
diff changeset
948 return self.target.bare == entity.bare and self.type == type_
230
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
949 except AttributeError as e:
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
950 e.include_traceback()
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
951 return False
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
952
201
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
953 def getWarningData(self):
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
954 if self.type not in ["one2one", "group"]:
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
955 raise Exception("Unmanaged type !")
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
956 if self.type == "one2one":
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
957 msg = "This message will be sent to your contact <span class='warningTarget'>%s</span>" % self.target
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
958 elif self.type == "group":
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
959 msg = "This message will be sent to all the participants of the multi-user room <span class='warningTarget'>%s</span>" % self.target
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
960 return ("ONE2ONE" if self.type == "one2one" else "GROUP", msg)
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
961
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
962 def onTextEntered(self, text):
269
9eb9c7d41bdc browser_side: added generic method "send" in SatWebFrontend
souliane <souliane@mailoo.org>
parents: 267
diff changeset
963 self.host.send([("groupchat" if self.type == 'group' else "chat", str(self.target))], text)
223
624a87377412 browser_side, plugin XEP-0085: limit the number of bridge methods calls for "chatStateComposing".
souliane <souliane@mailoo.org>
parents: 218
diff changeset
964 self.state_machine._onEvent("active")
201
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
965
179
8475a29d7214 closing a group chat widget now leave the muc room (bug 11)
Goffi <goffi@goffi.org>
parents: 178
diff changeset
966 def onQuit(self):
195
dd27072d8ae0 browser side: widgets refactoring:
Goffi <goffi@goffi.org>
parents: 194
diff changeset
967 base_widget.LiberviaWidget.onQuit(self)
179
8475a29d7214 closing a group chat widget now leave the muc room (bug 11)
Goffi <goffi@goffi.org>
parents: 178
diff changeset
968 if self.type == 'group':
8475a29d7214 closing a group chat widget now leave the muc room (bug 11)
Goffi <goffi@goffi.org>
parents: 178
diff changeset
969 self.host.bridge.call('mucLeave', None, self.target.bare)
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
970
19
e8e3704eb97f Added basic chat panel
Goffi <goffi@goffi.org>
parents: 18
diff changeset
971 def setUserNick(self, nick):
e8e3704eb97f Added basic chat panel
Goffi <goffi@goffi.org>
parents: 18
diff changeset
972 """Set the nick of the user, usefull for e.g. change the color of the user"""
e8e3704eb97f Added basic chat panel
Goffi <goffi@goffi.org>
parents: 18
diff changeset
973 self.nick = nick
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
974
33
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
975 def setPresents(self, nicks):
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
976 """Set the users presents in this room
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
977 @param occupants: list of nicks (string)"""
35
d43d6e4b9dc8 room user joining/leaving
Goffi <goffi@goffi.org>
parents: 34
diff changeset
978 self.occupants_list.clear()
33
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
979 for nick in nicks:
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
980 self.occupants_list.addOccupant(nick)
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
981
35
d43d6e4b9dc8 room user joining/leaving
Goffi <goffi@goffi.org>
parents: 34
diff changeset
982 def userJoined(self, nick, data):
d43d6e4b9dc8 room user joining/leaving
Goffi <goffi@goffi.org>
parents: 34
diff changeset
983 self.occupants_list.addOccupant(nick)
d43d6e4b9dc8 room user joining/leaving
Goffi <goffi@goffi.org>
parents: 34
diff changeset
984 self.printInfo("=> %s has joined the room" % nick)
d43d6e4b9dc8 room user joining/leaving
Goffi <goffi@goffi.org>
parents: 34
diff changeset
985
d43d6e4b9dc8 room user joining/leaving
Goffi <goffi@goffi.org>
parents: 34
diff changeset
986 def userLeft(self, nick, data):
d43d6e4b9dc8 room user joining/leaving
Goffi <goffi@goffi.org>
parents: 34
diff changeset
987 self.occupants_list.removeOccupant(nick)
d43d6e4b9dc8 room user joining/leaving
Goffi <goffi@goffi.org>
parents: 34
diff changeset
988 self.printInfo("<= %s has left the room" % nick)
d43d6e4b9dc8 room user joining/leaving
Goffi <goffi@goffi.org>
parents: 34
diff changeset
989
19
e8e3704eb97f Added basic chat panel
Goffi <goffi@goffi.org>
parents: 18
diff changeset
990 def historyPrint(self, size=20):
e8e3704eb97f Added basic chat panel
Goffi <goffi@goffi.org>
parents: 18
diff changeset
991 """Print the initial history"""
e8e3704eb97f Added basic chat panel
Goffi <goffi@goffi.org>
parents: 18
diff changeset
992 def getHistoryCB(history):
213
8bbac49765d6 browser side: display the day change in chat window
souliane <souliane@mailoo.org>
parents: 210
diff changeset
993 # display day change
8bbac49765d6 browser side: display the day change in chat window
souliane <souliane@mailoo.org>
parents: 210
diff changeset
994 day_format = "%A, %d %b %Y"
8bbac49765d6 browser side: display the day change in chat window
souliane <souliane@mailoo.org>
parents: 210
diff changeset
995 previous_day = datetime.now().strftime(day_format)
123
5cb852d9757e use of async history
Goffi <goffi@goffi.org>
parents: 120
diff changeset
996 for line in history:
235
b304cdf13a3b browser and server side: XHTML handling, first draft:
Goffi <goffi@goffi.org>
parents: 232
diff changeset
997 timestamp, from_jid, to_jid, message, mess_type, extra = line
213
8bbac49765d6 browser side: display the day change in chat window
souliane <souliane@mailoo.org>
parents: 210
diff changeset
998 message_day = datetime.fromtimestamp(float(timestamp or time())).strftime(day_format)
8bbac49765d6 browser side: display the day change in chat window
souliane <souliane@mailoo.org>
parents: 210
diff changeset
999 if previous_day != message_day:
8bbac49765d6 browser side: display the day change in chat window
souliane <souliane@mailoo.org>
parents: 210
diff changeset
1000 self.printInfo("* " + message_day)
8bbac49765d6 browser side: display the day change in chat window
souliane <souliane@mailoo.org>
parents: 210
diff changeset
1001 previous_day = message_day
235
b304cdf13a3b browser and server side: XHTML handling, first draft:
Goffi <goffi@goffi.org>
parents: 232
diff changeset
1002 self.printMessage(from_jid, message, extra, timestamp)
123
5cb852d9757e use of async history
Goffi <goffi@goffi.org>
parents: 120
diff changeset
1003 self.host.bridge.call('getHistory', getHistoryCB, self.host.whoami.bare, self.target.bare, size, True)
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
1004
35
d43d6e4b9dc8 room user joining/leaving
Goffi <goffi@goffi.org>
parents: 34
diff changeset
1005 def printInfo(self, msg, type='normal'):
d43d6e4b9dc8 room user joining/leaving
Goffi <goffi@goffi.org>
parents: 34
diff changeset
1006 """Print general info
d43d6e4b9dc8 room user joining/leaving
Goffi <goffi@goffi.org>
parents: 34
diff changeset
1007 @param msg: message to print
d43d6e4b9dc8 room user joining/leaving
Goffi <goffi@goffi.org>
parents: 34
diff changeset
1008 @type: one of:
d43d6e4b9dc8 room user joining/leaving
Goffi <goffi@goffi.org>
parents: 34
diff changeset
1009 normal: general info like "toto has joined the room"
d43d6e4b9dc8 room user joining/leaving
Goffi <goffi@goffi.org>
parents: 34
diff changeset
1010 me: "/me" information like "/me clenches his fist" ==> "toto clenches his fist"
d43d6e4b9dc8 room user joining/leaving
Goffi <goffi@goffi.org>
parents: 34
diff changeset
1011 """
54
f25c4077f6b9 addind contact + subscription management + misc
Goffi <goffi@goffi.org>
parents: 52
diff changeset
1012 _wid = Label(msg)
35
d43d6e4b9dc8 room user joining/leaving
Goffi <goffi@goffi.org>
parents: 34
diff changeset
1013 if type == 'normal':
d43d6e4b9dc8 room user joining/leaving
Goffi <goffi@goffi.org>
parents: 34
diff changeset
1014 _wid.setStyleName('chatTextInfo')
d43d6e4b9dc8 room user joining/leaving
Goffi <goffi@goffi.org>
parents: 34
diff changeset
1015 elif type == 'me':
d43d6e4b9dc8 room user joining/leaving
Goffi <goffi@goffi.org>
parents: 34
diff changeset
1016 _wid.setStyleName('chatTextMe')
d43d6e4b9dc8 room user joining/leaving
Goffi <goffi@goffi.org>
parents: 34
diff changeset
1017 else:
d43d6e4b9dc8 room user joining/leaving
Goffi <goffi@goffi.org>
parents: 34
diff changeset
1018 _wid.setStyleName('chatTextInfo')
d43d6e4b9dc8 room user joining/leaving
Goffi <goffi@goffi.org>
parents: 34
diff changeset
1019 self.content.add(_wid)
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
1020
235
b304cdf13a3b browser and server side: XHTML handling, first draft:
Goffi <goffi@goffi.org>
parents: 232
diff changeset
1021 def printMessage(self, from_jid, msg, extra, timestamp=None):
19
e8e3704eb97f Added basic chat panel
Goffi <goffi@goffi.org>
parents: 18
diff changeset
1022 """Print message in chat window. Must be implemented by child class"""
210
3092f6b1710c browser side: make the OK button title for group selector configureable + few "cosmetic" changes (PEP 8...)
souliane <souliane@mailoo.org>
parents: 206
diff changeset
1023 _jid = JID(from_jid)
3092f6b1710c browser side: make the OK button title for group selector configureable + few "cosmetic" changes (PEP 8...)
souliane <souliane@mailoo.org>
parents: 206
diff changeset
1024 nick = _jid.node if self.type == 'one2one' else _jid.resource
226
744426c2b699 browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 223
diff changeset
1025 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
d43d6e4b9dc8 room user joining/leaving
Goffi <goffi@goffi.org>
parents: 34
diff changeset
1026 if msg.startswith('/me '):
210
3092f6b1710c browser side: make the OK button title for group selector configureable + few "cosmetic" changes (PEP 8...)
souliane <souliane@mailoo.org>
parents: 206
diff changeset
1027 self.printInfo('* %s %s' % (nick, msg[4:]), type='me')
35
d43d6e4b9dc8 room user joining/leaving
Goffi <goffi@goffi.org>
parents: 34
diff changeset
1028 return
235
b304cdf13a3b browser and server side: XHTML handling, first draft:
Goffi <goffi@goffi.org>
parents: 232
diff changeset
1029 self.content.add(ChatText(timestamp, nick, mymess, msg, extra.get('xhtml')))
34
ed935f763cc8 browser side: misc css/layout fixes
Goffi <goffi@goffi.org>
parents: 33
diff changeset
1030 self.content_scroll.scrollToBottom()
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
1031
285
4f0c2fea358a browser_side (plugin radiocol): use the status label to give more information
souliane <souliane@mailoo.org>
parents: 282
diff changeset
1032 def startGame(self, game_type, waiting, referee, players, *args):
36
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents: 35
diff changeset
1033 """Configure the chat window to start a game"""
275
a763b2ac5d41 bridge + browser_side: bridge signals for games and their callbacks:
souliane <souliane@mailoo.org>
parents: 273
diff changeset
1034 classes = {"Tarot": CardPanel, "RadioCol": RadioColPanel}
a763b2ac5d41 bridge + browser_side: bridge signals for games and their callbacks:
souliane <souliane@mailoo.org>
parents: 273
diff changeset
1035 if game_type not in classes.keys():
a763b2ac5d41 bridge + browser_side: bridge signals for games and their callbacks:
souliane <souliane@mailoo.org>
parents: 273
diff changeset
1036 return # unknown game
a763b2ac5d41 bridge + browser_side: bridge signals for games and their callbacks:
souliane <souliane@mailoo.org>
parents: 273
diff changeset
1037 attr = game_type.lower()
a763b2ac5d41 bridge + browser_side: bridge signals for games and their callbacks:
souliane <souliane@mailoo.org>
parents: 273
diff changeset
1038 self.occupants_list.addSpecials(players, SYMBOLS[attr])
a763b2ac5d41 bridge + browser_side: bridge signals for games and their callbacks:
souliane <souliane@mailoo.org>
parents: 273
diff changeset
1039 if waiting or not self.nick in players:
a763b2ac5d41 bridge + browser_side: bridge signals for games and their callbacks:
souliane <souliane@mailoo.org>
parents: 273
diff changeset
1040 return # waiting for player or not playing
a763b2ac5d41 bridge + browser_side: bridge signals for games and their callbacks:
souliane <souliane@mailoo.org>
parents: 273
diff changeset
1041 attr = "%s_panel" % attr
a763b2ac5d41 bridge + browser_side: bridge signals for games and their callbacks:
souliane <souliane@mailoo.org>
parents: 273
diff changeset
1042 if hasattr(self, attr):
a763b2ac5d41 bridge + browser_side: bridge signals for games and their callbacks:
souliane <souliane@mailoo.org>
parents: 273
diff changeset
1043 return
a763b2ac5d41 bridge + browser_side: bridge signals for games and their callbacks:
souliane <souliane@mailoo.org>
parents: 273
diff changeset
1044 print ("%s Game Started \o/" % game_type)
285
4f0c2fea358a browser_side (plugin radiocol): use the status label to give more information
souliane <souliane@mailoo.org>
parents: 282
diff changeset
1045 panel = classes[game_type](self, referee, self.nick, players, *args)
275
a763b2ac5d41 bridge + browser_side: bridge signals for games and their callbacks:
souliane <souliane@mailoo.org>
parents: 273
diff changeset
1046 setattr(self, attr, panel)
a763b2ac5d41 bridge + browser_side: bridge signals for games and their callbacks:
souliane <souliane@mailoo.org>
parents: 273
diff changeset
1047 self.vpanel.insert(panel, 0)
a763b2ac5d41 bridge + browser_side: bridge signals for games and their callbacks:
souliane <souliane@mailoo.org>
parents: 273
diff changeset
1048 self.vpanel.setCellHeight(panel, panel.getHeight())
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
1049
37
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
1050 def getGame(self, game_type):
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
1051 """Return class managing the game type"""
226
744426c2b699 browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 223
diff changeset
1052 # TODO: check that the game is launched, and manage errors
210
3092f6b1710c browser side: make the OK button title for group selector configureable + few "cosmetic" changes (PEP 8...)
souliane <souliane@mailoo.org>
parents: 206
diff changeset
1053 if game_type == "Tarot":
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
1054 return self.tarot_panel
210
3092f6b1710c browser side: make the OK button title for group selector configureable + few "cosmetic" changes (PEP 8...)
souliane <souliane@mailoo.org>
parents: 206
diff changeset
1055 elif game_type == "RadioCol":
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
1056 return self.radiocol_panel
18
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
1057
210
3092f6b1710c browser side: make the OK button title for group selector configureable + few "cosmetic" changes (PEP 8...)
souliane <souliane@mailoo.org>
parents: 206
diff changeset
1058
195
dd27072d8ae0 browser side: widgets refactoring:
Goffi <goffi@goffi.org>
parents: 194
diff changeset
1059 class WebPanel(base_widget.LiberviaWidget):
181
c0b78a3af06d browser side: web widget first draft
Goffi <goffi@goffi.org>
parents: 179
diff changeset
1060 """ (mini)browser like widget """
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
1061
181
c0b78a3af06d browser side: web widget first draft
Goffi <goffi@goffi.org>
parents: 179
diff changeset
1062 def __init__(self, host, url=None):
c0b78a3af06d browser side: web widget first draft
Goffi <goffi@goffi.org>
parents: 179
diff changeset
1063 """
c0b78a3af06d browser side: web widget first draft
Goffi <goffi@goffi.org>
parents: 179
diff changeset
1064 @param host: SatWebFrontend instance
c0b78a3af06d browser side: web widget first draft
Goffi <goffi@goffi.org>
parents: 179
diff changeset
1065 """
195
dd27072d8ae0 browser side: widgets refactoring:
Goffi <goffi@goffi.org>
parents: 194
diff changeset
1066 base_widget.LiberviaWidget.__init__(self, host)
181
c0b78a3af06d browser side: web widget first draft
Goffi <goffi@goffi.org>
parents: 179
diff changeset
1067 self._vpanel = VerticalPanel()
188
39936b83da9d Browser Side: Web Panel widget position/size fix
Goffi <goffi@goffi.org>
parents: 187
diff changeset
1068 self._vpanel.setSize('100%', '100%')
210
3092f6b1710c browser side: make the OK button title for group selector configureable + few "cosmetic" changes (PEP 8...)
souliane <souliane@mailoo.org>
parents: 206
diff changeset
1069 self._url = dialog.ExtTextBox(enter_cb=self.onUrlClick)
181
c0b78a3af06d browser side: web widget first draft
Goffi <goffi@goffi.org>
parents: 179
diff changeset
1070 self._url.setText(url or "")
c0b78a3af06d browser side: web widget first draft
Goffi <goffi@goffi.org>
parents: 179
diff changeset
1071 self._url.setWidth('100%')
c0b78a3af06d browser side: web widget first draft
Goffi <goffi@goffi.org>
parents: 179
diff changeset
1072 hpanel = HorizontalPanel()
c0b78a3af06d browser side: web widget first draft
Goffi <goffi@goffi.org>
parents: 179
diff changeset
1073 hpanel.add(self._url)
c0b78a3af06d browser side: web widget first draft
Goffi <goffi@goffi.org>
parents: 179
diff changeset
1074 btn = Button("Go", self.onUrlClick)
c0b78a3af06d browser side: web widget first draft
Goffi <goffi@goffi.org>
parents: 179
diff changeset
1075 hpanel.setCellWidth(self._url, "100%")
c0b78a3af06d browser side: web widget first draft
Goffi <goffi@goffi.org>
parents: 179
diff changeset
1076 #self.setCellWidth(btn, "10%")
c0b78a3af06d browser side: web widget first draft
Goffi <goffi@goffi.org>
parents: 179
diff changeset
1077 hpanel.add(self._url)
c0b78a3af06d browser side: web widget first draft
Goffi <goffi@goffi.org>
parents: 179
diff changeset
1078 hpanel.add(btn)
c0b78a3af06d browser side: web widget first draft
Goffi <goffi@goffi.org>
parents: 179
diff changeset
1079 self._vpanel.add(hpanel)
188
39936b83da9d Browser Side: Web Panel widget position/size fix
Goffi <goffi@goffi.org>
parents: 187
diff changeset
1080 self._vpanel.setCellHeight(hpanel, '20px')
181
c0b78a3af06d browser side: web widget first draft
Goffi <goffi@goffi.org>
parents: 179
diff changeset
1081 self._frame = Frame(url or "")
c0b78a3af06d browser side: web widget first draft
Goffi <goffi@goffi.org>
parents: 179
diff changeset
1082 self._frame.setSize('100%', '100%')
188
39936b83da9d Browser Side: Web Panel widget position/size fix
Goffi <goffi@goffi.org>
parents: 187
diff changeset
1083 DOM.setStyleAttribute(self._frame.getElement(), "position", "relative")
181
c0b78a3af06d browser side: web widget first draft
Goffi <goffi@goffi.org>
parents: 179
diff changeset
1084 self._vpanel.add(self._frame)
c0b78a3af06d browser side: web widget first draft
Goffi <goffi@goffi.org>
parents: 179
diff changeset
1085 self.setWidget(self._vpanel)
c0b78a3af06d browser side: web widget first draft
Goffi <goffi@goffi.org>
parents: 179
diff changeset
1086
c0b78a3af06d browser side: web widget first draft
Goffi <goffi@goffi.org>
parents: 179
diff changeset
1087 def onUrlClick(self, sender):
c0b78a3af06d browser side: web widget first draft
Goffi <goffi@goffi.org>
parents: 179
diff changeset
1088 self._frame.setUrl(self._url.getText())
c0b78a3af06d browser side: web widget first draft
Goffi <goffi@goffi.org>
parents: 179
diff changeset
1089
210
3092f6b1710c browser side: make the OK button title for group selector configureable + few "cosmetic" changes (PEP 8...)
souliane <souliane@mailoo.org>
parents: 206
diff changeset
1090
33
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
1091 class MainPanel(AbsolutePanel):
18
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
1092
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
1093 def __init__(self, host):
210
3092f6b1710c browser side: make the OK button title for group selector configureable + few "cosmetic" changes (PEP 8...)
souliane <souliane@mailoo.org>
parents: 206
diff changeset
1094 self.host = host
33
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
1095 AbsolutePanel.__init__(self)
18
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
1096
226
744426c2b699 browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 223
diff changeset
1097 # menu
218
4e6467efd6bf browser_side: small improvements for parameters panel
souliane <souliane@mailoo.org>
parents: 217
diff changeset
1098 self.menu = Menu(host)
184
97d5e9de1106 browser side: contacts panel switch:
Goffi <goffi@goffi.org>
parents: 181
diff changeset
1099
226
744426c2b699 browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 223
diff changeset
1100 # unibox
33
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
1101 unibox_panel = UniBoxPanel(host)
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
1102 self.host.setUniBox(unibox_panel.unibox)
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
1103
226
744426c2b699 browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 223
diff changeset
1104 # status bar
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
1105 status = host.status_panel
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
1106
226
744426c2b699 browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 223
diff changeset
1107 # contacts
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents: 231
diff changeset
1108 self._contacts = HorizontalPanel()
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents: 231
diff changeset
1109 self._contacts.addStyleName('globalLeftArea')
255
da0487f0a2e7 browser_side: small changes to prepare the contact group manager:
souliane <souliane@mailoo.org>
parents: 249
diff changeset
1110 self.contacts_switch = Button(u'«', self._contactsSwitch)
da0487f0a2e7 browser_side: small changes to prepare the contact group manager:
souliane <souliane@mailoo.org>
parents: 249
diff changeset
1111 self.contacts_switch.addStyleName('contactsSwitch')
da0487f0a2e7 browser_side: small changes to prepare the contact group manager:
souliane <souliane@mailoo.org>
parents: 249
diff changeset
1112 self._contacts.add(self.contacts_switch)
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents: 231
diff changeset
1113 self._contacts.add(self.host.contact_panel)
184
97d5e9de1106 browser side: contacts panel switch:
Goffi <goffi@goffi.org>
parents: 181
diff changeset
1114
226
744426c2b699 browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 223
diff changeset
1115 # tabs
195
dd27072d8ae0 browser side: widgets refactoring:
Goffi <goffi@goffi.org>
parents: 194
diff changeset
1116 self.tab_panel = base_widget.MainTabPanel(host)
dd27072d8ae0 browser side: widgets refactoring:
Goffi <goffi@goffi.org>
parents: 194
diff changeset
1117 self.discuss_panel = base_widget.WidgetsPanel(self.host, locked=True)
23
0ce2a57b34ca added tab panel
Goffi <goffi@goffi.org>
parents: 22
diff changeset
1118 self.tab_panel.add(self.discuss_panel, "Discussions")
0ce2a57b34ca added tab panel
Goffi <goffi@goffi.org>
parents: 22
diff changeset
1119 self.tab_panel.selectTab(0)
18
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
1120
210
3092f6b1710c browser side: make the OK button title for group selector configureable + few "cosmetic" changes (PEP 8...)
souliane <souliane@mailoo.org>
parents: 206
diff changeset
1121 header = AbsolutePanel()
218
4e6467efd6bf browser_side: small improvements for parameters panel
souliane <souliane@mailoo.org>
parents: 217
diff changeset
1122 header.add(self.menu)
109
5c363b638127 browser side: grouped header panel in a global Absolute panel
Goffi <goffi@goffi.org>
parents: 101
diff changeset
1123 header.add(unibox_panel)
5c363b638127 browser side: grouped header panel in a global Absolute panel
Goffi <goffi@goffi.org>
parents: 101
diff changeset
1124 header.add(status)
5c363b638127 browser side: grouped header panel in a global Absolute panel
Goffi <goffi@goffi.org>
parents: 101
diff changeset
1125 header.setStyleName('header')
5c363b638127 browser side: grouped header panel in a global Absolute panel
Goffi <goffi@goffi.org>
parents: 101
diff changeset
1126 self.add(header)
184
97d5e9de1106 browser side: contacts panel switch:
Goffi <goffi@goffi.org>
parents: 181
diff changeset
1127
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents: 231
diff changeset
1128 self._hpanel = HorizontalPanel()
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents: 231
diff changeset
1129 self._hpanel.add(self._contacts)
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents: 231
diff changeset
1130 self._hpanel.add(self.tab_panel)
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents: 231
diff changeset
1131 self.add(self._hpanel)
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
1132
18
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
1133 self.setWidth("100%")
33
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
1134 Window.addWindowResizeListener(self)
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
1135
255
da0487f0a2e7 browser_side: small changes to prepare the contact group manager:
souliane <souliane@mailoo.org>
parents: 249
diff changeset
1136 def _contactsSwitch(self, btn=None):
184
97d5e9de1106 browser side: contacts panel switch:
Goffi <goffi@goffi.org>
parents: 181
diff changeset
1137 """ (Un)hide contacts panel """
255
da0487f0a2e7 browser_side: small changes to prepare the contact group manager:
souliane <souliane@mailoo.org>
parents: 249
diff changeset
1138 if btn is None:
da0487f0a2e7 browser_side: small changes to prepare the contact group manager:
souliane <souliane@mailoo.org>
parents: 249
diff changeset
1139 btn = self.contacts_switch
184
97d5e9de1106 browser side: contacts panel switch:
Goffi <goffi@goffi.org>
parents: 181
diff changeset
1140 cpanel = self.host.contact_panel
97d5e9de1106 browser side: contacts panel switch:
Goffi <goffi@goffi.org>
parents: 181
diff changeset
1141 cpanel.setVisible(not cpanel.getVisible())
206
4d7054542751 browser side: contactBox doesn't use left margin anymore (avoid scrollbar issues) + some cosmetic changes to contact panel switch button
Goffi <goffi@goffi.org>
parents: 202
diff changeset
1142 btn.setText(u"«" if cpanel.getVisible() else u"»")
184
97d5e9de1106 browser side: contacts panel switch:
Goffi <goffi@goffi.org>
parents: 181
diff changeset
1143 self.host.resize()
97d5e9de1106 browser side: contacts panel switch:
Goffi <goffi@goffi.org>
parents: 181
diff changeset
1144
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents: 231
diff changeset
1145 def _contactsMove(self, parent):
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents: 231
diff changeset
1146 """Move the contacts container (containing the contact list and
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents: 231
diff changeset
1147 the "hide/show" button) to another parent, but always as the
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents: 231
diff changeset
1148 first child position (insert at index 0).
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents: 231
diff changeset
1149 """
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents: 231
diff changeset
1150 if self._contacts.getParent():
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents: 231
diff changeset
1151 if self._contacts.getParent() == parent:
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents: 231
diff changeset
1152 return
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents: 231
diff changeset
1153 self._contacts.removeFromParent()
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents: 231
diff changeset
1154 parent.insert(self._contacts, 0)
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents: 231
diff changeset
1155
33
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
1156 def onWindowResized(self, width, height):
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
1157 _elts = doc().getElementsByClassName('gwt-TabBar')
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
1158 if not _elts.length:
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
1159 tab_bar_h = 0
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
1160 else:
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
1161 tab_bar_h = _elts.item(0).offsetHeight
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
1162 ideal_height = Window.getClientHeight() - tab_bar_h
210
3092f6b1710c browser side: make the OK button title for group selector configureable + few "cosmetic" changes (PEP 8...)
souliane <souliane@mailoo.org>
parents: 206
diff changeset
1163 self.setHeight("%s%s" % (ideal_height, "px"))
241
86055ccf69c3 browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents: 239
diff changeset
1164
86055ccf69c3 browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents: 239
diff changeset
1165
86055ccf69c3 browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents: 239
diff changeset
1166 class PopupMenuPanel(PopupPanel):
86055ccf69c3 browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents: 239
diff changeset
1167 """This implementation of a popup menu (context menu) allow you to assign
86055ccf69c3 browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents: 239
diff changeset
1168 two special methods which are common to all the items, in order to hide
86055ccf69c3 browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents: 239
diff changeset
1169 certain items and also easily define their callbacks. The menu can be
86055ccf69c3 browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents: 239
diff changeset
1170 bound to any of the mouse button (left, middle, right).
86055ccf69c3 browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents: 239
diff changeset
1171 """
279
2d6bd975a72d browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents: 276
diff changeset
1172 def __init__(self, entries, hide=None, callback=None, vertical=True, style={}, **kwargs):
241
86055ccf69c3 browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents: 239
diff changeset
1173 """
86055ccf69c3 browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents: 239
diff changeset
1174 @param entries: a dict of dicts, where each sub-dict is representing
86055ccf69c3 browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents: 239
diff changeset
1175 one menu item: the sub-dict key can be used as the item text and
86055ccf69c3 browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents: 239
diff changeset
1176 description, but optional "title" and "desc" entries would be used
86055ccf69c3 browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents: 239
diff changeset
1177 if they exists. The sub-dicts may be extended later to do
86055ccf69c3 browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents: 239
diff changeset
1178 more complicated stuff or overwrite the common methods.
86055ccf69c3 browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents: 239
diff changeset
1179 @param hide: function with 2 args: widget, key as string and
86055ccf69c3 browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents: 239
diff changeset
1180 returns True if that item should be hidden from the context menu.
279
2d6bd975a72d browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents: 276
diff changeset
1181 @param callback: function with 2 args: sender, key as string
241
86055ccf69c3 browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents: 239
diff changeset
1182 @param vertical: True or False, to set the direction
86055ccf69c3 browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents: 239
diff changeset
1183 @param item_style: alternative CSS class for the menu items
86055ccf69c3 browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents: 239
diff changeset
1184 @param menu_style: supplementary CSS class for the sender widget
86055ccf69c3 browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents: 239
diff changeset
1185 """
86055ccf69c3 browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents: 239
diff changeset
1186 PopupPanel.__init__(self, autoHide=True, **kwargs)
86055ccf69c3 browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents: 239
diff changeset
1187 self._entries = entries
86055ccf69c3 browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents: 239
diff changeset
1188 self._hide = hide
86055ccf69c3 browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents: 239
diff changeset
1189 self._callback = callback
86055ccf69c3 browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents: 239
diff changeset
1190 self.vertical = vertical
279
2d6bd975a72d browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents: 276
diff changeset
1191 self.style = {"selected": None, "menu": "recipientTypeMenu", "item": "popupMenuItem"}
2d6bd975a72d browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents: 276
diff changeset
1192 self.style.update(style)
241
86055ccf69c3 browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents: 239
diff changeset
1193 self._senders = {}
86055ccf69c3 browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents: 239
diff changeset
1194
86055ccf69c3 browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents: 239
diff changeset
1195 def _show(self, sender):
86055ccf69c3 browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents: 239
diff changeset
1196 """Popup the menu relative to this sender's position.
86055ccf69c3 browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents: 239
diff changeset
1197 @param sender: the widget that has been clicked
86055ccf69c3 browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents: 239
diff changeset
1198 """
86055ccf69c3 browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents: 239
diff changeset
1199 menu = VerticalPanel() if self.vertical is True else HorizontalPanel()
279
2d6bd975a72d browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents: 276
diff changeset
1200 menu.setStyleName(self.style["menu"])
241
86055ccf69c3 browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents: 239
diff changeset
1201
86055ccf69c3 browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents: 239
diff changeset
1202 def button_cb(item):
86055ccf69c3 browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents: 239
diff changeset
1203 """You can not put that method in the loop and rely
86055ccf69c3 browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents: 239
diff changeset
1204 on _key, because it is overwritten by each step.
86055ccf69c3 browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents: 239
diff changeset
1205 You can rely on item.key instead, which is copied
86055ccf69c3 browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents: 239
diff changeset
1206 from _key after the item creation.
86055ccf69c3 browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents: 239
diff changeset
1207 @param item: the menu item that has been clicked
86055ccf69c3 browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents: 239
diff changeset
1208 """
86055ccf69c3 browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents: 239
diff changeset
1209 if self._callback is not None:
86055ccf69c3 browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents: 239
diff changeset
1210 self._callback(sender=sender, key=item.key)
86055ccf69c3 browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents: 239
diff changeset
1211 self.hide(autoClosed=True)
86055ccf69c3 browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents: 239
diff changeset
1212
86055ccf69c3 browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents: 239
diff changeset
1213 for _key in self._entries.keys():
86055ccf69c3 browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents: 239
diff changeset
1214 entry = self._entries[_key]
86055ccf69c3 browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents: 239
diff changeset
1215 if self._hide is not None and self._hide(sender=sender, key=_key) is True:
86055ccf69c3 browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents: 239
diff changeset
1216 continue
86055ccf69c3 browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents: 239
diff changeset
1217 title = entry["title"] if "title" in entry.keys() else _key
86055ccf69c3 browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents: 239
diff changeset
1218 item = Button(title, button_cb)
86055ccf69c3 browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents: 239
diff changeset
1219 item.key = _key
279
2d6bd975a72d browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents: 276
diff changeset
1220 item.setStyleName(self.style["item"])
241
86055ccf69c3 browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents: 239
diff changeset
1221 item.setTitle(entry["desc"] if "desc" in entry.keys() else title)
86055ccf69c3 browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents: 239
diff changeset
1222 menu.add(item)
242
a25aa882e09a browser_side: add context menu for contact:
souliane <souliane@mailoo.org>
parents: 241
diff changeset
1223 if len(menu.getChildren()) == 0:
a25aa882e09a browser_side: add context menu for contact:
souliane <souliane@mailoo.org>
parents: 241
diff changeset
1224 return
241
86055ccf69c3 browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents: 239
diff changeset
1225 self.add(menu)
86055ccf69c3 browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents: 239
diff changeset
1226 if self.vertical is True:
86055ccf69c3 browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents: 239
diff changeset
1227 x = sender.getAbsoluteLeft() + sender.getOffsetWidth()
86055ccf69c3 browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents: 239
diff changeset
1228 y = sender.getAbsoluteTop()
86055ccf69c3 browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents: 239
diff changeset
1229 else:
86055ccf69c3 browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents: 239
diff changeset
1230 x = sender.getAbsoluteLeft()
86055ccf69c3 browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents: 239
diff changeset
1231 y = sender.getAbsoluteTop() + sender.getOffsetHeight()
86055ccf69c3 browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents: 239
diff changeset
1232 self.setPopupPosition(x, y)
86055ccf69c3 browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents: 239
diff changeset
1233 self.show()
279
2d6bd975a72d browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents: 276
diff changeset
1234 if self.style["selected"]:
2d6bd975a72d browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents: 276
diff changeset
1235 sender.addStyleDependentName(self.style["selected"])
241
86055ccf69c3 browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents: 239
diff changeset
1236
86055ccf69c3 browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents: 239
diff changeset
1237 def _onHide(popup):
279
2d6bd975a72d browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents: 276
diff changeset
1238 if self.style["selected"]:
2d6bd975a72d browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents: 276
diff changeset
1239 sender.removeStyleDependentName(self.style["selected"])
241
86055ccf69c3 browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents: 239
diff changeset
1240 return PopupPanel.onHideImpl(self, popup)
86055ccf69c3 browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents: 239
diff changeset
1241
86055ccf69c3 browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents: 239
diff changeset
1242 self.onHideImpl = _onHide
86055ccf69c3 browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents: 239
diff changeset
1243
86055ccf69c3 browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents: 239
diff changeset
1244 def registerClickSender(self, sender, button=BUTTON_LEFT):
86055ccf69c3 browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents: 239
diff changeset
1245 """Bind the menu to the specified sender.
86055ccf69c3 browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents: 239
diff changeset
1246 @param sender: the widget to which the menu should be bound
86055ccf69c3 browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents: 239
diff changeset
1247 @param: BUTTON_LEFT, BUTTON_MIDDLE or BUTTON_RIGHT
86055ccf69c3 browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents: 239
diff changeset
1248 """
86055ccf69c3 browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents: 239
diff changeset
1249 self._senders.setdefault(sender, [])
86055ccf69c3 browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents: 239
diff changeset
1250 self._senders[sender].append(button)
86055ccf69c3 browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents: 239
diff changeset
1251
86055ccf69c3 browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents: 239
diff changeset
1252 if button == BUTTON_RIGHT:
86055ccf69c3 browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents: 239
diff changeset
1253 # WARNING: to disable the context menu is a bit tricky...
86055ccf69c3 browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents: 239
diff changeset
1254 # The following seems to work on Firefox 24.0, but:
86055ccf69c3 browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents: 239
diff changeset
1255 # TODO: find a cleaner way to disable the context menu
86055ccf69c3 browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents: 239
diff changeset
1256 sender.getElement().setAttribute("oncontextmenu", "return false")
86055ccf69c3 browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents: 239
diff changeset
1257
86055ccf69c3 browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents: 239
diff changeset
1258 def _onBrowserEvent(event):
86055ccf69c3 browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents: 239
diff changeset
1259 button = DOM.eventGetButton(event)
86055ccf69c3 browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents: 239
diff changeset
1260 if DOM.eventGetType(event) == "mousedown" and button in self._senders[sender]:
86055ccf69c3 browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents: 239
diff changeset
1261 self._show(sender)
86055ccf69c3 browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents: 239
diff changeset
1262 return sender.__class__.onBrowserEvent(sender, event)
86055ccf69c3 browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents: 239
diff changeset
1263
86055ccf69c3 browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents: 239
diff changeset
1264 sender.onBrowserEvent = _onBrowserEvent
86055ccf69c3 browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents: 239
diff changeset
1265
86055ccf69c3 browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents: 239
diff changeset
1266 def registerMiddleClickSender(self, sender):
86055ccf69c3 browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents: 239
diff changeset
1267 self.registerClickSender(sender, BUTTON_MIDDLE)
86055ccf69c3 browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents: 239
diff changeset
1268
86055ccf69c3 browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents: 239
diff changeset
1269 def registerRightClickSender(self, sender):
86055ccf69c3 browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents: 239
diff changeset
1270 self.registerClickSender(sender, BUTTON_RIGHT)
264
2a93f8e6f989 browser_side: added class ToggleStackPanel
souliane <souliane@mailoo.org>
parents: 261
diff changeset
1271
2a93f8e6f989 browser_side: added class ToggleStackPanel
souliane <souliane@mailoo.org>
parents: 261
diff changeset
1272
2a93f8e6f989 browser_side: added class ToggleStackPanel
souliane <souliane@mailoo.org>
parents: 261
diff changeset
1273 class ToggleStackPanel(StackPanel):
2a93f8e6f989 browser_side: added class ToggleStackPanel
souliane <souliane@mailoo.org>
parents: 261
diff changeset
1274 """This is a pyjamas.ui.StackPanel with modified behavior. All sub-panels ca be
2a93f8e6f989 browser_side: added class ToggleStackPanel
souliane <souliane@mailoo.org>
parents: 261
diff changeset
1275 visible at the same time, clicking a sub-panel header will not display it and hide
2a93f8e6f989 browser_side: added class ToggleStackPanel
souliane <souliane@mailoo.org>
parents: 261
diff changeset
1276 the others but only toggle its own visibility. The argument 'visibleStack' is ignored.
2a93f8e6f989 browser_side: added class ToggleStackPanel
souliane <souliane@mailoo.org>
parents: 261
diff changeset
1277 Note that the argument 'visible' has been added to listener's 'onStackChanged' method.
2a93f8e6f989 browser_side: added class ToggleStackPanel
souliane <souliane@mailoo.org>
parents: 261
diff changeset
1278 """
2a93f8e6f989 browser_side: added class ToggleStackPanel
souliane <souliane@mailoo.org>
parents: 261
diff changeset
1279
2a93f8e6f989 browser_side: added class ToggleStackPanel
souliane <souliane@mailoo.org>
parents: 261
diff changeset
1280 def __init__(self, **kwargs):
2a93f8e6f989 browser_side: added class ToggleStackPanel
souliane <souliane@mailoo.org>
parents: 261
diff changeset
1281 StackPanel.__init__(self, **kwargs)
2a93f8e6f989 browser_side: added class ToggleStackPanel
souliane <souliane@mailoo.org>
parents: 261
diff changeset
1282
2a93f8e6f989 browser_side: added class ToggleStackPanel
souliane <souliane@mailoo.org>
parents: 261
diff changeset
1283 def onBrowserEvent(self, event):
2a93f8e6f989 browser_side: added class ToggleStackPanel
souliane <souliane@mailoo.org>
parents: 261
diff changeset
1284 if DOM.eventGetType(event) == "click":
2a93f8e6f989 browser_side: added class ToggleStackPanel
souliane <souliane@mailoo.org>
parents: 261
diff changeset
1285 index = self.getDividerIndex(DOM.eventGetTarget(event))
2a93f8e6f989 browser_side: added class ToggleStackPanel
souliane <souliane@mailoo.org>
parents: 261
diff changeset
1286 if index != -1:
2a93f8e6f989 browser_side: added class ToggleStackPanel
souliane <souliane@mailoo.org>
parents: 261
diff changeset
1287 self.toggleStack(index)
2a93f8e6f989 browser_side: added class ToggleStackPanel
souliane <souliane@mailoo.org>
parents: 261
diff changeset
1288
2a93f8e6f989 browser_side: added class ToggleStackPanel
souliane <souliane@mailoo.org>
parents: 261
diff changeset
1289 def add(self, widget, stackText="", asHTML=False, visible=False):
2a93f8e6f989 browser_side: added class ToggleStackPanel
souliane <souliane@mailoo.org>
parents: 261
diff changeset
1290 StackPanel.add(self, widget, stackText, asHTML)
2a93f8e6f989 browser_side: added class ToggleStackPanel
souliane <souliane@mailoo.org>
parents: 261
diff changeset
1291 self.setStackVisible(self.getWidgetCount() - 1, visible)
2a93f8e6f989 browser_side: added class ToggleStackPanel
souliane <souliane@mailoo.org>
parents: 261
diff changeset
1292
2a93f8e6f989 browser_side: added class ToggleStackPanel
souliane <souliane@mailoo.org>
parents: 261
diff changeset
1293 def toggleStack(self, index):
2a93f8e6f989 browser_side: added class ToggleStackPanel
souliane <souliane@mailoo.org>
parents: 261
diff changeset
1294 if index >= self.getWidgetCount():
2a93f8e6f989 browser_side: added class ToggleStackPanel
souliane <souliane@mailoo.org>
parents: 261
diff changeset
1295 return
2a93f8e6f989 browser_side: added class ToggleStackPanel
souliane <souliane@mailoo.org>
parents: 261
diff changeset
1296 visible = not self.getWidget(index).getVisible()
2a93f8e6f989 browser_side: added class ToggleStackPanel
souliane <souliane@mailoo.org>
parents: 261
diff changeset
1297 self.setStackVisible(index, visible)
2a93f8e6f989 browser_side: added class ToggleStackPanel
souliane <souliane@mailoo.org>
parents: 261
diff changeset
1298 for listener in self.stackListeners:
2a93f8e6f989 browser_side: added class ToggleStackPanel
souliane <souliane@mailoo.org>
parents: 261
diff changeset
1299 listener.onStackChanged(self, index, visible)