From f0c61a2f38433233d853b90c71a4a0b9b787a745 Mon Sep 17 00:00:00 2001 From: Sai Vineet Date: Wed, 12 Mar 2014 17:16:21 +0000 Subject: Add theme switching to editor Now there is a view toolbar, which will have more options in the near future. --- 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 @@ + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + A + + 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 @@ + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + A + + 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): -- cgit v0.9.1