def traits_view(self):
        ideogram_grp = VGroup(UItem('ideogram_graph',
                                    visible_when='ideogram_visible',
                                    editor=ComponentEditor()),
                              label='Ideogram')

        spectrum_grp = VGroup(UItem('spectrum_graph',
                                    visible_when='spectrum_visible',
                                    editor=ComponentEditor()),
                              label='Spectrum')

        fmt = '%0.4f'
        age_grp = HGroup(Readonly('min_age', format_str=fmt, label='Min.'),
                         Readonly('max_age', format_str=fmt, label='Max.'),
                         Readonly(
                             'mean',
                             format_str=fmt,
                         ),
                         Readonly('weighted_mean',
                                  format_str=fmt,
                                  label='Wtd. Mean'),
                         label='Age',
                         show_border=True)

        mswd_grp = HGroup(
            Readonly('mswd', format_str=fmt, label='MSWD'),
            HGroup(Readonly('mswd_low', format_str=fmt, label='Low'),
                   Readonly('mswd_high', format_str=fmt, label='High'),
                   show_border=True,
                   label='Acceptable Range'))

        analyses_grp = UItem('analyses',
                             editor=TabularEditor(adapter=AnalysisAdapter()))

        stats_grp = VGroup(Readonly('n'),
                           analyses_grp,
                           age_grp,
                           mswd_grp,
                           label='Stats')

        vg = Tabbed(stats_grp, ideogram_grp, spectrum_grp)
        v = View(vg)
        return v
Ejemplo n.º 2
0
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(),
    )
 def traits_view(self):
     return View(Tabbed(*self._get_tabs()))
Ejemplo n.º 4
0
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)
Ejemplo n.º 5
0
class CUDSItemModelView(ModelView):
    """Wraps the CUDSItem node in a ModelView for easier representation
    and access."""
    traits_view = View(
        VGroup(
            VGroup(
                Item("model.name", resizable=True, enabled_when="False"),
                label="CUDS Item Data",
                show_border=True,
            ),
            Tabbed(
                HGroup(
                    VGroup(
                        UItem(
                            "all_fixed_properties",
                            editor=ListStrEditor(
                                adapter=PropertyAdapter(),
                                selected="selected_fixed_property"),
                        ),
                        UItem("selected_fixed_property_model_view",
                              style="custom",
                              enabled_when="fixed_property_model_view_enabled",
                              full_size=True),
                        show_border=False),
                    label="Fixed Properties",
                    show_border=False,
                ),
                HGroup(
                    VGroup(
                        UItem(
                            "all_variable_properties",
                            editor=ListStrEditor(
                                adapter=PropertyAdapter(),
                                selected="selected_variable_property"),
                        ),
                        UItem(
                            "selected_variable_property_model_view",
                            style="custom",
                            enabled_when=
                            "variable_property_model_view_enabled",  # noqa
                        ),
                        show_border=False),
                    label="Variable Properties",
                    show_border=False,
                ),
            )))

    #: A list of the fixed and variable properties on the CUDSItem
    #: we are visualising, and only that object.
    obj_fixed_properties = Property(List(FixedProperty), depends_on="model")
    obj_variable_properties = Property(List(VariableProperty),
                                       depends_on="model")

    #: A list of the fixed and variable properties on the CUDSItem
    #: we are visualising. This includes all those that we inherit
    all_fixed_properties = Property(List(FixedProperty), depends_on="model")
    all_variable_properties = Property(List(VariableProperty),
                                       depends_on="model")

    #: The properties that we inherit from the base CUDSItems.
    inherited_properties = Property(Either(List(FixedProperty),
                                           List(VariableProperty)),
                                    depends_on="model")

    #: The properties that are selected by the user when they click
    selected_fixed_property = Instance(FixedProperty)
    selected_variable_property = Instance(VariableProperty)

    #: The ModelViews of the above, to allow controlled presentation.
    selected_variable_property_model_view = Instance(VariablePropertyModelView)
    selected_fixed_property_model_view = Instance(FixedPropertyModelView)

    #: State that says if the editor window should be enabled or not
    #: Inherited variables cannot be edited on a derived class.
    fixed_property_model_view_enabled = Bool()
    variable_property_model_view_enabled = Bool()

    def _get_obj_fixed_properties(self):
        """Gets the fixed properties, only local to the object"""
        return [
            p for p in self.model.properties.values()
            if isinstance(p, FixedProperty)
        ]

    def _get_obj_variable_properties(self):
        """Gets the variable properties, only local to the object"""
        return [
            p for p in self.model.properties.values()
            if isinstance(p, VariableProperty)
        ]

    def _get_all_fixed_properties(self):
        """Gets all the fixed properties, both local to the object
        and from its hierarchy"""
        inherited_properties = [
            p for p in self.inherited_properties
            if isinstance(p, FixedProperty)
        ]

        return self.obj_fixed_properties + inherited_properties

    def _get_all_variable_properties(self):
        """Gets all the variable properties, both local to the object
        and from its hierarchy"""
        inherited_properties = [
            p for p in self.inherited_properties
            if isinstance(p, VariableProperty)
        ]
        return self.obj_variable_properties + inherited_properties

    def _get_inherited_properties(self):
        """Gets all the inherited properties."""
        parent_classes = list(traverse_to_root(self.model))[1:]
        inherited_properties = []
        for parent in parent_classes:
            inherited_properties += [p for p in parent.properties.values()]

        return inherited_properties

    @on_trait_change("selected_variable_property")
    def _update_selected_variable_property_model_view(self, value):
        """Syncs the modelview with the changed selected property"""
        self.selected_variable_property_model_view = VariablePropertyModelView(
            model=self.selected_variable_property)
        self.variable_property_model_view_enabled = \
            self.selected_variable_property in self.obj_variable_properties

    @on_trait_change("selected_fixed_property")
    def _update_selected_fixed_property_model_view(self, value):
        """Syncs the modelview with the changed selected property"""
        self.selected_fixed_property_model_view = FixedPropertyModelView(
            model=self.selected_fixed_property)
        self.fixed_property_model_view_enabled = \
            self.selected_fixed_property in self.obj_fixed_properties