start.py 5.4 KB

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