brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.1 KiB · d05c268 Raw
75 lines · python
1#!/usr/bin/env python2##===-- sandbox.py -------------------------------------------*- Python -*-===##3##4# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.5# See https://llvm.org/LICENSE.txt for license information.6# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception7##8##===----------------------------------------------------------------------===##9 10 11import curses12 13import os14import signal15import sys16 17import queue18 19import cui20 21event_queue = None22 23 24class SandboxUI(cui.CursesUI):25    def __init__(self, screen, event_queue):26        super(SandboxUI, self).__init__(screen, event_queue)27 28        height, width = self.screen.getmaxyx()29        w2 = width / 230        h2 = height / 231 32        self.wins = []33        # self.wins.append(cui.TitledWin(w2, h2, w2, h2, "Test Window 4"))34        list_win = cui.ListWin(w2, h2, w2, h2)35        for i in range(0, 40):36            list_win.addItem("Item %s" % i)37        self.wins.append(list_win)38        self.wins.append(cui.TitledWin(0, 0, w2, h2, "Test Window 1"))39        self.wins.append(cui.TitledWin(w2, 0, w2, h2, "Test Window 2"))40        self.wins.append(cui.TitledWin(0, h2, w2, h2, "Test Window 3"))41 42        # def callback(s, content):43        #  self.wins[0].win.scroll(1)44        #  self.wins[0].win.addstr(10, 0, '%s: %s' % (s, content))45        #  self.wins[0].win.scroll(1)46        #  self.el.showPrompt(10, 0)47 48        # self.wins[0].win.scrollok(1)49        # self.el = cui.CursesEditLine(self.wins[0].win, None,50        #  lambda c: callback('got', c), lambda c: callback('tab', c))51        # self.el.prompt = '>>> '52        # self.el.showPrompt(10, 0)53 54    def handleEvent(self, event):55        if isinstance(event, int):56            if event == ord("q"):57                sys.exit(0)58            # self.el.handleEvent(event)59        super(SandboxUI, self).handleEvent(event)60 61 62def main(screen):63    global event_queue64    event_queue = queue.Queue()65 66    sandbox = SandboxUI(screen, event_queue)67    sandbox.eventLoop()68 69 70if __name__ == "__main__":71    try:72        curses.wrapper(main)73    except KeyboardInterrupt:74        exit()75