python类windows()的实例源码

SideBarAPI.py 文件源码 项目:.sublime 作者: cxdongjack 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def open(self, use_powershell = True):
        if self.isDirectory():
            import subprocess
            if sublime.platform() == 'osx':
                subprocess.Popen(['/Applications/Utilities/Terminal.app/Contents/MacOS/Terminal', '.'], cwd=self.forCwdSystemPath())
            elif sublime.platform() == 'windows':
                if use_powershell:
                    try:
                        subprocess.Popen(['start', 'powershell'], cwd=self.forCwdSystemPath(), shell=True)
                    except:
                        subprocess.Popen(['start', 'cmd', '.'], cwd=self.forCwdSystemPath(), shell=True)
                else:
                    subprocess.Popen(['start', 'cmd', '.'], cwd=self.forCwdSystemPath(), shell=True)
            elif sublime.platform() == 'linux':
                subprocess.Popen(['gnome-terminal', '.'], cwd=self.forCwdSystemPath())
        else:
            if sublime.platform() == 'osx':
                import subprocess
                subprocess.Popen(['open', self.name()], cwd=self.dirname())
            elif sublime.platform() == 'windows':
                import subprocess
                subprocess.Popen(['start',  '', escapeCMDWindows(self.path())], cwd=self.dirname(), shell=True)
            else:
                from . import desktop
                desktop.open(self.path())
                print('using desktop')
SideBarAPI.py 文件源码 项目:.sublime 作者: cxdongjack 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def _moveMoveViews(self, old, location):
        for window in sublime.windows():
            active_view = window.active_view()
            views = []
            for view in window.views():
                if view.file_name():
                    views.append(view)
            views.reverse();
            for view in views:
                if old == view.file_name():
                    active_view = self._moveMoveView(window, view, location, active_view)
                elif view.file_name().find(old+'\\') == 0:
                    active_view = self._moveMoveView(window, view, view.file_name().replace(old+'\\', location+'\\', 1), active_view)
                elif view.file_name().find(old+'/') == 0:
                    active_view = self._moveMoveView(window, view, view.file_name().replace(old+'/', location+'/', 1), active_view)
SideBarAPI.py 文件源码 项目:.sublime 作者: cxdongjack 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def closeViews(self):
        path = self.path()
        closed_items = []
        for window in sublime.windows():
            active_view = window.active_view()
            views = []
            for view in window.views():
                if view.file_name():
                    views.append(view)
            views.reverse();
            for view in views:
                if path == view.file_name() or view.file_name().find(path+'\\') == 0 or view.file_name().find(path+'/') == 0:
                    if view.window():
                        closed_items.append([view.file_name(), view.window(), view.window().get_view_index(view)])
                    if len(window.views()) == 1:
                        window.new_file()
                    window.focus_view(view)
                    window.run_command('revert')
                    window.run_command('close')

            # try to repaint
            try:
                window.focus_view(active_view)
                window.focus_view(window.active_view())
            except:
                try:
                    window.focus_view(window.active_view())
                except:
                    pass
        return closed_items
MarkdownLivePreview.py 文件源码 项目:MarkdownLivePreview 作者: math2001 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def on_activated_async(self, view):
        vsettings = view.settings()

        if (is_markdown_view(view) and get_settings().get(ON_OPEN)
            and not vsettings.get(PREVIEW_ENABLED)
            and vsettings.get('syntax') != 'Packages/MarkdownLivePreview/' + \
                                           '.sublime/MarkdownLivePreviewSyntax' + \
                                           '.hidden-tmLanguage'
            and not any(filter(lambda window: window.settings().get(PREVIEW_WINDOW) is True,
                               sublime.windows()))):
            sublime.run_command('new_markdown_live_preview')
Log Highlight.py 文件源码 项目:Log-Highlight 作者: poucotm 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def run(self, edit):
        ret = sublime.ok_cancel_dialog('Erase Customized Log Highlight Syntax & Theme ?')
        if ret:
            try:
                wins_l = sublime.windows()
                for w in wins_l:
                    s_view = w.get_output_panel('loghighlight')
                    if s_view:
                        w.run_command("hide_panel", {"panel": "output.loghighlight"})
                        s_view.set_syntax_file('Packages/Log Highlight/Log Highlight.tmLanguage')
                        s_view.settings().set('color_scheme', 'Packages/Log Highlight/Log Highlight.hidden-tmTheme')
                    view_l = w.views()
                    for v in view_l:
                        if check_syntax(v):
                            v.set_syntax_file('Packages/Log Highlight/Log Highlight.tmLanguage')
                            v.settings().set('color_scheme', 'Packages/Log Highlight/Log Highlight.hidden-tmTheme')

                usr_syntax = os.path.join(sublime.packages_path(), 'User/Log Highlight.tmLanguage')
                if os.path.exists(usr_syntax):
                    os.remove(usr_syntax)

                usr_theme = os.path.join(sublime.packages_path(), 'User/Log Highlight.hidden-tmTheme')
                if os.path.exists(usr_theme):
                    os.remove(usr_theme)

            except Exception:
                disp_exept()

