当前位置: 首页>>代码示例>>Python>>正文


Python Settings.get_from_user_settings方法代码示例

本文整理汇总了Python中settings.Settings.get_from_user_settings方法的典型用法代码示例。如果您正苦于以下问题:Python Settings.get_from_user_settings方法的具体用法?Python Settings.get_from_user_settings怎么用?Python Settings.get_from_user_settings使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在settings.Settings的用法示例。


在下文中一共展示了Settings.get_from_user_settings方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: BaseCommand

# 需要导入模块: from settings import Settings [as 别名]
# 或者: from settings.Settings import get_from_user_settings [as 别名]
class BaseCommand(sublime_plugin.WindowCommand):
    package_name = "Gulp"
    
    def run(self, task_name=None, task_flag=None, silent=False, paths=[]):
        self.setup_data_from_settings()
        self.task_name = task_name
        self.task_flag = task_flag if task_name is not None and task_flag is not None else self.get_flag_from_task_name()
        self.silent = silent
        self._working_dir = ""
        self.sercheable_folders = [os.path.dirname(path) for path in paths] if len(paths) > 0 else self.window.folders()
        self.output_view = None
        self.work()

    def setup_data_from_settings(self):
        self.settings = Settings()
        self.results_in_new_tab = self.settings.get("results_in_new_tab", False)
        self.nonblocking  = self.settings.get("nonblocking", True)
        self.exec_args = self.settings.get('exec_args', False)
        self.check_for_gulpfile = self.settings.get('check_for_gulpfile', True)


    def get_flag_from_task_name(self):
        flags = self.settings.get("flags", {})
        return flags[self.task_name] if self.task_name in flags else ""

    # Properties
    @property
    def working_dir(self): 
        return self._working_dir

    @working_dir.setter
    def working_dir(self, value): 
        if self.check_for_gulpfile:
            self._working_dir = os.path.dirname(value)
        else:
            self._working_dir = value

    # Main method, override
    def work(self):
        pass

    # Panels and message
    def show_quick_panel(self, items, on_done=None, font=sublime.MONOSPACE_FONT):
        self.defer_sync(lambda: self.window.show_quick_panel(items, on_done, font))

    def show_input_panel(self, caption, initial_text="", on_done=None, on_change=None, on_cancel=None):
        self.window.show_input_panel(caption, initial_text, on_done, on_change, on_cancel)

    def status_message(self, text):
        sublime.status_message("%s: %s" % (self.package_name, text))

    def error_message(self, text):
        sublime.error_message("%s: %s" % (self.package_name, text))

    # Output view
    def show_output_panel(self, text):
        if self.silent:
            self.status_message(text)
            return
        
        if self.results_in_new_tab:
            new_tab_path = os.path.join(self.gulp_results_path(), "Gulp Results")
            self.output_view = self.window.open_file(new_tab_path)
            self.output_view.set_scratch(True)
        else:
            self.output_view = self.window.get_output_panel("gulp_output")
            self.show_panel()
            
        self.output_view.settings().set("scroll_past_end", False)
        self.add_syntax()
        self.append_to_output_view(text)

    def gulp_results_path(self):
        return next(folder_path for folder_path in self.sercheable_folders if self.working_dir.find(folder_path) != -1) if self.working_dir else ""

    def gulp_results_view(self):
        if self.output_view is None:
            gulp_results = [view for view in sublime.active_window().views() if view.file_name() and os.path.basename(view.file_name()) == "Gulp Results"]
            return gulp_results[0] if len(gulp_results) > 0 else None
        else:
            return self.output_view

    def add_syntax(self):
        if self.settings.has("syntax_override"):
            syntax_file = self.settings.get("syntax_override")
        else:
            syntax_file = self.settings.get_from_user_settings("syntax", "Packages/Gulp/syntax/GulpResults.tmLanguage")
            
        if syntax_file:
            self.output_view.set_syntax_file(syntax_file)

    def append_to_output_view_in_main_thread(self, text):
        self.defer_sync(lambda: self.append_to_output_view(text))

    def append_to_output_view(self, text):
        if not self.silent:
            decoded_text = text if is_sublime_text_3 else CrossPlaformCodecs.force_decode(text)
            self._insert(self.output_view, decoded_text)

    def _insert(self, view, content):
