当前位置: 首页>>代码示例>>Python>>正文


Python Canvas.put_str方法代码示例

本文整理汇总了Python中caca.canvas.Canvas.put_str方法的典型用法代码示例。如果您正苦于以下问题:Python Canvas.put_str方法的具体用法?Python Canvas.put_str怎么用?Python Canvas.put_str使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在caca.canvas.Canvas的用法示例。


在下文中一共展示了Canvas.put_str方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_clear

# 需要导入模块: from caca.canvas import Canvas [as 别名]
# 或者: from caca.canvas.Canvas import put_str [as 别名]
 def test_clear(self):
     """ module canvas: Canvas.clear()
     """
     cv = Canvas(5, 1)
     cv.put_str(0, 0, "test!")
     cv.clear()
     data = cv.export_to_memory("utf8").strip('\n')
     self.assertEqual("     ", data)
开发者ID:Kirkman,项目名称:libcaca,代码行数:10,代码来源:canvas.py

示例2: test_blit

# 需要导入模块: from caca.canvas import Canvas [as 别名]
# 或者: from caca.canvas.Canvas import put_str [as 别名]
 def test_blit(self):
     """ module canvas: Canvas.blit()
     """
     cv1 = Canvas(10, 1)
     cv2 = Canvas(10, 1)
     cv2.put_str(0, 0, "teststring")
     self.assertEqual(0, cv1.blit(0, 0, cv2))
     self.assertEqual("teststring", cv1.export_to_memory("utf8").strip('\n'))
     self.assertRaises(CanvasError, cv1.blit, 0, 0, "abc")
     self.assertRaises(CanvasError, cv1.blit, "a", 0, cv2)
开发者ID:Kirkman,项目名称:libcaca,代码行数:12,代码来源:canvas.py

示例3: test_blit_mask

# 需要导入模块: from caca.canvas import Canvas [as 别名]
# 或者: from caca.canvas.Canvas import put_str [as 别名]
 def test_blit_mask(self):
     """ module canvas: Canvas.blit() (with mask)
     """
     cv1 = Canvas(10, 1)
     cv2 = Canvas(10, 1)
     mask = Canvas(10, 1)
     badm = Canvas()
     cv2.put_str(0, 0, "teststring")
     mask.put_str(0, 0, "####")
     self.assertEqual(0, cv1.blit(0, 0, cv2, mask))
     self.assertEqual("test      ", cv1.export_to_memory("utf8").strip("\n"))
     self.assertRaises(CanvasError, cv1.blit, 0, 0, cv2, badm)
开发者ID:Kirkman,项目名称:libcaca,代码行数:14,代码来源:canvas.py

示例4: main

