<commit_before># -*- coding: utf-8 -*-
"""
    Custom widget for wxPython: file list control
"""

import wx
import os
import time


class FileListCtrl(wx.ListCtrl):

    def __init__(self, parent, id, ico_folder):
        wx.ListCtrl.__init__(self, parent, id, style=wx.LC_REPORT)

        self.__path = ico_folder + '/icons/mimetypes/'
        images = [ico_folder + '/icons/empty.png', ico_folder + '/icons/mimetypes/folder.png', ico_folder + '/icons/ui/up16.png']
        types_icons = [self.__path + f for f in os.listdir(self.__path)]
        types_icons.sort()
        images += types_icons
        self.supported_types = [f.replace(self.__path,'').replace('.png', '') for f in types_icons if not f.endswith('folder.png')]

        # information about file in columns
        self.InsertColumn(0, 'Имя')
        self.InsertColumn(1, 'Тип')
        self.InsertColumn(2, 'Размер', wx.LIST_FORMAT_RIGHT)
        self.InsertColumn(3, 'Посл. изменение')
        # size for every column by ID
        self.SetColumnWidth(0, 450)
        self.SetColumnWidth(1, 80)
        self.SetColumnWidth(2, 150)
        self.SetColumnWidth(3, 120)
        # add images for supported files
        self.il = wx.ImageList(16, 16)
        for i in images:
            self.il.Add(wx.Bitmap(i))
        self.SetImageList(self.il, wx.IMAGE_LIST_SMALL)

        j = 0
        # up from this folder to '..'
        #self.InsertStringItem(0, '..')
        #self.SetItemImage(0, 2)

        # all founded folders append first
        directories = [f for f in os.listdir('.') if os.path.isdir(f)]
        directories.sort()
        directories = directories

        for i in directories:
            (name, ext) = os.path.splitext(i)
            ex = ext[1:]
            size = os.path.getsize(i)
            sec = os.path.getmtime(i)
            create_time = os.path.getctime(i)
            self.InsertStringItem(j, name)
            self.SetStringItem(j, 1, ex)
            self.SetStringItem(j, 2, str(size) + ' B')
            self.SetStringItem(j, 3, time.strftime('%Y-%m-%d %H:%M', time.localtime(sec)))
            self.SetItemImage(j, 1)
            j += 1

        # after append all files in directory
        files = [f for f in os.listdir('.') if os.path.isfile(f)]
        files.sort()

        for i in files:
            (name, ext) = os.path.splitext(i)
            ex = ext[1:]
            size = os.path.getsize(i)
            sec = os.path.getmtime(i)
            self.InsertStringItem(j, name)
            self.SetStringItem(j, 1, ex)
            self.SetStringItem(j, 2, str(size) + ' B')
            self.SetStringItem(j, 3, time.strftime('%Y-%m-%d %H:%M', time.localtime(sec)))

            # its supported type
            if ex in self.supported_types:
                index = self.supported_types.index(ex) + 4
                self.SetItemImage(j, index)
            # unsupported type; set "unknown ico"
            else:
                self.SetItemImage(j, 0)

            if (j % 2) == 0:
                self.SetItemBackgroundColour(j, '#e6f1f5')
            j += 1

    def ResizeColumns(self, sizeX):
        self.SetColumnWidth(0, sizeX * 0.5625)
        self.SetColumnWidth(1, sizeX * 0.1)
        self.SetColumnWidth(2, sizeX * 0.1875)
        self.SetColumnWidth(3, sizeX * 0.15)<commit_msg>Added function for commands: convert Size<commit_after># -*- coding: utf-8 -*-
"""
    Custom widget for wxPython: file list control
"""

import wx
import os
import time
from helenae.utils.commands import convertSize


