test_ui.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. import os
  4. import sys
  5. import pygame
  6. if not pygame.display.get_init():
  7. pygame.display.init()
  8. if not pygame.font.get_init():
  9. pygame.font.init()
  10. # from wicd import misc
  11. # noinspection PyPep8
  12. import config_manager as config
  13. import plugins
  14. import skin_manager as SkinManager
  15. import GdUI as UI
  16. plugins = plugins.LoadPlugins(config)
  17. fonts = UI.FontManager
  18. myscriptname = os.path.basename(os.path.realpath(__file__))
  19. SkinManager.load_skin("cpi_default")
  20. def process_event(event, ui_root: UI.Widget):
  21. if event is not None:
  22. if event.type == pygame.QUIT:
  23. sys.exit()
  24. elif event.type == pygame.KEYDOWN:
  25. if event.key == pygame.K_q:
  26. sys.exit()
  27. else:
  28. ui_root.handle_event(event)
  29. def main_loop():
  30. screen = UI.Screen(fps=30, bg_color=SkinManager.get_color("background"))
  31. cont = UI.Container(10, 10, 50, 50, bg_color=(192, 192, 192))
  32. lbl = UI.Label(0, 0, auto_resize=True)
  33. lbl.set_text("Hello the World")
  34. lbl.set_bgcolor(None)
  35. lbl.set_color(SkinManager.get_color("URL"))
  36. lbl.set_font("noto_40")
  37. img = UI.Image(x=30, y=30, image=UI.ImageManager.get_image("blank_icon"))
  38. corner_ul = UI.Image(x=0, y=0, image=UI.ImageManager.get_sprite("corners_tiles", 10, 10, 1))
  39. corner_ur = UI.Image(x=screen.get_rect().width - 10, y=0,
  40. image=UI.ImageManager.get_sprite("corners_tiles", 10, 10, 2))
  41. corner_dl = UI.Image(x=0, y=screen.get_rect().height - 10,
  42. image=UI.ImageManager.get_sprite("corners_tiles", 10, 10, 3))
  43. corner_dr = UI.Image(x=screen.get_rect().width - 10, y=screen.get_rect().height - 10,
  44. image=UI.ImageManager.get_sprite("corners_tiles", 10, 10, 4))
  45. cont.add_child(lbl)
  46. bottom_bar = UI.FlowContainer(x=0, y=screen.get_rect().height - 20, width=screen.get_rect().width, height=20,
  47. bg_color=(83, 83, 83))
  48. lblA = UI.Label(0, 0, auto_resize=True)
  49. lblA.set_text("A")
  50. lblA.set_color(SkinManager.get_color("URL"))
  51. lblA.set_font("noto_13")
  52. lblB = UI.Label(0, 0, auto_resize=True)
  53. lblB.set_text("D")
  54. lblB.set_color(SkinManager.get_color("URL"))
  55. lblB.set_font("noto_13")
  56. lblC = UI.Label(0, 0, auto_resize=True)
  57. lblC.set_text("C")
  58. lblC.set_color((0, 255, 0))
  59. lblC.set_font("noto_13")
  60. lblD = UI.Label(0, 0, auto_resize=True)
  61. lblD.set_text("C")
  62. lblD.set_color((255, 0, 0))
  63. lblD.set_font("noto_13")
  64. bottom_bar.add_left_child(lblA)
  65. bottom_bar.add_left_child(lblB)
  66. bottom_bar.add_right_child(lblC)
  67. bottom_bar.add_right_child(lblD)
  68. bottom_bar.set_margin(10)
  69. screen.add_child(img)
  70. screen.add_child(cont)
  71. screen.add_child(bottom_bar)
  72. screen.add_child(corner_ul)
  73. screen.add_child(corner_ur)
  74. screen.add_child(corner_dl)
  75. screen.add_child(corner_dr)
  76. x = 0
  77. y = 10
  78. while True:
  79. for event in pygame.event.get():
  80. process_event(event, screen)
  81. screen.Draw()
  82. cont.set_position(x, y)
  83. x += 5
  84. if x > 320:
  85. x = 0
  86. y += 1
  87. while (y > 240):
  88. y = y * 2 / 240
  89. # socket_thread(main_screen)
  90. def init():
  91. os.environ['SDL_VIDEO_CENTERED'] = '1'
  92. os.chdir(os.path.dirname(os.path.realpath(__file__)))
  93. if not pygame.image.get_extended():
  94. print("This pygame does not support PNG")
  95. sys.exit()
  96. main_loop()
  97. init()