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

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import unittest
  5. import pythoncom
  6. import win32con
  7. import winerror
  8. import win32clipboard
  9. from win32com.server.util import NewEnum, wrap
  10. from win32com.server.exception import COMException
  11. IDataObject_Methods = 'GetData GetDataHere QueryGetData\n                         GetCanonicalFormatEtc SetData EnumFormatEtc\n                         DAdvise DUnadvise EnumDAdvise'.split()
  12. num_do_objects = 0
  13.  
  14. def WrapCOMObject(ob, iid = None):
  15.     return wrap(ob, iid = iid, useDispatcher = 0)
  16.  
  17.  
  18. class TestDataObject:
  19.     _com_interfaces_ = [
  20.         pythoncom.IID_IDataObject]
  21.     _public_methods_ = IDataObject_Methods
  22.     
  23.     def __init__(self, strval):
  24.         global num_do_objects
  25.         num_do_objects += 1
  26.         self.strval = strval
  27.         self.supported_fe = []
  28.         for cf in (win32con.CF_TEXT, win32con.CF_UNICODETEXT):
  29.             fe = (cf, None, pythoncom.DVASPECT_CONTENT, -1, pythoncom.TYMED_HGLOBAL)
  30.             self.supported_fe.append(fe)
  31.         
  32.  
  33.     
  34.     def __del__(self):
  35.         global num_do_objects
  36.         num_do_objects -= 1
  37.  
  38.     
  39.     def _query_interface_(self, iid):
  40.         if iid == pythoncom.IID_IEnumFORMATETC:
  41.             return NewEnum(self.supported_fe, iid = iid)
  42.  
  43.     
  44.     def GetData(self, fe):
  45.         ret_stg = None
  46.         (cf, target, aspect, index, tymed) = fe
  47.         if aspect & pythoncom.DVASPECT_CONTENT and tymed == pythoncom.TYMED_HGLOBAL:
  48.             if cf == win32con.CF_TEXT:
  49.                 ret_stg = pythoncom.STGMEDIUM()
  50.                 ret_stg.set(pythoncom.TYMED_HGLOBAL, self.strval)
  51.             elif cf == win32con.CF_UNICODETEXT:
  52.                 ret_stg = pythoncom.STGMEDIUM()
  53.                 ret_stg.set(pythoncom.TYMED_HGLOBAL, unicode(self.strval))
  54.             
  55.         
  56.         if ret_stg is None:
  57.             raise COMException(hresult = winerror.E_NOTIMPL)
  58.         ret_stg is None
  59.         return ret_stg
  60.  
  61.     
  62.     def GetDataHere(self, fe):
  63.         raise COMException(hresult = winerror.E_NOTIMPL)
  64.  
  65.     
  66.     def QueryGetData(self, fe):
  67.         (cf, target, aspect, index, tymed) = fe
  68.         if aspect & pythoncom.DVASPECT_CONTENT == 0:
  69.             raise COMException(hresult = winerror.DV_E_DVASPECT)
  70.         aspect & pythoncom.DVASPECT_CONTENT == 0
  71.         if tymed != pythoncom.TYMED_HGLOBAL:
  72.             raise COMException(hresult = winerror.DV_E_TYMED)
  73.         tymed != pythoncom.TYMED_HGLOBAL
  74.  
  75.     
  76.     def GetCanonicalFormatEtc(self, fe):
  77.         RaiseCOMException(winerror.DATA_S_SAMEFORMATETC)
  78.  
  79.     
  80.     def SetData(self, fe, medium):
  81.         raise COMException(hresult = winerror.E_NOTIMPL)
  82.  
  83.     
  84.     def EnumFormatEtc(self, direction):
  85.         if direction != pythoncom.DATADIR_GET:
  86.             raise COMException(hresult = winerror.E_NOTIMPL)
  87.         direction != pythoncom.DATADIR_GET
  88.         return NewEnum(self.supported_fe, iid = pythoncom.IID_IEnumFORMATETC)
  89.  
  90.     
  91.     def DAdvise(self, fe, flags, sink):
  92.         raise COMException(hresult = winerror.E_NOTIMPL)
  93.  
  94.     
  95.     def DUnadvise(self, connection):
  96.         raise COMException(hresult = winerror.E_NOTIMPL)
  97.  
  98.     
  99.     def EnumDAdvise(self):
  100.         raise COMException(hresult = winerror.E_NOTIMPL)
  101.  
  102.  
  103.  
  104. class ClipboardTester(unittest.TestCase):
  105.     
  106.     def setUp(self):
  107.         pythoncom.OleInitialize()
  108.  
  109.     
  110.     def tearDown(self):
  111.         
  112.         try:
  113.             pythoncom.OleFlushClipboard()
  114.         except pythoncom.com_error:
  115.             pass
  116.  
  117.  
  118.     
  119.     def testIsCurrentClipboard(self):
  120.         do = TestDataObject('Hello from Python')
  121.         do = WrapCOMObject(do, iid = pythoncom.IID_IDataObject)
  122.         pythoncom.OleSetClipboard(do)
  123.         self.failUnless(pythoncom.OleIsCurrentClipboard(do))
  124.  
  125.     
  126.     def testComToWin32(self):
  127.         do = TestDataObject('Hello from Python')
  128.         do = WrapCOMObject(do, iid = pythoncom.IID_IDataObject)
  129.         pythoncom.OleSetClipboard(do)
  130.         win32clipboard.OpenClipboard()
  131.         got = win32clipboard.GetClipboardData(win32con.CF_TEXT)
  132.         self.assertEqual(got, 'Hello from Python')
  133.         got = win32clipboard.GetClipboardData(win32con.CF_UNICODETEXT)
  134.         self.assertEqual(got, u'Hello from Python')
  135.         win32clipboard.CloseClipboard()
  136.  
  137.     
  138.     def testWin32ToCom(self):
  139.         val = 'Hello again!'
  140.         win32clipboard.OpenClipboard()
  141.         win32clipboard.SetClipboardData(win32con.CF_TEXT, val)
  142.         win32clipboard.CloseClipboard()
  143.         do = pythoncom.OleGetClipboard()
  144.         cf = (win32con.CF_TEXT, None, pythoncom.DVASPECT_CONTENT, -1, pythoncom.TYMED_HGLOBAL)
  145.         stg = do.GetData(cf)
  146.         got = stg.data
  147.         self.failUnlessEqual(got, val + '\x00')
  148.  
  149.     
  150.     def testDataObjectFlush(self):
  151.         do = TestDataObject('Hello from Python')
  152.         do = WrapCOMObject(do, iid = pythoncom.IID_IDataObject)
  153.         pythoncom.OleSetClipboard(do)
  154.         self.assertEqual(num_do_objects, 1)
  155.         do = None
  156.         pythoncom.OleFlushClipboard()
  157.         self.assertEqual(num_do_objects, 0)
  158.  
  159.     
  160.     def testDataObjectReset(self):
  161.         do = TestDataObject('Hello from Python')
  162.         do = WrapCOMObject(do)
  163.         pythoncom.OleSetClipboard(do)
  164.         do = None
  165.         self.assertEqual(num_do_objects, 1)
  166.         pythoncom.OleSetClipboard(None)
  167.         self.assertEqual(num_do_objects, 0)
  168.  
  169.  
  170. if __name__ == '__main__':
  171.     import util
  172.     util.testmain()
  173.  
  174.