本文整理汇总了Python中sublime.set_timeout_async方法的典型用法代码示例。如果您正苦于以下问题:Python sublime.set_timeout_async方法的具体用法?Python sublime.set_timeout_async怎么用?Python sublime.set_timeout_async使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sublime
的用法示例。
在下文中一共展示了sublime.set_timeout_async方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run
# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import set_timeout_async [as 别名]
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)
示例2: on_modified
# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import set_timeout_async [as 别名]
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)
示例3: run_in_worker
# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import set_timeout_async [as 别名]
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`.
#
示例4: test_a
# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import set_timeout_async [as 别名]
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)
示例5: on_close
# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import set_timeout_async [as 别名]
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())
# -----------------
示例6: subl
# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import set_timeout_async [as 别名]
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)
示例7: plugin_loaded
# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import set_timeout_async [as 别名]
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()
示例8: try_apply_theme
# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import set_timeout_async [as 别名]
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)
示例9: run
# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import set_timeout_async [as 别名]
def run(self, edit):
# check whether the lua files
suffix_setting = self.view.settings().get('syntax')
file_suffix = suffix_setting.split('.')[0]
if file_suffix[-3:].lower() != 'lua': return
# get lines of replacement
r = sublime.Region(0, self.view.size())
self.view.unfold(r)
# get characters of view
lines = []
for region in self.view.lines(r):
cache = self.view.substr(region)
if len(cache) == 0: cache = ' '
lines.append(cache)
# get cursor position before the replacement
selection = self.view.sel()[0].b
row, col = self.view.rowcol(selection)
# replace the content after format
print("Run Lua Format")
self.view.replace(edit, r, lua_format(lines, get_settings()))
# set tab_size from lua-format-setting
self.view.run_command("set_setting", {"setting": "tab_size", "value": get_settings().get('tab_size', 4)})
# deal cursor position
selection = self.view.full_line(self.view.text_point(row - 1, 0)).b
cursor_pos = sublime.Region(selection, selection)
regions = self.view.sel()
regions.clear()
regions.add(cursor_pos)
sublime.set_timeout_async(lambda: self.view.show(cursor_pos), 0)
示例10: get_info
# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import set_timeout_async [as 别名]
def get_info(self, path):
self.preview_path = path
self.parent = dirname(path)
self.size = 0
self.errors = []
self._created, self._accessed, self._modified = get_dates(path)
try:
self.size += getsize(path)
except OSError as e:
self.errors.append(str(e))
if not self.view.is_popup_visible():
return
sublime.set_timeout_async(self.update_preview, 1)
示例11: open_from_preview
# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import set_timeout_async [as 别名]
def open_from_preview(self, payload):
msg, path = payload.split('\v')
def open_file(path):
(self.view.window() or sublime.active_window()).open_file(path)
def app(path):
self.view.update_popup('Please, wait…')
sublime.set_timeout_async(
self.view.run_command('dired_quick_look', {'preview': False, 'files': [path]}), 1)
def external(path):
self.view.update_popup('Please, wait…')
sublime.set_timeout_async(
self.view.run_command('dired_open_external', {'fname': path}), 1)
def ql(path):
self.view.update_popup('Please, wait…')
sublime.set_timeout_async(
self.view.run_command('dired_quick_look', {'files': [path]}), 1)
case = {
'file': open_file,
'app': app,
'external': external,
'ql': ql
}
case[msg](path)
# EVENT LISTENERS ###################################################
示例12: pfile_modified
# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import set_timeout_async [as 别名]
def pfile_modified(pfile, view):
pfile.dirty = True
now = time.time()
if now - pfile.last_modified > .5:
pfile.last_modified = now
if is_st2:
sublime.set_timeout(lambda: maybe_save_pfile(pfile, view, now), 5000)
else:
sublime.set_timeout_async(lambda: maybe_save_pfile(pfile, view, now), 5000)
if pfile.cached_completions and sel_start(view.sel()[0]) < pfile.cached_completions[0]:
pfile.cached_completions = None
if pfile.cached_arguments and sel_start(view.sel()[0]) < pfile.cached_arguments[0]:
pfile.cached_arguments = None
示例13: _loading_popup
# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import set_timeout_async [as 别名]
def _loading_popup(self, location, content, callback, loading_message='loading...'):
def _update(self, location, content, callback, loading_message):
loading_content = content + Html.div(loading_message)
self._update_popup(loading_content, location)
output = callback()
self._update_popup(content + output, location)
sublime.set_timeout_async(
functools.partial(_update, self, location, content, callback, loading_message),
0,
)
示例14: result_handler
# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import set_timeout_async [as 别名]
def result_handler(view, encoded_password, decoded_password, index):
if index is RESULTS.cancel:
return
elif index is RESULTS.display:
message = 'Encoded: {}\nDecoded: {}'.format(encoded_password, decoded_password)
sublime.message_dialog(message)
elif index is RESULTS.clipboard:
sublime.set_clipboard(decoded_password)
sublime.set_timeout_async(
functools.partial(clear_clipboard, view, decoded_password),
10000
)
示例15: async_decode_single_password
# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import set_timeout_async [as 别名]
def async_decode_single_password(pre_command_selection, pre_command_visible_region, view, passwords, index):
""" Calls decode_single_password asyncronously so the UI does not block"""
sublime.set_timeout_async(
functools.partial(
decode_single_password,
pre_command_selection,
pre_command_visible_region,
view,
passwords,
index
),
0
)