demo_editor.py
author Radek Brich <radek.brich@devl.cz>
Sun, 22 Feb 2015 09:53:13 +0100
changeset 119 dd91747504dd
parent 76 fa5301e58eca
permissions -rwxr-xr-x
Redraw widgets on request. Add scrollbar demo.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     1
#!/usr/bin/env python3
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     2
# -*- coding: utf-8 -*-
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     3
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     4
import locale
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     5
locale.setlocale(locale.LC_ALL, '')
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     6
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     7
import os
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     8
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     9
from tuikit.application import Application
76
fa5301e58eca Update demo_input, demo_editor. Update ScrollView: show/hide scrollbars as needed on child size requests.
Radek Brich <radek.brich@devl.cz>
parents: 62
diff changeset
    10
from tuikit.scrollview import ScrollView
fa5301e58eca Update demo_input, demo_editor. Update ScrollView: show/hide scrollbars as needed on child size requests.
Radek Brich <radek.brich@devl.cz>
parents: 62
diff changeset
    11
from tuikit.editbox import EditBox
2
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    12
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    13
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    14
class MyApplication(Application):
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    15
    def __init__(self):
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    16
        Application.__init__(self)
45
43b2279b06e1 Clean up Emitter class, simplify event handling. Fix Container.focusnext() method. Add events test (handler auto-registration, order).
Radek Brich <radek.brich@devl.cz>
parents: 41
diff changeset
    17
        self.top.add_handler('keypress', self.on_top_keypress)
2
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    18
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    19
        t = open('tuikit/widget.py').read()
76
fa5301e58eca Update demo_input, demo_editor. Update ScrollView: show/hide scrollbars as needed on child size requests.
Radek Brich <radek.brich@devl.cz>
parents: 62
diff changeset
    20
        editbox = EditBox(t)
fa5301e58eca Update demo_input, demo_editor. Update ScrollView: show/hide scrollbars as needed on child size requests.
Radek Brich <radek.brich@devl.cz>
parents: 62
diff changeset
    21
fa5301e58eca Update demo_input, demo_editor. Update ScrollView: show/hide scrollbars as needed on child size requests.
Radek Brich <radek.brich@devl.cz>
parents: 62
diff changeset
    22
        scroll = ScrollView()
fa5301e58eca Update demo_input, demo_editor. Update ScrollView: show/hide scrollbars as needed on child size requests.
Radek Brich <radek.brich@devl.cz>
parents: 62
diff changeset
    23
        scroll.add(editbox)
fa5301e58eca Update demo_input, demo_editor. Update ScrollView: show/hide scrollbars as needed on child size requests.
Radek Brich <radek.brich@devl.cz>
parents: 62
diff changeset
    24
fa5301e58eca Update demo_input, demo_editor. Update ScrollView: show/hide scrollbars as needed on child size requests.
Radek Brich <radek.brich@devl.cz>
parents: 62
diff changeset
    25
        self.top.add(scroll, halign='fill', valign='fill')
2
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    26
41
37b7dfc3eae6 Update Emitter: All event handlers now have exactly one argument: object inherited from Event class, which carries any data.
Radek Brich <radek.brich@devl.cz>
parents: 34
diff changeset
    27
    def on_top_keypress(self, ev):
37b7dfc3eae6 Update Emitter: All event handlers now have exactly one argument: object inherited from Event class, which carries any data.
Radek Brich <radek.brich@devl.cz>
parents: 34
diff changeset
    28
        if ev.keyname == 'escape':
2
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    29
            self.terminate()
45
43b2279b06e1 Clean up Emitter class, simplify event handling. Fix Container.focusnext() method. Add events test (handler auto-registration, order).
Radek Brich <radek.brich@devl.cz>
parents: 41
diff changeset
    30
            return True
2
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    31
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    32
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    33
if __name__ == '__main__':
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    34
    os.environ['ESCDELAY'] = '25' # do not wait 1 second after pressing Escape key
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    35
    app = MyApplication()
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    36
    app.start()
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    37