def capture_olympus(): activate_olympus = """ osascript -e 'tell application "OLYMPUS Capture" to activate' """ enter = """ osascript -e 'tell application "System Events" to keystroke return' """ # activate_python = """ # osascript -e 'tell application "System Events" to tell process "Python" ' \ # -e 'set frontmost to true ' \ # -e 'windows where title contains "Slideshow" ' \ # -e 'if result is not {} then perform action "AXRaise" of item 1 of result ' \ # -e 'end tell' # """ activate_python = """ osascript -e 'tell application "Python" to activate' """ print "Activating Olympus" os.system(activate_olympus) time.sleep(0.1) print "Enter" os.system(enter) time.sleep(0.1) print "Activating Python" t = threading.Thread(target=os.system, args=(activate_python, )) t.start() for i in range(10): check_for_event() time.sleep(0.1) t.join() print "done"
def take_picture(self, filename=tmp_dir + "picture.jpg"): old_dir = os.getcwd() os.chdir(self.folder) cur_newest = self.get_newest() if not self.simulate: capture_olympus() start = time.time() new_file = None while new_file is None: newest_file = self.get_newest() if newest_file: if not cur_newest or os.path.getctime( newest_file) > os.path.getctime(cur_newest): new_file = newest_file break if time.time() - start > self.timeout: os.chdir(old_dir) raise CameraException( "Could not get picture, is the camera running? Change flash batteries?" ) check_for_event() time.sleep(0.1) shutil.copy(new_file, filename) os.chdir(old_dir) return filename
def focus_python(): activate_python = """ osascript -e 'tell application "Python" to activate' """ print "Activating Python" t = threading.Thread(target=os.system, args=(activate_python, )) t.start() for i in range(10): check_for_event() sleep(0.1) t.join() print "done"
def main(): display = GuiModule('set-time', display_size, hide_mouse=False) for digit in range(len(date_digits)): display.clear() show_numpad(display, numpad, button_size) display.show_button('Date:', (400, 100), outline=(0, 0, 0)) show_digits(display, date_digits, button_size) display.apply() digit_done = False while not digit_done: r, e = check_for_event() while r: digit_done = handle_event(e, digit, date_digits, numpad) r, e = check_for_event() for digit in range(len(time_digits)): display.clear() show_numpad(display, numpad, button_size) display.show_button('Time:', (400, 100), outline=(0, 0, 0)) show_digits(display, time_digits, button_size) display.apply() digit_done = False while not digit_done: event = wait_for_event() digit_done = handle_event(event, digit, time_digits, numpad) # YYYY-MM-DD HH:mm date_str = (date_digits[4] + date_digits[5] + date_digits[6] + date_digits[7] + '-' + date_digits[2] + date_digits[3] + '-' + date_digits[0] + date_digits[1] + ' ' + time_digits[0] + time_digits[1] + ':' + time_digits[2] + time_digits[3]) subprocess.check_call(['date', '-s', date_str]) display.teardown() return 0
def take_picture(self): """Implements the picture taking routine""" # NUM PICs num_pics = 1 t = threading.Thread(target=self.say, args=("Pose for the photo!", )) t.start() activate_olympus = """ osascript -e 'tell application "OLYMPUS Capture" to activate' """ os.system(activate_olympus) self.display.msg( "\n\n\n\n\n\n\nTaking {} picture ...".format(num_pics)) sleep(3.0) t.join() # Extract display and image sizes display_size = self.display.get_size() focus_python() self.display.msg("Look at the camera...".format(num_pics)) self.say("Look at the camera") sleep(0.5) words = random.choice(word_list) #words.append(0.3) # Take pictures filenames = [i for i in range(num_pics)] for x in range(num_pics): # Countdown self.show_counter(self.pose_time) self.display.msg("") #self.display.msg("S M I L E !!!\n\n {} of {}".format(x + 1, num_pics)) t = threading.Thread(target=self.say_with_delay, args=tuple(words)) t.start() try: #t = threading.Thread(target=self.camera.take_picture, args=(tmp_dir + "photobooth_%02d.jpg" % x, )) #t.start() filenames[x] = self.camera.take_picture(tmp_dir + "photobooth_%02d.jpg" % x) #if self.shutter: # self.shutter.play() except CameraException as e: raise e t.join() # Show 'Wait' self.display.msg("Please wait!\n\nWorking\n...") # Assemble them ass_outfile, outfile = self.assemble_picture(filenames[0]) if self.printer_module.can_print(): # Show picture for 10 seconds and then send it to the printer. # If auto_print is True, hitting the button cancels the print. # If auto_print is False, hitting the button sends the print tic = time() t = int(self.display_time - (time() - tic)) old_t = self.display_time + 1 do_print = auto_print # Clear event queue (in case they hit the button twice accidentally) self.clear_event_queue() while t > 0: if t != old_t: self.display.clear() self.display.show_picture(outfile, display_size, (0, 0)) self.display.show_message( "%s%d" % ("Wait for print \n or press button to cancel!\n " if auto_print else "Press button to print photo!\n", t)) self.display.apply() old_t = t # Watch for button, gpio, mouse press to cancel/enable printing r, e = check_for_event() if r: # Caught a button press. self.display.clear() self.display.show_picture(outfile, display_size, (0, 0)) self.display.show_message( "Printing%s" % (" cancelled" if auto_print else "")) self.display.apply() self.clear_event_queue() # Discard extra events (e.g., they hit the button a bunch) sleep(2) self.clear_event_queue() do_print = not do_print break sleep(0.1) t = int(self.display_time - (time() - tic)) # Either button pressed or countdown timed out if do_print: self.display.msg("Printing") self.printer_module.enqueue(ass_outfile) else: # No printer available, so just show montage for 10 seconds self.display.clear() self.display.show_picture(outfile, display_size, (0, 0)) self.display.apply() sleep(self.display_time) self.clear_event_queue()
def clear_event_queue(self): r, e = check_for_event() while r: r, e = check_for_event()
def check_and_handle_events(self): r, e = check_for_event() while r: self.handle_event(e) r, e = check_for_event()