Python sublime.set_timeout() Examples

The following are 30 code examples of sublime.set_timeout(). 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: package.py    From UnitTesting with MIT License 6 votes vote down vote up
def run(self, package=None, **kwargs):
        if not package:
            self.prompt_package(lambda x: self.run(x, **kwargs))
            return

        package, pattern = self.input_parser(package)

        if sys.version_info >= (3, 8) and self.package_python_version(package) == "3.3":
            print("run unit_testing in python 3.3")
            kwargs["package"] = package
            sublime.set_timeout(lambda: sublime.run_command(self.fallback33, kwargs))
            return

        if pattern is not None:
            # kwargs have the highest precedence when evaluating the settings,
            # so we sure don't want to pass `None` down
            kwargs['pattern'] = pattern

        settings = self.load_unittesting_settings(package, kwargs)
        stream = self.load_stream(package, settings)

        if settings["async"]:
            threading.Thread(target=lambda: self.unit_testing(stream, package, settings)).start()
        else:
            self.unit_testing(stream, package, settings) 
Example #2
Source File: thread_progress.py    From SyncSettings with MIT License 6 votes vote down vote up
def run(self, i):
        if not self.thread.is_alive():
            msg = '' if not self.success_message else 'Sync Settings: {}'.format(self.success_message)
            sublime.status_message(msg)
            return
        before = i % self.size
        after = (self.size - 1) - before

        sublime.status_message('Sync Settings: {} [{}={}]'.format(self.message, ' ' * before, ' ' * after))

        if not after:
            self.addend = -1
        if not before:
            self.addend = 1

        i += self.addend
        sublime.set_timeout(lambda: self.run(i), 100) 
Example #3
Source File: progress_notifier.py    From sublime-gulp with MIT License 6 votes vote down vote up
def run(self, i):
        if self.stopped:
            return

        before = i % self.size
        after = (self.size - 1) - before

        sublime.status_message('%s [%s=%s]' % (self.message, ' ' * before, ' ' * after))

        if not after:
            self.addend = -1
        if not before:
            self.addend = 1
        i += self.addend

        sublime.set_timeout(lambda: self.run(i), 100) 
Example #4
Source File: Glue.py    From glue with MIT License 6 votes vote down vote up
def print_on_complete(self, thread, user_command):
        if thread.is_alive():
            sublime.set_timeout(lambda: self.print_on_complete(thread, user_command), 20)
            return
        else:
            # command was successful
            if self.exitcode == 0:
                # clean the standard output string
                clean_stdout = self.clean_output(self.stdout)
                self.view.run_command('glue_writer', {'text': clean_stdout, 'command': user_command})
            # command was not successful (non-zero exit status)
            else:
                self.view.run_command('glue_writer', {'text': self.stderr, 'command': user_command})

            # print to stdout as well - removed
            # self.print_response()

    #------------------------------------------------------------------------------
    # [ clean_output method ] - remove special characters that should not be printed to standard output view
    #------------------------------------------------------------------------------ 
Example #5
Source File: code_map.py    From sublime-codemap with MIT License 6 votes vote down vote up
def create_codemap_group():
    """Adds a column on the right, and scales down the layout."""
    w = win()
    layout = win().get_layout()
    cols = layout['cols']
    cells = layout['cells']
    last_col = len(cols) - 1
    last_row = len(layout['rows']) - 1
    width = 1 - settings().get("codemap_width")

    for i, col in enumerate(cols):
        if col > 0:
            cols[i] = col*width

    cols.append(1)
    newcell = [last_col, 0, last_col + 1, last_row]
    cells.append(newcell)
    groups = w.num_groups()
    w.run_command("set_layout", layout)
    sublime.set_timeout(lambda: Mapper.block_max_pane(False), 10)
    return (groups + 1)

# ----------------- 
Example #6
Source File: code_map.py    From sublime-codemap with MIT License 6 votes vote down vote up
def reset_layout():
    """Removes the Code Map group, and scales up the layout."""
    w = win()
    layout = w.get_layout()
    cols = layout['cols']
    width = 1 - settings().get("codemap_width")

    alone_in_group = len(win().views_in_group(CodeMapListener.map_group)) == 0

    if alone_in_group:
        for i, col in enumerate(cols):
            if col > 0:
                cols[i] = col/width

        cols[-2] = 1.0
        del cols[-1]
        del layout['cells'][-1]

    Mapper.block_max_pane(True)
    w.run_command("set_layout", layout)
    sublime.set_timeout(lambda: Mapper.block_max_pane(False), 10)

