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


Python win32con.CF_TEXT属性代码示例

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


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

示例1: __init__

# 需要导入模块: import win32con [as 别名]
# 或者: from win32con import CF_TEXT [as 别名]
def __init__(self, contents=None, text=None, from_system=False):
        self._contents = {}

        # If requested, retrieve current system clipboard contents.
        if from_system:
            self.copy_from_system()

        # Process given contents for this Clipboard instance.
        if contents:
            try:
                self._contents = dict(contents)
            except Exception as e:
                raise TypeError("Invalid contents: %s (%r)" % (e, contents))

        # Handle special case of text content.
        if not text is None:
            self._contents[self.format_unicode] = text_type(text)

        # Use a binary string for CF_TEXT content.
        cf_text_content = self._contents.get(self.format_text)
        if isinstance(cf_text_content, text_type):
            enc = locale.getpreferredencoding()
            self._contents[self.format_text] = cf_text_content.encode(enc) 
开发者ID:dictation-toolbox,项目名称:dragonfly,代码行数:25,代码来源:clipboard.py

示例2: test_unicode_text

# 需要导入模块: import win32con [as 别名]
# 或者: from win32con import CF_TEXT [as 别名]
def test_unicode_text(self):
        val = "test-val"
        SetClipboardText(val)
        # GetClipboardData doesn't to auto string conversions - so on py3k,
        # CF_TEXT returns bytes.
        expected = str2bytes(val)
        self.failUnlessEqual(GetClipboardData(win32con.CF_TEXT), expected)
        SetClipboardText(val, win32con.CF_UNICODETEXT)
        self.failUnlessEqual(GetClipboardData(win32con.CF_UNICODETEXT), val) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:11,代码来源:test_clipboard.py

示例3: test_string

# 需要导入模块: import win32con [as 别名]
# 或者: from win32con import CF_TEXT [as 别名]
def test_string(self):
        val = str2bytes("test")
        SetClipboardData(win32con.CF_TEXT, val)
        self.failUnlessEqual(GetClipboardData(win32con.CF_TEXT), val) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:6,代码来源:test_clipboard.py

示例4: test_mem

# 需要导入模块: import win32con [as 别名]
# 或者: from win32con import CF_TEXT [as 别名]
def test_mem(self):
        val = str2bytes("test")
        expected = str2bytes("test\0")
        SetClipboardData(win32con.CF_TEXT, val)
        # Get the raw data - this will include the '\0'
        raw_data = GetGlobalMemory(GetClipboardDataHandle(win32con.CF_TEXT))
        self.failUnlessEqual(expected, raw_data) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:9,代码来源:test_clipboard.py

示例5: __init__

# 需要导入模块: import win32con [as 别名]
# 或者: from win32con import CF_TEXT [as 别名]
def __init__(self, strval):
        global num_do_objects
        num_do_objects += 1
        self.strval = strval
        self.supported_fe = []
        for cf in (win32con.CF_TEXT, win32con.CF_UNICODETEXT):
            fe = cf, None, pythoncom.DVASPECT_CONTENT, -1, pythoncom.TYMED_HGLOBAL
            self.supported_fe.append(fe) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:10,代码来源:testClipboard.py

示例6: testComToWin32

# 需要导入模块: import win32con [as 别名]
# 或者: from win32con import CF_TEXT [as 别名]
def testComToWin32(self):
        # Set the data via our DataObject
        do = TestDataObject("Hello from Python")
        do = WrapCOMObject(do, iid=pythoncom.IID_IDataObject)
        pythoncom.OleSetClipboard(do)
        # Then get it back via the standard win32 clipboard functions.
        win32clipboard.OpenClipboard()
        got = win32clipboard.GetClipboardData(win32con.CF_TEXT)
        # CF_TEXT gives bytes on py3k - use str2bytes() to ensure that's true.
        expected = str2bytes("Hello from Python")
        self.assertEqual(got, expected)
        # Now check unicode
        got = win32clipboard.GetClipboardData(win32con.CF_UNICODETEXT)
        self.assertEqual(got, u"Hello from Python")
        win32clipboard.CloseClipboard() 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:17,代码来源:testClipboard.py

示例7: testWin32ToCom

# 需要导入模块: import win32con [as 别名]
# 或者: from win32con import CF_TEXT [as 别名]
def testWin32ToCom(self):
        # Set the data via the std win32 clipboard functions.
        val = str2bytes("Hello again!") # ensure always bytes, even in py3k
        win32clipboard.OpenClipboard()
        win32clipboard.SetClipboardData(win32con.CF_TEXT, val)
        win32clipboard.CloseClipboard()
        # and get it via an IDataObject provided by COM
        do = pythoncom.OleGetClipboard()
        cf = win32con.CF_TEXT, None, pythoncom.DVASPECT_CONTENT, -1, pythoncom.TYMED_HGLOBAL
        stg = do.GetData(cf)
        got = stg.data
        # The data we get back has the \0, as our STGMEDIUM has no way of 
        # knowing if it meant to be a string, or a binary buffer, so
        # it must return it too.
        self.failUnlessEqual(got, str2bytes("Hello again!\0")) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:17,代码来源:testClipboard.py

示例8: TestText

# 需要导入模块: import win32con [as 别名]
# 或者: from win32con import CF_TEXT [as 别名]
def TestText():
    OpenClipboard()
    try:
        text = "Hello from Python"
        text_bytes = str2bytes(text)
        SetClipboardText(text)
        got = GetClipboardData(win32con.CF_TEXT)
        # CF_TEXT always gives us 'bytes' back .
        assert  got == text_bytes, "Didnt get the correct result back - '%r'." % (got,)
    finally:
        CloseClipboard()

    OpenClipboard()
    try:
        # CF_UNICODE text always gives unicode objects back.
        got = GetClipboardData(win32con.CF_UNICODETEXT)
        assert  got == text, "Didnt get the correct result back - '%r'." % (got,)
        assert type(got)==types.UnicodeType, "Didnt get the correct result back - '%r'." % (got,)

        # CF_OEMTEXT is a bytes-based format.
        got = GetClipboardData(win32con.CF_OEMTEXT)
        assert  got == text_bytes, "Didnt get the correct result back - '%r'." % (got,)

        # Unicode tests
        EmptyClipboard()
        text = u"Hello from Python unicode"
        text_bytes = str2bytes(text)
        # Now set the Unicode value
        SetClipboardData(win32con.CF_UNICODETEXT, text)
        # Get it in Unicode.
        got = GetClipboardData(win32con.CF_UNICODETEXT)
        assert  got == text, "Didnt get the correct result back - '%r'." % (got,)
        assert type(got)==types.UnicodeType, "Didnt get the correct result back - '%r'." % (got,)

        # Close and open the clipboard to ensure auto-conversions take place.
    finally:
        CloseClipboard()

    OpenClipboard()
    try:

        # Make sure I can still get the text as bytes
        got = GetClipboardData(win32con.CF_TEXT)
        assert  got == text_bytes, "Didnt get the correct result back - '%r'." % (got,)
        # Make sure we get back the correct types.
        got = GetClipboardData(win32con.CF_UNICODETEXT)
        assert type(got)==types.UnicodeType, "Didnt get the correct result back - '%r'." % (got,)
        got = GetClipboardData(win32con.CF_OEMTEXT)
        assert  got == text_bytes, "Didnt get the correct result back - '%r'." % (got,)
        print "Clipboard text tests worked correctly"
    finally:
        CloseClipboard() 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:54,代码来源:win32clipboardDemo.py


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