home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyc (Python 2.6)
-
- import unittest
- import pythoncom
- import win32con
- import winerror
- import win32clipboard
- from win32com.server.util import NewEnum, wrap
- from win32com.server.exception import COMException
- IDataObject_Methods = 'GetData GetDataHere QueryGetData\n GetCanonicalFormatEtc SetData EnumFormatEtc\n DAdvise DUnadvise EnumDAdvise'.split()
- num_do_objects = 0
-
- def WrapCOMObject(ob, iid = None):
- return wrap(ob, iid = iid, useDispatcher = 0)
-
-
- class TestDataObject:
- _com_interfaces_ = [
- pythoncom.IID_IDataObject]
- _public_methods_ = IDataObject_Methods
-
- 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)
-
-
-
- def __del__(self):
- global num_do_objects
- num_do_objects -= 1
-
-
- def _query_interface_(self, iid):
- if iid == pythoncom.IID_IEnumFORMATETC:
- return NewEnum(self.supported_fe, iid = iid)
-
-
- def GetData(self, fe):
- ret_stg = None
- (cf, target, aspect, index, tymed) = fe
- if aspect & pythoncom.DVASPECT_CONTENT and tymed == pythoncom.TYMED_HGLOBAL:
- if cf == win32con.CF_TEXT:
- ret_stg = pythoncom.STGMEDIUM()
- ret_stg.set(pythoncom.TYMED_HGLOBAL, self.strval)
- elif cf == win32con.CF_UNICODETEXT:
- ret_stg = pythoncom.STGMEDIUM()
- ret_stg.set(pythoncom.TYMED_HGLOBAL, unicode(self.strval))
-
-
- if ret_stg is None:
- raise COMException(hresult = winerror.E_NOTIMPL)
- ret_stg is None
- return ret_stg
-
-
- def GetDataHere(self, fe):
- raise COMException(hresult = winerror.E_NOTIMPL)
-
-
- def QueryGetData(self, fe):
- (cf, target, aspect, index, tymed) = fe
- if aspect & pythoncom.DVASPECT_CONTENT == 0:
- raise COMException(hresult = winerror.DV_E_DVASPECT)
- aspect & pythoncom.DVASPECT_CONTENT == 0
- if tymed != pythoncom.TYMED_HGLOBAL:
- raise COMException(hresult = winerror.DV_E_TYMED)
- tymed != pythoncom.TYMED_HGLOBAL
-
-
- def GetCanonicalFormatEtc(self, fe):
- RaiseCOMException(winerror.DATA_S_SAMEFORMATETC)
-
-
- def SetData(self, fe, medium):
- raise COMException(hresult = winerror.E_NOTIMPL)
-
-
- def EnumFormatEtc(self, direction):
- if direction != pythoncom.DATADIR_GET:
- raise COMException(hresult = winerror.E_NOTIMPL)
- direction != pythoncom.DATADIR_GET
- return NewEnum(self.supported_fe, iid = pythoncom.IID_IEnumFORMATETC)
-
-
- def DAdvise(self, fe, flags, sink):
- raise COMException(hresult = winerror.E_NOTIMPL)
-
-
- def DUnadvise(self, connection):
- raise COMException(hresult = winerror.E_NOTIMPL)
-
-
- def EnumDAdvise(self):
- raise COMException(hresult = winerror.E_NOTIMPL)
-
-
-
- class ClipboardTester(unittest.TestCase):
-
- def setUp(self):
- pythoncom.OleInitialize()
-
-
- def tearDown(self):
-
- try:
- pythoncom.OleFlushClipboard()
- except pythoncom.com_error:
- pass
-
-
-
- def testIsCurrentClipboard(self):
- do = TestDataObject('Hello from Python')
- do = WrapCOMObject(do, iid = pythoncom.IID_IDataObject)
- pythoncom.OleSetClipboard(do)
- self.failUnless(pythoncom.OleIsCurrentClipboard(do))
-
-
- def testComToWin32(self):
- do = TestDataObject('Hello from Python')
- do = WrapCOMObject(do, iid = pythoncom.IID_IDataObject)
- pythoncom.OleSetClipboard(do)
- win32clipboard.OpenClipboard()
- got = win32clipboard.GetClipboardData(win32con.CF_TEXT)
- self.assertEqual(got, 'Hello from Python')
- got = win32clipboard.GetClipboardData(win32con.CF_UNICODETEXT)
- self.assertEqual(got, u'Hello from Python')
- win32clipboard.CloseClipboard()
-
-
- def testWin32ToCom(self):
- val = 'Hello again!'
- win32clipboard.OpenClipboard()
- win32clipboard.SetClipboardData(win32con.CF_TEXT, val)
- win32clipboard.CloseClipboard()
- do = pythoncom.OleGetClipboard()
- cf = (win32con.CF_TEXT, None, pythoncom.DVASPECT_CONTENT, -1, pythoncom.TYMED_HGLOBAL)
- stg = do.GetData(cf)
- got = stg.data
- self.failUnlessEqual(got, val + '\x00')
-
-
- def testDataObjectFlush(self):
- do = TestDataObject('Hello from Python')
- do = WrapCOMObject(do, iid = pythoncom.IID_IDataObject)
- pythoncom.OleSetClipboard(do)
- self.assertEqual(num_do_objects, 1)
- do = None
- pythoncom.OleFlushClipboard()
- self.assertEqual(num_do_objects, 0)
-
-
- def testDataObjectReset(self):
- do = TestDataObject('Hello from Python')
- do = WrapCOMObject(do)
- pythoncom.OleSetClipboard(do)
- do = None
- self.assertEqual(num_do_objects, 1)
- pythoncom.OleSetClipboard(None)
- self.assertEqual(num_do_objects, 0)
-
-
- if __name__ == '__main__':
- import util
- util.testmain()
-
-