start.py 5.9 KB

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