demos/04_texteditor.py
author Radek Brich <radek.brich@devl.cz>
Mon, 16 Feb 2015 21:17:43 +0100
changeset 117 8680c2333546
parent 115 b4ff7392003a
permissions -rwxr-xr-x
Update FixedLayout. Add demo launcher.
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
117
8680c2333546 Update FixedLayout. Add demo launcher.
Radek Brich <radek.brich@devl.cz>
parents: 115
diff changeset
     3
import sys
2
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     4
96
68c562e0eb1f Add TextBox, text editor demo. Update demobase.
Radek Brich <radek.brich@devl.cz>
parents: 76
diff changeset
     5
from tuikit.core.application import Application
68c562e0eb1f Add TextBox, text editor demo. Update demobase.
Radek Brich <radek.brich@devl.cz>
parents: 76
diff changeset
     6
#from tuikit.scrollview import ScrollView
68c562e0eb1f Add TextBox, text editor demo. Update demobase.
Radek Brich <radek.brich@devl.cz>
parents: 76
diff changeset
     7
from tuikit.widgets.textbox import TextBox
2
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
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    10
class MyApplication(Application):
106
abcadb7e2ef1 Use Point for mouse events, add them to Container and Widget.
Radek Brich <radek.brich@devl.cz>
parents: 96
diff changeset
    11
2
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    12
    def __init__(self):
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    13
        Application.__init__(self)
115
b4ff7392003a GridLayout: basic implementation.
Radek Brich <radek.brich@devl.cz>
parents: 106
diff changeset
    14
        self.window_manager.sig_keypress.connect(self.on_wm_keypress)
96
68c562e0eb1f Add TextBox, text editor demo. Update demobase.
Radek Brich <radek.brich@devl.cz>
parents: 76
diff changeset
    15
        #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
    16
117
8680c2333546 Update FixedLayout. Add demo launcher.
Radek Brich <radek.brich@devl.cz>
parents: 115
diff changeset
    17
        t = open(sys.argv[0]).read()
96
68c562e0eb1f Add TextBox, text editor demo. Update demobase.
Radek Brich <radek.brich@devl.cz>
parents: 76
diff changeset
    18
        editbox = TextBox(t)
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
    19
96
68c562e0eb1f Add TextBox, text editor demo. Update demobase.
Radek Brich <radek.brich@devl.cz>
parents: 76
diff changeset
    20
        #scroll = ScrollView()
68c562e0eb1f Add TextBox, text editor demo. Update demobase.
Radek Brich <radek.brich@devl.cz>
parents: 76
diff changeset
    21
        #scroll.add(editbox)
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
    22
96
68c562e0eb1f Add TextBox, text editor demo. Update demobase.
Radek Brich <radek.brich@devl.cz>
parents: 76
diff changeset
    23
        self.root_window.add(editbox)
68c562e0eb1f Add TextBox, text editor demo. Update demobase.
Radek Brich <radek.brich@devl.cz>
parents: 76
diff changeset
    24
        #self.root_window.add(scroll, halign='fill', valign='fill')
2
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    25
115
b4ff7392003a GridLayout: basic implementation.
Radek Brich <radek.brich@devl.cz>
parents: 106
diff changeset
    26
    def on_wm_keypress(self, ev):
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
        if ev.keyname == 'escape':
115
b4ff7392003a GridLayout: basic implementation.
Radek Brich <radek.brich@devl.cz>
parents: 106
diff changeset
    28
            self.stop()
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
    29
            return True
2
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    30
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    31
if __name__ == '__main__':
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    32
    app = MyApplication()
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    33
    app.start()
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    34