##  Log Highlight  ____________________________________________

# to prevent re-run in short time
clients.py 文件源码 项目:LSP 作者: tomv564 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def unload_all_clients():
    for window in sublime.windows():
        for client in window_clients(window).values():
            unload_client(client)
clients.py 文件源码 项目:LSP 作者: tomv564 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def check_window_unloaded():
    global clients_by_window
    open_window_ids = list(window.id() for window in sublime.windows())
    iterable_clients_by_window = clients_by_window.copy()
    closed_windows = []
    for id, window_clients in iterable_clients_by_window.items():
        if id not in open_window_ids:
            debug("window closed", id)
            closed_windows.append(id)
    for closed_window_id in closed_windows:
        unload_window_clients(closed_window_id)
helpers.py 文件源码 项目:sublimeTextConfig 作者: luoye-fe 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def get_window_view(vid):
    """Look for the given vid in all the opened windows
    """

    for window in sublime.windows():
        view = get_view(window, vid)
        if view is not None:
            return view
util.py 文件源码 项目:sublimeTextConfig 作者: luoye-fe 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def create_tempdir():
    """Create a directory within the system temp directory used to create temp files."""
    try:
        if os.path.isdir(tempdir):
            shutil.rmtree(tempdir)

        os.mkdir(tempdir)

        # Make sure the directory can be removed by anyone in case the user
        # runs ST later as another user.
        os.chmod(tempdir, stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO)

    except PermissionError:
        if sublime.platform() != 'windows':
            current_user = pwd.getpwuid(os.geteuid())[0]
            temp_uid = os.stat(tempdir).st_uid
            temp_user = pwd.getpwuid(temp_uid)[0]
            message = (
                'The SublimeLinter temp directory:\n\n{0}\n\ncould not be cleared '
                'because it is owned by \'{1}\' and you are logged in as \'{2}\'. '
                'Please use sudo to remove the temp directory from a terminal.'
            ).format(tempdir, temp_user, current_user)
        else:
            message = (
                'The SublimeLinter temp directory ({}) could not be reset '
                'because it belongs to a different user.'
            ).format(tempdir)

        sublime.error_message(message)

    from . import persist
    persist.debug('temp directory:', tempdir)
Base.py 文件源码 项目:sublimeTextConfig 作者: luoye-fe 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def _search_existing_view(self):
        """
            returns True if a view with the name of
            this ArcticTypescript view is open and sets it as reference
        """
        for w in sublime.windows():
            for v in w.views():
                if v.name() == self.name:
                    self._view_reference = v
                    self.on_overtook_existing_view()
                    return self._is_view_still_open()
        return False
Project.py 文件源码 项目:sublimeTextConfig 作者: luoye-fe 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def __init__(self, startview):

        self.processes = None
        self.compiler = None
        self.errors = None
        self.highlighter = None
        self.tsserver = None
        self.completion = None

        if not startview.is_valid() or startview.window() is None:
            return

        self.id = random_str()
        OPENED_PROJECTS[self.id] = self

        self.project_file_name = startview.window().project_file_name()
        self.windows = [] # All windows with .ts files
        self.error_view = {} #key: window.window_id, value: view
        self.views = [] # All views with .ts files
        self.tsconfigdir = find_tsconfigdir(startview.file_name())
        self.tsconfigfile = os.path.join(self.tsconfigdir, "tsconfig.json")
        self.is_compiling = False
        self.authorized_commands = []
        self.forbidden_commands = []

        self.ArcticTypescript_sublime_settings = sublime.load_settings('ArcticTypescript.sublime-settings')

        self.open(startview)

        self._initialize_project()


    # ###############################################    INIT   ################
