home *** CD-ROM | disk | FTP | other *** search
/ One Click 11 / OneClick11.iso / Bancos de Dados / Conversao / Mysql2Excel / Setup.exe / Mysql2Excel.exe / pywin / mfc / dialog.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2003-06-23  |  12.8 KB  |  293 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.2)
  3.  
  4. ''' Base class for Dialogs.  Also contains a few useful utility functions
  5. '''
  6. import win32ui
  7. import win32con
  8. import window
  9.  
  10. def dllFromDll(dllid):
  11.     """ given a 'dll' (maybe a dll, filename, etc), return a DLL object """
  12.     if dllid == None:
  13.         return None
  14.     elif type('') == type(dllid):
  15.         return win32ui.LoadLibrary(dllid)
  16.     else:
  17.         
  18.         try:
  19.             dllid.GetFileName()
  20.         except AttributeError:
  21.             raise TypeError, 'DLL parameter must be None, a filename or a dll object'
  22.  
  23.         return dllid
  24.  
  25.  
  26. class Dialog(window.Wnd):
  27.     ''' Base class for a dialog'''
  28.     
  29.     def __init__(self, id, dllid = None):
  30.         ''' id is the resource ID, or a template
  31. \t\t\tdllid may be None, a dll object, or a string with a dll name '''
  32.         self.dll = dllFromDll(dllid)
  33.         if type(id) == type([]):
  34.             dlg = win32ui.CreateDialogIndirect(id)
  35.         else:
  36.             dlg = win32ui.CreateDialog(id, self.dll)
  37.         window.Wnd.__init__(self, dlg)
  38.         self.HookCommands()
  39.         self.bHaveInit = None
  40.  
  41.     
  42.     def HookCommands(self):
  43.         pass
  44.  
  45.     
  46.     def OnAttachedObjectDeath(self):
  47.         self.data = self._obj_.data
  48.         window.Wnd.OnAttachedObjectDeath(self)
  49.  
  50.     
  51.     def OnOK(self):
  52.         self._obj_.OnOK()
  53.  
  54.     
  55.     def OnCancel(self):
  56.         self._obj_.OnCancel()
  57.  
  58.     
  59.     def OnInitDialog(self):
  60.         self.bHaveInit = 1
  61.         if self._obj_.data:
  62.             self._obj_.UpdateData(0)
  63.         
  64.         return 1
  65.  
  66.     
  67.     def OnDestroy(self, msg):
  68.         self.dll = None
  69.  
  70.     
  71.     def AddDDX(self, *args):
  72.         self._obj_.datalist.append(args)
  73.  
  74.     
  75.     def __nonzero__(self):
  76.         return 1
  77.  
  78.     
  79.     def __len__(self):
  80.         return len(self.data)
  81.  
  82.     
  83.     def __getitem__(self, key):
  84.         return self.data[key]
  85.  
  86.     
  87.     def __setitem__(self, key, item):
  88.         self._obj_.data[key] = item
  89.  
  90.     
  91.     def keys(self):
  92.         return self.data.keys()
  93.  
  94.     
  95.     def items(self):
  96.         return self.data.items()
  97.  
  98.     
  99.     def values(self):
  100.         return self.data.values()
  101.  
  102.     
  103.     def has_key(self, key):
  104.         return self.data.has_key(key)
  105.  
  106.  
  107.  
  108. class PrintDialog(Dialog):
  109.     ''' Base class for a print dialog'''
  110.     
  111.     def __init__(self, pInfo, dlgID, printSetupOnly = 0, flags = win32ui.PD_ALLPAGES | win32ui.PD_USEDEVMODECOPIES | win32ui.PD_NOPAGENUMS | win32ui.PD_HIDEPRINTTOFILE | win32ui.PD_NOSELECTION, parent = None, dllid = None):
  112.         self.dll = dllFromDll(dllid)
  113.         if type(dlgID) == type([]):
  114.             raise TypeError, 'dlgID parameter must be an integer resource ID'
  115.         
  116.         dlg = win32ui.CreatePrintDialog(dlgID, printSetupOnly, flags, parent, self.dll)
  117.         window.Wnd.__init__(self, dlg)
  118.         self.HookCommands()
  119.         self.bHaveInit = None
  120.         self.pInfo = pInfo
  121.         flags = pInfo.GetFlags()
  122.         self['toFile'] = flags & win32ui.PD_PRINTTOFILE != 0
  123.         self['direct'] = pInfo.GetDirect()
  124.         self['preview'] = pInfo.GetPreview()
  125.         self['continuePrinting'] = pInfo.GetContinuePrinting()
  126.         self['curPage'] = pInfo.GetCurPage()
  127.         self['numPreviewPages'] = pInfo.GetNumPreviewPages()
  128.         self['userData'] = pInfo.GetUserData()
  129.         self['draw'] = pInfo.GetDraw()
  130.         self['pageDesc'] = pInfo.GetPageDesc()
  131.         self['minPage'] = pInfo.GetMinPage()
  132.         self['maxPage'] = pInfo.GetMaxPage()
  133.         self['offsetPage'] = pInfo.GetOffsetPage()
  134.         self['fromPage'] = pInfo.GetFromPage()
  135.         self['toPage'] = pInfo.GetToPage()
  136.         self['copies'] = 0
  137.         self['deviceName'] = ''
  138.         self['driverName'] = ''
  139.         self['printAll'] = 0
  140.         self['printCollate'] = 0
  141.         self['printRange'] = 0
  142.         self['printSelection'] = 0
  143.  
  144.     
  145.     def OnInitDialog(self):
  146.         self.pInfo.CreatePrinterDC()
  147.         return self._obj_.OnInitDialog()
  148.  
  149.     
  150.     def OnCancel(self):
  151.         del self.pInfo
  152.  
  153.     
  154.     def OnOK(self):
  155.         '''DoModal has finished. Can now access the users choices'''
  156.         self._obj_.OnOK()
  157.         pInfo = self.pInfo
  158.         flags = pInfo.GetFlags()
  159.         self['toFile'] = flags & win32ui.PD_PRINTTOFILE != 0
  160.         self['direct'] = pInfo.GetDirect()
  161.         self['preview'] = pInfo.GetPreview()
  162.         self['continuePrinting'] = pInfo.GetContinuePrinting()
  163.         self['curPage'] = pInfo.GetCurPage()
  164.         self['numPreviewPages'] = pInfo.GetNumPreviewPages()
  165.         self['userData'] = pInfo.GetUserData()
  166.         self['draw'] = pInfo.GetDraw()
  167.         self['pageDesc'] = pInfo.GetPageDesc()
  168.         self['minPage'] = pInfo.GetMinPage()
  169.         self['maxPage'] = pInfo.GetMaxPage()
  170.         self['offsetPage'] = pInfo.GetOffsetPage()
  171.         self['fromPage'] = pInfo.GetFromPage()
  172.         self['toPage'] = pInfo.GetToPage()
  173.         self['copies'] = pInfo.GetCopies()
  174.         self['deviceName'] = pInfo.GetDeviceName()
  175.         self['driverName'] = pInfo.GetDriverName()
  176.         self['printAll'] = pInfo.PrintAll()
  177.         self['printCollate'] = pInfo.PrintCollate()
  178.         self['printRange'] = pInfo.PrintRange()
  179.         self['printSelection'] = pInfo.PrintSelection()
  180.         del self.pInfo
  181.  
  182.  
  183.  
  184. class PropertyPage(Dialog):
  185.     ''' Base class for a Property Page'''
  186.     
  187.     def __init__(self, id, dllid = None, caption = 0):
  188.         ''' id is the resource ID
  189. \t\t\tdllid may be None, a dll object, or a string with a dll name '''
  190.         self.dll = dllFromDll(dllid)
  191.         if self.dll:
  192.             oldRes = win32ui.SetResource(self.dll)
  193.         
  194.         if type(id) == type([]):
  195.             dlg = win32ui.CreatePropertyPageIndirect(id)
  196.         else:
  197.             dlg = win32ui.CreatePropertyPage(id, caption)
  198.         if self.dll:
  199.             win32ui.SetResource(oldRes)
  200.         
  201.         window.Wnd.__init__(self, dlg)
  202.         self.HookCommands()
  203.  
  204.  
  205.  
  206. class PropertySheet(window.Wnd):
  207.     
  208.     def __init__(self, caption, dll = None, pageList = None):
  209.         """ Initialize a property sheet.  pageList is a list of ID's """
  210.         self.dll = dllFromDll(dll)
  211.         self.sheet = win32ui.CreatePropertySheet(caption)
  212.         window.Wnd.__init__(self, self.sheet)
  213.         if not (pageList is None):
  214.             self.AddPage(pageList)
  215.         
  216.  
  217.     
  218.     def OnInitDialog(self):
  219.         return self._obj_.OnInitDialog()
  220.  
  221.     
  222.     def DoModal(self):
  223.         if self.dll:
  224.             oldRes = win32ui.SetResource(self.dll)
  225.         
  226.         rc = self.sheet.DoModal()
  227.         if self.dll:
  228.             win32ui.SetResource(oldRes)
  229.         
  230.         return rc
  231.  
  232.     
  233.     def AddPage(self, pages):
  234.         if self.dll:
  235.             oldRes = win32ui.SetResource(self.dll)
  236.         
  237.         
  238.         try:
  239.             pages[0]
  240.             isSeq = 1
  241.         except (TypeError, KeyError):
  242.             isSeq = 0
  243.  
  244.         if isSeq:
  245.             for page in pages:
  246.                 self.DoAddSinglePage(page)
  247.             
  248.         else:
  249.             self.DoAddSinglePage(pages)
  250.         if self.dll:
  251.             win32ui.SetResource(oldRes)
  252.         
  253.  
  254.     
  255.     def DoAddSinglePage(self, page):
  256.         '''Page may be page, or int ID. Assumes DLL setup '''
  257.         if type(page) == type(0):
  258.             self.sheet.AddPage(win32ui.CreatePropertyPage(page))
  259.         else:
  260.             self.sheet.AddPage(page)
  261.  
  262.  
  263.  
  264. def GetSimpleInput(prompt, defValue = '', title = None):
  265.     """ displays a dialog, and returns a string, or None if cancelled.
  266. \targs prompt, defValue='', title=main frames title """
  267.     if title is None:
  268.         title = win32ui.GetMainFrame().GetWindowText()
  269.     
  270.     
  271.     class DlgSimpleInput(Dialog):
  272.         
  273.         def __init__(self, prompt, defValue, title):
  274.             self.title = title
  275.             Dialog.__init__(self, win32ui.IDD_SIMPLE_INPUT)
  276.             self.AddDDX(win32ui.IDC_EDIT1, 'result')
  277.             self.AddDDX(win32ui.IDC_PROMPT1, 'prompt')
  278.             self._obj_.data['result'] = defValue
  279.             self._obj_.data['prompt'] = prompt
  280.  
  281.         
  282.         def OnInitDialog(self):
  283.             self.SetWindowText(self.title)
  284.             return Dialog.OnInitDialog(self)
  285.  
  286.  
  287.     dlg = DlgSimpleInput(prompt, defValue, title)
  288.     if dlg.DoModal() != win32con.IDOK:
  289.         return None
  290.     
  291.     return dlg['result']
  292.  
  293.