# ----------------- 
Example #7
Source File: main_metadata.py    From SalesforceXyTools with Apache License 2.0 6 votes vote down vote up
def open_category_panel(self, thread, sel_category, timeout=200):
        if thread.is_alive():
            self.sublconsole.showlog("loading metadata , please wait...")
            timeout=200
            sublime.set_timeout(lambda: self.open_category_panel(thread, sel_category, timeout), timeout)
            return
        self.sublconsole.showlog("load metadata ok!")

        try:
            self.sel_category_list = self.metadata_cache.get_meta_category()
            if sel_category and sel_category in self.sel_category_list:
                self.open_detail_panel(sel_category)
            else:
                self.window.show_quick_panel(self.sel_category_list, self.panel_done, sublime.MONOSPACE_FONT)
        except Exception as e:
            self.sublconsole.showlog(e)
            return 
Example #8
Source File: Glue.py    From glue with MIT License 6 votes vote down vote up
def progress_indicator(self, thread, i=0, direction=1):
        if thread.is_alive():
            before = i % 8
            after = (7) - before
            if not after:
                direction = -1
            if not before:
                direction = 1
            i += direction
            self.view.set_status('glue_status_indicator', 'Glue: Running command [%s|%s]' % (' ' * before, ' ' * after))
            sublime.set_timeout(lambda: self.progress_indicator(thread, i, direction), 75)
            return
        else:
            self.view.erase_status('glue_status_indicator')
            sublime.status_message('Glue: Command completed.')

    #------------------------------------------------------------------------------
    # [ execute_command method ] - execute a system command
    #   run in a separate thread from muterun() method above
    #   assigns stdout stderr and exitcode in instance attributes
    #------------------------------------------------------------------------------ 
