def save_protocol(self, save_as=False, rename=False):
        app = get_app()
        name = app.protocol.name
        if app.dmf_device.name:
            if save_as or rename or app.protocol.name is None:
                # if the dialog is cancelled, name = ""
                if name is None:
                    name=''
                name = text_entry_dialog('Protocol name', name, 'Save protocol')
                if name is None:
                    name=''

            if name:
                path = os.path.join(app.get_device_directory(),
                                    app.dmf_device.name,
                                    "protocols")
                if os.path.isdir(path) == False:
                    os.mkdir(path)

                # current file name
                if app.protocol.name:
                    src = os.path.join(path, app.protocol.name)
                dest = os.path.join(path, name)

                # if the protocol name has changed
                if name != app.protocol.name:
                    app.protocol.name = name

                # if we're renaming
                if rename and os.path.isfile(src):
                    shutil.move(src, dest)
                else: # save the file
                    app.protocol.save(dest)
                self.modified = False
                emit_signal("on_protocol_changed")
Beispiel #2
0
 def on_edit_electrode_area__activate(self, widget, data=None):
     app = get_app()
     if app.dmf_device.scale is None:
         area = ""
     else:
         area = self.last_electrode_clicked.area() * app.dmf_device.scale
     area = text_entry_dialog("Area of electrode in mm<span "
             "rise=\"5000\" font_size=\"smaller\">2</span>:", str(area),
                     "Edit electrode area")
     if area:
         if is_float(area):
             app.dmf_device.scale = \
                 float(area)/self.last_electrode_clicked.area()
         else:
             logger.error("Area value is invalid.")
     emit_signal('on_dmf_device_changed')
Beispiel #3
0
 def on_edit_electrode_channels__activate(self, widget, data=None):
     # TODO: set default value
     channel_list = ','.join([str(i) for i in self.last_electrode_clicked.channels])
     app = get_app()
     options = self.model.controller.get_step_options()
     state = options.state_of_channels
     channel_list = text_entry_dialog('Channels', channel_list, 'Edit electrode channels')
     if channel_list:
         channels = channel_list.split(',')
         try: # convert to integers
             if len(channels[0]):
                 for i in range(0,len(channels)):
                     channels[i] = int(channels[i])
             else:
                 channels = []
             if channels and max(channels) >= len(state):
                 # zero-pad channel states for all steps
                 for i in range(len(app.protocol)):
                     options = self.model.controller.get_step_options(i)
                     options.state_of_channels = \
                         np.concatenate([options.state_of_channels, \
                             np.zeros(max(channels) - \
                             len(options.state_of_channels)+1, int)])
                     # don't emit signal for current step, we will do that after
                     if i != app.protocol.current_step_number:
                         emit_signal('on_step_options_changed',
                                     [self.model.controller.name, i],
                                     interface=IPlugin)
             self.last_electrode_clicked.channels = channels
             emit_signal('on_step_options_changed',
                         [self.model.controller.name,
                          app.protocol.current_step_number],
                         interface=IPlugin)
             emit_signal('on_dmf_device_changed')
         except:
             logger.error("Invalid channel.")