#.........这里部分代码省略.........
开发者ID:andreystarkov,项目名称:sublime3-front-end-2016,代码行数:103,代码来源:base_command.py

示例2: BaseCommand

# 需要导入模块: from settings import Settings [as 别名]
# 或者: from settings.Settings import get_from_user_settings [as 别名]
class BaseCommand(sublime_plugin.WindowCommand):
    def run(self, task_name=None, task_flag=None, silent=False, paths=[]):
        self.setup_data_from_settings()
        self.task_name = task_name
        self.task_flag = task_flag if task_name is not None and task_flag is not None else self.get_flag_from_task_name()
        self.silent = silent
        self._working_dir = ""
        self.sercheable_folders = [os.path.dirname(path) for path in paths] if len(paths) > 0 else self.window.folders()
        self.output_view = None
        self.work()

    def setup_data_from_settings(self):
        Settings.gather_shared_data()
        self.settings = Settings()
        self.results_in_new_tab = self.settings.get("results_in_new_tab", False)
        self.check_for_gulpfile = self.settings.get('check_for_gulpfile', True)

    def get_flag_from_task_name(self):
        flags = self.settings.get("flags", {})
        return flags[self.task_name] if self.task_name in flags else ""

    # Properties
    @property
    def working_dir(self):
        return self._working_dir

    @working_dir.setter
    def working_dir(self, value):
        if self.check_for_gulpfile:
            self._working_dir = os.path.dirname(value)
        else:
            self._working_dir = value

    # Main method, override
    def work(self):
        pass

    # Panels and message
    def show_quick_panel(self, items, on_done=None, font=sublime.MONOSPACE_FONT):
        defer_sync(lambda: self.window.show_quick_panel(items, on_done, font))

    def show_input_panel(self, caption, initial_text="", on_done=None, on_change=None, on_cancel=None):
        self.window.show_input_panel(caption, initial_text, on_done, on_change, on_cancel)

    def status_message(self, text):
        sublime.status_message("%s: %s" % (Settings.PACKAGE_NAME, text))

    def error_message(self, text):
        sublime.error_message("%s: %s" % (Settings.PACKAGE_NAME, text))

    # Output view
    def show_output_panel(self, text):
        if self.silent:
            self.status_message(text)
            return

        if self.results_in_new_tab:
            new_tab_path = os.path.join(self.gulp_results_path(), "Gulp Results")
            self.output_view = self.window.open_file(new_tab_path)
            self.output_view.set_scratch(True)
        else:
            self.output_view = self.window.get_output_panel("gulp_output")
            self.show_panel()

        self.output_view.settings().set("scroll_past_end", False)
        self.add_syntax()
        self.append_to_output_view(text)

    def gulp_results_path(self):
        return next(folder_path for folder_path in self.sercheable_folders if self.working_dir.find(folder_path) != -1) if self.working_dir else ""

    def gulp_results_view(self):
        if self.output_view is None:
            gulp_results = [view for view in sublime.active_window().views() if view.file_name() and os.path.basename(view.file_name()) == "Gulp Results"]
            return gulp_results[0] if len(gulp_results) > 0 else None
        else:
            return self.output_view

    def add_syntax(self):
        if self.settings.has("syntax_override"):
            syntax_file = self.settings.get("syntax_override")
        else:
            syntax_file = self.settings.get_from_user_settings("syntax", "Packages/Gulp/syntax/GulpResults.tmLanguage")

        if syntax_file:
            self.output_view.set_syntax_file(syntax_file)

    def append_to_output_view_in_main_thread(self, text):
        defer_sync(lambda: self.append_to_output_view(text))

    def append_to_output_view(self, text):
        if not self.silent:
            insert_in_output_view(self.output_view, text, self.results_in_new_tab)

    def set_output_close_on_timeout(self):
        timeout = self.settings.get("results_autoclose_timeout_in_milliseconds", False)
        if timeout:
            set_timeout(self.close_panel, timeout)

    def close_panel(self):
