Moving settings out of global space; added editor commands and wired them
This commit is contained in:
@@ -57,11 +57,10 @@ builtins.settings_manager = SettingsManager()
|
||||
|
||||
settings_manager.load_settings()
|
||||
|
||||
builtins.settings = settings_manager.settings
|
||||
builtins.logger = Logger(
|
||||
settings_manager.get_home_config_path(), \
|
||||
_ch_log_lvl = settings.debugging.ch_log_lvl, \
|
||||
_fh_log_lvl = settings.debugging.fh_log_lvl
|
||||
_ch_log_lvl = settings_manager.settings.debugging.ch_log_lvl, \
|
||||
_fh_log_lvl = settings_manager.settings.debugging.fh_log_lvl
|
||||
).get_logger()
|
||||
|
||||
builtins.threaded = threaded_wrapper
|
||||
|
||||
@@ -43,7 +43,7 @@ class BaseContainer(Gtk.Box):
|
||||
self.add( FooterContainer() )
|
||||
|
||||
def _update_transparency(self):
|
||||
self.ctx.add_class(f"mw_transparency_{settings.theming.transparency}")
|
||||
self.ctx.add_class(f"mw_transparency_{settings_manager.settings.theming.transparency}")
|
||||
|
||||
def _remove_transparency(self):
|
||||
self.ctx.remove_class(f"mw_transparency_{settings.theming.transparency}")
|
||||
self.ctx.remove_class(f"mw_transparency_{settings_manager.settings.theming.transparency}")
|
||||
@@ -6,6 +6,7 @@ gi.require_version('Gtk', '3.0')
|
||||
from gi.repository import Gtk
|
||||
|
||||
# Application imports
|
||||
from .code.editors_container import EditorsContainer
|
||||
|
||||
|
||||
|
||||
@@ -35,4 +36,4 @@ class FooterContainer(Gtk.Box):
|
||||
...
|
||||
|
||||
def _load_widgets(self):
|
||||
...
|
||||
self.add( EditorsContainer() )
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
# Lib imports
|
||||
|
||||
# Application imports
|
||||
from .commands import *
|
||||
from . import commands
|
||||
|
||||
|
||||
|
||||
@@ -18,12 +18,17 @@ class CommandSystem:
|
||||
self.data = (args, kwargs)
|
||||
|
||||
def exec(self, command: str):
|
||||
if not command in globals(): return
|
||||
if not hasattr(commands, command): return
|
||||
method = getattr(commands, command)
|
||||
|
||||
# method = getattr(self, command, None)
|
||||
method = globals()[command]
|
||||
args, kwargs = self.data
|
||||
if kwargs:
|
||||
method.execute(*args, kwargs)
|
||||
else:
|
||||
method.execute(*args)
|
||||
|
||||
def exec_with_args(self, command: str, args: list):
|
||||
if not hasattr(commands, command): return
|
||||
|
||||
method = getattr(commands, command)
|
||||
method.execute(*args)
|
||||
|
||||
@@ -2,11 +2,15 @@
|
||||
Commands Package
|
||||
"""
|
||||
|
||||
import os
|
||||
import pkgutil
|
||||
import importlib
|
||||
|
||||
__all__ = []
|
||||
|
||||
__all__ = [
|
||||
command.replace(".py", "") for command in os.listdir(
|
||||
os.path.dirname(__file__)
|
||||
) if "__init__" not in command
|
||||
]
|
||||
for loader, module_name, is_pkg in pkgutil.walk_packages(__path__):
|
||||
module = importlib.import_module(f"{__name__}.{module_name}")
|
||||
globals()[module_name] = module # Add module to package namespace
|
||||
__all__.append(module_name)
|
||||
|
||||
del pkgutil
|
||||
del importlib
|
||||
|
||||
@@ -18,5 +18,6 @@ def execute(
|
||||
file = editor.files.new()
|
||||
buffer = editor.get_buffer()
|
||||
editor.set_buffer(file.buffer)
|
||||
|
||||
|
||||
editor.files.remove_file(buffer)
|
||||
editor.command.exec("update_info_bar")
|
||||
|
||||
@@ -17,3 +17,4 @@ def execute(
|
||||
logger.debug("Focus Left Sibling Command")
|
||||
if not editor.sibling_left: return
|
||||
editor.sibling_left.grab_focus()
|
||||
editor.sibling_left.command.exec("set_miniview")
|
||||
|
||||
@@ -17,3 +17,4 @@ def execute(
|
||||
logger.debug("Focus Right Sibling Command")
|
||||
if not editor.sibling_right: return
|
||||
editor.sibling_right.grab_focus()
|
||||
editor.sibling_right.command.exec("set_miniview")
|
||||
32
src/core/widgets/code/commands/load_file.py
Normal file
32
src/core/widgets/code/commands/load_file.py
Normal file
@@ -0,0 +1,32 @@
|
||||
# Python imports
|
||||
|
||||
# Lib imports
|
||||
import gi
|
||||
|
||||
gi.require_version('GtkSource', '4')
|
||||
|
||||
from gi.repository import GtkSource
|
||||
from gi.repository import Gio
|
||||
|
||||
# Application imports
|
||||
from ..source_file import SourceFile
|
||||
|
||||
|
||||
|
||||
def execute(
|
||||
editor: GtkSource.View,
|
||||
gfile: Gio.File,
|
||||
file: SourceFile = None,
|
||||
):
|
||||
logger.debug("Load File Command")
|
||||
if not file:
|
||||
file = editor.files.new()
|
||||
|
||||
file.load_path(gfile)
|
||||
|
||||
language = editor.language_manager \
|
||||
.guess_language(file.fname, None)
|
||||
file.ftype = language
|
||||
|
||||
file.buffer.set_language(language)
|
||||
file.buffer.set_style_scheme(editor.syntax_theme)
|
||||
@@ -23,3 +23,4 @@ def execute(
|
||||
file.buffer.set_style_scheme(editor.syntax_theme)
|
||||
|
||||
editor.set_buffer(file.buffer)
|
||||
editor.exec_command("update_info_bar")
|
||||
|
||||
@@ -21,15 +21,8 @@ def execute(
|
||||
size = len(gfiles)
|
||||
for i, gfile in enumerate(gfiles):
|
||||
file = editor.files.new()
|
||||
file.load_path(gfile)
|
||||
|
||||
language = editor.language_manager \
|
||||
.guess_language(file.fname, None)
|
||||
file.ftype = language
|
||||
file.buffer.set_language(language)
|
||||
file.buffer.set_style_scheme(editor.syntax_theme)
|
||||
editor.command.exec_with_args("load_file", (editor, gfile, file))
|
||||
|
||||
if i == (size - 1):
|
||||
editor.set_buffer(file.buffer)
|
||||
|
||||
|
||||
editor.command.exec("update_info_bar")
|
||||
|
||||
@@ -24,3 +24,5 @@ def execute(
|
||||
.guess_language(file.fname, None)
|
||||
file.ftype = language
|
||||
file.buffer.set_language(language)
|
||||
|
||||
editor.exec_command("update_info_bar")
|
||||
|
||||
26
src/core/widgets/code/commands/set_focus_border.py
Normal file
26
src/core/widgets/code/commands/set_focus_border.py
Normal file
@@ -0,0 +1,26 @@
|
||||
# Python imports
|
||||
|
||||
# Lib imports
|
||||
import gi
|
||||
|
||||
gi.require_version('GtkSource', '4')
|
||||
|
||||
from gi.repository import GtkSource
|
||||
|
||||
# Application imports
|
||||
|
||||
|
||||
|
||||
def execute(
|
||||
editor: GtkSource.View = None
|
||||
):
|
||||
logger.debug("Set Focus Border Command")
|
||||
ctx = editor.get_style_context()
|
||||
ctx.add_class("source-view-focused")
|
||||
|
||||
if editor.sibling_right:
|
||||
ctx = editor.sibling_right.get_style_context()
|
||||
elif editor.sibling_left:
|
||||
ctx = editor.sibling_left.get_style_context()
|
||||
|
||||
ctx.remove_class("source-view-focused")
|
||||
21
src/core/widgets/code/commands/set_miniview.py
Normal file
21
src/core/widgets/code/commands/set_miniview.py
Normal file
@@ -0,0 +1,21 @@
|
||||
# Python imports
|
||||
|
||||
# Lib imports
|
||||
import gi
|
||||
|
||||
gi.require_version('GtkSource', '4')
|
||||
|
||||
from gi.repository import GtkSource
|
||||
from gi.repository import Gio
|
||||
|
||||
# Application imports
|
||||
from ..source_file import SourceFile
|
||||
|
||||
|
||||
|
||||
def execute(
|
||||
editor: GtkSource.View,
|
||||
):
|
||||
logger.debug("Set MiniView Command")
|
||||
event_system.emit("set-mini-view", (editor,))
|
||||
|
||||
33
src/core/widgets/code/commands/update_info_bar.py
Normal file
33
src/core/widgets/code/commands/update_info_bar.py
Normal file
@@ -0,0 +1,33 @@
|
||||
# Python imports
|
||||
|
||||
# Lib imports
|
||||
import gi
|
||||
|
||||
gi.require_version('GtkSource', '4')
|
||||
|
||||
from gi.repository import GtkSource
|
||||
from gi.repository import Gio
|
||||
|
||||
# Application imports
|
||||
from ..source_file import SourceFile
|
||||
|
||||
|
||||
|
||||
def execute(
|
||||
editor: GtkSource.View,
|
||||
):
|
||||
logger.debug("Update Info Bar Command")
|
||||
buffer = editor.get_buffer()
|
||||
file = editor.files.get_file(buffer)
|
||||
|
||||
if not file: return
|
||||
|
||||
iter = buffer.get_iter_at_mark( buffer.get_insert() )
|
||||
line = iter.get_line() + 1
|
||||
column = iter.get_line_offset()
|
||||
ftype = file.ftype.get_id() if hasattr(file.ftype, "get_id") else file.ftype
|
||||
|
||||
event_system.emit(
|
||||
"set-info-labels",
|
||||
(file.fpath, f"{line}:{column}", ftype, file.encoding)
|
||||
)
|
||||
@@ -53,6 +53,7 @@ class CompletionManager():
|
||||
def _start_completion(self):
|
||||
"""
|
||||
Note: Use IF NO providers have been added to completion...
|
||||
print("here")
|
||||
"""
|
||||
self._completor.start(
|
||||
[
|
||||
|
||||
@@ -85,7 +85,8 @@ class KeyMapper:
|
||||
|
||||
keyname = keyname.replace("<Control>", "") \
|
||||
.replace("<Shift>", "") \
|
||||
.replace("<Alt>", "")
|
||||
.replace("<Alt>", "") \
|
||||
.lower()
|
||||
|
||||
getattr(self.states[state], press_state)[keyname] = command
|
||||
|
||||
|
||||
3
src/core/widgets/code/mixins/__init__.py
Normal file
3
src/core/widgets/code/mixins/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
||||
"""
|
||||
Code Mixins Package
|
||||
"""
|
||||
50
src/core/widgets/code/mixins/source_view_dnd_mixin.py
Normal file
50
src/core/widgets/code/mixins/source_view_dnd_mixin.py
Normal file
@@ -0,0 +1,50 @@
|
||||
# Python imports
|
||||
|
||||
# Lib imports
|
||||
import gi
|
||||
gi.require_version('Gtk', '3.0')
|
||||
from gi.repository import Gtk
|
||||
from gi.repository import Gio
|
||||
|
||||
# Application imports
|
||||
|
||||
|
||||
|
||||
class SourceViewDnDMixin:
|
||||
|
||||
def _set_up_dnd(self):
|
||||
PLAIN_TEXT_TARGET_TYPE = 70
|
||||
URI_TARGET_TYPE = 80
|
||||
text_target = Gtk.TargetEntry.new('text/plain', Gtk.TargetFlags(0), PLAIN_TEXT_TARGET_TYPE)
|
||||
uri_target = Gtk.TargetEntry.new('text/uri-list', Gtk.TargetFlags(0), URI_TARGET_TYPE)
|
||||
targets = [ text_target, uri_target ]
|
||||
self.drag_dest_set_target_list(targets)
|
||||
|
||||
def _on_drag_data_received(self, widget, drag_context, x, y, data, info, time):
|
||||
if info == 70: return
|
||||
|
||||
if info == 80:
|
||||
uris = data.get_uris()
|
||||
buffer = self.get_buffer()
|
||||
file = self.files.get_file(buffer)
|
||||
|
||||
if len(uris) == 0:
|
||||
uris = data.get_text().split("\n")
|
||||
|
||||
if file.ftype == "buffer":
|
||||
gfile = Gio.File.new_for_uri(uris[0])
|
||||
self.command.exec_with_args(
|
||||
"load_file",
|
||||
(self, gfile, file)
|
||||
)
|
||||
|
||||
self.command.exec("update_info_bar")
|
||||
uris.pop(0)
|
||||
|
||||
for uri in uris:
|
||||
try:
|
||||
gfile = Gio.File.new_for_uri(uri)
|
||||
except Exception as e:
|
||||
gfile = Gio.File.new_for_path(uri)
|
||||
|
||||
self.command.exec_with_args("load_file", (self, gfile))
|
||||
@@ -42,7 +42,7 @@ class SourceFile(GtkSource.File):
|
||||
if not gfile: return
|
||||
self.set_location(gfile)
|
||||
|
||||
self.fpath = gfile.get_parent().get_path(),
|
||||
self.fpath = gfile.get_path()
|
||||
self.fname = gfile.get_basename()
|
||||
|
||||
def _set_signals(self):
|
||||
@@ -93,7 +93,6 @@ class SourceFile(GtkSource.File):
|
||||
self._write_file( self.get_location() )
|
||||
|
||||
def save_as(self):
|
||||
print("poop")
|
||||
file = event_system.emit_and_await("save-file-dialog")
|
||||
if not file: return
|
||||
|
||||
|
||||
@@ -39,10 +39,14 @@ class SourceFilesManager(list):
|
||||
|
||||
popped_file = self.pop(i)
|
||||
sibling_file = None
|
||||
if len(self) == 0:
|
||||
size = len(self)
|
||||
|
||||
if size == 0:
|
||||
sibling_file = self.new()
|
||||
else:
|
||||
sibling_file = self[ i - 1 if i > 0 else i + 1]
|
||||
new_i = 0 if size == 1 else i - 1 if i > 1 else i + 1
|
||||
|
||||
sibling_file = self[new_i]
|
||||
|
||||
return sibling_file, popped_file
|
||||
|
||||
|
||||
@@ -10,6 +10,8 @@ from gi.repository import GLib
|
||||
from gi.repository import GtkSource
|
||||
|
||||
# Application imports
|
||||
from .mixins.source_view_dnd_mixin import SourceViewDnDMixin
|
||||
|
||||
from .source_files_manager import SourceFilesManager
|
||||
from .completion_manager import CompletionManager
|
||||
from .command_system import CommandSystem
|
||||
@@ -17,7 +19,7 @@ from .key_mapper import KeyMapper
|
||||
|
||||
|
||||
|
||||
class SourceView(GtkSource.View):
|
||||
class SourceView(SourceViewDnDMixin, GtkSource.View):
|
||||
def __init__(self):
|
||||
super(SourceView, self).__init__()
|
||||
|
||||
@@ -36,6 +38,7 @@ class SourceView(GtkSource.View):
|
||||
ctx.add_class("source-view")
|
||||
|
||||
self.set_vexpand(True)
|
||||
self.set_bottom_margin(800)
|
||||
|
||||
self.set_show_line_marks(True)
|
||||
self.set_show_line_numbers(True)
|
||||
@@ -51,24 +54,20 @@ class SourceView(GtkSource.View):
|
||||
self.set_highlight_current_line(True)
|
||||
|
||||
def _setup_signals(self):
|
||||
# self.connect("show-completion", self._show_completion)
|
||||
self.map_id = self.connect("map", self._init_map)
|
||||
|
||||
# self.connect("focus", self._on_widget_focus)
|
||||
# self.connect("focus-in-event", self._focus_in_event)
|
||||
|
||||
# self.connect("drag-data-received", self._on_drag_data_received)
|
||||
self.connect("drag-data-received", self._on_drag_data_received)
|
||||
self.connect("focus-in-event", self._focus_in_event)
|
||||
self.connect("key-press-event", self._key_press_event)
|
||||
self.connect("key-release-event", self._key_release_event)
|
||||
# self.connect("button-press-event", self._button_press_event)
|
||||
# self.connect("button-release-event", self._button_release_event)
|
||||
# self.connect("scroll-event", self._scroll_event)
|
||||
self.connect("button-press-event", self._button_press_event)
|
||||
self.connect("button-release-event", self._button_release_event)
|
||||
|
||||
def _subscribe_to_events(self):
|
||||
...
|
||||
|
||||
def _load_widgets(self):
|
||||
...
|
||||
self._set_up_dnd()
|
||||
|
||||
def _init_map(self, view):
|
||||
def _first_show_init():
|
||||
@@ -89,19 +88,38 @@ class SourceView(GtkSource.View):
|
||||
self.files = SourceFilesManager()
|
||||
self.completion = CompletionManager()
|
||||
|
||||
self.command.set_data(self)
|
||||
self.completion.set_completer( self.get_completion() )
|
||||
|
||||
self.style_scheme_manager.append_search_path(
|
||||
f"{settings_manager.get_home_config_path()}/code_styles"
|
||||
)
|
||||
self.syntax_theme = self.style_scheme_manager.get_scheme(
|
||||
f"{settings.theming.syntax_theme}"
|
||||
f"{settings_manager.settings.theming.syntax_theme}"
|
||||
)
|
||||
|
||||
self.command.set_data(self)
|
||||
self.exec_command("new_file")
|
||||
if self.sibling_right:
|
||||
self.grab_focus()
|
||||
|
||||
|
||||
def _focus_in_event(self, view, eve):
|
||||
self.command.exec("set_miniview")
|
||||
self.command.exec("set_focus_border")
|
||||
self.command.exec("update_info_bar")
|
||||
|
||||
def _move_cursor(self, view, step, count, extend_selection):
|
||||
self.command.exec("update_info_bar")
|
||||
|
||||
def _button_press_event(self, view, eve):
|
||||
self.command.exec("update_info_bar")
|
||||
|
||||
def _button_release_event(self, view, eve):
|
||||
self.command.exec("update_info_bar")
|
||||
|
||||
def _key_press_event(self, view, eve):
|
||||
self.command.exec("update_info_bar")
|
||||
|
||||
command = self.key_mapper._key_press_event(eve)
|
||||
if not command: return False
|
||||
|
||||
@@ -109,6 +127,8 @@ class SourceView(GtkSource.View):
|
||||
return True
|
||||
|
||||
def _key_release_event(self, view, eve):
|
||||
self.command.exec("update_info_bar")
|
||||
|
||||
command = self.key_mapper._key_release_event(eve)
|
||||
if not command: return False
|
||||
|
||||
|
||||
@@ -38,11 +38,11 @@ class TransparencyScale(Gtk.Scale):
|
||||
adjust = self.get_adjustment()
|
||||
adjust.set_lower(0)
|
||||
adjust.set_upper(100)
|
||||
adjust.set_value(settings.theming.transparency)
|
||||
adjust.set_value(settings_manager.settings.theming.transparency)
|
||||
adjust.set_step_increment(1.0)
|
||||
|
||||
def _update_transparency(self, range):
|
||||
event_system.emit("remove-transparency")
|
||||
tp = int(range.get_value())
|
||||
settings.theming.transparency = tp
|
||||
settings_manager.settings.theming.transparency = tp
|
||||
event_system.emit("update-transparency")
|
||||
37
src/core/widgets/separator_widget.py
Normal file
37
src/core/widgets/separator_widget.py
Normal file
@@ -0,0 +1,37 @@
|
||||
# Python imports
|
||||
|
||||
# Lib imports
|
||||
import gi
|
||||
gi.require_version('Gtk', '3.0')
|
||||
from gi.repository import Gtk
|
||||
|
||||
# Application imports
|
||||
|
||||
|
||||
|
||||
class Separator(Gtk.Separator):
|
||||
def __init__(self, id: str = None, ORIENTATION: int = 0):
|
||||
super(Separator, self).__init__()
|
||||
|
||||
builder = settings_manager.get_builder()
|
||||
if id:
|
||||
builder.expose_object(id, self)
|
||||
|
||||
self.ORIENTATION = ORIENTATION
|
||||
self._setup_styling()
|
||||
self._setup_signals()
|
||||
self._load_widgets()
|
||||
|
||||
self.show()
|
||||
|
||||
|
||||
def _setup_styling(self):
|
||||
# HORIZONTAL = 0, VERTICAL = 1
|
||||
self.set_orientation(self.ORIENTATION)
|
||||
|
||||
|
||||
def _setup_signals(self):
|
||||
...
|
||||
|
||||
def _load_widgets(self):
|
||||
...
|
||||
@@ -62,7 +62,7 @@ class Window(Gtk.ApplicationWindow):
|
||||
|
||||
ctx = self.get_style_context()
|
||||
ctx.add_class("main-window")
|
||||
ctx.add_class(f"mw_transparency_{settings.theming.transparency}")
|
||||
ctx.add_class(f"mw_transparency_{settings_manager.settings.theming.transparency}")
|
||||
|
||||
def _setup_signals(self):
|
||||
self.connect("focus-in-event", self._on_focus_in_event)
|
||||
@@ -96,12 +96,12 @@ class Window(Gtk.ApplicationWindow):
|
||||
return 'X11'
|
||||
|
||||
def _set_size_constraints(self):
|
||||
_window_x = settings.config.main_window_x
|
||||
_window_y = settings.config.main_window_y
|
||||
_min_width = settings.config.main_window_min_width
|
||||
_min_height = settings.config.main_window_min_height
|
||||
_width = settings.config.main_window_width
|
||||
_height = settings.config.main_window_height
|
||||
_window_x = settings_manager.settings.config.main_window_x
|
||||
_window_y = settings_manager.settings.config.main_window_y
|
||||
_min_width = settings_manager.settings.config.main_window_min_width
|
||||
_min_height = settings_manager.settings.config.main_window_min_height
|
||||
_width = settings_manager.settings.config.main_window_width
|
||||
_height = settings_manager.settings.config.main_window_height
|
||||
|
||||
self.move(_window_x, _window_y - 28)
|
||||
self.set_size_request(_min_width, _min_height)
|
||||
@@ -111,7 +111,7 @@ class Window(Gtk.ApplicationWindow):
|
||||
screen = self.get_screen()
|
||||
visual = screen.get_rgba_visual()
|
||||
|
||||
if visual and screen.is_composited() and settings.config.make_transparent == 0:
|
||||
if visual and screen.is_composited() and settings_manager.settings.config.make_transparent == 0:
|
||||
self.set_visual(visual)
|
||||
self.set_app_paintable(True)
|
||||
# self.connect("draw", self._area_draw)
|
||||
|
||||
Reference in New Issue
Block a user