Feature - dark mode for embedded terminal and source view
James Cameron
4 years ago
0 | <?xml version="1.0" encoding="UTF-8" standalone="no"?> | |
1 | <!-- Created with Inkscape (http://www.inkscape.org/) --> | |
2 | ||
3 | <svg | |
4 | xmlns:dc="http://purl.org/dc/elements/1.1/" | |
5 | xmlns:cc="http://creativecommons.org/ns#" | |
6 | xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" | |
7 | xmlns:svg="http://www.w3.org/2000/svg" | |
8 | xmlns="http://www.w3.org/2000/svg" | |
9 | xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" | |
10 | xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" | |
11 | width="32px" | |
12 | height="32px" | |
13 | id="svg2985" | |
14 | version="1.1" | |
15 | inkscape:version="0.48.3.1 r9886" | |
16 | sodipodi:docname="dark-theme.svg"> | |
17 | <defs | |
18 | id="defs2987" /> | |
19 | <sodipodi:namedview | |
20 | id="base" | |
21 | pagecolor="#ffffff" | |
22 | bordercolor="#666666" | |
23 | borderopacity="1.0" | |
24 | inkscape:pageopacity="0.0" | |
25 | inkscape:pageshadow="2" | |
26 | inkscape:zoom="12.219689" | |
27 | inkscape:cx="12.682313" | |
28 | inkscape:cy="14.416406" | |
29 | inkscape:current-layer="layer1" | |
30 | showgrid="true" | |
31 | inkscape:grid-bbox="true" | |
32 | inkscape:document-units="px" | |
33 | inkscape:snap-global="false" | |
34 | objecttolerance="10000" | |
35 | guidetolerance="10000" | |
36 | showguides="false" | |
37 | inkscape:window-width="1360" | |
38 | inkscape:window-height="712" | |
39 | inkscape:window-x="0" | |
40 | inkscape:window-y="27" | |
41 | inkscape:window-maximized="1"> | |
42 | <sodipodi:guide | |
43 | position="0,0" | |
44 | orientation="0,32" | |
45 | id="guide3767" /> | |
46 | <sodipodi:guide | |
47 | position="32,0" | |
48 | orientation="-32,0" | |
49 | id="guide3769" /> | |
50 | <sodipodi:guide | |
51 | position="32,32" | |
52 | orientation="0,-32" | |
53 | id="guide3771" /> | |
54 | <sodipodi:guide | |
55 | position="0,32" | |
56 | orientation="32,0" | |
57 | id="guide3773" /> | |
58 | <inkscape:grid | |
59 | type="xygrid" | |
60 | id="grid3775" | |
61 | empspacing="5" | |
62 | visible="true" | |
63 | enabled="true" | |
64 | snapvisiblegridlinesonly="true" /> | |
65 | <sodipodi:guide | |
66 | position="0,0" | |
67 | orientation="0,32" | |
68 | id="guide3777" /> | |
69 | <sodipodi:guide | |
70 | position="32,0" | |
71 | orientation="-32,0" | |
72 | id="guide3779" /> | |
73 | <sodipodi:guide | |
74 | position="32,32" | |
75 | orientation="0,-32" | |
76 | id="guide3781" /> | |
77 | <sodipodi:guide | |
78 | position="0,32" | |
79 | orientation="32,0" | |
80 | id="guide3783" /> | |
81 | <sodipodi:guide | |
82 | position="0,0" | |
83 | orientation="0,32" | |
84 | id="guide3785" /> | |
85 | <sodipodi:guide | |
86 | position="32,0" | |
87 | orientation="-32,0" | |
88 | id="guide3787" /> | |
89 | <sodipodi:guide | |
90 | position="32,32" | |
91 | orientation="0,-32" | |
92 | id="guide3789" /> | |
93 | <sodipodi:guide | |
94 | position="0,32" | |
95 | orientation="32,0" | |
96 | id="guide3791" /> | |
97 | </sodipodi:namedview> | |
98 | <metadata | |
99 | id="metadata2990"> | |
100 | <rdf:RDF> | |
101 | <cc:Work | |
102 | rdf:about=""> | |
103 | <dc:format>image/svg+xml</dc:format> | |
104 | <dc:type | |
105 | rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> | |
106 | <dc:title></dc:title> | |
107 | </cc:Work> | |
108 | </rdf:RDF> | |
109 | </metadata> | |
110 | <g | |
111 | id="layer1" | |
112 | inkscape:label="Layer 1" | |
113 | inkscape:groupmode="layer"> | |
114 | <rect | |
115 | style="fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:none" | |
116 | id="rect2993" | |
117 | width="31.022896" | |
118 | height="31.194761" | |
119 | x="0.66299194" | |
120 | y="0.60228604" | |
121 | ry="2.9258621" /> | |
122 | <text | |
123 | xml:space="preserve" | |
124 | style="font-size:11.23703003px;font-style:normal;font-weight:normal;line-height:125%;letter-spacing:0px;word-spacing:0px;fill:#ffffff;fill-opacity:1;stroke:none;font-family:Sans" | |
125 | x="5.8393445" | |
126 | y="26.455677" | |
127 | id="text3763" | |
128 | sodipodi:linespacing="125%"><tspan | |
129 | sodipodi:role="line" | |
130 | id="tspan3765" | |
131 | x="5.8393445" | |
132 | y="26.455677" | |
133 | style="font-size:30.90183258px;fill:#ffffff;fill-opacity:1">A</tspan></text> | |
134 | </g> | |
135 | </svg> |
0 | <?xml version="1.0" encoding="UTF-8" standalone="no"?> | |
1 | <!-- Created with Inkscape (http://www.inkscape.org/) --> | |
2 | ||
3 | <svg | |
4 | xmlns:dc="http://purl.org/dc/elements/1.1/" | |
5 | xmlns:cc="http://creativecommons.org/ns#" | |
6 | xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" | |
7 | xmlns:svg="http://www.w3.org/2000/svg" | |
8 | xmlns="http://www.w3.org/2000/svg" | |
9 | xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" | |
10 | xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" | |
11 | width="32px" | |
12 | height="32px" | |
13 | id="svg2985" | |
14 | version="1.1" | |
15 | inkscape:version="0.48.3.1 r9886" | |
16 | sodipodi:docname="dark-theme.svg"> | |
17 | <defs | |
18 | id="defs2987" /> | |
19 | <sodipodi:namedview | |
20 | id="base" | |
21 | pagecolor="#ffffff" | |
22 | bordercolor="#666666" | |
23 | borderopacity="1.0" | |
24 | inkscape:pageopacity="0.0" | |
25 | inkscape:pageshadow="2" | |
26 | inkscape:zoom="12.219689" | |
27 | inkscape:cx="12.682313" | |
28 | inkscape:cy="14.416406" | |
29 | inkscape:current-layer="layer1" | |
30 | showgrid="true" | |
31 | inkscape:grid-bbox="true" | |
32 | inkscape:document-units="px" | |
33 | inkscape:snap-global="false" | |
34 | objecttolerance="10000" | |
35 | guidetolerance="10000" | |
36 | showguides="false" | |
37 | inkscape:window-width="1360" | |
38 | inkscape:window-height="712" | |
39 | inkscape:window-x="0" | |
40 | inkscape:window-y="27" | |
41 | inkscape:window-maximized="1"> | |
42 | <sodipodi:guide | |
43 | position="0,0" | |
44 | orientation="0,32" | |
45 | id="guide3767" /> | |
46 | <sodipodi:guide | |
47 | position="32,0" | |
48 | orientation="-32,0" | |
49 | id="guide3769" /> | |
50 | <sodipodi:guide | |
51 | position="32,32" | |
52 | orientation="0,-32" | |
53 | id="guide3771" /> | |
54 | <sodipodi:guide | |
55 | position="0,32" | |
56 | orientation="32,0" | |
57 | id="guide3773" /> | |
58 | <inkscape:grid | |
59 | type="xygrid" | |
60 | id="grid3775" | |
61 | empspacing="5" | |
62 | visible="true" | |
63 | enabled="true" | |
64 | snapvisiblegridlinesonly="true" /> | |
65 | <sodipodi:guide | |
66 | position="0,0" | |
67 | orientation="0,32" | |
68 | id="guide3777" /> | |
69 | <sodipodi:guide | |
70 | position="32,0" | |
71 | orientation="-32,0" | |
72 | id="guide3779" /> | |
73 | <sodipodi:guide | |
74 | position="32,32" | |
75 | orientation="0,-32" | |
76 | id="guide3781" /> | |
77 | <sodipodi:guide | |
78 | position="0,32" | |
79 | orientation="32,0" | |
80 | id="guide3783" /> | |
81 | <sodipodi:guide | |
82 | position="0,0" | |
83 | orientation="0,32" | |
84 | id="guide3785" /> | |
85 | <sodipodi:guide | |
86 | position="32,0" | |
87 | orientation="-32,0" | |
88 | id="guide3787" /> | |
89 | <sodipodi:guide | |
90 | position="32,32" | |
91 | orientation="0,-32" | |
92 | id="guide3789" /> | |
93 | <sodipodi:guide | |
94 | position="0,32" | |
95 | orientation="32,0" | |
96 | id="guide3791" /> | |
97 | </sodipodi:namedview> | |
98 | <metadata | |
99 | id="metadata2990"> | |
100 | <rdf:RDF> | |
101 | <cc:Work | |
102 | rdf:about=""> | |
103 | <dc:format>image/svg+xml</dc:format> | |
104 | <dc:type | |
105 | rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> | |
106 | <dc:title></dc:title> | |
107 | </cc:Work> | |
108 | </rdf:RDF> | |
109 | </metadata> | |
110 | <g | |
111 | id="layer1" | |
112 | inkscape:label="Layer 1" | |
113 | inkscape:groupmode="layer"> | |
114 | <rect | |
115 | style="fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:none" | |
116 | id="rect2993" | |
117 | width="31.022896" | |
118 | height="31.194761" | |
119 | x="0.66299194" | |
120 | y="0.60228604" | |
121 | ry="2.9258621" /> | |
122 | <text | |
123 | xml:space="preserve" | |
124 | style="font-size:11.23703002999999967px;font-style:normal;font-weight:normal;line-height:125%;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;font-family:Sans" | |
125 | x="5.8393445" | |
126 | y="26.455677" | |
127 | id="text3763" | |
128 | sodipodi:linespacing="125%"><tspan | |
129 | sodipodi:role="line" | |
130 | id="tspan3765" | |
131 | x="5.8393445" | |
132 | y="26.455677" | |
133 | style="font-size:30.90183258000000066px;fill:#000000;fill-opacity:1">A</tspan></text> | |
134 | </g> | |
135 | </svg> |
147 | 147 | def __init__(self, buffer_text, editor_id, collab): |
148 | 148 | GtkSource.View.__init__(self) |
149 | 149 | |
150 | self._css_provider = Gtk.CssProvider() | |
151 | self.set_light() | |
152 | self.get_style_context().add_provider( | |
153 | self._css_provider, Gtk.STYLE_PROVIDER_PRIORITY_USER) | |
154 | ||
150 | 155 | text_buffer = GtkSource.Buffer() |
151 | 156 | TextBufferCollaberizer(text_buffer, editor_id, collab) |
152 | 157 | |
188 | 193 | Pango.FontDescription( |
189 | 194 | 'Monospace {}'.format(font_size))) |
190 | 195 | |
196 | def set_dark(self): | |
197 | theme = b""" | |
198 | textview text { | |
199 | background: @black; | |
200 | color: @white; | |
201 | }""" | |
202 | self._css_provider.load_from_data(theme) | |
203 | ||
204 | def set_light(self): | |
205 | theme = b""" | |
206 | textview text { | |
207 | background: @white; | |
208 | color: @black; | |
209 | }""" | |
210 | self._css_provider.load_from_data(theme) | |
191 | 211 | |
192 | 212 | class SourceNotebook(AddNotebook): |
193 | 213 | def __init__(self, activity, collab): |
351 | 371 | def get_font_size(self): |
352 | 372 | return self._font_size |
353 | 373 | |
374 | def set_light(self): | |
375 | for i in range(self.get_n_pages()): | |
376 | page = self.get_nth_page(i) | |
377 | children = page.get_children() | |
378 | children[0].set_light() | |
379 | ||
380 | def set_dark(self): | |
381 | for i in range(self.get_n_pages()): | |
382 | page = self.get_nth_page(i) | |
383 | children = page.get_children() | |
384 | children[0].set_dark() | |
385 | ||
354 | 386 | def child_exited_cb(self, *args): |
355 | 387 | '''Called whenever a child exits. If there's a handler, runadd it.''' |
356 | 388 | h, self.activity._child_exited_handler = \ |
250 | 250 | actions_toolbar.insert(self._toggle_output, -1) |
251 | 251 | self._toggle_output.show() |
252 | 252 | |
253 | self._inverted_colors = ToggleToolButton(icon_name='dark-theme') | |
254 | self._inverted_colors.set_tooltip(_('Inverted Colors')) | |
255 | self._inverted_colors.set_accelerator('<Ctrl><Shift>I') | |
256 | self._inverted_colors.connect( | |
257 | 'toggled', self.__inverted_colors_toggled_cb) | |
258 | actions_toolbar.insert(self._inverted_colors, -1) | |
259 | self._inverted_colors.show() | |
260 | ||
253 | 261 | icons_path = os.path.join(get_bundle_path(), 'icons') |
254 | 262 | |
255 | 263 | icon_bw = Gtk.Image() |
403 | 411 | self._vte.set_size(30, 5) |
404 | 412 | self._vte.set_scrollback_lines(-1) |
405 | 413 | |
406 | # XXX support both Vte APIs | |
407 | if _has_new_vte_api(): | |
408 | foreground = Gdk.RGBA() | |
409 | foreground.parse('#000000') | |
410 | background = Gdk.RGBA() | |
411 | background.parse('#E7E7E7') | |
412 | else: | |
413 | foreground = Gdk.color_parse('#000000') | |
414 | background = Gdk.color_parse('#E7E7E7') | |
415 | ||
416 | self._vte.set_colors(foreground, background, []) | |
414 | self._vte_set_colors('#000000', '#E7E7E7') | |
417 | 415 | |
418 | 416 | self._child_exited_handler = None |
419 | 417 | self._vte.connect('child_exited', self._child_exited_cb) |
431 | 429 | self._outbox.show() |
432 | 430 | vpane.show() |
433 | 431 | return vpane |
432 | ||
433 | def _vte_set_colors(self, bg, fg): | |
434 | # XXX support both Vte APIs | |
435 | if _has_new_vte_api(): | |
436 | foreground = Gdk.RGBA() | |
437 | foreground.parse(bg) | |
438 | background = Gdk.RGBA() | |
439 | background.parse(fg) | |
440 | else: | |
441 | foreground = Gdk.color_parse(bg) | |
442 | background = Gdk.color_parse(fg) | |
443 | ||
444 | self._vte.set_colors(foreground, background, []) | |
434 | 445 | |
435 | 446 | def after_init(self): |
436 | 447 | self._outbox.hide() |
495 | 506 | self._outbox.hide() |
496 | 507 | self._toggle_output.set_tooltip(_('Show output panel')) |
497 | 508 | self._toggle_output.set_icon_name('tray-show') |
509 | ||
510 | def __inverted_colors_toggled_cb(self, button): | |
511 | if button.props.active: | |
512 | self._vte_set_colors('#E7E7E7', '#000000') | |
513 | self._source_tabs.set_dark() | |
514 | button.set_icon_name('light-theme') | |
515 | button.set_tooltip(_('Normal Colors')) | |
516 | else: | |
517 | self._vte_set_colors('#000000', '#E7E7E7') | |
518 | self._source_tabs.set_light() | |
519 | button.set_icon_name('dark-theme') | |
520 | button.set_tooltip(_('Inverted Colors')) | |
498 | 521 | |
499 | 522 | def _load_example_cb(self, widget): |
500 | 523 | widget.set_icon_name('pippy-openon') |