Mercurial > libervia-web
annotate browser_side/panels.py @ 351:c943fd54c90e
browser_side: heavy refactorisation for microblogs:
- RichTextEditor inheritates from BaseTextEditor
- stuff related to display/edition have been moved from MicroblogEntry to LightTextEditor and RichTextEditor. Now the editors has two modes for display/edition and the microblog bubble is actually the editor itself.
- RichTextEditor's display mode uses a LightTextEditor (this will be used for WYSIWYG edition)
- addressing stuff of RichTextEditor have been moved to a child class RichMessageEditor (used for the rich text editor when clicking on the button left to the unibox)
- handle blog titles
TODO:
- fix encode/decode errors when sending special chars
- fix images maximal width in the bubble
- rich content WYSIWYG edition
author | souliane <souliane@mailoo.org> |
---|---|
date | Wed, 12 Feb 2014 15:17:04 +0100 |
parents | f1b9ec412769 |
children | f4efffb9627c |
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 |
339
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
334
diff
changeset
|
4 # Libervia: a Salut à Toi frontend |
340 | 5 # Copyright (C) 2011, 2012, 2013, 2014 Jérôme Poisson <goffi@goffi.org> |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
6 |
339
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
334
diff
changeset
|
7 # This program is free software: you can redistribute it and/or modify |
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
334
diff
changeset
|
8 # it under the terms of the GNU Affero General Public License as published by |
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
334
diff
changeset
|
9 # the Free Software Foundation, either version 3 of the License, or |
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
334
diff
changeset
|
10 # (at your option) any later version. |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
11 |
339
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
334
diff
changeset
|
12 # This program is distributed in the hope that it will be useful, |
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
334
diff
changeset
|
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
334
diff
changeset
|
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
334
diff
changeset
|
15 # GNU Affero General Public License for more details. |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
16 |
339
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
334
diff
changeset
|
17 # You should have received a copy of the GNU Affero General Public License |
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
334
diff
changeset
|
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
19 |
226
744426c2b699
browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
223
diff
changeset
|
20 import pyjd # this is dummy in pyjs |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
21 from pyjamas.ui.SimplePanel import SimplePanel |
33 | 22 from pyjamas.ui.AbsolutePanel import AbsolutePanel |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
23 from pyjamas.ui.VerticalPanel import VerticalPanel |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
24 from pyjamas.ui.HorizontalPanel import HorizontalPanel |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
25 from pyjamas.ui.HTMLPanel import HTMLPanel |
181
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
26 from pyjamas.ui.Frame import Frame |
73
447dc8ac181b
Adrien's uniBox design integration + lastPopup style
Goffi <goffi@goffi.org>
parents:
71
diff
changeset
|
27 from pyjamas.ui.TextArea import TextArea |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
28 from pyjamas.ui.Label import Label |
83 | 29 from pyjamas.ui.Button import Button |
33 | 30 from pyjamas.ui.HTML import HTML |
83 | 31 from pyjamas.ui.Image import Image |
19 | 32 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
|
33 from pyjamas.ui.FlowPanel import FlowPanel |
282
ae3ec654836d
browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
34 from pyjamas.ui.KeyboardListener import KEY_ENTER, KEY_UP, KEY_DOWN, KeyboardHandler |
186
72bb1d845b6a
browser side: global resize on UniBox resize
Goffi <goffi@goffi.org>
parents:
185
diff
changeset
|
35 from pyjamas.ui.MouseListener import MouseHandler |
323
0b7934e75e76
misc: reorganization of the file panels.py + clean the modules import:
souliane <souliane@mailoo.org>
parents:
322
diff
changeset
|
36 from pyjamas.ui.FocusListener import FocusHandler |
33 | 37 from pyjamas.Timer import Timer |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
38 from pyjamas import DOM |
323
0b7934e75e76
misc: reorganization of the file panels.py + clean the modules import:
souliane <souliane@mailoo.org>
parents:
322
diff
changeset
|
39 from pyjamas import Window |
0b7934e75e76
misc: reorganization of the file panels.py + clean the modules import:
souliane <souliane@mailoo.org>
parents:
322
diff
changeset
|
40 from __pyjamas__ import doc |
0b7934e75e76
misc: reorganization of the file panels.py + clean the modules import:
souliane <souliane@mailoo.org>
parents:
322
diff
changeset
|
41 |
0b7934e75e76
misc: reorganization of the file panels.py + clean the modules import:
souliane <souliane@mailoo.org>
parents:
322
diff
changeset
|
42 from tools import html_sanitize, setPresenceStyle |
349
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
43 from base_panels import ChatText, OccupantsList, PopupMenuPanel, BaseTextEditor, LightTextEditor |
323
0b7934e75e76
misc: reorganization of the file panels.py + clean the modules import:
souliane <souliane@mailoo.org>
parents:
322
diff
changeset
|
44 from datetime import datetime |
0b7934e75e76
misc: reorganization of the file panels.py + clean the modules import:
souliane <souliane@mailoo.org>
parents:
322
diff
changeset
|
45 from time import time |
78
12680e220b35
browser side: refactoring: menu is now in its own module
Goffi <goffi@goffi.org>
parents:
75
diff
changeset
|
46 from card_game import CardPanel |
127 | 47 from radiocol import RadioColPanel |
78
12680e220b35
browser side: refactoring: menu is now in its own module
Goffi <goffi@goffi.org>
parents:
75
diff
changeset
|
48 from menu import Menu |
19 | 49 from jid import JID |
48
153de5d461a4
added Social Contract \o. (in French only so far)
Goffi <goffi@goffi.org>
parents:
43
diff
changeset
|
50 import dialog |
195 | 51 import base_widget |
282
ae3ec654836d
browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
52 import richtext |
323
0b7934e75e76
misc: reorganization of the file panels.py + clean the modules import:
souliane <souliane@mailoo.org>
parents:
322
diff
changeset
|
53 |
0b7934e75e76
misc: reorganization of the file panels.py + clean the modules import:
souliane <souliane@mailoo.org>
parents:
322
diff
changeset
|
54 from constants import Const |
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 |
349
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
56 from sat_frontends.tools.strings import addURLToText |
276
aebb96bfa8d1
frontends tools: moved src/tools/frontends to frontends/src/tools
souliane <souliane@mailoo.org>
parents:
275
diff
changeset
|
57 from sat_frontends.tools.games import SYMBOLS |
349
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
58 from sat.core.i18n import _ |
323
0b7934e75e76
misc: reorganization of the file panels.py + clean the modules import:
souliane <souliane@mailoo.org>
parents:
322
diff
changeset
|
59 |
279
2d6bd975a72d
browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents:
276
diff
changeset
|
60 |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
231
diff
changeset
|
61 class UniBoxPanel(HorizontalPanel): |
33 | 62 """Panel containing the UniBox""" |
63 | |
64 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
|
65 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
|
66 self.host = host |
33 | 67 self.setStyleName('uniBoxPanel') |
309
05e264e96a1c
browser_side: make unibox optional
souliane <souliane@mailoo.org>
parents:
307
diff
changeset
|
68 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
|
69 |
326
36927be51481
browser_side: fixed the behavior regarding "Enable unibox" parameter:
souliane <souliane@mailoo.org>
parents:
323
diff
changeset
|
70 def refresh(self): |
36927be51481
browser_side: fixed the behavior regarding "Enable unibox" parameter:
souliane <souliane@mailoo.org>
parents:
323
diff
changeset
|
71 """Enable or disable this panel. Contained widgets are created when necessary.""" |
36927be51481
browser_side: fixed the behavior regarding "Enable unibox" parameter:
souliane <souliane@mailoo.org>
parents:
323
diff
changeset
|
72 enable = self.host.params_ui['unibox']['value'] |
36927be51481
browser_side: fixed the behavior regarding "Enable unibox" parameter:
souliane <souliane@mailoo.org>
parents:
323
diff
changeset
|
73 self.setVisible(enable) |
36927be51481
browser_side: fixed the behavior regarding "Enable unibox" parameter:
souliane <souliane@mailoo.org>
parents:
323
diff
changeset
|
74 if enable and not self.unibox: |
351
c943fd54c90e
browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents:
350
diff
changeset
|
75 self.button = Button('<img src="media/icons/tango/actions/32/format-text-italic.png" class="richTextIcon"/>') |
309
05e264e96a1c
browser_side: make unibox optional
souliane <souliane@mailoo.org>
parents:
307
diff
changeset
|
76 self.button.setTitle('Open the rich text editor') |
05e264e96a1c
browser_side: make unibox optional
souliane <souliane@mailoo.org>
parents:
307
diff
changeset
|
77 self.button.addStyleName('uniBoxButton') |
05e264e96a1c
browser_side: make unibox optional
souliane <souliane@mailoo.org>
parents:
307
diff
changeset
|
78 self.add(self.button) |
05e264e96a1c
browser_side: make unibox optional
souliane <souliane@mailoo.org>
parents:
307
diff
changeset
|
79 self.unibox = UniBox(self.host) |
05e264e96a1c
browser_side: make unibox optional
souliane <souliane@mailoo.org>
parents:
307
diff
changeset
|
80 self.add(self.unibox) |
05e264e96a1c
browser_side: make unibox optional
souliane <souliane@mailoo.org>
parents:
307
diff
changeset
|
81 self.setCellWidth(self.unibox, '100%') |
351
c943fd54c90e
browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents:
350
diff
changeset
|
82 self.button.addClickListener(self.openRichMessageEditor) |
309
05e264e96a1c
browser_side: make unibox optional
souliane <souliane@mailoo.org>
parents:
307
diff
changeset
|
83 self.unibox.addKey("@@: ") |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
231
diff
changeset
|
84 |
351
c943fd54c90e
browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents:
350
diff
changeset
|
85 def openRichMessageEditor(self): |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
231
diff
changeset
|
86 """Open the rich text editor.""" |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
231
diff
changeset
|
87 self.button.setVisible(False) |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
231
diff
changeset
|
88 self.unibox.setVisible(False) |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
231
diff
changeset
|
89 self.setCellWidth(self.unibox, '0px') |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
231
diff
changeset
|
90 self.host.panel._contactsMove(self) |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
231
diff
changeset
|
91 |
351
c943fd54c90e
browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents:
350
diff
changeset
|
92 def afterEditCb(): |
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
|
93 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
|
94 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
|
95 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
|
96 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
|
97 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
|
98 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
|
99 |
351
c943fd54c90e
browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents:
350
diff
changeset
|
100 richtext.RichMessageEditor.getOrCreate(self.host, self, afterEditCb) |
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
|
101 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
|
102 self.host.resize() |
33 | 103 |
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
|
104 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
|
105 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
|
106 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
|
107 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
|
108 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
|
109 |
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
|
110 |
310
5d11ec1f2c22
browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents:
309
diff
changeset
|
111 class MessageBox(TextArea): |
5d11ec1f2c22
browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents:
309
diff
changeset
|
112 """A basic text area for entering messages""" |
33 | 113 |
114 def __init__(self, host): | |
73
447dc8ac181b
Adrien's uniBox design integration + lastPopup style
Goffi <goffi@goffi.org>
parents:
71
diff
changeset
|
115 TextArea.__init__(self) |
310
5d11ec1f2c22
browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents:
309
diff
changeset
|
116 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
|
117 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
|
118 self.setStyleName('messageBox') |
83 | 119 self.addKeyboardListener(self) |
186
72bb1d845b6a
browser side: global resize on UniBox resize
Goffi <goffi@goffi.org>
parents:
185
diff
changeset
|
120 MouseHandler.__init__(self) |
72bb1d845b6a
browser side: global resize on UniBox resize
Goffi <goffi@goffi.org>
parents:
185
diff
changeset
|
121 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
|
122 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
|
123 |
5d11ec1f2c22
browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents:
309
diff
changeset
|
124 def onBrowserEvent(self, event): |
5d11ec1f2c22
browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents:
309
diff
changeset
|
125 # 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
|
126 # 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
|
127 # 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
|
128 self.currentEvent = event |
5d11ec1f2c22
browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents:
309
diff
changeset
|
129 TextArea.onBrowserEvent(self, event) |
5d11ec1f2c22
browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents:
309
diff
changeset
|
130 |
5d11ec1f2c22
browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents:
309
diff
changeset
|
131 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
|
132 _txt = self.getText() |
5d11ec1f2c22
browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents:
309
diff
changeset
|
133 |
5d11ec1f2c22
browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents:
309
diff
changeset
|
134 def history_cb(text): |
5d11ec1f2c22
browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents:
309
diff
changeset
|
135 self.setText(text) |
5d11ec1f2c22
browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents:
309
diff
changeset
|
136 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
|
137 |
5d11ec1f2c22
browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents:
309
diff
changeset
|
138 if keycode == KEY_ENTER: |
5d11ec1f2c22
browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents:
309
diff
changeset
|
139 if _txt: |
5d11ec1f2c22
browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents:
309
diff
changeset
|
140 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
|
141 self.host._updateInputHistory(_txt) |
5d11ec1f2c22
browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents:
309
diff
changeset
|
142 self.setText('') |
5d11ec1f2c22
browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents:
309
diff
changeset
|
143 sender.cancelKey() |
5d11ec1f2c22
browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents:
309
diff
changeset
|
144 elif keycode == KEY_UP: |
5d11ec1f2c22
browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents:
309
diff
changeset
|
145 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
|
146 elif keycode == KEY_DOWN: |
5d11ec1f2c22
browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents:
309
diff
changeset
|
147 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
|
148 else: |
5d11ec1f2c22
browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents:
309
diff
changeset
|
149 self.__onComposing() |
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 def __onComposing(self): |
5d11ec1f2c22
browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents:
309
diff
changeset
|
152 """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
|
153 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
|
154 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
|
155 |
5d11ec1f2c22
browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents:
309
diff
changeset
|
156 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
|
157 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
|
158 if size != self.__size: |
5d11ec1f2c22
browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents:
309
diff
changeset
|
159 self.__size = size |
5d11ec1f2c22
browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents:
309
diff
changeset
|
160 self.host.resize() |
5d11ec1f2c22
browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents:
309
diff
changeset
|
161 |
5d11ec1f2c22
browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents:
309
diff
changeset
|
162 def onSelectedChange(self, selected): |
5d11ec1f2c22
browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents:
309
diff
changeset
|
163 self._selected_cache = selected |
5d11ec1f2c22
browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents:
309
diff
changeset
|
164 |
5d11ec1f2c22
browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents:
309
diff
changeset
|
165 |
5d11ec1f2c22
browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents:
309
diff
changeset
|
166 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
|
167 """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
|
168 |
5d11ec1f2c22
browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents:
309
diff
changeset
|
169 def __init__(self, host): |
5d11ec1f2c22
browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents:
309
diff
changeset
|
170 MessageBox.__init__(self, host) |
5d11ec1f2c22
browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents:
309
diff
changeset
|
171 #AutoCompleteTextBox.__init__(self) |
5d11ec1f2c22
browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents:
309
diff
changeset
|
172 self.setStyleName('uniBox') |
5d11ec1f2c22
browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents:
309
diff
changeset
|
173 self._popup = None |
5d11ec1f2c22
browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents:
309
diff
changeset
|
174 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
|
175 host.addSelectedListener(self.onSelectedChange) |
33 | 176 |
177 def addKey(self, key): | |
73
447dc8ac181b
Adrien's uniBox design integration + lastPopup style
Goffi <goffi@goffi.org>
parents:
71
diff
changeset
|
178 return |
447dc8ac181b
Adrien's uniBox design integration + lastPopup style
Goffi <goffi@goffi.org>
parents:
71
diff
changeset
|
179 #self.getCompletionItems().completions.append(key) |
33 | 180 |
55
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
181 def removeKey(self, key): |
255
da0487f0a2e7
browser_side: small changes to prepare the contact group manager:
souliane <souliane@mailoo.org>
parents:
249
diff
changeset
|
182 return |
da0487f0a2e7
browser_side: small changes to prepare the contact group manager:
souliane <souliane@mailoo.org>
parents:
249
diff
changeset
|
183 # 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
|
184 # 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
|
185 # 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
|
186 try: |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
187 self.getCompletionItems().completions.remove(key) |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
188 except KeyError: |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
189 print "WARNING: trying to remove an unknown key" |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
190 |
33 | 191 def showWarning(self, target_data): |
201
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
192 target_hook, _type, msg = target_data |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
193 if _type == "NONE": |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
194 return |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
195 if not msg: |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
196 print "WARNING: no msg set uniBox warning" |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
197 return |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
198 if _type == "PUBLIC": |
33 | 199 style = "targetPublic" |
201
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
200 elif _type == "GROUP": |
33 | 201 style = "targetGroup" |
201
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
202 elif _type == "STATUS": |
33 | 203 msg = "This will be your new status message" |
204 style = "targetStatus" | |
201
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
205 elif _type == "ONE2ONE": |
33 | 206 style = "targetOne2One" |
207 else: | |
201
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
208 print "ERROR: unknown message type" |
33 | 209 return |
210 contents = HTML(msg) | |
211 | |
48
153de5d461a4
added Social Contract \o. (in French only so far)
Goffi <goffi@goffi.org>
parents:
43
diff
changeset
|
212 self._popup = dialog.PopupPanelWrapper(autoHide=False, modal=False) |
33 | 213 self._popup.target_data = target_data |
214 self._popup.add(contents) | |
215 self._popup.setStyleName("warningPopup") | |
216 if style: | |
217 self._popup.addStyleName(style) | |
218 | |
219 left = 0 | |
226
744426c2b699
browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
223
diff
changeset
|
220 top = 0 # max(0, self.getAbsoluteTop() - contents.getOffsetHeight() - 2) |
33 | 221 self._popup.setPopupPosition(left, top) |
222 self._popup.show() | |
223 | |
224 def _timeCb(self, timer): | |
225 if self._popup: | |
226 self._popup.hide() | |
227 del self._popup | |
228 self._popup = None | |
229 | |
230 def _getTarget(self, txt): | |
201
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
231 """ Say who will receive the messsage |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
232 @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
|
233 - 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
|
234 - 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
|
235 - 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
|
236 target = self._selected_cache |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
237 |
201
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
238 def getSelectedOrStatus(): |
294
a6b3715f0bd6
browser_side: bug fixes for switching between unibox and rich text editor:
souliane <souliane@mailoo.org>
parents:
293
diff
changeset
|
239 if target and target.isSelectable(): |
201
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
240 _type, msg = target.getWarningData() |
226
744426c2b699
browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
223
diff
changeset
|
241 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
|
242 else: |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
243 _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
|
244 target_hook = (txt, None) |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
245 return (target_hook, _type, msg) |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
246 |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
247 if not txt.startswith('@'): |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
248 target_hook, _type, msg = getSelectedOrStatus() |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
249 elif txt.startswith('@@: '): |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
250 _type = "PUBLIC" |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
251 msg = MicroblogPanel.warning_msg_public |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
252 target_hook = (txt[4:], None) |
33 | 253 elif txt.startswith('@'): |
254 _end = txt.find(': ') | |
255 if _end == -1: | |
201
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
256 target_hook, _type, msg = getSelectedOrStatus() |
33 | 257 else: |
226
744426c2b699
browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
223
diff
changeset
|
258 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
|
259 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
|
260 # 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
|
261 group = None |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
262 target_hook, _type, msg = getSelectedOrStatus() |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
263 else: |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
264 _type = "GROUP" |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
265 msg = MicroblogPanel.warning_msg_group % group |
226
744426c2b699
browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
223
diff
changeset
|
266 target_hook = (txt[_end + 2:], group) |
33 | 267 else: |
201
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
268 print "ERROR: Unknown target" |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
269 target_hook, _type, msg = getSelectedOrStatus() |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
270 |
201
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
271 return (target_hook, _type, msg) |
33 | 272 |
273 def onKeyPress(self, sender, keycode, modifiers): | |
274 _txt = self.getText() | |
201
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
275 target = self._getTarget(_txt) |
33 | 276 if not self._popup: |
201
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
277 self.showWarning(target) |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
278 elif target != self._popup.target_data: |
226
744426c2b699
browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
223
diff
changeset
|
279 self._timeCb(None) # we remove the popup |
201
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
280 self.showWarning(target) |
33 | 281 |
282 self._timer.schedule(2000) | |
283 | |
83 | 284 if keycode == KEY_ENTER: |
33 | 285 if _txt: |
269
9eb9c7d41bdc
browser_side: added generic method "send" in SatWebFrontend
souliane <souliane@mailoo.org>
parents:
267
diff
changeset
|
286 target_hook, type_, msg = target |
201
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
287 if target_hook: |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
288 parsed_txt, data = target_hook |
269
9eb9c7d41bdc
browser_side: added generic method "send" in SatWebFrontend
souliane <souliane@mailoo.org>
parents:
267
diff
changeset
|
289 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
|
290 self.host._updateInputHistory(_txt) |
5d11ec1f2c22
browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents:
309
diff
changeset
|
291 self.setText('') |
226
744426c2b699
browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
223
diff
changeset
|
292 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
|
293 MessageBox.onKeyPress(self, sender, keycode, modifiers) |
214
7b26be266ab1
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
213
diff
changeset
|
294 |
231
fab7aa366576
browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents:
230
diff
changeset
|
295 def getTargetAndData(self): |
fab7aa366576
browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents:
230
diff
changeset
|
296 """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
|
297 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
|
298 @return a tuple (target, data) with: |
fab7aa366576
browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents:
230
diff
changeset
|
299 - 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
|
300 - 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
|
301 """ |
fab7aa366576
browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents:
230
diff
changeset
|
302 _txt = self.getText() |
fab7aa366576
browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents:
230
diff
changeset
|
303 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
|
304 if target_hook: |
fab7aa366576
browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents:
230
diff
changeset
|
305 data, target = target_hook |
fab7aa366576
browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents:
230
diff
changeset
|
306 if target is None: |
fab7aa366576
browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents:
230
diff
changeset
|
307 return target_hook |
fab7aa366576
browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents:
230
diff
changeset
|
308 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
|
309 if isinstance(self._selected_cache, MicroblogPanel): |
fab7aa366576
browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents:
230
diff
changeset
|
310 groups = self._selected_cache.accepted_groups |
fab7aa366576
browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents:
230
diff
changeset
|
311 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
|
312 if len(groups) > 1: |
fab7aa366576
browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents:
230
diff
changeset
|
313 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
|
314 elif isinstance(self._selected_cache, ChatPanel): |
fab7aa366576
browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents:
230
diff
changeset
|
315 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
|
316 else: |
a6b3715f0bd6
browser_side: bug fixes for switching between unibox and rich text editor:
souliane <souliane@mailoo.org>
parents:
293
diff
changeset
|
317 target = None |
231
fab7aa366576
browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents:
230
diff
changeset
|
318 return (_txt, target) |
fab7aa366576
browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents:
230
diff
changeset
|
319 |
294
a6b3715f0bd6
browser_side: bug fixes for switching between unibox and rich text editor:
souliane <souliane@mailoo.org>
parents:
293
diff
changeset
|
320 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
|
321 """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
|
322 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
|
323 self.onSelectedChange(None) |
a6b3715f0bd6
browser_side: bug fixes for switching between unibox and rich text editor:
souliane <souliane@mailoo.org>
parents:
293
diff
changeset
|
324 |
73
447dc8ac181b
Adrien's uniBox design integration + lastPopup style
Goffi <goffi@goffi.org>
parents:
71
diff
changeset
|
325 """def complete(self): |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
326 |
33 | 327 #self.visible=False #XXX: self.visible is not unset in pyjamas when ENTER is pressed and a completion is done |
328 #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
|
329 return AutoCompleteTextBox.complete(self)""" |
33 | 330 |
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
|
331 |
132
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
332 class MicroblogItem(): |
226
744426c2b699
browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
223
diff
changeset
|
333 # 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
|
334 |
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
335 def __init__(self, data): |
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
336 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
|
337 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
|
338 self.empty = data.get('new', False) |
351
c943fd54c90e
browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents:
350
diff
changeset
|
339 self.title = data.get('title', '') |
c943fd54c90e
browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents:
350
diff
changeset
|
340 self.title_xhtml = data.get('title_xhtml', '') |
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
|
341 self.content = data.get('content', '') |
351
c943fd54c90e
browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents:
350
diff
changeset
|
342 self.content_xhtml = data.get('content_xhtml', '') |
132
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
343 self.author = data['author'] |
307
44b46db7dfef
browser_side (groupblog): order items using "published" instead of "updated"
souliane <souliane@mailoo.org>
parents:
306
diff
changeset
|
344 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
|
345 try: |
44b46db7dfef
browser_side (groupblog): order items using "published" instead of "updated"
souliane <souliane@mailoo.org>
parents:
306
diff
changeset
|
346 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
|
347 except KeyError: |
44b46db7dfef
browser_side (groupblog): order items using "published" instead of "updated"
souliane <souliane@mailoo.org>
parents:
306
diff
changeset
|
348 self.published = self.updated |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
349 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
|
350 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
|
351 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
|
352 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
|
353 else: |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
354 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
|
355 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
|
356 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
|
357 self.hash = (self.service, self.node) |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
358 except KeyError: |
334
9c6be29c714a
browser side: removed logging imports: it's not working correctly with pyjamas
Goffi <goffi@goffi.org>
parents:
326
diff
changeset
|
359 print "Warning: can't manage item [%s] some keys are missing in microblog data (%s)" % (self.id, str(data)) |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
360 self.comments = False |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
361 |
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
|
362 |
282
ae3ec654836d
browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
363 class MicroblogEntry(SimplePanel, ClickHandler, FocusHandler, KeyboardHandler): |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
364 |
350
f1b9ec412769
browser_side: MicroblogEntry defines properties to access MicroblogItem attributes (instead of overwriting __getattr__)
souliane <souliane@mailoo.org>
parents:
349
diff
changeset
|
365 def __init__(self, blog_panel, data): |
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 """ |
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 @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
|
368 @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
|
369 """ |
350
f1b9ec412769
browser_side: MicroblogEntry defines properties to access MicroblogItem attributes (instead of overwriting __getattr__)
souliane <souliane@mailoo.org>
parents:
349
diff
changeset
|
370 self._base_item = data if isinstance(data, MicroblogItem) else MicroblogItem(data) |
f1b9ec412769
browser_side: MicroblogEntry defines properties to access MicroblogItem attributes (instead of overwriting __getattr__)
souliane <souliane@mailoo.org>
parents:
349
diff
changeset
|
371 for attr in ['id', 'type', 'empty', 'title', 'title_xhtml', 'content', 'content_xhtml', |
f1b9ec412769
browser_side: MicroblogEntry defines properties to access MicroblogItem attributes (instead of overwriting __getattr__)
souliane <souliane@mailoo.org>
parents:
349
diff
changeset
|
372 'author', 'updated', 'published', 'comments', 'service', 'node', 'hash']: |
f1b9ec412769
browser_side: MicroblogEntry defines properties to access MicroblogItem attributes (instead of overwriting __getattr__)
souliane <souliane@mailoo.org>
parents:
349
diff
changeset
|
373 getter = lambda attr: lambda inst: getattr(inst._base_item, attr) |
f1b9ec412769
browser_side: MicroblogEntry defines properties to access MicroblogItem attributes (instead of overwriting __getattr__)
souliane <souliane@mailoo.org>
parents:
349
diff
changeset
|
374 setattr(MicroblogEntry, attr, property(getter(attr))) |
f1b9ec412769
browser_side: MicroblogEntry defines properties to access MicroblogItem attributes (instead of overwriting __getattr__)
souliane <souliane@mailoo.org>
parents:
349
diff
changeset
|
375 |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
376 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
|
377 self._blog_panel = blog_panel |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
378 |
291
89818bca1a33
browser_side: set the ideal width for the blog post update dialog
souliane <souliane@mailoo.org>
parents:
289
diff
changeset
|
379 self.panel = FlowPanel() |
89818bca1a33
browser_side: set the ideal width for the blog post update dialog
souliane <souliane@mailoo.org>
parents:
289
diff
changeset
|
380 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
|
381 |
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
|
382 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
|
383 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
|
384 |
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
|
385 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
|
386 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
|
387 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
|
388 |
89818bca1a33
browser_side: set the ideal width for the blog post update dialog
souliane <souliane@mailoo.org>
parents:
289
diff
changeset
|
389 entry_avatar = SimplePanel() |
89818bca1a33
browser_side: set the ideal width for the blog post update dialog
souliane <souliane@mailoo.org>
parents:
289
diff
changeset
|
390 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
|
391 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
|
392 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
|
393 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
|
394 |
89818bca1a33
browser_side: set the ideal width for the blog post update dialog
souliane <souliane@mailoo.org>
parents:
289
diff
changeset
|
395 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
|
396 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
|
397 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
|
398 |
119 | 399 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
|
400 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
|
401 self.addClickListener(self) |
119 | 402 |
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
|
403 self.pub_data = (self.hash[0], self.hash[1], self.id) |
351
c943fd54c90e
browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents:
350
diff
changeset
|
404 self.__setContent() |
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
|
405 |
351
c943fd54c90e
browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents:
350
diff
changeset
|
406 def __setContent(self): |
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
|
407 """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
|
408 self.delete_label = self.update_label = self.comment_label = None |
351
c943fd54c90e
browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents:
350
diff
changeset
|
409 self.bubble = self._current_comment = None |
c943fd54c90e
browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents:
350
diff
changeset
|
410 self.__setHeader() |
c943fd54c90e
browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents:
350
diff
changeset
|
411 self.__setBubble() |
c943fd54c90e
browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents:
350
diff
changeset
|
412 self.__setIcons() |
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
|
413 |
351
c943fd54c90e
browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents:
350
diff
changeset
|
414 def __setHeader(self): |
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
|
415 """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
|
416 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
|
417 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
|
418 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
|
419 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
|
420 <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
|
421 <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
|
422 </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
|
423 '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
|
424 '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
|
425 } |
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 ) |
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 |
351
c943fd54c90e
browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents:
350
diff
changeset
|
428 def __setIcons(self): |
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
|
429 """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
|
430 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
|
431 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
|
432 |
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 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
|
434 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
|
435 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
|
436 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
|
437 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
|
438 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
|
439 |
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 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
|
441 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
|
442 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
|
443 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
|
444 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
|
445 |
119 | 446 def updateAvatar(self, new_avatar): |
447 """Change the avatar of the entry | |
448 @param new_avatar: path to the new image""" | |
449 self.avatar.setUrl(new_avatar) | |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
450 |
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
|
451 def onClick(self, sender): |
282
ae3ec654836d
browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
452 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
|
453 self._blog_panel.setSelectedEntry(self) |
282
ae3ec654836d
browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
454 elif sender == self.delete_label: |
ae3ec654836d
browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
455 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
|
456 elif sender == self.update_label: |
351
c943fd54c90e
browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents:
350
diff
changeset
|
457 self.bubble.edit(True) |
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
|
458 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
|
459 self._comment() |
282
ae3ec654836d
browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
460 |
351
c943fd54c90e
browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents:
350
diff
changeset
|
461 def __modifiedCb(self, content): |
c943fd54c90e
browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents:
350
diff
changeset
|
462 """Send the new content to the backend |
c943fd54c90e
browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents:
350
diff
changeset
|
463 @return: False to restore the original content if a deletion has been cancelled |
c943fd54c90e
browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents:
350
diff
changeset
|
464 """ |
c943fd54c90e
browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents:
350
diff
changeset
|
465 if not content['text']: # previous content has been emptied |
c943fd54c90e
browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents:
350
diff
changeset
|
466 self._delete(True) |
c943fd54c90e
browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents:
350
diff
changeset
|
467 return False |
307
44b46db7dfef
browser_side (groupblog): order items using "published" instead of "updated"
souliane <souliane@mailoo.org>
parents:
306
diff
changeset
|
468 extra = {'published': str(self.published)} |
351
c943fd54c90e
browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents:
350
diff
changeset
|
469 if self.empty or self.content_xhtml: |
c943fd54c90e
browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents:
350
diff
changeset
|
470 # TODO: if the user change his parameters after the message edition started, |
c943fd54c90e
browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents:
350
diff
changeset
|
471 # the message syntax could be different then the current syntax: pass the |
c943fd54c90e
browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents:
350
diff
changeset
|
472 # message syntax in extra for the frontend to use it instead of current syntax. |
c943fd54c90e
browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents:
350
diff
changeset
|
473 extra.update({'content_rich': content['text'], 'title': content['title']}) |
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
|
474 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
|
475 if self.type == 'main_item': |
351
c943fd54c90e
browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents:
350
diff
changeset
|
476 self._blog_panel.host.bridge.call('sendMblog', None, None, self._blog_panel.accepted_groups, content['text'], extra) |
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
|
477 else: |
351
c943fd54c90e
browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents:
350
diff
changeset
|
478 self._blog_panel.host.bridge.call('sendMblogComment', None, self._parent_entry.comments, content['text'], extra) |
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
|
479 else: |
351
c943fd54c90e
browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents:
350
diff
changeset
|
480 self._blog_panel.host.bridge.call('updateMblog', None, self.pub_data, self.comments, content['text'], extra) |
c943fd54c90e
browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents:
350
diff
changeset
|
481 return True |
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
|
482 |
351
c943fd54c90e
browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents:
350
diff
changeset
|
483 def __afterEditCb(self, content): |
c943fd54c90e
browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents:
350
diff
changeset
|
484 """Remove the entry if it was an empty one (used for creating a new blog post). |
c943fd54c90e
browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents:
350
diff
changeset
|
485 Data for the actual new blog post will be received from the bridge""" |
c943fd54c90e
browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents:
350
diff
changeset
|
486 if self.empty: |
c943fd54c90e
browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents:
350
diff
changeset
|
487 self._blog_panel.removeEntry(self.type, self.id) |
c943fd54c90e
browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents:
350
diff
changeset
|
488 if self.type == 'main_item': # restore the "New message" button |
c943fd54c90e
browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents:
350
diff
changeset
|
489 self._blog_panel.refresh() |
c943fd54c90e
browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents:
350
diff
changeset
|
490 else: # allow to create a new comment |
c943fd54c90e
browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents:
350
diff
changeset
|
491 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
|
492 |
351
c943fd54c90e
browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents:
350
diff
changeset
|
493 def __setBubble(self): |
c943fd54c90e
browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents:
350
diff
changeset
|
494 """Set the bubble displaying the initial content.""" |
c943fd54c90e
browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents:
350
diff
changeset
|
495 content = {'text': self.content_xhtml if self.content_xhtml else self.content, |
c943fd54c90e
browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents:
350
diff
changeset
|
496 'title': self.title_xhtml if self.title_xhtml else self.title} |
c943fd54c90e
browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents:
350
diff
changeset
|
497 if self.empty or self.content_xhtml: # new message and rich text message |
c943fd54c90e
browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents:
350
diff
changeset
|
498 content.update({'syntax': Const.SYNTAX_XHTML}) |
c943fd54c90e
browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents:
350
diff
changeset
|
499 if self.author != self._blog_panel.host.whoami.bare: |
c943fd54c90e
browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents:
350
diff
changeset
|
500 options = ['read_only'] |
c943fd54c90e
browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents:
350
diff
changeset
|
501 else: |
c943fd54c90e
browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents:
350
diff
changeset
|
502 options = [] if self.empty else ['update_msg'] |
c943fd54c90e
browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents:
350
diff
changeset
|
503 self.bubble = richtext.RichTextEditor(self._blog_panel.host, content, self.__modifiedCb, self.__afterEditCb, options) |
c943fd54c90e
browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents:
350
diff
changeset
|
504 else: # assume raw text message have no title |
c943fd54c90e
browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents:
350
diff
changeset
|
505 self.bubble = LightTextEditor(content, self.__modifiedCb, self.__afterEditCb, True) |
c943fd54c90e
browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents:
350
diff
changeset
|
506 self.bubble.setStyleName("bubble") |
c943fd54c90e
browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents:
350
diff
changeset
|
507 self.entry_dialog.add(self.bubble) |
c943fd54c90e
browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents:
350
diff
changeset
|
508 self.bubble.edit(False) |
282
ae3ec654836d
browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
509 |
351
c943fd54c90e
browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents:
350
diff
changeset
|
510 def _delete(self, empty=False): |
c943fd54c90e
browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents:
350
diff
changeset
|
511 """Ask confirmation for deletion. |
c943fd54c90e
browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents:
350
diff
changeset
|
512 @return: False if the deletion has been cancelled.""" |
282
ae3ec654836d
browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
513 def confirm_cb(answer): |
ae3ec654836d
browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
514 if answer: |
ae3ec654836d
browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
515 self._blog_panel.host.bridge.call('deleteMblog', None, self.pub_data, self.comments) |
351
c943fd54c90e
browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents:
350
diff
changeset
|
516 else: # restore the text if it has been emptied during the edition |
c943fd54c90e
browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents:
350
diff
changeset
|
517 self.bubble.setContent(self.bubble._original_content) |
282
ae3ec654836d
browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
518 |
351
c943fd54c90e
browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents:
350
diff
changeset
|
519 if self.empty: |
c943fd54c90e
browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents:
350
diff
changeset
|
520 text = _("New ") + (_("message") if self.comments else _("comment")) + _(" without body has been cancelled.") |
c943fd54c90e
browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents:
350
diff
changeset
|
521 dialog.InfoDialog(_("Information"), text).show() |
c943fd54c90e
browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents:
350
diff
changeset
|
522 return |
c943fd54c90e
browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents:
350
diff
changeset
|
523 text = "" |
c943fd54c90e
browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents:
350
diff
changeset
|
524 if empty: |
c943fd54c90e
browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents:
350
diff
changeset
|
525 text = (_("Message") if self.comments else _("Comment")) + _(" body has been emptied.<br/>") |
c943fd54c90e
browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents:
350
diff
changeset
|
526 target = _('message and all its comments') if self.comments else _('comment') |
c943fd54c90e
browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents:
350
diff
changeset
|
527 text += _("Do you really want to delete this %s?") % target |
c943fd54c90e
browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents:
350
diff
changeset
|
528 dialog.ConfirmDialog(confirm_cb, text=text).show() |
119 | 529 |
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
|
530 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
|
531 """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
|
532 if self._current_comment: |
351
c943fd54c90e
browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents:
350
diff
changeset
|
533 self._current_comment.bubble.setFocus(True) |
315
09205b410a53
browser_side: handle successive click on blog post "edit" and "comment" icons
souliane <souliane@mailoo.org>
parents:
314
diff
changeset
|
534 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
|
535 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
|
536 '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
|
537 '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
|
538 '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
|
539 '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
|
540 '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
|
541 } |
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
|
542 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
|
543 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
|
544 self._current_comment = entry |
351
c943fd54c90e
browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents:
350
diff
changeset
|
545 entry.bubble.edit(True) |
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 |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
547 |
195 | 548 class MicroblogPanel(base_widget.LiberviaWidget): |
201
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
549 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
|
550 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
|
551 |
132
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
552 def __init__(self, host, accepted_groups): |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
553 """Panel used to show microblog |
132
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
554 @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
|
555 """ |
230
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
556 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
|
557 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
|
558 self.host = host |
58
4fa3d57f72f8
browser side: microblog entries caching
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
559 self.entries = {} |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
560 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
|
561 self.selected_entry = None |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
562 self.vpanel = VerticalPanel() |
83 | 563 self.vpanel.setStyleName('microblogPanel') |
34 | 564 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
|
565 |
326
36927be51481
browser_side: fixed the behavior regarding "Enable unibox" parameter:
souliane <souliane@mailoo.org>
parents:
323
diff
changeset
|
566 def refresh(self): |
36927be51481
browser_side: fixed the behavior regarding "Enable unibox" parameter:
souliane <souliane@mailoo.org>
parents:
323
diff
changeset
|
567 """Refresh the display of this widget. If the unibox is disabled, |
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
|
568 display the 'New message' button on top of the panel""" |
326
36927be51481
browser_side: fixed the behavior regarding "Enable unibox" parameter:
souliane <souliane@mailoo.org>
parents:
323
diff
changeset
|
569 enable_button = self.host.uni_box is 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
|
570 if hasattr(self, 'new_button'): |
326
36927be51481
browser_side: fixed the behavior regarding "Enable unibox" parameter:
souliane <souliane@mailoo.org>
parents:
323
diff
changeset
|
571 self.new_button.setVisible(enable_button) |
36927be51481
browser_side: fixed the behavior regarding "Enable unibox" parameter:
souliane <souliane@mailoo.org>
parents:
323
diff
changeset
|
572 return |
36927be51481
browser_side: fixed the behavior regarding "Enable unibox" parameter:
souliane <souliane@mailoo.org>
parents:
323
diff
changeset
|
573 if enable_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
|
574 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
|
575 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
|
576 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
|
577 '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
|
578 '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
|
579 } |
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 entry = self.addEntry(data) |
351
c943fd54c90e
browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents:
350
diff
changeset
|
581 entry.bubble.edit(True) |
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.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
|
583 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
|
584 self.vpanel.insert(self.new_button, 0) |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
585 |
195 | 586 @classmethod |
587 def registerClass(cls): | |
230
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
588 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
|
589 base_widget.LiberviaWidget.addDropKey("CONTACT_TITLE", cls.createMetaPanel) |
195 | 590 |
591 @classmethod | |
230
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
592 def createPanel(cls, host, item): |
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
593 """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
|
594 @parem host: the SatWebFrontend instance |
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
595 @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
|
596 (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
|
597 @return: the created MicroblogPanel |
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
598 """ |
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
599 _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
|
600 _type = 'ALL' if _items == [] else 'GROUP' |
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
601 # 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
|
602 _new_panel = MicroblogPanel(host, _items) |
195 | 603 host.FillMicroblogPanel(_new_panel) |
230
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
604 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
|
605 host.setSelected(_new_panel) |
195 | 606 return _new_panel |
607 | |
608 @classmethod | |
230
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
609 def createMetaPanel(cls, host, item): |
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
610 """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
|
611 return MicroblogPanel.createPanel(host, None) |
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
612 |
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
613 @property |
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
614 def accepted_groups(self): |
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
615 return self._accepted_groups |
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
616 |
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
617 def matchEntity(self, entity): |
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
618 """ |
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
619 @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
|
620 (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
|
621 @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
|
622 """ |
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
623 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
|
624 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
|
625 return self.accepted_groups == entity |
195 | 626 |
201
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
627 def getWarningData(self): |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
628 if self.selected_entry: |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
629 if not self.selected_entry.comments: |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
630 print ("ERROR: an item without comment is selected") |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
631 return ("NONE", None) |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
632 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
|
633 |
230
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
634 elif not self._accepted_groups: |
201
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
635 # we have a meta MicroblogPanel, we publish publicly |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
636 return ("PUBLIC", self.warning_msg_public) |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
637 else: |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
638 # we only accept one group at the moment |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
639 # FIXME: manage several groups |
230
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
640 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
|
641 |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
642 def onTextEntered(self, text): |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
643 if self.selected_entry: |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
644 # we are entering a comment |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
645 comments_node = self.selected_entry.comments |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
646 if not comments_node: |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
647 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
|
648 target = ("COMMENT", comments_node) |
230
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
649 elif not self._accepted_groups: |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
650 # we are entering a public microblog |
269
9eb9c7d41bdc
browser_side: added generic method "send" in SatWebFrontend
souliane <souliane@mailoo.org>
parents:
267
diff
changeset
|
651 target = ("PUBLIC", None) |
201
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
652 else: |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
653 # 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
|
654 # FIXME: manage several groups |
269
9eb9c7d41bdc
browser_side: added generic method "send" in SatWebFrontend
souliane <souliane@mailoo.org>
parents:
267
diff
changeset
|
655 target = ("GROUP", self._accepted_groups[0]) |
9eb9c7d41bdc
browser_side: added generic method "send" in SatWebFrontend
souliane <souliane@mailoo.org>
parents:
267
diff
changeset
|
656 self.host.send([target], text) |
201
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
657 |
132
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
658 def accept_all(self): |
230
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
659 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
|
660 |
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
661 def getEntries(self): |
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
662 """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
|
663 and fill the panel""" |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
664 |
132
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
665 def massiveInsert(self, mblogs): |
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
666 """Insert several microblogs at once |
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
667 @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
|
668 """ |
242
a25aa882e09a
browser_side: add context menu for contact:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
669 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
|
670 for publisher in mblogs: |
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
671 print "adding blogs for [%s]" % publisher |
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
672 for mblog in mblogs[publisher]: |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
673 if not "content" in mblog: |
132
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
674 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
|
675 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
|
676 self.addEntry(mblog) |
132
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
677 |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
678 def mblogsInsert(self, mblogs): |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
679 """ Insert several microblogs at once |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
680 @param mblogs: list of microblogs |
132
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
681 """ |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
682 for mblog in mblogs: |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
683 if not "content" in mblog: |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
684 print ("WARNING: No content found in microblog [%s]", mblog) |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
685 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
|
686 self.addEntry(mblog) |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
687 |
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
|
688 def _chronoInsert(self, vpanel, entry, reverse=True): |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
689 """ Insert an entry in chronological order |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
690 @param vpanel: VerticalPanel instance |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
691 @param entry: MicroblogEntry |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
692 @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
|
693 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
|
694 entry.published = time() |
135
ceef355156de
server + browser side: groupblog subscription + fixed blog insertion order
Goffi <goffi@goffi.org>
parents:
132
diff
changeset
|
695 # we look for the right index to insert our entry: |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
696 # 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
|
697 # in the past |
ceef355156de
server + browser side: groupblog subscription + fixed blog insertion order
Goffi <goffi@goffi.org>
parents:
132
diff
changeset
|
698 idx = 0 |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
699 |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
700 for child in vpanel.children: |
135
ceef355156de
server + browser side: groupblog subscription + fixed blog insertion order
Goffi <goffi@goffi.org>
parents:
132
diff
changeset
|
701 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
|
702 idx += 1 |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
703 continue |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
704 if reverse: |
307
44b46db7dfef
browser_side (groupblog): order items using "published" instead of "updated"
souliane <souliane@mailoo.org>
parents:
306
diff
changeset
|
705 if child.published < entry.published: |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
706 break |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
707 else: |
307
44b46db7dfef
browser_side (groupblog): order items using "published" instead of "updated"
souliane <souliane@mailoo.org>
parents:
306
diff
changeset
|
708 if child.published > entry.published: |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
709 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
|
710 idx += 1 |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
711 |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
712 vpanel.insert(entry, idx) |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
713 |
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
|
714 def addEntry(self, data): |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
715 """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
|
716 @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
|
717 @return: the added entry, or None |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
718 """ |
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
|
719 _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
|
720 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
|
721 if not _entry.hash in self.comments: |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
722 # 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
|
723 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
|
724 parent = self.comments[_entry.hash] |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
725 parent_idx = self.vpanel.getWidgetIndex(parent) |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
726 # 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
|
727 try: |
226
744426c2b699
browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
223
diff
changeset
|
728 sub_panel = self.vpanel.getWidget(parent_idx + 1) |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
729 except IndexError: |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
730 sub_panel = None |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
731 if not sub_panel or not isinstance(sub_panel, VerticalPanel): |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
732 sub_panel = VerticalPanel() |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
733 sub_panel.setStyleName('microblogPanel') |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
734 sub_panel.addStyleName('subPanel') |
226
744426c2b699
browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
223
diff
changeset
|
735 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
|
736 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
|
737 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
|
738 if comment.pub_data[2] == _entry.id: |
282
ae3ec654836d
browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
739 # update an existing comment |
ae3ec654836d
browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
740 sub_panel.remove(comment) |
ae3ec654836d
browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
741 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
|
742 return _entry |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
743 # we want comments to be inserted in chronological order |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
744 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
|
745 return _entry |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
746 |
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
|
747 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
|
748 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
|
749 self.vpanel.remove(self.entries[_entry.id]) |
282
ae3ec654836d
browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
750 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
|
751 else: # new entry |
282
ae3ec654836d
browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
752 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
|
753 self.entries[_entry.id] = _entry |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
754 |
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
|
755 if _entry.comments: |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
756 # 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
|
757 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
|
758 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
|
759 |
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 return _entry |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
761 |
282
ae3ec654836d
browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
762 def removeEntry(self, type_, id_): |
ae3ec654836d
browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
763 """Remove an entry from the panel |
ae3ec654836d
browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
764 @param type_: entry type ('main_item' or 'comment') |
ae3ec654836d
browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
765 @param id_: entry id |
ae3ec654836d
browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
766 """ |
ae3ec654836d
browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
767 for child in self.vpanel.getChildren(): |
ae3ec654836d
browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
768 if isinstance(child, MicroblogEntry) and type_ == 'main_item': |
ae3ec654836d
browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
769 if child.pub_data[2] == id_: |
ae3ec654836d
browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
770 main_idx = self.vpanel.getWidgetIndex(child) |
ae3ec654836d
browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
771 try: |
ae3ec654836d
browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
772 sub_panel = self.vpanel.getWidget(main_idx + 1) |
ae3ec654836d
browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
773 if isinstance(sub_panel, VerticalPanel): |
ae3ec654836d
browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
774 sub_panel.removeFromParent() |
ae3ec654836d
browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
775 except IndexError: |
ae3ec654836d
browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
776 pass |
ae3ec654836d
browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
777 child.removeFromParent() |
ae3ec654836d
browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
778 self.selected_entry = None |
ae3ec654836d
browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
779 break |
ae3ec654836d
browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
780 elif isinstance(child, VerticalPanel) and type_ == 'comment': |
ae3ec654836d
browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
781 for comment in child.getChildren(): |
ae3ec654836d
browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
782 if comment.pub_data[2] == id_: |
ae3ec654836d
browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
783 comment.removeFromParent() |
ae3ec654836d
browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
784 self.selected_entry = None |
ae3ec654836d
browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
785 break |
ae3ec654836d
browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
786 |
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
|
787 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
|
788 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
|
789 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
|
790 except AttributeError: |
334
9c6be29c714a
browser side: removed logging imports: it's not working correctly with pyjamas
Goffi <goffi@goffi.org>
parents:
326
diff
changeset
|
791 print "FIXME: MicroblogPanel.vpanel should be wrapped in a ScrollPanel!" |
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
|
792 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
|
793 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
|
794 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
|
795 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
|
796 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
|
797 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
|
798 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
|
799 # 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
|
800 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
|
801 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
|
802 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
|
803 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
|
804 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
|
805 if entry: |
282
ae3ec654836d
browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
806 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
|
807 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
|
808 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
|
809 |
241
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
810 def updateValue(self, type_, jid, value): |
119 | 811 """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
|
812 @param type_: one of 'avatar', 'nick' |
119 | 813 @param jid: jid concerned |
814 @param value: new value""" | |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
815 def updateVPanel(vpanel): |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
816 for child in vpanel.children: |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
817 if isinstance(child, MicroblogEntry) and child.author == jid: |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
818 child.updateAvatar(value) |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
819 elif isinstance(child, VerticalPanel): |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
820 updateVPanel(child) |
241
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
821 if type_ == 'avatar': |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
822 updateVPanel(self.vpanel) |
119 | 823 |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
824 def setAcceptedGroup(self, group): |
230
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
825 """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
|
826 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
|
827 @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
|
828 """ |
230
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
829 if not hasattr(self, "_accepted_groups"): |
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
830 self._accepted_groups = [] |
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
831 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
|
832 for _group in groups: |
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
833 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
|
834 self._accepted_groups.append(_group) |
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
835 self._accepted_groups.sort() |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
836 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
837 def isJidAccepted(self, jid): |
163
b887186e8fc8
browser side: get entity's microblogs for newly added contacts
Goffi <goffi@goffi.org>
parents:
148
diff
changeset
|
838 """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
|
839 @param jid: jid |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
840 @return: True if the jid is accepted""" |
132
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
841 if self.accept_all(): |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
842 return True |
230
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
843 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
|
844 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
|
845 return True |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
846 return False |
19 | 847 |
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
|
848 |
347
f1ba38043d78
browser_side: status panel is based on a new class LightTextEditor which uses HTML5 "editablecontent" property
souliane <souliane@mailoo.org>
parents:
342
diff
changeset
|
849 class StatusPanel(LightTextEditor, ClickHandler): |
314
70ac3067d641
browser_side: status can be edited with a click on it
souliane <souliane@mailoo.org>
parents:
313
diff
changeset
|
850 |
349
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
851 EMPTY_STATUS = '<click to set a status>' |
314
70ac3067d641
browser_side: status can be edited with a click on it
souliane <souliane@mailoo.org>
parents:
313
diff
changeset
|
852 |
20 | 853 def __init__(self, host, status=''): |
854 self.host = host | |
349
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
855 modifiedCb = lambda content: self.host.bridge.call('setStatus', None, self.host.status_panel.presence, content['text']) or True |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
856 LightTextEditor.__init__(self, {'text': status}, modifiedCb, None, True) |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
857 self.edit(False) |
20 | 858 self.setStyleName('statusPanel') |
314
70ac3067d641
browser_side: status can be edited with a click on it
souliane <souliane@mailoo.org>
parents:
313
diff
changeset
|
859 ClickHandler.__init__(self) |
70ac3067d641
browser_side: status can be edited with a click on it
souliane <souliane@mailoo.org>
parents:
313
diff
changeset
|
860 self.addClickListener(self) |
19 | 861 |
349
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
862 @property |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
863 def status(self): |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
864 return self._original_content['text'] |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
865 |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
866 def __cleanContent(self, content): |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
867 status = content['text'] |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
868 if status == self.EMPTY_STATUS or status in Const.PRESENCE.values(): |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
869 content['text'] = '' |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
870 return content |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
871 |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
872 def getContent(self): |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
873 return self.__cleanContent(LightTextEditor.getContent(self)) |
19 | 874 |
349
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
875 def setContent(self, content): |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
876 content = self.__cleanContent(content) |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
877 BaseTextEditor.setContent(self, content) |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
878 |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
879 def setDisplayContent(self): |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
880 status = self._original_content['text'] |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
881 try: |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
882 presence = self.host.status_panel.presence |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
883 except AttributeError: # during initialization |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
884 presence = None |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
885 if not status: |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
886 if presence and presence in Const.PRESENCE: |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
887 status = Const.PRESENCE[presence] |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
888 else: |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
889 status = self.EMPTY_STATUS |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
890 self.setHTML(addURLToText(status)) |
19 | 891 |
314
70ac3067d641
browser_side: status can be edited with a click on it
souliane <souliane@mailoo.org>
parents:
313
diff
changeset
|
892 def onClick(self, sender): |
347
f1ba38043d78
browser_side: status panel is based on a new class LightTextEditor which uses HTML5 "editablecontent" property
souliane <souliane@mailoo.org>
parents:
342
diff
changeset
|
893 self.edit(True) |
314
70ac3067d641
browser_side: status can be edited with a click on it
souliane <souliane@mailoo.org>
parents:
313
diff
changeset
|
894 |
279
2d6bd975a72d
browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents:
276
diff
changeset
|
895 |
2d6bd975a72d
browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents:
276
diff
changeset
|
896 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
|
897 |
2d6bd975a72d
browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents:
276
diff
changeset
|
898 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
|
899 self.host = host |
2d6bd975a72d
browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents:
276
diff
changeset
|
900 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
|
901 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
|
902 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
|
903 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
|
904 self.setPresence(presence) |
2d6bd975a72d
browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents:
276
diff
changeset
|
905 entries = {} |
323
0b7934e75e76
misc: reorganization of the file panels.py + clean the modules import:
souliane <souliane@mailoo.org>
parents:
322
diff
changeset
|
906 for value in Const.PRESENCE.keys(): |
0b7934e75e76
misc: reorganization of the file panels.py + clean the modules import:
souliane <souliane@mailoo.org>
parents:
322
diff
changeset
|
907 entries.update({Const.PRESENCE[value]: {"value": value}}) |
279
2d6bd975a72d
browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents:
276
diff
changeset
|
908 |
2d6bd975a72d
browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents:
276
diff
changeset
|
909 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
|
910 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
|
911 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
|
912 |
2d6bd975a72d
browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents:
276
diff
changeset
|
913 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
|
914 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
|
915 |
2d6bd975a72d
browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents:
276
diff
changeset
|
916 panel = HorizontalPanel() |
2d6bd975a72d
browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents:
276
diff
changeset
|
917 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
|
918 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
|
919 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
|
920 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
|
921 panel.setStyleName("marginAuto") |
2d6bd975a72d
browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents:
276
diff
changeset
|
922 self.add(panel) |
2d6bd975a72d
browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents:
276
diff
changeset
|
923 |
349
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
924 self.status_panel.edit(False) |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
925 |
279
2d6bd975a72d
browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents:
276
diff
changeset
|
926 ClickHandler.__init__(self) |
2d6bd975a72d
browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents:
276
diff
changeset
|
927 self.addClickListener(self) |
2d6bd975a72d
browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents:
276
diff
changeset
|
928 |
349
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
929 @property |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
930 def presence(self): |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
931 return self._presence |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
932 |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
933 @property |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
934 def status(self): |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
935 return self.status_panel._original_content['text'] |
279
2d6bd975a72d
browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents:
276
diff
changeset
|
936 |
2d6bd975a72d
browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents:
276
diff
changeset
|
937 def setPresence(self, presence): |
349
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
938 self._presence = presence |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
939 setPresenceStyle(self.presence_button, self._presence) |
279
2d6bd975a72d
browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents:
276
diff
changeset
|
940 |
349
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
941 def setStatus(self, status): |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
942 self.status_panel.setContent({'text': status}) |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
943 self.status_panel.setDisplayContent() |
279
2d6bd975a72d
browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents:
276
diff
changeset
|
944 |
62 | 945 def onClick(self, sender): |
226
744426c2b699
browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
223
diff
changeset
|
946 # 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
|
947 self.host.setSelected(None) |
20 | 948 |
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
|
949 |
195 | 950 class ChatPanel(base_widget.LiberviaWidget): |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
951 |
179
8475a29d7214
closing a group chat widget now leave the muc room (bug 11)
Goffi <goffi@goffi.org>
parents:
178
diff
changeset
|
952 def __init__(self, host, target, type_='one2one'): |
19 | 953 """Panel used for conversation (one 2 one or group chat) |
954 @param host: SatWebFrontend instance | |
955 @param target: entity (JID) with who we have a conversation (contact's jid for one 2 one chat, or MUC room) | |
956 @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
|
957 base_widget.LiberviaWidget.__init__(self, host, target.bare, selectable=True) |
34 | 958 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
|
959 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
|
960 self.type = type_ |
33 | 961 self.nick = None |
19 | 962 if not target: |
963 print "ERROR: Empty target !" | |
964 return | |
965 self.target = target | |
84 | 966 self.__body = AbsolutePanel() |
967 self.__body.setStyleName('chatPanel_body') | |
33 | 968 chat_area = HorizontalPanel() |
969 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
|
970 if type_ == 'group': |
33 | 971 self.occupants_list = OccupantsList() |
972 chat_area.add(self.occupants_list) | |
84 | 973 self.__body.add(chat_area) |
33 | 974 self.content = AbsolutePanel() |
975 self.content.setStyleName('chatContent') | |
195 | 976 self.content_scroll = base_widget.ScrollPanelWrapper(self.content) |
34 | 977 chat_area.add(self.content_scroll) |
978 chat_area.setCellWidth(self.content_scroll, '100%') | |
84 | 979 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
|
980 self.vpanel.setCellHeight(self.__body, '100%') |
84 | 981 self.addStyleName('chatPanel') |
34 | 982 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
|
983 self.state_machine = ChatStateMachine(self.host, str(self.target)) |
19 | 984 |
84 | 985 """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
|
986 #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
|
987 #for the same reason as doAttachChildren |
195 | 988 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
|
989 |
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
|
990 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
|
991 #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
|
992 #the event will not propagate to children |
195 | 993 base_widget.ScrollPanelWrapper.doAttachChildren(self)""" |
994 | |
995 @classmethod | |
996 def registerClass(cls): | |
230
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
997 base_widget.LiberviaWidget.addDropKey("CONTACT", cls.createPanel) |
195 | 998 |
999 @classmethod | |
230
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
1000 def createPanel(cls, host, item): |
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
1001 _contact = item if isinstance(item, JID) else JID(item) |
195 | 1002 host.contact_panel.setContactMessageWaiting(_contact.bare, False) |
226
744426c2b699
browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
223
diff
changeset
|
1003 _new_panel = ChatPanel(host, _contact) # XXX: pyjamas doesn't seems to support creating with cls directly |
195 | 1004 _new_panel.historyPrint() |
230
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
1005 host.setSelected(_new_panel) |
195 | 1006 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
|
1007 |
230
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
1008 def refresh(self): |
326
36927be51481
browser_side: fixed the behavior regarding "Enable unibox" parameter:
souliane <souliane@mailoo.org>
parents:
323
diff
changeset
|
1009 """Refresh the display of this widget. If the unibox is disabled, |
36927be51481
browser_side: fixed the behavior regarding "Enable unibox" parameter:
souliane <souliane@mailoo.org>
parents:
323
diff
changeset
|
1010 add a message box at the bottom of the panel""" |
230
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
1011 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
|
1012 self.content_scroll.scrollToBottom() |
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
1013 |
326
36927be51481
browser_side: fixed the behavior regarding "Enable unibox" parameter:
souliane <souliane@mailoo.org>
parents:
323
diff
changeset
|
1014 enable_box = self.host.uni_box is None |
36927be51481
browser_side: fixed the behavior regarding "Enable unibox" parameter:
souliane <souliane@mailoo.org>
parents:
323
diff
changeset
|
1015 if hasattr(self, 'message_box'): |
36927be51481
browser_side: fixed the behavior regarding "Enable unibox" parameter:
souliane <souliane@mailoo.org>
parents:
323
diff
changeset
|
1016 self.message_box.setVisible(enable_box) |
36927be51481
browser_side: fixed the behavior regarding "Enable unibox" parameter:
souliane <souliane@mailoo.org>
parents:
323
diff
changeset
|
1017 return |
36927be51481
browser_side: fixed the behavior regarding "Enable unibox" parameter:
souliane <souliane@mailoo.org>
parents:
323
diff
changeset
|
1018 if enable_box: |
36927be51481
browser_side: fixed the behavior regarding "Enable unibox" parameter:
souliane <souliane@mailoo.org>
parents:
323
diff
changeset
|
1019 self.message_box = MessageBox(self.host) |
36927be51481
browser_side: fixed the behavior regarding "Enable unibox" parameter:
souliane <souliane@mailoo.org>
parents:
323
diff
changeset
|
1020 self.message_box.onSelectedChange(self) |
36927be51481
browser_side: fixed the behavior regarding "Enable unibox" parameter:
souliane <souliane@mailoo.org>
parents:
323
diff
changeset
|
1021 self.vpanel.add(self.message_box) |
36927be51481
browser_side: fixed the behavior regarding "Enable unibox" parameter:
souliane <souliane@mailoo.org>
parents:
323
diff
changeset
|
1022 |
230
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
1023 def matchEntity(self, entity): |
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
1024 """ |
267
a76243c02074
browser_side: changes regarding widgets and tabs:
souliane <souliane@mailoo.org>
parents:
264
diff
changeset
|
1025 @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
|
1026 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
|
1027 @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
|
1028 """ |
267
a76243c02074
browser_side: changes regarding widgets and tabs:
souliane <souliane@mailoo.org>
parents:
264
diff
changeset
|
1029 if isinstance(entity, tuple): |
a76243c02074
browser_side: changes regarding widgets and tabs:
souliane <souliane@mailoo.org>
parents:
264
diff
changeset
|
1030 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
|
1031 else: |
a76243c02074
browser_side: changes regarding widgets and tabs:
souliane <souliane@mailoo.org>
parents:
264
diff
changeset
|
1032 type_ = self.type |
230
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
1033 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
|
1034 try: |
267
a76243c02074
browser_side: changes regarding widgets and tabs:
souliane <souliane@mailoo.org>
parents:
264
diff
changeset
|
1035 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
|
1036 except AttributeError as e: |
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
1037 e.include_traceback() |
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
1038 return False |
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
1039 |
201
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
1040 def getWarningData(self): |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
1041 if self.type not in ["one2one", "group"]: |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
1042 raise Exception("Unmanaged type !") |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
1043 if self.type == "one2one": |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
1044 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
|
1045 elif self.type == "group": |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
1046 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
|
1047 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
|
1048 |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
1049 def onTextEntered(self, text): |
269
9eb9c7d41bdc
browser_side: added generic method "send" in SatWebFrontend
souliane <souliane@mailoo.org>
parents:
267
diff
changeset
|
1050 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
|
1051 self.state_machine._onEvent("active") |
201
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
1052 |
179
8475a29d7214
closing a group chat widget now leave the muc room (bug 11)
Goffi <goffi@goffi.org>
parents:
178
diff
changeset
|
1053 def onQuit(self): |
195 | 1054 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
|
1055 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
|
1056 self.host.bridge.call('mucLeave', None, self.target.bare) |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
1057 |
19 | 1058 def setUserNick(self, nick): |
1059 """Set the nick of the user, usefull for e.g. change the color of the user""" | |
1060 self.nick = nick | |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
1061 |
33 | 1062 def setPresents(self, nicks): |
1063 """Set the users presents in this room | |
1064 @param occupants: list of nicks (string)""" | |
35 | 1065 self.occupants_list.clear() |
33 | 1066 for nick in nicks: |
1067 self.occupants_list.addOccupant(nick) | |
1068 | |
35 | 1069 def userJoined(self, nick, data): |
1070 self.occupants_list.addOccupant(nick) | |
1071 self.printInfo("=> %s has joined the room" % nick) | |
1072 | |
1073 def userLeft(self, nick, data): | |
1074 self.occupants_list.removeOccupant(nick) | |
1075 self.printInfo("<= %s has left the room" % nick) | |
1076 | |
19 | 1077 def historyPrint(self, size=20): |
1078 """Print the initial history""" | |
1079 def getHistoryCB(history): | |
213
8bbac49765d6
browser side: display the day change in chat window
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
1080 # display day change |
8bbac49765d6
browser side: display the day change in chat window
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
1081 day_format = "%A, %d %b %Y" |
8bbac49765d6
browser side: display the day change in chat window
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
1082 previous_day = datetime.now().strftime(day_format) |
123 | 1083 for line in history: |
235
b304cdf13a3b
browser and server side: XHTML handling, first draft:
Goffi <goffi@goffi.org>
parents:
232
diff
changeset
|
1084 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
|
1085 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
|
1086 if previous_day != message_day: |
8bbac49765d6
browser side: display the day change in chat window
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
1087 self.printInfo("* " + message_day) |
8bbac49765d6
browser side: display the day change in chat window
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
1088 previous_day = message_day |
235
b304cdf13a3b
browser and server side: XHTML handling, first draft:
Goffi <goffi@goffi.org>
parents:
232
diff
changeset
|
1089 self.printMessage(from_jid, message, extra, timestamp) |
123 | 1090 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
|
1091 |
35 | 1092 def printInfo(self, msg, type='normal'): |
1093 """Print general info | |
1094 @param msg: message to print | |
1095 @type: one of: | |
1096 normal: general info like "toto has joined the room" | |
1097 me: "/me" information like "/me clenches his fist" ==> "toto clenches his fist" | |
1098 """ | |
54
f25c4077f6b9
addind contact + subscription management + misc
Goffi <goffi@goffi.org>
parents:
52
diff
changeset
|
1099 _wid = Label(msg) |
35 | 1100 if type == 'normal': |
1101 _wid.setStyleName('chatTextInfo') | |
1102 elif type == 'me': | |
1103 _wid.setStyleName('chatTextMe') | |
1104 else: | |
1105 _wid.setStyleName('chatTextInfo') | |
1106 self.content.add(_wid) | |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
1107 |
235
b304cdf13a3b
browser and server side: XHTML handling, first draft:
Goffi <goffi@goffi.org>
parents:
232
diff
changeset
|
1108 def printMessage(self, from_jid, msg, extra, timestamp=None): |
19 | 1109 """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
|
1110 _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
|
1111 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
|
1112 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 | 1113 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
|
1114 self.printInfo('* %s %s' % (nick, msg[4:]), type='me') |
35 | 1115 return |
235
b304cdf13a3b
browser and server side: XHTML handling, first draft:
Goffi <goffi@goffi.org>
parents:
232
diff
changeset
|
1116 self.content.add(ChatText(timestamp, nick, mymess, msg, extra.get('xhtml'))) |
34 | 1117 self.content_scroll.scrollToBottom() |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
1118 |
285
4f0c2fea358a
browser_side (plugin radiocol): use the status label to give more information
souliane <souliane@mailoo.org>
parents:
282
diff
changeset
|
1119 def startGame(self, game_type, waiting, referee, players, *args): |
36 | 1120 """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
|
1121 classes = {"Tarot": CardPanel, "RadioCol": RadioColPanel} |
a763b2ac5d41
bridge + browser_side: bridge signals for games and their callbacks:
souliane <souliane@mailoo.org>
parents:
273
diff
changeset
|
1122 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
|
1123 return # unknown game |
a763b2ac5d41
bridge + browser_side: bridge signals for games and their callbacks:
souliane <souliane@mailoo.org>
parents:
273
diff
changeset
|
1124 attr = game_type.lower() |
342
44491e963eee
browser_side: muc user symbols (used for showing who is playing) can also be removed
souliane <souliane@mailoo.org>
parents:
340
diff
changeset
|
1125 self.occupants_list.updateSpecials(players, SYMBOLS[attr]) |
275
a763b2ac5d41
bridge + browser_side: bridge signals for games and their callbacks:
souliane <souliane@mailoo.org>
parents:
273
diff
changeset
|
1126 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
|
1127 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
|
1128 attr = "%s_panel" % attr |
a763b2ac5d41
bridge + browser_side: bridge signals for games and their callbacks:
souliane <souliane@mailoo.org>
parents:
273
diff
changeset
|
1129 if hasattr(self, attr): |
a763b2ac5d41
bridge + browser_side: bridge signals for games and their callbacks:
souliane <souliane@mailoo.org>
parents:
273
diff
changeset
|
1130 return |
a763b2ac5d41
bridge + browser_side: bridge signals for games and their callbacks:
souliane <souliane@mailoo.org>
parents:
273
diff
changeset
|
1131 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
|
1132 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
|
1133 setattr(self, attr, panel) |
a763b2ac5d41
bridge + browser_side: bridge signals for games and their callbacks:
souliane <souliane@mailoo.org>
parents:
273
diff
changeset
|
1134 self.vpanel.insert(panel, 0) |
a763b2ac5d41
bridge + browser_side: bridge signals for games and their callbacks:
souliane <souliane@mailoo.org>
parents:
273
diff
changeset
|
1135 self.vpanel.setCellHeight(panel, panel.getHeight()) |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
1136 |
37
b306aa090438
Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
1137 def getGame(self, game_type): |
b306aa090438
Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
1138 """Return class managing the game type""" |
226
744426c2b699
browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
223
diff
changeset
|
1139 # 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
|
1140 if game_type == "Tarot": |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
1141 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
|
1142 elif game_type == "RadioCol": |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
1143 return self.radiocol_panel |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1144 |
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
|
1145 |
195 | 1146 class WebPanel(base_widget.LiberviaWidget): |
181
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
1147 """ (mini)browser like widget """ |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
1148 |
181
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
1149 def __init__(self, host, url=None): |
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
1150 """ |
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
1151 @param host: SatWebFrontend instance |
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
1152 """ |
195 | 1153 base_widget.LiberviaWidget.__init__(self, host) |
181
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
1154 self._vpanel = VerticalPanel() |
188
39936b83da9d
Browser Side: Web Panel widget position/size fix
Goffi <goffi@goffi.org>
parents:
187
diff
changeset
|
1155 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
|
1156 self._url = dialog.ExtTextBox(enter_cb=self.onUrlClick) |
181
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
1157 self._url.setText(url or "") |
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
1158 self._url.setWidth('100%') |
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
1159 hpanel = HorizontalPanel() |
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
1160 hpanel.add(self._url) |
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
1161 btn = Button("Go", self.onUrlClick) |
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
1162 hpanel.setCellWidth(self._url, "100%") |
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
1163 #self.setCellWidth(btn, "10%") |
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
1164 hpanel.add(self._url) |
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
1165 hpanel.add(btn) |
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
1166 self._vpanel.add(hpanel) |
188
39936b83da9d
Browser Side: Web Panel widget position/size fix
Goffi <goffi@goffi.org>
parents:
187
diff
changeset
|
1167 self._vpanel.setCellHeight(hpanel, '20px') |
181
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
1168 self._frame = Frame(url or "") |
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
1169 self._frame.setSize('100%', '100%') |
188
39936b83da9d
Browser Side: Web Panel widget position/size fix
Goffi <goffi@goffi.org>
parents:
187
diff
changeset
|
1170 DOM.setStyleAttribute(self._frame.getElement(), "position", "relative") |
181
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
1171 self._vpanel.add(self._frame) |
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
1172 self.setWidget(self._vpanel) |
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
1173 |
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
1174 def onUrlClick(self, sender): |
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
1175 self._frame.setUrl(self._url.getText()) |
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
1176 |
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
|
1177 |
33 | 1178 class MainPanel(AbsolutePanel): |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1179 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1180 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
|
1181 self.host = host |
33 | 1182 AbsolutePanel.__init__(self) |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1183 |
226
744426c2b699
browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
223
diff
changeset
|
1184 # menu |
218
4e6467efd6bf
browser_side: small improvements for parameters panel
souliane <souliane@mailoo.org>
parents:
217
diff
changeset
|
1185 self.menu = Menu(host) |
184
97d5e9de1106
browser side: contacts panel switch:
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
1186 |
226
744426c2b699
browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
223
diff
changeset
|
1187 # unibox |
309
05e264e96a1c
browser_side: make unibox optional
souliane <souliane@mailoo.org>
parents:
307
diff
changeset
|
1188 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
|
1189 self.unibox_panel.setVisible(False) |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
1190 |
226
744426c2b699
browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
223
diff
changeset
|
1191 # 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
|
1192 status = host.status_panel |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
1193 |
226
744426c2b699
browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
223
diff
changeset
|
1194 # contacts |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
231
diff
changeset
|
1195 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
|
1196 self._contacts.addStyleName('globalLeftArea') |
255
da0487f0a2e7
browser_side: small changes to prepare the contact group manager:
souliane <souliane@mailoo.org>
parents:
249
diff
changeset
|
1197 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
|
1198 self.contacts_switch.addStyleName('contactsSwitch') |
da0487f0a2e7
browser_side: small changes to prepare the contact group manager:
souliane <souliane@mailoo.org>
parents:
249
diff
changeset
|
1199 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
|
1200 self._contacts.add(self.host.contact_panel) |
184
97d5e9de1106
browser side: contacts panel switch:
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
1201 |
226
744426c2b699
browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
223
diff
changeset
|
1202 # tabs |
195 | 1203 self.tab_panel = base_widget.MainTabPanel(host) |
1204 self.discuss_panel = base_widget.WidgetsPanel(self.host, locked=True) | |
23 | 1205 self.tab_panel.add(self.discuss_panel, "Discussions") |
1206 self.tab_panel.selectTab(0) | |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1207 |
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
|
1208 header = AbsolutePanel() |
218
4e6467efd6bf
browser_side: small improvements for parameters panel
souliane <souliane@mailoo.org>
parents:
217
diff
changeset
|
1209 header.add(self.menu) |
309
05e264e96a1c
browser_side: make unibox optional
souliane <souliane@mailoo.org>
parents:
307
diff
changeset
|
1210 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
|
1211 header.add(status) |
5c363b638127
browser side: grouped header panel in a global Absolute panel
Goffi <goffi@goffi.org>
parents:
101
diff
changeset
|
1212 header.setStyleName('header') |
5c363b638127
browser side: grouped header panel in a global Absolute panel
Goffi <goffi@goffi.org>
parents:
101
diff
changeset
|
1213 self.add(header) |
184
97d5e9de1106
browser side: contacts panel switch:
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
1214 |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
231
diff
changeset
|
1215 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
|
1216 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
|
1217 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
|
1218 self.add(self._hpanel) |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
1219 |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1220 self.setWidth("100%") |
33 | 1221 Window.addWindowResizeListener(self) |
1222 | |
255
da0487f0a2e7
browser_side: small changes to prepare the contact group manager:
souliane <souliane@mailoo.org>
parents:
249
diff
changeset
|
1223 def _contactsSwitch(self, btn=None): |
184
97d5e9de1106
browser side: contacts panel switch:
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
1224 """ (Un)hide contacts panel """ |
255
da0487f0a2e7
browser_side: small changes to prepare the contact group manager:
souliane <souliane@mailoo.org>
parents:
249
diff
changeset
|
1225 if btn is None: |
da0487f0a2e7
browser_side: small changes to prepare the contact group manager:
souliane <souliane@mailoo.org>
parents:
249
diff
changeset
|
1226 btn = self.contacts_switch |
184
97d5e9de1106
browser side: contacts panel switch:
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
1227 cpanel = self.host.contact_panel |
97d5e9de1106
browser side: contacts panel switch:
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
1228 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
|
1229 btn.setText(u"«" if cpanel.getVisible() else u"»") |
184
97d5e9de1106
browser side: contacts panel switch:
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
1230 self.host.resize() |
97d5e9de1106
browser side: contacts panel switch:
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
1231 |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
231
diff
changeset
|
1232 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
|
1233 """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
|
1234 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
|
1235 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
|
1236 """ |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
231
diff
changeset
|
1237 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
|
1238 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
|
1239 return |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
231
diff
changeset
|
1240 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
|
1241 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
|
1242 |
33 | 1243 def onWindowResized(self, width, height): |
1244 _elts = doc().getElementsByClassName('gwt-TabBar') | |
1245 if not _elts.length: | |
1246 tab_bar_h = 0 | |
1247 else: | |
1248 tab_bar_h = _elts.item(0).offsetHeight | |
1249 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
|
1250 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
|
1251 |
326
36927be51481
browser_side: fixed the behavior regarding "Enable unibox" parameter:
souliane <souliane@mailoo.org>
parents:
323
diff
changeset
|
1252 def refresh(self): |
36927be51481
browser_side: fixed the behavior regarding "Enable unibox" parameter:
souliane <souliane@mailoo.org>
parents:
323
diff
changeset
|
1253 """Refresh the main panel""" |
36927be51481
browser_side: fixed the behavior regarding "Enable unibox" parameter:
souliane <souliane@mailoo.org>
parents:
323
diff
changeset
|
1254 self.unibox_panel.refresh() |