Renamed widget; moved to use signals; fixed label update

This commit is contained in:
itdominator 2024-09-08 01:20:22 -05:00
parent ed63067bb8
commit 08a3623c9b
7 changed files with 36 additions and 116 deletions

View File

@ -6,7 +6,6 @@ gi.require_version('Gtk', '3.0')
from gi.repository import Gtk from gi.repository import Gtk
# Application imports # Application imports
from ..widgets.buttons.open_files_button import OpenFilesButton
from ..widgets.controls.transparency_scale import TransparencyScale from ..widgets.controls.transparency_scale import TransparencyScale
@ -38,7 +37,6 @@ class HeaderContainer(Gtk.Box):
button = Gtk.Button(label = "Interactive Debug") button = Gtk.Button(label = "Interactive Debug")
button.connect("clicked", self._interactive_debug) button.connect("clicked", self._interactive_debug)
self.add( OpenFilesButton() )
self.add( TransparencyScale() ) self.add( TransparencyScale() )
self.add(button) self.add(button)

View File

@ -35,7 +35,7 @@ class BottomButtonBox(Gtk.Box):
def _load_buttons(self): def _load_buttons(self):
self.initialize_btn = Gtk.Button(label = "Initialize Message") self.initialize_btn = Gtk.Button(label = "Initialize Message")
self.initialized_btn = Gtk.Button(label = "Initialized Message") self.initialized_btn = Gtk.Button(label = "Initialized Notification")
self.notification_btn = Gtk.Button(label = "Send Notification") self.notification_btn = Gtk.Button(label = "Send Notification")
self.request_btn = Gtk.Button(label = "Send Request") self.request_btn = Gtk.Button(label = "Send Request")
self.full_init_btn = Gtk.Button(label = "Full Init") self.full_init_btn = Gtk.Button(label = "Full Init")
@ -101,6 +101,9 @@ class BottomButtonBox(Gtk.Box):
self.rest_buttons() self.rest_buttons()
self.get_parent().start_stop_lsp() self.get_parent().start_stop_lsp()
if not hasattr(self.get_parent(), "lsp_process"):
self.rest_buttons()
return
def full_init(self, button, eve = None): def full_init(self, button, eve = None):
button.hide() button.hide()

View File

@ -1,86 +0,0 @@
# Python imports
import os
# Lib imports
import gi
gi.require_version('Gtk', '3.0')
gi.require_version('Gdk', '3.0')
from gi.repository import Gtk
from gi.repository import Gdk
from gi.repository import Gio
# Application imports
class OpenFilesButton(Gtk.Button):
"""docstring for OpenFilesButton."""
def __init__(self):
super(OpenFilesButton, self).__init__()
self._setup_styling()
self._setup_signals()
self._subscribe_to_events()
self._load_widgets()
def _setup_styling(self):
self.set_label("Open File(s)...")
self.set_image( Gtk.Image.new_from_icon_name("gtk-open", 4) )
self.set_always_show_image(True)
self.set_image_position(1) # Left - 0, Right = 1
self.set_hexpand(False)
def _setup_signals(self):
self.connect("button-release-event", self._open_files)
def _subscribe_to_events(self):
event_system.subscribe("open_files", self._open_files)
def _load_widgets(self):
...
def _open_files(self, widget = None, eve = None, gfile = None):
start_dir = None
_gfiles = []
if gfile and gfile.query_exists():
start_dir = gfile.get_parent()
chooser = Gtk.FileChooserDialog("Open File(s)...", None,
Gtk.FileChooserAction.OPEN,
(
Gtk.STOCK_CANCEL,
Gtk.ResponseType.CANCEL,
Gtk.STOCK_OPEN,
Gtk.ResponseType.OK
)
)
chooser.set_select_multiple(True)
try:
folder = widget.get_current_file().get_parent() if not start_dir else start_dir
chooser.set_current_folder( folder.get_path() )
except Exception as e:
...
response = chooser.run()
if not response == Gtk.ResponseType.OK:
chooser.destroy()
return _gfiles
filenames = chooser.get_filenames()
if not filenames:
chooser.destroy()
return _gfiles
for file in filenames:
path = file if os.path.isabs(file) else os.path.abspath(file)
_gfiles.append( Gio.File.new_for_path(path) )
chooser.destroy()
logger.debug(_gfiles)
return _gfiles

View File

@ -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 .folder_choser_button import FolderChoserButton from .workspace_folder_choser_button import WorkspaceFolderChoserButton
@ -32,17 +32,17 @@ class TopButtonBox(Gtk.ButtonBox):
... ...
def _subscribe_to_events(self): def _subscribe_to_events(self):
... event_system.subscribe("update-message-id-lbl", self.update_message_id_lbl)
def _load_widgets(self): def _load_widgets(self):
box = Gtk.Box() box = Gtk.Box()
self.message_id_lbl = Gtk.Label(label = "Message ID: 0") self.message_id_lbl = Gtk.Label(label = "Message ID: 0")
self.folder_choser_lbl = Gtk.Label(label = "Workspace Folder: ") self.folder_choser_lbl = Gtk.Label(label = "Workspace Folder: ")
self.folder_choser_btn = FolderChoserButton() self.workspace_choser_btn = WorkspaceFolderChoserButton()
self.add(self.message_id_lbl) self.add(self.message_id_lbl)
box.add(self.folder_choser_lbl) box.add(self.folder_choser_lbl)
box.add(self.folder_choser_btn) box.add(self.workspace_choser_btn)
self.add(box) self.add(box)
def update_message_id_lbl(self, id: int): def update_message_id_lbl(self, id: int):

