#!/usr/bin/env python
#-*- coding: UTF-8 -*-
 
import wx
from stomamisc import *


class VirtualListCtrl(wx.ListCtrl):
    
    def __init__(self, parent, id, config):
        if config ['ListCtrl']['grid'] == 'True':
            wx.ListCtrl.__init__(self, parent, id, style = wx.LC_REPORT | wx.LC_VIRTUAL | wx.LC_SINGLE_SEL | wx.LC_HRULES | wx.LC_VRULES)
        else:
            wx.ListCtrl.__init__(self, parent, id, style = wx.LC_REPORT | wx.LC_VIRTUAL | wx.LC_SINGLE_SEL)
                      
        self.InsertColumn(0, 'Directoryname', width = int(config ['Window']['colwidth0']))
        self.InsertColumn(1, 'Filename', width = int(config ['Window']['colwidth1']))
        self.InsertColumn(2, 'Size', format = wx.LIST_FORMAT_RIGHT, width = int(config ['Window']['colwidth2']))
        self.InsertColumn(3, 'DateTime', format = wx.LIST_FORMAT_RIGHT, width = int(config ['Window']['colwidth3']))
    
        self.datasource = []
        self.SetItemCount(0)
    #-------------------------------------------------------------------------------------------
    
    def getColumnText(self, index, col):
        item = self.GetItem(index, col)
        return item.GetText()
    #-------------------------------------------------------------------------------------------

    def OnGetItemText(self, item, col):
        data = self.datasource[item]
        if col == 2:
            return format3P(data[col])
        else:
            return data[col]
    #-------------------------------------------------------------------------------------------
    
    def OnItemGetAttr(self, item):
        return None
    #-------------------------------------------------------------------------------------------
    
    def OnGetItemImage(self, item):
        return -1
    #-------------------------------------------------------------------------------------------
    
    def setDataSource(self, datasource, itemcount):
        self.DeleteAllItems()
        self.datasource = datasource
        self.SetItemCount(itemcount)        
# - class VirtualListCtrl(wx.ListCtrl):--------------------------------------------------------
