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

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import pythoncom
  5. import win32com.server.util as win32com
  6. import util
  7. import time
  8. import win32com
  9. import sys
  10. import string
  11. import win32api
  12. import traceback
  13. import win32com.client.dynamic as win32com
  14. import win32com.client as win32com
  15. import pythoncom
  16. from win32com.axcontrol import axcontrol
  17. from pywintypes import Unicode
  18. from win32com import storagecon
  19. from win32com.test.util import CheckClean
  20. import pywintypes
  21. import win32ui
  22. import win32api
  23. import os
  24. S_OK = 0
  25.  
  26. class LockBytes:
  27.     _public_methods_ = [
  28.         'ReadAt',
  29.         'WriteAt',
  30.         'Flush',
  31.         'SetSize',
  32.         'LockRegion',
  33.         'UnlockRegion',
  34.         'Stat']
  35.     _com_interfaces_ = [
  36.         pythoncom.IID_ILockBytes]
  37.     
  38.     def __init__(self, data = ''):
  39.         self.data = data
  40.         now = pywintypes.Time(time.time())
  41.         self.ctime = now
  42.         self.mtime = now
  43.         self.atime = now
  44.  
  45.     
  46.     def ReadAt(self, offset, cb):
  47.         print 'ReadAt'
  48.         result = self.data[offset:offset + cb]
  49.         return result
  50.  
  51.     
  52.     def WriteAt(self, offset, data):
  53.         print 'WriteAt ' + str(offset)
  54.         print 'len ' + str(len(data))
  55.         print 'data:'
  56.         if len(self.data) >= offset:
  57.             newdata = self.data[0:offset] + data
  58.         
  59.         print len(newdata)
  60.         if len(self.data) >= offset + len(data):
  61.             newdata = newdata + self.data[offset + len(data):]
  62.         
  63.         print len(newdata)
  64.         self.data = newdata
  65.         return len(data)
  66.  
  67.     
  68.     def Flush(self, whatsthis = 0):
  69.         print 'Flush' + str(whatsthis)
  70.         fname = os.path.join(win32api.GetTempPath(), 'persist.doc')
  71.         open(fname, 'wb').write(self.data)
  72.         return S_OK
  73.  
  74.     
  75.     def SetSize(self, size):
  76.         print 'Set Size' + str(size)
  77.         if size > len(self.data):
  78.             self.data = self.data + '\x00' * (size - len(self.data))
  79.         else:
  80.             self.data = self.data[0:size]
  81.         return S_OK
  82.  
  83.     
  84.     def LockRegion(self, offset, size, locktype):
  85.         print 'LockRegion'
  86.  
  87.     
  88.     def UnlockRegion(self, offset, size, locktype):
  89.         print 'UnlockRegion'
  90.  
  91.     
  92.     def Stat(self, statflag):
  93.         print 'returning Stat ' + str(statflag)
  94.         return ('PyMemBytes', storagecon.STGTY_LOCKBYTES, len(self.data), self.mtime, self.ctime, self.atime, storagecon.STGM_DIRECT | storagecon.STGM_READWRITE | storagecon.STGM_CREATE, storagecon.STGM_SHARE_EXCLUSIVE, '{00020905-0000-0000-C000-000000000046}', 0, 0)
  95.  
  96.  
  97.  
  98. class OleClientSite:
  99.     _public_methods_ = [
  100.         'SaveObject',
  101.         'GetMoniker',
  102.         'GetContainer',
  103.         'ShowObject',
  104.         'OnShowWindow',
  105.         'RequestNewObjectLayout']
  106.     _com_interfaces_ = [
  107.         axcontrol.IID_IOleClientSite]
  108.     
  109.     def __init__(self, data = ''):
  110.         self.IPersistStorage = None
  111.         self.IStorage = None
  112.  
  113.     
  114.     def SetIPersistStorage(self, IPersistStorage):
  115.         self.IPersistStorage = IPersistStorage
  116.  
  117.     
  118.     def SetIStorage(self, IStorage):
  119.         self.IStorage = IStorage
  120.  
  121.     
  122.     def SaveObject(self):
  123.         print 'SaveObject'
  124.         if self.IPersistStorage != None and self.IStorage != None:
  125.             self.IPersistStorage.Save(self.IStorage, 1)
  126.             self.IStorage.Commit(0)
  127.         
  128.         return S_OK
  129.  
  130.     
  131.     def GetMoniker(self, dwAssign, dwWhichMoniker):
  132.         print 'GetMoniker ' + str(dwAssign) + ' ' + str(dwWhichMoniker)
  133.  
  134.     
  135.     def GetContainer(self):
  136.         print 'GetContainer'
  137.  
  138.     
  139.     def ShowObject(self):
  140.         print 'ShowObject'
  141.  
  142.     
  143.     def OnShowWindow(self, fShow):
  144.         print 'ShowObject' + str(fShow)
  145.  
  146.     
  147.     def RequestNewObjectLayout(self):
  148.         print 'RequestNewObjectLayout'
  149.  
  150.  
  151.  
  152. def test():
  153.     lbcom = win32com.server.util.wrap(LockBytes(), pythoncom.IID_ILockBytes)
  154.     stcom = pythoncom.StgCreateDocfileOnILockBytes(lbcom, storagecon.STGM_DIRECT | storagecon.STGM_CREATE | storagecon.STGM_READWRITE | storagecon.STGM_SHARE_EXCLUSIVE, 0)
  155.     ocs = OleClientSite()
  156.     ocscom = win32com.server.util.wrap(ocs, axcontrol.IID_IOleClientSite)
  157.     oocom = axcontrol.OleCreate('{00020906-0000-0000-C000-000000000046}', axcontrol.IID_IOleObject, 0, (0,), ocscom, stcom)
  158.     mf = win32ui.GetMainFrame()
  159.     hwnd = mf.GetSafeHwnd()
  160.     oocom.SetHostNames('OTPython', 'This is Cool')
  161.     oocom.DoVerb(-1, ocscom, 0, hwnd, mf.GetWindowRect())
  162.     oocom.SetHostNames('OTPython2', 'ThisisCool2')
  163.     doc = win32com.client.Dispatch(oocom.QueryInterface(pythoncom.IID_IDispatch))
  164.     dpcom = oocom.QueryInterface(pythoncom.IID_IPersistStorage)
  165.     ocs.SetIPersistStorage(dpcom)
  166.     ocs.SetIStorage(stcom)
  167.     wrange = doc.Range()
  168.     for i in range(10):
  169.         wrange.InsertAfter('Hello from Python %d\n' % i)
  170.     
  171.     paras = doc.Paragraphs
  172.     for i in range(len(paras)):
  173.         paras[i]().Font.ColorIndex = i + 1
  174.         paras[i]().Font.Size = 12 + 4 * i
  175.     
  176.     dpcom.Save(stcom, 0)
  177.     dpcom.HandsOffStorage()
  178.     lbcom.Flush()
  179.     doc.Application.Quit()
  180.  
  181. if __name__ == '__main__':
  182.     test()
  183.     pythoncom.CoUninitialize()
  184.     CheckClean()
  185.  
  186.