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

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.2)
  3.  
  4. from pywin.mfc import dialog, thread
  5. import threading
  6. import win32ui
  7. import win32con
  8. import win32api
  9.  
  10. def MakeProgressDlgTemplate(caption, staticText = ''):
  11.     style = win32con.DS_MODALFRAME | win32con.WS_POPUP | win32con.WS_VISIBLE | win32con.WS_CAPTION | win32con.WS_SYSMENU | win32con.DS_SETFONT
  12.     cs = win32con.WS_CHILD | win32con.WS_VISIBLE
  13.     w = 215
  14.     h = 36
  15.     h = 40
  16.     dlg = [
  17.         [
  18.             caption,
  19.             (0, 0, w, h),
  20.             style,
  21.             None,
  22.             (8, 'MS Sans Serif')]]
  23.     s = win32con.WS_TABSTOP | cs
  24.     dlg.append([
  25.         130,
  26.         staticText,
  27.         1000,
  28.         (7, 7, w - 7, h - 32),
  29.         cs | win32con.SS_LEFT])
  30.     return dlg
  31.  
  32.  
  33. class CStatusProgressDialog(dialog.Dialog):
  34.     
  35.     def __init__(self, title, msg = '', maxticks = 100, tickincr = 1):
  36.         self.initMsg = msg
  37.         templ = MakeProgressDlgTemplate(title, msg)
  38.         dialog.Dialog.__init__(self, templ)
  39.         self.maxticks = maxticks
  40.         self.tickincr = tickincr
  41.         self.pbar = None
  42.  
  43.     
  44.     def OnInitDialog(self):
  45.         rc = dialog.Dialog.OnInitDialog(self)
  46.         self.static = self.GetDlgItem(1000)
  47.         self.pbar = win32ui.CreateProgressCtrl()
  48.         self.pbar.CreateWindow(win32con.WS_CHILD | win32con.WS_VISIBLE, (10, 30, 310, 44), self, 1001)
  49.         self.pbar.SetRange(0, self.maxticks)
  50.         self.pbar.SetStep(self.tickincr)
  51.         self.progress = 0
  52.         self.pincr = 5
  53.         return rc
  54.  
  55.     
  56.     def Close(self):
  57.         self.EndDialog(0)
  58.  
  59.     
  60.     def SetMaxTicks(self, maxticks):
  61.         if self.pbar is not None:
  62.             self.pbar.SetRange(0, maxticks)
  63.         
  64.  
  65.     
  66.     def Tick(self):
  67.         if self.pbar is not None:
  68.             self.pbar.StepIt()
  69.         
  70.  
  71.     
  72.     def SetTitle(self, text):
  73.         self.SetWindowText(text)
  74.  
  75.     
  76.     def SetText(self, text):
  77.         self.SetDlgItemText(1000, text)
  78.  
  79.     
  80.     def Set(self, pos, max = None):
  81.         if self.pbar is not None:
  82.             self.pbar.SetPos(pos)
  83.             if max is not None:
  84.                 self.pbar.SetRange(0, max)
  85.             
  86.         
  87.  
  88.  
  89. MYWM_SETTITLE = win32con.WM_USER + 10
  90. MYWM_SETMSG = win32con.WM_USER + 11
  91. MYWM_TICK = win32con.WM_USER + 12
  92. MYWM_SETMAXTICKS = win32con.WM_USER + 13
  93. MYWM_SET = win32con.WM_USER + 14
  94.  
  95. class CThreadedStatusProcessDialog(CStatusProgressDialog):
  96.     
  97.     def __init__(self, title, msg = '', maxticks = 100, tickincr = 1):
  98.         self.title = title
  99.         self.msg = msg
  100.         self.threadid = win32api.GetCurrentThreadId()
  101.         CStatusProgressDialog.__init__(self, title, msg, maxticks, tickincr)
  102.  
  103.     
  104.     def OnInitDialog(self):
  105.         rc = CStatusProgressDialog.OnInitDialog(self)
  106.         self.HookMessage(self.OnTitle, MYWM_SETTITLE)
  107.         self.HookMessage(self.OnMsg, MYWM_SETMSG)
  108.         self.HookMessage(self.OnTick, MYWM_TICK)
  109.         self.HookMessage(self.OnMaxTicks, MYWM_SETMAXTICKS)
  110.         self.HookMessage(self.OnSet, MYWM_SET)
  111.         return rc
  112.  
  113.     
  114.     def _Send(self, msg):
  115.         
  116.         try:
  117.             self.PostMessage(msg)
  118.         except win32ui.error:
  119.             pass
  120.  
  121.  
  122.     
  123.     def OnTitle(self, msg):
  124.         CStatusProgressDialog.SetTitle(self, self.title)
  125.  
  126.     
  127.     def OnMsg(self, msg):
  128.         CStatusProgressDialog.SetText(self, self.msg)
  129.  
  130.     
  131.     def OnTick(self, msg):
  132.         CStatusProgressDialog.Tick(self)
  133.  
  134.     
  135.     def OnMaxTicks(self, msg):
  136.         CStatusProgressDialog.SetMaxTicks(self, self.maxticks)
  137.  
  138.     
  139.     def OnSet(self, msg):
  140.         CStatusProgressDialog.Set(self, self.pos, self.max)
  141.  
  142.     
  143.     def Close(self):
  144.         if not __debug__ and self.threadid:
  145.             raise AssertionError, 'No thread!'
  146.         win32api.PostThreadMessage(self.threadid, win32con.WM_QUIT, 0, 0)
  147.  
  148.     
  149.     def SetMaxTicks(self, maxticks):
  150.         self.maxticks = maxticks
  151.         self._Send(MYWM_SETMAXTICKS)
  152.  
  153.     
  154.     def SetTitle(self, title):
  155.         self.title = title
  156.         self._Send(MYWM_SETTITLE)
  157.  
  158.     
  159.     def SetText(self, text):
  160.         self.msg = text
  161.         self._Send(MYWM_SETMSG)
  162.  
  163.     
  164.     def Tick(self):
  165.         self._Send(MYWM_TICK)
  166.  
  167.     
  168.     def Set(self, pos, max = None):
  169.         self.pos = pos
  170.         self.max = max
  171.         self._Send(MYWM_SET)
  172.  
  173.  
  174.  
  175. class ProgressThread(thread.WinThread):
  176.     
  177.     def __init__(self, title, msg = '', maxticks = 100, tickincr = 1):
  178.         self.title = title
  179.         self.msg = msg
  180.         self.maxticks = maxticks
  181.         self.tickincr = tickincr
  182.         self.dialog = None
  183.         thread.WinThread.__init__(self)
  184.         self.createdEvent = threading.Event()
  185.  
  186.     
  187.     def InitInstance(self):
  188.         self.dialog = CThreadedStatusProcessDialog(self.title, self.msg, self.maxticks, self.tickincr)
  189.         self.dialog.CreateWindow()
  190.         
  191.         try:
  192.             self.dialog.SetForegroundWindow()
  193.         except win32ui.error:
  194.             pass
  195.  
  196.         self.createdEvent.set()
  197.         return thread.WinThread.InitInstance(self)
  198.  
  199.     
  200.     def ExitInstance(self):
  201.         return 0
  202.  
  203.  
  204.  
  205. def StatusProgressDialog(title, msg = '', maxticks = 100, parent = None):
  206.     d = CStatusProgressDialog(title, msg, maxticks)
  207.     d.CreateWindow(parent)
  208.     return d
  209.  
  210.  
  211. def ThreadedStatusProgressDialog(title, msg = '', maxticks = 100):
  212.     t = ProgressThread(title, msg, maxticks)
  213.     t.CreateThread()
  214.     t.createdEvent.wait(10)
  215.     return t.dialog
  216.  
  217.  
  218. def demo():
  219.     d = StatusProgressDialog('A Demo', 'Doing something...')
  220.     import win32api
  221.     for i in range(100):
  222.         if i == 50:
  223.             d.SetText('Getting there...')
  224.         
  225.         if i == 90:
  226.             d.SetText('Nearly done...')
  227.         
  228.         win32api.Sleep(20)
  229.         d.Tick()
  230.     
  231.     d.Close()
  232.  
  233.  
  234. def thread_demo():
  235.     d = ThreadedStatusProgressDialog('A threaded demo', 'Doing something')
  236.     import win32api
  237.     for i in range(100):
  238.         if i == 50:
  239.             d.SetText('Getting there...')
  240.         
  241.         if i == 90:
  242.             d.SetText('Nearly done...')
  243.         
  244.         win32api.Sleep(20)
  245.         d.Tick()
  246.     
  247.     d.Close()
  248.  
  249. if __name__ == '__main__':
  250.     thread_demo()
  251.  
  252.