Project.py 文件源码 项目:sublimeTextConfig 作者: luoye-fe 项目源码 文件源码 阅读 36 收藏 0 点赞 0 评论 0
def collect_untracked_views_and_update_content(self, on_finished):
        """ Searches for opened ts views which belong to this project,
            add them to this project, transfer the current workspace
            view content to the tsserver and call on_finished afterwards. """

        def _collect_and_update_runner(fileslist):
            fileslist_normcased = [os.path.normcase(f) for f in fileslist]

            for w in sublime.windows():
                for v in w.views():
                    if not is_ts(v):
                        continue
                    v_tsconfigdir = find_tsconfigdir(v.file_name())
                    v_tsconfigfile = os.path.join(v_tsconfigdir, "tsconfig.json")
                    v_tsconfigfile = os.path.normcase(v_tsconfigfile)

                    # belong to same tsconfig AND is already registered in tsconfig[files]
                    # or referenced by other files in tsconfig[files] = fileslist
                    if v_tsconfigfile == os.path.normcase(self.tsconfigfile) \
                            and os.path.normcase(v.file_name()) in fileslist_normcased:
                        self.open(v)
                        self.tsserver.update(v)

            on_finished()

        self.tsserver.get_tss_indexed_files(_collect_and_update_runner)



    # ###############################################    OPEN/CLOSE   ##########
Project.py 文件源码 项目:sublimeTextConfig 作者: luoye-fe 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def close(self, view):
        """ Should be called if a view has been closed. Also accepts views which do not
            belong to this project
            Closes project if no more windows are open. """
        if view in self.views:
            self.views.remove(view)
            Debug('project+', "View %s removed from project %s" % (view.file_name(), self.tsconfigfile))
            for window in self.windows: # view.window() = None, so iterate all
                self._remove_window_if_not_needed(window)


    # ###############################################    KILL   ################
Project.py 文件源码 项目:sublimeTextConfig 作者: luoye-fe 项目源码 文件源码 阅读 70 收藏 0 点赞 0 评论 0
def _tsserverkilled(self):
        if self.processes:
            self.processes.kill()
        self.views = []
        self.windows = []
        OPENED_PROJECTS.pop(self.id)
        if self.on_project_closed:
            self.on_project_closed()
viewutils.py 文件源码 项目:sublimeTextConfig 作者: luoye-fe 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def get_any_ts_view():
    v = sublime.active_window().active_view()
    if is_ts(v) and not is_dts(v):
        return v
    for w in sublime.windows():
        for v in w.views():
            if is_ts(v) and not is_dts(v):
                return v
viewutils.py 文件源码 项目:sublimeTextConfig 作者: luoye-fe 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def get_any_view_with_root(root):
    return
    from .system.Liste import get_root
    v = sublime.active_window().active_view()
    if is_ts(v) and not is_dts(v) and get_root(v.file_name()) == root:
        return v
    for w in sublime.windows():
        for v in w.views():
            if is_ts(v) and not is_dts(v) and get_root(v.file_name()) == root:
                return v
plantuml.py 文件源码 项目:sublime-plantuml 作者: pkucmus 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def find_view(self, img_file_name):
        for window in sublime.windows():
            return window.find_open_file(os.path.abspath(img_file_name))
        return None
Utils.py 文件源码 项目:GhostText-for-SublimeText 作者: GhostText 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def search_views_by_title(needle):
        """
        Search for views in all open windows containing the given needle.
        """
        result = []
        for window in sublime.windows():
            for view in window.views():
                name = Utils.get_name_or_file_name_from_view(view)
                if needle in name:
                    result.append(view)
                if needle == name:
                    result.append(view)

        return result
Utils.py 文件源码 项目:GhostText-for-SublimeText 作者: GhostText 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def find_view_by_id(view_id):
        """
        Finds a view in all open windows containing the given id.
        """
        for window in sublime.windows():
            for view in window.views():
                if view.id() is view_id:
                    return view

        return None
Utils.py 文件源码 项目:GhostText-for-SublimeText 作者: GhostText 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def close_view(view):
        """
        Closes the given view by running the close_by_index command.
        If there are more than one open windows and the window has no more views it gets closed, too.
        """
        window = view.window()
        group_index, view_index = window.get_view_index(view)
        window.run_command('close_by_index', {'group': group_index, 'index': view_index})
        if len(sublime.windows()) > 1 and len(window.views()) is 0:
            window.run_command('close')


问题


面经


文章

微信
公众号

扫码关注公众号