當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。