def capture(self): try: random.choice(self.alarms).play() except Exception as e: print "WARNING: couldn't play alarm: %s" % e self.captions = captions.load_captions() self.caption_top, self.caption_bottom = captions.choose(self.captions) self.capture_start()
def __init__(self): QtGui.QMainWindow.__init__(self) self.setWindowFlags( QtCore.Qt.WindowStaysOnTopHint | QtCore.Qt.FramelessWindowHint | QtCore.Qt.X11BypassWindowManagerHint ) self.setAttribute(QtCore.Qt.WA_TranslucentBackground) self.setStyleSheet("background-color:transparent;") desktop = QtGui.qApp.desktop() self.setGeometry(desktop.rect()) self.capture_width=640 self.capture_height=480 self.labels = [] self.pix = None self.alarms = [] for (dirpath, dirnames, filenames) in os.walk("assets/alarms"): for filename in filenames: if os.path.splitext(filename)[1] == '.mp3': m = Phonon.MediaSource(os.path.join(dirpath, filename)) self.alarms.append(Phonon.createPlayer(Phonon.MusicCategory, m)) print "loaded %s" % filename self.font = QtGui.QFont('Impact', 50) self.font.setHintingPreference(QtGui.QFont.PreferDefaultHinting) self.font.setStyleStrategy(QtGui.QFont.PreferAntialias) self.font.setStyle(QtGui.QFont.StyleNormal) self.font.setWeight(QtGui.QFont.Normal) self.caught_dir = 'caught' try: os.makedirs(self.caught_dir) except OSError as e: if e.errno not in (errno.EEXIST,): raise print "saving captures to %s" % self.caught_dir # clear the screen after 30 seconds self.clear_timer = QtCore.QTimer() self.clear_timer.setInterval(30 * 1000) self.clear_timer.setSingleShot(True) self.clear_timer.timeout.connect(self.clear) # record video at 10 fps self.capture_fourcc = cv2.cv.CV_FOURCC(*'XVID') self.capture_fps = 10 self.camera = None self.writer = None self.capture_frame_timer = QtCore.QTimer(self) self.capture_frame_timer.setInterval(1000/self.capture_fps) self.capture_frame_timer.timeout.connect(self.capture_frame_timer_handler) # stop recording after 10 seconds self.capture_stop_timer = QtCore.QTimer(self) self.capture_stop_timer.setInterval(10 * 1000) self.capture_stop_timer.setSingleShot(True) self.capture_stop_timer.timeout.connect(self.capture_stop_timer_handler) # load captions self.captions = captions.load_captions() self.caption_top, self.caption_bottom = captions.choose(self.captions)