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

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import win32ui
  5. import win32con
  6. import win32api
  7. import string
  8. import commctrl
  9. import pythoncom
  10. from pywin.mfc import dialog
  11. error = 'TypeLib browser internal error'
  12. FRAMEDLG_STD = win32con.WS_CAPTION | win32con.WS_SYSMENU
  13. SS_STD = win32con.WS_CHILD | win32con.WS_VISIBLE
  14. BS_STD = SS_STD | win32con.WS_TABSTOP
  15. ES_STD = BS_STD | win32con.WS_BORDER
  16. LBS_STD = ES_STD | win32con.LBS_NOTIFY | win32con.LBS_NOINTEGRALHEIGHT | win32con.WS_VSCROLL
  17. CBS_STD = ES_STD | win32con.CBS_NOINTEGRALHEIGHT | win32con.WS_VSCROLL
  18. typekindmap = {
  19.     pythoncom.TKIND_ENUM: 'Enumeration',
  20.     pythoncom.TKIND_RECORD: 'Record',
  21.     pythoncom.TKIND_MODULE: 'Module',
  22.     pythoncom.TKIND_INTERFACE: 'Interface',
  23.     pythoncom.TKIND_DISPATCH: 'Dispatch',
  24.     pythoncom.TKIND_COCLASS: 'CoClass',
  25.     pythoncom.TKIND_ALIAS: 'Alias',
  26.     pythoncom.TKIND_UNION: 'Union' }
  27. TypeBrowseDialog_Parent = dialog.Dialog
  28.  
  29. class TypeBrowseDialog(TypeBrowseDialog_Parent):
  30.     IDC_TYPELIST = 1000
  31.     IDC_MEMBERLIST = 1001
  32.     IDC_PARAMLIST = 1002
  33.     IDC_LISTVIEW = 1003
  34.     
  35.     def __init__(self, typefile = None):
  36.         TypeBrowseDialog_Parent.__init__(self, self.GetTemplate())
  37.         
  38.         try:
  39.             if typefile:
  40.                 self.tlb = pythoncom.LoadTypeLib(typefile)
  41.             else:
  42.                 self.tlb = None
  43.         except pythoncom.ole_error:
  44.             self.MessageBox('The file does not contain type information')
  45.             self.tlb = None
  46.  
  47.         self.HookCommand(self.CmdTypeListbox, self.IDC_TYPELIST)
  48.         self.HookCommand(self.CmdMemberListbox, self.IDC_MEMBERLIST)
  49.  
  50.     
  51.     def OnAttachedObjectDeath(self):
  52.         self.tlb = None
  53.         self.typeinfo = None
  54.         self.attr = None
  55.         return TypeBrowseDialog_Parent.OnAttachedObjectDeath(self)
  56.  
  57.     
  58.     def _SetupMenu(self):
  59.         menu = win32ui.CreateMenu()
  60.         flags = win32con.MF_STRING | win32con.MF_ENABLED
  61.         menu.AppendMenu(flags, win32ui.ID_FILE_OPEN, '&Open...')
  62.         menu.AppendMenu(flags, win32con.IDCANCEL, '&Close')
  63.         mainMenu = win32ui.CreateMenu()
  64.         mainMenu.AppendMenu(flags | win32con.MF_POPUP, menu.GetHandle(), '&File')
  65.         self.SetMenu(mainMenu)
  66.         self.HookCommand(self.OnFileOpen, win32ui.ID_FILE_OPEN)
  67.  
  68.     
  69.     def OnFileOpen(self, id, code):
  70.         openFlags = win32con.OFN_OVERWRITEPROMPT | win32con.OFN_FILEMUSTEXIST
  71.         fspec = "Type Libraries (*.tlb, *.olb)|*.tlb;*.olb|OCX Files (*.ocx)|*.ocx|DLL's (*.dll)|*.dll|All Files (*.*)|*.*||"
  72.         dlg = win32ui.CreateFileDialog(1, None, None, openFlags, fspec)
  73.         if dlg.DoModal() == win32con.IDOK:
  74.             
  75.             try:
  76.                 self.tlb = pythoncom.LoadTypeLib(dlg.GetPathName())
  77.             except pythoncom.ole_error:
  78.                 self.MessageBox('The file does not contain type information')
  79.                 self.tlb = None
  80.  
  81.             self._SetupTLB()
  82.         
  83.  
  84.     
  85.     def OnInitDialog(self):
  86.         self._SetupMenu()
  87.         self.typelb = self.GetDlgItem(self.IDC_TYPELIST)
  88.         self.memberlb = self.GetDlgItem(self.IDC_MEMBERLIST)
  89.         self.paramlb = self.GetDlgItem(self.IDC_PARAMLIST)
  90.         self.listview = self.GetDlgItem(self.IDC_LISTVIEW)
  91.         itemDetails = (commctrl.LVCFMT_LEFT, 100, 'Item', 0)
  92.         self.listview.InsertColumn(0, itemDetails)
  93.         itemDetails = (commctrl.LVCFMT_LEFT, 1024, 'Details', 0)
  94.         self.listview.InsertColumn(1, itemDetails)
  95.         if self.tlb is None:
  96.             self.OnFileOpen(None, None)
  97.         else:
  98.             self._SetupTLB()
  99.         return TypeBrowseDialog_Parent.OnInitDialog(self)
  100.  
  101.     
  102.     def _SetupTLB(self):
  103.         self.typelb.ResetContent()
  104.         self.memberlb.ResetContent()
  105.         self.paramlb.ResetContent()
  106.         self.typeinfo = None
  107.         self.attr = None
  108.         if self.tlb is None:
  109.             return None
  110.         n = self.tlb.GetTypeInfoCount()
  111.         for i in range(n):
  112.             self.typelb.AddString(self.tlb.GetDocumentation(i)[0])
  113.         
  114.  
  115.     
  116.     def _SetListviewTextItems(self, items):
  117.         self.listview.DeleteAllItems()
  118.         index = -1
  119.         for item in items:
  120.             index = self.listview.InsertItem(index + 1, item[0])
  121.             data = item[1]
  122.             if data is None:
  123.                 data = ''
  124.             
  125.             self.listview.SetItemText(index, 1, data)
  126.         
  127.  
  128.     
  129.     def SetupAllInfoTypes(self):
  130.         infos = self._GetMainInfoTypes() + self._GetMethodInfoTypes()
  131.         self._SetListviewTextItems(infos)
  132.  
  133.     
  134.     def _GetMainInfoTypes(self):
  135.         pos = self.typelb.GetCurSel()
  136.         if pos < 0:
  137.             return []
  138.         docinfo = self.tlb.GetDocumentation(pos)
  139.         infos = [
  140.             ('GUID', str(self.attr[0]))]
  141.         infos.append(('Help File', docinfo[3]))
  142.         infos.append(('Help Context', str(docinfo[2])))
  143.         
  144.         try:
  145.             infos.append(('Type Kind', typekindmap[self.tlb.GetTypeInfoType(pos)]))
  146.         except:
  147.             pos < 0
  148.  
  149.         info = self.tlb.GetTypeInfo(pos)
  150.         attr = info.GetTypeAttr()
  151.         infos.append(('Attributes', str(attr)))
  152.         for j in range(attr[8]):
  153.             flags = info.GetImplTypeFlags(j)
  154.             refInfo = info.GetRefTypeInfo(info.GetRefTypeOfImplType(j))
  155.             doc = refInfo.GetDocumentation(-1)
  156.             attr = refInfo.GetTypeAttr()
  157.             typeKind = attr[5]
  158.             typeFlags = attr[11]
  159.             desc = doc[0]
  160.             desc = desc + ', Flags=0x%x, typeKind=0x%x, typeFlags=0x%x' % (flags, typeKind, typeFlags)
  161.             if flags & pythoncom.IMPLTYPEFLAG_FSOURCE:
  162.                 desc = desc + '(Source)'
  163.             
  164.             infos.append(('Implements', desc))
  165.         
  166.         return infos
  167.  
  168.     
  169.     def _GetMethodInfoTypes(self):
  170.         pos = self.memberlb.GetCurSel()
  171.         if pos < 0:
  172.             return []
  173.         (realPos, isMethod) = self._GetRealMemberPos(pos)
  174.         ret = []
  175.         if isMethod:
  176.             funcDesc = self.typeinfo.GetFuncDesc(realPos)
  177.             id = funcDesc[0]
  178.             ret.append(('Func Desc', str(funcDesc)))
  179.         else:
  180.             id = self.typeinfo.GetVarDesc(realPos)[0]
  181.         docinfo = self.typeinfo.GetDocumentation(id)
  182.         ret.append(('Help String', docinfo[1]))
  183.         ret.append(('Help Context', str(docinfo[2])))
  184.         return ret
  185.  
  186.     
  187.     def CmdTypeListbox(self, id, code):
  188.         if code == win32con.LBN_SELCHANGE:
  189.             pos = self.typelb.GetCurSel()
  190.             if pos >= 0:
  191.                 self.memberlb.ResetContent()
  192.                 self.typeinfo = self.tlb.GetTypeInfo(pos)
  193.                 self.attr = self.typeinfo.GetTypeAttr()
  194.                 for i in range(self.attr[7]):
  195.                     id = self.typeinfo.GetVarDesc(i)[0]
  196.                     self.memberlb.AddString(self.typeinfo.GetNames(id)[0])
  197.                 
  198.                 for i in range(self.attr[6]):
  199.                     id = self.typeinfo.GetFuncDesc(i)[0]
  200.                     self.memberlb.AddString(self.typeinfo.GetNames(id)[0])
  201.                 
  202.                 self.SetupAllInfoTypes()
  203.             
  204.             return 1
  205.  
  206.     
  207.     def _GetRealMemberPos(self, pos):
  208.         pos = self.memberlb.GetCurSel()
  209.         if pos >= self.attr[7]:
  210.             return (pos - self.attr[7], 1)
  211.         if pos >= 0:
  212.             return (pos, 0)
  213.         raise error, 'The position is not valid'
  214.  
  215.     
  216.     def CmdMemberListbox(self, id, code):
  217.         if code == win32con.LBN_SELCHANGE:
  218.             self.paramlb.ResetContent()
  219.             pos = self.memberlb.GetCurSel()
  220.             (realPos, isMethod) = self._GetRealMemberPos(pos)
  221.             if isMethod:
  222.                 id = self.typeinfo.GetFuncDesc(realPos)[0]
  223.                 names = self.typeinfo.GetNames(id)
  224.                 for i in range(len(names)):
  225.                     if i > 0:
  226.                         self.paramlb.AddString(names[i])
  227.                         continue
  228.                 
  229.             
  230.             self.SetupAllInfoTypes()
  231.             return 1
  232.  
  233.     
  234.     def GetTemplate(self):
  235.         w = 272
  236.         h = 192
  237.         style = FRAMEDLG_STD | win32con.WS_VISIBLE | win32con.DS_SETFONT | win32con.WS_MINIMIZEBOX
  238.         template = [
  239.             [
  240.                 'Type Library Browser',
  241.                 (0, 0, w, h),
  242.                 style,
  243.                 None,
  244.                 (8, 'Helv')]]
  245.         template.append([
  246.             130,
  247.             '&Type',
  248.             -1,
  249.             (10, 10, 62, 9),
  250.             SS_STD | win32con.SS_LEFT])
  251.         template.append([
  252.             131,
  253.             None,
  254.             self.IDC_TYPELIST,
  255.             (10, 20, 80, 80),
  256.             LBS_STD])
  257.         template.append([
  258.             130,
  259.             '&Members',
  260.             -1,
  261.             (100, 10, 62, 9),
  262.             SS_STD | win32con.SS_LEFT])
  263.         template.append([
  264.             131,
  265.             None,
  266.             self.IDC_MEMBERLIST,
  267.             (100, 20, 80, 80),
  268.             LBS_STD])
  269.         template.append([
  270.             130,
  271.             '&Parameters',
  272.             -1,
  273.             (190, 10, 62, 9),
  274.             SS_STD | win32con.SS_LEFT])
  275.         template.append([
  276.             131,
  277.             None,
  278.             self.IDC_PARAMLIST,
  279.             (190, 20, 75, 80),
  280.             LBS_STD])
  281.         lvStyle = SS_STD | commctrl.LVS_REPORT | commctrl.LVS_AUTOARRANGE | commctrl.LVS_ALIGNLEFT | win32con.WS_BORDER | win32con.WS_TABSTOP
  282.         template.append([
  283.             'SysListView32',
  284.             '',
  285.             self.IDC_LISTVIEW,
  286.             (10, 110, 255, 65),
  287.             lvStyle])
  288.         return template
  289.  
  290.  
  291. if __name__ == '__main__':
  292.     import sys
  293.     fname = None
  294.     
  295.     try:
  296.         fname = sys.argv[1]
  297.     except:
  298.         pass
  299.  
  300.     dlg = TypeBrowseDialog(fname)
  301.     
  302.     try:
  303.         win32api.GetConsoleTitle()
  304.         dlg.DoModal()
  305.     dlg.CreateWindow(win32ui.GetMainFrame())
  306.  
  307.  
  308.