LibreLightDesk.py 5.0 KB

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