1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
| #!/usr/bin/python
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from threading import Thread
import os, sys, time, ctypes, win32con
from ctypes import wintypes
statut_on_off = True
class MaFenetre(QWidget):
def __init__(self, FL=220, FH=100):
QWidget.__init__(self)
self.setWindowIcon(QIcon("icone64.ico"))
self.setWindowTitle("Test")
self.setFixedSize(FL, FH)
self.frame1 = QFrame(self)
self.frame1.setFrameStyle(QFrame.StyledPanel | QFrame.Plain)
self.frame1.setLineWidth(1)
self.frame1.setMidLineWidth(1)
self.frame1.setGeometry(5, 5, 210, 90)
def closeEvent(self, event):
global statut_on_off
statut_on_off = False
user32.PostQuitMessage (0)
byref = ctypes.byref
user32 = ctypes.windll.user32
def handle_win_f8 ():
os.startfile (os.environ['TEMP'])
def handle_win_f9 ():
user32.PostQuitMessage (0)
def HotKeysS():
HOTKEYS = {
1 : (win32con.VK_F8, win32con.MOD_CONTROL),
2 : (win32con.VK_F9, win32con.MOD_CONTROL)
}
HOTKEY_ACTIONS = {
1 : handle_win_f8,
2 : handle_win_f9
}
for id, (vk, modifiers) in HOTKEYS.items():
print ("Registering id", id, "for key", vk)
if not user32.RegisterHotKey (None, id, modifiers, vk):
print ("Unable to register id", id)
try:
msg = wintypes.MSG ()
while user32.GetMessageA (byref (msg), None, 0, 0) != 0:
if msg.message == win32con.WM_HOTKEY:
action_to_take = HOTKEY_ACTIONS.get (msg.wParam)
if action_to_take:
action_to_take ()
user32.TranslateMessage (byref (msg))
user32.DispatchMessageA (byref (msg))
finally:
for id in HOTKEYS.keys ():
user32.UnregisterHotKey (None, id)
def main():
a=QApplication(sys.argv)
fenetre=MaFenetre()
fenetre.show()
a.exec()
def Boucle():
global statut_on_off
while statut_on_off == True:
print("Action 1")
time.sleep(2)
print("Action 2")
time.sleep(2)
print("Action 3")
time.sleep(2)
thread_1 = Thread(target = main)
thread_2 = Thread(target = Boucle)
thread_3 = Thread(target = HotKeysS)
if __name__ == '__main__':
thread_1.start()
thread_2.start()
thread_3.start()
thread_1.join()
print("thread 1 joined.")
thread_2.join()
print("thread 2 joined.")
thread_3.join()
print("thread 3 joined.")
sys.exit() |
Partager