<commit_before>import os

from rctkdemos.demos import serve_demo, standalone
from rctk.widgets import Image
from rctk.resourceregistry import addResource, FileResource

class Demo(object):
    title = "Image"
    description = "Demonstrates the Image control"

    def build(self, tk, parent):
        resources = [ 
            addResource(FileResource("resources/nyancat-%d.png" % i,
                                     name="nyancat-%d" % i,
                                     type="image/png"))
            for i in range(0, 12)]
        img = Image(tk, resource=resources[0])
        parent.append(img)

        def update_image(i):
            img.resource = resources[i]
            tk.set_timer(lambda e: update_image((i+1) % 12), 250)

        update_image(0)
    
Standalone = standalone(Demo)

if __name__ == '__main__':
    serve_demo(Demo)<commit_msg>make demo start/stoppable, avoids unneccessary load on browser/demoserver<commit_after>from rctkdemos.demos import serve_demo, standalone
from rctk.widgets import Image, Button
from rctk.resourceregistry import addResource, FileResource

class Demo(object):
    title = "Image"
    description = "Demonstrates the Image control"

    def build(self, tk, parent):
        self.running = False

        resources = [ 
            addResource(FileResource("resources/nyancat-%d.png" % i,
                                     name="nyancat-%d" % i,
                                     type="image/png"))
            for i in range(0, 12)]
        img = Image(tk, resource=resources[0])
        button = Button(tk, "Start")
        parent.append(img)
        parent.append(button)

        def update_image(i):
            if self.running:
                img.resource = resources[i]
                tk.set_timer(lambda e: update_image((i+1) % 12), 250)

        def stop(e):
            self.running = False
            button.text = "Start"
            button.click = start

        def start(e):
            self.running = True
            button.click = stop
            button.text = "Stop"
            update_image(0)

        button.click = start

Standalone = standalone(Demo)

if __name__ == '__main__':
    serve_demo(Demo)
{'fraction_non_alphanumeric': 0.10154826958105646, 'fraction_numerical': 0.010018214936247723, 'mean_word_length': 1.9769647696476964, '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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4794461', 'n_tokens_mistral': 673, 'n_tokens_neox': 621, 'n_words': 151}