def _one_dim_view(self, object, style, width, trait): content = [] shape = object.shape items = [] format_func = self.editor.factory.format_func format_str = self.editor.factory.format_str for i in range(shape[0]): name = "f%d" % i self.add_trait( name, trait( object[i], event="field", auto_set=self.editor.factory.auto_set, enter_set=self.editor.factory.enter_set, ), ) items.append( Item( name=name, style=style, width=width, format_func=format_func, format_str=format_str, padding=-3, )) group = Group(orientation="horizontal", show_labels=False, *items) content.append(group) return View(Group(show_labels=False, *content))
class SearchIDFilter(TableFilter): name = 'Search data ID filter' id_substr = Str('') def filter(self, entry): return self.id_substr in entry.data_id filter_view = Group(Item('id_substr', label='Search annotation IDs'))
def traits_view(self): ncolumns = len(self.data[0]) w_table = min(WIDTH_CELL * ncolumns, MAX_WIDTH) w_view = min(w_table + W_MARGIN, MAX_WIDTH) return View(Group( Item('data', editor=TabularEditor(adapter=Array2DAdapter( ncolumns=ncolumns, format='%s', show_index=True)), show_label=False, width=w_table, padding=10), ), title='Annotations', width=w_view, height=800, resizable=True, buttons=OKCancelButtons)
class ScopeWnd(AbstractWnd): pin = PinTrait('analog') interval = Time() @property def conf(self): return dict(pin=self.pin, interval=self.interval) def plot(self, data, fig): time_plot(data, fig) def measure(self, conf, stop_condition): return measure(self.conf, stop_condition) view = View( HGroup( 'start', 'stop', 'auto_update', readonly('alive', checkbox=True), ), # instance('tester', view=View( slider('interval', 0.1, 10), 'pin', # ), # ), Group( Item('figure', editor=MPLFigureEditor(), show_label=False ), ), width=600, height=300, resizable=True)
class ProjectInfoUI(cmp.project.ProjectInfo): """Class that extends the :class:`ProjectInfo` with graphical components. It supports graphically the setting of all processing properties / attributes of an :class:`ProjectInfo` instance. Attributes ----------- creation_mode : traits.Enum Mode for loading the dataset. Valid values are 'Load BIDS dataset', 'Install Datalad BIDS dataset' install_datalad_dataset_via_ssh : traits.Bool If set to True install the datalad dataset from a remote server via ssh.(True by default) ssh_user : traits.Str Remote server username. (Required if ``install_datalad_dataset_via_ssh`` is True) ssh_pwd <traits.Password> Remote server password. (Required if ``install_datalad_dataset_via_ssh`` is True) ssh_remote : traits.Str Remote server IP or URL. (Required if ``install_datalad_dataset_via_ssh`` is True) datalad_dataset_path : traits.Directory Path to the datalad dataset on the remote server. (Required if ``install_datalad_dataset_via_ssh`` is True) summary_view_button : traits.ui.Button Button that shows the pipeline processing summary table pipeline_processing_summary_view : traits.ui.VGroup TraitsUI VGroup that contains ``Item('pipeline_processing_summary')`` dataset_view : traits.ui.View TraitsUI View that shows a summary of project settings and modality available for a given subject traits_view : QtView TraitsUI QtView that includes the View 'dataset_view' create_view : traits.ui.View Dialog view to create a BIDS Dataset subject_view : traits.ui.View Dialog view to select of subject subject_session_view : traits.ui.View Dialog view to select the subject session dmri_bids_acq_view : traits.ui.View Dialog view to select the diffusion acquisition model anat_warning_view : traits.ui.View View that displays a warning message regarding the anatomical T1w data anat_config_error_view : traits.ui.View Error view that displays an error message regarding the configuration of the anatomical pipeline dmri_warning_view : traits.ui.View View that displays a warning message regarding the diffusion MRI data dmri_config_error_view : traits.ui.View View that displays an error message regarding the configuration of the diffusion pipeline fmri_warning_view : traits.ui.View View that displays a warning message regarding the functional MRI data fmri_config_error_view : traits.ui.View View that displays an error message regarding the configuration of the fMRI pipeline open_view : traits.ui.View Dialog view to load a BIDS Dataset anat_select_config_to_load : traits.ui.View Dialog view to load the configuration file of the anatomical pipeline diffusion_imaging_model_select_view : traits.ui.View Dialog view to select the diffusion acquisition model dmri_select_config_to_load : traits.ui.View Dialog view to load the configuration file of the diffusion MRI pipeline fmri_select_config_to_load : traits.ui.View Dialog view to load the configuration file of the fMRI pipeline """ creation_mode = Enum("Load BIDS dataset", "Install Datalad BIDS dataset") install_datalad_dataset_via_ssh = Bool(True) ssh_user = String("remote_username") ssh_pwd = Password("") ssh_remote = String("IP address/ Machine name") datalad_dataset_path = Directory( "/shared/path/to/existing/datalad/dataset") anat_runs = List() anat_run = Enum(values="anat_runs") dmri_runs = List() dmri_run = Enum(values="dmri_runs") fmri_runs = List() fmri_run = Enum(values="fmri_runs") summary_view_button = Button("Pipeline processing summary") pipeline_processing_summary_view = VGroup( Item("pipeline_processing_summary")) dataset_view = VGroup( VGroup( HGroup( Item( "base_directory", width=-0.3, style="readonly", label="", resizable=True, ), Item( "number_of_subjects", width=-0.3, style="readonly", label="Number of participants", resizable=True, ), "summary_view_button", ), label="BIDS Dataset", ), spring, HGroup( Group( Item("subject", style="simple", show_label=True, resizable=True)), Group( Item("subject_session", style="simple", label="Session", resizable=True), visible_when='subject_session!=""', ), springy=True, ), spring, Group( Item("t1_available", style="readonly", label="T1", resizable=True), HGroup( Item( "dmri_available", style="readonly", label="Diffusion", resizable=True, ), Item( "diffusion_imaging_model", label="Model", resizable=True, enabled_when="dmri_available", ), ), Item("fmri_available", style="readonly", label="BOLD", resizable=True), label="Modalities", ), spring, Group( Item( "anat_last_date_processed", label="Anatomical pipeline", style="readonly", resizable=True, enabled_when="t1_available", ), Item( "dmri_last_date_processed", label="Diffusion pipeline", style="readonly", resizable=True, enabled_when="dmri_available", ), Item( "fmri_last_date_processed", label="fMRI pipeline", style="readonly", resizable=True, enabled_when="fmri_available", ), label="Last date processed", ), spring, Group(Item("number_of_cores", resizable=True), label="Processing configuration"), "550", spring, springy=True, ) traits_view = QtView(Include("dataset_view")) create_view = View( Item("creation_mode", style="custom"), Group( Group( Item("base_directory", label="BIDS Dataset"), visible_when='creation_mode=="Load BIDS dataset"', ), Group( Item("install_datalad_dataset_via_ssh"), visible_when='creation_mode=="Install Datalad/BIDS dataset"', ), Group( Item( "ssh_remote", label="Remote ssh server", visible_when="install_datalad_dataset_via_ssh", ), Item( "ssh_user", label="Remote username", visible_when="install_datalad_dataset_via_ssh", ), Item( "ssh_pwd", label="Remote password", visible_when="install_datalad_dataset_via_ssh", ), Item( "datalad_dataset_path", label="Datalad/BIDS Dataset Path/URL to be installed", ), Item("base_directory", label="Installation directory"), visible_when='creation_mode=="Install Datalad/BIDS dataset"', ), ), kind="livemodal", title="Data creation: BIDS dataset selection", # style_sheet=style_sheet, width=modal_width, buttons=["OK", "Cancel"], ) subject_view = View( Group(Item("subject", label="Selected Subject")), kind="modal", title="Subject and session selection", # style_sheet=style_sheet, width=modal_width, buttons=["OK", "Cancel"], ) subject_session_view = View( Group( Item("subject", style="readonly", label="Selected Subject"), Item("subject_session", label="Selected Session"), ), kind="modal", title="Session selection", # style_sheet=style_sheet, width=modal_width, buttons=["OK", "Cancel"], ) dmri_bids_acq_view = View( Group(Item("dmri_bids_acq", label="Selected model"), ), kind="modal", title="Selection of diffusion acquisition model", # style_sheet=style_sheet, width=modal_width, buttons=["OK", "Cancel"], ) anat_warning_view = View( Group(Item("anat_warning_msg", style="readonly", show_label=False), ), title="Warning : Anatomical T1w data", kind="modal", width=modal_width, # style_sheet=style_sheet, buttons=["OK", "Cancel"], ) anat_config_error_view = View( Group( Item("anat_config_error_msg", style="readonly", show_label=False), ), title="Error", kind="modal", width=modal_width, # style_sheet=style_sheet, buttons=["OK", "Cancel"], ) dmri_warning_view = View( Group(Item("dmri_warning_msg", style="readonly", show_label=False), ), title="Warning : Diffusion MRI data", kind="modal", width=modal_width, # style_sheet=style_sheet, buttons=["OK", "Cancel"], ) dmri_config_error_view = View( Group( Item("dmri_config_error_msg", style="readonly", show_label=False), ), title="Error", kind="modal", width=modal_width, # style_sheet=style_sheet, buttons=["OK", "Cancel"], ) fmri_warning_view = View( Group(Item("fmri_warning_msg", style="readonly", show_label=False), ), title="Warning : fMRI data", kind="modal", width=modal_width, # style_sheet=style_sheet, buttons=["OK", "Cancel"], ) fmri_config_error_view = View( Group( Item("fmri_config_error_msg", style="readonly", show_label=False), ), title="Error", kind="modal", width=modal_width, # style_sheet=style_sheet, buttons=["OK", "Cancel"], ) open_view = View( Item("creation_mode", label="Mode"), Group( Item("install_datalad_dataset_via_ssh"), Item( "ssh_remote", label="Remote ssh server", visible_when="install_datalad_dataset_via_ssh", ), Item( "ssh_user", label="Remote username", visible_when="install_datalad_dataset_via_ssh", ), Item( "ssh_pwd", label="Remote password", visible_when="install_datalad_dataset_via_ssh", ), Item( "datalad_dataset_path", label="Datalad/BIDS Dataset Path/URL to be installed", ), Item("base_directory", label="Installation directory"), visible_when='creation_mode=="Install Datalad BIDS dataset"', ), Group( Item("base_directory", label="BIDS Dataset"), visible_when='creation_mode=="Load BIDS dataset"', ), kind="livemodal", title="BIDS Dataset Creation/Loading", # style_sheet=style_sheet, width=600, height=250, buttons=["OK", "Cancel"], ) anat_select_config_to_load = View( Group( Item("anat_config_to_load_msg", style="readonly", show_label=False), Item( "anat_config_to_load", style="custom", editor=EnumEditor(name="anat_available_config"), show_label=False, ), ), title="Select configuration for anatomical pipeline", kind="modal", width=modal_width, # style_sheet=style_sheet, buttons=["OK", "Cancel"], ) anat_custom_map_view = View( Group( Item( "anat_custom_last_stage", editor=EnumEditor(name="anat_stage_names"), style="custom", show_label=False, ), ), title="Select until which stage to process the anatomical pipeline.", kind="modal", width=modal_width, # style_sheet=style_sheet, buttons=["OK", "Cancel"], ) diffusion_imaging_model_select_view = View( Group(Item("diffusion_imaging_model", label="Diffusion MRI modality"), ), title="Please select diffusion MRI modality", kind="modal", width=modal_width, buttons=["OK", "Cancel"], ) dmri_select_config_to_load = View( Group( Item("dmri_config_to_load_msg", style="readonly", show_label=False), ), Item( "dmri_config_to_load", style="custom", editor=EnumEditor(name="dmri_available_config"), show_label=False, ), title="Select configuration for diffusion pipeline", kind="modal", width=modal_width, # style_sheet=style_sheet, buttons=["OK", "Cancel"], ) dmri_custom_map_view = View( Group( Item( "dmri_custom_last_stage", editor=EnumEditor(name="dmri_stage_names"), style="custom", show_label=False, ), ), title="Select until which stage to process the diffusion pipeline.", kind="modal", width=modal_width, # style_sheet=style_sheet, buttons=["OK", "Cancel"], ) fmri_select_config_to_load = View( Group( Item("fmri_config_to_load_msg", style="readonly", show_label=False), ), Item( "fmri_config_to_load", style="custom", editor=EnumEditor(name="fmri_available_config"), show_label=False, ), title="Select configuration for fMRI pipeline", kind="modal", width=modal_width, # style_sheet=style_sheet, buttons=["OK", "Cancel"], ) fmri_custom_map_view = View( Group( Item( "fmri_custom_last_stage", editor=EnumEditor(name="fmri_stage_names"), style="custom", show_label=False, ), ), title="Select until which stage to process the fMRI pipeline.", kind="modal", width=modal_width, # style_sheet=style_sheet, buttons=["OK", "Cancel"], ) def _summary_view_button_fired(self): self.configure_traits(view="pipeline_processing_summary_view")
class BoardWrapper(HasTraits): pins = List(PinWrapper) digital_pins = List(PinWrapper) analog_pins = List(PinWrapper) defines = List(GuiDefine) port_type = Enum('serial', [ 'none', 'serial', ] ) serial_device = Enum(_auto_detect_serial_unix()) baudrate = Int(115200) sleep_after_connect = Int(2) timeout = Int(1) uptime = Float() tree = None vcc = Float() avr_name = Str() arduino_version = Str() firmware_build_time = Str() gcc_version = Str() libc_version = Str() libc_date = Str() connected = Bool(False) connect = Button() disconnect = Button() def _connect_fired(self): try: connection = SerialManager(device=self.serial_device, baudrate=self.baudrate, sleep_after_connect=self.sleep_after_connect, timeout=self.timeout) connection.open() print ArduinoApi(connection=connection).millis() except Exception as e: traceback.print_exc() message(traceback.format_exc(), buttons=['OK']) return a = self.tree = ArduinoTree(connection=connection) d = a.define.as_dict s = [GuiDefine(name=k, value=str(v)) for k, v in d.items()] s.sort(key=lambda x: x.name) self.defines = s self.digital_pins = [PinWrapper(pin=a.pin.get(x)) for x in a.pin.names_digital] self.analog_pins = [PinWrapper(pin=a.pin.get(x)) for x in a.pin.names_analog] self.pins = self.digital_pins + self.analog_pins fw = a.firmware_info self.arduino_version = fw.get('arduino_version') self.firmware_build_time = str(fw.get('compile_datetime')) self.avr_name = fw.get('avr_name') self.gcc_version = fw.get('gcc_version') self.libc_version = fw.get('libc_version') self.libc_date = str(fw.get('libc_date')) self.connected = True def _disconnect_fired(self): self.digital_pins = [] self.analog_pins = [] self.pins = [] self.defines = [] self.avr_name = '' self.arduino_version = '' self.firmware_build_time = '' self.gcc_version = '' self.libc_version = '' self.libc_date = '' self.tree.connection.close() del self.tree self.tree = None self.connected = False update_interval = Int(1000, desc='interval in msec') update_enable = Bool(True) def update(self): if self.update_enable and self.connected and self.tree: for x in self.pins: x.update() self.uptime = self.tree.api.millis() / 1000.0 self.vcc = self.tree.vcc.read() if self.tree.vcc else -1 time.sleep(self.update_interval / 1000.0) traits_view = View( Tabbed( Group( HGroup( Group( button('connect', enabled_when='not connected'), button('disconnect', enabled_when='connected'), Item( 'port_type', enabled_when='not connected', width=300, ), Group( 'serial_device', 'baudrate', 'sleep_after_connect', 'timeout', visible_when='port_type=="serial"', enabled_when='not connected', ), ), Group( 'avr_name', 'arduino_version', 'firmware_build_time', 'gcc_version', 'libc_version', 'libc_date', # 'baudrate', # 'sleep_after_connect', # visible_when='port_type=="serial"', springy=True, ), ), label='connection', ), Group( 'uptime', 'vcc', label='misc', ), Item(name='digital_pins', editor=ListEditor( style='custom', ), style='readonly', show_label=False, ), Item(name='analog_pins', editor=ListEditor( style='custom', ), style='readonly', show_label=False, ), Group( 'update_enable', Item(name='update_interval', editor=RangeEditor( mode='slider', low=1, high=1000, ), style='custom', ), label='settings', ), Item('defines', show_label=False, editor=ListEditor( # auto_size=False, # editable=False, # configurable=False, style='custom', ), style='readonly', ) ), width=800, height=600, buttons=['Undo', 'Revert', 'OK', 'Cancel'], kind='live', resizable=True, handler=Handler(), )
class FileEditor(TextEditor): """ Editor factory for file editors. """ # ------------------------------------------------------------------------- # Trait definitions: # ------------------------------------------------------------------------- #: Wildcard filter to apply to the file dialog: filter = filter_trait #: Optional extended trait name of the trait containing the list of #: filters: filter_name = Str() #: Should file extension be truncated? truncate_ext = Bool(False) #: Can the user select directories as well as files? allow_dir = Bool(False) #: Is user input set on every keystroke? (Overrides the default) ('simple' #: style only): auto_set = False #: Is user input set when the Enter key is pressed? (Overrides the default) #: ('simple' style only): enter_set = True #: The number of history entries to maintain: #: FIXME: This is currently only supported on wx. Qt support needs to be #: added entries = Int(10) #: The root path of the file tree view ('custom' style only, not supported #: under wx). If not specified, the filesystem root is used. root_path = File() #: Optional extend trait name of the trait containing the root path. root_path_name = Str() #: Optional extended trait name used to notify the editor when the file #: system view should be reloaded ('custom' style only): reload_name = Str() #: Optional extended trait name used to notify when the user double-clicks #: an entry in the file tree view. The associated path is assigned it: dclick_name = Str() #: The style of file dialog to use when the 'Browse...' button is clicked #: Should be one of 'open' or 'save' dialog_style = Str("open") # ------------------------------------------------------------------------- # Traits view definition: # ------------------------------------------------------------------------- traits_view = View([ [ "<options>", "truncate_ext{Automatically truncate file extension?}", "|options:[Options]>", ], ["filter", "|[Wildcard filters]<>"], ]) extras = Group()
class EventSelectionDialog(HasTraits): source_class_label = String("Select Event Source Classes") severity_level_label = String("Select Event Severity Levels") search = String(regex="^[_a-zA-Z0-9\*\.\$\^\?\s]*$") shown_event_names_list = String(regex="[_a-zA-Z0-9\*\.\$\^\?\n]*") quit_button = Button('Quit') query_button = Button('Run Query...') period_start_date = DelegatesTo("query_object") period_end_date = DelegatesTo("query_object") selected_list_of_event_severity_levels = DelegatesTo("query_object") list_of_event_severity_levels = DelegatesTo("query_object") selected_list_of_source_classes = DelegatesTo("query_object") list_of_source_classes = DelegatesTo("query_object") query_object = Instance(EventSelectionQuery) spring = Spring help_text = ( "Search engine like queries using alphanumeric characters and '_'and '.' \n" + "Space indicate OR-separated queries\n" + "? = match any character\n" + "* = any number of characters\n" + "^ = match beginning\n" "$ = match end") view = View( Group( VGroup( HGroup(Item("period_start_date", label="Period"), Item("period_end_date", show_label=False), Item("", resizable=True, width=1.0, show_label=False), HGroup(Item('quit_button', show_label=False), Item('query_button', show_label=False)), springy=True), HGroup( VGroup( HGroup( Item("severity_level_label", show_label=False, style="readonly")), Item("selected_list_of_event_severity_levels", editor=CheckListEditor( name="list_of_event_severity_levels"), style="custom", show_label=False)), VGroup( HGroup( Item("source_class_label", show_label=False, style="readonly")), Item("selected_list_of_source_classes", editor=CheckListEditor( name="list_of_source_classes"), style="custom", show_label=False)), # springy=True ), show_border=True), Item("_"), VGroup(Item("search", editor=HistoryEditor(auto_set=True), show_label=False, width=1.0, tooltip=help_text), Item( name='shown_event_names_list', style='readonly', resizable=True, show_label=False, ), scrollable=True, show_border=True), orientation='vertical', ), title='Select Events to Visualize', dock='horizontal', resizable=True, width=.5, height=.7) def __init__(self, query_object, **kwargs): ''' Creates a dialog window for selecting date period, source classes and event severity levels/types. :param query_object: :return: ''' assert isinstance(query_object, EventSelectionQuery) self.shown_event_names_list = "\n".join( list(query_object.list_of_event_names)) self.query_object = query_object self.query_start_date = query_object.period_start_date self.query_end_date = query_object.period_end_date HasTraits.__init__(self, **kwargs) def _search_changed(self): ''' Matches search query to the event names. :return: ''' query_st = str(self.search).strip() if re.match("^[_a-zA-Z0-9\*\.\$\^\?\s]*$", query_st) is None: return query_st = query_st.replace(".", "\.") query_st = query_st.replace("*", ".*") query_st = query_st.replace("?", ".?") queries = query_st.split() print self.search, query_st, queries, if len(queries) == 0: queries = [""] result = [ s for s in list(self.query_object.list_of_event_names) for q in queries if re.search((".*%s.*" % q), s) is not None ] self.query_object.selected_list_of_event_names = result self.shown_event_names_list = "\n".join(result) print len(self.shown_event_names_list) def _save_search(self): # A bug fix, stops the clearing of the search expression tmp = self.search self.search = " " self.search = tmp print len(self.query_object.selected_list_of_event_names) def _query_button_changed(self): self._save_search() self.query_object.execute_query() def _quit_button_changed(self): self._save_search() sys.exit(0)
def __init__(self, editor): """Initializes the object.""" super().__init__(editor=editor) factory = editor.factory types = factory.types labels = factory.labels editors = factory.editors cols = factory.cols # Get the tuple we are mirroring: object = editor.value # For each tuple field, add a trait with the appropriate trait # definition and default value: content = [] self.fields = len(object) len_labels = len(labels) len_editors = len(editors) if types is None: type = editor.value_trait.handler if isinstance(type, BaseTuple): types = type.types if not isinstance(types, SequenceTypes): types = [types] len_types = len(types) if len_types == 0: types = [Any] len_types = 1 for i, value in enumerate(object): type = types[i % len_types] auto_set = enter_set = None if isinstance(type, TraitType): auto_set = type.auto_set enter_set = type.enter_set if auto_set is None: auto_set = editor.factory.auto_set if enter_set is None: enter_set = editor.factory.enter_set label = "" if i < len_labels: label = labels[i] field_editor = None if i < len_editors: field_editor = editors[i] name = "f%d" % i self.add_trait( name, type( value, event="field", auto_set=auto_set, enter_set=enter_set, ), ) item = Item(name=name, label=label, editor=field_editor) if cols <= 1: content.append(item) else: if (i % cols) == 0: group = Group(orientation="horizontal") content.append(group) group.content.append(item) self.view = View(Group(show_labels=(len_labels != 0), *content))
class TextEditor(EditorFactory): """ Editor factory for text editors. """ # ------------------------------------------------------------------------- # Trait definitions: # ------------------------------------------------------------------------- #: Dictionary that maps user input to other values mapping = mapping_trait #: Is user input set on every keystroke? auto_set = Bool(True) #: Is user input set when the Enter key is pressed? enter_set = Bool(False) #: Is multi-line text allowed? multi_line = Bool(True) #: Is editor readonly (will use custom / default editor appearance with #: readonly flag set to true) in contrast with readonly style for item #: when completely another editor is used read_only = Bool(False) #: Is user input unreadable? (e.g., for a password) password = Bool(False) #: Function to evaluate textual user input evaluate = evaluate_trait #: The object trait containing the function used to evaluate user input evaluate_name = Str() #: The optional view to display when a read-only text editor is clicked: view = AView #: In a read-only text editor, allow selection and copying of the text. readonly_allow_selection = Bool(False) #: Grayed-out placeholder text to be displayed when the editor is empty. placeholder = Str() #: Whether or not to display a clear button for the text. This only works #: in the qt>=5.2 backend for simple/text styles of the editor. Note this #: trait is currently provisional and may be replaced in the future by a #: more general feature. cancel_button = Bool(False) # ------------------------------------------------------------------------- # Traits view definition: # ------------------------------------------------------------------------- traits_view = View( [ "auto_set{Set value when text is typed}", "enter_set{Set value when enter is pressed}", "multi_line{Allow multiple lines of text}", "<extras>", "|options:[Options]>", ] ) extras = Group("password{Is this a password field?}")
class PlotWnd(FigureWnd): dummy = Any def _dummy_default(self): self._project_changed() configfile = ConfigFile() # conf = None project = Enum(projects) def mfullpath(self, m): return self.project.result_dir / m def _project_default(self): x = Project.find(self.configfile.get('project')) if x: return x else: return projects[-1] plot_type = Any def _plot_type_default(self): x = self.project.plot(self.configfile.get('plot_type')) if x: return x else: if len(self.available_plots): return self.available_plots[-1] available_plots = List() def _available_plots_default(self): return self.project.allplots() measurement = Any available_measurements = List() def _available_measurements_default(self): return self.project.allmeasurements() # @traced def _measurement_changed(self): self.update_figure() self.result = '' self.result = self.project.analyse_str(self.mfullpath( self.measurement)) def _plot_type_changed(self): self.update_figure() if self.plot_type: self.configfile.set('plot_type', self.plot_type.name) def _available_plots_changed(self): if len(self.available_plots): self.plot_type = self.available_plots[0] # @traced def update_available_measurements(self): def fnames(ls): return [x.name for x in ls] self.available_measurements = fnames(self.project.allmeasurements()) if len(self.available_measurements): self.measurement = self.available_measurements[-1] else: self.measurement = None # self.measurement = None def _project_changed(self): self.configfile.set('project', self.project.name) # self.plot_type = None # self.available_plots = [] # self.measurement = None # self.available_measurements = [] self.update_available_measurements() self.available_plots = self.project.allplots() # if len(self.available_plots): # self.plot_type = self.available_plots[0] def create_plot(self, fig): # dw = DataWrapper(zipfile=self.measurement) try: assert self.measurement self.plot_type.create(fig, self.mfullpath(self.measurement)) except Exception as e: traceback.print_exc() # def measure(self, conf, stop_condition): # self.project.measure() reload = Button() def _reload_fired(self): self.update_available_measurements() show = Button() def _show_fired(self): assert self.measurement # dw = DataWrapper(zipfile=self.mfullpath(self.measurement)) # file_out = tempfile.NamedTemporaryFile( # prefix='measurement_', suffix='.json', delete=0) # file_out.close() # self.project.save(file_out.name, as_zip=0) d = tmpdir() z = ZipFile(self.mfullpath(self.measurement)) z.extractall(d) for f in d.walkfiles(): print f open_text_file_in_editor(f) rename = Button() def _rename_fired(self): assert self.measurement newname = inputbox(message='new name:', default=self.measurement) if newname: (self.project.result_dir / self.measurement).rename( self.project.result_dir / newname) self.update_available_measurements() delete = Button() def _delete_fired(self): assert self.measurement res = message('Delete "%s" ?' % self.measurement, buttons=['OK', 'Cancel']) if res: # path (self.project.result_dir / self.measurement).remove() self.update_available_measurements() directory = Button() def _directory_fired(self): open_text_file_in_editor(self.project.result_dir) analyse = Button() def _analyse_fired(self): assert self.measurement s = self.project.analyse_str(self.mfullpath(self.measurement)) print(s) textbox(s) open = Button() def _open_fired(self): # print self.measurement assert self.measurement # show.show(self.project.name, self.plot_type.name, self.measurement, # block=False) self.plot_type.display(self.mfullpath(self.measurement), block=False) config = Button() def _config_fired(self): open_text_file_in_editor(self.project.default_config_path) schematic_template = Button() def _schematic_template_fired(self): open_text_file_in_editor(self.project.schematic.template_path) schematic = Button() def _schematic_fired(self): open_string_in_editor(self.project.schematic.text) measure = Button() def _measure_fired(self): # print self.project.schematic.text # print self.project.default_config self.project.measure() self.update_available_measurements() # print self.available_plots # data = analyse(data) # IV_curve_plot(data, fig) # def measure(self, conf, stop_condition): # data = measure(self.conf) # return data result = Str() view = View( Group( Item(name='dummy', defined_when='0'), HGroup( 'project', button('config'), button('schematic_template'), button('schematic'), button('measure'), ), HGroup( Item( name='measurement', editor=EnumEditor(name='available_measurements'), # style='custom', ), button('reload'), button('show'), button('directory'), button('analyse'), button('rename'), button('delete'), ), HGroup( Item( name='plot_type', editor=EnumEditor(name='available_plots'), # style='custom', ), button('open'), ), # 'start', # 'stop', # 'auto_update', # readonly('alive', checkbox=True), ), '_', Tabbed( Item('figure', editor=MPLFigureEditor(), show_label=False), Item( name='result', show_label=False, style='readonly', editor=CodeEditor(), ), ), width=900, height=600, resizable=True)