# 需要导入模块: from caca.canvas import Canvas [as 别名]
# 或者: from caca.canvas.Canvas import put_str [as 别名]
def main():
    """ Main function. """

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

    for idx in range(1, 200):
        cv.create_frame(idx)

    sys.stderr.write("canvas created, size is %dx%d\n" \
                        % (cv.get_width(), cv.get_height()))

    cv.set_size(150, 80)
    sys.stderr.write("canvas expanded, size is %dx%d\n" \
                        % (cv.get_width(), cv.get_height()))

    for idx in range(0, 16):
        cv.set_frame(idx)
        cv.set_color_ansi(caca.COLOR_WHITE, idx)
        cv.fill_box(0, 0, 40, 15, ':')
        cv.set_color_ansi(caca.COLOR_WHITE, caca.COLOR_BLUE)
        cv.put_str((idx * 5) // 2, idx, "カカ")
        cv.set_color_ansi(caca.COLOR_DEFAULT, caca.COLOR_TRANSPARENT)

    cv.set_size(41, 16)
    sys.stderr.write("canvas shrinked, size is %dx%d\n" \
                        % (cv.get_width(), cv.get_height()))

    try:
        dp = Display(cv)
    except DisplayError as err:
        sys.stderr.write("%s\n" % err)
        sys.exit(2)

    dp.set_time(50000)
    sys.stderr.write("display attached, size is %dx%d\n" \
                        % (cv.get_width(), cv.get_height()))

    n = 0
    while not dp.get_event(caca.EVENT_KEY_PRESS, Event(), 0):
        cv.set_frame(n % 16)
        dp.refresh()
        n += 1
开发者ID:graingert,项目名称:libcaca,代码行数:48,代码来源:frames.py

示例5: test_put_str

# 需要导入模块: from caca.canvas import Canvas [as 别名]
# 或者: from caca.canvas.Canvas import put_str [as 别名]
    def test_put_str(self):
        """ module canvas: Canvas.put_str()
        """
        cv = Canvas(10, 1)
        self.assertEqual(10, cv.put_str(0, 0, "teststring"))
        liststring = []
        for i in range(0, 10):
            liststring.append(cv.get_char(i, 0))

        self.assertEqual("teststring", "".join(liststring))
        self.assertRaises(CanvasError, cv.put_str, 0, 0, 111)
        self.assertRaises(CanvasError, cv.put_str, 0, "z", "abc")
开发者ID:Kirkman,项目名称:libcaca,代码行数:14,代码来源:canvas.py

示例6: main

# 需要导入模块: from caca.canvas import Canvas [as 别名]
# 或者: from caca.canvas.Canvas import put_str [as 别名]
def main():
    """ Main function. """
    try:
        cv = Canvas(0, 0)
        dp = Display(cv)
    except (CanvasError, DisplayError) as err:
        sys.stderr.write("%s\n" % err)
        sys.exit(2)

    sprite = Canvas(0, 0)
    sprite.set_color_ansi(caca.COLOR_LIGHTRED, caca.COLOR_BLACK)
    sprite.import_from_memory(THE_PIG, "text")
    sprite.set_handle(sprite.get_width()//2, sprite.get_height()//2)

    cv.set_color_ansi(caca.COLOR_WHITE, caca.COLOR_BLUE)
    cv.put_str(0, 0, "Centered sprite")
    cv.blit(cv.get_width()//2, cv.get_height()//2, sprite, NullCanvas())

    dp.refresh()
    dp.get_event(caca.EVENT_KEY_PRESS, Event(), -1)

    sys.exit(0)
开发者ID:graingert,项目名称:libcaca,代码行数:24,代码来源:blit.py

示例7: main

# 需要导入模块: from caca.canvas import Canvas [as 别名]
# 或者: from caca.canvas.Canvas import put_str [as 别名]
def main():
    """ Main function. """

    try:
        cv = Canvas(8, 2)
    except CanvasError as err:
        sys.stderr.write("%s\n" % err)
        sys.exit(127)

    cv.set_color_ansi(caca.COLOR_WHITE, caca.COLOR_BLACK)
    cv.put_str(0, 0, "ABcde")
    cv.set_color_ansi(caca.COLOR_LIGHTRED, caca.COLOR_BLACK)
    cv.put_str(5, 0, "\\o/")
    cv.set_color_ansi(caca.COLOR_WHITE, caca.COLOR_BLUE)
    cv.put_str(0, 1, "&$âøÿØ?!")

    fonts = caca.get_font_list()
    if not fonts:
        sys.stderr.write("libcaca was compiled without any fonts\n")
        sys.exit(127)

    try:
        f = Font(fonts[0])
    except FontError as err:
        sys.stderr.write("%s\n" % err)
        sys.exit(127)

    w = cv.get_width() * f.get_width()
    h = cv.get_height() * f.get_height()
    buf = ctypes.c_buffer(4 * w * h)

    cv.render(f, buf, w, h, 4 * w)

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

    try:
        if sys.byteorder == 'big':
            dit = Dither(32, w, h, 4 * w, 0xff0000, 0xff00, 0xff, 0xff000000)
        else:
            dit = Dither(32, w, h, 4 * w, 0xff00, 0xff0000, 0xff000000, 0xff)

        dit.bitmap(cv, 0, 0, cv.get_width(), cv.get_height(), buf)
    except DitherError as err:
        sys.stderr.write("%s\n" % err)
        sys.exit(127)
    else:
        dp.refresh()

    dp.get_event(caca.EVENT_KEY_PRESS, Event(), -1)
开发者ID:Kirkman,项目名称:libcaca,代码行数:56,代码来源:font.py

示例8: main

# 需要导入模块: from caca.canvas import Canvas [as 别名]
# 或者: from caca.canvas.Canvas import put_str [as 别名]
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])
开发者ID:Kirkman,项目名称:libcaca,代码行数:41,代码来源:driver.py

示例9: main

# 需要导入模块: from caca.canvas import Canvas [as 别名]
# 或者: from caca.canvas.Canvas import put_str [as 别名]
def main():
    """ Main function. """

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

    cv.set_color_ansi(caca.COLOR_LIGHTGRAY, caca.COLOR_BLACK)
    cv.clear()

    for i in range(0, 16):
        if i >= 8:
            y = i + 3
        else:
            y = i + 2

        cv.set_color_ansi(caca.COLOR_LIGHTGRAY, caca.COLOR_BLACK)
        cv.printf(3, y, "ANSI %i", i)

        for j in range(0, 16):
            if j >= 8:
                x = 13 + (j * 4)
            else:
                x = 12 + (j * 4)
            if i >= 8:
                y = i + 3
            else:
                y = i + 2

            cv.set_color_ansi(i, j)
            cv.put_str(x, y, "Aaホ")

    cv.set_color_ansi(caca.COLOR_LIGHTGRAY, caca.COLOR_BLACK)
    cv.put_str(3, 20, "This is bold    This is blink    This is italics    This is underline")
    cv.set_attr(caca.STYLE_BOLD)
    cv.put_str(3 + 8, 20, "bold")
    cv.set_attr(caca.STYLE_BLINK)
    cv.put_str(3 + 24, 20, "blink")
    cv.set_attr(caca.STYLE_ITALICS)
    cv.put_str(3 + 41, 20, "italics")
    cv.set_attr(caca.STYLE_UNDERLINE)
    cv.put_str(3 + 60, 20, "underline")

    dp.refresh()
    dp.get_event(caca.EVENT_KEY_PRESS, Event(), -1)
开发者ID:Kirkman,项目名称:libcaca,代码行数:50,代码来源:colors.py

示例10: main

# 需要导入模块: from caca.canvas import Canvas [as 别名]
# 或者: from caca.canvas.Canvas import put_str [as 别名]
def main():
    """ Main function. """

    events = []
    quit = 0
    quit_string = ["", "q", "qu", "qui", "quit"]

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

    h = cv.get_height() - 1

    cv.set_color_ansi(caca.COLOR_WHITE, caca.COLOR_BLUE)
    cv.draw_line(0, 0, cv.get_width() - 1, 0, ' ')
    cv.draw_line(0, h, cv.get_width() - 1, h, ' ')
    cv.put_str(0, h, "Type \"quit\" to exit")

    dp.refresh()

    while quit < 4:
        ev = Event()
        if dp.get_event(caca.EVENT_ANY, ev, -1):
            if ev.get_type() == caca.EVENT_KEY_PRESS:
                key = ev.get_key_ch()
                if key == ord('u') and quit == 1:
                    quit += 1
                elif key == ord('i') and quit == 2:
                    quit += 1
                elif key == ord('t') and quit == 3:
                    quit += 1
                elif key == ord('q'):
                    quit = 1
                else:
                    quit = 0

            events.append(ev)

        cv.set_color_ansi(caca.COLOR_LIGHTGRAY, caca.COLOR_BLACK)
        cv.clear()

        #print current event
        cv.set_color_ansi(caca.COLOR_WHITE, caca.COLOR_BLUE)
        cv.draw_line(0, 0, cv.get_width() - 1, 0, ' ')
        if events:
            print_event(cv, 0, 0, events[-1])

        cv.draw_line(0, h, cv.get_width() - 1, h, ' ')
        cv.put_str(0, h, "Type \"quit\" to exit: %s" % quit_string[quit])

        #print previous events
        cv.set_color_ansi(caca.COLOR_WHITE, caca.COLOR_BLACK)
        counts = list(range(0, len(events)-1))
        counts.reverse()
        if len(events) > 1:
            j = 0
            for i in counts:
                if j < h - 1 and events[i].get_type():
                    print_event(cv, 0, ((len(events) - 1) - i), events[i])
                j += 1

        dp.refresh()
开发者ID:Kirkman,项目名称:libcaca,代码行数:67,代码来源:event.py

示例11: LibcacaServer

# 需要导入模块: from caca.canvas import Canvas [as 别名]
# 或者: from caca.canvas.Canvas import put_str [as 别名]

#.........这里部分代码省略.........
        self.dp = Display(self.cv)
        self.ev = Event()
        self.quit = False
        self.width = self.cv.get_width()
        self.height = self.cv.get_height()
        self.camera = Camera(self, 640 , 480)
        self.camera.translation = [3.5, 0, 1]
        self.camera.init()
        self.fps = -1.0
        self.frames = 0
        self.last_t = 0

    def compute_fps(self):
        now = time.time()
        if self.last_t == 0:
            self.last_t = now
            return
        PER = 2.0
        if now - self.last_t >= PER:
            self.fps = self.frames / PER
            self.frames = 0
            self.last_t = now
            return
        else:
            self.frames += 1


    def key_cb(self):
        UP, DOWN, LEFT, RIGHT = 273,274,275,276
        if self.dp.get_event(caca.EVENT_KEY_PRESS, self.ev, 0):
            ch = self.ev.get_key_ch()
            if ch == ord('q'):
                self.quit = True
            elif ch == UP:
                self.camera.rotate(0, 1)
            elif ch == DOWN:
                self.camera.rotate(0, -1)
            elif ch == LEFT:
                self.camera.rotate(1, 0)
            elif ch == RIGHT:
                self.camera.rotate(-1, 0)


    def project(self, p):
        u, v = self.camera.project(p)
        up, vp = int(u*self.width/self.camera.width), int((v)*self.height/self.camera.height)
        return up, self.height - vp


    def draw_floor(self):
        lines=[]
        L = 5
        w = 1
        N = int(L/w)
        self.cv.set_color_ansi(caca.COLOR_WHITE, caca.COLOR_BLACK)

        for i in range(-N,N+1):
            lines.append([i*w, L,0.005])
            lines.append([i*w,-L,0.005])

            lines.append([L    , i*w,0.005])
            lines.append([-L   , i*w,0.005] )


        for i  in range(len(lines)/2):
            p1 = lines[2*i]
            p2 = lines[2*i+1]
            u1, v1 = self.project(p1)
            u2, v2 = self.project(p2)
            self.cv.draw_thin_line(int(u1), int(v1), int(u2), int(v2))

    def draw_robot(self, r):
        self.cv.set_color_ansi(caca.COLOR_GREEN, caca.COLOR_BLACK)
        for j in r.moving_joint_list:
            u, v = self.project(j.T[:3,3])
            radius = 0
            if j.parent:
                up, vp = self.project(j.parent.T[:3,3])
                self.cv.draw_thin_line(int(u), int(v), int(up), int(vp))

        self.cv.set_color_ansi(caca.COLOR_RED, caca.COLOR_BLACK)
        for j in r.moving_joint_list:
            u, v = self.project(j.T[:3,3])
            self.cv.draw_circle(u, v, radius, '@')

    def run(self):
        try:
            while not self.quit:
                self.key_cb()
                self.compute_fps()
                self.cv.clear()
                self.draw_floor()
                for r in self.robots:
                    self.draw_robot(r)

                self.cv.put_str(0,0,"%3.1f FPS"%self.fps)
                self.dp.refresh()
            del self.cv, self.dp, self.ev
        except:
            del self.cv, self.dp, self.ev
开发者ID:duongdang,项目名称:robot-viewer,代码行数:104,代码来源:libcaca_server.py


注:本文中的caca.canvas.Canvas.put_str方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。