Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 
 

75 linhas
2.1 KiB

  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. # frames canvas frame switching features
  5. # Copyright (c) 2010 Alex Foulon <alxf@lavabit.com>
  6. #
  7. # This file is a Python port of "examples/frames.c"
  8. # which is:
  9. # Copyright (c) 2006-2010 Sam Hocevar <sam@hocevar.net>
  10. # All Rights Reserverd
  11. #
  12. # This library is free software. It comes without any warranty, to
  13. # the extent permitted by applicable law. You can redistribute it
  14. # and/or modify it under the terms of the Do What the Fuck You Want
  15. # to Public License, Version 2, as published by Sam Hocevar. See
  16. # http://www.wtfpl.net/ for more details.
  17. #
  18. import sys
  19. import caca
  20. from caca.canvas import Canvas, CanvasError
  21. from caca.display import Display, DisplayError, Event
  22. def main():
  23. """ Main function. """
  24. try:
  25. cv = Canvas(0, 0)
  26. except CanvasError as err:
  27. sys.stderr.write("%s\n" % err)
  28. sys.exit(2)
  29. for idx in range(1, 200):
  30. cv.create_frame(idx)
  31. sys.stderr.write("canvas created, size is %dx%d\n" \
  32. % (cv.get_width(), cv.get_height()))
  33. cv.set_size(150, 80)
  34. sys.stderr.write("canvas expanded, size is %dx%d\n" \
  35. % (cv.get_width(), cv.get_height()))
  36. for idx in range(0, 16):
  37. cv.set_frame(idx)
  38. cv.set_color_ansi(caca.COLOR_WHITE, idx)
  39. cv.fill_box(0, 0, 40, 15, ':')
  40. cv.set_color_ansi(caca.COLOR_WHITE, caca.COLOR_BLUE)
  41. cv.put_str((idx * 5) // 2, idx, "カカ")
  42. cv.set_color_ansi(caca.COLOR_DEFAULT, caca.COLOR_TRANSPARENT)
  43. cv.set_size(41, 16)
  44. sys.stderr.write("canvas shrinked, size is %dx%d\n" \
  45. % (cv.get_width(), cv.get_height()))
  46. try:
  47. dp = Display(cv)
  48. except DisplayError as err:
  49. sys.stderr.write("%s\n" % err)
  50. sys.exit(2)
  51. dp.set_time(50000)
  52. sys.stderr.write("display attached, size is %dx%d\n" \
  53. % (cv.get_width(), cv.get_height()))
  54. n = 0
  55. while not dp.get_event(caca.EVENT_KEY_PRESS, Event(), 0):
  56. cv.set_frame(n % 16)
  57. dp.refresh()
  58. n += 1
  59. if __name__ == "__main__":
  60. main()