bec_widgets.widgets.editors.monaco.monaco_widget#

Attributes#

Classes#

MonacoWidget

A simple Monaco editor widget

Module Contents#

class MonacoWidget(parent=None, config=None, client=None, gui_id=None, init_lsp: bool = True, **kwargs)#

Bases: bec_widgets.utils.bec_widget.BECWidget, qtpy.QtWidgets.QWidget

A simple Monaco editor widget

Base class for all BEC widgets. This class should be used as a mixin class for all BEC widgets, e.g.:

>>> class MyWidget(BECWidget, QWidget):
>>>     def __init__(self, parent=None, client=None, config=None, gui_id=None):
>>>         super().__init__(parent=parent, client=client, config=config, gui_id=gui_id)
Parameters:
  • client (BECClient, optional) – The BEC client.

  • config (ConnectionConfig, optional) – The connection configuration.

  • gui_id (str, optional) – The GUI ID.

  • theme_update (bool, optional) – Whether to subscribe to theme updates. Defaults to False. When set to True, the widget’s apply_theme method will be called when the theme changes.

_check_save_status(_text: str) None#
_format_code()#

Format the current code in the editor.

_handle_context_menu_action(action_id: str)#

Handle context menu action triggers.

_run_dialog_and_insert_code(dialog: bec_widgets.widgets.editors.monaco.scan_control_dialog.ScanControlDialog)#

Run the dialog and insert the generated scan code if accepted. It is a separate method to allow easier testing.

Parameters:

dialog (ScanControlDialog) – The scan control dialog instance.

_setup_context_menu()#

Setup custom context menu actions for the Monaco editor.

_show_scan_control_dialog()#

Show the scan control dialog and insert the generated scan code.

apply_theme(theme: str | None = None) None#

Apply the current theme to the Monaco editor.

Parameters:

theme (str, optional) – The theme to apply. If None, the current theme will be used.

clear_highlighted_lines() None#

Clear any highlighted lines in the Monaco editor.

current_cursor() dict[str, int]#

Get the current cursor position in the Monaco editor.

Returns:

A dictionary with keys ‘line’ and ‘column’ representing the cursor position.

Return type:

dict[str, int]

delete_line(line: int | None = None) None#

Delete a line in the Monaco editor.

Parameters:

line (int, optional) – The line number (1-based) to delete. If None, the current line will be deleted.

format() None#

Format the current text in the Monaco editor.

get_language() str#

Get the current programming language set in the Monaco editor.

get_lsp_header() str#

Get the current LSP header set in the Monaco editor.

Returns:

The LSP header.

Return type:

str

get_text() str#

Get the current text from the Monaco editor.

get_theme() str#

Get the current theme of the Monaco editor.

insert_text(text: str, line: int | None = None, column: int | None = None) None#

Insert text at the current cursor position or at a specified line and column.

Parameters:
  • text (str) – The text to insert.

  • line (int, optional) – The line number (1-based) to insert the text at. Defaults to None.

  • column (int, optional) – The column number (1-based) to insert the text at. Defaults to None.

open_file(file_name: str) None#

Open a file in the editor.

Parameters:

file_name (str) – The path + file name of the file that needs to be displayed.

set_cursor(line: int, column: int = 1, move_to_position: Literal[None, 'center', 'top', 'position'] = None) None#

Set the cursor position in the Monaco editor.

Parameters:
  • line (int) – Line number (1-based).

  • column (int) – Column number (1-based), defaults to 1.

  • move_to_position (Literal[None, "center", "top", "position"], optional) – Position to move the cursor to.

set_highlighted_lines(start_line: int, end_line: int) None#

Highlight a range of lines in the Monaco editor.

Parameters:
  • start_line (int) – The starting line number (1-based).

  • end_line (int) – The ending line number (1-based).

set_language(language: str) None#

Set the programming language for syntax highlighting in the Monaco editor.

Parameters:

language (str) – The programming language to set (e.g., “python”, “javascript”).

set_lsp_header(header: str) None#

Set the LSP (Language Server Protocol) header for the Monaco editor. The header is used to provide context for language servers but is not displayed in the editor.

Parameters:

header (str) – The LSP header to set.

set_minimap_enabled(enabled: bool) None#

Enable or disable the minimap in the Monaco editor.

Parameters:

enabled (bool) – If True, the minimap will be enabled; otherwise, it will be disabled.

set_readonly(read_only: bool) None#

Set the Monaco editor to read-only mode.

Parameters:

read_only (bool) – If True, the editor will be read-only.

set_text(text: str, file_name: str | None = None, reset: bool = False) None#

Set the text in the Monaco editor.

Parameters:
  • text (str) – The text to set in the editor.

  • file_name (str) – Set the file name

  • reset (bool) – If True, reset the original content to the new text.

set_theme(theme: str) None#

Set the theme for the Monaco editor.

Parameters:

theme (str) – The theme to set (e.g., “vs-dark”, “light”).

set_vim_mode_enabled(enabled: bool) None#

Enable or disable Vim mode in the Monaco editor.

Parameters:

enabled (bool) – If True, Vim mode will be enabled; otherwise, it will be disabled.

ICON_NAME = 'code'#
PLUGIN = True#
USER_ACCESS = ['set_text', 'get_text', 'insert_text', 'delete_line', 'open_file', 'set_language',...#
property current_file#

Get the current file being edited.

editor#
metadata#
property modified: bool#

Check if the editor content has been modified.

save_enabled#
text_changed#
qapp#