config.py 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  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. #print(sys.path)
  9. #print()
  10. import pathlib
  11. _file_path=pathlib.Path(__file__)
  12. print("file:",_file_path)
  13. import tool.movewin as movewin
  14. CAPTION = 'LibreLight SDL-CONFIG '
  15. movewin.check_is_started(CAPTION,_file_path,sleep=0)
  16. # ===== GUI =========
  17. import pygame
  18. import pygame.gfxdraw
  19. import pygame.font
  20. pg = pygame
  21. main_size=(600,500)
  22. window = pygame.display.set_mode(main_size,pg.RESIZABLE,32)
  23. pg = pygame
  24. pygame.init()
  25. pygame.mixer.quit()
  26. clock = pygame.time.Clock()
  27. icon = pygame.image.load('icon/scribble.png')
  28. pygame.display.set_icon(icon)
  29. import tool.movewin as movewin
  30. import tool.sdl_elm as sdl_elm
  31. CAPTION += ':{}'.format(random.randint(100,999))
  32. import tool.git as git
  33. CAPTION += git.get_all()
  34. _id = movewin.winfo(CAPTION)
  35. c1 = movewin.movewin(_id,200,50)
  36. os.system(c1)
  37. c1 = movewin.activate(_id)
  38. os.system(c1)
  39. pg.display.set_caption(CAPTION)
  40. font0 = pygame.font.SysFont("freesans",10)
  41. font0b = pygame.font.SysFont("freesansbold",10)
  42. font = pygame.font.SysFont("freemonobold",22)
  43. font10 = pygame.font.SysFont("freemonobold",10)
  44. font12 = pygame.font.SysFont("freemonobold",12)
  45. font15 = pygame.font.SysFont("freemonobold",15)
  46. font22 = pygame.font.SysFont("FreeSans",22)
  47. #font = pygame.font.SysFont(None,30)
  48. fr = font.render("hallo" ,1, (200,0,255))
  49. start = time.time()
  50. table = []
  51. r = 80
  52. i = 1
  53. bx = sdl_elm.Button(window,pos=[20,r,80,40])
  54. bx.text = "FIX:{}\n<val>\nx".format(i+1)
  55. bx.bg_on = [255,0,255]
  56. bx.btn1.color_on = [255,0,155]
  57. bx.btn1.type = "flash"
  58. table.append(bx)
  59. r+=bx.get_rect()[3]
  60. i += 1
  61. bx = sdl_elm.Button(window,pos=[20,r,80,40])
  62. bx.text = "FIX:{}\n<val>\nx".format(i+1)
  63. table.append(bx)
  64. r+=bx.get_rect()[3]
  65. i += 1
  66. r+=bx.get_rect()[3]
  67. bx = sdl_elm.Button(window,pos=[20,r,80,40])
  68. bx.text = "FIX:{}\n<val>\nx".format(i+1)
  69. #bx.font0 = pygame.font.SysFont("freesans",20)
  70. bx.btn4.val.set( 100)
  71. bx.fader = 0
  72. table.append(bx)
  73. r+=bx.get_rect()[3]
  74. i += 1
  75. bx = sdl_elm.Button(window,pos=[20,r,80,60])
  76. bx.text = "FIX:{}\n<val>\nx".format(i+1)
  77. #bx.font0 = pygame.font.SysFont("freesans-bold",20)
  78. bx.btn1.type = "flash"
  79. table.append(bx)
  80. r+=bx.get_rect()[3]
  81. i += 1
  82. bx = sdl_elm.Button(window,pos=[20,r,80,20])
  83. bx.text = "FIX:{}\n<val>\nx".format(i+1)
  84. #bx.font0 = pygame.font.SysFont("freesans",12)
  85. table.append(bx)
  86. table = []
  87. mouse_down = 0
  88. mouse_pos1 = [0,0]
  89. mouse_pos2 = [0,0]
  90. mouse_grab = []
  91. print(int((time.time()-boot)*10),"loop...")
  92. fps_t = time.time()
  93. fps = 0
  94. fps_old = 0
  95. import _thread as thread
  96. try:
  97. import remote.apcmini as apcmini
  98. apc_main = apcmini.MAIN()
  99. thread.start_new_thread(apc_main.loop,())
  100. time.sleep(1)
  101. except Exception as e:
  102. print("MIDI INI",e)
  103. #while 1:
  104. # if apc_main.buf:
  105. # buf = apc_main.buf[:]
  106. # apc_main.buf = []
  107. # for m in buf:
  108. # print("-> midi:",m)
  109. buf = []
  110. while 1:
  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("SDL-CONFIG " ,1, (200,200,200))
  127. window.blit(fr,(100,10 ))
  128. try:
  129. if apc_main.buf:
  130. buf = apc_main.buf[:]
  131. apc_main.buf = []
  132. except Exception as e:
  133. print("midi",e)
  134. r = 10
  135. fr = font22.render("MIDI: APCMINI" ,1, (200,100,200))
  136. window.blit(fr,(330,30+r ))
  137. r+=30
  138. for m in buf:
  139. #print("-> midi:",m)
  140. fr = font22.render("MIDI:"+str(m) ,1, (200,200,0))
  141. window.blit(fr,(330,30+r ))
  142. r+=30
  143. if 0: #timer balken
  144. pos = [160,110,70+80,20]
  145. pygame.draw.rect(window,rgb,pos)
  146. t=(time.time()-start)
  147. if t > 15:
  148. start = time.time()
  149. b= 80-int(t*10)
  150. pos = [160,110,70+(b),20]
  151. rgb = (0x00,0xff,0xff,0)
  152. pygame.draw.rect(window,rgb,pos)
  153. rgb = (0x00,0x00,0x00,0)
  154. fr = font22.render(str(round(t,1)) ,1, rgb) #(200,200,200))
  155. window.blit(fr,pos[:2])
  156. pos = [160,200,80,20]
  157. #fd = sdl_elm.Fader(window,pos)
  158. #fd.draw()
  159. pos = [160,90,70+80,20]
  160. pygame.draw.rect(window,rgb,pos)
  161. b= int(t*10)
  162. pos = [160,90,0+(b),20]
  163. rgb = (0x00,0xff,0xff,0)
  164. pygame.draw.rect(window,rgb,pos)
  165. rgb = (0x00,0x00,0x00,0)
  166. fr = font22.render(str(round(t,1)) ,1, rgb) #(200,200,200))
  167. window.blit(fr,pos[:2])
  168. rgb = (0xaa,0xaa,0xaa,0)
  169. fr = font22.render(str(round(t,1)) ,1, rgb) #(200,200,200))
  170. window.blit(fr,(500,500))
  171. for t in table:
  172. t.draw()
  173. resize_changed = 0
  174. for event in pygame.event.get():
  175. if "scancode" in event.dict:
  176. if event.scancode == 9:
  177. for t in table:
  178. t.btn2.clean()
  179. print("event",event)
  180. if event.type == pygame.QUIT:
  181. pygame.quit()
  182. sys.exit(0)
  183. elif event.type == pygame.VIDEORESIZE:
  184. scrsize = event.size
  185. width = event.w
  186. hight = event.h
  187. resize_changed = True
  188. for t in table:
  189. t.event(event)
  190. if "pos" in event.dict:
  191. if "button" in event.dict:
  192. if event.type == 5:#press
  193. mouse_down = 1
  194. mouse_pos1 = [event.pos[0],event.pos[1]]
  195. if event.type == 6:#release
  196. mouse_down = 0
  197. for btn in mouse_grab:
  198. btn.btn2.val.set(1)
  199. mouse_grab = []
  200. mouse_pos2 = [event.pos[0],event.pos[1]]
  201. if mouse_down:
  202. d1 = mouse_pos1[0]-mouse_pos2[0]
  203. d2 = mouse_pos1[1]-mouse_pos2[1]
  204. pix = 23
  205. #print(d1,d2)
  206. if ( d1 > pix or d1 < -pix) or ( d2 >pix or d2 < -pix):
  207. sdl_elm.draw_mouse_box(window,mouse_pos1,mouse_pos2)
  208. for t in table:
  209. pos = t.get_rect()
  210. mpos = [mouse_pos1[0],mouse_pos1[1],mouse_pos2[0],mouse_pos2[1]]
  211. if sdl_elm.check_area2(pos,mpos):
  212. t._set_mouse_focus(1)
  213. mouse_grab.append(t)
  214. else:
  215. t._set_mouse_focus(0)
  216. if resize_changed:# = True
  217. screen = pygame.display.set_mode(scrsize,pg.RESIZABLE)
  218. clock.tick(30)