Exemple #1
0
def SetDefaultList(listProcessor,*args):
    hwndList = listProcessor.GetControl()

    # set full row select style
    child_ex_style = win32gui.SendMessage(hwndList, commctrl.LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0)
    child_ex_style |= commctrl.LVS_EX_FULLROWSELECT
    win32gui.SendMessage(hwndList, commctrl.LVM_SETEXTENDEDLISTVIEWSTYLE, 0, child_ex_style)

    # set header row
    lvc =  LVCOLUMN(
                    mask = commctrl.LVCF_FMT | commctrl.LVCF_WIDTH | \
                    commctrl.LVCF_TEXT | commctrl.LVCF_SUBITEM
                    )
    lvc.fmt = commctrl.LVCFMT_LEFT
    lvc.iSubItem = 1
    lvc.text = "Object Name"
    lvc.cx = 275
    win32gui.SendMessage(hwndList, commctrl.LVM_INSERTCOLUMN, 0, lvc.toparam())
    lvc.iSubItem = 0
    lvc.text = "Title"
    lvc.cx = 275
    win32gui.SendMessage(hwndList, commctrl.LVM_INSERTCOLUMN, 0, lvc.toparam())

    #create imagelist
    global il
    il = win32gui.ImageList_Create(
                        win32api.GetSystemMetrics(win32con.SM_CXSMICON),
                        win32api.GetSystemMetrics(win32con.SM_CYSMICON),
                        commctrl.ILC_COLOR32 | commctrl.ILC_MASK,
                        1, # initial size
                        0) # cGrow

    win32gui.SendMessage(hwndList, commctrl.LVM_SETIMAGELIST,\
                                 commctrl.LVSIL_SMALL, il)
    # Set objects from config
    objs = eval(NewConn.getitem('_obj_list'))
    load_bmp_flags=win32con.LR_LOADFROMFILE | win32con.LR_LOADTRANSPARENT
    for obj in objs:
        image_path = os.path.join(listProcessor.window.manager.application_directory, "dialogs\\resources\\openerp_logo1.bmp")
        path=obj[2]
        if path:
            image_path = path
        try:
            hicon = win32gui.LoadImage(0, image_path,win32con.IMAGE_BITMAP, 40, 40, load_bmp_flags)
        except Exception, e:
            msg = "Problem loading the image \n\n" + getMessage(e)
            hicon = None
            win32ui.MessageBox(msg, "Load Image", flag_error)

        #Add the object in the list
        win32gui.ImageList_Add(il,hicon,0)
        cnt = win32gui.ImageList_GetImageCount(il)
        num_items = win32gui.SendMessage(hwndList, commctrl.LVM_GETITEMCOUNT)
        item = LVITEM(text=obj[0],iImage=cnt-2, iItem = num_items)
        new_index = win32gui.SendMessage(hwndList, commctrl.LVM_INSERTITEM, 0, item.toparam())
        item = LVITEM(text=obj[1], iItem = new_index, iSubItem = 1)
        win32gui.SendMessage(hwndList, commctrl.LVM_SETITEM, 0, item.toparam())
Exemple #2
0
    def _SetupList(self):
        child_style = win32con.WS_CHILD | win32con.WS_VISIBLE | win32con.WS_BORDER | win32con.WS_HSCROLL | win32con.WS_VSCROLL
        child_style |= commctrl.LVS_SINGLESEL | commctrl.LVS_SHOWSELALWAYS | commctrl.LVS_REPORT
        self.hwndList = win32gui.CreateWindow("SysListView32", None,
                                              child_style, 0, 0, 100, 100,
                                              self.hwnd, IDC_LISTBOX,
                                              self.hinst, None)

        child_ex_style = win32gui.SendMessage(
            self.hwndList, commctrl.LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0)
        child_ex_style |= commctrl.LVS_EX_FULLROWSELECT
        win32gui.SendMessage(self.hwndList,
                             commctrl.LVM_SETEXTENDEDLISTVIEWSTYLE, 0,
                             child_ex_style)

        # Add an image list - use the builtin shell folder icon - this
        # demonstrates the problem with alpha-blending of icons on XP if
        # winxpgui is not used in place of win32gui.
        il = win32gui.ImageList_Create(
            win32api.GetSystemMetrics(win32con.SM_CXSMICON),
            win32api.GetSystemMetrics(win32con.SM_CYSMICON),
            commctrl.ILC_COLOR32 | commctrl.ILC_MASK,
            1,  # initial size
            0)  # cGrow

        shell_dll = os.path.join(win32api.GetSystemDirectory(), "shell32.dll")
        large, small = win32gui.ExtractIconEx(shell_dll, 4, 1)
        win32gui.ImageList_ReplaceIcon(il, -1, small[0])
        win32gui.DestroyIcon(small[0])
        win32gui.DestroyIcon(large[0])
        win32gui.SendMessage(self.hwndList, commctrl.LVM_SETIMAGELIST,
                             commctrl.LVSIL_SMALL, il)

        # Setup the list control columns.
        lvc = LVCOLUMN(mask=commctrl.LVCF_FMT | commctrl.LVCF_WIDTH
                       | commctrl.LVCF_TEXT | commctrl.LVCF_SUBITEM)
        lvc.fmt = commctrl.LVCFMT_LEFT
        lvc.iSubItem = 1
        lvc.text = "Title"
        lvc.cx = 200
        win32gui.SendMessage(self.hwndList, commctrl.LVM_INSERTCOLUMN, 0,
                             lvc.toparam())
        lvc.iSubItem = 0
        lvc.text = "Order"
        lvc.cx = 50
        win32gui.SendMessage(self.hwndList, commctrl.LVM_INSERTCOLUMN, 0,
                             lvc.toparam())

        win32gui.UpdateWindow(self.hwnd)