Ejemplo n.º 1
0
class TartanDisplay(object):
    def __init__(self, app, spec, driver='gl'):
        self.app = app
        self.spec = spec
        self.widgets = []
        self.focus_order = None
        self.parser = FileParser(self.app)
        self.widgets = self.parser.parse(self.spec["widgets"])
        self.canvas = Canvas(self.spec["app"]["width"],
                             self.spec["app"]["height"])
        self.display = Display(self.canvas)
        self.display.set_driver(driver)

        if len(self.widgets) > 0:
            self.focused_widget = self.widgets[0]
        self.build_focus_order()

    def mark_dirty(self):
        self.dirty = True

    def mark_clean(self):
        self.dirty = False

    def build_focus_order(self):
        self.focus_order = self.widgets

    def refresh(self):
        self.canvas.clear()
        self.build_display()
        self.display.refresh()

    def blit(self, widget):
        self.canvas.blit(widget.anchor[0], widget.anchor[1], widget.canvas)

    def build_display(self):
        self.canvas.clear()
        for widget in self.widgets:
            widget.draw()
            self.blit(widget)
Ejemplo n.º 2
0
def main():
    """ Main function. """

    lst = caca.get_display_driver_list()
    cur = 0

    try:
        cv = Canvas(0, 0)
        dp = Display(cv)
    except (CanvasError, DisplayError) as err:
        sys.stderr.write("%s\n" % err)
        sys.exit(127)

    cv.set_color_ansi(caca.COLOR_WHITE, caca.COLOR_BLACK)

    while True:
        cv.put_str(1, 0, "Available drivers:")
        cur_driver = dp.get_driver()
        n = 0
        for driver, desc in lst:
            if driver == cur_driver:
                cv.put_str(2, n + 2, "%s %s (%s)" % ('*', driver, desc))
            else:
                cv.put_str(2, n + 2, "%s %s (%s)" % (' ', driver, desc))
            n += 1

        cv.put_str(2, n + 3, "Switching driver in 5 seconds")
        dp.refresh()

        if dp.get_event(caca.EVENT_KEY_PRESS, Event(), 5000000):
            break

        cur += 1
        if cur < len(lst) and lst[cur][0] == "raw":
            cur += 1
        if cur >= len(lst):
            cur = 0

        dp.set_driver(lst[cur][0])
Ejemplo n.º 3
0
def main():
    """ Main function. """

    lst = caca.get_display_driver_list()
    cur = 0

    try:
        cv = Canvas(0, 0)
        dp = Display(cv)
    except (CanvasError, DisplayError) as err:
        sys.stderr.write("%s\n" % err)
        sys.exit(127)

    cv.set_color_ansi(caca.COLOR_WHITE, caca.COLOR_BLACK)

    while True:
        cv.put_str(1, 0, "Available drivers:")
        cur_driver = dp.get_driver()
        n = 0
        for driver, desc in lst:
            if driver == cur_driver:
                cv.put_str(2, n + 2, "%s %s (%s)" % ('*', driver, desc))
            else:
                cv.put_str(2, n + 2, "%s %s (%s)" % (' ', driver, desc))
            n += 1

        cv.put_str(2, n + 3, "Switching driver in 5 seconds")
        dp.refresh()

        if dp.get_event(caca.EVENT_KEY_PRESS, Event(), 5000000):
            break

        cur += 1
        if cur < len(lst) and lst[cur][0] == "raw":
            cur += 1
        if cur >= len(lst):
            cur = 0

        dp.set_driver(lst[cur][0])