home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_2506 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-08-06  |  3.1 KB  |  124 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. from win32clipboard import *
  5. import win32con
  6. import types
  7. if not __debug__:
  8.     print 'WARNING: The test code in this module uses assert'
  9.     print 'This instance of Python has asserts disabled, so many tests will be skipped'
  10.  
  11. cf_names = { }
  12. for name, val in win32con.__dict__.items():
  13.     if name[:3] == 'CF_' and name != 'CF_SCREENFONTS':
  14.         cf_names[val] = name
  15.         continue
  16.  
  17.  
  18. def TestEmptyClipboard():
  19.     OpenClipboard()
  20.     
  21.     try:
  22.         EmptyClipboard()
  23.     finally:
  24.         CloseClipboard()
  25.  
  26.  
  27.  
  28. def TestText():
  29.     OpenClipboard()
  30.     
  31.     try:
  32.         text = 'Hello from Python'
  33.         SetClipboardText(text)
  34.         got = GetClipboardData(win32con.CF_TEXT)
  35.     finally:
  36.         CloseClipboard()
  37.  
  38.     OpenClipboard()
  39.     
  40.     try:
  41.         got = GetClipboardData(win32con.CF_UNICODETEXT)
  42.         got = GetClipboardData(win32con.CF_OEMTEXT)
  43.         EmptyClipboard()
  44.         text = u'Hello from Python unicode'
  45.         SetClipboardData(win32con.CF_UNICODETEXT, text)
  46.         got = GetClipboardData(win32con.CF_UNICODETEXT)
  47.     finally:
  48.         CloseClipboard()
  49.  
  50.     OpenClipboard()
  51.     
  52.     try:
  53.         got = GetClipboardData(win32con.CF_TEXT)
  54.         got = GetClipboardData(win32con.CF_UNICODETEXT)
  55.         got = GetClipboardData(win32con.CF_OEMTEXT)
  56.         print 'Clipboard text tests worked correctly'
  57.     finally:
  58.         CloseClipboard()
  59.  
  60.  
  61.  
  62. def TestClipboardEnum():
  63.     OpenClipboard()
  64.     
  65.     try:
  66.         enum = 0
  67.         while None:
  68.             enum = EnumClipboardFormats(enum)
  69.             if enum == 0:
  70.                 break
  71.             
  72.             n = cf_names.get(enum, '')
  73.             if not n:
  74.                 
  75.                 try:
  76.                     n = GetClipboardFormatName(enum)
  77.                 except error:
  78.                     n = 'unknown (%s)' % (enum,)
  79.                 except:
  80.                     None<EXCEPTION MATCH>error
  81.                 
  82.  
  83.             print 'Have format', n
  84.             continue
  85.             print 'Clipboard enumerator tests worked correctly'
  86.         CloseClipboard()
  87.         return None
  88.  
  89.  
  90.  
  91. class Foo:
  92.     
  93.     def __init__(self, **kw):
  94.         self.__dict__.update(kw)
  95.  
  96.     
  97.     def __cmp__(self, other):
  98.         return cmp(self.__dict__, other.__dict__)
  99.  
  100.  
  101.  
  102. def TestCustomFormat():
  103.     OpenClipboard()
  104.     
  105.     try:
  106.         fmt = RegisterClipboardFormat('Python Pickle Format')
  107.         import cPickle
  108.         pickled_object = Foo(a = 1, b = 2, Hi = 3)
  109.         SetClipboardData(fmt, cPickle.dumps(pickled_object))
  110.         data = GetClipboardData(fmt)
  111.         loaded_object = cPickle.loads(data)
  112.         print 'Clipboard custom format tests worked correctly'
  113.     finally:
  114.         CloseClipboard()
  115.  
  116.  
  117. if __name__ == '__main__':
  118.     TestEmptyClipboard()
  119.     TestText()
  120.     TestCustomFormat()
  121.     TestClipboardEnum()
  122.     TestEmptyClipboard()
  123.  
  124.