test_ui.py 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. import os
  4. import socket
  5. import sys
  6. import pygame
  7. if not pygame.display.get_init():
  8. pygame.display.init()
  9. if not pygame.font.get_init():
  10. pygame.font.init()
  11. # from wicd import misc
  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. global sound_patch
  31. screen = UI.Screen(fps=30, bg_color=SkinManager.get_color("background"))
  32. cont = UI.Container(10, 10, 50, 50, bg_color=(192, 192, 192))
  33. lbl = UI.Label(0, 0, auto_resize=True)
  34. lbl.SetText("Hello the World")
  35. lbl.set_bgcolor(None)
  36. lbl.set_color(SkinManager.get_color("URL"))
  37. lbl.set_font("noto_40")
  38. img = UI.Image(x=30, y=30, image=UI.ImageManager.get_image("blank_icon"))
  39. corner_ul = UI.Image(x=0, y=0, image=UI.ImageManager.get_sprite("corners_tiles", 10, 10, 1))
  40. corner_ur = UI.Image(x=screen.get_rect().width - 10, y=0,
  41. image=UI.ImageManager.get_sprite("corners_tiles", 10, 10, 2))
  42. corner_dl = UI.Image(x=0, y=screen.get_rect().height - 10,
  43. image=UI.ImageManager.get_sprite("corners_tiles", 10, 10, 3))
  44. corner_dr = UI.Image(x=screen.get_rect().width - 10, y=screen.get_rect().height - 10,
  45. image=UI.ImageManager.get_sprite("corners_tiles", 10, 10, 4))
  46. cont.add_child(lbl)
  47. bottom_bar = UI.FlowContainer(x=0, y=screen.get_rect().height - 20, width=screen.get_rect().width, height=20,
  48. bg_color=(83, 83, 83))
  49. lblA = UI.Label(0, 0, auto_resize=True)
  50. lblA.SetText("A")
  51. lblA.set_color(SkinManager.get_color("URL"))
  52. lblA.set_font("noto_13")
  53. lblB = UI.Label(0, 0, auto_resize=True)
  54. lblB.SetText("D")
  55. lblB.set_color(SkinManager.get_color("URL"))
  56. lblB.set_font("noto_13")
  57. lblC = UI.Label(0, 0, auto_resize=True)
  58. lblC.SetText("C")
  59. lblC.set_color((0, 255, 0))
  60. lblC.set_font("noto_13")
  61. lblD = UI.Label(0, 0, auto_resize=True)
  62. lblD.SetText("C")
  63. lblD.set_color((255, 0, 0))
  64. lblD.set_font("noto_13")
  65. bottom_bar.add_left_child(lblA)
  66. bottom_bar.add_left_child(lblB)
  67. bottom_bar.add_right_child(lblC)
  68. bottom_bar.add_right_child(lblD)
  69. bottom_bar.set_margin(10)
  70. screen.add_child(img)
  71. screen.add_child(cont)
  72. screen.add_child(bottom_bar)
  73. screen.add_child(corner_ul)
  74. screen.add_child(corner_ur)
  75. screen.add_child(corner_dl)
  76. screen.add_child(corner_dr)
  77. x = 0
  78. y = 10
  79. while True:
  80. for event in pygame.event.get():
  81. process_event(event, screen)
  82. screen.Draw()
  83. cont.set_position(x, y)
  84. x += 5
  85. if x > 320:
  86. x = 0
  87. y += 1
  88. while(y > 240):
  89. y = y * 2 / 240
  90. # socket_thread(main_screen)
  91. def init():
  92. os.environ['SDL_VIDEO_CENTERED'] = '1'
  93. os.chdir(os.path.dirname(os.path.realpath(__file__)))
  94. if pygame.image.get_extended() == False:
  95. print("This pygame does not support PNG")
  96. sys.exit()
  97. main_loop()
  98. init()