annotate src/browser/sat_browser/web_widget.py @ 977:d0de2a98e852

pages (tickets/new): refuse data if body is not set
author Goffi <goffi@goffi.org>
date Sat, 11 Nov 2017 19:02:27 +0100
parents fd4eae654182
children f2170536ba23
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
18
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/python
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
3
339
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 334
diff changeset
4 # Libervia: a Salut à Toi frontend
964
fd4eae654182 misc: date update (yes it's a bit late :p )
Goffi <goffi@goffi.org>
parents: 818
diff changeset
5 # Copyright (C) 2011-2017 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
439
d52f529a6d42 browser side: use of new log system (first draft):
Goffi <goffi@goffi.org>
parents: 433
diff changeset
21 from sat.core.log import getLogger
d52f529a6d42 browser side: use of new log system (first draft):
Goffi <goffi@goffi.org>
parents: 433
diff changeset
22 log = getLogger(__name__)
449
981ed669d3b3 /!\ reorganize all the file hierarchy, move the code and launching script to src:
souliane <souliane@mailoo.org>
parents: 442
diff changeset
23
676
849ffb24d5bf browser side: menus refactorisation:
Goffi <goffi@goffi.org>
parents: 648
diff changeset
24 from sat.core.i18n import D_
849ffb24d5bf browser side: menus refactorisation:
Goffi <goffi@goffi.org>
parents: 648
diff changeset
25
18
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
26 from pyjamas.ui.VerticalPanel import VerticalPanel
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
27 from pyjamas.ui.HorizontalPanel import HorizontalPanel
83
68d360caeecb New widget system: first draft
Goffi <goffi@goffi.org>
parents: 78
diff changeset
28 from pyjamas.ui.Button import Button
589
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 585
diff changeset
29 from pyjamas.ui.Frame import Frame
18
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
30 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
31
449
981ed669d3b3 /!\ reorganize all the file hierarchy, move the code and launching script to src:
souliane <souliane@mailoo.org>
parents: 442
diff changeset
32
981ed669d3b3 /!\ reorganize all the file hierarchy, move the code and launching script to src:
souliane <souliane@mailoo.org>
parents: 442
diff changeset
33 import dialog
648
6d3142b782c3 browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents: 637
diff changeset
34 import libervia_widget
433
bbdbee25123a import constants.Const as C (according to the coding rules)
souliane <souliane@mailoo.org>
parents: 432
diff changeset
35 from constants import Const as C
589
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 585
diff changeset
36 from sat_frontends.quick_frontend import quick_widgets
676
849ffb24d5bf browser side: menus refactorisation:
Goffi <goffi@goffi.org>
parents: 648
diff changeset
37 from sat_frontends.tools import host_listener
442
17259c2ff96f browser_side: changes about the UI (remarks from Franck):
souliane <souliane@mailoo.org>
parents: 439
diff changeset
38
17259c2ff96f browser_side: changes about the UI (remarks from Franck):
souliane <souliane@mailoo.org>
parents: 439
diff changeset
39
648
6d3142b782c3 browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents: 637
diff changeset
40 class WebWidget(quick_widgets.QuickWidget, libervia_widget.LiberviaWidget):
181
c0b78a3af06d browser side: web widget first draft
Goffi <goffi@goffi.org>
parents: 179
diff changeset
41 """ (mini)browser like widget """
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
42
615
70872a83ef15 browser side (web panel): add an option to hide url headed + use it for public blog
Goffi <goffi@goffi.org>
parents: 612
diff changeset
43 def __init__(self, host, target, show_url=True, profiles=None):
181
c0b78a3af06d browser side: web widget first draft
Goffi <goffi@goffi.org>
parents: 179
diff changeset
44 """
c0b78a3af06d browser side: web widget first draft
Goffi <goffi@goffi.org>
parents: 179
diff changeset
45 @param host: SatWebFrontend instance
589
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 585
diff changeset
46 @param target: url to open
181
c0b78a3af06d browser side: web widget first draft
Goffi <goffi@goffi.org>
parents: 179
diff changeset
47 """
589
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 585
diff changeset
48 quick_widgets.QuickWidget.__init__(self, host, target, C.PROF_KEY_NONE)
648
6d3142b782c3 browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents: 637
diff changeset
49 libervia_widget.LiberviaWidget.__init__(self, host)
181
c0b78a3af06d browser side: web widget first draft
Goffi <goffi@goffi.org>
parents: 179
diff changeset
50 self._vpanel = VerticalPanel()
188
39936b83da9d Browser Side: Web Panel widget position/size fix
Goffi <goffi@goffi.org>
parents: 187
diff changeset
51 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
52 self._url = dialog.ExtTextBox(enter_cb=self.onUrlClick)
589
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 585
diff changeset
53 self._url.setText(target or "")
181
c0b78a3af06d browser side: web widget first draft
Goffi <goffi@goffi.org>
parents: 179
diff changeset
54 self._url.setWidth('100%')
615
70872a83ef15 browser side (web panel): add an option to hide url headed + use it for public blog
Goffi <goffi@goffi.org>
parents: 612
diff changeset
55 if show_url:
70872a83ef15 browser side (web panel): add an option to hide url headed + use it for public blog
Goffi <goffi@goffi.org>
parents: 612
diff changeset
56 hpanel = HorizontalPanel()
70872a83ef15 browser side (web panel): add an option to hide url headed + use it for public blog
Goffi <goffi@goffi.org>
parents: 612
diff changeset
57 hpanel.add(self._url)
70872a83ef15 browser side (web panel): add an option to hide url headed + use it for public blog
Goffi <goffi@goffi.org>
parents: 612
diff changeset
58 btn = Button("Go", self.onUrlClick)
70872a83ef15 browser side (web panel): add an option to hide url headed + use it for public blog
Goffi <goffi@goffi.org>
parents: 612
diff changeset
59 hpanel.setCellWidth(self._url, "100%")
70872a83ef15 browser side (web panel): add an option to hide url headed + use it for public blog
Goffi <goffi@goffi.org>
parents: 612
diff changeset
60 hpanel.add(btn)
70872a83ef15 browser side (web panel): add an option to hide url headed + use it for public blog
Goffi <goffi@goffi.org>
parents: 612
diff changeset
61 self._vpanel.add(hpanel)
70872a83ef15 browser side (web panel): add an option to hide url headed + use it for public blog
Goffi <goffi@goffi.org>
parents: 612
diff changeset
62 self._vpanel.setCellHeight(hpanel, '20px')
589
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 585
diff changeset
63 self._frame = Frame(target or "")
181
c0b78a3af06d browser side: web widget first draft
Goffi <goffi@goffi.org>
parents: 179
diff changeset
64 self._frame.setSize('100%', '100%')
188
39936b83da9d Browser Side: Web Panel widget position/size fix
Goffi <goffi@goffi.org>
parents: 187
diff changeset
65 DOM.setStyleAttribute(self._frame.getElement(), "position", "relative")
181
c0b78a3af06d browser side: web widget first draft
Goffi <goffi@goffi.org>
parents: 179
diff changeset
66 self._vpanel.add(self._frame)
c0b78a3af06d browser side: web widget first draft
Goffi <goffi@goffi.org>
parents: 179
diff changeset
67 self.setWidget(self._vpanel)
c0b78a3af06d browser side: web widget first draft
Goffi <goffi@goffi.org>
parents: 179
diff changeset
68
c0b78a3af06d browser side: web widget first draft
Goffi <goffi@goffi.org>
parents: 179
diff changeset
69 def onUrlClick(self, sender):
612
5983d6be4f07 browser side (web panel): schemes are now checked, if no scheme is given (or a not accepted one), http:// is used
Goffi <goffi@goffi.org>
parents: 589
diff changeset
70 url = self._url.getText()
5983d6be4f07 browser side (web panel): schemes are now checked, if no scheme is given (or a not accepted one), http:// is used
Goffi <goffi@goffi.org>
parents: 589
diff changeset
71 scheme_end = url.find(':')
5983d6be4f07 browser side (web panel): schemes are now checked, if no scheme is given (or a not accepted one), http:// is used
Goffi <goffi@goffi.org>
parents: 589
diff changeset
72 scheme = "" if scheme_end == -1 else url[:scheme_end]
5983d6be4f07 browser side (web panel): schemes are now checked, if no scheme is given (or a not accepted one), http:// is used
Goffi <goffi@goffi.org>
parents: 589
diff changeset
73 if scheme not in C.WEB_PANEL_SCHEMES:
5983d6be4f07 browser side (web panel): schemes are now checked, if no scheme is given (or a not accepted one), http:// is used
Goffi <goffi@goffi.org>
parents: 589
diff changeset
74 url = "http://" + url
5983d6be4f07 browser side (web panel): schemes are now checked, if no scheme is given (or a not accepted one), http:// is used
Goffi <goffi@goffi.org>
parents: 589
diff changeset
75 self._frame.setUrl(url)
676
849ffb24d5bf browser side: menus refactorisation:
Goffi <goffi@goffi.org>
parents: 648
diff changeset
76
849ffb24d5bf browser side: menus refactorisation:
Goffi <goffi@goffi.org>
parents: 648
diff changeset
77
849ffb24d5bf browser side: menus refactorisation:
Goffi <goffi@goffi.org>
parents: 648
diff changeset
78 ## Menu
849ffb24d5bf browser side: menus refactorisation:
Goffi <goffi@goffi.org>
parents: 648
diff changeset
79
849ffb24d5bf browser side: menus refactorisation:
Goffi <goffi@goffi.org>
parents: 648
diff changeset
80 def hostReady(host):
849ffb24d5bf browser side: menus refactorisation:
Goffi <goffi@goffi.org>
parents: 648
diff changeset
81 def onWebWidget():
849ffb24d5bf browser side: menus refactorisation:
Goffi <goffi@goffi.org>
parents: 648
diff changeset
82 web_widget = host.displayWidget(WebWidget, C.WEB_PANEL_DEFAULT_URL)
849ffb24d5bf browser side: menus refactorisation:
Goffi <goffi@goffi.org>
parents: 648
diff changeset
83 host.setSelected(web_widget)
849ffb24d5bf browser side: menus refactorisation:
Goffi <goffi@goffi.org>
parents: 648
diff changeset
84
849ffb24d5bf browser side: menus refactorisation:
Goffi <goffi@goffi.org>
parents: 648
diff changeset
85 def gotMenus():
849ffb24d5bf browser side: menus refactorisation:
Goffi <goffi@goffi.org>
parents: 648
diff changeset
86 host.menus.addMenu(C.MENU_GLOBAL, (D_(u"General"), D_(u"Web widget")), callback=onWebWidget)
849ffb24d5bf browser side: menus refactorisation:
Goffi <goffi@goffi.org>
parents: 648
diff changeset
87 host.addListener('gotMenus', gotMenus)
849ffb24d5bf browser side: menus refactorisation:
Goffi <goffi@goffi.org>
parents: 648
diff changeset
88
849ffb24d5bf browser side: menus refactorisation:
Goffi <goffi@goffi.org>
parents: 648
diff changeset
89 host_listener.addListener(hostReady)