generated from itdominator/Python-With-Gtk-Template
Initial refactor
This commit is contained in:
parent
cfa718df88
commit
cdd09df5d7
|
@ -6,7 +6,7 @@ gi.require_version('Gtk', '3.0')
|
||||||
from gi.repository import Gtk
|
from gi.repository import Gtk
|
||||||
|
|
||||||
# Application imports
|
# Application imports
|
||||||
from ..widgets.controls.open_files_button import OpenFilesButton
|
from ..widgets.buttons.open_files_button import OpenFilesButton
|
||||||
from ..widgets.controls.transparency_scale import TransparencyScale
|
from ..widgets.controls.transparency_scale import TransparencyScale
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
"""
|
||||||
|
Buttons Module
|
||||||
|
"""
|
|
@ -0,0 +1,51 @@
|
||||||
|
# Python imports
|
||||||
|
|
||||||
|
# Lib imports
|
||||||
|
import gi
|
||||||
|
gi.require_version('Gtk', '3.0')
|
||||||
|
from gi.repository import Gtk
|
||||||
|
|
||||||
|
# Application imports
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class BottomButtonBox(Gtk.ButtonBox):
|
||||||
|
def __init__(self):
|
||||||
|
super(BottomButtonBox, self).__init__()
|
||||||
|
|
||||||
|
self._setup_styling()
|
||||||
|
self._setup_signals()
|
||||||
|
self._subscribe_to_events()
|
||||||
|
self._load_widgets()
|
||||||
|
|
||||||
|
self.show_all()
|
||||||
|
|
||||||
|
|
||||||
|
def _setup_styling(self):
|
||||||
|
ctx = self.get_style_context()
|
||||||
|
ctx.add_class("bottom-button-box")
|
||||||
|
|
||||||
|
def _setup_signals(self):
|
||||||
|
...
|
||||||
|
|
||||||
|
def _subscribe_to_events(self):
|
||||||
|
...
|
||||||
|
|
||||||
|
def _load_widgets(self):
|
||||||
|
self.initialize_btn = Gtk.Button(label = "Send Initialize Message")
|
||||||
|
self.notification_btn = Gtk.Button(label = "Send Notification")
|
||||||
|
self.message_btn = Gtk.Button(label = "Send Message")
|
||||||
|
self.start_stop_lsp_btn = Gtk.Button(label = "Start LSP")
|
||||||
|
|
||||||
|
self.add(self.initialize_btn)
|
||||||
|
self.add(self.notification_btn)
|
||||||
|
self.add(self.message_btn)
|
||||||
|
self.add(self.start_stop_lsp_btn)
|
||||||
|
|
||||||
|
def connect_widget_signals(self, parent):
|
||||||
|
if not parent: return
|
||||||
|
|
||||||
|
self.initialize_btn.connect("clicked", parent.send_initialize_message)
|
||||||
|
self.notification_btn.connect("clicked", parent.send_notification)
|
||||||
|
self.message_btn.connect("clicked", parent.send_message)
|
||||||
|
self.start_stop_lsp_btn.connect("clicked", parent.start_stop_lsp)
|
|
@ -0,0 +1,40 @@
|
||||||
|
# Python imports
|
||||||
|
|
||||||
|
# Lib imports
|
||||||
|
import gi
|
||||||
|
gi.require_version('Gtk', '3.0')
|
||||||
|
from gi.repository import Gtk
|
||||||
|
|
||||||
|
# Application imports
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class FolderChoserButton(Gtk.FileChooserButton):
|
||||||
|
def __init__(self):
|
||||||
|
super(FolderChoserButton, self).__init__()
|
||||||
|
|
||||||
|
self._setup_styling()
|
||||||
|
self._setup_signals()
|
||||||
|
self._subscribe_to_events()
|
||||||
|
self._load_widgets()
|
||||||
|
|
||||||
|
self.show_all()
|
||||||
|
|
||||||
|
|
||||||
|
def _setup_styling(self):
|
||||||
|
ctx = self.get_style_context()
|
||||||
|
ctx.add_class("folder-choser-button")
|
||||||
|
|
||||||
|
self.set_title("Chose Workspace")
|
||||||
|
self.set_action( Gtk.FileChooserAction.SELECT_FOLDER )
|
||||||
|
self.set_uri("file:///home/abaddon/Coding/Projects/Active/Python_Projects/testing/lsp_manager")
|
||||||
|
|
||||||
|
|
||||||
|
def _setup_signals(self):
|
||||||
|
...
|
||||||
|
|
||||||
|
def _subscribe_to_events(self):
|
||||||
|
...
|
||||||
|
|
||||||
|
def _load_widgets(self):
|
||||||
|
...
|
|
@ -0,0 +1,42 @@
|
||||||
|
# Python imports
|
||||||
|
|
||||||
|
# Lib imports
|
||||||
|
import gi
|
||||||
|
gi.require_version('Gtk', '3.0')
|
||||||
|
from gi.repository import Gtk
|
||||||
|
|
||||||
|
# Application imports
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class InfoLinkButton(Gtk.LinkButton):
|
||||||
|
def __init__(self, title: str = "[NO INFO TITLE PASSED]",
|
||||||
|
info_link: str or None = None):
|
||||||
|
super(InfoLinkButton, self).__init__()
|
||||||
|
|
||||||
|
info_link_title = f"{title} LSP Info" if info_link else "Generic LSP Info"
|
||||||
|
info_link = info_link if info_link else "https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#contentPart"
|
||||||
|
|
||||||
|
self.set_label(info_link_title)
|
||||||
|
self.set_uri(info_link)
|
||||||
|
|
||||||
|
self._setup_styling()
|
||||||
|
self._setup_signals()
|
||||||
|
self._subscribe_to_events()
|
||||||
|
self._load_widgets()
|
||||||
|
|
||||||
|
self.show_all()
|
||||||
|
|
||||||
|
|
||||||
|
def _setup_styling(self):
|
||||||
|
ctx = self.get_style_context()
|
||||||
|
ctx.add_class("info-link-button")
|
||||||
|
|
||||||
|
def _setup_signals(self):
|
||||||
|
...
|
||||||
|
|
||||||
|
def _subscribe_to_events(self):
|
||||||
|
...
|
||||||
|
|
||||||
|
def _load_widgets(self):
|
||||||
|
...
|
|
@ -0,0 +1,45 @@
|
||||||
|
# Python imports
|
||||||
|
|
||||||
|
# Lib imports
|
||||||
|
import gi
|
||||||
|
gi.require_version('Gtk', '3.0')
|
||||||
|
from gi.repository import Gtk
|
||||||
|
|
||||||
|
# Application imports
|
||||||
|
from .folder_choser_button import FolderChoserButton
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class TopButtonBox(Gtk.ButtonBox):
|
||||||
|
def __init__(self):
|
||||||
|
super(TopButtonBox, self).__init__()
|
||||||
|
|
||||||
|
self._setup_styling()
|
||||||
|
self._setup_signals()
|
||||||
|
self._subscribe_to_events()
|
||||||
|
self._load_widgets()
|
||||||
|
|
||||||
|
self.show_all()
|
||||||
|
|
||||||
|
|
||||||
|
def _setup_styling(self):
|
||||||
|
ctx = self.get_style_context()
|
||||||
|
ctx.add_class("top-button-box")
|
||||||
|
|
||||||
|
def _setup_signals(self):
|
||||||
|
...
|
||||||
|
|
||||||
|
def _subscribe_to_events(self):
|
||||||
|
...
|
||||||
|
|
||||||
|
def _load_widgets(self):
|
||||||
|
self.message_id_lbl = Gtk.Label(label = "Message ID: 0")
|
||||||
|
self.folder_choser_lbl = Gtk.Label(label = "Workspace Folder:")
|
||||||
|
self.folder_choser_btn = FolderChoserButton()
|
||||||
|
|
||||||
|
self.add(self.message_id_lbl)
|
||||||
|
self.add(self.folder_choser_lbl)
|
||||||
|
self.add(self.folder_choser_btn)
|
||||||
|
|
||||||
|
def update_message_id_lbl(self, id: int):
|
||||||
|
self.message_id_lbl.set_label(f"Message ID: {id}")
|
|
@ -0,0 +1,3 @@
|
||||||
|
"""
|
||||||
|
Enteries Module
|
||||||
|
"""
|
|
@ -0,0 +1,41 @@
|
||||||
|
# Python imports
|
||||||
|
|
||||||
|
# Lib imports
|
||||||
|
import gi
|
||||||
|
gi.require_version('Gtk', '3.0')
|
||||||
|
from gi.repository import Gtk
|
||||||
|
|
||||||
|
# Application imports
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class AltCommandEntry(Gtk.Entry):
|
||||||
|
def __init__(self, alt_command):
|
||||||
|
super(AltCommandEntry, self).__init__()
|
||||||
|
|
||||||
|
self.set_text(alt_command)
|
||||||
|
|
||||||
|
self._setup_styling()
|
||||||
|
self._setup_signals()
|
||||||
|
self._subscribe_to_events()
|
||||||
|
self._load_widgets()
|
||||||
|
|
||||||
|
self.show_all()
|
||||||
|
|
||||||
|
|
||||||
|
def _setup_styling(self):
|
||||||
|
ctx = self.get_style_context()
|
||||||
|
ctx.add_class("alt-command-entry")
|
||||||
|
|
||||||
|
self.set_hexpand(True)
|
||||||
|
self.set_placeholder_text("Alt Command:")
|
||||||
|
|
||||||
|
def _setup_signals(self):
|
||||||
|
...
|
||||||
|
|
||||||
|
def _subscribe_to_events(self):
|
||||||
|
...
|
||||||
|
|
||||||
|
def _load_widgets(self):
|
||||||
|
...
|
||||||
|
|
|
@ -0,0 +1,41 @@
|
||||||
|
# Python imports
|
||||||
|
|
||||||
|
# Lib imports
|
||||||
|
import gi
|
||||||
|
gi.require_version('Gtk', '3.0')
|
||||||
|
from gi.repository import Gtk
|
||||||
|
|
||||||
|
# Application imports
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class CommandEntry(Gtk.Entry):
|
||||||
|
def __init__(self, command):
|
||||||
|
super(CommandEntry, self).__init__()
|
||||||
|
|
||||||
|
self.set_text(command)
|
||||||
|
|
||||||
|
self._setup_styling()
|
||||||
|
self._setup_signals()
|
||||||
|
self._subscribe_to_events()
|
||||||
|
self._load_widgets()
|
||||||
|
|
||||||
|
self.show_all()
|
||||||
|
|
||||||
|
|
||||||
|
def _setup_styling(self):
|
||||||
|
ctx = self.get_style_context()
|
||||||
|
ctx.add_class("command-entry")
|
||||||
|
|
||||||
|
self.set_hexpand(True)
|
||||||
|
self.set_placeholder_text("Command:")
|
||||||
|
|
||||||
|
def _setup_signals(self):
|
||||||
|
...
|
||||||
|
|
||||||
|
def _subscribe_to_events(self):
|
||||||
|
...
|
||||||
|
|
||||||
|
def _load_widgets(self):
|
||||||
|
...
|
||||||
|
|
|
@ -0,0 +1,60 @@
|
||||||
|
# Python imports
|
||||||
|
import json
|
||||||
|
|
||||||
|
# Lib imports
|
||||||
|
import gi
|
||||||
|
gi.require_version('GtkSource', '4')
|
||||||
|
from gi.repository import GtkSource
|
||||||
|
|
||||||
|
# Application imports
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class InitOptionsSourceView(GtkSource.View):
|
||||||
|
def __init__(self, init_ops_data):
|
||||||
|
super(InitOptionsSourceView, self).__init__()
|
||||||
|
|
||||||
|
init_ops_txt = json.dumps( init_ops_data, separators=(',', ':'), indent=4 )
|
||||||
|
self.init_ops_txt = init_ops_txt if not init_ops_txt in ["", "{}"] else "{\n \n}"
|
||||||
|
|
||||||
|
self._setup_styling()
|
||||||
|
self._setup_signals()
|
||||||
|
self._subscribe_to_events()
|
||||||
|
self._load_widgets()
|
||||||
|
|
||||||
|
self.show_all()
|
||||||
|
|
||||||
|
|
||||||
|
def _setup_styling(self):
|
||||||
|
language_manager = GtkSource.LanguageManager()
|
||||||
|
style_scheme_manager = GtkSource.StyleSchemeManager()
|
||||||
|
style_scheme = style_scheme_manager.get_scheme("peacocks-in-space")
|
||||||
|
style_scheme = style_scheme if style_scheme else style_scheme_manager.get_scheme("solarized-dark")
|
||||||
|
buffer = self.get_buffer()
|
||||||
|
ctx = self.get_style_context()
|
||||||
|
|
||||||
|
self.set_vexpand(True)
|
||||||
|
self.set_hexpand(True)
|
||||||
|
self.set_indent_width(4)
|
||||||
|
self.set_tab_width(4)
|
||||||
|
self.set_insert_spaces_instead_of_tabs(True)
|
||||||
|
|
||||||
|
ctx.add_class("init-options-source-view")
|
||||||
|
|
||||||
|
buffer.set_language( language_manager.get_language("json") )
|
||||||
|
buffer.set_style_scheme(style_scheme)
|
||||||
|
buffer.set_text(self.init_ops_txt)
|
||||||
|
|
||||||
|
def _setup_signals(self):
|
||||||
|
...
|
||||||
|
|
||||||
|
def _subscribe_to_events(self):
|
||||||
|
...
|
||||||
|
|
||||||
|
def _load_widgets(self):
|
||||||
|
...
|
||||||
|
|
||||||
|
def get_text_str(self) -> str:
|
||||||
|
buffer = self.get_buffer()
|
||||||
|
start, end = buffer.get_bounds()
|
||||||
|
return buffer.get_text(start, end, True)
|
|
@ -0,0 +1,115 @@
|
||||||
|
# Python imports
|
||||||
|
|
||||||
|
# Lib imports
|
||||||
|
import gi
|
||||||
|
gi.require_version('GtkSource', '4')
|
||||||
|
from gi.repository import GtkSource
|
||||||
|
|
||||||
|
# Application imports
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Request type formatting
|
||||||
|
# https://github.com/microsoft/multilspy/blob/main/src/multilspy/language_server.py#L417
|
||||||
|
|
||||||
|
content_part = """{
|
||||||
|
"method": "textDocument/definition",
|
||||||
|
"params": {
|
||||||
|
"textDocument": {
|
||||||
|
"uri": "file:///home/abaddon/Coding/Projects/Active/Python_Projects/000_Usable/gtk/LSP-Manager/src/core/widgets/lsp_message_box.py",
|
||||||
|
"languageId": "python3",
|
||||||
|
"version": 1,
|
||||||
|
"text": ""
|
||||||
|
},
|
||||||
|
"position": {
|
||||||
|
"line": 5,
|
||||||
|
"character": 12,
|
||||||
|
"offset": 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
|
||||||
|
references_query = """{
|
||||||
|
|
||||||
|
"method": "textDocument/references",
|
||||||
|
"params": {
|
||||||
|
"context": {
|
||||||
|
"includeDeclaration": false
|
||||||
|
},
|
||||||
|
"textDocument": {
|
||||||
|
"uri": "file:///home/abaddon/Coding/Projects/Active/Python_Projects/000_Usable/gtk/LSP-Manager/src/core/widgets/lsp_message_box.py",
|
||||||
|
"languageId": "python3",
|
||||||
|
"version": 1,
|
||||||
|
"text": ""
|
||||||
|
},
|
||||||
|
"position": {
|
||||||
|
"line": 30,
|
||||||
|
"character": 13,
|
||||||
|
"offset": 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
|
||||||
|
symbols_query = """{
|
||||||
|
"method": "textDocument/documentSymbol",
|
||||||
|
"params": {
|
||||||
|
"textDocument": {
|
||||||
|
"uri": "file:///home/abaddon/Coding/Projects/Active/Python_Projects/000_Usable/gtk/LSP-Manager/src/core/widgets/lsp_message_box.py",
|
||||||
|
"languageId": "python3",
|
||||||
|
"version": 1,
|
||||||
|
"text": ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class LspMessageSourceView(GtkSource.View):
|
||||||
|
def __init__(self):
|
||||||
|
super(LspMessageSourceView, self).__init__()
|
||||||
|
|
||||||
|
self._setup_styling()
|
||||||
|
self._setup_signals()
|
||||||
|
self._subscribe_to_events()
|
||||||
|
self._load_widgets()
|
||||||
|
|
||||||
|
self.show_all()
|
||||||
|
|
||||||
|
|
||||||
|
def _setup_styling(self):
|
||||||
|
language_manager = GtkSource.LanguageManager()
|
||||||
|
style_scheme_manager = GtkSource.StyleSchemeManager()
|
||||||
|
style_scheme = style_scheme_manager.get_scheme("peacocks-in-space")
|
||||||
|
style_scheme = style_scheme if style_scheme else style_scheme_manager.get_scheme("solarized-dark")
|
||||||
|
buffer = self.get_buffer()
|
||||||
|
ctx = self.get_style_context()
|
||||||
|
|
||||||
|
self.set_vexpand(True)
|
||||||
|
self.set_hexpand(True)
|
||||||
|
self.set_indent_width(4)
|
||||||
|
self.set_tab_width(4)
|
||||||
|
self.set_insert_spaces_instead_of_tabs(True)
|
||||||
|
|
||||||
|
ctx.add_class("lsp-message-source-view")
|
||||||
|
|
||||||
|
buffer.set_language( language_manager.get_language("json") )
|
||||||
|
buffer.set_style_scheme(style_scheme)
|
||||||
|
buffer.set_text(content_part)
|
||||||
|
|
||||||
|
|
||||||
|
def _setup_signals(self):
|
||||||
|
...
|
||||||
|
|
||||||
|
def _subscribe_to_events(self):
|
||||||
|
...
|
||||||
|
|
||||||
|
def _load_widgets(self):
|
||||||
|
...
|
||||||
|
|
||||||
|
def get_text_str(self) -> str:
|
||||||
|
buffer = self.get_buffer()
|
||||||
|
start, end = buffer.get_bounds()
|
||||||
|
return buffer.get_text(start, end, True)
|
|
@ -0,0 +1,41 @@
|
||||||
|
# Python imports
|
||||||
|
|
||||||
|
# Lib imports
|
||||||
|
import gi
|
||||||
|
gi.require_version('Gtk', '3.0')
|
||||||
|
from gi.repository import Gtk
|
||||||
|
|
||||||
|
# Application imports
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class SocketEntry(Gtk.Entry):
|
||||||
|
def __init__(self, socket_command):
|
||||||
|
super(SocketEntry, self).__init__()
|
||||||
|
|
||||||
|
self.set_text(socket_command)
|
||||||
|
|
||||||
|
self._setup_styling()
|
||||||
|
self._setup_signals()
|
||||||
|
self._subscribe_to_events()
|
||||||
|
self._load_widgets()
|
||||||
|
|
||||||
|
self.show_all()
|
||||||
|
|
||||||
|
|
||||||
|
def _setup_styling(self):
|
||||||
|
ctx = self.get_style_context()
|
||||||
|
ctx.add_class("socket-entry")
|
||||||
|
|
||||||
|
self.set_hexpand(True)
|
||||||
|
self.set_placeholder_text("Socket:")
|
||||||
|
|
||||||
|
def _setup_signals(self):
|
||||||
|
...
|
||||||
|
|
||||||
|
def _subscribe_to_events(self):
|
||||||
|
...
|
||||||
|
|
||||||
|
def _load_widgets(self):
|
||||||
|
...
|
||||||
|
|
|
@ -14,65 +14,9 @@ from gi.repository import GLib
|
||||||
from gi.repository import GtkSource
|
from gi.repository import GtkSource
|
||||||
|
|
||||||
# Application imports
|
# Application imports
|
||||||
|
from .buttons.top_button_box import TopButtonBox
|
||||||
|
from .enteries.lsp_message_source_view import LspMessageSourceView
|
||||||
|
from .buttons.bottom_button_box import BottomButtonBox
|
||||||
# Request type formatting
|
|
||||||
# https://github.com/microsoft/multilspy/blob/main/src/multilspy/language_server.py#L417
|
|
||||||
|
|
||||||
content_part = """{
|
|
||||||
"method": "textDocument/definition",
|
|
||||||
"params": {
|
|
||||||
"textDocument": {
|
|
||||||
"uri": "file:///home/abaddon/Coding/Projects/Active/Python_Projects/000_Usable/gtk/LSP-Manager/src/core/widgets/lsp_message_box.py",
|
|
||||||
"languageId": "python3",
|
|
||||||
"version": 1,
|
|
||||||
"text": ""
|
|
||||||
},
|
|
||||||
"position": {
|
|
||||||
"line": 5,
|
|
||||||
"character": 12,
|
|
||||||
"offset": 0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
"""
|
|
||||||
|
|
||||||
references_query = """{
|
|
||||||
|
|
||||||
"method": "textDocument/references",
|
|
||||||
"params": {
|
|
||||||
"context": {
|
|
||||||
"includeDeclaration": false
|
|
||||||
},
|
|
||||||
"textDocument": {
|
|
||||||
"uri": "file:///home/abaddon/Coding/Projects/Active/Python_Projects/000_Usable/gtk/LSP-Manager/src/core/widgets/lsp_message_box.py",
|
|
||||||
"languageId": "python3",
|
|
||||||
"version": 1,
|
|
||||||
"text": ""
|
|
||||||
},
|
|
||||||
"position": {
|
|
||||||
"line": 43,
|
|
||||||
"character": 13,
|
|
||||||
"offset": 0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
"""
|
|
||||||
|
|
||||||
symbols_query = """{
|
|
||||||
"method": "textDocument/documentSymbol",
|
|
||||||
"params": {
|
|
||||||
"textDocument": {
|
|
||||||
"uri": "file:///home/abaddon/Coding/Projects/Active/Python_Projects/000_Usable/gtk/LSP-Manager/src/core/widgets/lsp_message_box.py",
|
|
||||||
"languageId": "python3",
|
|
||||||
"version": 1,
|
|
||||||
"text": ""
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
"""
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -118,77 +62,42 @@ class LSPMessageBox(Gtk.Box):
|
||||||
...
|
...
|
||||||
|
|
||||||
def _load_widgets(self):
|
def _load_widgets(self):
|
||||||
scrolled_win = Gtk.ScrolledWindow()
|
scrolled_win = Gtk.ScrolledWindow()
|
||||||
self.top_buttons = Gtk.ButtonBox()
|
self.lsp_msg_src_vw = LspMessageSourceView()
|
||||||
self.buttons = Gtk.ButtonBox()
|
self.top_buttons = TopButtonBox()
|
||||||
|
self.bottom_buttons = BottomButtonBox()
|
||||||
file_choser_lbl = Gtk.Label(label="Workspace Folder:")
|
|
||||||
self.file_choser_btn = Gtk.FileChooserButton()
|
|
||||||
|
|
||||||
initialize_btn = Gtk.Button(label="Send Initialize Message")
|
|
||||||
notification_btn = Gtk.Button(label="Send Notification Message")
|
|
||||||
message_btn = Gtk.Button(label="Send Message")
|
|
||||||
start_stop_lsp_btn = Gtk.Button(label="Start LSP")
|
|
||||||
|
|
||||||
source_view = GtkSource.View()
|
|
||||||
language_manager = GtkSource.LanguageManager()
|
|
||||||
style_scheme_manager = GtkSource.StyleSchemeManager()
|
|
||||||
style_scheme = style_scheme_manager.get_scheme("peacocks-in-space")
|
|
||||||
style_scheme = style_scheme if style_scheme else style_scheme_manager.get_scheme("solarized-dark")
|
|
||||||
self.buffer = source_view.get_buffer()
|
|
||||||
|
|
||||||
self.file_choser_btn.set_title("Chose Workspace")
|
|
||||||
self.file_choser_btn.set_action( Gtk.FileChooserAction.SELECT_FOLDER )
|
|
||||||
self.file_choser_btn.set_uri("file:///home/abaddon/Coding/Projects/Active/Python_Projects/testing/lsp_manager")
|
|
||||||
|
|
||||||
self.buffer.set_language( language_manager.get_language("json") )
|
|
||||||
self.buffer.set_style_scheme(style_scheme)
|
|
||||||
self.buffer.set_text(content_part)
|
|
||||||
|
|
||||||
source_view.set_indent_width(4)
|
|
||||||
source_view.set_tab_width(4)
|
|
||||||
source_view.set_insert_spaces_instead_of_tabs(True)
|
|
||||||
source_view.set_hexpand(True)
|
|
||||||
source_view.set_vexpand(True)
|
|
||||||
|
|
||||||
initialize_btn.connect("clicked", self.send_initialize_message)
|
|
||||||
notification_btn.connect("clicked", self.send_notification_message)
|
|
||||||
message_btn.connect("clicked", self.send_message_message)
|
|
||||||
start_stop_lsp_btn.connect("clicked", self.start_stop_lsp)
|
|
||||||
|
|
||||||
scrolled_win.add(source_view)
|
|
||||||
|
|
||||||
self.top_buttons.add(Gtk.Label(label=f"Message ID: {self._message_id}"))
|
|
||||||
self.top_buttons.add(file_choser_lbl)
|
|
||||||
self.top_buttons.add(self.file_choser_btn)
|
|
||||||
|
|
||||||
self.buttons.add(initialize_btn)
|
|
||||||
self.buttons.add(notification_btn)
|
|
||||||
self.buttons.add(message_btn)
|
|
||||||
self.buttons.add(start_stop_lsp_btn)
|
|
||||||
|
|
||||||
|
scrolled_win.add(self.lsp_msg_src_vw)
|
||||||
self.add(self.top_buttons)
|
self.add(self.top_buttons)
|
||||||
self.add(scrolled_win)
|
self.add(scrolled_win)
|
||||||
self.add(self.buttons)
|
self.add(self.bottom_buttons)
|
||||||
|
|
||||||
|
self.bottom_buttons.connect_widget_signals(self)
|
||||||
|
|
||||||
self._disable_buttons()
|
self._disable_buttons()
|
||||||
start_stop_lsp_btn.set_sensitive(True)
|
|
||||||
|
def _enable_buttons(self):
|
||||||
|
for button in self.bottom_buttons.get_children():
|
||||||
|
button.set_sensitive(True)
|
||||||
|
|
||||||
|
def _disable_buttons(self):
|
||||||
|
for button in self.bottom_buttons.get_children():
|
||||||
|
button.set_sensitive(False)
|
||||||
|
|
||||||
|
self.bottom_buttons.get_children()[-1].set_sensitive(True)
|
||||||
|
|
||||||
|
|
||||||
def update_message_id_label(self):
|
def update_message_id_label(self):
|
||||||
self.top_buttons.get_children()[0].set_label(f"Message ID: {self._message_id}")
|
self.top_buttons.update_message_id_lbl(self._message_id)
|
||||||
|
|
||||||
def post_int_run(self):
|
|
||||||
lsp_ui = self.get_parent()
|
|
||||||
self.alt_command_entry = lsp_ui.alt_command_entry
|
|
||||||
self.command_entry = lsp_ui.command_entry
|
|
||||||
self.socket_entry = lsp_ui.socket_entry
|
|
||||||
self.init_options_buffer = lsp_ui.init_options_text_vw.get_buffer()
|
|
||||||
del lsp_ui
|
|
||||||
|
|
||||||
def send_initialize_message(self, button, eve = None):
|
def send_initialize_message(self, button, eve = None):
|
||||||
workspace_file = self.file_choser_btn.get_file().get_path()
|
parent = self.get_parent()
|
||||||
workspace_uri = self.file_choser_btn.get_uri()
|
folder_choser_btn = self.top_buttons.folder_choser_btn
|
||||||
folder_name = os.path.basename(workspace_file)
|
|
||||||
|
init_ops = parent.init_ops_src_vw.get_text_str()
|
||||||
|
workspace_file = folder_choser_btn.get_file().get_path()
|
||||||
|
workspace_uri = folder_choser_btn.get_uri()
|
||||||
|
folder_name = os.path.basename(workspace_file)
|
||||||
|
|
||||||
self._lsp_init_data["processId"] = settings_manager.get_app_pid()
|
self._lsp_init_data["processId"] = settings_manager.get_app_pid()
|
||||||
self._lsp_init_data["rootPath"] = workspace_file
|
self._lsp_init_data["rootPath"] = workspace_file
|
||||||
|
@ -200,13 +109,17 @@ class LSPMessageBox(Gtk.Box):
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
start, end = self.init_options_buffer.get_bounds()
|
|
||||||
init_ops = self.init_options_buffer.get_text(start, end, True)
|
|
||||||
self._lsp_init_data["initializationOptions"] = json.loads(init_ops)
|
self._lsp_init_data["initializationOptions"] = json.loads(init_ops)
|
||||||
|
|
||||||
self.make_request("initialize", self._lsp_init_data)
|
self.make_request("initialize", self._lsp_init_data)
|
||||||
button.set_sensitive(False)
|
button.set_sensitive(False)
|
||||||
|
|
||||||
|
del init_ops
|
||||||
|
del workspace_file
|
||||||
|
del workspace_uri
|
||||||
|
del folder_name
|
||||||
|
del parent
|
||||||
|
|
||||||
def send_initialized_message(self):
|
def send_initialized_message(self):
|
||||||
self.make_request("initialized")
|
self.make_request("initialized")
|
||||||
|
|
||||||
|
@ -223,6 +136,11 @@ class LSPMessageBox(Gtk.Box):
|
||||||
self.lsp_process.stdin.write( message.encode("utf-8") )
|
self.lsp_process.stdin.write( message.encode("utf-8") )
|
||||||
self.lsp_process.stdin.flush()
|
self.lsp_process.stdin.flush()
|
||||||
|
|
||||||
|
del data
|
||||||
|
del message_str
|
||||||
|
del message_size
|
||||||
|
del message
|
||||||
|
|
||||||
def make_request(self, method: str, params: {} = {}):
|
def make_request(self, method: str, params: {} = {}):
|
||||||
self._monitor_lsp_response()
|
self._monitor_lsp_response()
|
||||||
|
|
||||||
|
@ -243,15 +161,16 @@ class LSPMessageBox(Gtk.Box):
|
||||||
self._message_id += 1
|
self._message_id += 1
|
||||||
self.update_message_id_label()
|
self.update_message_id_label()
|
||||||
|
|
||||||
|
del data
|
||||||
|
del message_str
|
||||||
|
del message_size
|
||||||
|
del message
|
||||||
|
|
||||||
def send_notification_message(self, button, eve = None):
|
def send_notification(self, button, eve = None):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def send_message_message(self, button, eve = None):
|
def send_message(self, button, eve = None):
|
||||||
start, end = self.buffer.get_bounds()
|
message = json.loads( self.lsp_msg_src_vw.get_text_str() )
|
||||||
data = self.buffer.get_text(start, end, True)
|
|
||||||
message = json.loads(data)
|
|
||||||
|
|
||||||
self.make_request(message["method"], message["params"])
|
self.make_request(message["method"], message["params"])
|
||||||
|
|
||||||
def start_stop_lsp(self, button, eve = None):
|
def start_stop_lsp(self, button, eve = None):
|
||||||
|
@ -267,12 +186,12 @@ class LSPMessageBox(Gtk.Box):
|
||||||
button.set_label("Start LSP")
|
button.set_label("Start LSP")
|
||||||
self.stop_lsp()
|
self.stop_lsp()
|
||||||
self._disable_buttons()
|
self._disable_buttons()
|
||||||
button.set_sensitive(True)
|
|
||||||
|
|
||||||
def start_lsp(self):
|
def start_lsp(self):
|
||||||
_command: str = self.alt_command_entry.get_text()
|
parent = self.get_parent()
|
||||||
# _command: str = self.command_entry.get_text()
|
_command: str = parent.alt_command_entry.get_text()
|
||||||
# _command: str = self.socket_entry.get_text()
|
# _command: str = parent.command_entry.get_text()
|
||||||
|
# _command: str = parent.socket_entry.get_text()
|
||||||
command: [] = _command.split() if len( _command.split() ) > 0 else [ _command ]
|
command: [] = _command.split() if len( _command.split() ) > 0 else [ _command ]
|
||||||
self.lsp_process = subprocess.Popen(
|
self.lsp_process = subprocess.Popen(
|
||||||
command,
|
command,
|
||||||
|
@ -369,12 +288,3 @@ class LSPMessageBox(Gtk.Box):
|
||||||
print(lsp_result)
|
print(lsp_result)
|
||||||
print()
|
print()
|
||||||
print()
|
print()
|
||||||
|
|
||||||
def _enable_buttons(self):
|
|
||||||
for button in self.buttons.get_children():
|
|
||||||
button.set_sensitive(True)
|
|
||||||
|
|
||||||
def _disable_buttons(self):
|
|
||||||
for button in self.buttons.get_children():
|
|
||||||
button.set_sensitive(False)
|
|
||||||
|
|
|
@ -1,15 +1,17 @@
|
||||||
# Python imports
|
# Python imports
|
||||||
import json
|
|
||||||
|
|
||||||
# Lib imports
|
# Lib imports
|
||||||
import gi
|
import gi
|
||||||
gi.require_version('Gtk', '3.0')
|
gi.require_version('Gtk', '3.0')
|
||||||
gi.require_version('GtkSource', '4')
|
|
||||||
from gi.repository import Gtk
|
from gi.repository import Gtk
|
||||||
from gi.repository import GtkSource
|
|
||||||
|
|
||||||
# Application imports
|
# Application imports
|
||||||
from .lsp_message_box import LSPMessageBox
|
from .lsp_message_box import LSPMessageBox
|
||||||
|
from .enteries.alt_command_entry import AltCommandEntry
|
||||||
|
from .enteries.command_entry import CommandEntry
|
||||||
|
from .enteries.socket_entry import SocketEntry
|
||||||
|
from .enteries.init_options_source_view import InitOptionsSourceView
|
||||||
|
from .buttons.info_link_button import InfoLinkButton
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -17,23 +19,14 @@ class LSPUI(Gtk.Grid):
|
||||||
def __init__(self, language, data):
|
def __init__(self, language, data):
|
||||||
super(LSPUI, self).__init__()
|
super(LSPUI, self).__init__()
|
||||||
|
|
||||||
self._data = data
|
self._data = data
|
||||||
self._language = language
|
self._language = language
|
||||||
self._no_init_ops_text = "{\n \n}"
|
|
||||||
|
|
||||||
self.alt_command_entry = Gtk.Entry()
|
|
||||||
self.command_entry = Gtk.Entry()
|
|
||||||
self.socket_entry = Gtk.Entry()
|
|
||||||
self.init_options_text_vw = GtkSource.View()
|
|
||||||
self.message_box = LSPMessageBox()
|
|
||||||
|
|
||||||
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.message_box.post_int_run()
|
|
||||||
|
|
||||||
self.show_all()
|
self.show_all()
|
||||||
|
|
||||||
|
|
||||||
|
@ -48,16 +41,6 @@ class LSPUI(Gtk.Grid):
|
||||||
self.set_margin_left(10)
|
self.set_margin_left(10)
|
||||||
self.set_margin_right(10)
|
self.set_margin_right(10)
|
||||||
|
|
||||||
self.alt_command_entry.set_hexpand(True)
|
|
||||||
self.command_entry.set_hexpand(True)
|
|
||||||
self.socket_entry.set_hexpand(True)
|
|
||||||
self.init_options_text_vw.set_vexpand(True)
|
|
||||||
self.init_options_text_vw.set_hexpand(True)
|
|
||||||
|
|
||||||
self.alt_command_entry.set_placeholder_text("Alt Command:")
|
|
||||||
self.command_entry.set_placeholder_text("Command:")
|
|
||||||
self.socket_entry.set_placeholder_text("Socket")
|
|
||||||
|
|
||||||
def _setup_signals(self):
|
def _setup_signals(self):
|
||||||
...
|
...
|
||||||
|
|
||||||
|
@ -65,48 +48,27 @@ class LSPUI(Gtk.Grid):
|
||||||
...
|
...
|
||||||
|
|
||||||
def _load_widgets(self):
|
def _load_widgets(self):
|
||||||
_language_manager = GtkSource.LanguageManager()
|
scrolled_win = Gtk.ScrolledWindow()
|
||||||
_style_scheme_manager = GtkSource.StyleSchemeManager()
|
alt_command_lbl = Gtk.Label(label="Alt Command:")
|
||||||
style_scheme = _style_scheme_manager.get_scheme("peacocks-in-space")
|
command_lbl = Gtk.Label(label="Command:")
|
||||||
style_scheme = style_scheme if style_scheme else _style_scheme_manager.get_scheme("solarized-dark")
|
socket_lbl = Gtk.Label(label="Socket:")
|
||||||
buffer = self.init_options_text_vw.get_buffer()
|
init_options_lbl = Gtk.Label(label="Initialization Options:")
|
||||||
scrolled_win1 = Gtk.ScrolledWindow()
|
message_box_lbl = Gtk.Label(label="Message Box:")
|
||||||
|
|
||||||
buffer.set_language( _language_manager.get_language("json") )
|
self.link_btn = InfoLinkButton(self._language.title(), self._data["info"])
|
||||||
buffer.set_style_scheme(style_scheme)
|
self.alt_command_entry = AltCommandEntry( self._data["alt-command"] )
|
||||||
|
self.command_entry = CommandEntry( self._data["command"] )
|
||||||
|
self.socket_entry = SocketEntry( self._data["socket"] )
|
||||||
|
self.init_ops_src_vw = InitOptionsSourceView( self._data["initialization-options"] )
|
||||||
|
self.message_box = LSPMessageBox()
|
||||||
|
|
||||||
info_link = self._data["info"]
|
|
||||||
info_link_title = self._language.title() + " LSP Info" if info_link else "Generic LSP Info"
|
|
||||||
info_link = info_link if info_link else "https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#contentPart"
|
|
||||||
link_btn = Gtk.LinkButton(info_link)
|
|
||||||
|
|
||||||
alt_command_lbl = Gtk.Label(label="Alt Command:")
|
|
||||||
command_lbl = Gtk.Label(label="Command:")
|
|
||||||
socket_lbl = Gtk.Label(label="Socket:")
|
|
||||||
init_options_lbl = Gtk.Label(label="Initialization Options:")
|
|
||||||
message_box_lbl = Gtk.Label(label="Message Box:")
|
|
||||||
|
|
||||||
self.alt_command_entry.set_text(self._data["alt-command"])
|
|
||||||
self.command_entry.set_text(self._data["command"])
|
|
||||||
self.socket_entry.set_text(self._data["socket"])
|
|
||||||
|
|
||||||
init_ops_txt = json.dumps( self._data["initialization-options"], separators=(',', ':'), indent=4 )
|
|
||||||
init_ops_txt = init_ops_txt if not init_ops_txt in ["", "{}"] else self._no_init_ops_text
|
|
||||||
buffer.set_text(init_ops_txt)
|
|
||||||
|
|
||||||
link_btn.set_label(info_link_title)
|
|
||||||
init_options_lbl.set_margin_top(10)
|
init_options_lbl.set_margin_top(10)
|
||||||
message_box_lbl.set_margin_top(10)
|
message_box_lbl.set_margin_top(10)
|
||||||
self.init_options_text_vw.set_indent_width(4)
|
|
||||||
self.init_options_text_vw.set_tab_width(4)
|
|
||||||
self.init_options_text_vw.set_insert_spaces_instead_of_tabs(True)
|
|
||||||
self.init_options_text_vw.set_hexpand(True)
|
|
||||||
self.init_options_text_vw.set_vexpand(True)
|
|
||||||
|
|
||||||
scrolled_win1.add(self.init_options_text_vw)
|
scrolled_win.add(self.init_ops_src_vw)
|
||||||
|
|
||||||
# child, left, top, width, height
|
# child, left, top, width, height
|
||||||
self.attach(link_btn, 0, 0, 3, 1)
|
self.attach(self.link_btn, 0, 0, 3, 1)
|
||||||
|
|
||||||
self.attach(alt_command_lbl, 0, 1, 1, 1)
|
self.attach(alt_command_lbl, 0, 1, 1, 1)
|
||||||
self.attach(command_lbl, 0, 2, 1, 1)
|
self.attach(command_lbl, 0, 2, 1, 1)
|
||||||
|
@ -117,8 +79,7 @@ class LSPUI(Gtk.Grid):
|
||||||
self.attach(self.socket_entry, 1, 3, 2, 1)
|
self.attach(self.socket_entry, 1, 3, 2, 1)
|
||||||
|
|
||||||
self.attach(init_options_lbl, 0, 4, 3, 1)
|
self.attach(init_options_lbl, 0, 4, 3, 1)
|
||||||
self.attach(scrolled_win1, 0, 5, 3, 1)
|
self.attach(scrolled_win, 0, 5, 3, 1)
|
||||||
|
|
||||||
self.attach(message_box_lbl, 0, 6, 3, 1)
|
self.attach(message_box_lbl, 0, 6, 3, 1)
|
||||||
self.attach(self.message_box, 0, 7, 3, 1)
|
self.attach(self.message_box, 0, 7, 3, 1)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue