def initUI(self): menu = QMenu() # Use Buddha in place of smiley face # iconPath = pyInstallerResourcePath('exit-gray.png') iconPath = pyInstallerResourcePath('meditate.png') self.trayIcon = QSystemTrayIcon(self) supported = self.trayIcon.supportsMessages() self.trayIcon.setIcon(QIcon(iconPath)) self.trayIcon.setContextMenu(menu) self.trayIcon.showMessage('a', 'b') self.trayIcon.show() self.postureIcon = QSystemTrayIcon(self) self.postureIcon.setIcon(QIcon(pyInstallerResourcePath('posture.png'))) self.postureIcon.setContextMenu(menu) self.postureIcon.show() exitAction = QAction("&Quit Sensei", self, shortcut="Ctrl+Q", triggered=self.closeEvent) preferencesAction = QAction("&Preferences...", self, triggered=self.showApp) # preferencesAction.setStatusTip('Sensei Preferences') aboutAction = QAction("&About Sensei", self, triggered=self.aboutEvent) menu.addAction(aboutAction) menu.addSeparator() menu.addAction(preferencesAction) menu.addSeparator() menu.addAction(exitAction) optionsMenu = menu.addMenu('&Options') soundToggleAction = QAction("Toggle Sound", self, triggered=self.toggleSound) optionsMenu.addAction(soundToggleAction) # TODO: Add settings panel. # changeSettings = QAction(QIcon('exit.png'), "&Settings", self, shortcut="Cmd+,", triggered=self.changeSettings) # changeSettings.setStatusTip('Change Settings') # menu.addAction(changeSettings) self.pbar = QProgressBar(self) self.pbar.setGeometry(30, 40, 200, 25) self.pbarValue = 0 self.setGeometry(300, 300, 290, 150) self.setWindowTitle('Posture Monitor') self.startButton = QPushButton('Calibrate', self) self.startButton.move(30, 60) self.startButton.clicked.connect(self.calibrate) self.stopButton = QPushButton('Stop', self) self.stopButton.move(30, 60) self.stopButton.clicked.connect(self.endCalibration) self.stopButton.hide() self.settingsButton = QPushButton('Settings', self) self.settingsButton.move(140, 60) self.settingsButton.clicked.connect(self.settings) self.doneButton = QPushButton('Done', self) self.doneButton.move(30, 60) self.doneButton.hide() self.doneButton.clicked.connect(self.minimize) # TODO: Create QWidget panel for Settings with MONITOR_DELAY # and SENSITIVITY options. # layout = QFormLayout() # self.le = QLineEdit() self.instructions = QLabel(self) self.instructions.move(40, 20) self.instructions.setText('Sit upright and click \'Calibrate\'') self.instructions.setGeometry(40, 20, 230, 25) if not supported: self.instructions.setText( 'Error: Notification is not available on your system.') self.show()
MONITOR_DELAY = 2000 # Notify when user is 1.2 times closer than the calibration distance. SENSITIVITY = 1.2 CALIBRATION_SAMPLE_RATE = 100 # Sound setting soundOn = True USER_ID = None SESSION_ID = None TERMINAL_NOTIFIER_INSTALLED = None CASCPATH = 'face.xml' # CASCPATH = pyInstallerResourcePath('haarcascade_eye_tree_eyeglasses.xml') FACECASCADE = CascadeClassifier(pyInstallerResourcePath(CASCPATH)) print("path:", pyInstallerResourcePath(CASCPATH)) APP_ICON_PATH = pyInstallerResourcePath('posture.png') def trace(frame, event, arg): print(("%s, %s:%d" % (event, frame.f_code.co_filename, frame.f_lineno))) return trace def getFaces(frame): gray = cvtColor(frame, COLOR_BGR2GRAY) faces = FACECASCADE.detectMultiScale( gray, scaleFactor=1.1,