generated from itdominator/Python-With-Gtk-Template
Template file watcher, them selection popover, added needed controls
This commit is contained in:
parent
76300b09b6
commit
aed28a026c
@ -6,6 +6,7 @@ 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.scale_up_button import ScaleUpButton
|
||||
from ..controls.scale_down_button import ScaleDownButton
|
||||
@ -31,9 +32,7 @@ class BannerControls(Gtk.Box):
|
||||
...
|
||||
|
||||
def _load_widgets(self):
|
||||
# styles_chooser_button = GtkSource.StyleSchemeChooserButton()
|
||||
|
||||
self.add(ToggleLineHighlight())
|
||||
# self.add(styles_chooser_button)
|
||||
self.add(ScaleUpButton())
|
||||
self.add(ScaleDownButton())
|
||||
self.pack_end(ThemeButton(), False, False, 0)
|
||||
|
@ -6,8 +6,7 @@ gi.require_version('Gtk', '3.0')
|
||||
from gi.repository import Gtk
|
||||
|
||||
# Application imports
|
||||
from ..tab_header_widget import TabHeaderWidget
|
||||
from .source_view import SourceView
|
||||
from .sourceview_container import SourceViewContainer
|
||||
|
||||
|
||||
|
||||
@ -15,37 +14,73 @@ class EditorNotebook(Gtk.Notebook):
|
||||
def __init__(self):
|
||||
super(EditorNotebook, self).__init__()
|
||||
|
||||
self.set_group_name("editor_widget")
|
||||
|
||||
self._add_action_widgets()
|
||||
self._setup_styling()
|
||||
self._setup_signals()
|
||||
self._subscribe_to_events()
|
||||
self._load_widgets()
|
||||
|
||||
self.show_all()
|
||||
|
||||
|
||||
def _setup_styling(self):
|
||||
...
|
||||
self.set_scrollable(True)
|
||||
|
||||
def _setup_signals(self):
|
||||
...
|
||||
|
||||
def _subscribe_to_events(self):
|
||||
# event_system.subscribe("set_buffer_language", self.action_controller, *("set_buffer_language",))
|
||||
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("toggle_highlight_line", self.action_controller)
|
||||
event_system.subscribe("scale_up_text", self.action_controller)
|
||||
event_system.subscribe("scale_down_text", self.action_controller)
|
||||
|
||||
|
||||
def _add_action_widgets(self):
|
||||
start_box = Gtk.Box()
|
||||
end_box = Gtk.Box()
|
||||
|
||||
search = Gtk.SearchEntry()
|
||||
search.set_placeholder_text("Search...")
|
||||
search.connect("changed", self._text_search)
|
||||
|
||||
add_btn = Gtk.Button()
|
||||
add_btn.set_image( Gtk.Image.new_from_icon_name("add", 4) )
|
||||
add_btn.set_always_show_image(True)
|
||||
add_btn.connect("released", self.create_view)
|
||||
|
||||
end_box.add(add_btn)
|
||||
end_box.add(search)
|
||||
|
||||
start_box.show_all()
|
||||
end_box.show_all()
|
||||
|
||||
# PACKTYPE: 0 Start, 1 = End
|
||||
self.set_action_widget(start_box, 0)
|
||||
self.set_action_widget(end_box, 1)
|
||||
|
||||
def _load_widgets(self):
|
||||
self.create_view()
|
||||
|
||||
def create_view(self):
|
||||
scroll_view = Gtk.ScrolledWindow()
|
||||
source_view = SourceView()
|
||||
tab_widget = TabHeaderWidget(scroll_view, source_view, self.close_tab)
|
||||
scroll_view.add(source_view)
|
||||
def create_view(self, widget = None, eve = None):
|
||||
container = SourceViewContainer(self.close_tab)
|
||||
|
||||
index = self.append_page(scroll_view, tab_widget)
|
||||
self.set_tab_detachable(scroll_view, True)
|
||||
self.set_current_page(index)
|
||||
index = self.append_page(container, container.get_tab_widget())
|
||||
self.set_tab_detachable(container, True)
|
||||
|
||||
ctx = self.get_style_context()
|
||||
ctx.add_class("notebook-unselected-focus")
|
||||
self.set_tab_reorderable(scroll_view, True)
|
||||
self.set_tab_reorderable(container, True)
|
||||
self.show_all()
|
||||
|
||||
def close_tab(self, button, scroll_view, source_view, eve=None):
|
||||
self.set_current_page(index)
|
||||
|
||||
def close_tab(self, button, scroll_view, source_view, eve = None):
|
||||
if self.get_n_pages() == 1:
|
||||
return
|
||||
|
||||
@ -55,3 +90,44 @@ class EditorNotebook(Gtk.Notebook):
|
||||
watcher.cancel()
|
||||
|
||||
self.remove_page(page_num)
|
||||
|
||||
|
||||
|
||||
def _text_search(self, widget = None, eve = None):
|
||||
self.action_controller("do_text_search", widget.get_text())
|
||||
|
||||
def action_controller(self, action = "", query = ""):
|
||||
page_num = self.get_current_page()
|
||||
container = self.get_nth_page( page_num )
|
||||
source_view = container.get_source_view()
|
||||
|
||||
if action == "do_text_search":
|
||||
self.do_text_search(source_view, query)
|
||||
if action == "set_buffer_language":
|
||||
self.set_buffer_language(source_view, query)
|
||||
if action == "set_buffer_style":
|
||||
self.set_buffer_style(source_view, query)
|
||||
if action == "toggle_highlight_line":
|
||||
self.toggle_highlight_line(source_view)
|
||||
if action == "scale_up_text":
|
||||
self.scale_up_text(source_view)
|
||||
if action == "scale_down_text":
|
||||
self.scale_down_text(source_view)
|
||||
|
||||
def do_text_search(self, query = ""):
|
||||
source_view.scale_down_text()
|
||||
|
||||
def set_buffer_language(self, source_view, language = "python3"):
|
||||
source_view.set_buffer_language(language)
|
||||
|
||||
def set_buffer_style(self, source_view, style = "tango"):
|
||||
source_view.set_buffer_style(style)
|
||||
|
||||
def scale_up_text(self, source_view):
|
||||
source_view.scale_up_text()
|
||||
|
||||
def scale_down_text(self, source_view):
|
||||
source_view.scale_down_text()
|
||||
|
||||
def toggle_highlight_line(self, source_view):
|
||||
source_view.toggle_highlight_line()
|
||||
|
@ -4,6 +4,7 @@
|
||||
import gi
|
||||
gi.require_version('GtkSource', '4')
|
||||
from gi.repository import GtkSource
|
||||
from gi.repository import Gio
|
||||
|
||||
# Application imports
|
||||
|
||||
@ -16,6 +17,7 @@ class SourceView(GtkSource.View):
|
||||
self._language_manager = GtkSource.LanguageManager()
|
||||
self._style_scheme_manager = GtkSource.StyleSchemeManager()
|
||||
self._general_style_tag = None
|
||||
self._file_watcher = None
|
||||
|
||||
self._buffer = self.get_buffer()
|
||||
|
||||
@ -34,13 +36,13 @@ class SourceView(GtkSource.View):
|
||||
self.set_auto_indent(True)
|
||||
self.set_monospace(True)
|
||||
self.set_tab_width(4)
|
||||
# self.set_show_right_margin(True)
|
||||
# self.set_right_margin_position(80)
|
||||
self.set_show_right_margin(True)
|
||||
self.set_right_margin_position(80)
|
||||
self.set_background_pattern(0) # 0 = None, 1 = Grid
|
||||
|
||||
self._set_buffer_language()
|
||||
self._set_buffer_style()
|
||||
self._create_default_tag()
|
||||
self.set_buffer_language()
|
||||
self.set_buffer_style()
|
||||
|
||||
self.set_vexpand(True)
|
||||
|
||||
@ -48,12 +50,7 @@ class SourceView(GtkSource.View):
|
||||
...
|
||||
|
||||
def _subscribe_to_events(self):
|
||||
event_system.subscribe("set_buffer_language", self._set_buffer_language)
|
||||
event_system.subscribe("set_buffer_style", self._set_buffer_style)
|
||||
event_system.subscribe("toggle_highlight_line", self.toggle_highlight_line)
|
||||
event_system.subscribe("scale_up_text", self.scale_up_text)
|
||||
event_system.subscribe("scale_down_text", self.scale_down_text)
|
||||
|
||||
...
|
||||
|
||||
def _load_widgets(self):
|
||||
...
|
||||
@ -63,17 +60,46 @@ class SourceView(GtkSource.View):
|
||||
self._general_style_tag.set_property('size', 100)
|
||||
self._general_style_tag.set_property('scale', 100)
|
||||
|
||||
def _set_buffer_language(self, language = "python3"):
|
||||
def set_buffer_language(self, language = "python3"):
|
||||
self._buffer.set_language( self._language_manager.get_language(language) )
|
||||
|
||||
def _set_buffer_style(self, style = "tango"):
|
||||
def set_buffer_style(self, style = "tango"):
|
||||
self._buffer.set_style_scheme( self._style_scheme_manager.get_scheme(style) )
|
||||
|
||||
|
||||
def get_file_watcher(self):
|
||||
return None
|
||||
return self._file_watcher
|
||||
|
||||
def create_file_watcher(self, file_path = None):
|
||||
if not file_path:
|
||||
return
|
||||
|
||||
if self._file_watcher:
|
||||
self._file_watcher.cancel()
|
||||
self._file_watcher = None
|
||||
|
||||
self._file_watcher = Gio.File.new_for_path(file_path) \
|
||||
.monitor_file([
|
||||
Gio.FileMonitorFlags.WATCH_MOVES,
|
||||
Gio.FileMonitorFlags.WATCH_HARD_LINKS
|
||||
], Gio.Cancellable())
|
||||
|
||||
self._file_watcher.connect("changed", self.file_watch_updates)
|
||||
|
||||
def file_watch_updates(self, file_monitor, file, other_file=None, eve_type=None, data=None):
|
||||
if settings.is_debug():
|
||||
logger.debug(eve_type)
|
||||
|
||||
if eve_type in [Gio.FileMonitorEvent.CREATED,
|
||||
Gio.FileMonitorEvent.DELETED,
|
||||
Gio.FileMonitorEvent.RENAMED]:
|
||||
...
|
||||
|
||||
if eve_type in [ Gio.FileMonitorEvent.CHANGED ]:
|
||||
...
|
||||
|
||||
|
||||
def toggle_highlight_line(self, widget=None, eve=None):
|
||||
def toggle_highlight_line(self, widget = None, eve = None):
|
||||
self.set_highlight_current_line( not self.get_highlight_current_line() )
|
||||
|
||||
def scale_up_text(self, scale_step = 10):
|
||||
|
46
src/core/widgets/base/sourceview_container.py
Normal file
46
src/core/widgets/base/sourceview_container.py
Normal file
@ -0,0 +1,46 @@
|
||||
# Python imports
|
||||
|
||||
# Lib imports
|
||||
import gi
|
||||
gi.require_version('Gtk', '3.0')
|
||||
from gi.repository import Gtk
|
||||
|
||||
# Application imports
|
||||
from ..tab_header_widget import TabHeaderWidget
|
||||
from .source_view import SourceView
|
||||
|
||||
|
||||
|
||||
class SourceViewContainer(Gtk.ScrolledWindow):
|
||||
def __init__(self, close_tab):
|
||||
super(SourceViewContainer, self).__init__()
|
||||
|
||||
self._close_tab = close_tab
|
||||
self._source_view = None
|
||||
self._tab_widget = None
|
||||
|
||||
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):
|
||||
...
|
||||
|
||||
def _load_widgets(self):
|
||||
self._source_view = SourceView()
|
||||
self._tab_widget = TabHeaderWidget(self, self._source_view, self._close_tab)
|
||||
self.add(self._source_view)
|
||||
|
||||
def get_tab_widget(self):
|
||||
return self._tab_widget
|
||||
|
||||
def get_source_view(self):
|
||||
return self._source_view
|
@ -32,4 +32,4 @@ class ScaleDownButton(Gtk.Button):
|
||||
...
|
||||
|
||||
def _emit_scale_eve(self, widget, eve = None):
|
||||
event_system.emit('scale_down_text')
|
||||
event_system.emit('scale_down_text', ("scale_down_text",))
|
||||
|
@ -32,4 +32,4 @@ class ScaleUpButton(Gtk.Button):
|
||||
...
|
||||
|
||||
def _emit_scale_eve(self, widget, eve = None):
|
||||
event_system.emit('scale_up_text')
|
||||
event_system.emit('scale_up_text', ("scale_up_text",))
|
||||
|
78
src/core/widgets/controls/theme_button.py
Normal file
78
src/core/widgets/controls/theme_button.py
Normal file
@ -0,0 +1,78 @@
|
||||
# Python imports
|
||||
|
||||
# Lib imports
|
||||
import gi
|
||||
gi.require_version('Gtk', '3.0')
|
||||
gi.require_version('GtkSource', '4')
|
||||
from gi.repository import Gtk
|
||||
from gi.repository import GtkSource
|
||||
|
||||
# Application imports
|
||||
|
||||
|
||||
|
||||
class ThemePopover(Gtk.Popover):
|
||||
"""docstring for ThemePopover."""
|
||||
|
||||
def __init__(self):
|
||||
super(ThemePopover, self).__init__()
|
||||
|
||||
self._style_choser = None
|
||||
|
||||
self._setup_styling()
|
||||
self._setup_signals()
|
||||
self._load_widgets()
|
||||
|
||||
|
||||
def _setup_styling(self):
|
||||
self.set_modal(True)
|
||||
self.set_position(Gtk.PositionType.BOTTOM)
|
||||
self.set_size_request(320, 280)
|
||||
|
||||
def _setup_signals(self):
|
||||
event_system.subscribe("show_theme_popup", self._show_theme_popup)
|
||||
|
||||
def _load_widgets(self):
|
||||
self._style_choser = GtkSource.StyleSchemeChooserWidget()
|
||||
self._style_choser.show_all()
|
||||
self._style_choser.connect("button-release-event", self._set_theme)
|
||||
|
||||
self.add(self._style_choser)
|
||||
|
||||
|
||||
def _show_theme_popup(self, widget = None, eve = None):
|
||||
self.popup()
|
||||
|
||||
def _set_theme(self, widget = None, eve = None):
|
||||
style_scheme = widget.get_style_scheme()
|
||||
id = style_scheme.get_id()
|
||||
event_system.emit('set_buffer_style', ("set_buffer_style", id.lower(),))
|
||||
|
||||
|
||||
|
||||
class ThemeButton(Gtk.Button):
|
||||
def __init__(self):
|
||||
super(ThemeButton, self).__init__()
|
||||
|
||||
self._setup_styling()
|
||||
self._setup_signals()
|
||||
self._subscribe_to_events()
|
||||
self._load_widgets()
|
||||
|
||||
|
||||
def _setup_styling(self):
|
||||
self.set_label("Themes")
|
||||
|
||||
def _setup_signals(self):
|
||||
self.connect("clicked", self._show_popover)
|
||||
|
||||
def _subscribe_to_events(self):
|
||||
...
|
||||
|
||||
def _load_widgets(self):
|
||||
popover = ThemePopover()
|
||||
popover.set_relative_to(self)
|
||||
|
||||
|
||||
def _show_popover(self, widget, eve = None):
|
||||
event_system.emit("show_theme_popup")
|
@ -8,6 +8,7 @@ from gi.repository import Gtk
|
||||
# Application imports
|
||||
|
||||
|
||||
|
||||
class ToggleLineHighlight(Gtk.ToggleButton):
|
||||
def __init__(self):
|
||||
super(ToggleLineHighlight, self).__init__()
|
||||
@ -31,4 +32,4 @@ class ToggleLineHighlight(Gtk.ToggleButton):
|
||||
...
|
||||
|
||||
def _emit_toggle_eve(self, widget, eve = None):
|
||||
event_system.emit('toggle_highlight_line')
|
||||
event_system.emit('toggle_highlight_line', ("toggle_highlight_line",))
|
||||
|
BIN
user_config/usr/share/newton_editor/icons/brain.png
Normal file
BIN
user_config/usr/share/newton_editor/icons/brain.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 26 KiB |
Loading…
Reference in New Issue
Block a user