<commit_before># encoding: utf-8

from efl.elementary.label import Label
from efl.elementary.box import Box
from efl.elementary.table import Table
from efl.elementary.button import Button
from efl.elementary.entry import Entry
from efl.elementary.scroller import Scroller, Scrollable, ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_ON, ELM_SCROLLER_POLICY_AUTO
from efl.evas import EVAS_HINT_EXPAND, EVAS_HINT_FILL

EXPAND_BOTH = EVAS_HINT_EXPAND, EVAS_HINT_EXPAND
EXPAND_HORIZ = EVAS_HINT_EXPAND, 0.0
FILL_BOTH = EVAS_HINT_FILL, EVAS_HINT_FILL
FILL_HORIZ = EVAS_HINT_FILL, 0.5

class SortedList(Scroller):

    """

    A "spread sheet like" widget for elementary.

    Argument "titles" is a list, with each element being a tuple:
    (<Display Text>, <Sortable>)

    """

    def __init__(self, parent_widget, titles=None, initial_sort=0,
        ascending=True, *args, **kwargs):
        Scroller.__init__(self, parent_widget, *args, **kwargs)
        self.policy_set(ELM_SCROLLER_POLICY_AUTO, ELM_SCROLLER_POLICY_OFF)

        self.mainBox = Box(self, size_hint_weight=EXPAND_BOTH,
                size_hint_align=FILL_BOTH)
        self.mainBox.show()

        self.header = titles
        self.sort_column = initial_sort
        self.sort_column_ascending = ascending

        self.rows = []
        self.header_row = []
        
        self.headerTbl = Table(self, size_hint_weight=EXPAND_HORIZ,
                size_hint_align=FILL_HORIZ)
        self.headerTbl.homogeneous_set(True)
        self.headerTbl.show()
        
        self.listTbl = Table(self, size_hint_weight=EXPAND_BOTH,
                size_hint_align=FILL_BOTH)
        self.listTbl.homogeneous_set(True)
        self.listTbl.show()
        
        self.mainScr = Scroller(self, size_hint_weight=EXPAND_BOTH,
                size_hint_align=FILL_BOTH)
        self.mainScr.policy_set(ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_AUTO)
        self.mainScr.content = self.listTbl
        self.mainScr.show()
        
        self.lists = []

        #self.pack_end(self.header_box)

        if titles is not None:
            self.header_row_pack(titles)
            
        self.mainBox.pack_end(self.headerTbl)
        self.mainBox.pack_end(self.mainScr)
        
        self.content = self.mainBox
        self.show()

    def header_row_pack(self, titles):

        """Takes a list (or a tuple) of tuples (string, bool, int) and packs them to
        the first row of the table."""

        assert isinstance(titles, (list, tuple))
        for t in titles:
            assert isinstance(t, tuple)
            assert len(t) == 3
            title, sortable, wdth = t
            try:
                assert isinstance(title, basestring)
            except:
                assert isinstance(title, str)
            assert isinstance(sortable, bool)
            assert isinstance(wdth, int)

        def sort_btn_cb(button, col):
            if self.sort_column == col:
                self.reverse()
            else:
                self.sort_by_column(col)

        currentwdth = 0
        for count, t in enumerate(titles):
            title, sortable, wdth = t
            btn = Button(self, size_hint_weight=EXPAND_HORIZ,
                size_hint_align=FILL_HORIZ, text=title)
            btn.callback_clicked_add(sort_btn_cb, count)
            if not sortable:
                btn.disabled = True
            btn.show()
            self.headerTbl.pack(btn, currentwdth, 0, wdth, 1)
            self.header_row.append(btn)
            
            bx = Box(self, size_hint_weight=EXPAND_BOTH,
                size_hint_align=FILL_BOTH)
            bx.show()
            
            self.listTbl.pack(bx, currentwdth, 0, wdth, 1)
            self.lists.append(bx)
            
            currentwdth += wdth


    def row_pack(self, row, sort=True):

        """Takes a list of items and packs them to the table."""

        assert len(row) == len(self.header_row), (
            "The row you are trying to add to this sorted list has the wrong "
            "number of items! expected: %i got: %i" % (
                len(self.header_row), len(row)
                )
            )

        self.rows.append(row)
        self.add_row(row)

        if sort:
            self.sort_by_column(self.sort_column)
    
    def add_row(self, row):
        #print("Test %s"%row)
        for count, item in enumerate(row):
            self.lists[count].pack_end(item)<commit_msg>Working on moving sorted list to genlist. Currently broken in this commit. Use release for working version<commit_after># encoding: utf-8

from efl.elementary.label import Label
from efl.elementary.box import Box
from efl.elementary.table import Table
from efl.elementary.button import Button
from efl.elementary.genlist import Genlist, GenlistItemClass
from efl.elementary.scroller import Scroller, Scrollable, ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_ON, ELM_SCROLLER_POLICY_AUTO
from efl.evas import EVAS_HINT_EXPAND, EVAS_HINT_FILL, EVAS_ASPECT_CONTROL_VERTICAL

