def delete_released(self, event): """Button has been released Only delete the image if the button has been pressed for five seconds. Otherwise, do nothing. """ if not self.is_pressed: # Got here by cosmic rays, or some such. return None self.is_pressed = False if self.press_start > 0 and time.time() > self.press_start + self.PRESS_TIME: shutil.rmtree(self.images.current().directory) self.images = utils.disk_image_list(self.source_dir) self.refresh()
def scan_device(self, event): if self.disks.current() != None and self.disks.current().present: self.updates = False partitions = utils.get_device_partitions(self.disks.current().path) self.copy_dir = None tmp_listener = pifacecad.SwitchEventListener(chip=self.cad) tmp_listener.register(self.BUTTON_COPY_Y, pifacecad.IODIR_FALLING_EDGE, self.copy_image) tmp_listener.register(self.BUTTON_COPY_N, pifacecad.IODIR_FALLING_EDGE, self.pass_image) tmp_listener.activate() for partition in partitions: self.write_queue.put({"action": "write", "pos": [0, 0], "blank": 1, "text": partition}) mnt = utils.mount(partition) if mnt: self.write_queue.put({"action": "write", "pos": [0, 1], "blank": 1, "text": "Scanning ..."}) images = utils.scan(mnt) for dir in images: self.write_queue.put({"action": "write", "pos": [0, 0], "blank": 1, "text": images[dir]}) self.write_queue.put({"action": "write", "pos": [0, 1], "blank": 1, "text": "Y N"}) self.do_copy = None while self.do_copy == None: pass if self.do_copy == 1: self.write_queue.put({"action": "write", "pos": [0, 1], "blank": 1, "text": "Copying ..."}) # Find a nunique directory name i = 1 while os.path.exists(self.source_dir + "/{0:06d}".format(i)): i += 1 new_dir = self.source_dir + "/{0:06d}".format(i) os.mkdir(new_dir) distutils.dir_util.copy_tree(dir, new_dir) # self.main_lines[0]['source'] = utils.disk_image_list(self.source_dir) self.images = utils.disk_image_list(self.source_dir) utils.umount(mnt) tmp_listener.deactivate() self.refresh() self.updates = True
def __init__(self, disks, source_dir, write_function): # Callback function for writing to the device self.write_function = write_function self.source_dir = source_dir self.disks = disks self.images = utils.disk_image_list(self.source_dir) self.main_lines = [ { #'source': self.images, "info": ["name", "n_post_scripts", "n_variables"], "x": 1, }, {"source": disks, "info": ["model", "node_path"], "x": 2}, ] self.pointer_pos = 0 self.info_n = 0 self.load_line = {"source": disks, "info": ["model", "node_path"], "x": 1} self.delete_line = {"source": self.images, "info": ["name", "n_post_scripts", "n_variables"], "x": 0} self.system_data = [ self.ip_address, self.cpu_temp, self.storage_total, self.storage_used, self.storage_free, self.shutdown, self.reboot, ] self.system_n = 0 # Send updates to display of devices self.updates = False # Whether button is pressed or not self.is_pressed = False self.cad = pifacecad.PiFaceCAD() self.listener = pifacecad.SwitchEventListener(chip=self.cad) self.scroll = False self.display = self.DISPLAY_FIRST self.write_queue = multiprocessing.Queue() self.writer = threading.Thread(target=_lcd_writer, args=(self.write_queue, self.cad)) self.writer.start() # Store bitmaps for the partial blocks that make up the progree bar. # Each one contains 8 lines of the same number: # BLOCK[0] '# ' = 16 # BLOCK[1] '## ' = 24 # BLOCK[2] '### ' = 28 # BLOCK[3] '#### ' = 30 # BLOCK[4] '#####' = 31 n = 0 for j in range(5): n = n + (2 ** (4 - j)) self.write_queue.put({"action": "store", "bitmap": self.BLOCK[j], "lines": [n] * 8}) self.write_queue.put( { "action": "store", "bitmap": self.UNSELECTED, "lines": [ 31, # ##### 17, # # # 17, # # # 17, # # # 17, # # # 17, # # # 17, # # # 31, # ##### ], } ) self.write_queue.put( { "action": "store", "bitmap": self.SELECTED, "lines": [ 31, # ##### 17, # # # 21, # # # # 21, # # # # 21, # # # # 21, # # # # 17, # # # 31, # ##### ], } ) self.write_queue.put( { "action": "store", "bitmap": self.POINTER, "lines": [0, 8, 12, 14, 12, 8, 0, 0], # # # # ## # ### # ## # # # # } )