SHARE
TWEET

Untitled

a guest Feb 20th, 2019 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from subprocess import Popen
  2. import time
  3. from pynput import keyboard
  4. import blinkt
  5. import os
  6. import colorama
  7. colorama.init()
  8.  
  9. p = ...
  10. nr_wyboru = 0
  11.  
  12. #Numer do Wybrania, Sciezka do Pliku, Jak ma sie nazywac w menu
  13. switcher = {
  14.     1:['examples/candle', 'Swieczka'],
  15.     2:['examples/1d_tetris', 'Tetris'],
  16.     3:['examples/binary_clock', 'Zegar Binarny'],
  17.     4:['examples/gradient_graph', 'Wykres'],
  18.     5:['examples/pulse', 'Pulsowanie'],
  19.     6:['examples/rainbow', 'Tecza'],
  20.     7:['examples/solid_colours', 'Kolory']
  21. }
  22. #Wybor Mozliwych Trybow
  23. def tryby(klawisz):
  24.     return switcher.get(klawisz,False)
  25.  
  26. def showMenu():
  27.     global nr_wyboru
  28.     for item in switcher:
  29.         if item == nr_wyboru:
  30.             wybor = colorama.Fore.GREEN + "{}. {}{}".format(item, switcher[item][1], colorama.Fore.RESET)
  31.         else:
  32.             wybor = "{}. {}".format(item, switcher[item][1])
  33.         print(wybor)
  34.     print(colorama.Style.DIM + colorama.Fore.WHITE + "Wcisnij ESC, aby wyjsc" + colorama.Fore.RESET  + colorama.Style.BRIGHT)
  35.     print( "-" * 40 + colorama.Fore.WHITE)
  36.  
  37. #Wyczysz LED-y przed wlaczeniem nowego skryptu
  38. def wyczysc():
  39.     os.system('clear')
  40.     for i in range(8):
  41.         blinkt.clear()
  42.         blinkt.show()
  43.  
  44.  
  45. #Sprawdz czy nie dziala juz jeden skrypt, jesli tak to go wylacz
  46. def sprawdz():
  47.     try:
  48.         if p.poll() == None:
  49.             p.terminate()
  50.     except:
  51.         pass
  52.     wyczysc()
  53.  
  54.  
  55. def on_release(key):
  56.     global p, nr_wyboru
  57.     sprawdz()
  58.  
  59.     #zakoncczenie programu
  60.     if key == keyboard.Key.esc:
  61.         return False
  62.  
  63.     try:
  64.         #print(int(key.char), type(int(key.char)))
  65.         trybLED = tryby(int(key.char))[0]
  66.         if trybLED != None:
  67.             nr_wyboru = int(key.char)
  68.             p = Popen(['python', '{}.py'.format(trybLED)])
  69.         #print(tryby(int(key.char)))
  70.  
  71.     except:
  72.         nr_wyboru = 0
  73.         print(colorama.Back.RED + "Nieprawidlowy wybor" + colorama.Back.RESET)
  74.     #sprawdz()
  75.     showMenu()
  76.  
  77.  
  78.  
  79. print(colorama.Style.BRIGHT)
  80. os.system('clear')
  81. wyczysc()
  82. showMenu()
  83. with keyboard.Listener(on_release=on_release) as listener:
  84.         listener.join()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top