本文整理汇总了Python中OmniMarkupLib.Setting.Setting.instance方法的典型用法代码示例。如果您正苦于以下问题:Python Setting.instance方法的具体用法?Python Setting.instance怎么用?Python Setting.instance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OmniMarkupLib.Setting.Setting
的用法示例。
在下文中一共展示了Setting.instance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: plugin_loaded
# 需要导入模块: from OmniMarkupLib.Setting import Setting [as 别名]
# 或者: from OmniMarkupLib.Setting.Setting import instance [as 别名]
def plugin_loaded():
Server.init()
# Setting must be the first to initialize.
Setting.instance().init()
PluginManager.instance().subscribe_setting_events()
RendererManager.start()
PluginManager.instance().restart_server()
示例2: run
# 需要导入模块: from OmniMarkupLib.Setting import Setting [as 别名]
# 或者: from OmniMarkupLib.Setting.Setting import instance [as 别名]
def run(self, edit, immediate=True):
# Whether RendererManager is finished loading?
if not RendererManager.ensure_started():
sublime.status_message('OmniMarkupPreviewer have not yet started')
return
buffer_id = self.view.buffer_id()
# Opened in a tab already?
opened = False
for view in self.view.window().views():
if view.buffer_id() == buffer_id:
opened = True
break
if not opened:
RendererManager.enqueue_view(self.view, immediate=True)
host = Setting.instance().server_host
port = Setting.instance().server_port
if host == '0.0.0.0':
host = '127.0.0.1'
url = 'http://%s:%d/view/%d' % (host, port, buffer_id)
# Open with the default browser
log.info('Launching web browser for %s', url)
launching_web_browser_for_url(
url,
success_msg_default='Preview launched in default web browser',
success_msg_user='Preview launched in user defined web browser')
示例3: launching_web_browser_for_url
# 需要导入模块: from OmniMarkupLib.Setting import Setting [as 别名]
# 或者: from OmniMarkupLib.Setting.Setting import instance [as 别名]
def launching_web_browser_for_url(url, success_msg_default=None, success_msg_user=None):
try:
setting = Setting.instance()
if setting.browser_command:
browser_command = [os.path.expandvars(arg).format(url=url)
for arg in setting.browser_command]
if os.name == 'nt':
# unicode arguments broken under windows
encoding = locale.getpreferredencoding()
browser_command = [arg.encode(encoding) for arg in browser_command]
subprocess.Popen(browser_command)
if success_msg_user:
sublime.status_message(success_msg_user)
else:
# Default web browser
desktop.open(url)
if success_msg_default:
sublime.status_message(success_msg_default)
except:
if setting.browser_command:
log.exception('Error while launching user defined web browser')
else:
log.exception('Error while launching default web browser')
示例4: init
# 需要导入模块: from OmniMarkupLib.Setting import Setting [as 别名]
# 或者: from OmniMarkupLib.Setting.Setting import instance [as 别名]
def init(cls):
setting = Setting.instance()
setting.subscribe('changing', cls.on_setting_changing)
setting.subscribe('changed', cls.on_setting_changed)
cls.on_setting_changing(setting)
cls.load_renderers()
cls.on_setting_changed(setting)
示例5: render_view_to_string
# 需要导入模块: from OmniMarkupLib.Setting import Setting [as 别名]
# 或者: from OmniMarkupLib.Setting.Setting import instance [as 别名]
def render_view_to_string(cls, view):
fullpath = view.file_name() or ''
lang = RendererManager.get_lang_by_scope_name(view.scope_name(0))
text = view.substr(sublime.Region(0, view.size()))
html_part = RendererManager.render_text(
fullpath, lang, text,
post_process_func=cls.render_text_postprocess_exporting
)
setting = Setting.instance()
return template(setting.export_options['template_name'],
mathjax_enabled=setting.mathjax_enabled,
filename=os.path.basename(fullpath),
dirname=os.path.dirname(fullpath),
html_part=html_part
)
示例6: run
# 需要导入模块: from OmniMarkupLib.Setting import Setting [as 别名]
# 或者: from OmniMarkupLib.Setting.Setting import instance [as 别名]
def run(self, edit):
view = self.view
try:
html_content = RendererManager.render_view_to_string(view)
setting = Setting.instance()
target_folder = setting.export_options['target_folder']
if target_folder is not None:
fullpath = self.view.file_name() or ''
timestamp_format = setting.export_options['timestamp_format']
if (not os.path.exists(fullpath) and target_folder == ".") or \
not os.path.isdir(target_folder):
target_folder = None
elif target_folder == '.':
fn_base, _ = os.path.splitext(fullpath)
html_fn = '%s%s.html' % (fn_base, time.strftime(timestamp_format,
time.localtime()))
elif not os.path.exists(fullpath):
html_fn = os.path.join(target_folder, 'Untitled%s.html' % \
time.strftime(timestamp_format, time.localtime()))
else:
fn_base = os.path.basename(fullpath)
html_fn = os.path.join(target_folder, '%s%s.html' % \
(fn_base, time.strftime(timestamp_format, time.localtime())))
if target_folder is None:
with tempfile.NamedTemporaryFile(delete=False, suffix='.html') as f:
html_fn = f.name
with codecs.open(html_fn, 'w', encoding='utf-8') as html_file:
html_file.write(html_content)
# Copy contents to clipboard
if setting.export_options['copy_to_clipboard']:
sublime.set_clipboard(html_content)
sublime.status_message('Exported result copied to clipboard')
# Open output file if necessary
if setting.export_options['open_after_exporting']:
log.info('Launching web browser for %s', html_fn)
launching_web_browser_for_url(html_fn)
except NotImplementedError:
pass
except:
log.exception("Error while exporting")
示例7: handler_view
# 需要导入模块: from OmniMarkupLib.Setting import Setting [as 别名]
# 或者: from OmniMarkupLib.Setting.Setting import instance [as 别名]
def handler_view(buffer_id):
# A browser refresh always get the latest result
f = Future(render_text_by_buffer_id, buffer_id)
sublime.set_timeout(f, 0)
entry = f.result()
entry = entry or RenderedMarkupCache.instance().get_entry(buffer_id)
if entry is None:
return bottle.HTTPError(
404,
'buffer_id(%d) is not valid (not open or unsupported file format)' % buffer_id
)
setting = Setting.instance()
return template(setting.html_template_name,
buffer_id=buffer_id,
ajax_polling_interval=setting.ajax_polling_interval,
mathjax_enabled=setting.mathjax_enabled,
**entry)
示例8: restart_server
# 需要导入模块: from OmniMarkupLib.Setting import Setting [as 别名]
# 或者: from OmniMarkupLib.Setting.Setting import instance [as 别名]
def restart_server(self):
global g_server
if g_server is not None:
self.stop_server()
setting = Setting.instance()
g_server = Server.Server(host=setting.server_host, port=setting.server_port)
示例9: subscribe_setting_events
# 需要导入模块: from OmniMarkupLib.Setting import Setting [as 别名]
# 或者: from OmniMarkupLib.Setting.Setting import instance [as 别名]
def subscribe_setting_events(self):
Setting.instance().subscribe('changing', self.on_setting_changing)
Setting.instance().subscribe('changed', self.on_setting_changed)
示例10: _on_post_save
# 需要导入模块: from OmniMarkupLib.Setting import Setting [as 别名]
# 或者: from OmniMarkupLib.Setting.Setting import instance [as 别名]
def _on_post_save(self, view):
if not Setting.instance().refresh_on_saved:
return
self.throttle.put(view, preemptive=True)
示例11: callback
# 需要导入模块: from OmniMarkupLib.Setting import Setting [as 别名]
# 或者: from OmniMarkupLib.Setting.Setting import instance [as 别名]
def callback():
setting = Setting.instance()
if not setting.refresh_on_modified:
return
timeout = setting.refresh_on_modified_delay / 1000.0
self.throttle.put(view, preemptive=False, timeout=timeout)
示例12: try_download_mathjax
# 需要导入模块: from OmniMarkupLib.Setting import Setting [as 别名]
# 或者: from OmniMarkupLib.Setting.Setting import instance [as 别名]
def try_download_mathjax(self, setting=None):
if setting is None:
setting = Setting.instance()
if setting.mathjax_enabled:
OnDemandDownloader.on_demand_download_mathjax(setting)
示例13: on_post_save
# 需要导入模块: from OmniMarkupLib.Setting import Setting [as 别名]
# 或者: from OmniMarkupLib.Setting.Setting import instance [as 别名]
def on_post_save(self, view):
if view.is_scratch() or not Setting.instance().refresh_on_saved:
return
self.delayed_views_worker.queue(view, preemptive=True)
示例14: on_modified
# 需要导入模块: from OmniMarkupLib.Setting import Setting [as 别名]
# 或者: from OmniMarkupLib.Setting.Setting import instance [as 别名]
def on_modified(self, view):
if view.is_scratch() or not Setting.instance().refresh_on_modified:
return
self.delayed_views_worker.queue(view, preemptive=False,
timeout=float(Setting.instance().refresh_on_modified_delay) / 1000)
示例15: __init__
# 需要导入模块: from OmniMarkupLib.Setting import Setting [as 别名]
# 或者: from OmniMarkupLib.Setting.Setting import instance [as 别名]
def __init__(self):
setting = Setting.instance()
self.on_setting_changing(setting)