python类set_clipboard()的实例源码

SideBar.py 文件源码 项目:.sublime 作者: cxdongjack 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def run(self, paths = []):
        items = []

        for item in SideBarSelection(paths).getSelectedItems():
            if item.isUnderCurrentProject():
                items.append(item.url('url_production'))

        if len(items) > 0:
            sublime.set_clipboard("\n".join(items));
            if len(items) > 1 :
                sublime.status_message("Items URL copied")
            else :
                sublime.status_message("Item URL copied")
imp_developer.py 文件源码 项目:ElectricImp-Sublime 作者: electricimp 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def run(self):
        self.init_env_and_settings()

        def check_settings_callback():
            settings = self.load_settings()
            if EI_DEVICE_ID in settings:
                device_id = settings.get(EI_DEVICE_ID)
                response, code = HTTP.get(self.env.project_manager.get_build_api_key(),
                                          PL_BUILD_API_URL_V4 + "devices/" + device_id)
                agent_id = response.get("device").get("agent_id")
                agent_url = PL_AGENT_URL.format(agent_id)
                sublime.set_clipboard(agent_url)
                sublime.message_dialog(STR_AGENT_URL_COPIED.format(device_id, agent_url))

        self.check_settings(callback=check_settings_callback)
SingleTrailingNewLine.py 文件源码 项目:sublime-single-trailing-new-line 作者: mattst 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def run(self, edit):

        syntax_current_file = self.view.settings().get("syntax")
        sublime.set_clipboard(syntax_current_file)

        msg = "Syntax copied to the clipboard"
        sublime.status_message(msg)
registers.py 文件源码 项目:VintageousPlus 作者: trishume 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def _maybe_set_sys_clipboard(self, name, value):
        # We actually need to check whether the option is set to a bool; could
        # be any JSON type.
        if (name in REG_SYS_CLIPBOARD_ALL or
           self.settings.view['vintageous_use_sys_clipboard'] is True):
                # Make sure Sublime Text does the right thing in the presence
                # of multiple selections.
                if len(value) > 1:
                    self.view.run_command('copy')
                else:
                    sublime.set_clipboard(value[0])
test_registers.py 文件源码 项目:VintageousPlus 作者: trishume 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def setUp(self):
        super().setUp()
        sublime.set_clipboard('')
        registers._REGISTER_DATA = registers.init_register_data()
        self.view.settings().erase('vintage')
        self.view.settings().erase('vintageous_use_sys_clipboard')
        # self.regs = Registers(view=self.view,
                              # settings=SettingsManager(view=self.view))
        self.regs = State(self.view).registers
test_registers.py 文件源码 项目:VintageousPlus 作者: trishume 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def testGetSysClipboardAlwaysIfRequested(self):
        self.regs.settings.view['vintageous_use_sys_clipboard'] = True
        sublime.set_clipboard('foo')
        self.assertEqual(self.regs.get(), ['foo'])
test_registers.py 文件源码 项目:VintageousPlus 作者: trishume 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def setUp(self):
        super().setUp()
        sublime.set_clipboard('')
        registers._REGISTER_DATA = registers.init_register_data()
        self.view.settings().erase('vintage')
        self.view.settings().erase('vintageous_use_sys_clipboard')
        self.regs = State(self.view).registers
        self.regs.view = mock.Mock()
test_registers.py 文件源码 项目:VintageousPlus 作者: trishume 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def setUp(self):
        super().setUp()
        sublime.set_clipboard('')
        registers._REGISTER_DATA = registers.init_register_data()
        self.view.settings().erase('vintage')
        self.view.settings().erase('vintageous_use_sys_clipboard')
        self.regs = State(self.view).registers
        self.regs.view = mock.Mock()
show_scope_name.py 文件源码 项目:st-user-package 作者: math2001 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def copy(view, text):
    sublime.set_clipboard(text)
    view.hide_popup()
    sublime.status_message('Scope name copied to clipboard')
Confluence.py 文件源码 项目:SublimeConfluence 作者: mlf4aiur 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def update_from_editor(self):
        # Example Data:
        """
        {
          "id": "3604482",
          "type": "page",
          "title": "new page",
          "space": {
            "key": "TST"
          },
          "body": {
            "storage": {
              "value": "<p>This is the updated text for the new page</p>",
              "representation": "storage"
            }
          },
          "version": {
            "number": 2
          }
        }
        """
        content_id = self.content["id"]
        title = self.content["title"]
        space_key = self.content["space"]["key"]
        version_number = self.content["version"]["number"] + 1
        region = sublime.Region(0, self.view.size())
        contents = self.view.substr(region)
        syntax = self.view.settings().get("syntax")
        if "HTML" in syntax:
            new_content = "".join(contents.split("\n"))
        else:
            markup = Markup()
            meta, content = markup.get_meta_and_content(contents)
            new_content = markup.to_html("\n".join(content), syntax)

        space = dict(key=space_key)
        version = dict(number=version_number, minorEdit=False)
        body = dict(storage=dict(value=new_content, representation="storage"))
        data = dict(id=content_id, type="page", title=title,
                    space=space, version=version, body=body)
        try:
            self.confluence_api = ConfluenceApi(self.username, self.password, self.base_uri)
            response = self.confluence_api.update_content(content_id, data)
            if response.ok:
                content_uri = self.confluence_api.get_content_uri(self.content)
                sublime.set_clipboard(content_uri)
                sublime.status_message(self.MSG_SUCCESS)
                self.view.settings().set("confluence_content", response.json())
            else:
                print(response.text)
                sublime.error_message("Can't update content, reason: {}".format(response.reason))
        except Exception:
            print(response.text)
            sublime.error_message("Can't update content, reason: {}".format(response.reason))
