Python sublime.set_timeout_async() Examples

The following are 30 code examples of sublime.set_timeout_async(). 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: code_map.py    From sublime-codemap with MIT License 6 votes vote down vote up
def on_close(self, view):

        if ACTIVE and view.file_name() == code_map_file:

            # Issue #35: Issue + Possible Solution:
            #            Toggling Code Map with show_code_map cmd causes active view / file to close
            #            ( whether using the keybind or calling directly )
            view.set_scratch(False)

            reset_globals()
            if settings().get('close_empty_group_on_closing_map', False):
                reset_layout()
            sublime.set_timeout_async(focus_source_code)

            # try to reactivate, in case another window with Codemap is open,
            # or a new workspace has been loaded
            sublime.set_timeout_async(lambda: reactivate())

    # ----------------- 
Example #2
Source File: test_deferred_timing.py    From UnitTesting with MIT License 6 votes vote down vote up
def test_a(self):
        # `patch` doesn't work as a decorator with generator functions so we
        # use `with`
        with patch.object(sublime, 'set_timeout_async', sublime.set_timeout):
            messages = []

            def work(message, worktime=None):
                # simulate that a task might take some time
                # this will not yield back but block
                if worktime:
                    time.sleep(worktime)

                messages.append(message)

            def uut():
                run_in_worker(work, 1, 0.5)   # add task (A)
                run_in_worker(work, 2)        # add task (B)

            uut()   # after that task queue has: (A)..(B)
            yield   # add task (C) and wait for (C)
            expected = [1, 2]
            self.assertEqual(messages, expected) 
Example #3
Source File: test_deferred_timing.py    From UnitTesting with MIT License 6 votes vote down vote up
def run_in_worker(fn, *args, **kwargs):
    sublime.set_timeout_async(partial(fn, *args, **kwargs))


# When we swap `set_timeout_async` with `set_timeout` we basically run
# our program single-threaded.
# This has some benefits:
# - We avoid async/timing issues
# - We can use plain `yield` to run Sublime's task queue empty, see below
# - Every code we run will get correct coverage
#
# However note, that Sublime will just put all async events on the queue,
# avoiding the API. We cannot patch that. That means, the event handlers
# will *not* run using plain `yield` like below, you still have to await
# them using `yield AWAIT_WORKER`.
# 
Example #4
Source File: listener.py    From network_tech with Apache License 2.0 6 votes vote down vote up
def run(self, edit):
        settings = sublime.load_settings(SETTINGS_FILE_NAME)
        network_info_on_hover = settings.get(NETWORK_INFO_ON_HOVER_SETTING_NAME, True)
        print(network_info_on_hover)
        settings.set(NETWORK_INFO_ON_HOVER_SETTING_NAME, not network_info_on_hover)
        sublime.save_settings(SETTINGS_FILE_NAME)

        setting_status = 'ON' if not network_info_on_hover else 'OFF'
        set_status = 'Network Info Popup: {}'.format(setting_status)

        def clear_status():
            current_status = self.view.get_status(STATUS_KEY)
            if set_status == current_status:
                self.view.erase_status(STATUS_KEY)

        self.view.set_status(STATUS_KEY, set_status)
        sublime.set_timeout_async(clear_status, 4000) 
Example #5
Source File: project_manager.py    From ProjectManager with MIT License 6 votes vote down vote up
def subl(*args):
    executable_path = sublime.executable_path()
    if sublime.platform() == 'osx':
        app_path = executable_path[:executable_path.rfind('.app/') + 5]
        executable_path = app_path + 'Contents/SharedSupport/bin/subl'

    subprocess.Popen([executable_path] + list(args))

    def on_activated():
        window = sublime.active_window()
        view = window.active_view()

        if sublime.platform() == 'windows':
            # fix focus on windows
            window.run_command('focus_neighboring_group')
            window.focus_view(view)

        sublime_plugin.on_activated(view.id())
        sublime.set_timeout_async(lambda: sublime_plugin.on_activated_async(view.id()))

    sublime.set_timeout(on_activated, 300) 
