start.py 5.6 KB

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