demos/03_event.py
author Radek Brich <radek.brich@devl.cz>
Sat, 21 Feb 2015 12:01:57 +0100
changeset 118 8c7970520632
child 119 dd91747504dd
permissions -rwxr-xr-x
Add mouse events, event demo.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
118
8c7970520632 Add mouse events, event demo.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     1
#!/usr/bin/env python3
8c7970520632 Add mouse events, event demo.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     2
8c7970520632 Add mouse events, event demo.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     3
from tuikit.core.buffer import Buffer
8c7970520632 Add mouse events, event demo.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     4
from tuikit.driver.cursesw import CursesWDriver
8c7970520632 Add mouse events, event demo.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     5
8c7970520632 Add mouse events, event demo.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     6
buffer = Buffer()
8c7970520632 Add mouse events, event demo.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     7
line = 0
8c7970520632 Add mouse events, event demo.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     8
with CursesWDriver() as driver:
8c7970520632 Add mouse events, event demo.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     9
    buffer.resize(*driver.size)
8c7970520632 Add mouse events, event demo.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    10
    buffer.puts(str(driver.size), 0, 10)
8c7970520632 Add mouse events, event demo.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    11
    while True:
8c7970520632 Add mouse events, event demo.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    12
        for event in driver.getevents():
8c7970520632 Add mouse events, event demo.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    13
            buffer.puts(str(event), 0, line)
8c7970520632 Add mouse events, event demo.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    14
            line += 1
8c7970520632 Add mouse events, event demo.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    15
        driver.draw(buffer)
8c7970520632 Add mouse events, event demo.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    16
        driver.flush()
8c7970520632 Add mouse events, event demo.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    17
        if line >= buffer.size.h:
8c7970520632 Add mouse events, event demo.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    18
            buffer.fill()
8c7970520632 Add mouse events, event demo.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    19
            line = 0