LibreLightDesk.py 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. #!/usr/bin/python3
  2. import time
  3. boot = time.time()
  4. import random
  5. import os
  6. import sys
  7. #sys.path.insert(0,os.path.realpath(os.getcwd() + '/..'))
  8. sys.path.insert(0,"/opt/LibreLight/Xdesk/")
  9. print(sys.path)
  10. print()
  11. import pathlib
  12. BASE_PATH = "/opt/LibreLight/Xdesk/"
  13. _file_path=pathlib.Path(__file__)
  14. print("__file__ =",_file_path)
  15. import tool.movewin as movewin
  16. CAPTION = 'LibreLight Start XX'
  17. movewin.check_is_started(CAPTION,_file_path)
  18. from lib.xcolor import *
  19. # ===== GUI =========
  20. import pygame
  21. import pygame.gfxdraw
  22. import pygame.font
  23. pg = pygame
  24. main_size=(550,400)
  25. window = pygame.display.set_mode(main_size,pg.RESIZABLE,32)
  26. pg = pygame
  27. pygame.init()
  28. pygame.mixer.quit()
  29. clock = pygame.time.Clock()
  30. icon = pygame.image.load('icon/scribble.png')
  31. pygame.display.set_icon(icon)
  32. import tool.movewin as movewin
  33. import tool.sdl_elm as sdl_elm
  34. import lib.baselib as baselib
  35. CAPTION = 'LibreLight Start '
  36. CAPTION += ':{}'.format(random.randint(100,999))
  37. import tool.git as git
  38. CAPTION += git.get_all()
  39. if 0:
  40. _id = movewin.winfo(CAPTION)
  41. c1 = movewin.movewin(_id,200,50)
  42. os.system(c1)
  43. c1 = movewin.activate(_id)
  44. os.system(c1)
  45. pg.display.set_caption(CAPTION)
  46. font0 = pygame.font.SysFont("freesans",10)
  47. font0b = pygame.font.SysFont("freesansbold",10)
  48. font = pygame.font.SysFont("freemonobold",22)
  49. font10 = pygame.font.SysFont("freemonobold",10)
  50. font12 = pygame.font.SysFont("freemonobold",12)
  51. font15 = pygame.font.SysFont("freemonobold",15)
  52. font22 = pygame.font.SysFont("FreeSans-bold",42)
  53. #font = pygame.font.SysFont(None,30)
  54. fr = font.render("hallo" ,1, (200,0,255))
  55. start = time.time()
  56. table = []
  57. x = 80
  58. y = 120
  59. import os
  60. import lib.fork as fork
  61. BASE_PATH = "/opt/LibreLight/Xdesk/"
  62. import lib.baselib as baselib
  63. SHOW_NAME = baselib.current_show_name()
  64. print([SHOW_NAME])
  65. import lib.restart as restart
  66. def exit(args=None):
  67. pygame.quit()
  68. sys.exit()
  69. def check_default():
  70. try:
  71. f = open("/home/user/LibreLight/config.json")
  72. lines = f.readlines()
  73. f.close()
  74. for line in lines:
  75. if '{"START_MODE":"PRO"}' in line:
  76. restart.pro()
  77. print(" PRO")
  78. #pygame.quit()
  79. return 0
  80. elif '{"START_MODE":"EASY"}' in line:
  81. restart.easy()
  82. print(" EASY")
  83. #pygame.quit()
  84. return 0
  85. print(line)
  86. except Exception as e:
  87. print("Exception",e)
  88. return 1
  89. bx = sdl_elm.Button(window,pos=[x,y,400,60])
  90. bx.text = " EASY"
  91. bx.font0 = pygame.font.SysFont("freesans-bold",85)
  92. bx.btn1.color = GREEN
  93. bx.btn1.cb_on.set(restart.easy)
  94. table.append(bx)
  95. y+=bx.get_rect()[3]+20
  96. bx = sdl_elm.Button(window,pos=[x,y,400,60])
  97. bx.text = " PRO"
  98. bx.btn1.color = GOLD
  99. bx.btn1.cb_on.set(restart.pro)
  100. bx.font0 = pygame.font.SysFont("freesans-bold",85)
  101. table.append(bx)
  102. y+=bx.get_rect()[3]+30
  103. bx = sdl_elm.Button(window,pos=[x,y,400,60])
  104. bx.text = " Exit"
  105. bx.btn1.cb_on.set(exit)
  106. bx.font0 = pygame.font.SysFont("freesans-bold",80)
  107. table.append(bx)
  108. mouse_down = 0
  109. mouse_pos1 = [0,0]
  110. mouse_pos2 = [0,0]
  111. mouse_grab = []
  112. print(int((time.time()-boot)*10),"loop...")
  113. fps_t = time.time()
  114. fps = 0
  115. fps_old = 0
  116. run = check_default()
  117. while run:
  118. fps +=1
  119. t = time.time()
  120. if t-fps_t >= 1:
  121. #print("FPS:",fps)
  122. fps_old = fps
  123. fps=0
  124. fps_t =t
  125. pygame.display.flip()
  126. pos = [160,10,70,60]
  127. rgb = (0xdd,0xdd,0xdd,0)
  128. rgb = (0xaa,0xaa,0xaa,0)
  129. window.fill((5,5,5))
  130. pygame.draw.rect(window,(0,0,0),[0,0,main_size[0],main_size[1]])
  131. fr = font22.render("FPS:"+str(fps_old) ,1, (200,200,200))
  132. #window.blit(fr,(10,10 ))
  133. fr = font22.render(" Lichtsteuerung" ,1, (255,255,0))
  134. window.blit(fr,(80,20 ))
  135. fr = font22.render(" Modus wählen ! " ,1, (255,255,0))
  136. window.blit(fr,(80,60 ))
  137. for t in table:
  138. t.draw()
  139. resize_changed = 0
  140. for event in pygame.event.get():
  141. if "scancode" in event.dict:
  142. if event.scancode == 9:
  143. for t in table:
  144. t.btn2.clean()
  145. print("event",event)
  146. if event.type == pygame.QUIT:
  147. pygame.quit()
  148. sys.exit(0)
  149. elif event.type == pygame.VIDEORESIZE:
  150. scrsize = event.size
  151. width = event.w
  152. hight = event.h
  153. resize_changed = True
  154. for t in table:
  155. t.event(event)
  156. if "pos" in event.dict:
  157. if "button" in event.dict:
  158. if event.type == 5:#press
  159. mouse_down = 1
  160. mouse_pos1 = [event.pos[0],event.pos[1]]
  161. if event.type == 6:#release
  162. mouse_down = 0
  163. for btn in mouse_grab:
  164. btn.btn2.val.set(1)
  165. mouse_grab = []
  166. mouse_pos2 = [event.pos[0],event.pos[1]]
  167. if mouse_down:
  168. d1 = mouse_pos1[0]-mouse_pos2[0]
  169. d2 = mouse_pos1[1]-mouse_pos2[1]
  170. pix = 23
  171. #print(d1,d2)
  172. if ( d1 > pix or d1 < -pix) or ( d2 >pix or d2 < -pix):
  173. sdl_elm.draw_mouse_box(window,mouse_pos1,mouse_pos2)
  174. for t in table:
  175. pos = t.get_rect()
  176. mpos = [mouse_pos1[0],mouse_pos1[1],mouse_pos2[0],mouse_pos2[1]]
  177. if sdl_elm.check_area2(pos,mpos):
  178. t._set_mouse_focus(1)
  179. mouse_grab.append(t)
  180. else:
  181. t._set_mouse_focus(0)
  182. if resize_changed:# = True
  183. screen = pygame.display.set_mode(scrsize,pg.RESIZABLE)
  184. clock.tick(30)