From 2caf38174220b58bb0b662cb9797aff9fd11d601 Mon Sep 17 00:00:00 2001 From: itdominator <1itdominator@gmail.com> Date: Tue, 10 Oct 2023 14:51:57 -0500 Subject: [PATCH] Externalized some settings; added more css control; added syntax themes --- .../widgets/base/sourceview/source_view.py | 4 +- .../base/sourceview/source_view_events.py | 18 ++- src/core/widgets/controls/theme_button.py | 6 +- src/utils/settings_manager/options/theming.py | 8 +- .../gtksourceview-4/styles/blackleaf.xml | 113 +++++++++++++++++ .../styles/chocolateicecream.xml | 114 ++++++++++++++++++ .../styles/darkchocolateicecream.xml | 67 ++++++++++ user_config/usr/share/newton/settings.json | 8 +- user_config/usr/share/newton/stylesheet.css | 61 ++++++++-- 9 files changed, 368 insertions(+), 31 deletions(-) create mode 100644 user_config/local/share/gtksourceview-4/styles/blackleaf.xml create mode 100755 user_config/local/share/gtksourceview-4/styles/chocolateicecream.xml create mode 100755 user_config/local/share/gtksourceview-4/styles/darkchocolateicecream.xml diff --git a/src/core/widgets/base/sourceview/source_view.py b/src/core/widgets/base/sourceview/source_view.py index e9f3896..689e942 100644 --- a/src/core/widgets/base/sourceview/source_view.py +++ b/src/core/widgets/base/sourceview/source_view.py @@ -39,7 +39,7 @@ class SourceView(SourceViewEventsMixin, GtkSource.View): self._ignore_internal_change = False self._buffer = self.get_buffer() self._completion = self.get_completion() - self.px_value = 16 + self._px_value = settings.theming.default_zoom self._multi_insert_marks = [] self.freeze_multi_line_insert = False @@ -54,6 +54,8 @@ class SourceView(SourceViewEventsMixin, GtkSource.View): def _setup_styling(self): ctx = self.get_style_context() ctx.add_class("source-view") + ctx.add_class(f"px{self._px_value}") + self.set_show_line_marks(True) self.set_show_line_numbers(True) diff --git a/src/core/widgets/base/sourceview/source_view_events.py b/src/core/widgets/base/sourceview/source_view_events.py index f8d5638..5bac8e0 100644 --- a/src/core/widgets/base/sourceview/source_view_events.py +++ b/src/core/widgets/base/sourceview/source_view_events.py @@ -19,7 +19,7 @@ class SourceViewEventsMixin: def set_buffer_language(self, language = "python3"): self._buffer.set_language( self._language_manager.get_language(language) ) - def set_buffer_style(self, style = "tango"): + def set_buffer_style(self, style = settings.theming.syntax_theme): self._buffer.set_style_scheme( self._style_scheme_manager.get_scheme(style) ) def toggle_highlight_line(self, widget = None, eve = None): @@ -28,10 +28,9 @@ class SourceViewEventsMixin: def scale_up_text(self, scale_step = 10): ctx = self.get_style_context() - if self.px_value < 99: - self.px_value += 1 - - ctx.add_class(f"px{self.px_value}") + if self._px_value < 99: + self._px_value += 1 + ctx.add_class(f"px{self._px_value}") # NOTE: Hope to bring this or similar back after we decouple scaling issues coupled with the miniview. # tag_table = self._buffer.get_tag_table() @@ -45,11 +44,10 @@ class SourceViewEventsMixin: def scale_down_text(self, scale_step = 10): ctx = self.get_style_context() - ctx.remove_class(f"px{self.px_value}") - if self.px_value > 1: - self.px_value -= 1 - - ctx.add_class(f"px{self.px_value}") + if self._px_value > 1: + ctx.remove_class(f"px{self._px_value}") + self._px_value -= 1 + ctx.add_class(f"px{self._px_value}") # NOTE: Hope to bring this or similar back after we decouple scaling issues coupled with the miniview. # tag_table = self._buffer.get_tag_table() diff --git a/src/core/widgets/controls/theme_button.py b/src/core/widgets/controls/theme_button.py index 3dd8bb0..2add82a 100644 --- a/src/core/widgets/controls/theme_button.py +++ b/src/core/widgets/controls/theme_button.py @@ -44,8 +44,10 @@ class ThemePopover(Gtk.Popover): self.popup() def _set_theme(self, widget = None, eve = None): - style_scheme = widget.get_style_scheme() - id = style_scheme.get_id() + style_scheme = widget.get_style_scheme() + id = style_scheme.get_id() + settings.theming.syntax_theme = id.lower() + event_system.emit('set_buffer_style', ("set_buffer_style", id.lower(),)) diff --git a/src/utils/settings_manager/options/theming.py b/src/utils/settings_manager/options/theming.py index 034f7bd..7a2c587 100644 --- a/src/utils/settings_manager/options/theming.py +++ b/src/utils/settings_manager/options/theming.py @@ -8,6 +8,8 @@ from dataclasses import dataclass @dataclass class Theming: - success_color: str = "#88cc27" - warning_color: str = "#ffa800" - error_color: str = "#ff0000" + default_zoom: int = 12 + syntax_theme: str = "tango" + success_color: str = "#88cc27" + warning_color: str = "#ffa800" + error_color: str = "#ff0000" \ No newline at end of file diff --git a/user_config/local/share/gtksourceview-4/styles/blackleaf.xml b/user_config/local/share/gtksourceview-4/styles/blackleaf.xml new file mode 100644 index 0000000..1bd4aaf --- /dev/null +++ b/user_config/local/share/gtksourceview-4/styles/blackleaf.xml @@ -0,0 +1,113 @@ + + Hamad Al Marri + Color scheme using Black Leaf color palette + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +