Python sublime.Window() Examples

The following are 30 code examples of sublime.Window(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module sublime , or try the search function .
Example #1
Source File: output_panel.py    From omnisharp-sublime with MIT License 6 votes vote down vote up
def __init__(self, window, panel_name, file_regex=None,
                 line_regex=None, path=None, read_only=True,
                 auto_show=True):
        if not isinstance(window, Window):
            raise ValueError("window parameter is invalid")
        if not isinstance(panel_name, basestring):
            raise ValueError("panel_name must be a string")

        self.window = window
        self.panel_name = panel_name
        self.view = window.get_output_panel(panel_name)
        self.view.set_read_only(read_only)
        self.settings = ViewSettings(self.view)

        self.set_path(path, file_regex, line_regex)

        self.auto_show = auto_show 
Example #2
Source File: registry.py    From LSP with MIT License 6 votes vote down vote up
def _sessions_for_view_and_window(view: sublime.View, window: Optional[sublime.Window],
                                  point: Optional[int] = None) -> Iterable[Session]:
    if not window:
        debug("no window for view", view.file_name())
        return []

    file_path = view.file_name()
    if not file_path:
        # debug("no session for unsaved file")
        return []

    manager = windows.lookup(window)
    scope_configs = manager._configs.scope_configs(view, point)
    sessions = (manager.get_session(config.name, file_path) for config in scope_configs)
    ready_sessions = (session for session in sessions if session and session.state == ClientStates.READY)
    return ready_sessions 
Example #3
Source File: clients.py    From LSP with MIT License 6 votes vote down vote up
def get_window_env(window: sublime.Window, config: ClientConfig) -> Tuple[List[str], Dict[str, str]]:

    # Create a dictionary of Sublime Text variables
    variables = window.extract_variables()

    # Expand language server command line environment variables
    expanded_args = list(
        sublime.expand_variables(os.path.expanduser(arg), variables)
        for arg in config.binary_args
    )

    # Override OS environment variables
    env = os.environ.copy()
    for var, value in config.env.items():
        # Expand both ST and OS environment variables
        env[var] = os.path.expandvars(sublime.expand_variables(value, variables))

    return expanded_args, env 
Example #4
Source File: debugger.py    From sublime_debugger with MIT License 6 votes vote down vote up
def for_window(window: sublime.Window, create: bool = False) -> 'Optional[Debugger]':
		global instances
		id = window.id()
		instance = Debugger.instances.get(id)

		if not instance and create:
			if Debugger.creating.get(id):
				raise core.Error("We shouldn't be creating another debugger instance for this window...")

			Debugger.creating[id] = True
			try:
				instance = Debugger(window)
				Debugger.instances[id] = instance

			except dap.Error as e:
				core.log_exception()

			Debugger.creating[id] = False

		if instance and create:
			instance.show()

		return instance 
Example #5
Source File: clients.py    From LSP with MIT License 6 votes vote down vote up
def start_window_config(window: sublime.Window,
                        workspace_folders: List[WorkspaceFolder],
                        config: ClientConfig,
                        on_pre_initialize: Callable[[Session], None],
                        on_post_initialize: Callable[[Session], None],
                        on_post_exit: Callable[[str], None],
                        on_stderr_log: Optional[Callable[[str], None]]) -> Optional[Session]:
    args, env = get_window_env(window, config)
    config.binary_args = args
    return create_session(config=config,
                          workspace_folders=workspace_folders,
                          env=env,
                          settings=settings,
                          on_pre_initialize=on_pre_initialize,
                          on_post_initialize=on_post_initialize,
                          on_post_exit=lambda config_name: on_session_ended(window, config_name, on_post_exit),
                          on_stderr_log=on_stderr_log) 
Example #6
Source File: status.py    From GitSavvy with MIT License 6 votes vote down vote up
def load_inline_diff_views(self, window, non_cached_files, cached_files):
        # type: (sublime.Window, List[str], List[str]) -> None
        for fpath in non_cached_files:
            syntax = util.file.guess_syntax_for_file(window, fpath)
            settings = {
                "file_path": fpath,
                "repo_path": self.repo_path,
                "syntax": syntax
            }
            window.run_command("gs_inline_diff", {
                "settings": settings,
                "cached": False
            })

        for fpath in cached_files:
            syntax = util.file.guess_syntax_for_file(window, fpath)
            settings = {
                "file_path": fpath,
                "repo_path": self.repo_path,
                "syntax": syntax
            }
            window.run_command("gs_inline_diff", {
                "settings": settings,
                "cached": True
            }) 
Example #7
Source File: panels.py    From LSP with MIT License 5 votes vote down vote up
def create_panel(window: sublime.Window, name: str, result_file_regex: str, result_line_regex: str,
                 syntax: str) -> Optional[sublime.View]:
    panel = create_output_panel(window, name)
    if not panel:
        return None
    panel.settings().set("result_file_regex", result_file_regex)
    panel.settings().set("result_line_regex", result_line_regex)
    panel.assign_syntax(syntax)
    # Call create_output_panel a second time after assigning the above
    # settings, so that it'll be picked up as a result buffer
    # see: Packages/Default/exec.py#L228-L230
    panel = window.create_output_panel(name)
    # All our panels are read-only
    panel.set_read_only(True)
    return panel 
Example #8
Source File: diagnostics.py    From LSP with MIT License 5 votes vote down vote up
def __init__(self, window: sublime.Window) -> None:
        self._window = window
        self._to_render = []  # type: List[str]
        self._panel = ensure_diagnostics_panel(self._window) 
Example #9
Source File: diagnostics.py    From LSP with MIT License 5 votes vote down vote up
def __init__(self, window: sublime.Window, documents_state: DocumentsState) -> None:
        self._window = window
        self._dirty = False
        self._received_diagnostics_after_change = False
        self._show_panel_on_diagnostics = False if settings.auto_show_diagnostics_panel == 'never' else True
        self._panel_update = DiagnosticOutputPanel(self._window)
        self._bar_summary_update = StatusBarSummary(self._window)
        self._relevance_check = HasRelevantDiagnostics()
        self._cursor = DiagnosticsCursor(settings.show_diagnostics_severity_level)
        self._phantoms = DiagnosticsPhantoms(self._window)
        self._diagnostics = {}  # type: Dict[str, Dict[str, List[Diagnostic]]]
        if settings.auto_show_diagnostics_panel == 'saved':
            setattr(documents_state, 'changed', self.on_document_changed)
            setattr(documents_state, 'saved', self.on_document_saved) 
Example #10
Source File: panels.py    From LSP with MIT License 5 votes vote down vote up
def toggle_output_panel(window: Window, panel_type: str) -> None:
    panel_name = "output.{}".format(panel_type)
    command = "{}_panel".format("hide" if window.active_panel() == panel_name else "show")
    window.run_command(command, {"panel": panel_name}) 
Example #11
Source File: main.py    From LSP with MIT License 5 votes vote down vote up
def ensure_server_panel(window: sublime.Window) -> Optional[sublime.View]:
    return ensure_panel(window, PanelName.LanguageServers, "", "", "Packages/LSP/Syntaxes/ServerLog.sublime-syntax") 
Example #12
Source File: diagnostics.py    From LSP with MIT License 5 votes vote down vote up
def __init__(self, window: sublime.Window) -> None:
        self._window = window 
Example #13
Source File: registry.py    From LSP with MIT License 5 votes vote down vote up
def unload_sessions(window: sublime.Window) -> None:
    wm = windows.lookup(window)
    wm.end_sessions() 
Example #14
Source File: panels.py    From LSP with MIT License 5 votes vote down vote up
def create_output_panel(window: sublime.Window, name: str) -> Optional[sublime.View]:
    panel = window.create_output_panel(name)
    settings = panel.settings()
    for key, value in OUTPUT_PANEL_SETTINGS.items():
        settings.set(key, value)
    return panel 
Example #15
Source File: panels.py    From LSP with MIT License 5 votes vote down vote up
def destroy_output_panels(window: sublime.Window) -> None:
    for field in filter(lambda a: not a.startswith('__'), PanelName.__dict__.keys()):
        panel_name = getattr(PanelName, field)
        panel = window.find_output_panel(panel_name)
        if panel and panel.is_valid():
            panel.settings().set("syntax", "Packages/Text/Plain text.tmLanguage")
            window.destroy_output_panel(panel_name) 
Example #16
Source File: show_commit_info.py    From GitSavvy with MIT License 5 votes vote down vote up
def panel_is_visible(window, name=PANEL_NAME):
    # type: (sublime.Window, str) -> bool
    return window.active_panel() == "output.{}".format(name) 
Example #17
Source File: status.py    From GitSavvy with MIT License 5 votes vote down vote up
def load_diff_windows(self, window, non_cached_files, cached_files):
        # type: (sublime.Window, List[str], List[str]) -> None
        for fpath in non_cached_files:
            window.run_command("gs_diff", {
                "file_path": fpath,
                "in_cached_mode": False,
            })

        for fpath in cached_files:
            window.run_command("gs_diff", {
                "file_path": fpath,
                "in_cached_mode": True,
            }) 
Example #18
Source File: show_commit_info.py    From GitSavvy with MIT License 5 votes vote down vote up
def _draw(window, view, text, commit):
    # type: (sublime.Window, sublime.View, str, str) -> None
    with restore_viewport_position(view, commit):
        replace_view_content(view, text)

    intra_line_colorizer.annotate_intra_line_differences(view)

    # In case we reuse a hidden panel, show the panel after updating
    # the content to reduce visual flicker.
    ensure_panel_is_visible(window) 
Example #19
Source File: clients.py    From LSP with MIT License 5 votes vote down vote up
def on_session_ended(window: sublime.Window, config_name: str, on_post_exit_handler: Callable[[str], None]) -> None:
    on_post_exit_handler(config_name) 
Example #20
Source File: view.py    From GitSavvy with MIT License 5 votes vote down vote up
def refresh_gitsavvy_interfaces(
    window,
    refresh_sidebar=False,
    refresh_status_bar=True,
    interface_reset_cursor=False
):
    # type: (Optional[sublime.Window], bool, bool, bool) -> None
    """
    Looks for GitSavvy interface views in the current window and refresh them.

    Note that it only refresh visible views.
    Other views will be refreshed when activated.
    """
    if window is None:
        return

    if refresh_sidebar:
        window.run_command("refresh_folder_list")
    if refresh_status_bar:
        av = window.active_view()
        if av:
            av.run_command("gs_update_status_bar")

    for group in range(window.num_groups()):
        view = window.active_view_in_group(group)
        if view.settings().get("git_savvy.interface") is not None:
            view.run_command("gs_interface_refresh", {"nuke_cursors": interface_reset_cursor})

        if view.settings().get("git_savvy.log_graph_view", False):
            view.run_command("gs_log_graph_refresh") 
Example #21
Source File: file.py    From GitSavvy with MIT License 5 votes vote down vote up
def guess_syntax_for_file(window, filename):
    # type: (sublime.Window, str) -> str
    view = window.find_open_file(filename)
    if view:
        syntax = view.settings().get("syntax")
        remember_syntax_choice(filename, syntax)
        return syntax
    return get_syntax_for_file(filename) 
Example #22
Source File: inline_diff.py    From GitSavvy with MIT License 5 votes vote down vote up
def open_file(self, window, file_path, line_no, col_no):
        # type: (sublime.Window, str, LineNo, ColNo) -> None
        window.open_file(
            "{file}:{line_no}:{col_no}".format(
                file=file_path,
                line_no=line_no,
                col_no=col_no
            ),
            sublime.ENCODED_POSITION
        ) 
Example #23
Source File: show_commit_info.py    From GitSavvy with MIT License 5 votes vote down vote up
def ensure_panel(window, name=PANEL_NAME, syntax="Packages/GitSavvy/syntax/show_commit.sublime-syntax"):
    # type: (sublime.Window, str, str) -> sublime.View
    output_view = window.find_output_panel(name)
    if output_view:
        return output_view

    output_view = window.create_output_panel(name)
    output_view.set_read_only(True)
    if syntax:
        output_view.set_syntax_file(syntax)
    output_view.settings().set("git_savvy.show_commit_view", True)
    return output_view 
Example #24
Source File: debugger.py    From sublime_debugger with MIT License 5 votes vote down vote up
def get(window: sublime.Window, run: bool = False) -> 'Optional[Debugger]':
		return Debugger.for_window(window, run) 
Example #25
Source File: sublime_plugin.py    From TerminalView with MIT License 5 votes vote down vote up
def create_window_commands(window_id):
    window = sublime.Window(window_id)
    cmds = []
    for class_ in window_command_classes:
        cmds.append(class_(window))
    return cmds 
Example #26
Source File: sublime_plugin.py    From TerminalView with MIT License 5 votes vote down vote up
def on_window_command(window_id, name, args):
    window = sublime.Window(window_id)
    for callback in all_callbacks['on_window_command']:
        try:
            res = callback.on_window_command(window, name, args)
            if isinstance(res, tuple):
                return res
            elif res:
                return (res, None)
        except:
            traceback.print_exc()

    return ("", None) 
Example #27
Source File: sublime_plugin.py    From TerminalView with MIT License 5 votes vote down vote up
def on_post_window_command(window_id, name, args):
    window = sublime.Window(window_id)
    for callback in all_callbacks['on_post_window_command']:
        try:
            callback.on_post_window_command(window, name, args)
        except:
            traceback.print_exc() 
Example #28
Source File: main.py    From sublime_debugger with MIT License 5 votes vote down vote up
def open(window_or_view: Union[sublime.View, sublime.Window]):
	if isinstance(window_or_view, sublime.View):
		view = window_or_view 
		window = view.window()
	else:
		window = window_or_view
		view = window.active_view()

	if get_setting(view, 'open_at_startup', False) and (not window.id() in was_opened_at_startup) and Debugger.should_auto_open_in_window(window):
		was_opened_at_startup.add(window.id())
		Debugger.for_window(window, create=True) 
Example #29
Source File: main.py    From sublime_debugger with MIT License 5 votes vote down vote up
def on_load_project(window: sublime.Window):
	if debugger := Debugger.get(window):
		debugger.project.reload() 
Example #30
Source File: main.py    From sublime_debugger with MIT License 5 votes vote down vote up
def on_pre_close_window(window: sublime.Window):
	if debugger := Debugger.get(window):
		debugger.dispose()