EXPAND_BOTH = EVAS_HINT_EXPAND, EVAS_HINT_EXPAND
EXPAND_HORIZ = EVAS_HINT_EXPAND, 0.0
FILL_BOTH = EVAS_HINT_FILL, EVAS_HINT_FILL
FILL_HORIZ = EVAS_HINT_FILL, 0.5

class SortedList(Scroller):

    """

    A "spread sheet like" widget for elementary.

    Argument "titles" is a list, with each element being a tuple:
    (<Display Text>, <Sortable>, <Width>)

    """

    def __init__(self, parent_widget, titles=None, initial_sort=0,
        ascending=True, *args, **kwargs):
        Scroller.__init__(self, parent_widget, *args, **kwargs)
        self.policy_set(ELM_SCROLLER_POLICY_AUTO, ELM_SCROLLER_POLICY_OFF)

        self.mainBox = Box(self, size_hint_weight=EXPAND_BOTH,
                size_hint_align=FILL_BOTH)
        self.mainBox.show()

        self.header = titles
        self.sort_column = initial_sort
        self.sort_column_ascending = ascending

        self.rows = []
        self.header_row = []
        self.header_widths = []
        
        self.headerTbl = Table(self, size_hint_weight=EXPAND_HORIZ,
                size_hint_align=FILL_HORIZ)
        self.headerTbl.homogeneous_set(True)
        self.headerTbl.show()
        
        self.genList = Genlist(self, size_hint_weight=EXPAND_BOTH,  size_hint_align=FILL_BOTH)
        self.genList.show()
        
        self.lists = []

        #self.pack_end(self.header_box)

        if titles is not None:
            self.header_row_pack(titles)
            
        self.mainBox.pack_end(self.headerTbl)
        self.mainBox.pack_end(self.genList)
        
        self.content = self.mainBox
        self.show()

    def header_row_pack(self, titles):

        """Takes a list (or a tuple) of tuples (string, bool, int) and packs them to
        the first row of the table."""

        assert isinstance(titles, (list, tuple))
        for t in titles:
            assert isinstance(t, tuple)
            assert len(t) == 3
            title, sortable, wdth = t
            try:
                assert isinstance(title, basestring)
            except:
                assert isinstance(title, str)
            assert isinstance(sortable, bool)
            assert isinstance(wdth, int)

        def sort_btn_cb(button, col):
            if self.sort_column == col:
                self.reverse()
            else:
                self.sort_by_column(col)

        currentwdth = 0
        for count, t in enumerate(titles):
            title, sortable, wdth = t
            btn = Button(self, size_hint_weight=EXPAND_HORIZ,
                size_hint_align=FILL_HORIZ, text=title)
            btn.callback_clicked_add(sort_btn_cb, count)
            if not sortable:
                btn.disabled = True
            btn.show()
            self.headerTbl.pack(btn, currentwdth, 0, wdth, 1)
            self.header_row.append(btn)
            self.header_widths.append(wdth)
            
            currentwdth += wdth

    def row_pack(self, row, sort=True):

        """Takes a list of items and packs them to the table."""

        assert len(row) == len(self.header_row), (
            "The row you are trying to add to this sorted list has the wrong "
            "number of items! expected: %i got: %i" % (
                len(self.header_row), len(row)
                )
            )

        self.rows.append(row)
        self.add_row(row)

        if sort:
            self.sort_by_column(self.sort_column)
    
    def add_row(self, row):
        def gl_text_get(obj, part, item_data):
            return item_data

        def gl_content_get(obj, part, item_data):
            rowTbl = Table(self, size_hint_weight=EXPAND_BOTH,
                size_hint_align=FILL_BOTH, size_hint_aspect=(EVAS_ASPECT_CONTROL_VERTICAL, 1, 1))
            rowTbl.homogeneous_set(True)
            
            currentwdth = 0
            for count, item in enumerate(item_data):
                rowTbl.pack(item, currentwdth, 0, self.header_widths[count], 1)
                
                currentwdth += self.header_widths[count]
            
            #rowTbl.show()
            
            return rowTbl
                
        def gl_state_get(obj, part, item_data):
            return False
            
        def gl_item_sel(gli, gl, *args, **kwargs):
            print("\n---GenlistItem selected---")
            print(gli)
            print(gl)
            print(args)
            print(kwargs)
            print(("item_data: %s" % gli.data_get()))
            
        itc = GenlistItemClass(item_style="full",
                            text_get_func=gl_text_get,
                            content_get_func=gl_content_get,
                            state_get_func=gl_state_get)
                            
        self.genList.item_append(itc, row, func=gl_item_sel)
{'fraction_non_alphanumeric': 0.08688993261180314, 'fraction_numerical': 0.002756789871349806, 'mean_word_length': 2.024081506637851, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, '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': '2944900', 'n_tokens_mistral': 3216, 'n_tokens_neox': 3094, 'n_words': 648}