<commit_before>from rctkdemos.demos import serve_demo, standalone
from rctk.widgets import Text, Button, StaticText, Panel, Collection
from rctk.layouts import Grid


class Demo(object):
    title = "Collection"
    description = "Demonstrates the Collection control"
    
    def append(self, event):
        if len(self.text.value):
            self.collection.append(self.text.value)
            self.text.value = ''
            self.collection.layout()
    
    def remove(self, event):
        if len(self.text.value):
            self.collection.remove(self.text.value)
            self.text.value = ''
            self.collection.layout()
    
    def clear(self, event):
        self.collection.clear()
        self.text.value = ''
        self.collection.layout()
    
    def build(self, tk, parent):
        parent.setLayout(Grid(rows=2, columns=6))
        self.text = Text(tk)
        append_button = Button(tk, 'Append')
        append_button.click = self.append
        remove_button = Button(tk, 'Remove')
        remove_button.click = self.remove
        clear_button = Button(tk, 'Clear')
        clear_button.click = self.clear
        parent.append(self.text)
        parent.append(append_button)
        parent.append(StaticText(tk, ' or '))
        parent.append(remove_button)
        parent.append(StaticText(tk, ' or '))
        parent.append(clear_button)
        
        self.collection = Collection(tk, StaticText)
        self.collection.extend(['Hello', 'World', 'Bye'])
        parent.append(self.collection)
    

Standalone = standalone(Demo)

if __name__ == '__main__':
    serve_demo(Demo)

<commit_msg>Improved Collection demo<commit_after>from rctkdemos.demos import serve_demo, standalone
from rctk.widgets import Text, Button, StaticText, Panel, Collection
from rctk.layouts import Grid


class Demo(object):
    title = "Collection"
    description = "Demonstrates the Collection control"
    
    def append(self, event):
        if len(self.text.value):
            self.collection.append(self.text.value)
            self.text.value = ''
    
    def remove(self, event):
        if len(self.text.value):
            self.collection.remove(self.text.value)
            self.text.value = ''
    
    def clear(self, event):
        self.collection.clear()
        self.text.value = ''
    
    def build(self, tk, parent):
        parent.setLayout(Grid(rows=2, columns=4, expand_vertical=True))
        self.text = Text(tk)
        append_button = Button(tk, 'Append')
        append_button.click = self.append
        remove_button = Button(tk, 'Remove')
        remove_button.click = self.remove
        clear_button = Button(tk, 'Clear')
        clear_button.click = self.clear
        parent.append(self.text)
        parent.append(append_button)
        parent.append(remove_button)
        parent.append(clear_button)
        self.collection = Collection(tk, StaticText)
        self.collection.extend(['Hello', 'World', 'Bye'])
        parent.append(self.collection)
    

Standalone = standalone(Demo)

if __name__ == '__main__':
    serve_demo(Demo)


{'fraction_non_alphanumeric': 0.1147276828875282, 'fraction_numerical': 0.0012890750886239124, 'mean_word_length': 2.51131221719457, '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': '5373948', 'n_tokens_mistral': 929, 'n_tokens_neox': 908, 'n_words': 180}