def save_dmf_device(self, save_as=False, rename=False): ''' Save device configuration. If `save_as=True`, we are saving a copy of the current device with a new name. If `rename=True`, we are saving the current device with a new name _(no new copy is created)_. ''' app = get_app() name = app.dmf_device.name # If the device has no name, try to get one. if save_as or rename or name is None: if name is None: name = "" name = text_entry_dialog('Device name', name, 'Save device') if name is None: name = "" if name: # Construct the directory name for the current device. if app.dmf_device.name: src = os.path.join(app.get_device_directory(), app.dmf_device.name) # Construct the directory name for the new device _(which is the # same as the current device, if we are not renaming or "saving # as")_. dest = os.path.join(app.get_device_directory(), name) # If we're renaming, move the old directory. if rename and os.path.isdir(src): if src == dest: return if os.path.isdir(dest): logger.error("A device with that " "name already exists.") return shutil.move(src, dest) # Create the directory for the new device name, if it doesn't # exist. if not os.path.isdir(dest): os.mkdir(dest) # If the device name has changed, update the application device # state. if name != app.dmf_device.name: app.dmf_device.name = name # Update GUI to reflect updated name. app.main_window_controller.update_device_name_label() # Save the device to the new target directory. app.dmf_device.save(os.path.join(dest, "device")) # Reset modified status, since save acts as a checkpoint. self.modified = False
def check_text_entry_dialog(*args, **kwargs): from pygtkhelpers.ui.extra_dialogs import text_entry_dialog validate = kwargs.pop('validate', lambda x: True) while True: response = text_entry_dialog(*args, **kwargs) # Cancel calibration if response is None: return # Check that it is a valid voltage elif validate(response): return response
def check_text_entry_dialog(*args, **kwargs): from pygtkhelpers.ui.extra_dialogs import text_entry_dialog validate = kwargs.pop('validate', lambda x: True) while True: response = text_entry_dialog(*args, **kwargs) # Cancel calibration if response is None: return # Check that it is a valid voltage elif validate(response): return response
def save_dmf_device(self, save_as=False, rename=False): ''' Save device configuration. If `save_as=True`, we are saving a copy of the current device with a new name. If `rename=True`, we are saving the current device with a new name _(no new copy is created)_. ''' app = get_app() name = app.dmf_device.name # If the device has no name, try to get one. if save_as or rename or name is None: if name is None: name = "" name = text_entry_dialog('Device name', name, 'Save device') if name is None: name = "" if name: device_directory = ph.path(app.get_device_directory()).realpath() # Construct the directory name for the current device. if app.dmf_device.name: src = device_directory.joinpath(app.dmf_device.name) # Construct the directory name for the new device _(which is the # same as the current device, if we are not renaming or "saving # as")_. dest = device_directory.joinpath(name) # If we're renaming, move the old directory. if rename and src.isdir(): if src == dest: return if dest.isdir(): _L().error("A device with that name already exists.") return shutil.move(src, dest) # Create the directory for the new device name, if it doesn't # exist. dest.makedirs_p() # Convert device to SVG string. svg_unicode = app.dmf_device.to_svg() output_path = dest.joinpath(DEVICE_FILENAME) # Save the device to the new target directory. with output_path.open('wb') as output: output.write(svg_unicode) # Reset modified status, since save acts as a checkpoint. self.modified = False # Notify plugins that device has been saved. emit_signal('on_dmf_device_saved', [app.dmf_device, str(output_path)]) # If the device name has changed, update the application device # state. if name != app.dmf_device.name: self.load_device(output_path) return output_path
def save_dmf_device(self, save_as=False, rename=False): ''' Save device configuration. If `save_as=True`, we are saving a copy of the current device with a new name. If `rename=True`, we are saving the current device with a new name _(no new copy is created)_. ''' app = get_app() name = app.dmf_device.name # If the device has no name, try to get one. if save_as or rename or name is None: if name is None: name = "" name = text_entry_dialog('Device name', name, 'Save device') if name is None: name = "" if name: device_directory = ph.path(app.get_device_directory()).realpath() # Construct the directory name for the current device. if app.dmf_device.name: src = device_directory.joinpath(app.dmf_device.name) # Construct the directory name for the new device _(which is the # same as the current device, if we are not renaming or "saving # as")_. dest = device_directory.joinpath(name) # If we're renaming, move the old directory. if rename and src.isdir(): if src == dest: return if dest.isdir(): _L().error("A device with that name already exists.") return shutil.move(src, dest) # Create the directory for the new device name, if it doesn't # exist. dest.makedirs_p() # Convert device to SVG string. svg_unicode = app.dmf_device.to_svg() output_path = dest.joinpath(DEVICE_FILENAME) # Save the device to the new target directory. with output_path.open('wb') as output: output.write(svg_unicode) # Reset modified status, since save acts as a checkpoint. self.modified = False # Notify plugins that device has been saved. emit_signal('on_dmf_device_saved', [app.dmf_device, str(output_path)]) # If the device name has changed, update the application device # state. if name != app.dmf_device.name: self.load_device(output_path) return output_path