1 | import os |
---|
2 | |
---|
3 | from gi.repository import Gtk |
---|
4 | from gi.repository import WebKit |
---|
5 | from gi.repository import GConf |
---|
6 | |
---|
7 | from jarabe import config |
---|
8 | |
---|
9 | |
---|
10 | def setup_theme(): |
---|
11 | settings = Gtk.Settings.get_default() |
---|
12 | sugar_theme = 'sugar-72' |
---|
13 | if 'SUGAR_SCALING' in os.environ: |
---|
14 | if os.environ['SUGAR_SCALING'] == '100': |
---|
15 | sugar_theme = 'sugar-100' |
---|
16 | settings.set_property('gtk-theme-name', sugar_theme) |
---|
17 | settings.set_property('gtk-icon-theme-name', 'sugar') |
---|
18 | |
---|
19 | icons_path = os.path.join(config.data_path, 'icons') |
---|
20 | Gtk.IconTheme.get_default().append_search_path(icons_path) |
---|
21 | |
---|
22 | def setup_fonts(): |
---|
23 | client = GConf.Client.get_default() |
---|
24 | face = client.get_string('/desktop/sugar/font/default_face') |
---|
25 | size = client.get_float('/desktop/sugar/font/default_size') |
---|
26 | settings = Gtk.Settings.get_default() |
---|
27 | settings.set_property("gtk-font-name", "%s %f" % (face, size)) |
---|
28 | |
---|
29 | setup_fonts() |
---|
30 | setup_theme() |
---|
31 | |
---|
32 | CSS_STYLE = """ |
---|
33 | body { |
---|
34 | background-color: #ffffff; |
---|
35 | } |
---|
36 | audio, video { |
---|
37 | width: 500px; |
---|
38 | height: 55px; |
---|
39 | color: #ffffff; |
---|
40 | } |
---|
41 | audio::-webkit-media-controls-enclosure, video::-webkit-media-controls-enclosure { |
---|
42 | height: 55px; |
---|
43 | } |
---|
44 | audio::-webkit-media-controls-panel, video::-webkit-media-controls-panel { |
---|
45 | height: 55px; |
---|
46 | background-color: #282828; |
---|
47 | border-radius: 25px; |
---|
48 | } |
---|
49 | audio::-webkit-media-controls-mute-button, video::-webkit-media-controls-mute-button, |
---|
50 | audio::-webkit-media-controls-play-button, video::-webkit-media-controls-play-button, |
---|
51 | audio::-webkit-media-controls-toggle-closed-captions-button, video::-webkit-media-controls-toggle-closed-captions-button, |
---|
52 | audio::-webkit-media-controls-fullscreen-button, video::-webkit-media-controls-fullscreen-button, |
---|
53 | audio::-webkit-media-controls-seek-back-button, video::-webkit-media-controls-seek-back-button, |
---|
54 | audio::-webkit-media-controls-seek-forward-button, video::-webkit-media-controls-seek-forward-button { |
---|
55 | width: 55px; |
---|
56 | height: 55px; |
---|
57 | } |
---|
58 | audio::-webkit-media-controls-current-time-display, video::-webkit-media-controls-current-time-display, |
---|
59 | audio::-webkit-media-controls-time-remaining-display, video::-webkit-media-controls-time-remaining-display { |
---|
60 | height: 55px; |
---|
61 | line-height: 0px; |
---|
62 | font-size: 23px; |
---|
63 | text-align: center; |
---|
64 | } |
---|
65 | """.replace('\n', '') |
---|
66 | |
---|
67 | INJECT_STYLE_SCRIPT = """ |
---|
68 | var style = document.createElement('style'); |
---|
69 | style.innerHTML = '%s'; |
---|
70 | document.body.appendChild(style); |
---|
71 | """ % CSS_STYLE |
---|
72 | |
---|
73 | |
---|
74 | class MyWindow(Gtk.Window): |
---|
75 | def __init__(self): |
---|
76 | Gtk.Window.__init__(self) |
---|
77 | self.resize(800, 600) |
---|
78 | self.connect('destroy', lambda w: Gtk.main_quit()) |
---|
79 | |
---|
80 | scrolled = Gtk.ScrolledWindow() |
---|
81 | self.add(scrolled) |
---|
82 | scrolled.show() |
---|
83 | |
---|
84 | self.inject_style = False |
---|
85 | |
---|
86 | view = WebKit.WebView() |
---|
87 | view_settings = view.get_settings() |
---|
88 | view_settings.props.enable_file_access_from_file_uris = True |
---|
89 | view.set_settings(view_settings) |
---|
90 | |
---|
91 | view.connect('notify::load-status', self.on_load_status) |
---|
92 | view.connect('load-error', self.load_error_cb) |
---|
93 | view.connect('mime-type-policy-decision-requested', |
---|
94 | self.mime_type_policy_cb) |
---|
95 | |
---|
96 | view.load_uri("file:///home/olpc/Library/JamendoMusic/2970.ogg") |
---|
97 | scrolled.add(view) |
---|
98 | view.show() |
---|
99 | |
---|
100 | def on_load_status(self, widget, param): |
---|
101 | status = widget.get_load_status() |
---|
102 | |
---|
103 | def mime_type_policy_cb(self, web_view, web_frame, request, mimetype, |
---|
104 | policy_decision): |
---|
105 | if mimetype == 'audio/x-vorbis+ogg': |
---|
106 | self.inject_style = True |
---|
107 | |
---|
108 | def load_error_cb(self, web_view, web_frame, uri, web_error): |
---|
109 | if web_error.code in (WebKit.PolicyError.\ |
---|
110 | FRAME_LOAD_INTERRUPTED_BY_POLICY_CHANGE, |
---|
111 | WebKit.PluginError.WILL_HANDLE_LOAD): |
---|
112 | if self.inject_style: |
---|
113 | web_view.execute_script(INJECT_STYLE_SCRIPT) |
---|
114 | |
---|
115 | |
---|
116 | window = MyWindow() |
---|
117 | window.show() |
---|
118 | |
---|
119 | Gtk.main() |
---|