<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-

from libavg import avg, AVGApp, ui
from libavg.ui import simple

class SimpleUIApp(AVGApp):
    def init(self):
        hScrollBar = simple.ScrollBar(pos=(10,10), size=(150,20), parent=self._parentNode)
        self.__addValueDisplay(hScrollBar, (175,12))

        vScrollBar = simple.ScrollBar(pos=(15,60), size=(20,150), 
                orientation=ui.Orientation.VERTICAL, parent=self._parentNode)
        vScrollBar.thumbExtent = 5
        vScrollBar.range = (0,10)
        self.__addValueDisplay(vScrollBar, (10,220))

        hSlider = simple.Slider(pos=(10,35), size=(150,20), parent=self._parentNode)
        self.__addValueDisplay(hSlider, (175,38))

        vSlider = simple.Slider(pos=(60.5,60), size=(20,150), 
                orientation=ui.Orientation.VERTICAL, parent=self._parentNode)
        self.__addValueDisplay(vSlider, (55,220))

        image = avg.ImageNode(href="rgb24-64x64.png", size=(1024, 1024))
        self.scrollArea = simple.ScrollArea(contentNode=image, parent=self._parentNode,
                pos=(220,10), size=(220,220))

        imageWidthSlider = simple.Slider(pos=(220,240), size=(220,20), 
                parent=self._parentNode)
        imageWidthSlider.range = (100,1024)
        imageWidthSlider.thumbPos = 1024
        imageWidthSlider.subscribe(ui.ScrollBar.THUMB_POS_CHANGED, self.setImageWidth)

        imageHeightSlider = simple.Slider(pos=(450,10), size=(20,220), 
                orientation=ui.Orientation.VERTICAL, parent=self._parentNode)
        imageHeightSlider.range = (100,1024)
        imageHeightSlider.thumbPos = 1024
        imageHeightSlider.subscribe(ui.ScrollBar.THUMB_POS_CHANGED, self.setImageHeight)

    def setText(self, pos, node):
        node.text = "%.2f"%pos

    def setImageWidth(self, thumbPos):
        self.scrollArea.contentsize = (thumbPos, self.scrollArea.contentsize.y)
    
    def setImageHeight(self, thumbPos):
        self.scrollArea.contentsize = (self.scrollArea.contentsize.x, thumbPos)
    
    def __addValueDisplay(self, scrollBar, pos):
        textNode = avg.WordsNode(pos=pos, parent=self._parentNode)
        scrollBar.subscribe(ui.ScrollBar.THUMB_POS_CHANGED, 
                lambda pos, node=textNode: self.setText(pos, node))
        self.setText(scrollBar.thumbPos, textNode)<commit_msg>uilib branch: sample update.<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-

from libavg import avg, AVGApp, ui
from libavg.ui import simple

class SimpleUIApp(AVGApp):
    def init(self):
        hScrollBar = simple.ScrollBar(pos=(10,10), size=(150,20), parent=self._parentNode)
        self.__addValueDisplay(hScrollBar, (175,12))

        vScrollBar = simple.ScrollBar(pos=(15,60), size=(20,150), 
                orientation=ui.Orientation.VERTICAL, parent=self._parentNode)
        vScrollBar.thumbextent = 5
        vScrollBar.range = (0,10)
        self.__addValueDisplay(vScrollBar, (10,220))

        hSlider = simple.Slider(pos=(10,35), size=(150,20), parent=self._parentNode)
        self.__addValueDisplay(hSlider, (175,38))

        vSlider = simple.Slider(pos=(60.5,60), size=(20,150), 
                orientation=ui.Orientation.VERTICAL, parent=self._parentNode)
        self.__addValueDisplay(vSlider, (55,220))

        image = avg.ImageNode(href="rgb24-64x64.png", size=(1024, 1024))
        self.scrollArea = simple.ScrollArea(contentNode=image, parent=self._parentNode,
                pos=(220,10), size=(220,220))

        imageWidthSlider = simple.Slider(pos=(220,240), size=(220,20), 
                parent=self._parentNode)
        imageWidthSlider.range = (100,1024)
        imageWidthSlider.thumbpos = 1024
        imageWidthSlider.subscribe(ui.ScrollBar.THUMB_POS_CHANGED, self.setImageWidth)

        imageHeightSlider = simple.Slider(pos=(450,10), size=(20,220), 
                orientation=ui.Orientation.VERTICAL, parent=self._parentNode)
        imageHeightSlider.range = (100,1024)
        imageHeightSlider.thumbpos = 1024
        imageHeightSlider.subscribe(ui.ScrollBar.THUMB_POS_CHANGED, self.setImageHeight)

    def setText(self, pos, node):
        node.text = "%.2f"%pos

    def setImageWidth(self, thumbPos):
        self.scrollArea.contentsize = (thumbPos, self.scrollArea.contentsize.y)
    
    def setImageHeight(self, thumbPos):
        self.scrollArea.contentsize = (self.scrollArea.contentsize.x, thumbPos)
    
    def __addValueDisplay(self, scrollBar, pos):
        textNode = avg.WordsNode(pos=pos, parent=self._parentNode)
        scrollBar.subscribe(ui.ScrollBar.THUMB_POS_CHANGED, 
                lambda pos, node=textNode: self.setText(pos, node))
        self.setText(scrollBar.thumbpos, textNode)
{'fraction_non_alphanumeric': 0.12724582540689072, 'fraction_numerical': 0.055379412386387654, 'mean_word_length': 3.266907123534716, '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': '3676045', 'n_tokens_mistral': 1658, 'n_tokens_neox': 1494, 'n_words': 224}