Advertisement
16amattice

Untitled

Feb 7th, 2023
890
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.63 KB | None | 0 0
  1. import sys
  2. from pynput import keyboard
  3. from PyQt5.QtCore import Qt
  4. from PyQt5.QtWidgets import QApplication, QLabel, QMainWindow
  5.  
  6. class MainWindow(QMainWindow):
  7.     def __init__(self):
  8.         super().__init__()
  9.         self.setWindowFlags(Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint)
  10.         self.setGeometry(100, 100, 128, 128)
  11.         self.setAttribute(Qt.WA_TranslucentBackground)
  12.         self.setStyleSheet("background: transparent;")
  13.  
  14.         self.muted = False
  15.         self.label = QLabel("Unmuted", self)
  16.         self.label.setAlignment(Qt.AlignCenter)
  17.         self.label.setStyleSheet("color: white; font: bold 20px;")
  18.  
  19.         self.setCentralWidget(self.label)
  20.         self.hotkey_listener = keyboard.GlobalHotKeys({
  21.             '=': self.toggle_mute,
  22.             '<alt>+q': self.quit
  23.         })
  24.         self.hotkey_listener.start()
  25.  
  26.     def toggle_mute(self):
  27.         self.muted = not self.muted
  28.         if self.muted:
  29.             self.label.setText("Muted")
  30.         else:
  31.             self.label.setText("Unmuted")
  32.  
  33.     def quit(self):
  34.         self.hotkey_listener.stop()
  35.         self.close()
  36.  
  37.     def mousePressEvent(self, event):
  38.         if event.button() == Qt.LeftButton:
  39.             self.drag_position = event.globalPos() - self.frameGeometry().topLeft()
  40.             event.accept()
  41.  
  42.     def mouseMoveEvent(self, event):
  43.         if event.buttons() == Qt.LeftButton:
  44.             self.move(event.globalPos() - self.drag_position)
  45.             event.accept()
  46.  
  47. if __name__ == '__main__':
  48.     app = QApplication(sys.argv)
  49.  
  50.     main_window = MainWindow()
  51.     main_window.show()
  52.  
  53.     sys.exit(app.exec_())
  54.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement