From 72bea6386bad75fa8c35c8bef921293495f541c3 Mon Sep 17 00:00:00 2001 From: itdominator <1itdominator@gmail.com> Date: Mon, 20 Mar 2023 00:18:49 -0500 Subject: [PATCH] Improved Keybindings, added status bar, added open file button --- src/core/controller_data.py | 1 + src/core/core_widget.py | 8 +- .../mixins/signals/keyboard_signals_mixin.py | 23 +- src/core/widgets/base/banner_controls.py | 19 +- .../widgets/base/bottom_status_info_widget.py | 85 ++++ src/core/widgets/base/editer_notebook.py | 45 +- src/core/widgets/base/source_view.py | 58 ++- src/core/widgets/controls/open_file_button.py | 60 +++ .../widgets/controls/scale_down_button.py | 2 + src/core/widgets/controls/scale_up_button.py | 2 + src/core/widgets/controls/theme_button.py | 2 + .../widgets/controls/toggle_line_highlight.py | 2 + src/core/widgets/tab_header_widget.py | 22 +- src/utils/keybindings.py | 6 +- src/utils/settings/settings.py | 25 +- .../usr/applications/newton_editor.desktop | 4 +- .../usr/share/newton_editor/key-bindings.json | 8 +- .../newton_editor/ui_widgets/about_ui.glade | 390 ++++++++++++++++++ .../ui_widgets/bottom_status_info_ui.glade | 68 +++ .../ui_widgets/save_load_ui.glade | 65 +++ 20 files changed, 856 insertions(+), 39 deletions(-) create mode 100644 src/core/widgets/base/bottom_status_info_widget.py create mode 100644 src/core/widgets/controls/open_file_button.py create mode 100644 user_config/usr/share/newton_editor/ui_widgets/about_ui.glade create mode 100644 user_config/usr/share/newton_editor/ui_widgets/bottom_status_info_ui.glade create mode 100644 user_config/usr/share/newton_editor/ui_widgets/save_load_ui.glade diff --git a/src/core/controller_data.py b/src/core/controller_data.py index 4068f12..8ac1b71 100644 --- a/src/core/controller_data.py +++ b/src/core/controller_data.py @@ -17,6 +17,7 @@ class ControllerData: self.window = settings.get_main_window() self.builder = None self.core_widget = None + self.was_midified_key = False self.ctrl_down = False self.shift_down = False self.alt_down = False diff --git a/src/core/core_widget.py b/src/core/core_widget.py index 4fa6712..c319894 100644 --- a/src/core/core_widget.py +++ b/src/core/core_widget.py @@ -8,6 +8,7 @@ from gi.repository import Gtk # Application imports from .widgets.base.banner_controls import BannerControls from .widgets.base.editer_notebook import EditorNotebook +from .widgets.base.bottom_status_info_widget import BottomStatusInfoWidget @@ -15,11 +16,14 @@ class CoreWidget(Gtk.Box): def __init__(self): super(CoreWidget, self).__init__() + builder = settings.get_builder() + builder.expose_object("core_widget", self) + self._setup_styling() self._setup_signals() self._load_widgets() - self.show_all() + self.show() def _setup_styling(self): @@ -31,3 +35,5 @@ class CoreWidget(Gtk.Box): def _load_widgets(self): self.add(BannerControls()) self.add(EditorNotebook()) + + BottomStatusInfoWidget() diff --git a/src/core/mixins/signals/keyboard_signals_mixin.py b/src/core/mixins/signals/keyboard_signals_mixin.py index 3b3a4a7..c8582f8 100644 --- a/src/core/mixins/signals/keyboard_signals_mixin.py +++ b/src/core/mixins/signals/keyboard_signals_mixin.py @@ -26,7 +26,11 @@ class KeyboardSignalsMixin: self.alt_down = False def on_global_key_press_controller(self, eve, user_data): - keyname = Gdk.keyval_name(user_data.keyval).lower() + keyname = Gdk.keyval_name(user_data.keyval).lower() + modifiers = Gdk.ModifierType(user_data.get_state() & ~Gdk.ModifierType.LOCK_MASK) + + self.was_midified_key = True if modifiers != 0 else False + if keyname.replace("_l", "").replace("_r", "") in ["control", "alt", "shift"]: if "control" in keyname: self.ctrl_down = True @@ -37,8 +41,12 @@ class KeyboardSignalsMixin: def on_global_key_release_controller(self, widget, event): """ Handler for keyboard events """ - keyname = Gdk.keyval_name(event.keyval).lower() + keyname = Gdk.keyval_name(event.keyval).lower() + modifiers = Gdk.ModifierType(event.get_state() & ~Gdk.ModifierType.LOCK_MASK) + if keyname.replace("_l", "").replace("_r", "") in ["control", "alt", "shift"]: + should_return = self.was_midified_key and (self.ctrl_down or self.shift_down or self.alt_down) + if "control" in keyname: self.ctrl_down = False if "shift" in keyname: @@ -46,7 +54,16 @@ class KeyboardSignalsMixin: if "alt" in keyname: self.alt_down = False + # NOTE: In effect a filter after releasing a modifier and we have a modifier mapped + if should_return: + self.was_midified_key = False + return + mapping = keybindings.lookup(event) + logger.debug(f"on_global_key_release_controller > key > {keyname}") + logger.debug(f"on_global_key_release_controller > keyval > {event.keyval}") + logger.debug(f"on_global_key_release_controller > mapping > {mapping}") + if mapping: # See if in controller scope try: @@ -62,8 +79,6 @@ class KeyboardSignalsMixin: self.handle_key_event_system(sender, eve_type) else: - logger.debug(f"on_global_key_release_controller > key > {keyname}") - if self.ctrl_down: if not keyname in ["1", "kp_1", "2", "kp_2", "3", "kp_3", "4", "kp_4"]: self.handle_key_event_system(None, mapping) diff --git a/src/core/widgets/base/banner_controls.py b/src/core/widgets/base/banner_controls.py index 29f03ed..2c852de 100644 --- a/src/core/widgets/base/banner_controls.py +++ b/src/core/widgets/base/banner_controls.py @@ -6,10 +6,11 @@ gi.require_version('Gtk', '3.0') from gi.repository import Gtk # Application imports -from ..controls.theme_button import ThemeButton -from ..controls.toggle_line_highlight import ToggleLineHighlight +from ..controls.open_file_button import OpenFileButton from ..controls.scale_up_button import ScaleUpButton from ..controls.scale_down_button import ScaleDownButton +from ..controls.toggle_line_highlight import ToggleLineHighlight +from ..controls.theme_button import ThemeButton @@ -17,12 +18,13 @@ class BannerControls(Gtk.Box): def __init__(self): super(BannerControls, self).__init__() - self._setup_styling() self._setup_signals() + self._subscribe_to_events() self._load_widgets() self.show_all() + self.hide() def _setup_styling(self): @@ -31,8 +33,15 @@ class BannerControls(Gtk.Box): def _setup_signals(self): ... + def _subscribe_to_events(self): + event_system.subscribe("tggl_top_main_menubar", self._tggl_top_main_menubar) + def _load_widgets(self): - self.add(ToggleLineHighlight()) - self.add(ScaleDownButton()) + self.add(OpenFileButton()) self.add(ScaleUpButton()) + self.add(ScaleDownButton()) + self.add(ToggleLineHighlight()) self.pack_end(ThemeButton(), False, False, 0) + + def _tggl_top_main_menubar(self): + self.show() if not self.is_visible() else self.hide() diff --git a/src/core/widgets/base/bottom_status_info_widget.py b/src/core/widgets/base/bottom_status_info_widget.py new file mode 100644 index 0000000..1ef7037 --- /dev/null +++ b/src/core/widgets/base/bottom_status_info_widget.py @@ -0,0 +1,85 @@ +# Python imports + +# Lib imports +import gi +gi.require_version('Gtk', '3.0') +from gi.repository import Gtk +from gi.repository import Gio + +# Application imports + + +# NOTE: https://github.com/rwaldron/gtksourceview/blob/master/tests/test-widget.py + + +class BottomStatusInfoWidget: + """docstring for BottomStatusInfoWidget.""" + + def __init__(self): + super(BottomStatusInfoWidget, self).__init__() + + _GLADE_FILE = f"{settings.get_ui_widgets_path()}/bottom_status_info_ui.glade" + self._builder = Gtk.Builder() + self._builder.add_from_file(_GLADE_FILE) + + self._setup_styling() + self._setup_signals() + self._subscribe_to_events() + self._load_widgets() + + + def _setup_styling(self): + ... + + def _setup_signals(self): + ... + + def _subscribe_to_events(self): + event_system.subscribe("set_bottom_labels", self.set_bottom_labels) + + event_system.subscribe("set_path_label", self._set_path_label) + event_system.subscribe("set_encoding_label", self._set_encoding_label) + event_system.subscribe("set_line_char_label", self._set_line_char_label) + event_system.subscribe("set_file_type_label", self._set_file_type_label) + + + def _load_widgets(self): + builder = settings.get_builder() + + self.bottom_status_info = self._builder.get_object("bottom_status_info") + self.bottom_path_label = self._builder.get_object("bottom_path_label") + self.bottom_encoding_label = self._builder.get_object("bottom_encoding_label") + self.bottom_line_char_label = self._builder.get_object("bottom_line_char_label") + self.bottom_file_type_label = self._builder.get_object("bottom_file_type_label") + + builder.expose_object(f"bottom_status_info", self.bottom_status_info) + builder.expose_object(f"bottom_path_label", self.bottom_path_label) + builder.expose_object(f"bottom_encoding_label", self.bottom_encoding_label) + builder.expose_object(f"bottom_line_char_label", self.bottom_line_char_label) + builder.expose_object(f"bottom_file_type_label", self.bottom_file_type_label) + + self.bottom_path_label.set_hexpand(True) + self._set_line_char_label() + + builder.get_object("core_widget").add(self.bottom_status_info) + + + def set_bottom_labels(self, gfile, info): + self.bottom_path_label.set_text( gfile.get_path() ) + self.bottom_path_label.set_tooltip_text( gfile.get_path() ) + + self.bottom_encoding_label.set_text("utf-8") + self.bottom_line_char_label.set_text("0:0") + self.bottom_file_type_label.set_text( info.get_content_type() ) + + def _set_path_label(self): + ... + + def _set_encoding_label(self): + ... + + def _set_line_char_label(self, label = "0:0"): + self.bottom_line_char_label.set_text(label) + + def _set_file_type_label(self): + ... diff --git a/src/core/widgets/base/editer_notebook.py b/src/core/widgets/base/editer_notebook.py index 5bd3501..10418ee 100644 --- a/src/core/widgets/base/editer_notebook.py +++ b/src/core/widgets/base/editer_notebook.py @@ -3,7 +3,10 @@ # Lib imports import gi gi.require_version('Gtk', '3.0') +gi.require_version('Gdk', '3.0') from gi.repository import Gtk +from gi.repository import Gdk +from gi.repository import Gio # Application imports from .sourceview_container import SourceViewContainer @@ -29,6 +32,7 @@ class EditorNotebook(Gtk.Notebook): self.set_scrollable(True) def _setup_signals(self): + # self.connect("button-press-event", self._dbl_click_create_view) ... def _subscribe_to_events(self): @@ -37,15 +41,13 @@ class EditorNotebook(Gtk.Notebook): event_system.subscribe("set_buffer_style", self.action_controller) event_system.subscribe("set_buffer_language", self.action_controller) event_system.subscribe("set_buffer_style", self.action_controller) - event_system.subscribe("open_files", self._open_files) - event_system.subscribe("toggle_highlight_line", self.action_controller) + event_system.subscribe("toggle_highlight_line", self._toggle_highlight_line) + event_system.subscribe("keyboard_create_tab", self._keyboard_create_tab) + event_system.subscribe("keyboard_close_tab", self._keyboard_close_tab) + event_system.subscribe("keyboard_prev_tab", self._keyboard_prev_tab) + event_system.subscribe("keyboard_next_tab", self._keyboard_next_tab) event_system.subscribe("keyboard_scale_up_text", self._keyboard_scale_up_text) event_system.subscribe("keyboard_scale_down_text", self._keyboard_scale_down_text) - event_system.subscribe("keyboard_create_tab", self.create_view) - event_system.subscribe("keyboard_close_tab", self._keyboard_close_tab) - - def _open_files(self): - print("Open file stub...") def _add_action_widgets(self): start_box = Gtk.Box() @@ -73,6 +75,9 @@ class EditorNotebook(Gtk.Notebook): def _load_widgets(self): self.create_view() + def _keyboard_create_tab(self, _gfile): + self.create_view(gfile=_gfile) + def create_view(self, widget = None, eve = None, gfile = None): container = SourceViewContainer(self.close_tab) @@ -101,9 +106,22 @@ class EditorNotebook(Gtk.Notebook): self.remove_page(page_num) + def _dbl_click_create_view(self, notebook, eve): + if eve.type == Gdk.EventType.DOUBLE_BUTTON_PRESS and eve.button == 1: # l-click + ... + + def _toggle_highlight_line(self): + self.action_controller("toggle_highlight_line") + def _keyboard_close_tab(self): self.action_controller("close_tab") + def _keyboard_next_tab(self): + self.action_controller("keyboard_next_tab") + + def _keyboard_prev_tab(self): + self.action_controller("keyboard_prev_tab") + def _keyboard_scale_up_text(self): self.action_controller("scale_up_text") @@ -132,6 +150,11 @@ class EditorNotebook(Gtk.Notebook): self.scale_down_text(source_view) if action == "close_tab": self.close_tab(None, container, source_view) + if action == "keyboard_prev_tab": + self.keyboard_prev_tab(page_num) + if action == "keyboard_next_tab": + self.keyboard_next_tab(page_num) + def do_text_search(self, query = ""): source_view.scale_down_text() @@ -142,6 +165,14 @@ class EditorNotebook(Gtk.Notebook): def set_buffer_style(self, source_view, style = "tango"): source_view.set_buffer_style(style) + def keyboard_prev_tab(self, page_num): + page_num = self.get_n_pages() - 1 if page_num == 0 else page_num - 1 + self.set_current_page(page_num) + + def keyboard_next_tab(self, page_num): + page_num = 0 if self.get_n_pages() - 1 == page_num else page_num + 1 + self.set_current_page(page_num) + def scale_up_text(self, source_view): source_view.scale_up_text() diff --git a/src/core/widgets/base/source_view.py b/src/core/widgets/base/source_view.py index 688bcff..9177d2b 100644 --- a/src/core/widgets/base/source_view.py +++ b/src/core/widgets/base/source_view.py @@ -54,12 +54,15 @@ class SourceView(GtkSource.View): self.set_vexpand(True) def _setup_signals(self): - self.connect("drag-data-received", self._on_drag_data_received) - ... + self.connect("drag-data-received", self._on_drag_data_received) + self._buffer.connect("mark-set", self._on_cursor_move) + # self.completion.add_provider(srcCompleteonSnippets) + # self.completion.add_provider(srcCompleteonWords) def _subscribe_to_events(self): ... + def _load_widgets(self): ... @@ -155,17 +158,23 @@ class SourceView(GtkSource.View): def open_file(self, gfile, *args): - info = gfile.query_info("standard::content-type", 0, cancellable=None) + info = gfile.query_info("standard::*", 0, cancellable=None) content_type = info.get_content_type() + display_name = info.get_display_name() + tab_widget = self.get_parent().get_tab_widget() lm = self._language_manager.guess_language(None, content_type) - if settings.is_debug(): - logger.debug(f"Detected Content Type: {content_type}") + tab_widget.set_tab_label(display_name) + event_system.emit("set_bottom_labels", (gfile, info)) + logger.debug(f"Detected Content Type: {content_type}") with open(gfile.get_path(), 'r') as f: data = f.read() self._buffer.set_text(data) - self.set_buffer_language( lm.get_id() ) + try: + self.set_buffer_language( lm.get_id() ) + except Exception as e: + ... # self.current_file = myfile # self.current_filename = myfile.rpartition("/")[2] @@ -176,3 +185,40 @@ class SourceView(GtkSource.View): # self.headerbar.set_title("TextEdit") self.grab_focus() # self.is_changed = False + + + + def _on_cursor_move(self, buf, cursor_iter, mark, user_data = None): + if mark != buf.get_insert(): + return + + self.update_cursor_position() + + + def update_cursor_position(self): + iter = self._buffer.get_iter_at_mark(self._buffer.get_insert()) + chars = iter.get_offset() + row = iter.get_line() + 1 + col = self.get_visual_column(iter) + 1 + + classes = self._buffer.get_context_classes_at_iter(iter) + classes_str = "" + + i = 0 + for c in classes: + if len(classes) != i + 1: + classes_str += c + ", " + else: + classes_str += c + + cursor_data = f"char: {chars}, line: {row}, column: {col}, classes: {classes_str}" + logger.debug(cursor_data) + event_system.emit("set_line_char_label", (f"{row}:{col}",)) + + + # https://github.com/ptomato/inform7-ide/blob/main/src/actions.c + def action_uncomment_selection(self): + ... + + def action_comment_out_selection(self): + pass diff --git a/src/core/widgets/controls/open_file_button.py b/src/core/widgets/controls/open_file_button.py new file mode 100644 index 0000000..648b5a5 --- /dev/null +++ b/src/core/widgets/controls/open_file_button.py @@ -0,0 +1,60 @@ +# Python imports +import os + +# Lib imports +import gi +gi.require_version('Gtk', '3.0') +gi.require_version('Gdk', '3.0') +from gi.repository import Gtk +from gi.repository import Gdk +from gi.repository import Gio + +# Application imports + + + +class OpenFileButton(Gtk.Button): + """docstring for OpenFileButton.""" + + def __init__(self): + super(OpenFileButton, self).__init__() + + self._setup_styling() + self._setup_signals() + self._subscribe_to_events() + self._load_widgets() + + + def _setup_styling(self): + self.set_label("Open File(s)...") + self.set_image( Gtk.Image.new_from_icon_name("gtk-open", 4) ) + self.set_always_show_image(True) + self.set_image_position(1) # Left - 0, Right = 1 + # self.set_margin_left(5) + self.set_margin_right(5) + self.set_hexpand(False) + + def _setup_signals(self): + self.connect("button-release-event", self._open_files) + + def _subscribe_to_events(self): + event_system.subscribe("open_files", self._open_files) + + def _load_widgets(self): + ... + + def _open_files(self, widget = None, eve = None): + chooser = Gtk.FileChooserDialog("Open File...", None, + Gtk.FileChooserAction.OPEN, + (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, + Gtk.STOCK_OPEN, Gtk.ResponseType.OK)) + + response = chooser.run() + if response == Gtk.ResponseType.OK: + filename = chooser.get_filename() + if filename: + path = filename if os.path.isabs(filename) else os.path.abspath(filename) + _gfile = Gio.File.new_for_path(path) + event_system.emit("keyboard_create_tab", (_gfile,)) + + chooser.destroy() diff --git a/src/core/widgets/controls/scale_down_button.py b/src/core/widgets/controls/scale_down_button.py index b734769..fa91866 100644 --- a/src/core/widgets/controls/scale_down_button.py +++ b/src/core/widgets/controls/scale_down_button.py @@ -24,6 +24,8 @@ class ScaleDownButton(Gtk.Button): self.set_image( Gtk.Image.new_from_icon_name("gtk-remove", 4) ) self.set_always_show_image(True) self.set_image_position(1) # Left - 0, Right = 1 + # self.set_margin_left(5) + # self.set_margin_right(5) self.set_hexpand(False) def _setup_signals(self): diff --git a/src/core/widgets/controls/scale_up_button.py b/src/core/widgets/controls/scale_up_button.py index 0ae383f..a302b3a 100644 --- a/src/core/widgets/controls/scale_up_button.py +++ b/src/core/widgets/controls/scale_up_button.py @@ -24,6 +24,8 @@ class ScaleUpButton(Gtk.Button): self.set_image( Gtk.Image.new_from_icon_name("gtk-add", 4) ) self.set_always_show_image(True) self.set_image_position(1) # Left - 0, Right = 1 + self.set_margin_left(5) + # self.set_margin_right(5) self.set_hexpand(False) def _setup_signals(self): diff --git a/src/core/widgets/controls/theme_button.py b/src/core/widgets/controls/theme_button.py index 70b22de..3dd8bb0 100644 --- a/src/core/widgets/controls/theme_button.py +++ b/src/core/widgets/controls/theme_button.py @@ -65,6 +65,8 @@ class ThemeButton(Gtk.Button): self.set_image( Gtk.Image.new_from_icon_name("gtk-page-setup", 4) ) self.set_always_show_image(True) self.set_image_position(1) # Left - 0, Right = 1 + self.set_margin_left(5) + # self.set_margin_right(5) def _setup_signals(self): self.connect("clicked", self._show_popover) diff --git a/src/core/widgets/controls/toggle_line_highlight.py b/src/core/widgets/controls/toggle_line_highlight.py index cc2339e..0deb8cc 100644 --- a/src/core/widgets/controls/toggle_line_highlight.py +++ b/src/core/widgets/controls/toggle_line_highlight.py @@ -24,6 +24,8 @@ class ToggleLineHighlight(Gtk.Button): # self.set_image( Gtk.Image.new_from_icon_name("gtk-add", 4) ) self.set_always_show_image(True) self.set_image_position(1) # Left - 0, Right = 1 + # self.set_margin_left(5) + # self.set_margin_right(5) self.set_hexpand(False) def _setup_signals(self): diff --git a/src/core/widgets/tab_header_widget.py b/src/core/widgets/tab_header_widget.py index 274cbf8..83031e1 100644 --- a/src/core/widgets/tab_header_widget.py +++ b/src/core/widgets/tab_header_widget.py @@ -9,8 +9,8 @@ from gi.repository import Gtk -class TabHeaderWidget(Gtk.ButtonBox): - """docstring for TabHeaderWidget""" +class TabHeaderWidget(Gtk.Box): + """ docstring for TabHeaderWidget """ ccount = 0 def __new__(cls, *args, **kwargs): @@ -30,31 +30,41 @@ class TabHeaderWidget(Gtk.ButtonBox): self._setup_styling() self._setup_signals() + self._subscribe_to_events() self._load_widgets() + self.set_tab_label() + self.show_all() + def _setup_styling(self): self.set_orientation(0) + self.set_hexpand(False) def _setup_signals(self): ... + def _subscribe_to_events(self): + ... + def _load_widgets(self): label = Gtk.Label() close = Gtk.Button() icon = Gtk.Image(stock=Gtk.STOCK_CLOSE) - label.set_label("untitled") - label.set_width_chars(len(self.NAME)) + # NOTE: Setup with settings and from file label.set_xalign(0.0) + label.set_margin_left(25) + label.set_margin_right(25) + label.set_hexpand(True) close.set_always_show_image(True) close.set_hexpand(False) - close.set_size_request(32, 32) close.set_image( Gtk.Image.new_from_icon_name("gtk-close", 4) ) close.connect("released", self._close_tab, *(self._scroll_view, self._source_view,)) self.add(label) self.add(close) - self.show_all() + def set_tab_label(self, label = "untitled"): + self.get_children()[0].set_label(label) diff --git a/src/utils/keybindings.py b/src/utils/keybindings.py index 84d4d52..cb47685 100644 --- a/src/utils/keybindings.py +++ b/src/utils/keybindings.py @@ -11,7 +11,7 @@ from gi.repository import Gdk -def err(log = ""): +def logger(log = ""): print(log) @@ -68,7 +68,7 @@ class Keybindings: # Does much the same, but with worse error handling. # keyval, mask = Gtk.accelerator_parse(binding) except KeymapError as e: - err(f"Keybinding reload failed to parse binding '{binding}': {e}") + logger(f"Keybinding reload failed to parse binding '{binding}': {e}") else: if mask & Gdk.ModifierType.SHIFT_MASK: if keyval == Gdk.KEY_Tab: @@ -120,7 +120,7 @@ class Keybindings: Gdk.ModifierType(event.get_state() & ~Gdk.ModifierType.LOCK_MASK), event.group) except TypeError: - err(f"Keybinding lookup failed to translate keyboard event: {dir(event)}") + logger(f"Keybinding lookup failed to translate keyboard event: {dir(event)}") return None mask = (event.get_state() & ~consumed) & self._masks diff --git a/src/utils/settings/settings.py b/src/utils/settings/settings.py index d81a9d4..85e4af0 100644 --- a/src/utils/settings/settings.py +++ b/src/utils/settings/settings.py @@ -29,6 +29,8 @@ class Settings(StartCheckMixin): self._CSS_FILE = f"{self._HOME_CONFIG_PATH}/stylesheet.css" self._KEY_BINDINGS_FILE = f"{self._HOME_CONFIG_PATH}/key-bindings.json" self._PID_FILE = f"{self._HOME_CONFIG_PATH}/{app_name.lower()}.pid" + self._UI_WIDEGTS_PATH = f"{self._HOME_CONFIG_PATH}/ui_widgets" + self._CONTEXT_MENU = f"{self._HOME_CONFIG_PATH}/contexct_menu.json" self._WINDOW_ICON = f"{self._DEFAULT_ICONS}/{app_name.lower()}.png" if not os.path.exists(self._HOME_CONFIG_PATH): @@ -63,12 +65,25 @@ class Settings(StartCheckMixin): self._WINDOW_ICON = f"{self._USR_PATH}/icons/{app_name.lower()}.png" if not os.path.exists(self._WINDOW_ICON): raise MissingConfigError("Unable to find the application icon.") + if not os.path.exists(self._UI_WIDEGTS_PATH): + self._UI_WIDEGTS_PATH = f"{self._USR_PATH}/ui_widgets" + if not os.path.exists(self._CONTEXT_MENU): + self._CONTEXT_MENU = f"{self._USR_PATH}/contexct_menu.json" - with open(self._KEY_BINDINGS_FILE) as file: - print(self._KEY_BINDINGS_FILE) - bindings = json.load(file)["keybindings"] - keybindings.configure(bindings) + try: + with open(self._KEY_BINDINGS_FILE) as file: + bindings = json.load(file)["keybindings"] + keybindings.configure(bindings) + except Exception as e: + print( f"Settings: {self._KEY_BINDINGS_FILE}\n\t\t{repr(e)}" ) + + try: + with open(self._CONTEXT_MENU) as file: + self._context_menu_data = json.load(file) + except Exception as e: + print( f"Settings: {self._CONTEXT_MENU}\n\t\t{repr(e)}" ) + self._main_window = None self._main_window_w = 800 @@ -115,6 +130,8 @@ class Settings(StartCheckMixin): def get_builder(self) -> any: return self._builder def get_paint_bg_color(self) -> any: return self.PAINT_BG_COLOR def get_glade_file(self) -> str: return self._GLADE_FILE + def get_ui_widgets_path(self) -> str: return self._UI_WIDEGTS_PATH + def get_plugins_path(self) -> str: return self._PLUGINS_PATH def get_icon_theme(self) -> str: return self._ICON_THEME diff --git a/user_config/usr/applications/newton_editor.desktop b/user_config/usr/applications/newton_editor.desktop index 1d6ed4a..eb68352 100755 --- a/user_config/usr/applications/newton_editor.desktop +++ b/user_config/usr/applications/newton_editor.desktop @@ -6,6 +6,6 @@ Exec=/bin/newton_editor %F Icon=/usr/share/newton_editor/icons/newton_editor.png Type=Application StartupNotify=true -Categories=System;FileTools;Utility; -MimeType= +Categories=GNOME;GTK;Utility;TextEditor;Development; +MimeType=text/plain;text/py;text/js;text/java;text/cpp;text/sh;text/html;text/json; Terminal=false diff --git a/user_config/usr/share/newton_editor/key-bindings.json b/user_config/usr/share/newton_editor/key-bindings.json index e95106a..2cf294d 100644 --- a/user_config/usr/share/newton_editor/key-bindings.json +++ b/user_config/usr/share/newton_editor/key-bindings.json @@ -2,12 +2,18 @@ "keybindings": { "help" : "F1", "open_terminal" : "F4", - "tggl_top_main_menubar" : "h", + "tggl_top_main_menubar" : "Alt_L", "tear_down" : "q", "toggle_highlight_line" : "h", "open_files" : "o", "keyboard_create_tab" : "t", "keyboard_close_tab" : "w", + "keyboard_up" : "Up", + "keyboard_down" : "Down", + "keyboard_left" : "Left", + "keyboard_riht" : "Right", + "keyboard_prev_tab" : "Page_Up", + "keyboard_next_tab" : "Page_Down", "keyboard_scale_up_text" : "equal", "keyboard_scale_down_text" : "minus" } diff --git a/user_config/usr/share/newton_editor/ui_widgets/about_ui.glade b/user_config/usr/share/newton_editor/ui_widgets/about_ui.glade new file mode 100644 index 0000000..f559f6c --- /dev/null +++ b/user_config/usr/share/newton_editor/ui_widgets/about_ui.glade @@ -0,0 +1,390 @@ + + + + + + 320 + 480 + False + 5 + center-on-parent + ../icons/solarfm.png + dialog + True + True + False + center + SolarFM + 0.0.1 + Copyright (C) 2021 GPL2 + by ITDominator + https://code.itdominator.com/itdominator/SolarFM + SolarFM - Copyright (C) 2021 ITDominator GPL2 + + + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Lesser General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + <one line to give the program's name and a brief idea of what it does.> + Copyright (C) <year> <name of author> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + <signature of Ty Coon>, 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. + + Lead Developer: + ITDominator <1itdominator@gmail.com> + + +SolarFM is developed on Atom, git, and using Python 3+ with Gtk GObject introspection. + translator-credits + ../icons/solarfm-64x64.png + True + custom + + + False + + + False + + + False + False + 0 + + + + + + diff --git a/user_config/usr/share/newton_editor/ui_widgets/bottom_status_info_ui.glade b/user_config/usr/share/newton_editor/ui_widgets/bottom_status_info_ui.glade new file mode 100644 index 0000000..f3ee0e4 --- /dev/null +++ b/user_config/usr/share/newton_editor/ui_widgets/bottom_status_info_ui.glade @@ -0,0 +1,68 @@ + + + + + + True + False + 10 + 10 + 10 + 10 + 6 + 6 + 15 + top + + + True + False + True + 10 + + + False + True + 4 + + + + + True + False + start + True + 320 + + + False + True + 0 + + + + + True + False + + + False + True + end + 1 + + + + + True + False + + + False + True + end + 2 + + + + diff --git a/user_config/usr/share/newton_editor/ui_widgets/save_load_ui.glade b/user_config/usr/share/newton_editor/ui_widgets/save_load_ui.glade new file mode 100644 index 0000000..ba42cba --- /dev/null +++ b/user_config/usr/share/newton_editor/ui_widgets/save_load_ui.glade @@ -0,0 +1,65 @@ + + + + + + False + dialog + True + + + False + vertical + 2 + + + False + end + + + gtk-cancel + True + True + True + True + True + + + True + True + 0 + + + + + gtk-ok + True + True + True + True + True + + + True + True + 1 + + + + + False + False + 0 + + + + + + + + + button11 + button12 + + +