Mercurial > libervia-web
comparison browser/sat_browser/web_widget.py @ 1124:28e3eb3bb217
files reorganisation and installation rework:
- files have been reorganised to follow other SàT projects and usual Python organisation (no more "/src" directory)
- VERSION file is now used, as for other SàT projects
- replace the overcomplicated setup.py be a more sane one. Pyjamas part is not compiled anymore by setup.py, it must be done separatly
- removed check for data_dir if it's empty
- installation tested working in virtual env
- libervia launching script is now in bin/libervia
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 25 Aug 2018 17:59:48 +0200 |
parents | src/browser/sat_browser/web_widget.py@f2170536ba23 |
children | 2af117bfe6cc |
comparison
equal
deleted
inserted
replaced
1123:63a4b8fe9782 | 1124:28e3eb3bb217 |
---|---|
1 #!/usr/bin/python | |
2 # -*- coding: utf-8 -*- | |
3 | |
4 # Libervia: a Salut à Toi frontend | |
5 # Copyright (C) 2011-2018 Jérôme Poisson <goffi@goffi.org> | |
6 | |
7 # This program is free software: you can redistribute it and/or modify | |
8 # it under the terms of the GNU Affero General Public License as published by | |
9 # the Free Software Foundation, either version 3 of the License, or | |
10 # (at your option) any later version. | |
11 | |
12 # This program is distributed in the hope that it will be useful, | |
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 # GNU Affero General Public License for more details. | |
16 | |
17 # You should have received a copy of the GNU Affero General Public License | |
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 | |
20 import pyjd # this is dummy in pyjs | |
21 from sat.core.log import getLogger | |
22 log = getLogger(__name__) | |
23 | |
24 from sat.core.i18n import D_ | |
25 | |
26 from pyjamas.ui.VerticalPanel import VerticalPanel | |
27 from pyjamas.ui.HorizontalPanel import HorizontalPanel | |
28 from pyjamas.ui.Button import Button | |
29 from pyjamas.ui.Frame import Frame | |
30 from pyjamas import DOM | |
31 | |
32 | |
33 import dialog | |
34 import libervia_widget | |
35 from constants import Const as C | |
36 from sat_frontends.quick_frontend import quick_widgets | |
37 from sat_frontends.tools import host_listener | |
38 | |
39 | |
40 class WebWidget(quick_widgets.QuickWidget, libervia_widget.LiberviaWidget): | |
41 """ (mini)browser like widget """ | |
42 | |
43 def __init__(self, host, target, show_url=True, profiles=None): | |
44 """ | |
45 @param host: SatWebFrontend instance | |
46 @param target: url to open | |
47 """ | |
48 quick_widgets.QuickWidget.__init__(self, host, target, C.PROF_KEY_NONE) | |
49 libervia_widget.LiberviaWidget.__init__(self, host) | |
50 self._vpanel = VerticalPanel() | |
51 self._vpanel.setSize('100%', '100%') | |
52 self._url = dialog.ExtTextBox(enter_cb=self.onUrlClick) | |
53 self._url.setText(target or "") | |
54 self._url.setWidth('100%') | |
55 if show_url: | |
56 hpanel = HorizontalPanel() | |
57 hpanel.add(self._url) | |
58 btn = Button("Go", self.onUrlClick) | |
59 hpanel.setCellWidth(self._url, "100%") | |
60 hpanel.add(btn) | |
61 self._vpanel.add(hpanel) | |
62 self._vpanel.setCellHeight(hpanel, '20px') | |
63 self._frame = Frame(target or "") | |
64 self._frame.setSize('100%', '100%') | |
65 DOM.setStyleAttribute(self._frame.getElement(), "position", "relative") | |
66 self._vpanel.add(self._frame) | |
67 self.setWidget(self._vpanel) | |
68 | |
69 def onUrlClick(self, sender): | |
70 url = self._url.getText() | |
71 scheme_end = url.find(':') | |
72 scheme = "" if scheme_end == -1 else url[:scheme_end] | |
73 if scheme not in C.WEB_PANEL_SCHEMES: | |
74 url = "http://" + url | |
75 self._frame.setUrl(url) | |
76 | |
77 | |
78 ## Menu | |
79 | |
80 def hostReady(host): | |
81 def onWebWidget(): | |
82 web_widget = host.displayWidget(WebWidget, C.WEB_PANEL_DEFAULT_URL) | |
83 host.setSelected(web_widget) | |
84 | |
85 def gotMenus(): | |
86 host.menus.addMenu(C.MENU_GLOBAL, (D_(u"General"), D_(u"Web widget")), callback=onWebWidget) | |
87 host.addListener('gotMenus', gotMenus) | |
88 | |
89 host_listener.addListener(hostReady) |