Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSai Vineet <saivineet89@gmail.com>2014-03-12 17:16:21 (GMT)
committer Gonzalo Odiard <godiard@gmail.com>2014-03-13 20:14:15 (GMT)
commitf0c61a2f38433233d853b90c71a4a0b9b787a745 (patch)
tree03e58d5fd0873410042cb3ea9d129936337a8a66
parent0f015f654595452918bd77ba2e7ee8842bb8e365 (diff)
Add theme switching to editor
Now there is a view toolbar, which will have more options in the near future.
-rw-r--r--develop-activity/develop_app.py12
-rw-r--r--develop-activity/icons/dark-theme.svg136
-rw-r--r--develop-activity/icons/light-theme.svg136
-rw-r--r--develop-activity/sourceview_editor.py27
-rw-r--r--develop-activity/toolbars.py26
5 files changed, 336 insertions, 1 deletions
diff --git a/develop-activity/develop_app.py b/develop-activity/develop_app.py
index b55e7a7..b83d0de 100644
--- a/develop-activity/develop_app.py
+++ b/develop-activity/develop_app.py
@@ -49,6 +49,7 @@ import sourceview_editor
S_WHERE = sourceview_editor.S_WHERE
from symbols_tree import SymbolsTree
from toolbars import DevelopEditToolbar, DevelopSearchToolbar
+from toolbars import DevelopViewToolbar
from widgets import FileViewer, WelcomePage
SEARCH_ICONS = {False: {S_WHERE.selection: "search-in-selection",
@@ -73,6 +74,8 @@ class DevelopActivity(activity.Activity):
super(DevelopActivity, self).__init__(handle)
self.max_participants = 1
+ self.current_theme = "light"
+
logging.info(repr(handle.get_dict()))
# Source buffer
@@ -85,6 +88,15 @@ class DevelopActivity(activity.Activity):
toolbarbox.toolbar.insert(activity_button, 0)
self.set_toolbar_box(toolbarbox)
+ view_btn = ToolbarButton()
+ view_toolbar = DevelopViewToolbar(self)
+ view_btn.props.page = view_toolbar
+ view_btn.props.icon_name = 'toolbar-view'
+ view_btn.props.label = _('View')
+ view_toolbar.connect('theme-changed',
+ self.editor.theme_changed_cb)
+ toolbarbox.toolbar.insert(view_btn, -1)
+
edit_btn = ToolbarButton()
edit_btn.props.page = DevelopEditToolbar(self)
edit_btn.props.icon_name = 'toolbar-edit'
diff --git a/develop-activity/icons/dark-theme.svg b/develop-activity/icons/dark-theme.svg
new file mode 100644
index 0000000..6a44324
--- /dev/null
+++ b/develop-activity/icons/dark-theme.svg
@@ -0,0 +1,136 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!-- Created with Inkscape (http://www.inkscape.org/) -->
+
+<svg
+ xmlns:dc="http://purl.org/dc/elements/1.1/"
+ xmlns:cc="http://creativecommons.org/ns#"
+ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+ xmlns:svg="http://www.w3.org/2000/svg"
+ xmlns="http://www.w3.org/2000/svg"
+ xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
+ xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
+ width="32px"
+ height="32px"
+ id="svg2985"
+ version="1.1"
+ inkscape:version="0.48.3.1 r9886"
+ sodipodi:docname="dark-theme.svg">
+ <defs
+ id="defs2987" />
+ <sodipodi:namedview
+ id="base"
+ pagecolor="#ffffff"
+ bordercolor="#666666"
+ borderopacity="1.0"
+ inkscape:pageopacity="0.0"
+ inkscape:pageshadow="2"
+ inkscape:zoom="12.219689"
+ inkscape:cx="12.682313"
+ inkscape:cy="14.416406"
+ inkscape:current-layer="layer1"
+ showgrid="true"
+ inkscape:grid-bbox="true"
+ inkscape:document-units="px"
+ inkscape:snap-global="false"
+ objecttolerance="10000"
+ guidetolerance="10000"
+ showguides="false"
+ inkscape:window-width="1360"
+ inkscape:window-height="712"
+ inkscape:window-x="0"
+ inkscape:window-y="27"
+ inkscape:window-maximized="1">
+ <sodipodi:guide
+ position="0,0"
+ orientation="0,32"
+ id="guide3767" />
+ <sodipodi:guide
+ position="32,0"
+ orientation="-32,0"
+ id="guide3769" />
+ <sodipodi:guide
+ position="32,32"
+ orientation="0,-32"
+ id="guide3771" />
+ <sodipodi:guide
+ position="0,32"
+ orientation="32,0"
+ id="guide3773" />
+ <inkscape:grid
+ type="xygrid"
+ id="grid3775"
+ empspacing="5"
+ visible="true"
+ enabled="true"
+ snapvisiblegridlinesonly="true" />
+ <sodipodi:guide
+ position="0,0"
+ orientation="0,32"
+ id="guide3777" />
+ <sodipodi:guide
+ position="32,0"
+ orientation="-32,0"
+ id="guide3779" />
+ <sodipodi:guide
+ position="32,32"
+ orientation="0,-32"
+ id="guide3781" />
+ <sodipodi:guide
+ position="0,32"
+ orientation="32,0"
+ id="guide3783" />
+ <sodipodi:guide
+ position="0,0"
+ orientation="0,32"
+ id="guide3785" />
+ <sodipodi:guide
+ position="32,0"
+ orientation="-32,0"
+ id="guide3787" />
+ <sodipodi:guide
+ position="32,32"
+ orientation="0,-32"
+ id="guide3789" />
+ <sodipodi:guide
+ position="0,32"
+ orientation="32,0"
+ id="guide3791" />
+ </sodipodi:namedview>
+ <metadata
+ id="metadata2990">
+ <rdf:RDF>
+ <cc:Work
+ rdf:about="">
+ <dc:format>image/svg+xml</dc:format>
+ <dc:type
+ rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
+ <dc:title></dc:title>
+ </cc:Work>
+ </rdf:RDF>
+ </metadata>
+ <g
+ id="layer1"
+ inkscape:label="Layer 1"
+ inkscape:groupmode="layer">
+ <rect
+ style="fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:none"
+ id="rect2993"
+ width="31.022896"
+ height="31.194761"
+ x="0.66299194"
+ y="0.60228604"
+ ry="2.9258621" />
+ <text
+ xml:space="preserve"
+ 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"
+ x="5.8393445"
+ y="26.455677"
+ id="text3763"
+ sodipodi:linespacing="125%"><tspan
+ sodipodi:role="line"
+ id="tspan3765"
+ x="5.8393445"
+ y="26.455677"
+ style="font-size:30.90183258px;fill:#ffffff;fill-opacity:1">A</tspan></text>
+ </g>
+</svg>
diff --git a/develop-activity/icons/light-theme.svg b/develop-activity/icons/light-theme.svg
new file mode 100644
index 0000000..8dea23f
--- /dev/null
+++ b/develop-activity/icons/light-theme.svg
@@ -0,0 +1,136 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!-- Created with Inkscape (http://www.inkscape.org/) -->
+
+<svg
+ xmlns:dc="http://purl.org/dc/elements/1.1/"
+ xmlns:cc="http://creativecommons.org/ns#"
+ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+ xmlns:svg="http://www.w3.org/2000/svg"
+ xmlns="http://www.w3.org/2000/svg"
+ xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
+ xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
+ width="32px"
+ height="32px"
+ id="svg2985"
+ version="1.1"
+ inkscape:version="0.48.3.1 r9886"
+ sodipodi:docname="dark-theme.svg">
+ <defs
+ id="defs2987" />
+ <sodipodi:namedview
+ id="base"
+ pagecolor="#ffffff"
+ bordercolor="#666666"
+ borderopacity="1.0"
+ inkscape:pageopacity="0.0"
+ inkscape:pageshadow="2"
+ inkscape:zoom="12.219689"
+ inkscape:cx="12.682313"
+ inkscape:cy="14.416406"
+ inkscape:current-layer="layer1"
+ showgrid="true"
+ inkscape:grid-bbox="true"
+ inkscape:document-units="px"
+ inkscape:snap-global="false"
+ objecttolerance="10000"
+ guidetolerance="10000"
+ showguides="false"
+ inkscape:window-width="1360"
+ inkscape:window-height="712"
+ inkscape:window-x="0"
+ inkscape:window-y="27"
+ inkscape:window-maximized="1">
+ <sodipodi:guide
+ position="0,0"
+ orientation="0,32"
+ id="guide3767" />
+ <sodipodi:guide
+ position="32,0"
+ orientation="-32,0"
+ id="guide3769" />
+ <sodipodi:guide
+ position="32,32"
+ orientation="0,-32"
+ id="guide3771" />
+ <sodipodi:guide
+ position="0,32"
+ orientation="32,0"
+ id="guide3773" />
+ <inkscape:grid
+ type="xygrid"
+ id="grid3775"
+ empspacing="5"
+ visible="true"
+ enabled="true"
+ snapvisiblegridlinesonly="true" />
+ <sodipodi:guide
+ position="0,0"
+ orientation="0,32"
+ id="guide3777" />
+ <sodipodi:guide
+ position="32,0"
+ orientation="-32,0"
+ id="guide3779" />
+ <sodipodi:guide
+ position="32,32"
+ orientation="0,-32"
+ id="guide3781" />
+ <sodipodi:guide
+ position="0,32"
+ orientation="32,0"
+ id="guide3783" />
+ <sodipodi:guide
+ position="0,0"
+ orientation="0,32"
+ id="guide3785" />
+ <sodipodi:guide
+ position="32,0"
+ orientation="-32,0"
+ id="guide3787" />
+ <sodipodi:guide
+ position="32,32"
+ orientation="0,-32"
+ id="guide3789" />
+ <sodipodi:guide
+ position="0,32"
+ orientation="32,0"
+ id="guide3791" />
+ </sodipodi:namedview>
+ <metadata
+ id="metadata2990">
+ <rdf:RDF>
+ <cc:Work
+ rdf:about="">
+ <dc:format>image/svg+xml</dc:format>
+ <dc:type
+ rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
+ <dc:title></dc:title>
+ </cc:Work>
+ </rdf:RDF>
+ </metadata>
+ <g
+ id="layer1"
+ inkscape:label="Layer 1"
+ inkscape:groupmode="layer">
+ <rect
+ style="fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:none"
+ id="rect2993"
+ width="31.022896"
+ height="31.194761"
+ x="0.66299194"
+ y="0.60228604"
+ ry="2.9258621" />
+ <text
+ xml:space="preserve"
+ 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"
+ x="5.8393445"
+ y="26.455677"
+ id="text3763"
+ sodipodi:linespacing="125%"><tspan
+ sodipodi:role="line"
+ id="tspan3765"
+ x="5.8393445"
+ y="26.455677"
+ style="font-size:30.90183258000000066px;fill:#000000;fill-opacity:1">A</tspan></text>
+ </g>
+</svg>
diff --git a/develop-activity/sourceview_editor.py b/develop-activity/sourceview_editor.py
index fcdf1fb..9e2cb77 100644
--- a/develop-activity/sourceview_editor.py
+++ b/develop-activity/sourceview_editor.py
@@ -49,6 +49,18 @@ class GtkSourceview2Editor(Gtk.Notebook):
self.connect('switch-page', self._switch_page_cb)
self.set_scrollable(True)
+ self.theme_state = "light"
+
+ def theme_changed_cb(self, widget, theme_name):
+ self.theme_state = theme_name
+ for i in range(0, self.get_n_pages()):
+ page = self.get_nth_page(i)
+ children = page.get_children()
+ if isinstance(children[0], Icon):
+ children[1].get_children()[0].set_theme(theme_name)
+ else:
+ children[0].get_children()[0].set_theme(theme_name)
+
def _page_removed_cb(self, __notebook, page, n):
try:
page.page.remove()
@@ -75,6 +87,7 @@ class GtkSourceview2Editor(Gtk.Notebook):
Gtk.PolicyType.AUTOMATIC)
page = GtkSourceview2Page(full_path)
+ page.set_theme(self.theme_state)
vbox = Gtk.VBox()
if full_path.endswith('.svg'):
@@ -262,9 +275,15 @@ class GtkSourceview2Page(GtkSource.View):
self.set_cursor_visible(True)
self.set_show_line_numbers(True)
self.set_insert_spaces_instead_of_tabs(True)
+ self.set_highlight_current_line(True)
self.text_buffer = GtkSource.Buffer()
+ stylemanager = GtkSource.StyleSchemeManager()
+ self.light_theme = stylemanager.get_scheme('classic')
+ self.dark_theme = stylemanager.get_scheme('oblivion')
+ self.text_buffer.set_style_scheme(self.light_theme)
+
# Tags for search
tagtable = self.text_buffer.get_tag_table()
hilite_tag = Gtk.TextTag.new('search-hilite')
@@ -284,6 +303,14 @@ class GtkSourceview2Page(GtkSource.View):
self.load_text()
self.show()
+ def set_theme(self, theme):
+ if theme == "light":
+ self.text_buffer.set_style_scheme(self.light_theme)
+ # print "light"
+ elif theme == "dark":
+ self.text_buffer.set_style_scheme(self.dark_theme)
+ # print "dark"
+
def load_text(self, offset=None):
'''
Load the text, and optionally scroll to the given offset in the file.
diff --git a/develop-activity/toolbars.py b/develop-activity/toolbars.py
index 7bee272..f8b0807 100644
--- a/develop-activity/toolbars.py
+++ b/develop-activity/toolbars.py
@@ -37,11 +37,35 @@ SEARCH_ICONS = {False: {S_WHERE.selection: "search-in-selection",
class DevelopViewToolbar(Gtk.Toolbar):
+ __gsignals__ = {
+ 'theme-changed': (GObject.SIGNAL_RUN_FIRST, None,
+ (str,))
+ }
def __init__(self, _activity):
+ GObject.GObject.__init__(self)
+
self._activity = _activity
- # theme_toggler = ToggleToolButton()
+ self.theme_toggler = ToolButton('dark-theme')
+ self.theme_state = "light"
+ self.theme_toggler.connect('clicked', self._toggled_theme)
+ self.insert(self.theme_toggler, -1)
+ self.theme_toggler.show()
+
+ self.show()
+
+ def _toggled_theme(self, button):
+ if self.theme_state == "dark":
+ self.theme_state = "light"
+ self.theme_toggler.set_icon_name('dark-theme')
+ self.theme_toggler.set_tooltip('Switch to Dark Theme')
+ elif self.theme_state == "light":
+ self.theme_state = "dark"
+ self.theme_toggler.set_icon_name('light-theme')
+ self.theme_toggler.set_tooltip('Switch to Light Theme')
+
+ self.emit('theme-changed', self.theme_state)
class DevelopEditToolbar(EditToolbar):