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

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.2)
  3.  
  4. from pywin.mfc import dialog
  5. import win32ui
  6. import win32con
  7. import commctrl
  8. import win32api
  9.  
  10. class ListDialog(dialog.Dialog):
  11.     
  12.     def __init__(self, title, list):
  13.         dialog.Dialog.__init__(self, self._maketemplate(title))
  14.         self.HookMessage(self.on_size, win32con.WM_SIZE)
  15.         self.HookNotify(self.OnListItemChange, commctrl.LVN_ITEMCHANGED)
  16.         self.HookCommand(self.OnListClick, win32ui.IDC_LIST1)
  17.         self.items = list
  18.  
  19.     
  20.     def _maketemplate(self, title):
  21.         style = win32con.WS_DLGFRAME | win32con.WS_SYSMENU | win32con.WS_VISIBLE
  22.         ls = win32con.WS_CHILD | win32con.WS_VISIBLE | commctrl.LVS_ALIGNLEFT | commctrl.LVS_REPORT
  23.         bs = win32con.WS_CHILD | win32con.WS_VISIBLE
  24.         return [
  25.             [
  26.                 title,
  27.                 (0, 0, 200, 200),
  28.                 style,
  29.                 None,
  30.                 (8, 'MS Sans Serif')],
  31.             [
  32.                 'SysListView32',
  33.                 None,
  34.                 win32ui.IDC_LIST1,
  35.                 (0, 0, 200, 200),
  36.                 ls],
  37.             [
  38.                 128,
  39.                 'OK',
  40.                 win32con.IDOK,
  41.                 (10, 0, 50, 14),
  42.                 bs | win32con.BS_DEFPUSHBUTTON],
  43.             [
  44.                 128,
  45.                 'Cancel',
  46.                 win32con.IDCANCEL,
  47.                 (0, 0, 50, 14),
  48.                 bs]]
  49.  
  50.     
  51.     def FillList(self):
  52.         size = self.GetWindowRect()
  53.         width = size[2] - size[0] - 10
  54.         itemDetails = (commctrl.LVCFMT_LEFT, width, 'Item', 0)
  55.         self.itemsControl.InsertColumn(0, itemDetails)
  56.         index = 0
  57.         for item in self.items:
  58.             index = self.itemsControl.InsertItem(index + 1, str(item), 0)
  59.         
  60.  
  61.     
  62.     def OnListClick(self, id, code):
  63.         if code == commctrl.NM_DBLCLK:
  64.             self.EndDialog(win32con.IDOK)
  65.         
  66.         return 1
  67.  
  68.     
  69.     def OnListItemChange(self, std, extra):
  70.         (hwndFrom, idFrom, code) = ()
  71.         (itemNotify, sub, newState, oldState, change, point, lparam) = (std, extra)
  72.         oldSel = oldState & commctrl.LVIS_SELECTED != 0
  73.         newSel = newState & commctrl.LVIS_SELECTED != 0
  74.         if oldSel != newSel:
  75.             
  76.             try:
  77.                 self.selecteditem = itemNotify
  78.                 self.butOK.EnableWindow(1)
  79.             except win32ui.error:
  80.                 self.selecteditem = None
  81.  
  82.         
  83.  
  84.     
  85.     def OnInitDialog(self):
  86.         rc = dialog.Dialog.OnInitDialog(self)
  87.         self.itemsControl = self.GetDlgItem(win32ui.IDC_LIST1)
  88.         self.butOK = self.GetDlgItem(win32con.IDOK)
  89.         self.butCancel = self.GetDlgItem(win32con.IDCANCEL)
  90.         self.FillList()
  91.         size = self.GetWindowRect()
  92.         self.LayoutControls(size[2] - size[0], size[3] - size[1])
  93.         self.butOK.EnableWindow(0)
  94.         return rc
  95.  
  96.     
  97.     def LayoutControls(self, w, h):
  98.         self.itemsControl.MoveWindow((0, 0, w, h - 30))
  99.         self.butCancel.MoveWindow((10, h - 24, 60, h - 4))
  100.         self.butOK.MoveWindow((w - 60, h - 24, w - 10, h - 4))
  101.  
  102.     
  103.     def on_size(self, params):
  104.         lparam = params[3]
  105.         w = win32api.LOWORD(lparam)
  106.         h = win32api.HIWORD(lparam)
  107.         self.LayoutControls(w, h)
  108.  
  109.  
  110.  
  111. class ListsDialog(ListDialog):
  112.     
  113.     def __init__(self, title, list, colHeadings = [
  114.         'Item']):
  115.         ListDialog.__init__(self, title, list)
  116.         self.colHeadings = colHeadings
  117.  
  118.     
  119.     def FillList(self):
  120.         index = 0
  121.         size = self.GetWindowRect()
  122.         width = size[2] - size[0] - 10 - win32api.GetSystemMetrics(win32con.SM_CXVSCROLL)
  123.         numCols = len(self.colHeadings)
  124.         for col in self.colHeadings:
  125.             itemDetails = (commctrl.LVCFMT_LEFT, width / numCols, col, 0)
  126.             self.itemsControl.InsertColumn(index, itemDetails)
  127.             index = index + 1
  128.         
  129.         index = 0
  130.         for items in self.items:
  131.             index = self.itemsControl.InsertItem(index + 1, str(items[0]), 0)
  132.             for itemno in range(1, numCols):
  133.                 item = items[itemno]
  134.                 self.itemsControl.SetItemText(index, itemno, str(item))
  135.             
  136.         
  137.  
  138.  
  139.  
  140. def SelectFromList(title, lst):
  141.     dlg = ListDialog(title, lst)
  142.     if dlg.DoModal() == win32con.IDOK:
  143.         return dlg.selecteditem
  144.     else:
  145.         return None
  146.  
  147.  
  148. def SelectFromLists(title, lists, headings):
  149.     dlg = ListsDialog(title, lists, headings)
  150.     if dlg.DoModal() == win32con.IDOK:
  151.         return dlg.selecteditem
  152.     else:
  153.         return None
  154.  
  155.  
  156. def test():
  157.     print SelectFromLists('Multi-List', [
  158.         ('1', 1, 'a'),
  159.         ('2', 2, 'b'),
  160.         ('3', 3, 'c')], [
  161.         'Col 1',
  162.         'Col 2'])
  163.  
  164. if __name__ == '__main__':
  165.     test()
  166.  
  167.