home *** CD-ROM | disk | FTP | other *** search
/ Freelog 116 / FreelogNo116-JuilletSeptembre2013.iso / Bureautique / gImageReader / gimagereader_0.9-1_win32.exe / bin / pywin / dialogs / list.pyc (.txt) < prev    next >
Python Compiled Bytecode  |  2011-03-24  |  6KB  |  163 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.7)
  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.         return 1
  66.  
  67.     
  68.     def OnListItemChange(self, std, extra):
  69.         (hwndFrom, idFrom, code) = std
  70.         (itemNotify, sub, newState, oldState, change, point, lparam) = extra
  71.         oldSel = oldState & commctrl.LVIS_SELECTED != 0
  72.         newSel = newState & commctrl.LVIS_SELECTED != 0
  73.         if oldSel != newSel:
  74.             
  75.             try:
  76.                 self.selecteditem = itemNotify
  77.                 self.butOK.EnableWindow(1)
  78.             except win32ui.error:
  79.                 self.selecteditem = None
  80.             
  81.  
  82.  
  83.     
  84.     def OnInitDialog(self):
  85.         rc = dialog.Dialog.OnInitDialog(self)
  86.         self.itemsControl = self.GetDlgItem(win32ui.IDC_LIST1)
  87.         self.butOK = self.GetDlgItem(win32con.IDOK)
  88.         self.butCancel = self.GetDlgItem(win32con.IDCANCEL)
  89.         self.FillList()
  90.         size = self.GetWindowRect()
  91.         self.LayoutControls(size[2] - size[0], size[3] - size[1])
  92.         self.butOK.EnableWindow(0)
  93.         return rc
  94.  
  95.     
  96.     def LayoutControls(self, w, h):
  97.         self.itemsControl.MoveWindow((0, 0, w, h - 30))
  98.         self.butCancel.MoveWindow((10, h - 24, 60, h - 4))
  99.         self.butOK.MoveWindow((w - 60, h - 24, w - 10, h - 4))
  100.  
  101.     
  102.     def on_size(self, params):
  103.         lparam = params[3]
  104.         w = win32api.LOWORD(lparam)
  105.         h = win32api.HIWORD(lparam)
  106.         self.LayoutControls(w, h)
  107.  
  108.  
  109.  
  110. class ListsDialog(ListDialog):
  111.     
  112.     def __init__(self, title, list, colHeadings = [
  113.         'Item']):
  114.         ListDialog.__init__(self, title, list)
  115.         self.colHeadings = colHeadings
  116.  
  117.     
  118.     def FillList(self):
  119.         index = 0
  120.         size = self.GetWindowRect()
  121.         width = size[2] - size[0] - 10 - win32api.GetSystemMetrics(win32con.SM_CXVSCROLL)
  122.         numCols = len(self.colHeadings)
  123.         for col in self.colHeadings:
  124.             itemDetails = (commctrl.LVCFMT_LEFT, width / numCols, col, 0)
  125.             self.itemsControl.InsertColumn(index, itemDetails)
  126.             index = index + 1
  127.         
  128.         index = 0
  129.         for items in self.items:
  130.             index = self.itemsControl.InsertItem(index + 1, str(items[0]), 0)
  131.             for itemno in range(1, numCols):
  132.                 item = items[itemno]
  133.                 self.itemsControl.SetItemText(index, itemno, str(item))
  134.             
  135.         
  136.  
  137.  
  138.  
  139. def SelectFromList(title, lst):
  140.     dlg = ListDialog(title, lst)
  141.     if dlg.DoModal() == win32con.IDOK:
  142.         return dlg.selecteditem
  143.     return None
  144.  
  145.  
  146. def SelectFromLists(title, lists, headings):
  147.     dlg = ListsDialog(title, lists, headings)
  148.     if dlg.DoModal() == win32con.IDOK:
  149.         return dlg.selecteditem
  150.     return None
  151.  
  152.  
  153. def test():
  154.     print SelectFromLists('Multi-List', [
  155.         ('1', 1, 'a'),
  156.         ('2', 2, 'b'),
  157.         ('3', 3, 'c')], [
  158.         'Col 1',
  159.         'Col 2'])
  160.  
  161. if __name__ == '__main__':
  162.     test()
  163.