Example #6
Source File: SwiftKitten.py    From SwiftKitten with MIT License 6 votes vote down vote up
def on_modified(self, view):
        """
        """
        sel = view.sel()
        if not view.match_selector(sel[0].a, "source.swift"):
            return

        # clear linting
        self.errors = {}
        view.erase_regions("swiftkitten.diagnostics")

        self.query_id = None
        self.pending += 1

        def handle_timeout():
            self.handle_timeout(view)
        sublime.set_timeout_async(handle_timeout, self.delay) 
Example #7
Source File: theme_generator.py    From GitSavvy with MIT License 6 votes vote down vote up
def try_apply_theme(view, theme_path, tries=0):
    """ Safly apply new theme as color_scheme. """
    try:
        sublime.load_resource(theme_path)
    except Exception:
        if tries >= 8:
            print(
                'GitSavvy: The theme {} is not ready to load. Maybe restart to get colored '
                'highlights.'.format(theme_path)
            )
            return

        delay = (pow(2, tries) - 1) * 10
        sublime.set_timeout_async(lambda: try_apply_theme(view, theme_path, tries + 1), delay)
        return

    view.settings().set("color_scheme", theme_path) 
Example #8
Source File: git_savvy.py    From GitSavvy with MIT License 6 votes vote down vote up
def plugin_loaded():

    try:
        import package_control
    except ImportError:
        pass
    else:
        if (
            package_control.events.install('GitSavvy') or
            package_control.events.post_upgrade('GitSavvy')
        ):
            # The "event" (flag) is set for 5 seconds. To not get into a
            # reloader excess we wait for that time, so that the next time
            # this exact `plugin_loaded` handler runs, the flag is already
            # unset.
            sublime.set_timeout_async(reload_plugin, 5000)
            return

    prepare_gitsavvy() 
Example #9
Source File: checkout.py    From GitSavvy with MIT License 5 votes vote down vote up
def on_enter_local_name(self, branch_name):
        if not self.validate_branch_name(branch_name):
            sublime.error_message(NEW_BRANCH_INVALID.format(branch_name))
            sublime.set_timeout_async(
                lambda: self.on_branch_selection(self.remote_branch, branch_name), 100)
            return None

        self.git("checkout", "-b", branch_name, "--track", self.remote_branch)
        self.window.status_message(
            "Checked out `{}` as local branch `{}`.".format(self.remote_branch, branch_name))
        util.view.refresh_gitsavvy_interfaces(self.window,
                                              refresh_sidebar=True,
                                              interface_reset_cursor=True) 
Example #10
Source File: open_on_remote.py    From GitSavvy with MIT License 5 votes vote down vote up
def run(self, edit, remote=None):
        sublime.set_timeout_async(lambda: self.run_async(remote)) 
Example #11
Source File: commit.py    From GitSavvy with MIT License 5 votes vote down vote up
def run(self, edit, default_repo=True):
        if not default_repo:
            first_cursor = self.view.sel()[0].begin()
            text_before_cursor = self.view.substr(sublime.Region(0, first_cursor))
            nondefault_repo = re.search(
                r"([a-zA-Z\-_0-9\.]+)/([a-zA-Z\-_0-9\.]+)#$", text_before_cursor).groups()
        else:
            nondefault_repo = None

        sublime.set_timeout_async(lambda: self.run_async(nondefault_repo)) 
Example #12
Source File: commit.py    From GitSavvy with MIT License 5 votes vote down vote up
def run(self, edit):
        sublime.set_timeout_async(lambda: self.run_async()) 
Example #13
Source File: configure.py    From GitSavvy with MIT License 5 votes vote down vote up
def run(self):
        sublime.set_timeout_async(self.run_async) 
Example #14
Source File: ignore.py    From GitSavvy with MIT License 5 votes vote down vote up
def run(self):
        sublime.set_timeout_async(self.run_async, 0) 
Example #15
Source File: quick_stage.py    From GitSavvy with MIT License 5 votes vote down vote up
def run(self):
        sublime.set_timeout_async(self.run_async) 
Example #16
Source File: checkout.py    From GitSavvy with MIT License 5 votes vote down vote up
def run(self, branch=None):
        sublime.set_timeout_async(lambda: self.run_async(branch), 0) 
Example #17
Source File: checkout.py    From GitSavvy with MIT License 5 votes vote down vote up
def run(self, base_branch=None):
        sublime.set_timeout_async(lambda: self.run_async(base_branch)) 