#.........这里部分代码省略.........
开发者ID:1901,项目名称:sublime_sync,代码行数:103,代码来源:base_command.py

示例3: BaseCommand

# 需要导入模块: from settings import Settings [as 别名]
# 或者: from settings.Settings import get_from_user_settings [as 别名]

#.........这里部分代码省略.........

    def show_input_panel(self, caption, initial_text="", on_done=None, on_change=None, on_cancel=None):
        self.window.show_input_panel(caption, initial_text, on_done, on_change, on_cancel)

    def status_message(self, text):
        sublime.status_message("%s: %s" % (self.package_name, text))

    def error_message(self, text):
        sublime.error_message("%s: %s" % (self.package_name, text))

    # Output view
    def show_output_panel(self, text=''):
        if self.silent:
            self.status_message(text)
            return
        
        if self.results_in_new_tab:
            new_tab_path = os.path.join(self.commandbox_results_path(), "Commandbox Results")
            self.output_view = self.window.open_file(new_tab_path)
            self.output_view.set_scratch(True)
        else:
            self.output_view = self.window.get_output_panel("commandbox_output")
            self.show_panel()
            
        self.output_view.settings().set("scroll_past_end", False)
        self.add_syntax()
        self.appendToOutput(text)

    def commandbox_results_path(self):
        return next(folder_path for folder_path in self.searchable_folders if self.working_dir.find(folder_path) != -1) if self.working_dir else ""

    def commandbox_results_view(self):
        if self.output_view is None:
            commandbox_results = [view for view in sublime.active_window().views() if view.file_name() and os.path.basename(view.file_name()) == "Gulp Results"]
            return commandbox_results[0] if len(commandbox_results) > 0 else None
        else:
            return self.output_view

    def add_syntax(self):
        if self.settings.has("syntax_override"):
            syntax_file = self.settings.get("syntax_override")
        else:
            syntax_file = self.settings.get_from_user_settings("syntax", "Packages/Gulp/syntax/GulpResults.tmLanguage")
            
        if syntax_file:
            self.output_view.set_syntax_file(syntax_file)

    def appendToMainThreadOutput(self, text):
        self.defer_sync(lambda: self.appendToOutput(text))

    def appendToOutput(self, text):
        if not self.silent:
            decoded_text = text if is_sublime_text_3 else CrossPlatformCodecs.force_decode(text)
            self._insert(self.output_view, decoded_text)

    def _insert(self, view, content):
        if view is None:
            return

        if self.results_in_new_tab and view.is_loading():
            self.set_timeout(lambda: self._insert(view, content), 15)
        else:
            view.set_read_only(False)
            view.run_command("view_insert", { "size": view.size(), "content": content })
            view.set_viewport_position((0, view.size()), True)
            view.set_read_only(True)

    def setOutputCloseOnTimeout(self):
        timeout = self.settings.get("results_autoclose_timeout_in_milliseconds", False)
        if timeout:
            self.set_timeout(self.close_panel, timeout)

    def close_panel(self):
        if self.results_in_new_tab:
            self.output_view = self.commandbox_results_view()
            if self.output_view and self.output_view.file_name():
                self.window.focus_view(self.output_view)
                self.window.run_command('close_file')
        else:
            self.window.run_command("hide_panel", { "panel": "output.commandbox_output" })

    def show_panel(self):
        self.window.run_command("show_panel", { "panel": "output.commandbox_output" })

    # Sync/async calls
    def defer_sync(self, fn):
        self.set_timeout(fn, 0)

    def defer(self, fn):
        self.async(fn, 0)

    def set_timeout(self, fn, delay):
        sublime.set_timeout(fn, delay)
        
    def async(self, fn, delay):
        if is_sublime_text_3:
            progress = ProgressNotifier("Commandbox: Running...\n\n")
            sublime.set_timeout_async(lambda: self.call(fn, progress), delay)
        else:
            fn()
开发者ID:Ortus-Solutions,项目名称:sublime-commandbox,代码行数:104,代码来源:BaseCommand.py


注:本文中的settings.Settings.get_from_user_settings方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。