LibreLightDesk.py 4.8 KB

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