Example #18
Source File: checkout.py    From GitSavvy with MIT License 5 votes vote down vote up
def on_done(self, branch_name):
        if not self.validate_branch_name(branch_name):
            sublime.error_message(NEW_BRANCH_INVALID.format(branch_name))
            sublime.set_timeout_async(
                lambda: self.run_async(base_branch=self.base_branch, new_branch=branch_name), 100)
            return None

        self.git(
            "checkout", "-b",
            branch_name,
            self.base_branch if self.base_branch else None)
        self.window.status_message("Created and checked out `{}` branch.".format(branch_name))
        util.view.refresh_gitsavvy_interfaces(self.window,
                                              refresh_sidebar=True,
                                              interface_reset_cursor=True) 
Example #19
Source File: open_on_remote.py    From GitSavvy with MIT License 5 votes vote down vote up
def run(self, edit, remote=None):
        sublime.set_timeout_async(lambda: self.run_async(remote)) 
Example #20
Source File: pull_request.py    From GitSavvy with MIT License 5 votes vote down vote up
def run(self):
        sublime.set_timeout_async(self.run_async, 0) 
Example #21
Source File: pull_request.py    From GitSavvy with MIT License 5 votes vote down vote up
def run(self):
        sublime.set_timeout_async(self.run_async, 0) 
Example #22
Source File: add_fork_as_remote.py    From GitSavvy with MIT License 5 votes vote down vote up
def run(self):
        sublime.set_timeout_async(self.run_async, 0) 
Example #23
Source File: git_savvy.py    From GitSavvy with MIT License 5 votes vote down vote up
def prepare_gitsavvy():
    from .common import util
    sublime.set_timeout_async(util.file.determine_syntax_files)

    # Ensure all interfaces are ready.
    sublime.set_timeout_async(
        lambda: util.view.refresh_gitsavvy(sublime.active_window().active_view()))

    savvy_settings = sublime.load_settings("GitSavvy.sublime-settings")
    if savvy_settings.get("load_additional_codecs"):
        sublime.set_timeout_async(reload_codecs) 
Example #24
Source File: autocomplete.py    From FlowIDE with MIT License 5 votes vote down vote up
def on_query_completions(self, view, prefix, locations):
        # Return the pending completions and clear them
        if self.completions_ready and self.completions:
            self.completions_ready = False
            return self.completions

        sublime.set_timeout_async(
            lambda: self.on_query_completions_async(
                view, prefix, locations
            )
        ) 
Example #25
Source File: check.py    From FlowIDE with MIT License 5 votes vote down vote up
def on_selection_modified_async(self, view):
        self.view = view
        sublime.set_timeout_async(
            lambda: self.run_check(view)
        ) 
Example #26
Source File: coverage.py    From FlowIDE with MIT License 5 votes vote down vote up
def on_selection_modified_async(self, view):
        self.view = view
        sublime.set_timeout_async(
            lambda: self.run_coverage(view)
        ) 
Example #27
Source File: go_to_definition.py    From FlowIDE with MIT License 5 votes vote down vote up
def run(self, edit):
        sublime.set_timeout_async(self.run_async) 
Example #28
Source File: type_hint.py    From FlowIDE with MIT License 5 votes vote down vote up
def run(self, edit):
        sublime.set_timeout_async(self.run_async) 
Example #29
Source File: edit.py    From LSP with MIT License 5 votes vote down vote up
def open_and_apply_edits(self, path: str, file_changes: List[TextEdit]) -> None:
        view = self.window.open_file(path)
        if view:
            if view.is_loading():
                # TODO: wait for event instead.
                sublime.set_timeout_async(
                    lambda: view.run_command('lsp_apply_document_edit', {'changes': file_changes}),
                    500
                )
            else:
                view.run_command('lsp_apply_document_edit',
                                 {'changes': file_changes})
        else:
            debug('view not found to apply', path, file_changes) 
Example #30
Source File: color.py    From LSP with MIT License 5 votes vote down vote up
def schedule_request(self) -> None:
        sel = self.view.sel()
        if len(sel) < 1:
            return

        current_point = sel[0].begin()
        if self._stored_point != current_point:
            self._stored_point = current_point
            sublime.set_timeout_async(lambda: self.fire_request(current_point), 800)