View File

@ -9,9 +9,9 @@ from gi.repository import Gtk
class FolderChoserButton(Gtk.FileChooserButton): class WorkspaceFolderChoserButton(Gtk.FileChooserButton):
def __init__(self): def __init__(self):
super(FolderChoserButton, self).__init__() super(WorkspaceFolderChoserButton, self).__init__()
self._setup_styling() self._setup_styling()
self._setup_signals() self._setup_signals()
@ -34,7 +34,14 @@ class FolderChoserButton(Gtk.FileChooserButton):
... ...
def _subscribe_to_events(self): def _subscribe_to_events(self):
... event_system.subscribe("get-workspace-path", self.get_workspace_path)
event_system.subscribe("get-workspace-uri", self.get_workspace_uri)
def _load_widgets(self): def _load_widgets(self):
... ...
def get_workspace_path(self):
return self.get_file().get_path()
def get_workspace_uri(self):
return self.get_uri()

View File

@ -71,6 +71,7 @@ class LogList(Gtk.ListBox):
frame.show_all() frame.show_all()
logger.debug(f"{lbl_str}:\n{message}")
del message del message
del lbl_str del lbl_str

View File

@ -66,26 +66,24 @@ class LSPMessageBox(Gtk.Box):
def _load_widgets(self): def _load_widgets(self):
scrolled_win = Gtk.ScrolledWindow() scrolled_win = Gtk.ScrolledWindow()
self.lsp_msg_src_vw = LspMessageSourceView() self.lsp_msg_src_vw = LspMessageSourceView()
self.top_buttons = TopButtonBox() top_buttons = TopButtonBox()
self.bottom_buttons = BottomButtonBox() bottom_buttons = BottomButtonBox()
scrolled_win.show_all() scrolled_win.show_all()
scrolled_win.add(self.lsp_msg_src_vw) scrolled_win.add(self.lsp_msg_src_vw)
self.add(self.top_buttons) self.add(top_buttons)
self.add(scrolled_win) self.add(scrolled_win)
self.add(self.bottom_buttons) self.add(bottom_buttons)
def update_message_id_label(self): def update_message_id_label(self):
self.top_buttons.update_message_id_lbl(self._message_id) event_system.emit("update-message-id-lbl", (self._message_id,))
def send_initialize_message(self): def send_initialize_message(self):
parent = self.get_parent() parent = self.get_parent()
folder_choser_btn = self.top_buttons.folder_choser_btn
init_ops = parent.init_ops_src_vw.get_text_str() init_ops = parent.init_ops_src_vw.get_text_str()
workspace_file = folder_choser_btn.get_file().get_path() workspace_file = event_system.emit_and_await("get-workspace-path")
workspace_uri = folder_choser_btn.get_uri() workspace_uri = event_system.emit_and_await("get-workspace-uri")
folder_name = os.path.basename(workspace_file) folder_name = os.path.basename(workspace_file)
self._lsp_init_ops["processId"] = settings_manager.get_app_pid() self._lsp_init_ops["processId"] = settings_manager.get_app_pid()
@ -115,9 +113,10 @@ class LSPMessageBox(Gtk.Box):
def send_request(self, method: str, params: {} = {}): def send_request(self, method: str, params: {} = {}):
self._monitor_lsp_response() self._monitor_lsp_response()
self._send_message( LSPRequest(self._message_id, method, params) )
self._message_id += 1 self._message_id += 1
self._send_message( LSPRequest(self._message_id, method, params) ) self.update_message_id_label()
def _send_message(self, data: LSPRequest or LSPNotification): def _send_message(self, data: LSPRequest or LSPNotification):
if not data or not hasattr(self, "lsp_process"): return if not data or not hasattr(self, "lsp_process"): return
@ -132,8 +131,6 @@ 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()
self.update_message_id_label()
del message_str del message_str
del message_size del message_size
del message del message
@ -170,7 +167,6 @@ class LSPMessageBox(Gtk.Box):
stdin = subprocess.PIPE stdin = subprocess.PIPE
) )
except Exception as e: except Exception as e:
self.bottom_buttons.rest_buttons()
self.get_parent().log_list.add_log_entry( self.get_parent().log_list.add_log_entry(
"LSP Client Error", "LSP Client Error",
LSPResponse( LSPResponse(
@ -180,6 +176,7 @@ class LSPMessageBox(Gtk.Box):
} }
) )
) )
return return
return self.lsp_process.pid return self.lsp_process.pid
@ -259,7 +256,7 @@ class LSPMessageBox(Gtk.Box):
if isinstance(result, dict): if isinstance(result, dict):
keys = result.keys() keys = result.keys()
if "capabilities" in keys: if "capabilities" in keys:
logger.debug(f"LSP Capabilities Response:\n{result}") ...
if isinstance(result, list): if isinstance(result, list):
... ...