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


Python Canvas.set_size方法代码示例

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


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

示例1: test_set_size

# 需要导入模块: from caca.canvas import Canvas [as 别名]
# 或者: from caca.canvas.Canvas import set_size [as 别名]
    def test_set_size(self):
        """ module canvas: Canvas.set_size()
        """
        cv = Canvas(0, 0)
        cv.set_size(1234, 1001)

        self.assertEqual((1234, 1001), (cv.get_width(), cv.get_height()))
        self.assertRaises(CanvasError, cv.set_size, "a", 12)
        self.assertRaises(CanvasError, cv.set_size, 12, "a")
开发者ID:Kirkman,项目名称:libcaca,代码行数:11,代码来源:canvas.py

示例2: main

# 需要导入模块: from caca.canvas import Canvas [as 别名]
# 或者: from caca.canvas.Canvas import set_size [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

示例3: main

# 需要导入模块: from caca.canvas import Canvas [as 别名]
# 或者: from caca.canvas.Canvas import set_size [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


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