Confluence.py 文件源码 项目:SublimeConfluence 作者: mlf4aiur 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def update_from_source(self):
        region = sublime.Region(0, self.view.size())
        contents = self.view.substr(region)
        markup = Markup()
        meta, content = markup.get_meta_and_content(contents)
        syntax = self.view.settings().get("syntax")
        new_content = markup.to_html("\n".join(content), syntax)
        if not new_content:
            sublime.error_message(
                "Can't update: this doesn't appear to be a valid Confluence page.")
            return
        self.confluence_api = ConfluenceApi(self.username, self.password, self.base_uri)

        get_content_by_title_resp = self.confluence_api.get_content_by_title(
            meta["space_key"], meta["title"])
        if get_content_by_title_resp.ok:
            content_id = get_content_by_title_resp.json()["results"][0]["id"]

            get_content_by_id_resp = self.confluence_api.get_content_by_id(content_id)
            if get_content_by_id_resp.ok:
                content = get_content_by_id_resp.json()
                space = dict(key=meta["space_key"])
                version_number = content["version"]["number"] + 1
                version = dict(number=version_number, minorEdit=False)
                # ancestor_id = int(ancestor["id"])
                body = dict(storage=dict(value=new_content, representation="storage"))
                data = dict(id=content_id, type="page", title=meta["title"],
                            space=space, version=version, body=body)

                update_content_resp = self.confluence_api.update_content(content_id, data)
                if update_content_resp.ok:
                    self.view.settings().set("confluence_content", update_content_resp.json())
                    content_uri = self.confluence_api.get_content_uri(update_content_resp.json())
                    sublime.set_clipboard(content_uri)
                    sublime.status_message(self.MSG_SUCCESS)
                else:
                    print(update_content_resp.text)
                    sublime.error_message("Can not update content, reason: {}".format(
                        update_content_resp.reason))
            else:
                print(get_content_by_id_resp.text)
                sublime.error_message("Can not get content by id, reason: {}".format(
                    get_content_by_id_resp.reason))
        else:
            print(get_content_by_title_resp.text)
            sublime.error_message("Can not get content by title, reason: {}".format(
                get_content_by_title_resp.reason))
environment.py 文件源码 项目:a-file-icon 作者: ihodev 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def run(self):
        info = {}

        info["platform"] = sublime.platform()
        info["sublime_version"] = sublime.version()

        info["current_theme"] = get_current()
        info["installed_themes"] = "".join([
            "\n  <li>{}</li>".format(k) for k in get_installed().keys()
        ])

        info["package_version"] = _get_package_version()
        info["installed_via_pc"] = _is_installed_via_pc()

        msg = """\
            <b>Platform:</b> %(platform)s<br>
            <b>A File Icon:</b> %(package_version)s<br>
            <b>Sublime Text:</b> %(sublime_version)s<br>
            <b>Package Control:</b> %(installed_via_pc)s<br>
            <b>Current Theme:</b> %(current_theme)s<br>
            <b>Installed Themes:</b><br>
            <ul>%(installed_themes)s
            </ul>
        """ % info

        html = """\
            <div id="afi-environment">
                <style>
                    #afi-environment {
                        padding: 0.5rem;
                        line-height: 1.5;
                    }
                    #afi-environment ul {
                        margin-top: 0.5rem;
                        margin-bottom: 0;
                        margin-left: 1rem;
                    }
                    #afi-environment a {
                        display: inline;
                    }
                </style>
                <a href="copy">Copy</a><br><br>
                %(msg)s
            </div>
        """ % {"msg": msg}

        window = sublime.active_window()
        view = window.active_view()
        window.focus_view(view)
        row = int(view.rowcol(view.visible_region().a)[0] + 1)

        def on_navigate(href):
            if (href.startswith("copy")):
                sublime.set_clipboard(msg.replace("    ", ""))
            view.hide_popup()

        view.show_popup(html,
                        location=view.text_point(row, 5),
                        max_width=800,
                        max_height=800,
                        on_navigate=on_navigate)


问题


面经


文章

微信
公众号

扫码关注公众号