Example #9
Source File: __init__.py    From Requester with MIT License 6 votes vote down vote up
def _run(self, thread, count=0):
        """Evaluate environment in a separate thread and show an activity
        indicator. Inspect thread at regular intervals until it's finished, at
        which point `make_requests` can be invoked. Return if thread times out.
        """
        REFRESH_MULTIPLIER = 2
        activity = self.get_activity_indicator(count//REFRESH_MULTIPLIER, self.ACTIVITY_SPACES)
        if count > 0:  # don't distract user with RequesterEnv status if env can be evaluated quickly
            self.view.set_status('requester.activity', '{} {}'.format('RequesterEnv', activity))

        if thread.is_alive():
            timeout = self.config.get('timeout_env', None)
            if timeout is not None and count * self.REFRESH_MS/REFRESH_MULTIPLIER > timeout * 1000:
                sublime.error_message('Timeout Error: environment took too long to parse')
                self.view.set_status('requester.activity', '')
                return
            sublime.set_timeout(lambda: self._run(thread, count+1), self.REFRESH_MS/REFRESH_MULTIPLIER)

        else:
            requests = self.get_requests()
            self.view.set_status('requester.activity', '')
            self.make_requests(requests, self._env) 
Example #10
Source File: jumping.py    From SublimeFileBrowser with MIT License 6 votes vote down vote up
def run(self, edit):
        pt = self.view.sel()[0].a
        row, col = self.view.rowcol(pt)
        points = [[n, t] for n, t in jump_points()]
        current_project = [points[row - 3][1]]
        settings = load_settings('dired.sublime-settings')
        smart_jump = settings.get('dired_smart_jump', False)
        if smart_jump and len(self.view.window().views()) == 1:
            show(self.view.window(), current_project[0])
        else:
            self.view.run_command("dired_open_in_new_window", {"project_folder": current_project})

        def close_view(view):
            if ST3:
                view.close()
            else:
                view.window().run_command("close_file")

        sublime.set_timeout(close_view(self.view), 100) 
Example #11
Source File: dired_file_operations.py    From SublimeFileBrowser with MIT License 6 votes vote down vote up
def progress_bar(self, threads, i=0, dir=1):
        threads = [t for t in threads if t.is_alive()]
        if threads:
            # This animates a little activity indicator in the status area
            before = i % 8
            after = (7) - before
            if not after:  dir = -1
            if not before: dir = 1
            i += dir
            self.view.set_status('__FileBrowser__', u'Please wait%s…%sWriting %s' %
                                 (' ' * before, ' ' * after, u', '.join([t.name if ST3 else t.name.decode('utf8') for t in threads])))
            sublime.set_timeout(lambda: self.progress_bar(threads, i, dir), 100)
            return
        else:
            emit_event(u'watch_view', self.view.id(), plugin=u'FileBrowserWFS')
            self.view.run_command('dired_clear_copy_cut_list') 
Example #12
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 #13
Source File: dired_misc.py    From SublimeFileBrowser with MIT License 6 votes vote down vote up
def on_new(self, view):
        if not self.MOVE:
            return
        w = sublime.active_window()
        if w.num_groups() < 2:
            return
        if is_any_dired_in_group(w, 0):
            if w.active_group() == 0:
                # at this point views are exist, so we cannot avoid the use of
                # set_view_index, but ST2 return None if group has no views
                # ST3 return None if group has active image’s view
                avig1 = w.active_view_in_group(1)
                if avig1:
                    _group, active_view_index_in_other_group = w.get_view_index(avig1)
                    index = active_view_index_in_other_group + 1
                else:
                    index = 0
                sublime.set_timeout(lambda: w.set_view_index(view, 1, index), 1) 
Example #14
Source File: progress_notifier.py    From sublime-text-trello with MIT License 6 votes vote down vote up
def run(self, i):
        if self.stopped:
            return

        before = i % self.size
        after = (self.size - 1) - before

        sublime.status_message('%s [%s=%s]' % (self.message, ' ' * before, ' ' * after))

        if not after:
            self.addend = -1
        if not before:
            self.addend = 1
        i += self.addend

        sublime.set_timeout(lambda: self.run(i), 100) 
Example #15
Source File: exec.py    From sublime-ide-r with MIT License 6 votes vote down vote up
def run(self, selector="", kill=False, **kwargs):
        if kill:
            if ride_settings.get("terminus_exec", False):
                self.window.run_command("terminus_cancel_build")
            else:
                self.window.run_command("exec", {"kill": True})
            return

        if "cmd" in kwargs and kwargs["cmd"]:
            self.window.run_command("ride_exec_core", kwargs)
        elif "cmd" not in kwargs:
            # as a workaround of
            # https://github.com/SublimeTextIssues/Core/issues/3010
            # we pass an empty `text`
            sublime.set_timeout(lambda: self.window.run_command(
                    "show_overlay", {
                        "overlay": "command_palette",
                        "command": "ride_exec_core",
                        "text": ""
                    }), 10) 
Example #16
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 #17
Source File: test.py    From UnitTesting with MIT License 5 votes vote down vote up
def test_defer(self):
        self.setText("foo")
        self.view.sel().clear()
        self.view.sel().add(sublime.Region(0, 0))
        sublime.set_timeout(lambda: self.setText("foo"), 100)
        yield 200
        self.assertEqual(self.getRow(0), "foofoo") 
Example #18
Source File: ChromeREPL.py    From ChromeREPL with MIT License 5 votes vote down vote up
def run(self, edit):
    connection = ChromeREPLConnection.get_instance(self.view)

    # store selection for later restoration
    prev = []
    for sel in self.view.sel():
      prev.append(sel)

    success = True
    # evaluate selections in Chrome
    for sel in self.view.sel():
      if sel.a == sel.b:  # the 'selection' is a single point
        sel = self.view.line(sel)
        self.view.sel().add(sel)

      try:
        expression = self.view.substr(sel)
        connection.execute(expression)
      except Exception as e:
        success = False

    if success:
      # highlight
      self.view.add_regions(self.HIGHLIGHT_KEY,
                            self.view.sel(),
                            self.HIGHLIGHT_SCOPE,
                            flags=sublime.DRAW_NO_OUTLINE)

      # clear selection so highlighting will be visible
      self.view.sel().clear()

      # do highlighting
      sublime.set_timeout(lambda: self.view.sel().add_all(prev), 10)

      # remove highlight and restore original selection
      sublime.set_timeout(lambda: self.view.erase_regions(self.HIGHLIGHT_KEY), 50) 
Example #19
Source File: progress_notifier.py    From sublime-text-trello with MIT License 5 votes vote down vote up
def __init__(self, message, success_message = ''):
        self.message = message
        self.success_message = success_message
        self.stopped = False
        self.addend = 1
        self.size = 8
        sublime.set_timeout(lambda: self.run(0), 100) 
Example #20
Source File: trello.py    From sublime-text-trello with MIT License 5 votes vote down vote up
def show_quick_panel(self, items, on_done = None, on_highlighted = None, selected_index = -1):
        sublime.set_timeout(lambda: self.view.window().show_quick_panel(items, on_done, sublime.MONOSPACE_FONT, selected_index, on_highlighted), 0) 
Example #21
Source File: download.py    From SyncSettings with MIT License 5 votes vote down vote up
def check_installation(self, packages, on_done=None):
        package_settings = sublime.load_settings('Package Control.sublime-settings').get('installed_packages')
        should_call = False
        for package in packages:
            if package not in package_settings:
                should_call = True
                break
        if should_call:
            sublime.set_timeout(lambda: self.check_installation(packages, on_done), 100)
        if not should_call and on_done:
            on_done() 
Example #22
Source File: utils.py    From R-Box with MIT License 5 votes vote down vote up
def write(self, s):
        sublime.set_timeout(
            lambda: self.output_view.run_command('output_panel_insert', {'characters': s}),
            10) 
Example #23
Source File: utils.py    From R-Box with MIT License 5 votes vote down vote up
def preference_temporary_settings(key, value, timeout=0):
    pref_settings = sublime.load_settings("Preferences.sublime-settings")
    old_value = pref_settings.get(key)
    pref_settings.set(key, value)
    yield
    sublime.set_timeout(
        lambda: pref_settings.set(key, old_value), timeout) 
Example #24
Source File: Localize.py    From LocalizedMenu with MIT License 5 votes vote down vote up
def plugin_loaded():
	sublime.set_timeout(init, 200) 
Example #25
Source File: runner.py    From UnitTesting with MIT License 5 votes vote down vote up
def defer(delay, callback, *args, **kwargs):
    # Rely on late binding in case a user patches it
    sublime.set_timeout(partial(callback, *args, **kwargs), delay) 
Example #26
Source File: sublime_event_loop.py    From sublime_debugger with MIT License 5 votes vote down vote up
def call_later(self, delay, callback, *args, context=None):
		handle = Handle(callback, args)
		sublime.set_timeout(handle, delay * 1000)
		return handle 
Example #27
Source File: test_deferred_timing.py    From UnitTesting with MIT License 5 votes vote down vote up
def test_b(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):
                if worktime:
                    time.sleep(worktime)
                messages.append(message)

            def sub_task():
                run_in_worker(work, 2, 0.5)  # add task (D)

            def uut():
                run_in_worker(work, 1, 0.3)    # add task (A)
                run_in_worker(sub_task)      # add task (B)

            uut()
            # task queue now: (A)..(B)

            yield  # add task (C) and wait for (C)
            #        (A) runs, (B) runs and adds task (D), (C) resolves
            expected = [1]
            self.assertEqual(messages, expected)
            # task queue now: (D)
            yield  # add task (E) and wait for it
            #        (D) runs and (E) resolves
            expected = [1, 2]
            self.assertEqual(messages, expected) 
Example #28
Source File: test.py    From UnitTesting with MIT License 5 votes vote down vote up
def test_condition(self):
        x = []

        def append():
            x.append(1)

        def condition():
            return len(x) == 1

        sublime.set_timeout(append, 100)

        # wait until `condition()` is true
        yield condition

        self.assertEqual(x[0], 1) 
Example #29
Source File: test.py    From UnitTesting with MIT License 5 votes vote down vote up
def test_condition_timeout(self):
        x = []

        def append():
            x.append(1)

        sublime.set_timeout(append, 100)

        # wait until condition timeout
        yield {"condition": lambda: False, "timeout": 500}

        self.assertEqual(x[0], 1) 
Example #30
Source File: sublime_event_loop.py    From sublime_debugger with MIT License 5 votes vote down vote up
def call_soon(self, callback, *args, context=None):
		handle = Handle(callback, args)
		sublime.set_timeout(handle, 0)
		return handle