class FileListCtrl(wx.ListCtrl):

    def __init__(self, parent, id, ico_folder):
        wx.ListCtrl.__init__(self, parent, id, style=wx.LC_REPORT)

        self.currentDir = None
        self.__path = ico_folder + '/icons/mimetypes/'
        images = [ico_folder + '/icons/empty.png', ico_folder + '/icons/mimetypes/folder.png', ico_folder + '/icons/ui/up16.png']
        types_icons = [self.__path + f for f in os.listdir(self.__path)]
        types_icons.sort()
        images += types_icons
        self.supported_types = [f.replace(self.__path,'').replace('.png', '') for f in types_icons if not f.endswith('folder.png')]

        # information about file in columns
        self.InsertColumn(0, 'Имя')
        self.InsertColumn(1, 'Тип')
        self.InsertColumn(2, 'Размер', wx.LIST_FORMAT_RIGHT)
        self.InsertColumn(3, 'Посл. изменение')
        # size for every column by ID
        self.SetColumnWidth(0, 450)
        self.SetColumnWidth(1, 80)
        self.SetColumnWidth(2, 150)
        self.SetColumnWidth(3, 120)
        # add images for supported files
        self.il = wx.ImageList(16, 16)
        for i in images:
            self.il.Add(wx.Bitmap(i))
        self.SetImageList(self.il, wx.IMAGE_LIST_SMALL)

        # events
        self.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.onLeftClick)

    def setCurrentDir(self, dir):
        self.currentDir = dir
        if not self.currentDir.endswith('/'):
            self.currentDir += '/'


    def insertUpDirectory(self):
        #up from this folder to '..'
        self.InsertStringItem(0, '..')
        self.SetItemImage(0, 2)

    def showFilesInDirectory(self, directory='.', j=0):
        self.DeleteAllItems()

        # add at the and of our 'directory' string '/' if doesn't contain this symbol
        if not directory.endswith('/'):
            directory += '/'

        # all founded folders append first
        directories = [f for f in os.listdir(directory) if os.path.isdir(directory+f)]
        directories.sort()

        for i in directories:
            size = os.path.getsize(directory+i)
            sec = os.path.getmtime(directory+i)
            self.InsertStringItem(j, i)
            self.SetStringItem(j, 1, '')
            self.SetStringItem(j, 2, '')
            self.SetStringItem(j, 3, time.strftime('%Y-%m-%d %H:%M', time.localtime(sec)))
            self.SetItemImage(j, 1)
            if (j % 2) == 0:
                self.SetItemBackgroundColour(j, '#e6f1f5')
            j += 1

        # after append all files in directory
        files = [f for f in os.listdir(directory) if os.path.isfile(directory+f)]
        files.sort()

        for i in files:
            (name, ext) = os.path.splitext(i)
            ex = ext[1:]
            size = os.path.getsize(directory+i)
            sec = os.path.getmtime(directory+i)
            self.InsertStringItem(j, name)
            self.SetStringItem(j, 1, ex)
            self.SetStringItem(j, 2, convertSize(size))
            self.SetStringItem(j, 3, time.strftime('%Y-%m-%d %H:%M', time.localtime(sec)))

            # its supported type
            if ex in self.supported_types:
                index = self.supported_types.index(ex) + 4
                self.SetItemImage(j, index)
            # unsupported type; set "unknown ico"
            else:
                self.SetItemImage(j, 0)

            if (j % 2) == 0:
                self.SetItemBackgroundColour(j, '#e6f1f5')
            j += 1

    def ResizeColumns(self, sizeX):
        self.SetColumnWidth(0, sizeX * 0.5625)
        self.SetColumnWidth(1, sizeX * 0.1)
        self.SetColumnWidth(2, sizeX * 0.1875)
        self.SetColumnWidth(3, sizeX * 0.15)

    def onLeftClick(self, event):
        index = self.GetFirstSelected()
        item = self.getFullnameItem(index)
        # TODO: go to some folder inside...

    def getFullnameItem(self, index):
        item = self.GetItem(index, 0).GetText()
        if self.GetItem(index, 1).GetText() != '':
            item += '.' + self.GetItem(index, 1).GetText()
        return item

    def getSelectedItems(self):
        selection = []
        index = self.GetFirstSelected()
        selection.append(self.getFullnameItem(index))
        while len(selection) != self.GetSelectedItemCount():
            index = self.GetNextSelected(index)
            selection.append(self.getFullnameItem(index))
        return selection
{'fraction_non_alphanumeric': 0.1280595508453192, 'fraction_numerical': 0.017789553368660106, 'mean_word_length': 2.0712901975978304, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3812920', 'n_tokens_mistral': 2636, 'n_tokens_neox': 2500, 'n_words': 566}