aligned to base template project; scroll past end added; move line selection preservation

This commit is contained in:
itdominator 2024-01-27 23:44:34 -06:00
parent 880c4839cc
commit 0c6af185a2
10 changed files with 111 additions and 46 deletions

View File

@ -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()

View File

@ -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()
self.load_ipc(args, unknownargs)
if not self.is_ipc_alive:
self.setup_debug_hook()
Window(args, unknownargs).main()
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}"
self.send_ipc_message(message)
ipc_server.send_ipc_message(message)
raise AppLaunchException(f"{app_name} IPC Server Exists: Have sent path(s) to it and closing...")
self.setup_debug_hook()
Window(args, unknownargs)
def socket_realization_check(self):
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:
...

View File

@ -1,3 +0,0 @@
"""
Gtk Bound Signal Module
"""

View File

@ -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()

View File

@ -0,0 +1,3 @@
"""
Controllers Module
"""

View File

@ -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])

View File

@ -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()

View File

@ -121,9 +121,30 @@ class SourceViewControllerMixin(KeyInputController, SourceViewEvents):
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)
@ -132,7 +153,31 @@ class SourceViewControllerMixin(KeyInputController, SourceViewEvents):
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)

View File

@ -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()

View File

@ -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);