Mercurial > libervia-web
annotate browser_side/panels.py @ 322:971e3812903a
browser_side: scroll to the clicked microblog post and blink it (previous behavior is conserved when the unibox is enabled)
author | souliane <souliane@mailoo.org> |
---|---|
date | Fri, 03 Jan 2014 22:44:59 +0100 |
parents | 462a0a8894e3 |
children | 0b7934e75e76 |
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 | 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 | 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 | 31 from pyjamas.ui.Button import Button |
33 | 32 from pyjamas.ui.HTML import HTML |
83 | 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 | 36 from pyjamas.ui.ClickListener import ClickHandler |
291
89818bca1a33
browser_side: set the ideal width for the blog post update dialog
souliane <souliane@mailoo.org>
parents:
289
diff
changeset
|
37 from pyjamas.ui.FlowPanel import FlowPanel |
282
ae3ec654836d
browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
38 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
|
39 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
|
40 from pyjamas.ui.MouseListener import MouseHandler |
33 | 41 from pyjamas.Timer import Timer |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
42 from pyjamas import DOM |
78
12680e220b35
browser side: refactoring: menu is now in its own module
Goffi <goffi@goffi.org>
parents:
75
diff
changeset
|
43 from card_game import CardPanel |
127 | 44 from radiocol import RadioColPanel |
78
12680e220b35
browser side: refactoring: menu is now in its own module
Goffi <goffi@goffi.org>
parents:
75
diff
changeset
|
45 from menu import Menu |
19 | 46 from jid import JID |
306
52b1afd7ac3f
server_side: display rich text in blogs (addURLToText is now in sat_frontends/tools/strings)
souliane <souliane@mailoo.org>
parents:
302
diff
changeset
|
47 from tools import html_sanitize, inlineRoot, setPresenceStyle |
52b1afd7ac3f
server_side: display rich text in blogs (addURLToText is now in sat_frontends/tools/strings)
souliane <souliane@mailoo.org>
parents:
302
diff
changeset
|
48 from sat_frontends.tools.strings import addURLToText |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
49 from datetime import datetime |
19 | 50 from time import time |
48
153de5d461a4
added Social Contract \o. (in French only so far)
Goffi <goffi@goffi.org>
parents:
43
diff
changeset
|
51 import dialog |
195 | 52 import base_widget |
282
ae3ec654836d
browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
53 from dialog import ConfirmDialog |
ae3ec654836d
browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
54 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
|
55 from plugin_xep_0085 import ChatStateMachine |
195 | 56 from pyjamas import Window |
78
12680e220b35
browser side: refactoring: menu is now in its own module
Goffi <goffi@goffi.org>
parents:
75
diff
changeset
|
57 from __pyjamas__ import doc |
276
aebb96bfa8d1
frontends tools: moved src/tools/frontends to frontends/src/tools
souliane <souliane@mailoo.org>
parents:
275
diff
changeset
|
58 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
|
59 from sat_frontends import constants |
282
ae3ec654836d
browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
60 from pyjamas.ui.FocusListener import FocusHandler |
ae3ec654836d
browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
61 import logging |
279
2d6bd975a72d
browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents:
276
diff
changeset
|
62 |
2d6bd975a72d
browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents:
276
diff
changeset
|
63 |
2d6bd975a72d
browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents:
276
diff
changeset
|
64 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
|
65 |
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
|
66 |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
231
diff
changeset
|
67 class UniBoxPanel(HorizontalPanel): |
33 | 68 """Panel containing the UniBox""" |
69 | |
70 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
|
71 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
|
72 self.host = host |
33 | 73 self.setStyleName('uniBoxPanel') |
309
05e264e96a1c
browser_side: make unibox optional
souliane <souliane@mailoo.org>
parents:
307
diff
changeset
|
74 self.unibox = None |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
231
diff
changeset
|
75 |
309
05e264e96a1c
browser_side: make unibox optional
souliane <souliane@mailoo.org>
parents:
307
diff
changeset
|
76 def setUniBox(self, enable): |
05e264e96a1c
browser_side: make unibox optional
souliane <souliane@mailoo.org>
parents:
307
diff
changeset
|
77 """Enable or disable the unibox widget. |
05e264e96a1c
browser_side: make unibox optional
souliane <souliane@mailoo.org>
parents:
307
diff
changeset
|
78 @param enable: boolean |
313
5ad70625867a
browser_side: save the unibox panel space when unibox is disabled
souliane <souliane@mailoo.org>
parents:
312
diff
changeset
|
79 @return: UniBox instance or None if disabled |
309
05e264e96a1c
browser_side: make unibox optional
souliane <souliane@mailoo.org>
parents:
307
diff
changeset
|
80 """ |
05e264e96a1c
browser_side: make unibox optional
souliane <souliane@mailoo.org>
parents:
307
diff
changeset
|
81 if enable: |
05e264e96a1c
browser_side: make unibox optional
souliane <souliane@mailoo.org>
parents:
307
diff
changeset
|
82 self.button = Button ('<img src="media/icons/tango/actions/32/format-text-italic.png" class="richTextIcon"/>') |
05e264e96a1c
browser_side: make unibox optional
souliane <souliane@mailoo.org>
parents:
307
diff
changeset
|
83 self.button.setTitle('Open the rich text editor') |
05e264e96a1c
browser_side: make unibox optional
souliane <souliane@mailoo.org>
parents:
307
diff
changeset
|
84 self.button.addStyleName('uniBoxButton') |
05e264e96a1c
browser_side: make unibox optional
souliane <souliane@mailoo.org>
parents:
307
diff
changeset
|
85 self.add(self.button) |
05e264e96a1c
browser_side: make unibox optional
souliane <souliane@mailoo.org>
parents:
307
diff
changeset
|
86 self.unibox = UniBox(self.host) |
05e264e96a1c
browser_side: make unibox optional
souliane <souliane@mailoo.org>
parents:
307
diff
changeset
|
87 self.add(self.unibox) |
05e264e96a1c
browser_side: make unibox optional
souliane <souliane@mailoo.org>
parents:
307
diff
changeset
|
88 self.setCellWidth(self.unibox, '100%') |
05e264e96a1c
browser_side: make unibox optional
souliane <souliane@mailoo.org>
parents:
307
diff
changeset
|
89 self.button.addClickListener(self.openRichTextEditor) |
05e264e96a1c
browser_side: make unibox optional
souliane <souliane@mailoo.org>
parents:
307
diff
changeset
|
90 self.unibox.addKey("@@: ") |
313
5ad70625867a
browser_side: save the unibox panel space when unibox is disabled
souliane <souliane@mailoo.org>
parents:
312
diff
changeset
|
91 return self.unibox |
309
05e264e96a1c
browser_side: make unibox optional
souliane <souliane@mailoo.org>
parents:
307
diff
changeset
|
92 else: |
05e264e96a1c
browser_side: make unibox optional
souliane <souliane@mailoo.org>
parents:
307
diff
changeset
|
93 if self.unibox: |
05e264e96a1c
browser_side: make unibox optional
souliane <souliane@mailoo.org>
parents:
307
diff
changeset
|
94 self.remove(self.unibox) |
05e264e96a1c
browser_side: make unibox optional
souliane <souliane@mailoo.org>
parents:
307
diff
changeset
|
95 self.unibox = None |
313
5ad70625867a
browser_side: save the unibox panel space when unibox is disabled
souliane <souliane@mailoo.org>
parents:
312
diff
changeset
|
96 return None |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
231
diff
changeset
|
97 |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
231
diff
changeset
|
98 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
|
99 """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
|
100 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
|
101 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
|
102 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
|
103 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
|
104 |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
231
diff
changeset
|
105 def onCloseCallback(): |
292
1a5dc08c2749
browser_side: set the ideal width for the rich text dialog when displayed in the unibox panel
souliane <souliane@mailoo.org>
parents:
291
diff
changeset
|
106 Window.removeWindowResizeListener(self) |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
231
diff
changeset
|
107 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
|
108 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
|
109 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
|
110 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
|
111 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
|
112 |
282
ae3ec654836d
browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
113 richtext.RichTextEditor.getOrCreate(self.host, self, onCloseCallback) |
292
1a5dc08c2749
browser_side: set the ideal width for the rich text dialog when displayed in the unibox panel
souliane <souliane@mailoo.org>
parents:
291
diff
changeset
|
114 Window.addWindowResizeListener(self) |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
231
diff
changeset
|
115 self.host.resize() |
33 | 116 |
292
1a5dc08c2749
browser_side: set the ideal width for the rich text dialog when displayed in the unibox panel
souliane <souliane@mailoo.org>
parents:
291
diff
changeset
|
117 def onWindowResized(self, width, height): |
1a5dc08c2749
browser_side: set the ideal width for the rich text dialog when displayed in the unibox panel
souliane <souliane@mailoo.org>
parents:
291
diff
changeset
|
118 right = self.host.panel.menu.getAbsoluteLeft() + self.host.panel.menu.getOffsetWidth() |
1a5dc08c2749
browser_side: set the ideal width for the rich text dialog when displayed in the unibox panel
souliane <souliane@mailoo.org>
parents:
291
diff
changeset
|
119 left = self.host.panel._contacts.getAbsoluteLeft() + self.host.panel._contacts.getOffsetWidth() |
1a5dc08c2749
browser_side: set the ideal width for the rich text dialog when displayed in the unibox panel
souliane <souliane@mailoo.org>
parents:
291
diff
changeset
|
120 ideal_width = right - left - 40 |
1a5dc08c2749
browser_side: set the ideal width for the rich text dialog when displayed in the unibox panel
souliane <souliane@mailoo.org>
parents:
291
diff
changeset
|
121 self.host.richtext.setWidth("%spx" % ideal_width) |
1a5dc08c2749
browser_side: set the ideal width for the rich text dialog when displayed in the unibox panel
souliane <souliane@mailoo.org>
parents:
291
diff
changeset
|
122 |
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
|
123 |
310
5d11ec1f2c22
browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents:
309
diff
changeset
|
124 class MessageBox(TextArea): |
5d11ec1f2c22
browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents:
309
diff
changeset
|
125 """A basic text area for entering messages""" |
33 | 126 |
127 def __init__(self, host): | |
73
447dc8ac181b
Adrien's uniBox design integration + lastPopup style
Goffi <goffi@goffi.org>
parents:
71
diff
changeset
|
128 TextArea.__init__(self) |
310
5d11ec1f2c22
browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents:
309
diff
changeset
|
129 self.host = 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
|
130 self.__size = (0, 0) |
310
5d11ec1f2c22
browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents:
309
diff
changeset
|
131 self.setStyleName('messageBox') |
83 | 132 self.addKeyboardListener(self) |
186
72bb1d845b6a
browser side: global resize on UniBox resize
Goffi <goffi@goffi.org>
parents:
185
diff
changeset
|
133 MouseHandler.__init__(self) |
72bb1d845b6a
browser side: global resize on UniBox resize
Goffi <goffi@goffi.org>
parents:
185
diff
changeset
|
134 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
|
135 self._selected_cache = None |
310
5d11ec1f2c22
browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents:
309
diff
changeset
|
136 |
5d11ec1f2c22
browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents:
309
diff
changeset
|
137 def onBrowserEvent(self, event): |
5d11ec1f2c22
browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents:
309
diff
changeset
|
138 # XXX: woraroung a pyjamas bug: self.currentEvent is not set |
5d11ec1f2c22
browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents:
309
diff
changeset
|
139 # so the TextBox's cancelKey doens't work. This is a workaround |
5d11ec1f2c22
browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents:
309
diff
changeset
|
140 # FIXME: fix the bug upstream |
5d11ec1f2c22
browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents:
309
diff
changeset
|
141 self.currentEvent = event |
5d11ec1f2c22
browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents:
309
diff
changeset
|
142 TextArea.onBrowserEvent(self, event) |
5d11ec1f2c22
browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents:
309
diff
changeset
|
143 |
5d11ec1f2c22
browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents:
309
diff
changeset
|
144 def onKeyPress(self, sender, keycode, modifiers): |
5d11ec1f2c22
browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents:
309
diff
changeset
|
145 _txt = self.getText() |
5d11ec1f2c22
browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents:
309
diff
changeset
|
146 |
5d11ec1f2c22
browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents:
309
diff
changeset
|
147 def history_cb(text): |
5d11ec1f2c22
browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents:
309
diff
changeset
|
148 self.setText(text) |
5d11ec1f2c22
browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents:
309
diff
changeset
|
149 Timer(5, lambda: self.setCursorPos(len(text))) |
5d11ec1f2c22
browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents:
309
diff
changeset
|
150 |
5d11ec1f2c22
browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents:
309
diff
changeset
|
151 if keycode == KEY_ENTER: |
5d11ec1f2c22
browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents:
309
diff
changeset
|
152 if _txt: |
5d11ec1f2c22
browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents:
309
diff
changeset
|
153 self._selected_cache.onTextEntered(_txt) |
5d11ec1f2c22
browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents:
309
diff
changeset
|
154 self.host._updateInputHistory(_txt) |
5d11ec1f2c22
browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents:
309
diff
changeset
|
155 self.setText('') |
5d11ec1f2c22
browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents:
309
diff
changeset
|
156 sender.cancelKey() |
5d11ec1f2c22
browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents:
309
diff
changeset
|
157 elif keycode == KEY_UP: |
5d11ec1f2c22
browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents:
309
diff
changeset
|
158 self.host._updateInputHistory(_txt, -1, history_cb) |
5d11ec1f2c22
browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents:
309
diff
changeset
|
159 elif keycode == KEY_DOWN: |
5d11ec1f2c22
browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents:
309
diff
changeset
|
160 self.host._updateInputHistory(_txt, +1, history_cb) |
5d11ec1f2c22
browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents:
309
diff
changeset
|
161 else: |
5d11ec1f2c22
browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents:
309
diff
changeset
|
162 self.__onComposing() |
5d11ec1f2c22
browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents:
309
diff
changeset
|
163 |
5d11ec1f2c22
browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents:
309
diff
changeset
|
164 def __onComposing(self): |
5d11ec1f2c22
browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents:
309
diff
changeset
|
165 """Callback when the user is composing a text.""" |
5d11ec1f2c22
browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents:
309
diff
changeset
|
166 if hasattr(self._selected_cache, "target"): |
5d11ec1f2c22
browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents:
309
diff
changeset
|
167 self._selected_cache.state_machine._onEvent("composing") |
5d11ec1f2c22
browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents:
309
diff
changeset
|
168 |
5d11ec1f2c22
browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents:
309
diff
changeset
|
169 def onMouseUp(self, sender, x, y): |
5d11ec1f2c22
browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents:
309
diff
changeset
|
170 size = (self.getOffsetWidth(), self.getOffsetHeight()) |
5d11ec1f2c22
browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents:
309
diff
changeset
|
171 if size != self.__size: |
5d11ec1f2c22
browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents:
309
diff
changeset
|
172 self.__size = size |
5d11ec1f2c22
browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents:
309
diff
changeset
|
173 self.host.resize() |
5d11ec1f2c22
browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents:
309
diff
changeset
|
174 |
5d11ec1f2c22
browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents:
309
diff
changeset
|
175 def onSelectedChange(self, selected): |
5d11ec1f2c22
browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents:
309
diff
changeset
|
176 self._selected_cache = selected |
5d11ec1f2c22
browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents:
309
diff
changeset
|
177 |
5d11ec1f2c22
browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents:
309
diff
changeset
|
178 |
5d11ec1f2c22
browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents:
309
diff
changeset
|
179 class UniBox(MessageBox, MouseHandler): #AutoCompleteTextBox): |
5d11ec1f2c22
browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents:
309
diff
changeset
|
180 """This text box is used as a main typing point, for message, microblog, etc""" |
5d11ec1f2c22
browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents:
309
diff
changeset
|
181 |
5d11ec1f2c22
browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents:
309
diff
changeset
|
182 def __init__(self, host): |
5d11ec1f2c22
browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents:
309
diff
changeset
|
183 MessageBox.__init__(self, host) |
5d11ec1f2c22
browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents:
309
diff
changeset
|
184 #AutoCompleteTextBox.__init__(self) |
5d11ec1f2c22
browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents:
309
diff
changeset
|
185 self.setStyleName('uniBox') |
5d11ec1f2c22
browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents:
309
diff
changeset
|
186 self._popup = None |
5d11ec1f2c22
browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents:
309
diff
changeset
|
187 self._timer = Timer(notify=self._timeCb) |
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
|
188 host.addSelectedListener(self.onSelectedChange) |
33 | 189 |
190 def addKey(self, key): | |
73
447dc8ac181b
Adrien's uniBox design integration + lastPopup style
Goffi <goffi@goffi.org>
parents:
71
diff
changeset
|
191 return |
447dc8ac181b
Adrien's uniBox design integration + lastPopup style
Goffi <goffi@goffi.org>
parents:
71
diff
changeset
|
192 #self.getCompletionItems().completions.append(key) |
33 | 193 |
55
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
194 def removeKey(self, key): |
255
da0487f0a2e7
browser_side: small changes to prepare the contact group manager:
souliane <souliane@mailoo.org>
parents:
249
diff
changeset
|
195 return |
da0487f0a2e7
browser_side: small changes to prepare the contact group manager:
souliane <souliane@mailoo.org>
parents:
249
diff
changeset
|
196 # 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
|
197 # 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
|
198 # 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
|
199 try: |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
200 self.getCompletionItems().completions.remove(key) |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
201 except KeyError: |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
202 print "WARNING: trying to remove an unknown key" |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
203 |
33 | 204 def showWarning(self, target_data): |
201
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
205 target_hook, _type, msg = target_data |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
206 if _type == "NONE": |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
207 return |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
208 if not msg: |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
209 print "WARNING: no msg set uniBox warning" |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
210 return |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
211 if _type == "PUBLIC": |
33 | 212 style = "targetPublic" |
201
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
213 elif _type == "GROUP": |
33 | 214 style = "targetGroup" |
201
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
215 elif _type == "STATUS": |
33 | 216 msg = "This will be your new status message" |
217 style = "targetStatus" | |
201
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
218 elif _type == "ONE2ONE": |
33 | 219 style = "targetOne2One" |
220 else: | |
201
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
221 print "ERROR: unknown message type" |
33 | 222 return |
223 contents = HTML(msg) | |
224 | |
48
153de5d461a4
added Social Contract \o. (in French only so far)
Goffi <goffi@goffi.org>
parents:
43
diff
changeset
|
225 self._popup = dialog.PopupPanelWrapper(autoHide=False, modal=False) |
33 | 226 self._popup.target_data = target_data |
227 self._popup.add(contents) | |
228 self._popup.setStyleName("warningPopup") | |
229 if style: | |
230 self._popup.addStyleName(style) | |
231 | |
232 left = 0 | |
226
744426c2b699
browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
223
diff
changeset
|
233 top = 0 # max(0, self.getAbsoluteTop() - contents.getOffsetHeight() - 2) |
33 | 234 self._popup.setPopupPosition(left, top) |
235 self._popup.show() | |
236 | |
237 def _timeCb(self, timer): | |
238 if self._popup: | |
239 self._popup.hide() | |
240 del self._popup | |
241 self._popup = None | |
242 | |
243 def _getTarget(self, txt): | |
201
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
244 """ Say who will receive the messsage |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
245 @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
|
246 - 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
|
247 - 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
|
248 - 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
|
249 target = self._selected_cache |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
250 |
201
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
251 def getSelectedOrStatus(): |
294
a6b3715f0bd6
browser_side: bug fixes for switching between unibox and rich text editor:
souliane <souliane@mailoo.org>
parents:
293
diff
changeset
|
252 if target and target.isSelectable(): |
201
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
253 _type, msg = target.getWarningData() |
226
744426c2b699
browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
223
diff
changeset
|
254 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
|
255 else: |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
256 _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
|
257 target_hook = (txt, None) |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
258 return (target_hook, _type, msg) |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
259 |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
260 if not txt.startswith('@'): |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
261 target_hook, _type, msg = getSelectedOrStatus() |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
262 elif txt.startswith('@@: '): |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
263 _type = "PUBLIC" |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
264 msg = MicroblogPanel.warning_msg_public |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
265 target_hook = (txt[4:], None) |
33 | 266 elif txt.startswith('@'): |
267 _end = txt.find(': ') | |
268 if _end == -1: | |
201
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
269 target_hook, _type, msg = getSelectedOrStatus() |
33 | 270 else: |
226
744426c2b699
browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
223
diff
changeset
|
271 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
|
272 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
|
273 # 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
|
274 group = None |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
275 target_hook, _type, msg = getSelectedOrStatus() |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
276 else: |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
277 _type = "GROUP" |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
278 msg = MicroblogPanel.warning_msg_group % group |
226
744426c2b699
browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
223
diff
changeset
|
279 target_hook = (txt[_end + 2:], group) |
33 | 280 else: |
201
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
281 print "ERROR: Unknown target" |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
282 target_hook, _type, msg = getSelectedOrStatus() |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
283 |
201
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
284 return (target_hook, _type, msg) |
33 | 285 |
286 def onKeyPress(self, sender, keycode, modifiers): | |
287 _txt = self.getText() | |
201
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
288 target = self._getTarget(_txt) |
33 | 289 if not self._popup: |
201
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
290 self.showWarning(target) |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
291 elif target != self._popup.target_data: |
226
744426c2b699
browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
223
diff
changeset
|
292 self._timeCb(None) # we remove the popup |
201
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
293 self.showWarning(target) |
33 | 294 |
295 self._timer.schedule(2000) | |
296 | |
83 | 297 if keycode == KEY_ENTER: |
33 | 298 if _txt: |
269
9eb9c7d41bdc
browser_side: added generic method "send" in SatWebFrontend
souliane <souliane@mailoo.org>
parents:
267
diff
changeset
|
299 target_hook, type_, msg = target |
201
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
300 if target_hook: |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
301 parsed_txt, data = target_hook |
269
9eb9c7d41bdc
browser_side: added generic method "send" in SatWebFrontend
souliane <souliane@mailoo.org>
parents:
267
diff
changeset
|
302 self.host.send([(type_, data)], parsed_txt) |
310
5d11ec1f2c22
browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents:
309
diff
changeset
|
303 self.host._updateInputHistory(_txt) |
5d11ec1f2c22
browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents:
309
diff
changeset
|
304 self.setText('') |
226
744426c2b699
browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
223
diff
changeset
|
305 self._timeCb(None) # we remove the popup |
310
5d11ec1f2c22
browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents:
309
diff
changeset
|
306 MessageBox.onKeyPress(self, sender, keycode, modifiers) |
214
7b26be266ab1
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
213
diff
changeset
|
307 |
231
fab7aa366576
browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents:
230
diff
changeset
|
308 def getTargetAndData(self): |
fab7aa366576
browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents:
230
diff
changeset
|
309 """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
|
310 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
|
311 @return a tuple (target, data) with: |
fab7aa366576
browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents:
230
diff
changeset
|
312 - 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
|
313 - 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
|
314 """ |
fab7aa366576
browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents:
230
diff
changeset
|
315 _txt = self.getText() |
fab7aa366576
browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents:
230
diff
changeset
|
316 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
|
317 if target_hook: |
fab7aa366576
browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents:
230
diff
changeset
|
318 data, target = target_hook |
fab7aa366576
browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents:
230
diff
changeset
|
319 if target is None: |
fab7aa366576
browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents:
230
diff
changeset
|
320 return target_hook |
fab7aa366576
browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents:
230
diff
changeset
|
321 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
|
322 if isinstance(self._selected_cache, MicroblogPanel): |
fab7aa366576
browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents:
230
diff
changeset
|
323 groups = self._selected_cache.accepted_groups |
fab7aa366576
browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents:
230
diff
changeset
|
324 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
|
325 if len(groups) > 1: |
fab7aa366576
browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents:
230
diff
changeset
|
326 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
|
327 elif isinstance(self._selected_cache, ChatPanel): |
fab7aa366576
browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents:
230
diff
changeset
|
328 target = self._selected_cache.target |
294
a6b3715f0bd6
browser_side: bug fixes for switching between unibox and rich text editor:
souliane <souliane@mailoo.org>
parents:
293
diff
changeset
|
329 else: |
a6b3715f0bd6
browser_side: bug fixes for switching between unibox and rich text editor:
souliane <souliane@mailoo.org>
parents:
293
diff
changeset
|
330 target = None |
231
fab7aa366576
browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents:
230
diff
changeset
|
331 return (_txt, target) |
fab7aa366576
browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents:
230
diff
changeset
|
332 |
294
a6b3715f0bd6
browser_side: bug fixes for switching between unibox and rich text editor:
souliane <souliane@mailoo.org>
parents:
293
diff
changeset
|
333 def onWidgetClosed(self, lib_wid): |
a6b3715f0bd6
browser_side: bug fixes for switching between unibox and rich text editor:
souliane <souliane@mailoo.org>
parents:
293
diff
changeset
|
334 """Called when a libervia widget is closed""" |
a6b3715f0bd6
browser_side: bug fixes for switching between unibox and rich text editor:
souliane <souliane@mailoo.org>
parents:
293
diff
changeset
|
335 if self._selected_cache == lib_wid: |
a6b3715f0bd6
browser_side: bug fixes for switching between unibox and rich text editor:
souliane <souliane@mailoo.org>
parents:
293
diff
changeset
|
336 self.onSelectedChange(None) |
a6b3715f0bd6
browser_side: bug fixes for switching between unibox and rich text editor:
souliane <souliane@mailoo.org>
parents:
293
diff
changeset
|
337 |
73
447dc8ac181b
Adrien's uniBox design integration + lastPopup style
Goffi <goffi@goffi.org>
parents:
71
diff
changeset
|
338 """def complete(self): |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
339 |
33 | 340 #self.visible=False #XXX: self.visible is not unset in pyjamas when ENTER is pressed and a completion is done |
341 #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
|
342 return AutoCompleteTextBox.complete(self)""" |
33 | 343 |
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
|
344 |
132
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
345 class MicroblogItem(): |
226
744426c2b699
browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
223
diff
changeset
|
346 # 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
|
347 |
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
348 def __init__(self, data): |
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
349 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
|
350 self.type = data.get('type', 'main_item') |
312
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
351 self.empty = data.get('new', False) |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
352 self.content = data.get('content', '') |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
353 self.xhtml = data.get('xhtml', '') |
132
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
354 self.author = data['author'] |
307
44b46db7dfef
browser_side (groupblog): order items using "published" instead of "updated"
souliane <souliane@mailoo.org>
parents:
306
diff
changeset
|
355 self.updated = float(data.get('updated', 0)) # XXX: int doesn't work here |
44b46db7dfef
browser_side (groupblog): order items using "published" instead of "updated"
souliane <souliane@mailoo.org>
parents:
306
diff
changeset
|
356 try: |
44b46db7dfef
browser_side (groupblog): order items using "published" instead of "updated"
souliane <souliane@mailoo.org>
parents:
306
diff
changeset
|
357 self.published = float(data['published']) # XXX: int doesn't work here |
44b46db7dfef
browser_side (groupblog): order items using "published" instead of "updated"
souliane <souliane@mailoo.org>
parents:
306
diff
changeset
|
358 except KeyError: |
44b46db7dfef
browser_side (groupblog): order items using "published" instead of "updated"
souliane <souliane@mailoo.org>
parents:
306
diff
changeset
|
359 self.published = self.updated |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
360 self.comments = data.get('comments', False) |
312
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
361 if self.empty and self.type == 'main_item': |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
362 self.service = self.node = None |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
363 self.hash = (self.service, self.node) |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
364 else: |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
365 try: |
312
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
366 self.service = data['comments_service'] if self.comments else data['service'] |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
367 self.node = data['comments_node'] if self.comments else data['node'] |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
368 self.hash = (self.service, self.node) |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
369 except KeyError: |
312
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
370 logging.error("Warning: can't manage item [%s] some keys are missing in microblog data (%s)" % (self.id, data.keys())) |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
371 self.comments = False |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
372 |
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
|
373 |
282
ae3ec654836d
browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
374 class MicroblogEntry(SimplePanel, ClickHandler, FocusHandler, KeyboardHandler): |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
375 |
312
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
376 def __init__(self, blog_panel, data={}): |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
377 """ |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
378 @param blog_panel: the parent panel |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
379 @param data: dict containing the blog item data, or a MicroblogItem instance. |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
380 """ |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
381 if isinstance(data, MicroblogItem): |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
382 self._base_item = data |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
383 else: |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
384 self._base_item = MicroblogItem(data) |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
385 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
|
386 self._blog_panel = blog_panel |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
387 |
291
89818bca1a33
browser_side: set the ideal width for the blog post update dialog
souliane <souliane@mailoo.org>
parents:
289
diff
changeset
|
388 self.panel = FlowPanel() |
89818bca1a33
browser_side: set the ideal width for the blog post update dialog
souliane <souliane@mailoo.org>
parents:
289
diff
changeset
|
389 self.panel.setStyleName('mb_entry') |
307
44b46db7dfef
browser_side (groupblog): order items using "published" instead of "updated"
souliane <souliane@mailoo.org>
parents:
306
diff
changeset
|
390 |
312
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
391 self.header = HTMLPanel('') |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
392 self.panel.add(self.header) |
291
89818bca1a33
browser_side: set the ideal width for the blog post update dialog
souliane <souliane@mailoo.org>
parents:
289
diff
changeset
|
393 |
312
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
394 self.entry_actions = VerticalPanel() |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
395 self.entry_actions.setStyleName('mb_entry_actions') |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
396 self.panel.add(self.entry_actions) |
291
89818bca1a33
browser_side: set the ideal width for the blog post update dialog
souliane <souliane@mailoo.org>
parents:
289
diff
changeset
|
397 |
89818bca1a33
browser_side: set the ideal width for the blog post update dialog
souliane <souliane@mailoo.org>
parents:
289
diff
changeset
|
398 entry_avatar = SimplePanel() |
89818bca1a33
browser_side: set the ideal width for the blog post update dialog
souliane <souliane@mailoo.org>
parents:
289
diff
changeset
|
399 entry_avatar.setStyleName('mb_entry_avatar') |
312
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
400 self.avatar = Image(self._blog_panel.host.getAvatar(self.author)) |
291
89818bca1a33
browser_side: set the ideal width for the blog post update dialog
souliane <souliane@mailoo.org>
parents:
289
diff
changeset
|
401 entry_avatar.add(self.avatar) |
89818bca1a33
browser_side: set the ideal width for the blog post update dialog
souliane <souliane@mailoo.org>
parents:
289
diff
changeset
|
402 self.panel.add(entry_avatar) |
89818bca1a33
browser_side: set the ideal width for the blog post update dialog
souliane <souliane@mailoo.org>
parents:
289
diff
changeset
|
403 |
89818bca1a33
browser_side: set the ideal width for the blog post update dialog
souliane <souliane@mailoo.org>
parents:
289
diff
changeset
|
404 self.entry_dialog = SimplePanel() |
89818bca1a33
browser_side: set the ideal width for the blog post update dialog
souliane <souliane@mailoo.org>
parents:
289
diff
changeset
|
405 self.entry_dialog.setStyleName('mb_entry_dialog') |
89818bca1a33
browser_side: set the ideal width for the blog post update dialog
souliane <souliane@mailoo.org>
parents:
289
diff
changeset
|
406 self.panel.add(self.entry_dialog) |
89818bca1a33
browser_side: set the ideal width for the blog post update dialog
souliane <souliane@mailoo.org>
parents:
289
diff
changeset
|
407 |
119 | 408 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
|
409 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
|
410 self.addClickListener(self) |
119 | 411 |
312
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
412 self.pub_data = (self.hash[0], self.hash[1], self.id) |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
413 self._setContent() |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
414 |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
415 def __getattr__(self, name): |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
416 """This allows to directly use the attributes of MicroblogItem""" |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
417 if hasattr(self, name): |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
418 return self.__dict__[name] |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
419 else: |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
420 return getattr(self._base_item, name) |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
421 |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
422 def _setContent(self): |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
423 """Actually set the entry content (header, icons, bubble...)""" |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
424 self.delete_label = self.update_label = self.comment_label = None |
315
09205b410a53
browser_side: handle successive click on blog post "edit" and "comment" icons
souliane <souliane@mailoo.org>
parents:
314
diff
changeset
|
425 self.bubble = self.editbox = self._current_comment = None |
312
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
426 self._setHeader() |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
427 if self.empty: |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
428 self.editable_content = ['', const.SYNTAX_XHTML] |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
429 else: |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
430 self.editable_content = [self.xhtml, const.SYNTAX_XHTML] if self.xhtml else [self.content, None] |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
431 self.setEntryDialog() |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
432 self._setIcons() |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
433 |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
434 def _setHeader(self): |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
435 """Set the entry header""" |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
436 if self.empty: |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
437 return |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
438 update_text = u" — ✍ " + "<span class='mb_entry_timestamp'>%s</span>" % datetime.fromtimestamp(self.updated) |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
439 self.header.setHTML("""<div class='mb_entry_header'> |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
440 <span class='mb_entry_author'>%(author)s</span> on |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
441 <span class='mb_entry_timestamp'>%(published)s</span>%(updated)s |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
442 </div>""" % {'author': html_sanitize(self.author), |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
443 'published': datetime.fromtimestamp(self.published), |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
444 'updated': update_text if self.published != self.updated else '' |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
445 } |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
446 ) |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
447 |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
448 def _setIcons(self): |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
449 """Set the entry icons (delete, update, comment)""" |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
450 if self.empty: |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
451 return |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
452 |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
453 def addIcon(label, title): |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
454 label = Label(label) |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
455 label.setTitle(title) |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
456 label.addClickListener(self) |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
457 self.entry_actions.add(label) |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
458 return label |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
459 |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
460 if self.author == self._blog_panel.host.whoami.bare: |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
461 self.delete_label = addIcon(u"✗", "Delete this message") |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
462 self.update_label = addIcon(u"✍", "Edit this message") |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
463 if self.comments: |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
464 self.comment_label = addIcon(u"↶", "Comment this message") |
291
89818bca1a33
browser_side: set the ideal width for the blog post update dialog
souliane <souliane@mailoo.org>
parents:
289
diff
changeset
|
465 |
119 | 466 def updateAvatar(self, new_avatar): |
467 """Change the avatar of the entry | |
468 @param new_avatar: path to the new image""" | |
469 self.avatar.setUrl(new_avatar) | |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
470 |
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
|
471 def onClick(self, sender): |
282
ae3ec654836d
browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
472 if sender == self: |
322
971e3812903a
browser_side: scroll to the clicked microblog post and blink it (previous behavior is conserved when the unibox is enabled)
souliane <souliane@mailoo.org>
parents:
319
diff
changeset
|
473 self._blog_panel.setSelectedEntry(self) |
282
ae3ec654836d
browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
474 elif sender == self.delete_label: |
ae3ec654836d
browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
475 self._delete() |
312
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
476 elif sender == self.update_label: |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
477 self.setEntryDialog(edit=True) |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
478 elif sender == self.comment_label: |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
479 self._comment() |
282
ae3ec654836d
browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
480 |
ae3ec654836d
browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
481 def onKeyUp(self, sender, keycode, modifiers): |
ae3ec654836d
browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
482 """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
|
483 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
|
484 return |
ae3ec654836d
browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
485 if keycode == KEY_ENTER: |
312
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
486 self._updateContent() |
282
ae3ec654836d
browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
487 |
ae3ec654836d
browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
488 def onLostFocus(self, sender): |
ae3ec654836d
browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
489 """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
|
490 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
|
491 return |
312
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
492 self._updateContent() |
282
ae3ec654836d
browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
493 |
312
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
494 def _updateContent(self, cancel=False): |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
495 """Send the new content to the backend, remove the entry if it was |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
496 an empty one (used for creating a new blog post)""" |
282
ae3ec654836d
browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
497 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
|
498 return |
291
89818bca1a33
browser_side: set the ideal width for the blog post update dialog
souliane <souliane@mailoo.org>
parents:
289
diff
changeset
|
499 self.entry_dialog.setWidth("auto") |
89818bca1a33
browser_side: set the ideal width for the blog post update dialog
souliane <souliane@mailoo.org>
parents:
289
diff
changeset
|
500 self.entry_dialog.remove(self.edit_panel) |
89818bca1a33
browser_side: set the ideal width for the blog post update dialog
souliane <souliane@mailoo.org>
parents:
289
diff
changeset
|
501 self.entry_dialog.add(self.bubble) |
282
ae3ec654836d
browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
502 new_text = self.editbox.getText().strip() |
ae3ec654836d
browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
503 self.edit_panel = self.editbox = None |
312
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
504 |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
505 def removeNewEntry(): |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
506 if self.empty: |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
507 self._blog_panel.removeEntry(self.type, self.id) |
315
09205b410a53
browser_side: handle successive click on blog post "edit" and "comment" icons
souliane <souliane@mailoo.org>
parents:
314
diff
changeset
|
508 if self.type == 'main_item': # restore the "New message" button |
312
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
509 self._blog_panel.setUniBox(enable=False) |
315
09205b410a53
browser_side: handle successive click on blog post "edit" and "comment" icons
souliane <souliane@mailoo.org>
parents:
314
diff
changeset
|
510 else: # allow to create a new comment |
09205b410a53
browser_side: handle successive click on blog post "edit" and "comment" icons
souliane <souliane@mailoo.org>
parents:
314
diff
changeset
|
511 self._parent_entry._current_comment = None |
312
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
512 |
282
ae3ec654836d
browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
513 if cancel or new_text == self.editable_content[0] or new_text == "": |
312
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
514 removeNewEntry() |
282
ae3ec654836d
browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
515 return |
ae3ec654836d
browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
516 self.editable_content[0] = new_text |
307
44b46db7dfef
browser_side (groupblog): order items using "published" instead of "updated"
souliane <souliane@mailoo.org>
parents:
306
diff
changeset
|
517 extra = {'published': str(self.published)} |
312
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
518 if self.empty or self.xhtml: |
307
44b46db7dfef
browser_side (groupblog): order items using "published" instead of "updated"
souliane <souliane@mailoo.org>
parents:
306
diff
changeset
|
519 extra.update({'rich': new_text}) |
312
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
520 if self.empty: |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
521 if self.type == 'main_item': |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
522 self._blog_panel.host.bridge.call('sendMblog', None, None, self._blog_panel.accepted_groups, new_text, extra) |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
523 else: |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
524 self._blog_panel.host.bridge.call('sendMblogComment', None, self._parent_entry.comments, new_text, extra) |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
525 else: |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
526 self._blog_panel.host.bridge.call('updateMblog', None, self.pub_data, self.comments, new_text, extra) |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
527 removeNewEntry() |
282
ae3ec654836d
browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
528 |
312
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
529 def setEntryDialog(self, edit=False): |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
530 """Set the bubble or the editor |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
531 @param edit: set to True to display the editor""" |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
532 if edit: |
315
09205b410a53
browser_side: handle successive click on blog post "edit" and "comment" icons
souliane <souliane@mailoo.org>
parents:
314
diff
changeset
|
533 if self.editbox and self.editbox.getVisible(): |
09205b410a53
browser_side: handle successive click on blog post "edit" and "comment" icons
souliane <souliane@mailoo.org>
parents:
314
diff
changeset
|
534 self.editbox.setFocus(True) |
09205b410a53
browser_side: handle successive click on blog post "edit" and "comment" icons
souliane <souliane@mailoo.org>
parents:
314
diff
changeset
|
535 return |
312
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
536 if self.empty or self.xhtml: |
315
09205b410a53
browser_side: handle successive click on blog post "edit" and "comment" icons
souliane <souliane@mailoo.org>
parents:
314
diff
changeset
|
537 def cb(result): |
09205b410a53
browser_side: handle successive click on blog post "edit" and "comment" icons
souliane <souliane@mailoo.org>
parents:
314
diff
changeset
|
538 self._updateContent(result == richtext.CANCEL) |
312
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
539 |
319
462a0a8894e3
browser_side: display the good text for microblog button regarding the context: "Send message" or "Update"
souliane <souliane@mailoo.org>
parents:
315
diff
changeset
|
540 options = ['no_recipient', 'no_sync_unibox', 'no_style', 'no_close'] |
462a0a8894e3
browser_side: display the good text for microblog button regarding the context: "Send message" or "Update"
souliane <souliane@mailoo.org>
parents:
315
diff
changeset
|
541 if not self.empty: |
462a0a8894e3
browser_side: display the good text for microblog button regarding the context: "Send message" or "Update"
souliane <souliane@mailoo.org>
parents:
315
diff
changeset
|
542 options.append('update_msg') |
315
09205b410a53
browser_side: handle successive click on blog post "edit" and "comment" icons
souliane <souliane@mailoo.org>
parents:
314
diff
changeset
|
543 editor = richtext.RichTextEditor(self._blog_panel.host, self.panel, cb, options=options) |
09205b410a53
browser_side: handle successive click on blog post "edit" and "comment" icons
souliane <souliane@mailoo.org>
parents:
314
diff
changeset
|
544 editor.setWidth('100%') |
09205b410a53
browser_side: handle successive click on blog post "edit" and "comment" icons
souliane <souliane@mailoo.org>
parents:
314
diff
changeset
|
545 self.editbox = editor.textarea |
312
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
546 editor.setVisible(True) # needed to build the toolbar |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
547 if self.editable_content[0]: |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
548 self._blog_panel.host.bridge.call('syntaxConvert', lambda d: self._setOriginalText(d, editor), |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
549 self.editable_content[0], self.editable_content[1]) |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
550 else: |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
551 self._setOriginalText("", editor) |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
552 else: |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
553 if not self.editbox: |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
554 self.editbox = TextArea() |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
555 self.editbox.addFocusListener(self) |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
556 self.editbox.addKeyboardListener(self) |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
557 self._setOriginalText(self.editable_content[0], self.editbox) |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
558 else: |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
559 if not self.bubble: |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
560 self.bubble = HTML() |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
561 self.bubble.setStyleName("bubble") |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
562 |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
563 self.bubble.setHTML(addURLToText(html_sanitize(self.content)) if not self.xhtml else self.xhtml) |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
564 self.entry_dialog.add(self.bubble) |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
565 |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
566 def _setOriginalText(self, text, container): |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
567 """Set the original text to be modified in the editor""" |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
568 text = text.strip() |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
569 container.original_text = text |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
570 self.editbox.setWidth('100%') |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
571 self.editbox.setText(text) |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
572 panel = SimplePanel() |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
573 panel.add(container) |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
574 panel.setStyleName("bubble") |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
575 panel.addStyleName('bubble-editbox') |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
576 if self.bubble: |
291
89818bca1a33
browser_side: set the ideal width for the blog post update dialog
souliane <souliane@mailoo.org>
parents:
289
diff
changeset
|
577 self.entry_dialog.remove(self.bubble) |
312
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
578 self.entry_dialog.add(panel) |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
579 self.editbox.setFocus(True) |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
580 if text: |
282
ae3ec654836d
browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
581 self.editbox.setSelectionRange(len(text), 0) |
312
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
582 self.edit_panel = panel |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
583 self.editable_content = [text, container.format if isinstance(container, richtext.RichTextEditor) else None] |
282
ae3ec654836d
browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
584 |
ae3ec654836d
browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
585 def _delete(self): |
ae3ec654836d
browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
586 """Ask confirmation for deletion""" |
ae3ec654836d
browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
587 def confirm_cb(answer): |
ae3ec654836d
browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
588 if answer: |
ae3ec654836d
browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
589 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
|
590 |
ae3ec654836d
browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
591 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
|
592 _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
|
593 _dialog.show() |
119 | 594 |
312
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
595 def _comment(self): |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
596 """Add an empty entry for a new comment""" |
315
09205b410a53
browser_side: handle successive click on blog post "edit" and "comment" icons
souliane <souliane@mailoo.org>
parents:
314
diff
changeset
|
597 if self._current_comment: |
09205b410a53
browser_side: handle successive click on blog post "edit" and "comment" icons
souliane <souliane@mailoo.org>
parents:
314
diff
changeset
|
598 self._current_comment.editbox.setFocus(True) |
09205b410a53
browser_side: handle successive click on blog post "edit" and "comment" icons
souliane <souliane@mailoo.org>
parents:
314
diff
changeset
|
599 return |
312
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
600 data = {'id': str(time()), |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
601 'new': True, |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
602 'type': 'comment', |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
603 'author': self._blog_panel.host.whoami.bare, |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
604 'service': self.service, |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
605 'node': self.node |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
606 } |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
607 entry = self._blog_panel.addEntry(data) |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
608 entry._parent_entry = self |
315
09205b410a53
browser_side: handle successive click on blog post "edit" and "comment" icons
souliane <souliane@mailoo.org>
parents:
314
diff
changeset
|
609 self._current_comment = entry |
312
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
610 entry.setEntryDialog(edit=True) |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
611 |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
612 |
195 | 613 class MicroblogPanel(base_widget.LiberviaWidget): |
201
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
614 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
|
615 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
|
616 |
132
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
617 def __init__(self, host, accepted_groups): |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
618 """Panel used to show microblog |
132
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
619 @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
|
620 """ |
230
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
621 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
|
622 self.setAcceptedGroup(accepted_groups) |
312
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
623 self.host = host |
58
4fa3d57f72f8
browser side: microblog entries caching
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
624 self.entries = {} |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
625 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
|
626 self.selected_entry = None |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
627 self.vpanel = VerticalPanel() |
83 | 628 self.vpanel.setStyleName('microblogPanel') |
34 | 629 self.setWidget(self.vpanel) |
312
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
630 self.setUniBox(self.host.uni_box) |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
631 |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
632 def setUniBox(self, enable=False): |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
633 """Enable or disable the unibox. If it is disabled, |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
634 display the 'New message' button on top of the panel""" |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
635 if enable: |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
636 return |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
637 if hasattr(self, 'new_button'): |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
638 self.new_button.setVisible(True) |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
639 else: |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
640 def addBox(): |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
641 self.new_button.setVisible(False) |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
642 data = {'id': str(time()), |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
643 'new': True, |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
644 'author': self.host.whoami.bare, |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
645 } |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
646 entry = self.addEntry(data) |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
647 entry.setEntryDialog(edit=True) |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
648 self.new_button = Button("New message", listener=addBox) |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
649 self.new_button.setStyleName("microblogNewButton") |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
650 self.vpanel.insert(self.new_button, 0) |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
651 |
195 | 652 @classmethod |
653 def registerClass(cls): | |
230
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
654 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
|
655 base_widget.LiberviaWidget.addDropKey("CONTACT_TITLE", cls.createMetaPanel) |
195 | 656 |
657 @classmethod | |
230
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
658 def createPanel(cls, host, item): |
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
659 """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
|
660 @parem host: the SatWebFrontend instance |
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
661 @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
|
662 (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
|
663 @return: the created MicroblogPanel |
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
664 """ |
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
665 _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
|
666 _type = 'ALL' if _items == [] else 'GROUP' |
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
667 # 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
|
668 _new_panel = MicroblogPanel(host, _items) |
195 | 669 host.FillMicroblogPanel(_new_panel) |
230
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
670 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
|
671 host.setSelected(_new_panel) |
195 | 672 return _new_panel |
673 | |
674 @classmethod | |
230
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
675 def createMetaPanel(cls, host, item): |
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
676 """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
|
677 return MicroblogPanel.createPanel(host, None) |
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
678 |
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
679 @property |
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
680 def accepted_groups(self): |
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
681 return self._accepted_groups |
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
682 |
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
683 def matchEntity(self, entity): |
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
684 """ |
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
685 @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
|
686 (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
|
687 @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
|
688 """ |
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
689 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
|
690 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
|
691 return self.accepted_groups == entity |
195 | 692 |
201
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
693 def getWarningData(self): |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
694 if self.selected_entry: |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
695 if not self.selected_entry.comments: |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
696 print ("ERROR: an item without comment is selected") |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
697 return ("NONE", None) |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
698 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
|
699 |
230
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
700 elif not self._accepted_groups: |
201
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
701 # we have a meta MicroblogPanel, we publish publicly |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
702 return ("PUBLIC", self.warning_msg_public) |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
703 else: |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
704 # we only accept one group at the moment |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
705 # FIXME: manage several groups |
230
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
706 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
|
707 |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
708 def onTextEntered(self, text): |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
709 if self.selected_entry: |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
710 # we are entering a comment |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
711 comments_node = self.selected_entry.comments |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
712 if not comments_node: |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
713 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
|
714 target = ("COMMENT", comments_node) |
230
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
715 elif not self._accepted_groups: |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
716 # we are entering a public microblog |
269
9eb9c7d41bdc
browser_side: added generic method "send" in SatWebFrontend
souliane <souliane@mailoo.org>
parents:
267
diff
changeset
|
717 target = ("PUBLIC", None) |
201
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
718 else: |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
719 # 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
|
720 # FIXME: manage several groups |
269
9eb9c7d41bdc
browser_side: added generic method "send" in SatWebFrontend
souliane <souliane@mailoo.org>
parents:
267
diff
changeset
|
721 target = ("GROUP", self._accepted_groups[0]) |
9eb9c7d41bdc
browser_side: added generic method "send" in SatWebFrontend
souliane <souliane@mailoo.org>
parents:
267
diff
changeset
|
722 self.host.send([target], text) |
201
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
723 |
132
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
724 def accept_all(self): |
230
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
725 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
|
726 |
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
727 def getEntries(self): |
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
728 """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
|
729 and fill the panel""" |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
730 |
132
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
731 def massiveInsert(self, mblogs): |
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
732 """Insert several microblogs at once |
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
733 @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
|
734 """ |
242
a25aa882e09a
browser_side: add context menu for contact:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
735 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
|
736 for publisher in mblogs: |
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
737 print "adding blogs for [%s]" % publisher |
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
738 for mblog in mblogs[publisher]: |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
739 if not "content" in mblog: |
132
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
740 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
|
741 continue |
312
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
742 self.addEntry(mblog) |
132
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
743 |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
744 def mblogsInsert(self, mblogs): |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
745 """ Insert several microblogs at once |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
746 @param mblogs: list of microblogs |
132
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
747 """ |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
748 for mblog in mblogs: |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
749 if not "content" in mblog: |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
750 print ("WARNING: No content found in microblog [%s]", mblog) |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
751 continue |
312
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
752 self.addEntry(mblog) |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
753 |
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
|
754 def _chronoInsert(self, vpanel, entry, reverse=True): |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
755 """ Insert an entry in chronological order |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
756 @param vpanel: VerticalPanel instance |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
757 @param entry: MicroblogEntry |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
758 @param reverse: more recent entry on top if True, chronological order else""" |
312
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
759 if entry.empty: |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
760 entry.published = time() |
135
ceef355156de
server + browser side: groupblog subscription + fixed blog insertion order
Goffi <goffi@goffi.org>
parents:
132
diff
changeset
|
761 # we look for the right index to insert our entry: |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
762 # 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
|
763 # in the past |
ceef355156de
server + browser side: groupblog subscription + fixed blog insertion order
Goffi <goffi@goffi.org>
parents:
132
diff
changeset
|
764 idx = 0 |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
765 |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
766 for child in vpanel.children: |
135
ceef355156de
server + browser side: groupblog subscription + fixed blog insertion order
Goffi <goffi@goffi.org>
parents:
132
diff
changeset
|
767 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
|
768 idx += 1 |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
769 continue |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
770 if reverse: |
307
44b46db7dfef
browser_side (groupblog): order items using "published" instead of "updated"
souliane <souliane@mailoo.org>
parents:
306
diff
changeset
|
771 if child.published < entry.published: |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
772 break |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
773 else: |
307
44b46db7dfef
browser_side (groupblog): order items using "published" instead of "updated"
souliane <souliane@mailoo.org>
parents:
306
diff
changeset
|
774 if child.published > entry.published: |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
775 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
|
776 idx += 1 |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
777 |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
778 vpanel.insert(entry, idx) |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
779 |
312
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
780 def addEntry(self, data): |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
781 """Add an entry to the panel |
312
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
782 @param data: dict containing the item data |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
783 @return: the added entry, or None |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
784 """ |
312
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
785 _entry = MicroblogEntry(self, data) |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
786 if _entry.type == "comment": |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
787 if not _entry.hash in self.comments: |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
788 # The comments node is not known in this panel |
312
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
789 return None |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
790 parent = self.comments[_entry.hash] |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
791 parent_idx = self.vpanel.getWidgetIndex(parent) |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
792 # 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
|
793 try: |
226
744426c2b699
browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
223
diff
changeset
|
794 sub_panel = self.vpanel.getWidget(parent_idx + 1) |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
795 except IndexError: |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
796 sub_panel = None |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
797 if not sub_panel or not isinstance(sub_panel, VerticalPanel): |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
798 sub_panel = VerticalPanel() |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
799 sub_panel.setStyleName('microblogPanel') |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
800 sub_panel.addStyleName('subPanel') |
226
744426c2b699
browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
223
diff
changeset
|
801 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
|
802 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
|
803 comment = sub_panel.getIndexedChild(idx) |
312
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
804 if comment.pub_data[2] == _entry.id: |
282
ae3ec654836d
browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
805 # update an existing comment |
ae3ec654836d
browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
806 sub_panel.remove(comment) |
ae3ec654836d
browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
807 sub_panel.insert(_entry, idx) |
312
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
808 return _entry |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
809 # we want comments to be inserted in chronological order |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
810 self._chronoInsert(sub_panel, _entry, reverse=False) |
312
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
811 return _entry |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
812 |
312
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
813 if _entry.id in self.entries: # update |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
814 idx = self.vpanel.getWidgetIndex(self.entries[_entry.id]) |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
815 self.vpanel.remove(self.entries[_entry.id]) |
282
ae3ec654836d
browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
816 self.vpanel.insert(_entry, idx) |
312
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
817 else: # new entry |
282
ae3ec654836d
browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
818 self._chronoInsert(self.vpanel, _entry) |
312
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
819 self.entries[_entry.id] = _entry |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
820 |
312
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
821 if _entry.comments: |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
822 # entry has comments, we keep the comment node as a reference |
312
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
823 self.comments[_entry.hash] = _entry |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
824 self.host.bridge.call('getMblogComments', self.mblogsInsert, _entry.service, _entry.node) |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
825 |
b4781a350483
browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents:
311
diff
changeset
|
826 return _entry |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
827 |
282
ae3ec654836d
browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
828 def removeEntry(self, type_, id_): |
ae3ec654836d
browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
829 """Remove an entry from the panel |
ae3ec654836d
browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
830 @param type_: entry type ('main_item' or 'comment') |
ae3ec654836d
browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
831 @param id_: entry id |
ae3ec654836d
browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
832 """ |
ae3ec654836d
browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
833 for child in self.vpanel.getChildren(): |
ae3ec654836d
browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
834 if isinstance(child, MicroblogEntry) and type_ == 'main_item': |
ae3ec654836d
browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
835 if child.pub_data[2] == id_: |
ae3ec654836d
browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
836 main_idx = self.vpanel.getWidgetIndex(child) |
ae3ec654836d
browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
837 try: |
ae3ec654836d
browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
838 sub_panel = self.vpanel.getWidget(main_idx + 1) |
ae3ec654836d
browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
839 if isinstance(sub_panel, VerticalPanel): |
ae3ec654836d
browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
840 sub_panel.removeFromParent() |
ae3ec654836d
browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
841 except IndexError: |
ae3ec654836d
browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
842 pass |
ae3ec654836d
browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
843 child.removeFromParent() |
ae3ec654836d
browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
844 self.selected_entry = None |
ae3ec654836d
browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
845 break |
ae3ec654836d
browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
846 elif isinstance(child, VerticalPanel) and type_ == 'comment': |
ae3ec654836d
browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
847 for comment in child.getChildren(): |
ae3ec654836d
browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
848 if comment.pub_data[2] == id_: |
ae3ec654836d
browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
849 comment.removeFromParent() |
ae3ec654836d
browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
850 self.selected_entry = None |
ae3ec654836d
browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
851 break |
ae3ec654836d
browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
852 |
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
|
853 def setSelectedEntry(self, entry): |
322
971e3812903a
browser_side: scroll to the clicked microblog post and blink it (previous behavior is conserved when the unibox is enabled)
souliane <souliane@mailoo.org>
parents:
319
diff
changeset
|
854 try: |
971e3812903a
browser_side: scroll to the clicked microblog post and blink it (previous behavior is conserved when the unibox is enabled)
souliane <souliane@mailoo.org>
parents:
319
diff
changeset
|
855 self.vpanel.getParent().ensureVisible(entry) # scroll to the clicked entry |
971e3812903a
browser_side: scroll to the clicked microblog post and blink it (previous behavior is conserved when the unibox is enabled)
souliane <souliane@mailoo.org>
parents:
319
diff
changeset
|
856 except AttributeError: |
971e3812903a
browser_side: scroll to the clicked microblog post and blink it (previous behavior is conserved when the unibox is enabled)
souliane <souliane@mailoo.org>
parents:
319
diff
changeset
|
857 logging.error("FIXME: MicroblogPanel.vpanel should be wrapped in a ScrollPanel!") |
971e3812903a
browser_side: scroll to the clicked microblog post and blink it (previous behavior is conserved when the unibox is enabled)
souliane <souliane@mailoo.org>
parents:
319
diff
changeset
|
858 removeStyle = lambda entry: entry.removeStyleName('selected_entry') |
971e3812903a
browser_side: scroll to the clicked microblog post and blink it (previous behavior is conserved when the unibox is enabled)
souliane <souliane@mailoo.org>
parents:
319
diff
changeset
|
859 if not self.host.uni_box or not entry.comments: |
971e3812903a
browser_side: scroll to the clicked microblog post and blink it (previous behavior is conserved when the unibox is enabled)
souliane <souliane@mailoo.org>
parents:
319
diff
changeset
|
860 entry.addStyleName('selected_entry') # blink the clicked entry |
971e3812903a
browser_side: scroll to the clicked microblog post and blink it (previous behavior is conserved when the unibox is enabled)
souliane <souliane@mailoo.org>
parents:
319
diff
changeset
|
861 clicked_entry = entry # entry may be None when the timer is done |
971e3812903a
browser_side: scroll to the clicked microblog post and blink it (previous behavior is conserved when the unibox is enabled)
souliane <souliane@mailoo.org>
parents:
319
diff
changeset
|
862 Timer(500, lambda: removeStyle(clicked_entry)) |
971e3812903a
browser_side: scroll to the clicked microblog post and blink it (previous behavior is conserved when the unibox is enabled)
souliane <souliane@mailoo.org>
parents:
319
diff
changeset
|
863 if not self.host.uni_box: |
971e3812903a
browser_side: scroll to the clicked microblog post and blink it (previous behavior is conserved when the unibox is enabled)
souliane <souliane@mailoo.org>
parents:
319
diff
changeset
|
864 return # unibox is disabled |
971e3812903a
browser_side: scroll to the clicked microblog post and blink it (previous behavior is conserved when the unibox is enabled)
souliane <souliane@mailoo.org>
parents:
319
diff
changeset
|
865 # from here the previous behavior (toggle main item selection) is conserved |
971e3812903a
browser_side: scroll to the clicked microblog post and blink it (previous behavior is conserved when the unibox is enabled)
souliane <souliane@mailoo.org>
parents:
319
diff
changeset
|
866 entry = entry if entry.comments else None |
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
|
867 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
|
868 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
|
869 if self.selected_entry: |
322
971e3812903a
browser_side: scroll to the clicked microblog post and blink it (previous behavior is conserved when the unibox is enabled)
souliane <souliane@mailoo.org>
parents:
319
diff
changeset
|
870 removeStyle(self.selected_entry) |
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
|
871 if entry: |
282
ae3ec654836d
browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
872 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
|
873 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
|
874 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
|
875 |
241
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
876 def updateValue(self, type_, jid, value): |
119 | 877 """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
|
878 @param type_: one of 'avatar', 'nick' |
119 | 879 @param jid: jid concerned |
880 @param value: new value""" | |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
881 def updateVPanel(vpanel): |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
882 for child in vpanel.children: |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
883 if isinstance(child, MicroblogEntry) and child.author == jid: |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
884 child.updateAvatar(value) |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
885 elif isinstance(child, VerticalPanel): |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
886 updateVPanel(child) |
241
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
887 if type_ == 'avatar': |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
888 updateVPanel(self.vpanel) |
119 | 889 |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
890 def setAcceptedGroup(self, group): |
230
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
891 """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
|
892 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
|
893 @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
|
894 """ |
230
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
895 if not hasattr(self, "_accepted_groups"): |
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
896 self._accepted_groups = [] |
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
897 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
|
898 for _group in groups: |
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
899 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
|
900 self._accepted_groups.append(_group) |
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
901 self._accepted_groups.sort() |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
902 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
903 def isJidAccepted(self, jid): |
163
b887186e8fc8
browser side: get entity's microblogs for newly added contacts
Goffi <goffi@goffi.org>
parents:
148
diff
changeset
|
904 """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
|
905 @param jid: jid |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
906 @return: True if the jid is accepted""" |
132
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
907 if self.accept_all(): |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
908 return True |
230
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
909 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
|
910 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
|
911 return True |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
912 return False |
19 | 913 |
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
|
914 |
314
70ac3067d641
browser_side: status can be edited with a click on it
souliane <souliane@mailoo.org>
parents:
313
diff
changeset
|
915 class StatusPanel(HTMLPanel, ClickHandler, FocusHandler, KeyboardHandler): |
70ac3067d641
browser_side: status can be edited with a click on it
souliane <souliane@mailoo.org>
parents:
313
diff
changeset
|
916 |
70ac3067d641
browser_side: status can be edited with a click on it
souliane <souliane@mailoo.org>
parents:
313
diff
changeset
|
917 EMPTY_STATUS = '<click to set a status>' |
70ac3067d641
browser_side: status can be edited with a click on it
souliane <souliane@mailoo.org>
parents:
313
diff
changeset
|
918 |
20 | 919 def __init__(self, host, status=''): |
920 self.host = host | |
314
70ac3067d641
browser_side: status can be edited with a click on it
souliane <souliane@mailoo.org>
parents:
313
diff
changeset
|
921 self.status = status |
19 | 922 HTMLPanel.__init__(self, self.__getContent()) |
20 | 923 self.setStyleName('statusPanel') |
314
70ac3067d641
browser_side: status can be edited with a click on it
souliane <souliane@mailoo.org>
parents:
313
diff
changeset
|
924 ClickHandler.__init__(self) |
70ac3067d641
browser_side: status can be edited with a click on it
souliane <souliane@mailoo.org>
parents:
313
diff
changeset
|
925 FocusHandler.__init__(self) |
70ac3067d641
browser_side: status can be edited with a click on it
souliane <souliane@mailoo.org>
parents:
313
diff
changeset
|
926 KeyboardHandler.__init__(self) |
70ac3067d641
browser_side: status can be edited with a click on it
souliane <souliane@mailoo.org>
parents:
313
diff
changeset
|
927 self.addClickListener(self) |
19 | 928 |
929 def __getContent(self): | |
314
70ac3067d641
browser_side: status can be edited with a click on it
souliane <souliane@mailoo.org>
parents:
313
diff
changeset
|
930 return "<span class='status'>%(status)s</span>" % {'status': html_sanitize(self.status or self.EMPTY_STATUS)} |
19 | 931 |
932 def changeStatus(self, new_status): | |
314
70ac3067d641
browser_side: status can be edited with a click on it
souliane <souliane@mailoo.org>
parents:
313
diff
changeset
|
933 self.status = new_status |
19 | 934 self.setHTML(self.__getContent()) |
935 | |
314
70ac3067d641
browser_side: status can be edited with a click on it
souliane <souliane@mailoo.org>
parents:
313
diff
changeset
|
936 def onClick(self, sender): |
70ac3067d641
browser_side: status can be edited with a click on it
souliane <souliane@mailoo.org>
parents:
313
diff
changeset
|
937 self.textarea = TextArea() |
70ac3067d641
browser_side: status can be edited with a click on it
souliane <souliane@mailoo.org>
parents:
313
diff
changeset
|
938 self.textarea.setStyleName('status-edit') |
70ac3067d641
browser_side: status can be edited with a click on it
souliane <souliane@mailoo.org>
parents:
313
diff
changeset
|
939 self.textarea.setText(self.status) |
70ac3067d641
browser_side: status can be edited with a click on it
souliane <souliane@mailoo.org>
parents:
313
diff
changeset
|
940 self.textarea.addKeyboardListener(self) |
70ac3067d641
browser_side: status can be edited with a click on it
souliane <souliane@mailoo.org>
parents:
313
diff
changeset
|
941 self.setVisible(False) |
70ac3067d641
browser_side: status can be edited with a click on it
souliane <souliane@mailoo.org>
parents:
313
diff
changeset
|
942 self.parent.insert(self.textarea, self.parent.getWidgetIndex(self)) |
70ac3067d641
browser_side: status can be edited with a click on it
souliane <souliane@mailoo.org>
parents:
313
diff
changeset
|
943 self.textarea.setFocus(True) |
70ac3067d641
browser_side: status can be edited with a click on it
souliane <souliane@mailoo.org>
parents:
313
diff
changeset
|
944 self.textarea.setSelectionRange(0, len(self.status)) |
70ac3067d641
browser_side: status can be edited with a click on it
souliane <souliane@mailoo.org>
parents:
313
diff
changeset
|
945 self.textarea.addFocusListener(self) |
70ac3067d641
browser_side: status can be edited with a click on it
souliane <souliane@mailoo.org>
parents:
313
diff
changeset
|
946 self.textarea.addKeyboardListener(self) |
70ac3067d641
browser_side: status can be edited with a click on it
souliane <souliane@mailoo.org>
parents:
313
diff
changeset
|
947 |
70ac3067d641
browser_side: status can be edited with a click on it
souliane <souliane@mailoo.org>
parents:
313
diff
changeset
|
948 def onKeyPress(self, sender, keycode, modifiers): |
70ac3067d641
browser_side: status can be edited with a click on it
souliane <souliane@mailoo.org>
parents:
313
diff
changeset
|
949 text = self.textarea.getText() |
70ac3067d641
browser_side: status can be edited with a click on it
souliane <souliane@mailoo.org>
parents:
313
diff
changeset
|
950 |
70ac3067d641
browser_side: status can be edited with a click on it
souliane <souliane@mailoo.org>
parents:
313
diff
changeset
|
951 if keycode == KEY_ENTER: |
70ac3067d641
browser_side: status can be edited with a click on it
souliane <souliane@mailoo.org>
parents:
313
diff
changeset
|
952 if text != self.status: |
70ac3067d641
browser_side: status can be edited with a click on it
souliane <souliane@mailoo.org>
parents:
313
diff
changeset
|
953 self.host.bridge.call('setStatus', None, self.host.status_panel.presence, text) |
70ac3067d641
browser_side: status can be edited with a click on it
souliane <souliane@mailoo.org>
parents:
313
diff
changeset
|
954 self.parent.remove(self.textarea) |
70ac3067d641
browser_side: status can be edited with a click on it
souliane <souliane@mailoo.org>
parents:
313
diff
changeset
|
955 self.setVisible(True) |
70ac3067d641
browser_side: status can be edited with a click on it
souliane <souliane@mailoo.org>
parents:
313
diff
changeset
|
956 |
70ac3067d641
browser_side: status can be edited with a click on it
souliane <souliane@mailoo.org>
parents:
313
diff
changeset
|
957 def onLostFocus(self, sender): |
70ac3067d641
browser_side: status can be edited with a click on it
souliane <souliane@mailoo.org>
parents:
313
diff
changeset
|
958 FocusHandler.onLostFocus(self, sender) |
70ac3067d641
browser_side: status can be edited with a click on it
souliane <souliane@mailoo.org>
parents:
313
diff
changeset
|
959 if sender == self.textarea: |
70ac3067d641
browser_side: status can be edited with a click on it
souliane <souliane@mailoo.org>
parents:
313
diff
changeset
|
960 self.onKeyPress(self, KEY_ENTER, None) |
70ac3067d641
browser_side: status can be edited with a click on it
souliane <souliane@mailoo.org>
parents:
313
diff
changeset
|
961 |
279
2d6bd975a72d
browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents:
276
diff
changeset
|
962 |
2d6bd975a72d
browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents:
276
diff
changeset
|
963 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
|
964 |
2d6bd975a72d
browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents:
276
diff
changeset
|
965 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
|
966 self.host = host |
2d6bd975a72d
browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents:
276
diff
changeset
|
967 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
|
968 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
|
969 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
|
970 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
|
971 self.setPresence(presence) |
2d6bd975a72d
browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents:
276
diff
changeset
|
972 entries = {} |
2d6bd975a72d
browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents:
276
diff
changeset
|
973 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
|
974 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
|
975 |
2d6bd975a72d
browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents:
276
diff
changeset
|
976 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
|
977 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
|
978 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
|
979 |
2d6bd975a72d
browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents:
276
diff
changeset
|
980 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
|
981 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
|
982 |
2d6bd975a72d
browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents:
276
diff
changeset
|
983 panel = HorizontalPanel() |
2d6bd975a72d
browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents:
276
diff
changeset
|
984 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
|
985 panel.add(self.status_panel) |
314
70ac3067d641
browser_side: status can be edited with a click on it
souliane <souliane@mailoo.org>
parents:
313
diff
changeset
|
986 panel.setCellVerticalAlignment(self.presence_button, 'baseline') |
70ac3067d641
browser_side: status can be edited with a click on it
souliane <souliane@mailoo.org>
parents:
313
diff
changeset
|
987 panel.setCellVerticalAlignment(self.status_panel, 'baseline') |
279
2d6bd975a72d
browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents:
276
diff
changeset
|
988 panel.setStyleName("marginAuto") |
2d6bd975a72d
browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents:
276
diff
changeset
|
989 self.add(panel) |
2d6bd975a72d
browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents:
276
diff
changeset
|
990 |
2d6bd975a72d
browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents:
276
diff
changeset
|
991 ClickHandler.__init__(self) |
2d6bd975a72d
browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents:
276
diff
changeset
|
992 self.addClickListener(self) |
2d6bd975a72d
browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents:
276
diff
changeset
|
993 |
2d6bd975a72d
browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents:
276
diff
changeset
|
994 def getPresence(self): |
2d6bd975a72d
browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents:
276
diff
changeset
|
995 return self.presence |
2d6bd975a72d
browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents:
276
diff
changeset
|
996 |
2d6bd975a72d
browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents:
276
diff
changeset
|
997 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
|
998 status = self.status_panel.status |
302
6e36b44cbd34
browser_side: bug fix for setting a new presence when the current one is 'unavailable'
souliane <souliane@mailoo.org>
parents:
294
diff
changeset
|
999 if not status.strip() or status == " " or (self.presence in const.PRESENCE and status == const.PRESENCE[self.presence]): |
279
2d6bd975a72d
browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents:
276
diff
changeset
|
1000 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
|
1001 self.presence = presence |
2d6bd975a72d
browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents:
276
diff
changeset
|
1002 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
|
1003 |
2d6bd975a72d
browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents:
276
diff
changeset
|
1004 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
|
1005 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
|
1006 |
62 | 1007 def onClick(self, sender): |
226
744426c2b699
browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
223
diff
changeset
|
1008 # 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
|
1009 self.host.setSelected(None) |
20 | 1010 |
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
|
1011 |
19 | 1012 class ChatText(HTMLPanel): |
1013 | |
235
b304cdf13a3b
browser and server side: XHTML handling, first draft:
Goffi <goffi@goffi.org>
parents:
232
diff
changeset
|
1014 def __init__(self, timestamp, nick, mymess, msg, xhtml = None): |
19 | 1015 _date = datetime.fromtimestamp(float(timestamp or time())) |
1016 _msg_class = ["chat_text_msg"] | |
1017 if mymess: | |
1018 _msg_class.append("chat_text_mymess") | |
1019 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
|
1020 {"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
|
1021 "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
|
1022 "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
|
1023 "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
|
1024 ) |
19 | 1025 self.setStyleName('chatText') |
33 | 1026 |
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 |
33 | 1028 class Occupant(HTML): |
1029 """Occupant of a MUC room""" | |
1030 | |
273
11718798ab8a
browser_side: can identify muc members with symbols
souliane <souliane@mailoo.org>
parents:
269
diff
changeset
|
1031 def __init__(self, nick, special=""): |
11718798ab8a
browser_side: can identify muc members with symbols
souliane <souliane@mailoo.org>
parents:
269
diff
changeset
|
1032 HTML.__init__(self) |
33 | 1033 self.nick = nick |
273
11718798ab8a
browser_side: can identify muc members with symbols
souliane <souliane@mailoo.org>
parents:
269
diff
changeset
|
1034 self.special = special |
11718798ab8a
browser_side: can identify muc members with symbols
souliane <souliane@mailoo.org>
parents:
269
diff
changeset
|
1035 self._refresh() |
35 | 1036 |
1037 def __str__(self): | |
181
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
1038 return self.nick |
33 | 1039 |
273
11718798ab8a
browser_side: can identify muc members with symbols
souliane <souliane@mailoo.org>
parents:
269
diff
changeset
|
1040 def addSpecial(self, special=""): |
11718798ab8a
browser_side: can identify muc members with symbols
souliane <souliane@mailoo.org>
parents:
269
diff
changeset
|
1041 if special not in self.special: |
11718798ab8a
browser_side: can identify muc members with symbols
souliane <souliane@mailoo.org>
parents:
269
diff
changeset
|
1042 self.special += special |
11718798ab8a
browser_side: can identify muc members with symbols
souliane <souliane@mailoo.org>
parents:
269
diff
changeset
|
1043 self._refresh() |
11718798ab8a
browser_side: can identify muc members with symbols
souliane <souliane@mailoo.org>
parents:
269
diff
changeset
|
1044 |
11718798ab8a
browser_side: can identify muc members with symbols
souliane <souliane@mailoo.org>
parents:
269
diff
changeset
|
1045 def _refresh(self): |
11718798ab8a
browser_side: can identify muc members with symbols
souliane <souliane@mailoo.org>
parents:
269
diff
changeset
|
1046 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
|
1047 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
|
1048 |
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
|
1049 |
33 | 1050 class OccupantsList(AbsolutePanel): |
1051 """Panel user to show occupants of a room""" | |
1052 | |
1053 def __init__(self): | |
1054 AbsolutePanel.__init__(self) | |
35 | 1055 self.occupants_list = {} |
33 | 1056 self.setStyleName('occupantsList') |
1057 | |
1058 def addOccupant(self, nick): | |
35 | 1059 _occupant = Occupant(nick) |
1060 self.occupants_list[nick] = _occupant | |
1061 self.add(_occupant) | |
33 | 1062 |
35 | 1063 def removeOccupant(self, nick): |
1064 try: | |
1065 self.remove(self.occupants_list[nick]) | |
1066 except KeyError: | |
1067 print "ERROR: trying to remove an unexisting nick" | |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
1068 |
35 | 1069 def clear(self): |
1070 self.occupants_list.clear() | |
1071 AbsolutePanel.clear(self) | |
1072 | |
273
11718798ab8a
browser_side: can identify muc members with symbols
souliane <souliane@mailoo.org>
parents:
269
diff
changeset
|
1073 def addSpecials(self, occupants=[], html=""): |
11718798ab8a
browser_side: can identify muc members with symbols
souliane <souliane@mailoo.org>
parents:
269
diff
changeset
|
1074 index = 0 |
11718798ab8a
browser_side: can identify muc members with symbols
souliane <souliane@mailoo.org>
parents:
269
diff
changeset
|
1075 special = html |
11718798ab8a
browser_side: can identify muc members with symbols
souliane <souliane@mailoo.org>
parents:
269
diff
changeset
|
1076 for occupant in occupants: |
11718798ab8a
browser_side: can identify muc members with symbols
souliane <souliane@mailoo.org>
parents:
269
diff
changeset
|
1077 if occupant in self.occupants_list.keys(): |
11718798ab8a
browser_side: can identify muc members with symbols
souliane <souliane@mailoo.org>
parents:
269
diff
changeset
|
1078 if isinstance(html, list): |
11718798ab8a
browser_side: can identify muc members with symbols
souliane <souliane@mailoo.org>
parents:
269
diff
changeset
|
1079 special = html[index] |
11718798ab8a
browser_side: can identify muc members with symbols
souliane <souliane@mailoo.org>
parents:
269
diff
changeset
|
1080 index = (index + 1) % len(html) |
11718798ab8a
browser_side: can identify muc members with symbols
souliane <souliane@mailoo.org>
parents:
269
diff
changeset
|
1081 self.occupants_list[occupant].addSpecial(special) |
11718798ab8a
browser_side: can identify muc members with symbols
souliane <souliane@mailoo.org>
parents:
269
diff
changeset
|
1082 |
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
|
1083 |
195 | 1084 class ChatPanel(base_widget.LiberviaWidget): |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1085 |
179
8475a29d7214
closing a group chat widget now leave the muc room (bug 11)
Goffi <goffi@goffi.org>
parents:
178
diff
changeset
|
1086 def __init__(self, host, target, type_='one2one'): |
19 | 1087 """Panel used for conversation (one 2 one or group chat) |
1088 @param host: SatWebFrontend instance | |
1089 @param target: entity (JID) with who we have a conversation (contact's jid for one 2 one chat, or MUC room) | |
1090 @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
|
1091 base_widget.LiberviaWidget.__init__(self, host, target.bare, selectable=True) |
34 | 1092 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
|
1093 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
|
1094 self.type = type_ |
33 | 1095 self.nick = None |
19 | 1096 if not target: |
1097 print "ERROR: Empty target !" | |
1098 return | |
1099 self.target = target | |
84 | 1100 self.__body = AbsolutePanel() |
1101 self.__body.setStyleName('chatPanel_body') | |
33 | 1102 chat_area = HorizontalPanel() |
1103 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
|
1104 if type_ == 'group': |
33 | 1105 self.occupants_list = OccupantsList() |
1106 chat_area.add(self.occupants_list) | |
84 | 1107 self.__body.add(chat_area) |
33 | 1108 self.content = AbsolutePanel() |
1109 self.content.setStyleName('chatContent') | |
195 | 1110 self.content_scroll = base_widget.ScrollPanelWrapper(self.content) |
34 | 1111 chat_area.add(self.content_scroll) |
1112 chat_area.setCellWidth(self.content_scroll, '100%') | |
84 | 1113 self.vpanel.add(self.__body) |
311
3135ff840b8e
browser_side: message box below the ChatPanel when unibox is disabled
souliane <souliane@mailoo.org>
parents:
310
diff
changeset
|
1114 self.vpanel.setCellHeight(self.__body, '100%') |
84 | 1115 self.addStyleName('chatPanel') |
34 | 1116 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
|
1117 self.state_machine = ChatStateMachine(self.host, str(self.target)) |
311
3135ff840b8e
browser_side: message box below the ChatPanel when unibox is disabled
souliane <souliane@mailoo.org>
parents:
310
diff
changeset
|
1118 self.setUniBox(self.host.uni_box) |
3135ff840b8e
browser_side: message box below the ChatPanel when unibox is disabled
souliane <souliane@mailoo.org>
parents:
310
diff
changeset
|
1119 |
3135ff840b8e
browser_side: message box below the ChatPanel when unibox is disabled
souliane <souliane@mailoo.org>
parents:
310
diff
changeset
|
1120 def setUniBox(self, enable): |
3135ff840b8e
browser_side: message box below the ChatPanel when unibox is disabled
souliane <souliane@mailoo.org>
parents:
310
diff
changeset
|
1121 """Enable or disable the unibox. If it is disabled, |
3135ff840b8e
browser_side: message box below the ChatPanel when unibox is disabled
souliane <souliane@mailoo.org>
parents:
310
diff
changeset
|
1122 display a message box below the panel.""" |
3135ff840b8e
browser_side: message box below the ChatPanel when unibox is disabled
souliane <souliane@mailoo.org>
parents:
310
diff
changeset
|
1123 if enable: |
3135ff840b8e
browser_side: message box below the ChatPanel when unibox is disabled
souliane <souliane@mailoo.org>
parents:
310
diff
changeset
|
1124 return |
3135ff840b8e
browser_side: message box below the ChatPanel when unibox is disabled
souliane <souliane@mailoo.org>
parents:
310
diff
changeset
|
1125 message_box = MessageBox(self.host) |
3135ff840b8e
browser_side: message box below the ChatPanel when unibox is disabled
souliane <souliane@mailoo.org>
parents:
310
diff
changeset
|
1126 message_box.onSelectedChange(self) |
3135ff840b8e
browser_side: message box below the ChatPanel when unibox is disabled
souliane <souliane@mailoo.org>
parents:
310
diff
changeset
|
1127 self.vpanel.add(message_box) |
19 | 1128 |
84 | 1129 """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
|
1130 #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
|
1131 #for the same reason as doAttachChildren |
195 | 1132 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
|
1133 |
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
|
1134 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
|
1135 #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
|
1136 #the event will not propagate to children |
195 | 1137 base_widget.ScrollPanelWrapper.doAttachChildren(self)""" |
1138 | |
1139 @classmethod | |
1140 def registerClass(cls): | |
230
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
1141 base_widget.LiberviaWidget.addDropKey("CONTACT", cls.createPanel) |
195 | 1142 |
1143 @classmethod | |
230
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
1144 def createPanel(cls, host, item): |
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
1145 _contact = item if isinstance(item, JID) else JID(item) |
195 | 1146 host.contact_panel.setContactMessageWaiting(_contact.bare, False) |
226
744426c2b699
browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
223
diff
changeset
|
1147 _new_panel = ChatPanel(host, _contact) # XXX: pyjamas doesn't seems to support creating with cls directly |
195 | 1148 _new_panel.historyPrint() |
230
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
1149 host.setSelected(_new_panel) |
195 | 1150 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
|
1151 |
230
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
1152 def refresh(self): |
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
1153 """Refresh the display of this widget.""" |
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
1154 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
|
1155 self.content_scroll.scrollToBottom() |
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
1156 |
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
1157 def matchEntity(self, entity): |
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
1158 """ |
267
a76243c02074
browser_side: changes regarding widgets and tabs:
souliane <souliane@mailoo.org>
parents:
264
diff
changeset
|
1159 @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
|
1160 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
|
1161 @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
|
1162 """ |
267
a76243c02074
browser_side: changes regarding widgets and tabs:
souliane <souliane@mailoo.org>
parents:
264
diff
changeset
|
1163 if isinstance(entity, tuple): |
a76243c02074
browser_side: changes regarding widgets and tabs:
souliane <souliane@mailoo.org>
parents:
264
diff
changeset
|
1164 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
|
1165 else: |
a76243c02074
browser_side: changes regarding widgets and tabs:
souliane <souliane@mailoo.org>
parents:
264
diff
changeset
|
1166 type_ = self.type |
230
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
1167 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
|
1168 try: |
267
a76243c02074
browser_side: changes regarding widgets and tabs:
souliane <souliane@mailoo.org>
parents:
264
diff
changeset
|
1169 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
|
1170 except AttributeError as e: |
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
1171 e.include_traceback() |
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
1172 return False |
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
1173 |
201
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
1174 def getWarningData(self): |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
1175 if self.type not in ["one2one", "group"]: |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
1176 raise Exception("Unmanaged type !") |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
1177 if self.type == "one2one": |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
1178 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
|
1179 elif self.type == "group": |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
1180 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
|
1181 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
|
1182 |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
1183 def onTextEntered(self, text): |
269
9eb9c7d41bdc
browser_side: added generic method "send" in SatWebFrontend
souliane <souliane@mailoo.org>
parents:
267
diff
changeset
|
1184 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
|
1185 self.state_machine._onEvent("active") |
201
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
1186 |
179
8475a29d7214
closing a group chat widget now leave the muc room (bug 11)
Goffi <goffi@goffi.org>
parents:
178
diff
changeset
|
1187 def onQuit(self): |
195 | 1188 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
|
1189 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
|
1190 self.host.bridge.call('mucLeave', None, self.target.bare) |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
1191 |
19 | 1192 def setUserNick(self, nick): |
1193 """Set the nick of the user, usefull for e.g. change the color of the user""" | |
1194 self.nick = nick | |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
1195 |
33 | 1196 def setPresents(self, nicks): |
1197 """Set the users presents in this room | |
1198 @param occupants: list of nicks (string)""" | |
35 | 1199 self.occupants_list.clear() |
33 | 1200 for nick in nicks: |
1201 self.occupants_list.addOccupant(nick) | |
1202 | |
35 | 1203 def userJoined(self, nick, data): |
1204 self.occupants_list.addOccupant(nick) | |
1205 self.printInfo("=> %s has joined the room" % nick) | |
1206 | |
1207 def userLeft(self, nick, data): | |
1208 self.occupants_list.removeOccupant(nick) | |
1209 self.printInfo("<= %s has left the room" % nick) | |
1210 | |
19 | 1211 def historyPrint(self, size=20): |
1212 """Print the initial history""" | |
1213 def getHistoryCB(history): | |
213
8bbac49765d6
browser side: display the day change in chat window
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
1214 # display day change |
8bbac49765d6
browser side: display the day change in chat window
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
1215 day_format = "%A, %d %b %Y" |
8bbac49765d6
browser side: display the day change in chat window
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
1216 previous_day = datetime.now().strftime(day_format) |
123 | 1217 for line in history: |
235
b304cdf13a3b
browser and server side: XHTML handling, first draft:
Goffi <goffi@goffi.org>
parents:
232
diff
changeset
|
1218 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
|
1219 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
|
1220 if previous_day != message_day: |
8bbac49765d6
browser side: display the day change in chat window
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
1221 self.printInfo("* " + message_day) |
8bbac49765d6
browser side: display the day change in chat window
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
1222 previous_day = message_day |
235
b304cdf13a3b
browser and server side: XHTML handling, first draft:
Goffi <goffi@goffi.org>
parents:
232
diff
changeset
|
1223 self.printMessage(from_jid, message, extra, timestamp) |
123 | 1224 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
|
1225 |
35 | 1226 def printInfo(self, msg, type='normal'): |
1227 """Print general info | |
1228 @param msg: message to print | |
1229 @type: one of: | |
1230 normal: general info like "toto has joined the room" | |
1231 me: "/me" information like "/me clenches his fist" ==> "toto clenches his fist" | |
1232 """ | |
54
f25c4077f6b9
addind contact + subscription management + misc
Goffi <goffi@goffi.org>
parents:
52
diff
changeset
|
1233 _wid = Label(msg) |
35 | 1234 if type == 'normal': |
1235 _wid.setStyleName('chatTextInfo') | |
1236 elif type == 'me': | |
1237 _wid.setStyleName('chatTextMe') | |
1238 else: | |
1239 _wid.setStyleName('chatTextInfo') | |
1240 self.content.add(_wid) | |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
1241 |
235
b304cdf13a3b
browser and server side: XHTML handling, first draft:
Goffi <goffi@goffi.org>
parents:
232
diff
changeset
|
1242 def printMessage(self, from_jid, msg, extra, timestamp=None): |
19 | 1243 """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
|
1244 _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
|
1245 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
|
1246 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 | 1247 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
|
1248 self.printInfo('* %s %s' % (nick, msg[4:]), type='me') |
35 | 1249 return |
235
b304cdf13a3b
browser and server side: XHTML handling, first draft:
Goffi <goffi@goffi.org>
parents:
232
diff
changeset
|
1250 self.content.add(ChatText(timestamp, nick, mymess, msg, extra.get('xhtml'))) |
34 | 1251 self.content_scroll.scrollToBottom() |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
1252 |
285
4f0c2fea358a
browser_side (plugin radiocol): use the status label to give more information
souliane <souliane@mailoo.org>
parents:
282
diff
changeset
|
1253 def startGame(self, game_type, waiting, referee, players, *args): |
36 | 1254 """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
|
1255 classes = {"Tarot": CardPanel, "RadioCol": RadioColPanel} |
a763b2ac5d41
bridge + browser_side: bridge signals for games and their callbacks:
souliane <souliane@mailoo.org>
parents:
273
diff
changeset
|
1256 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
|
1257 return # unknown game |
a763b2ac5d41
bridge + browser_side: bridge signals for games and their callbacks:
souliane <souliane@mailoo.org>
parents:
273
diff
changeset
|
1258 attr = game_type.lower() |
a763b2ac5d41
bridge + browser_side: bridge signals for games and their callbacks:
souliane <souliane@mailoo.org>
parents:
273
diff
changeset
|
1259 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
|
1260 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
|
1261 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
|
1262 attr = "%s_panel" % attr |
a763b2ac5d41
bridge + browser_side: bridge signals for games and their callbacks:
souliane <souliane@mailoo.org>
parents:
273
diff
changeset
|
1263 if hasattr(self, attr): |
a763b2ac5d41
bridge + browser_side: bridge signals for games and their callbacks:
souliane <souliane@mailoo.org>
parents:
273
diff
changeset
|
1264 return |
a763b2ac5d41
bridge + browser_side: bridge signals for games and their callbacks:
souliane <souliane@mailoo.org>
parents:
273
diff
changeset
|
1265 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
|
1266 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
|
1267 setattr(self, attr, panel) |
a763b2ac5d41
bridge + browser_side: bridge signals for games and their callbacks:
souliane <souliane@mailoo.org>
parents:
273
diff
changeset
|
1268 self.vpanel.insert(panel, 0) |
a763b2ac5d41
bridge + browser_side: bridge signals for games and their callbacks:
souliane <souliane@mailoo.org>
parents:
273
diff
changeset
|
1269 self.vpanel.setCellHeight(panel, panel.getHeight()) |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
1270 |
37
b306aa090438
Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
1271 def getGame(self, game_type): |
b306aa090438
Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
1272 """Return class managing the game type""" |
226
744426c2b699
browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
223
diff
changeset
|
1273 # 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
|
1274 if game_type == "Tarot": |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
1275 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
|
1276 elif game_type == "RadioCol": |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
1277 return self.radiocol_panel |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1278 |
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
|
1279 |
195 | 1280 class WebPanel(base_widget.LiberviaWidget): |
181
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
1281 """ (mini)browser like widget """ |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
1282 |
181
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
1283 def __init__(self, host, url=None): |
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
1284 """ |
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
1285 @param host: SatWebFrontend instance |
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
1286 """ |
195 | 1287 base_widget.LiberviaWidget.__init__(self, host) |
181
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
1288 self._vpanel = VerticalPanel() |
188
39936b83da9d
Browser Side: Web Panel widget position/size fix
Goffi <goffi@goffi.org>
parents:
187
diff
changeset
|
1289 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
|
1290 self._url = dialog.ExtTextBox(enter_cb=self.onUrlClick) |
181
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
1291 self._url.setText(url or "") |
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
1292 self._url.setWidth('100%') |
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
1293 hpanel = HorizontalPanel() |
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
1294 hpanel.add(self._url) |
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
1295 btn = Button("Go", self.onUrlClick) |
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
1296 hpanel.setCellWidth(self._url, "100%") |
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
1297 #self.setCellWidth(btn, "10%") |
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
1298 hpanel.add(self._url) |
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
1299 hpanel.add(btn) |
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
1300 self._vpanel.add(hpanel) |
188
39936b83da9d
Browser Side: Web Panel widget position/size fix
Goffi <goffi@goffi.org>
parents:
187
diff
changeset
|
1301 self._vpanel.setCellHeight(hpanel, '20px') |
181
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
1302 self._frame = Frame(url or "") |
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
1303 self._frame.setSize('100%', '100%') |
188
39936b83da9d
Browser Side: Web Panel widget position/size fix
Goffi <goffi@goffi.org>
parents:
187
diff
changeset
|
1304 DOM.setStyleAttribute(self._frame.getElement(), "position", "relative") |
181
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
1305 self._vpanel.add(self._frame) |
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
1306 self.setWidget(self._vpanel) |
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
1307 |
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
1308 def onUrlClick(self, sender): |
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
1309 self._frame.setUrl(self._url.getText()) |
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
1310 |
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
|
1311 |
33 | 1312 class MainPanel(AbsolutePanel): |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1313 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1314 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
|
1315 self.host = host |
33 | 1316 AbsolutePanel.__init__(self) |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1317 |
226
744426c2b699
browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
223
diff
changeset
|
1318 # menu |
218
4e6467efd6bf
browser_side: small improvements for parameters panel
souliane <souliane@mailoo.org>
parents:
217
diff
changeset
|
1319 self.menu = Menu(host) |
184
97d5e9de1106
browser side: contacts panel switch:
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
1320 |
226
744426c2b699
browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
223
diff
changeset
|
1321 # unibox |
309
05e264e96a1c
browser_side: make unibox optional
souliane <souliane@mailoo.org>
parents:
307
diff
changeset
|
1322 self.unibox_panel = UniBoxPanel(host) |
313
5ad70625867a
browser_side: save the unibox panel space when unibox is disabled
souliane <souliane@mailoo.org>
parents:
312
diff
changeset
|
1323 self.unibox_panel.setVisible(False) |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
1324 |
226
744426c2b699
browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
223
diff
changeset
|
1325 # 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
|
1326 status = host.status_panel |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
1327 |
226
744426c2b699
browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
223
diff
changeset
|
1328 # contacts |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
231
diff
changeset
|
1329 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
|
1330 self._contacts.addStyleName('globalLeftArea') |
255
da0487f0a2e7
browser_side: small changes to prepare the contact group manager:
souliane <souliane@mailoo.org>
parents:
249
diff
changeset
|
1331 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
|
1332 self.contacts_switch.addStyleName('contactsSwitch') |
da0487f0a2e7
browser_side: small changes to prepare the contact group manager:
souliane <souliane@mailoo.org>
parents:
249
diff
changeset
|
1333 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
|
1334 self._contacts.add(self.host.contact_panel) |
184
97d5e9de1106
browser side: contacts panel switch:
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
1335 |
226
744426c2b699
browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
223
diff
changeset
|
1336 # tabs |
195 | 1337 self.tab_panel = base_widget.MainTabPanel(host) |
1338 self.discuss_panel = base_widget.WidgetsPanel(self.host, locked=True) | |
23 | 1339 self.tab_panel.add(self.discuss_panel, "Discussions") |
1340 self.tab_panel.selectTab(0) | |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1341 |
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
|
1342 header = AbsolutePanel() |
218
4e6467efd6bf
browser_side: small improvements for parameters panel
souliane <souliane@mailoo.org>
parents:
217
diff
changeset
|
1343 header.add(self.menu) |
309
05e264e96a1c
browser_side: make unibox optional
souliane <souliane@mailoo.org>
parents:
307
diff
changeset
|
1344 header.add(self.unibox_panel) |
109
5c363b638127
browser side: grouped header panel in a global Absolute panel
Goffi <goffi@goffi.org>
parents:
101
diff
changeset
|
1345 header.add(status) |
5c363b638127
browser side: grouped header panel in a global Absolute panel
Goffi <goffi@goffi.org>
parents:
101
diff
changeset
|
1346 header.setStyleName('header') |
5c363b638127
browser side: grouped header panel in a global Absolute panel
Goffi <goffi@goffi.org>
parents:
101
diff
changeset
|
1347 self.add(header) |
184
97d5e9de1106
browser side: contacts panel switch:
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
1348 |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
231
diff
changeset
|
1349 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
|
1350 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
|
1351 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
|
1352 self.add(self._hpanel) |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
1353 |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1354 self.setWidth("100%") |
33 | 1355 Window.addWindowResizeListener(self) |
1356 | |
255
da0487f0a2e7
browser_side: small changes to prepare the contact group manager:
souliane <souliane@mailoo.org>
parents:
249
diff
changeset
|
1357 def _contactsSwitch(self, btn=None): |
184
97d5e9de1106
browser side: contacts panel switch:
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
1358 """ (Un)hide contacts panel """ |
255
da0487f0a2e7
browser_side: small changes to prepare the contact group manager:
souliane <souliane@mailoo.org>
parents:
249
diff
changeset
|
1359 if btn is None: |
da0487f0a2e7
browser_side: small changes to prepare the contact group manager:
souliane <souliane@mailoo.org>
parents:
249
diff
changeset
|
1360 btn = self.contacts_switch |
184
97d5e9de1106
browser side: contacts panel switch:
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
1361 cpanel = self.host.contact_panel |
97d5e9de1106
browser side: contacts panel switch:
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
1362 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
|
1363 btn.setText(u"«" if cpanel.getVisible() else u"»") |
184
97d5e9de1106
browser side: contacts panel switch:
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
1364 self.host.resize() |
97d5e9de1106
browser side: contacts panel switch:
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
1365 |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
231
diff
changeset
|
1366 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
|
1367 """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
|
1368 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
|
1369 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
|
1370 """ |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
231
diff
changeset
|
1371 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
|
1372 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
|
1373 return |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
231
diff
changeset
|
1374 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
|
1375 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
|
1376 |
33 | 1377 def onWindowResized(self, width, height): |
1378 _elts = doc().getElementsByClassName('gwt-TabBar') | |
1379 if not _elts.length: | |
1380 tab_bar_h = 0 | |
1381 else: | |
1382 tab_bar_h = _elts.item(0).offsetHeight | |
1383 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
|
1384 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
|
1385 |
313
5ad70625867a
browser_side: save the unibox panel space when unibox is disabled
souliane <souliane@mailoo.org>
parents:
312
diff
changeset
|
1386 def setUniBoxPanel(self, enable): |
5ad70625867a
browser_side: save the unibox panel space when unibox is disabled
souliane <souliane@mailoo.org>
parents:
312
diff
changeset
|
1387 """Enable or disable the unibox |
5ad70625867a
browser_side: save the unibox panel space when unibox is disabled
souliane <souliane@mailoo.org>
parents:
312
diff
changeset
|
1388 @param enable: boolean |
5ad70625867a
browser_side: save the unibox panel space when unibox is disabled
souliane <souliane@mailoo.org>
parents:
312
diff
changeset
|
1389 @return: UniBox instance or None if disabled |
5ad70625867a
browser_side: save the unibox panel space when unibox is disabled
souliane <souliane@mailoo.org>
parents:
312
diff
changeset
|
1390 """ |
5ad70625867a
browser_side: save the unibox panel space when unibox is disabled
souliane <souliane@mailoo.org>
parents:
312
diff
changeset
|
1391 self.unibox_panel.setVisible(enable) |
5ad70625867a
browser_side: save the unibox panel space when unibox is disabled
souliane <souliane@mailoo.org>
parents:
312
diff
changeset
|
1392 return self.unibox_panel.setUniBox(enable) |
5ad70625867a
browser_side: save the unibox panel space when unibox is disabled
souliane <souliane@mailoo.org>
parents:
312
diff
changeset
|
1393 |
241
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
1394 |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
1395 class PopupMenuPanel(PopupPanel): |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
1396 """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
|
1397 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
|
1398 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
|
1399 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
|
1400 """ |
279
2d6bd975a72d
browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents:
276
diff
changeset
|
1401 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
|
1402 """ |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
1403 @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
|
1404 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
|
1405 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
|
1406 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
|
1407 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
|
1408 @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
|
1409 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
|
1410 @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
|
1411 @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
|
1412 @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
|
1413 @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
|
1414 """ |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
1415 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
|
1416 self._entries = entries |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
1417 self._hide = hide |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
1418 self._callback = callback |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
1419 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
|
1420 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
|
1421 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
|
1422 self._senders = {} |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
1423 |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
1424 def _show(self, sender): |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
1425 """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
|
1426 @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
|
1427 """ |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
1428 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
|
1429 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
|
1430 |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
1431 def button_cb(item): |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
1432 """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
|
1433 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
|
1434 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
|
1435 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
|
1436 @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
|
1437 """ |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
1438 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
|
1439 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
|
1440 self.hide(autoClosed=True) |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
1441 |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
1442 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
|
1443 entry = self._entries[_key] |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
1444 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
|
1445 continue |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
1446 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
|
1447 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
|
1448 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
|
1449 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
|
1450 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
|
1451 menu.add(item) |
242
a25aa882e09a
browser_side: add context menu for contact:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
1452 if len(menu.getChildren()) == 0: |
a25aa882e09a
browser_side: add context menu for contact:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
1453 return |
241
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
1454 self.add(menu) |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
1455 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
|
1456 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
|
1457 y = sender.getAbsoluteTop() |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
1458 else: |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
1459 x = sender.getAbsoluteLeft() |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
1460 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
|
1461 self.setPopupPosition(x, y) |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
1462 self.show() |
279
2d6bd975a72d
browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents:
276
diff
changeset
|
1463 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
|
1464 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
|
1465 |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
1466 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
|
1467 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
|
1468 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
|
1469 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
|
1470 |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
1471 self.onHideImpl = _onHide |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
1472 |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
1473 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
|
1474 """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
|
1475 @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
|
1476 @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
|
1477 """ |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
1478 self._senders.setdefault(sender, []) |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
1479 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
|
1480 |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
1481 if button == BUTTON_RIGHT: |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
1482 # 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
|
1483 # 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
|
1484 # 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
|
1485 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
|
1486 |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
1487 def _onBrowserEvent(event): |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
1488 button = DOM.eventGetButton(event) |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
1489 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
|
1490 self._show(sender) |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
1491 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
|
1492 |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
1493 sender.onBrowserEvent = _onBrowserEvent |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
1494 |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
1495 def registerMiddleClickSender(self, sender): |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
1496 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
|
1497 |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
1498 def registerRightClickSender(self, sender): |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
1499 self.registerClickSender(sender, BUTTON_RIGHT) |
264
2a93f8e6f989
browser_side: added class ToggleStackPanel
souliane <souliane@mailoo.org>
parents:
261
diff
changeset
|
1500 |
2a93f8e6f989
browser_side: added class ToggleStackPanel
souliane <souliane@mailoo.org>
parents:
261
diff
changeset
|
1501 |
2a93f8e6f989
browser_side: added class ToggleStackPanel
souliane <souliane@mailoo.org>
parents:
261
diff
changeset
|
1502 class ToggleStackPanel(StackPanel): |
2a93f8e6f989
browser_side: added class ToggleStackPanel
souliane <souliane@mailoo.org>
parents:
261
diff
changeset
|
1503 """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
|
1504 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
|
1505 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
|
1506 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
|
1507 """ |
2a93f8e6f989
browser_side: added class ToggleStackPanel
souliane <souliane@mailoo.org>
parents:
261
diff
changeset
|
1508 |
2a93f8e6f989
browser_side: added class ToggleStackPanel
souliane <souliane@mailoo.org>
parents:
261
diff
changeset
|
1509 def __init__(self, **kwargs): |
2a93f8e6f989
browser_side: added class ToggleStackPanel
souliane <souliane@mailoo.org>
parents:
261
diff
changeset
|
1510 StackPanel.__init__(self, **kwargs) |
2a93f8e6f989
browser_side: added class ToggleStackPanel
souliane <souliane@mailoo.org>
parents:
261
diff
changeset
|
1511 |
2a93f8e6f989
browser_side: added class ToggleStackPanel
souliane <souliane@mailoo.org>
parents:
261
diff
changeset
|
1512 def onBrowserEvent(self, event): |
2a93f8e6f989
browser_side: added class ToggleStackPanel
souliane <souliane@mailoo.org>
parents:
261
diff
changeset
|
1513 if DOM.eventGetType(event) == "click": |
2a93f8e6f989
browser_side: added class ToggleStackPanel
souliane <souliane@mailoo.org>
parents:
261
diff
changeset
|
1514 index = self.getDividerIndex(DOM.eventGetTarget(event)) |
2a93f8e6f989
browser_side: added class ToggleStackPanel
souliane <souliane@mailoo.org>
parents:
261
diff
changeset
|
1515 if index != -1: |
2a93f8e6f989
browser_side: added class ToggleStackPanel
souliane <souliane@mailoo.org>
parents:
261
diff
changeset
|
1516 self.toggleStack(index) |
2a93f8e6f989
browser_side: added class ToggleStackPanel
souliane <souliane@mailoo.org>
parents:
261
diff
changeset
|
1517 |
2a93f8e6f989
browser_side: added class ToggleStackPanel
souliane <souliane@mailoo.org>
parents:
261
diff
changeset
|
1518 def add(self, widget, stackText="", asHTML=False, visible=False): |
2a93f8e6f989
browser_side: added class ToggleStackPanel
souliane <souliane@mailoo.org>
parents:
261
diff
changeset
|
1519 StackPanel.add(self, widget, stackText, asHTML) |
2a93f8e6f989
browser_side: added class ToggleStackPanel
souliane <souliane@mailoo.org>
parents:
261
diff
changeset
|
1520 self.setStackVisible(self.getWidgetCount() - 1, visible) |
2a93f8e6f989
browser_side: added class ToggleStackPanel
souliane <souliane@mailoo.org>
parents:
261
diff
changeset
|
1521 |
2a93f8e6f989
browser_side: added class ToggleStackPanel
souliane <souliane@mailoo.org>
parents:
261
diff
changeset
|
1522 def toggleStack(self, index): |
2a93f8e6f989
browser_side: added class ToggleStackPanel
souliane <souliane@mailoo.org>
parents:
261
diff
changeset
|
1523 if index >= self.getWidgetCount(): |
2a93f8e6f989
browser_side: added class ToggleStackPanel
souliane <souliane@mailoo.org>
parents:
261
diff
changeset
|
1524 return |
2a93f8e6f989
browser_side: added class ToggleStackPanel
souliane <souliane@mailoo.org>
parents:
261
diff
changeset
|
1525 visible = not self.getWidget(index).getVisible() |
2a93f8e6f989
browser_side: added class ToggleStackPanel
souliane <souliane@mailoo.org>
parents:
261
diff
changeset
|
1526 self.setStackVisible(index, visible) |
2a93f8e6f989
browser_side: added class ToggleStackPanel
souliane <souliane@mailoo.org>
parents:
261
diff
changeset
|
1527 for listener in self.stackListeners: |
2a93f8e6f989
browser_side: added class ToggleStackPanel
souliane <souliane@mailoo.org>
parents:
261
diff
changeset
|
1528 listener.onStackChanged(self, index, visible) |