From 0c6af185a26967c69bd52dfddcc8090980a28dc7 Mon Sep 17 00:00:00 2001 From: itdominator <1itdominator@gmail.com> Date: Sat, 27 Jan 2024 23:44:34 -0600 Subject: [PATCH] aligned to base template project; scroll past end added; move line selection preservation --- src/__main__.py | 5 -- src/app.py | 34 +++++++----- src/core/__init__.py | 3 - .../{core_widget.py => base_container.py} | 4 +- src/core/controllers/__init__.py | 3 + .../base_controller.py} | 11 ++-- .../base_controller_data.py} | 5 +- .../base/sourceview/source_view_controller.py | 55 +++++++++++++++++-- src/core/window.py | 32 ++++++++--- user_config/usr/share/newton/stylesheet.css | 5 ++ 10 files changed, 111 insertions(+), 46 deletions(-) delete mode 100644 src/core/__init__.py rename src/core/containers/{core_widget.py => base_container.py} (94%) create mode 100644 src/core/controllers/__init__.py rename src/core/{controller.py => controllers/base_controller.py} (87%) rename src/core/{controller_data.py => controllers/base_controller_data.py} (94%) diff --git a/src/__main__.py b/src/__main__.py index 5bbe908..d44b8cc 100644 --- a/src/__main__.py +++ b/src/__main__.py @@ -10,9 +10,6 @@ import tracemalloc tracemalloc.start() # Lib imports -import gi -gi.require_version('Gtk', '3.0') -from gi.repository import Gtk # Application imports from __builtins__ import * @@ -20,7 +17,6 @@ from app import Application - if __name__ == "__main__": ''' Set process title, get arguments, and create GTK main thread. ''' @@ -47,7 +43,6 @@ if __name__ == "__main__": settings_manager.do_dirty_start_check() Application(args, unknownargs) - Gtk.main() except Exception as e: traceback.print_exc() quit() \ No newline at end of file diff --git a/src/app.py b/src/app.py index e00fc89..b945b22 100644 --- a/src/app.py +++ b/src/app.py @@ -16,35 +16,39 @@ class AppLaunchException(Exception): -class Application(IPCServer): +class Application: """ docstring for Application. """ def __init__(self, args, unknownargs): super(Application, self).__init__() if not settings_manager.is_trace_debug(): - self.socket_realization_check() - - if not self.is_ipc_alive: - for arg in unknownargs + [args.new_tab,]: - if os.path.isfile(arg): - message = f"FILE|{arg}" - self.send_ipc_message(message) - - raise AppLaunchException(f"{app_name} IPC Server Exists: Have sent path(s) to it and closing...") + self.load_ipc(args, unknownargs) self.setup_debug_hook() - Window(args, unknownargs) + Window(args, unknownargs).main() - def socket_realization_check(self): + def load_ipc(self, args, unknownargs): + ipc_server = IPCServer() + self.ipc_realization_check(ipc_server) + + if not ipc_server.is_ipc_alive: + for arg in unknownargs + [args.new_tab,]: + if os.path.isfile(arg): + message = f"FILE|{arg}" + ipc_server.send_ipc_message(message) + + raise AppLaunchException(f"{app_name} IPC Server Exists: Have sent path(s) to it and closing...") + + def ipc_realization_check(self, ipc_server): try: - self.create_ipc_listener() + ipc_server.create_ipc_listener() except Exception: - self.send_test_ipc_message() + ipc_server.send_test_ipc_message() try: - self.create_ipc_listener() + ipc_server.create_ipc_listener() except Exception as e: ... diff --git a/src/core/__init__.py b/src/core/__init__.py deleted file mode 100644 index 90cfadc..0000000 --- a/src/core/__init__.py +++ /dev/null @@ -1,3 +0,0 @@ -""" - Gtk Bound Signal Module -""" diff --git a/src/core/containers/core_widget.py b/src/core/containers/base_container.py similarity index 94% rename from src/core/containers/core_widget.py rename to src/core/containers/base_container.py index e04841e..5670529 100644 --- a/src/core/containers/core_widget.py +++ b/src/core/containers/base_container.py @@ -14,9 +14,9 @@ from .editors_container import EditorsContainer -class CoreWidget(Gtk.Box): +class BaseContainer(Gtk.Box): def __init__(self): - super(CoreWidget, self).__init__() + super(BaseContainer, self).__init__() builder = settings_manager.get_builder() self.ctx = self.get_style_context() diff --git a/src/core/controllers/__init__.py b/src/core/controllers/__init__.py new file mode 100644 index 0000000..c004b70 --- /dev/null +++ b/src/core/controllers/__init__.py @@ -0,0 +1,3 @@ +""" + Controllers Module +""" \ No newline at end of file diff --git a/src/core/controller.py b/src/core/controllers/base_controller.py similarity index 87% rename from src/core/controller.py rename to src/core/controllers/base_controller.py index 27f15e2..341edd4 100644 --- a/src/core/controller.py +++ b/src/core/controllers/base_controller.py @@ -10,13 +10,14 @@ from gi.repository import Gdk from gi.repository import GLib # Application imports -from .controller_data import ControllerData -from .containers.core_widget import CoreWidget -from .mixins.signals_mixins import SignalsMixins +from ..mixins.signals_mixins import SignalsMixins +from ..containers.base_container import BaseContainer + +from .base_controller_data import BaseControllerData -class Controller(SignalsMixins, ControllerData): +class BaseController(SignalsMixins, BaseControllerData): def __init__(self, args, unknownargs): messages = [] for arg in unknownargs + [args.new_tab,]: @@ -60,7 +61,7 @@ class Controller(SignalsMixins, ControllerData): self.builder.expose_object("main_window", self.window) settings_manager.set_builder(self.builder) - self.core_widget = CoreWidget() + self.core_widget = BaseContainer() settings_manager.register_signals_to_builder([self, self.core_widget]) diff --git a/src/core/controller_data.py b/src/core/controllers/base_controller_data.py similarity index 94% rename from src/core/controller_data.py rename to src/core/controllers/base_controller_data.py index def6d80..3467eac 100644 --- a/src/core/controller_data.py +++ b/src/core/controllers/base_controller_data.py @@ -9,9 +9,8 @@ from plugins.plugins_controller import PluginsController - -class ControllerData: - ''' ControllerData contains most of the state of the app at ay given time. It also has some support methods. ''' +class BaseControllerData: + ''' BaseControllerData contains most of the state of the app at ay given time. It also has some support methods. ''' def setup_controller_data(self) -> None: self.window = settings_manager.get_main_window() diff --git a/src/core/widgets/base/sourceview/source_view_controller.py b/src/core/widgets/base/sourceview/source_view_controller.py index a173524..3b4831c 100644 --- a/src/core/widgets/base/sourceview/source_view_controller.py +++ b/src/core/widgets/base/sourceview/source_view_controller.py @@ -117,22 +117,67 @@ class SourceViewControllerMixin(KeyInputController, SourceViewEvents): buffer.redo() def keyboard_move_lines_up(self): - buffer = self.get_buffer() + buffer = self.get_buffer() self.begin_user_action(buffer) + had_selection = buffer.get_has_selection() + itr = buffer.get_iter_at_mark( buffer.get_insert() ) + line = itr.get_line() - 1 + line_index = itr.get_line_index() + selection_bounds = None + + if had_selection: + selection_bounds = buffer.get_selection_bounds() + sbounds_start = selection_bounds[0].get_line_offset() + sbounds_end = selection_bounds[1].get_line_offset() + self.emit("move-lines", *(False,)) - # unindent_lines - # self.emit("move-words", *(self, 4,)) + if not had_selection: + self.emit("select-all", *(False,)) + line_itr = buffer.get_iter_at_line_offset(line, line_index) + self.get_buffer().place_cursor(line_itr) + else: + buffer = self.get_buffer() + sbounds = buffer.get_selection_bounds() + start_itr = buffer.get_iter_at_line_offset( sbounds[0].get_line(), sbounds_start) + end_itr = buffer.get_iter_at_line_offset( sbounds[1].get_line() - 1, sbounds_end) + + self.emit("select-all", *(False,)) + buffer.select_range(start_itr, end_itr) self.end_user_action(buffer) def keyboard_move_lines_down(self): - buffer = self.get_buffer() + buffer = self.get_buffer() self.begin_user_action(buffer) + had_selection = buffer.get_has_selection() + itr = buffer.get_iter_at_mark( buffer.get_insert() ) + line = itr.get_line() + 1 + line_index = itr.get_line_index() + selection_bounds = None + sbounds_start = None + sbounds_end = None + + if had_selection: + selection_bounds = buffer.get_selection_bounds() + sbounds_start = selection_bounds[0].get_line_offset() + sbounds_end = selection_bounds[1].get_line_offset() + self.emit("move-lines", *(True,)) - # self.emit("move-words", *(self, -4,)) + if not had_selection: + self.emit("select-all", *(False,)) + line_itr = buffer.get_iter_at_line_offset(line, line_index) + self.get_buffer().place_cursor(line_itr) + else: + buffer = self.get_buffer() + sbounds = buffer.get_selection_bounds() + start_itr = buffer.get_iter_at_line_offset( sbounds[0].get_line(), sbounds_start) + end_itr = buffer.get_iter_at_line_offset( sbounds[1].get_line() - 1, sbounds_end) + + self.emit("select-all", *(False,)) + buffer.select_range(start_itr, end_itr) self.end_user_action(buffer) \ No newline at end of file diff --git a/src/core/window.py b/src/core/window.py index 66b374a..b3a54fd 100644 --- a/src/core/window.py +++ b/src/core/window.py @@ -1,5 +1,4 @@ # Python imports -import time import signal # Lib imports @@ -12,7 +11,8 @@ from gi.repository import Gdk from gi.repository import GLib # Application imports -from core.controller import Controller +from core.controllers.base_controller import BaseController + class ControllerStartExceptiom(Exception): @@ -20,7 +20,6 @@ class ControllerStartExceptiom(Exception): - class Window(Gtk.ApplicationWindow): """docstring for Window.""" @@ -30,12 +29,12 @@ class Window(Gtk.ApplicationWindow): self._controller = None - self._set_window_data() self._setup_styling() self._setup_signals() self._subscribe_to_events() - self._load_widgets(args, unknownargs) + + self._set_window_data() self._set_size_constraints() self.show() @@ -49,21 +48,26 @@ class Window(Gtk.ApplicationWindow): ctx = self.get_style_context() ctx.add_class("main-window") + ctx.add_class(f"mw_transparency_{settings.theming.transparency}") def _setup_signals(self): + self.connect("focus-in-event", self._on_focus_in_event) + self.connect("focus-out-event", self._on_focus_out_event) + self.connect("delete-event", self._tear_down) GLib.unix_signal_add(GLib.PRIORITY_DEFAULT, signal.SIGINT, self._tear_down) def _subscribe_to_events(self): event_system.subscribe("tear_down", self._tear_down) + event_system.subscribe("load_interactive_debug", self._load_interactive_debug) def _load_widgets(self, args, unknownargs): if settings_manager.is_debug(): self.set_interactive_debugging(True) - self._controller = Controller(args, unknownargs) + self._controller = BaseController(args, unknownargs) if not self._controller: - raise ControllerStartException("Controller exited and doesn't exist...") + raise ControllerStartException("BaseController exited and doesn't exist...") self.add( self._controller.get_core_widget() ) @@ -83,7 +87,7 @@ class Window(Gtk.ApplicationWindow): screen = self.get_screen() visual = screen.get_rgba_visual() - if visual != None and screen.is_composited(): + if visual != None and screen.is_composited() and settings.config.make_transparent == 0: self.set_visual(visual) self.set_app_paintable(True) self.connect("draw", self._area_draw) @@ -102,6 +106,15 @@ class Window(Gtk.ApplicationWindow): cr.set_operator(cairo.OPERATOR_OVER) + def _on_focus_in_event(self, widget, event): + event_system.emit("pause_dnd_signals") + + def _on_focus_out_event(self, widget, event): + event_system.emit("listen_dnd_signals") + + def _load_interactive_debug(self): + self.set_interactive_debugging(True) + def _tear_down(self, widget = None, eve = None): event_system.emit("shutting_down") @@ -116,3 +129,6 @@ class Window(Gtk.ApplicationWindow): settings_manager.clear_pid() Gtk.main_quit() + + def main(self): + Gtk.main() \ No newline at end of file diff --git a/user_config/usr/share/newton/stylesheet.css b/user_config/usr/share/newton/stylesheet.css index b63bcfc..85b7a72 100644 --- a/user_config/usr/share/newton/stylesheet.css +++ b/user_config/usr/share/newton/stylesheet.css @@ -81,6 +81,11 @@ notebook > stack > scrolledwindow > textview { color: rgba(255, 255, 255, 1); } +textview { + padding-bottom: 50em; +} + + /* any popover */ popover { background: rgba(39, 43, 52, 0.86);