LibreLightDesk.py 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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. _file_path=pathlib.Path(__file__)
  13. print("file:",_file_path)
  14. import tool.movewin as movewin
  15. count = movewin.search_process(_file_path)
  16. CAPTION = 'LibreLight Start XX'
  17. if count >= 2:
  18. search = CAPTION[:]
  19. _ids = movewin.winfo(search)
  20. for _id in _ids:
  21. c3 = movewin.activate(_id)
  22. os.system(c3)
  23. sys.exit()
  24. from lib.xcolor import *
  25. # ===== GUI =========
  26. import pygame
  27. import pygame.gfxdraw
  28. import pygame.font
  29. pg = pygame
  30. main_size=(550,400)
  31. window = pygame.display.set_mode(main_size,pg.RESIZABLE,32)
  32. pg = pygame
  33. pygame.init()
  34. pygame.mixer.quit()
  35. clock = pygame.time.Clock()
  36. import tool.movewin as movewin
  37. import tool.sdl_elm as sdl_elm
  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. BASE_PATH = "/opt/LibreLight/Xdesk/"
  65. import lib.restart as restart
  66. def exit(args):
  67. pygame.quit()
  68. sys.exit()
  69. bx = sdl_elm.Button(window,pos=[x,y,400,60])
  70. bx.text = " EASY"
  71. bx.font0 = pygame.font.SysFont("freesans-bold",85)
  72. bx.btn1.color = GREEN
  73. bx.btn1.cb_on.set(restart.easy)
  74. table.append(bx)
  75. y+=bx.get_rect()[3]+20
  76. bx = sdl_elm.Button(window,pos=[x,y,400,60])
  77. bx.text = " PRO"
  78. bx.btn1.color = GOLD
  79. bx.btn1.cb_on.set(restart.pro)
  80. bx.font0 = pygame.font.SysFont("freesans-bold",85)
  81. table.append(bx)
  82. y+=bx.get_rect()[3]+30
  83. bx = sdl_elm.Button(window,pos=[x,y,400,60])
  84. bx.text = " Exit"
  85. bx.btn1.cb_on.set(exit)
  86. bx.font0 = pygame.font.SysFont("freesans-bold",80)
  87. table.append(bx)
  88. mouse_down = 0
  89. mouse_pos1 = [0,0]
  90. mouse_pos2 = [0,0]
  91. mouse_grab = []
  92. print(int((time.time()-boot)*10),"loop...")
  93. fps_t = time.time()
  94. fps = 0
  95. fps_old = 0
  96. while 1:
  97. fps +=1
  98. t = time.time()
  99. if t-fps_t >= 1:
  100. #print("FPS:",fps)
  101. fps_old = fps
  102. fps=0
  103. fps_t =t
  104. pygame.display.flip()
  105. pos = [160,10,70,60]
  106. rgb = (0xdd,0xdd,0xdd,0)
  107. rgb = (0xaa,0xaa,0xaa,0)
  108. window.fill((5,5,5))
  109. pygame.draw.rect(window,(0,0,0),[0,0,main_size[0],main_size[1]])
  110. fr = font22.render("FPS:"+str(fps_old) ,1, (200,200,200))
  111. #window.blit(fr,(10,10 ))
  112. fr = font22.render(" Lichtsteuerung" ,1, (255,255,0))
  113. window.blit(fr,(80,20 ))
  114. fr = font22.render(" Modus wählen ! " ,1, (255,255,0))
  115. window.blit(fr,(80,60 ))
  116. for t in table:
  117. t.draw()
  118. resize_changed = 0
  119. for event in pygame.event.get():
  120. if "scancode" in event.dict:
  121. if event.scancode == 9:
  122. for t in table:
  123. t.btn2.clean()
  124. print("event",event)
  125. if event.type == pygame.QUIT:
  126. pygame.quit()
  127. sys.exit(0)
  128. elif event.type == pygame.VIDEORESIZE:
  129. scrsize = event.size
  130. width = event.w
  131. hight = event.h
  132. resize_changed = True
  133. for t in table:
  134. t.event(event)
  135. if "pos" in event.dict:
  136. if "button" in event.dict:
  137. if event.type == 5:#press
  138. mouse_down = 1
  139. mouse_pos1 = [event.pos[0],event.pos[1]]
  140. if event.type == 6:#release
  141. mouse_down = 0
  142. for btn in mouse_grab:
  143. btn.btn2.val.set(1)
  144. mouse_grab = []
  145. mouse_pos2 = [event.pos[0],event.pos[1]]
  146. if mouse_down:
  147. d1 = mouse_pos1[0]-mouse_pos2[0]
  148. d2 = mouse_pos1[1]-mouse_pos2[1]
  149. pix = 23
  150. #print(d1,d2)
  151. if ( d1 > pix or d1 < -pix) or ( d2 >pix or d2 < -pix):
  152. sdl_elm.draw_mouse_box(window,mouse_pos1,mouse_pos2)
  153. for t in table:
  154. pos = t.get_rect()
  155. mpos = [mouse_pos1[0],mouse_pos1[1],mouse_pos2[0],mouse_pos2[1]]
  156. if sdl_elm.check_area2(pos,mpos):
  157. t._set_mouse_focus(1)
  158. mouse_grab.append(t)
  159. else:
  160. t._set_mouse_focus(0)
  161. if resize_changed:# = True
  162. screen = pygame.display.set_mode(scrsize,pg.RESIZABLE)
  163. clock.tick(30)