generated from itdominator/Python-With-Gtk-Template
Added code minimap; added DnD of text; initial multi mark insert inferastructure
This commit is contained in:
parent
5512655f3d
commit
c86c339138
@ -8,6 +8,7 @@ from utils.ipc_server import IPCServer
|
|||||||
from core.window import Window
|
from core.window import Window
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class AppLaunchException(Exception):
|
class AppLaunchException(Exception):
|
||||||
...
|
...
|
||||||
|
|
||||||
|
@ -6,10 +6,10 @@ gi.require_version('Gtk', '3.0')
|
|||||||
from gi.repository import Gtk
|
from gi.repository import Gtk
|
||||||
|
|
||||||
# Application imports
|
# Application imports
|
||||||
|
from .widgets.save_file_dialog import SaveFileDialog
|
||||||
from .widgets.base.banner_controls import BannerControls
|
from .widgets.base.banner_controls import BannerControls
|
||||||
from .editors_container import EditorsContainer
|
from .editors_container import EditorsContainer
|
||||||
from .widgets.base.general_info_widget import GeneralInfoWidget
|
from .widgets.base.general_info_widget import GeneralInfoWidget
|
||||||
from .widgets.save_file_dialog import SaveFileDialog
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -6,25 +6,27 @@ gi.require_version('Gtk', '3.0')
|
|||||||
from gi.repository import Gtk
|
from gi.repository import Gtk
|
||||||
|
|
||||||
# Application imports
|
# Application imports
|
||||||
|
from .widgets.miniview_widget import MiniViewWidget
|
||||||
from .widgets.base.notebook.editor_notebook import EditorNotebook
|
from .widgets.base.notebook.editor_notebook import EditorNotebook
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class EditorsContainer(Gtk.Paned):
|
class EditorsPaned(Gtk.Paned):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super(EditorsContainer, self).__init__()
|
super(EditorsPaned, self).__init__()
|
||||||
|
|
||||||
self._setup_styling()
|
self._setup_styling()
|
||||||
self._setup_signals()
|
self._setup_signals()
|
||||||
self._subscribe_to_events()
|
self._subscribe_to_events()
|
||||||
self._load_widgets()
|
self._load_widgets()
|
||||||
|
|
||||||
self.show()
|
self.show_all()
|
||||||
|
|
||||||
|
|
||||||
def _setup_styling(self):
|
def _setup_styling(self):
|
||||||
self.set_wide_handle(True)
|
self.set_wide_handle(True)
|
||||||
self.set_vexpand(True)
|
self.set_vexpand(True)
|
||||||
|
self.set_hexpand(True)
|
||||||
|
|
||||||
def _setup_signals(self):
|
def _setup_signals(self):
|
||||||
...
|
...
|
||||||
@ -35,3 +37,32 @@ class EditorsContainer(Gtk.Paned):
|
|||||||
def _load_widgets(self):
|
def _load_widgets(self):
|
||||||
self.add1(EditorNotebook())
|
self.add1(EditorNotebook())
|
||||||
self.add2(EditorNotebook())
|
self.add2(EditorNotebook())
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class EditorsContainer(Gtk.Box):
|
||||||
|
def __init__(self):
|
||||||
|
super(EditorsContainer, self).__init__()
|
||||||
|
|
||||||
|
self._setup_styling()
|
||||||
|
self._setup_signals()
|
||||||
|
self._subscribe_to_events()
|
||||||
|
self._load_widgets()
|
||||||
|
|
||||||
|
self.show_all()
|
||||||
|
|
||||||
|
|
||||||
|
def _setup_styling(self):
|
||||||
|
self.set_vexpand(True)
|
||||||
|
self.set_hexpand(True)
|
||||||
|
|
||||||
|
def _setup_signals(self):
|
||||||
|
...
|
||||||
|
|
||||||
|
def _subscribe_to_events(self):
|
||||||
|
...
|
||||||
|
|
||||||
|
def _load_widgets(self):
|
||||||
|
self.add(EditorsPaned())
|
||||||
|
self.add(MiniViewWidget())
|
||||||
|
@ -41,6 +41,8 @@ class EditorControllerMixin:
|
|||||||
self.keyboard_move_tab_left(page_num)
|
self.keyboard_move_tab_left(page_num)
|
||||||
if action == "keyboard_move_tab_right":
|
if action == "keyboard_move_tab_right":
|
||||||
self.keyboard_move_tab_right(page_num)
|
self.keyboard_move_tab_right(page_num)
|
||||||
|
if action == "keyboard_insert_mark":
|
||||||
|
self.keyboard_insert_mark(source_view)
|
||||||
if action == "keyboard_move_tab_to_1":
|
if action == "keyboard_move_tab_to_1":
|
||||||
self.keyboard_move_tab_to_1(page_num)
|
self.keyboard_move_tab_to_1(page_num)
|
||||||
if action == "keyboard_move_tab_to_2":
|
if action == "keyboard_move_tab_to_2":
|
||||||
|
@ -65,6 +65,10 @@ class EditorEventsMixin:
|
|||||||
page_num = 0 if self.get_n_pages() - 1 == page_num else page_num + 1
|
page_num = 0 if self.get_n_pages() - 1 == page_num else page_num + 1
|
||||||
self.set_current_page(page_num)
|
self.set_current_page(page_num)
|
||||||
|
|
||||||
|
# NOTE: This feels bad man...
|
||||||
|
def keyboard_insert_mark(self, source_view):
|
||||||
|
source_view.keyboard_insert_mark()
|
||||||
|
|
||||||
def keyboard_move_tab_to_1(self, page_num):
|
def keyboard_move_tab_to_1(self, page_num):
|
||||||
notebook = self.builder.get_object("notebook_1")
|
notebook = self.builder.get_object("notebook_1")
|
||||||
if self.NAME == "notebook_1":
|
if self.NAME == "notebook_1":
|
||||||
|
@ -55,11 +55,8 @@ class EditorNotebook(EditorEventsMixin, EditorControllerMixin, Gtk.Notebook):
|
|||||||
|
|
||||||
def _setup_signals(self):
|
def _setup_signals(self):
|
||||||
self.connect("switch-page", self._switch_page_update)
|
self.connect("switch-page", self._switch_page_update)
|
||||||
# self.connect("button-press-event", self._dbl_click_create_view)
|
|
||||||
...
|
|
||||||
|
|
||||||
def _subscribe_to_events(self):
|
def _subscribe_to_events(self):
|
||||||
# event_system.subscribe("set_buffer_language", self.action_controller, *("set_buffer_language",))
|
|
||||||
event_system.subscribe("create_view", self._create_view)
|
event_system.subscribe("create_view", self._create_view)
|
||||||
event_system.subscribe("set_buffer_style", self.action_controller)
|
event_system.subscribe("set_buffer_style", self.action_controller)
|
||||||
event_system.subscribe("set_buffer_language", self.action_controller)
|
event_system.subscribe("set_buffer_language", self.action_controller)
|
||||||
@ -72,6 +69,7 @@ class EditorNotebook(EditorEventsMixin, EditorControllerMixin, Gtk.Notebook):
|
|||||||
event_system.subscribe("keyboard_next_tab", self._keyboard_next_tab)
|
event_system.subscribe("keyboard_next_tab", self._keyboard_next_tab)
|
||||||
event_system.subscribe("keyboard_move_tab_left", self._keyboard_move_tab_left)
|
event_system.subscribe("keyboard_move_tab_left", self._keyboard_move_tab_left)
|
||||||
event_system.subscribe("keyboard_move_tab_right", self._keyboard_move_tab_right)
|
event_system.subscribe("keyboard_move_tab_right", self._keyboard_move_tab_right)
|
||||||
|
event_system.subscribe("keyboard_insert_mark", self._keyboard_insert_mark)
|
||||||
event_system.subscribe("keyboard_move_tab_to_1", self._keyboard_move_tab_to_1)
|
event_system.subscribe("keyboard_move_tab_to_1", self._keyboard_move_tab_to_1)
|
||||||
event_system.subscribe("keyboard_move_tab_to_2", self._keyboard_move_tab_to_2)
|
event_system.subscribe("keyboard_move_tab_to_2", self._keyboard_move_tab_to_2)
|
||||||
event_system.subscribe("keyboard_scale_up_text", self._keyboard_scale_up_text)
|
event_system.subscribe("keyboard_scale_up_text", self._keyboard_scale_up_text)
|
||||||
@ -118,6 +116,7 @@ class EditorNotebook(EditorEventsMixin, EditorControllerMixin, Gtk.Notebook):
|
|||||||
def _switch_page_update(self, notebook, page, page_num):
|
def _switch_page_update(self, notebook, page, page_num):
|
||||||
source_view = page.get_source_view()
|
source_view = page.get_source_view()
|
||||||
gfile = source_view.get_current_file()
|
gfile = source_view.get_current_file()
|
||||||
|
|
||||||
if not gfile:
|
if not gfile:
|
||||||
event_system.emit("set_path_label", ("",))
|
event_system.emit("set_path_label", ("",))
|
||||||
event_system.emit("set_file_type_label", (source_view._current_filetype,))
|
event_system.emit("set_file_type_label", (source_view._current_filetype,))
|
||||||
@ -126,6 +125,8 @@ class EditorNotebook(EditorEventsMixin, EditorControllerMixin, Gtk.Notebook):
|
|||||||
source_view.update_cursor_position()
|
source_view.update_cursor_position()
|
||||||
source_view.set_bottom_labels(gfile)
|
source_view.set_bottom_labels(gfile)
|
||||||
|
|
||||||
|
event_system.emit(f"set_source_view", (source_view,))
|
||||||
|
|
||||||
def _create_view(self, gfile = None, line: int = 0):
|
def _create_view(self, gfile = None, line: int = 0):
|
||||||
if not self.is_editor_focused: # TODO: Find way to converge this
|
if not self.is_editor_focused: # TODO: Find way to converge this
|
||||||
return
|
return
|
||||||
@ -168,6 +169,9 @@ class EditorNotebook(EditorEventsMixin, EditorControllerMixin, Gtk.Notebook):
|
|||||||
def _keyboard_move_tab_right(self):
|
def _keyboard_move_tab_right(self):
|
||||||
self.action_controller("keyboard_move_tab_right")
|
self.action_controller("keyboard_move_tab_right")
|
||||||
|
|
||||||
|
def _keyboard_insert_mark(self):
|
||||||
|
self.action_controller("keyboard_insert_mark")
|
||||||
|
|
||||||
def _keyboard_move_tab_to_1(self):
|
def _keyboard_move_tab_to_1(self):
|
||||||
self.action_controller("keyboard_move_tab_to_1")
|
self.action_controller("keyboard_move_tab_to_1")
|
||||||
|
|
||||||
|
@ -59,7 +59,7 @@ class PythonCompletionProvider(GObject.Object, GtkSource.CompletionProvider):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
ch = iter.get_char()
|
ch = iter.get_char()
|
||||||
if not (ch in ('_', '.') or ch.isalnum()):
|
if not (ch in ('_', '.', ' ') or ch.isalnum()):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
@ -7,6 +7,7 @@ gi.require_version('GtkSource', '4')
|
|||||||
gi.require_version('Gdk', '3.0')
|
gi.require_version('Gdk', '3.0')
|
||||||
from gi.repository import Gtk
|
from gi.repository import Gtk
|
||||||
from gi.repository import Gdk
|
from gi.repository import Gdk
|
||||||
|
from gi.repository import GLib
|
||||||
from gi.repository import Gio
|
from gi.repository import Gio
|
||||||
from gi.repository import GtkSource
|
from gi.repository import GtkSource
|
||||||
|
|
||||||
@ -40,6 +41,7 @@ class SourceView(SourceViewEventsMixin, GtkSource.View):
|
|||||||
self._ignore_internal_change = False
|
self._ignore_internal_change = False
|
||||||
self._buffer = self.get_buffer()
|
self._buffer = self.get_buffer()
|
||||||
self._completion = self.get_completion()
|
self._completion = self.get_completion()
|
||||||
|
self._insert_marks = []
|
||||||
|
|
||||||
self._setup_styling()
|
self._setup_styling()
|
||||||
self._setup_signals()
|
self._setup_signals()
|
||||||
@ -72,6 +74,7 @@ class SourceView(SourceViewEventsMixin, GtkSource.View):
|
|||||||
self.connect("focus", self._on_widget_focus)
|
self.connect("focus", self._on_widget_focus)
|
||||||
self._buffer.connect("mark-set", self._on_cursor_move)
|
self._buffer.connect("mark-set", self._on_cursor_move)
|
||||||
self._buffer.connect('changed', self._is_modified)
|
self._buffer.connect('changed', self._is_modified)
|
||||||
|
self._buffer.connect('insert-text', self._insert_text)
|
||||||
|
|
||||||
def _subscribe_to_events(self):
|
def _subscribe_to_events(self):
|
||||||
...
|
...
|
||||||
@ -106,6 +109,15 @@ class SourceView(SourceViewEventsMixin, GtkSource.View):
|
|||||||
self._is_changed = True
|
self._is_changed = True
|
||||||
self.update_cursor_position()
|
self.update_cursor_position()
|
||||||
|
|
||||||
|
def _insert_text(self, text_buffer, location_itr, text_str, len_int):
|
||||||
|
with text_buffer.freeze_notify():
|
||||||
|
for mark in self._insert_marks:
|
||||||
|
itr = text_buffer.get_iter_at_mark(mark)
|
||||||
|
print(itr)
|
||||||
|
|
||||||
|
# GLib.idle_add(text_buffer.insert, *(itr, text_str, -1))
|
||||||
|
text_buffer.insert(itr, text_str, -1)
|
||||||
|
|
||||||
def _on_widget_focus(self, widget, eve = None):
|
def _on_widget_focus(self, widget, eve = None):
|
||||||
target = self.get_parent().get_parent().NAME
|
target = self.get_parent().get_parent().NAME
|
||||||
path = self._current_file if self._current_file else ""
|
path = self._current_file if self._current_file else ""
|
||||||
@ -121,20 +133,19 @@ class SourceView(SourceViewEventsMixin, GtkSource.View):
|
|||||||
if mark != buf.get_insert(): return
|
if mark != buf.get_insert(): return
|
||||||
self.update_cursor_position()
|
self.update_cursor_position()
|
||||||
|
|
||||||
|
# NOTE: Not sure but this might not be efficient if the map reloads the same view.
|
||||||
|
event_system.emit(f"set_source_view", (self,))
|
||||||
|
|
||||||
def _set_up_dnd(self):
|
def _set_up_dnd(self):
|
||||||
WIDGET_TARGET_TYPE = 70
|
PLAIN_TEXT_TARGET_TYPE = 70
|
||||||
URI_TARGET_TYPE = 80
|
URI_TARGET_TYPE = 80
|
||||||
widget_target = Gtk.TargetEntry.new('dummy', Gtk.TargetFlags(0), WIDGET_TARGET_TYPE)
|
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)
|
uri_target = Gtk.TargetEntry.new('text/uri-list', Gtk.TargetFlags(0), URI_TARGET_TYPE)
|
||||||
targets = [ widget_target, uri_target ]
|
targets = [ text_target, uri_target ]
|
||||||
self.drag_dest_set_target_list(targets)
|
self.drag_dest_set_target_list(targets)
|
||||||
|
|
||||||
def _on_drag_data_received(self, widget, drag_context, x, y, data, info, time):
|
def _on_drag_data_received(self, widget, drag_context, x, y, data, info, time):
|
||||||
if info == 70:
|
if info == 70:
|
||||||
print(drag_context)
|
|
||||||
print(data)
|
|
||||||
print(info)
|
|
||||||
# detach_tab(child)
|
|
||||||
return
|
return
|
||||||
|
|
||||||
if info == 80:
|
if info == 80:
|
||||||
|
@ -50,6 +50,14 @@ class SourceViewEventsMixin:
|
|||||||
|
|
||||||
event_system.emit("set_line_char_label", (f"{row}:{col}",))
|
event_system.emit("set_line_char_label", (f"{row}:{col}",))
|
||||||
|
|
||||||
|
def keyboard_insert_mark(self):
|
||||||
|
iter = self._buffer.get_iter_at_mark( self._buffer.get_insert() )
|
||||||
|
mark = Gtk.TextMark.new(name = None, left_gravity = False)
|
||||||
|
|
||||||
|
self._buffer.add_mark(mark, iter)
|
||||||
|
self._insert_marks.append(mark)
|
||||||
|
mark.set_visible(True)
|
||||||
|
|
||||||
def got_to_line(self, line: int = 0):
|
def got_to_line(self, line: int = 0):
|
||||||
index = line - 1
|
index = line - 1
|
||||||
buffer = self.get_buffer()
|
buffer = self.get_buffer()
|
||||||
|
38
src/core/widgets/miniview_widget.py
Normal file
38
src/core/widgets/miniview_widget.py
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
# Python imports
|
||||||
|
|
||||||
|
# Lib imports
|
||||||
|
import gi
|
||||||
|
gi.require_version('GtkSource', '4')
|
||||||
|
from gi.repository.GtkSource import Map
|
||||||
|
|
||||||
|
|
||||||
|
# Application imports
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class MiniViewWidget(Map):
|
||||||
|
def __init__(self):
|
||||||
|
super(MiniViewWidget, self).__init__()
|
||||||
|
|
||||||
|
self._setup_styling()
|
||||||
|
self._setup_signals()
|
||||||
|
self._subscribe_to_events()
|
||||||
|
self._load_widgets()
|
||||||
|
|
||||||
|
self.show_all()
|
||||||
|
|
||||||
|
|
||||||
|
def _setup_styling(self):
|
||||||
|
self.set_hexpand(False)
|
||||||
|
|
||||||
|
def _setup_signals(self):
|
||||||
|
event_system.subscribe(f"set_source_view", self.set_source_view)
|
||||||
|
|
||||||
|
def _subscribe_to_events(self):
|
||||||
|
...
|
||||||
|
|
||||||
|
def _load_widgets(self):
|
||||||
|
...
|
||||||
|
|
||||||
|
def set_source_view(self, source_view):
|
||||||
|
self.set_view(source_view)
|
@ -9,6 +9,7 @@
|
|||||||
"keyboard_create_tab" : "<Control>t",
|
"keyboard_create_tab" : "<Control>t",
|
||||||
"keyboard_close_tab" : "<Control>w",
|
"keyboard_close_tab" : "<Control>w",
|
||||||
"keyboard_save_file" : "<Control>s",
|
"keyboard_save_file" : "<Control>s",
|
||||||
|
"keyboard_insert_mark" : "<Control>m",
|
||||||
"keyboard_save_file_as" : "<Shift><Control>s",
|
"keyboard_save_file_as" : "<Shift><Control>s",
|
||||||
"keyboard_up" : "Up",
|
"keyboard_up" : "Up",
|
||||||
"keyboard_down" : "Down",
|
"keyboard_down" : "Down",
|
||||||
|
@ -1,5 +1,16 @@
|
|||||||
/* Set fm to have transparent window */
|
|
||||||
* {
|
* {
|
||||||
background: rgba(39, 43, 52, 0.24);
|
background: rgba(39, 43, 52, 0.24);
|
||||||
color: rgba(255, 255, 255, 1);
|
color: rgba(255, 255, 255, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
* selection {
|
||||||
|
background-color: rgba(0, 115, 115, 0.34);
|
||||||
|
/* Bergundy */
|
||||||
|
/* background-color: rgba(116, 0, 0, 0.64); */
|
||||||
|
color: rgba(255, 255, 255, 0.5);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
.error_txt { color: rgb(170, 18, 18); }
|
||||||
|
.warning_txt { color: rgb(255, 168, 0); }
|
||||||
|
.success_txt { color: rgb(136, 204, 39); }
|
||||||
|
Loading…
Reference in New Issue
Block a user