demo_colors.py
author Radek Brich <radek.brich@devl.cz>
Sat, 21 Feb 2015 12:01:57 +0100
changeset 118 8c7970520632
parent 70 db2eab0beb45
permissions -rwxr-xr-x
Add mouse events, event demo.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
46
2b43a7f38c34 Minor updates. Replace super() with direct class reference. Add demo_colors.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     1
#!/usr/bin/env python3
2b43a7f38c34 Minor updates. Replace super() with direct class reference. Add demo_colors.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     2
# -*- coding: utf-8 -*-
2b43a7f38c34 Minor updates. Replace super() with direct class reference. Add demo_colors.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     3
2b43a7f38c34 Minor updates. Replace super() with direct class reference. Add demo_colors.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     4
import locale
2b43a7f38c34 Minor updates. Replace super() with direct class reference. Add demo_colors.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     5
locale.setlocale(locale.LC_ALL, '')
2b43a7f38c34 Minor updates. Replace super() with direct class reference. Add demo_colors.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     6
62
2f61931520c9 Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
     7
from tuikit import Application, Window, Label, AnchorLayout, VerticalLayout
46
2b43a7f38c34 Minor updates. Replace super() with direct class reference. Add demo_colors.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     8
2b43a7f38c34 Minor updates. Replace super() with direct class reference. Add demo_colors.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     9
2b43a7f38c34 Minor updates. Replace super() with direct class reference. Add demo_colors.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    10
class MyApplication(Application):
2b43a7f38c34 Minor updates. Replace super() with direct class reference. Add demo_colors.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    11
    def __init__(self):
62
2f61931520c9 Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
    12
        Application.__init__(self, top_layout=AnchorLayout)
46
2b43a7f38c34 Minor updates. Replace super() with direct class reference. Add demo_colors.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    13
        self.top.add_handler('keypress', self.on_top_keypress)
2b43a7f38c34 Minor updates. Replace super() with direct class reference. Add demo_colors.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    14
62
2f61931520c9 Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
    15
        win = Window(inner_layout=VerticalLayout)
2f61931520c9 Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
    16
        win.resize(30,10)
2f61931520c9 Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
    17
        win.title = 'styles'
60
fccca2a60492 DriverSDL: Implement blink attribute.
Radek Brich <radek.brich@devl.cz>
parents: 52
diff changeset
    18
52
50a1857557da Update SDL driver: Enlarge char, attr to 32 bits, 64 bits per terminal cell. Colors and attributes are complete, only blink does not work.
Radek Brich <radek.brich@devl.cz>
parents: 46
diff changeset
    19
        for attr in ['blink', 'bold', 'standout', 'underline']:
46
2b43a7f38c34 Minor updates. Replace super() with direct class reference. Add demo_colors.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    20
            label = Label(attr)
2b43a7f38c34 Minor updates. Replace super() with direct class reference. Add demo_colors.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    21
            label.color = 'test-' + attr
62
2f61931520c9 Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
    22
            win.add(label)
46
2b43a7f38c34 Minor updates. Replace super() with direct class reference. Add demo_colors.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    23
62
2f61931520c9 Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
    24
        self.top.add(win)
46
2b43a7f38c34 Minor updates. Replace super() with direct class reference. Add demo_colors.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    25
62
2f61931520c9 Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
    26
    def apply_theme(self):
2f61931520c9 Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
    27
        Application.apply_theme(self)
70
db2eab0beb45 Update drivers: Rename setcolor to defcolor, add real setcolor which ignores color stack.
Radek Brich <radek.brich@devl.cz>
parents: 62
diff changeset
    28
        self.driver.defcolor('test-blink',              'cyan on blue, blink')
db2eab0beb45 Update drivers: Rename setcolor to defcolor, add real setcolor which ignores color stack.
Radek Brich <radek.brich@devl.cz>
parents: 62
diff changeset
    29
        self.driver.defcolor('test-bold',               'cyan on blue, bold')
db2eab0beb45 Update drivers: Rename setcolor to defcolor, add real setcolor which ignores color stack.
Radek Brich <radek.brich@devl.cz>
parents: 62
diff changeset
    30
        self.driver.defcolor('test-standout',           'cyan on blue, standout')
db2eab0beb45 Update drivers: Rename setcolor to defcolor, add real setcolor which ignores color stack.
Radek Brich <radek.brich@devl.cz>
parents: 62
diff changeset
    31
        self.driver.defcolor('test-underline',          'cyan on blue, underline')
52
50a1857557da Update SDL driver: Enlarge char, attr to 32 bits, 64 bits per terminal cell. Colors and attributes are complete, only blink does not work.
Radek Brich <radek.brich@devl.cz>
parents: 46
diff changeset
    32
46
2b43a7f38c34 Minor updates. Replace super() with direct class reference. Add demo_colors.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    33
    def on_top_keypress(self, ev):
2b43a7f38c34 Minor updates. Replace super() with direct class reference. Add demo_colors.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    34
        if ev.keyname == 'escape':
2b43a7f38c34 Minor updates. Replace super() with direct class reference. Add demo_colors.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    35
            self.terminate()
2b43a7f38c34 Minor updates. Replace super() with direct class reference. Add demo_colors.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    36
            return True
2b43a7f38c34 Minor updates. Replace super() with direct class reference. Add demo_colors.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    37
2b43a7f38c34 Minor updates. Replace super() with direct class reference. Add demo_colors.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    38
2b43a7f38c34 Minor updates. Replace super() with direct class reference. Add demo_colors.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    39
if __name__ == '__main__':
2b43a7f38c34 Minor updates. Replace super() with direct class reference. Add demo_colors.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    40
    app = MyApplication()
2b43a7f38c34 Minor updates. Replace super() with direct class reference. Add demo_colors.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    41
    app.start()
2b43a7f38c34 Minor updates. Replace super() with direct class reference. Add demo_colors.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    42