class NewModelBDialog(NewModelDialog): """Create a dialog requesting the parameters to create Model B.""" model_name = Str(MODEL_B_NAME) nclasses = Int(5) nannotators = Int(8) # prior strength multiplies the dirichlet parameters alpha prior_strength = Float(1.0) parameters_group = VGroup( Item(name='nclasses', editor=RangeEditor(mode='spinner', low=2, high=1000), label='Number of annotation classes:', width=100), Item(name='nannotators', editor=RangeEditor(mode='spinner', low=2, high=1000), label='Number of annotators:', width=100), Item(name='prior_strength', editor=RangeEditor(mode='slider', low=0.0, low_label='null ', high=3.0, high_label=' high', label_width=50), label='Informativeness of prior:') )
class _SamplingParamsDialog(HasTraits): nsamples = Int(200) burn_in_samples = Int(100) thin_samples = Int(1) traits_view = View(VGroup( Item('nsamples', label='Number of samples', editor=RangeEditor(mode='spinner', low=100, high=50000, is_float=False), width=100), Item('burn_in_samples', label='Number of samples in burn-in phase', editor=RangeEditor(mode='spinner', low=1, high=50000, is_float=False), width=100), Item('thin_samples', label='Thinning (keep 1 samples every N)', editor=RangeEditor(mode='spinner', low=1, high=50000, is_float=False), width=100), ), buttons=OKCancelButtons)
def traits_view(self): view = View(VGroup( Item('nannotators', editor=RangeEditor(mode='spinner', low=3, high=1000), label='Number of annotators:'), Item('nitems', editor=RangeEditor(mode='spinner', low=2, high=1000000), label='Number of items'), ), buttons=['OK', 'Cancel']) return view
class NewModelBtDialog(NewModelDialog): model_name = Str(MODEL_BT_NAME) nclasses = Int(5) nannotators = Int(8) parameters_group = VGroup( Item(name='nclasses', editor=RangeEditor(mode='spinner', low=2, high=1000), label='Number of annotation classes:', width=100), Item(name='nannotators', editor=RangeEditor(mode='spinner', low=2, high=1000), label='Number of annotators:', width=100), )
def default_traits_view(self): view = View( Item('scene', editor=SceneEditor(scene_class=MayaviScene), height=600, width=600, show_label=False), HGroup( Item("current_time", label="Date"), Item(" "), Item("num_of_shown_days", label="Show"), Item("_home_button", show_label=False), Item("_selected_source_name", show_label=False), Item("_selected_event_name", editor=CheckListEditor(name='_selected_events_list'), show_label=False), Item("_back1", show_label=False), Item( "Relative_Start_Day", show_label=False, editor=RangeEditor(mode="slider", low_name="_low_start_day_number", high_name="_high_start_day_number"), tooltip= "Shows total number of days in data set and the currently selected day", springy=True, full_size=True), Item("_forward1", show_label=False), Item("move_step", show_label=False), Item("play_button", label='Play')), title="Visualization of Events", resizable=True) view.resizable = True return view
class FloatWithRangeEditor(HasTraits): """Dialog containing a RangeEditor in 'spinner' mode for an Int. """ number = Float(5.0) traits_view = View(Item('number', editor=RangeEditor(low=0.0, high=12.0)), buttons=['OK'])
class NumberWithRangeEditor(HasTraits): """Dialog containing a RangeEditor in 'spinner' mode for an Int. """ number = Int traits_view = View( Item(label="Range should be 3 to 8. Enter 1, then press OK"), Item('number', editor=RangeEditor(low=3, high=8, mode='text')), buttons=['OK'])
class NumberWithSpinnerEditor(HasTraits): """Dialog containing a RangeEditor in 'spinner' mode for an Int. """ number = Int traits_view = View(Item(label="Enter 4, then press OK without defocusing"), Item('number', editor=RangeEditor(low=3, high=8, mode='spinner')), buttons=['OK'])
class NewModelADialog(NewModelDialog): """Create a dialog requesting the parameters to create Model A.""" model_name = Str(MODEL_A_NAME) nclasses = Int(5) parameters_group = VGroup( Item(name='nclasses', editor=RangeEditor(mode='spinner', low=3, high=1000), label='Number of annotation classes:', width=100), )
def slider(name, low=0, high=100, is_float=True): return Item( name=name, editor=RangeEditor( mode='slider', low=low, high=high, is_float=is_float, ), style='custom', )
def traits_view(self): traits_view = View( VGroup( Item('annotator_idx', label='Annotator index', editor=RangeEditor(mode='spinner', low=0, high=self.theta.shape[0]-1, ), ), HGroup( Item('theta_j_view', style='custom', show_label=False), ), ), width = 500, height = 400, resizable = True ) return traits_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 PinWrapper(HasTraits): pin = Any() function = Any() usb = Any() timer = Any() initmode = False avr_pin = Any() def _pin_changed(self): self.initmode = True self.name = self.pin.name self.mode = ['INPUT', 'OUTPUT'][self.pin.read_mode()] if self.mode == 'OUTPUT': # TODO: self.digital_output = bool(self.pin.read_digital_value()) self.function = self.pin.programming_function if hasattr(self.pin, 'is_usb_plus'): self.usb = ['', '+', '-'][self.pin.is_usb_plus + 2 * self.pin.is_usb_minus] else: self.usb = '' if self.pin.pwm.available: ls = [ int(x) for x in self.pin.pwm.frequencies_available if x is not None ] if not ls: ls = [-1] self.add_trait('pwm_frequency', Enum(ls)) self.pwm_frequency = int( self.pin.pwm.frequency if self.pin.pwm.frequency else -1) self.timer = self.pin.pwm.timer_register_name_b self.avr_pin = self.pin.avr_pin self.initmode = False def _pwm_frequency_changed(self): self.pin.pwm.frequency = self.pwm_frequency pwm_output = Range(0, 255) def _pwm_output_changed(self): self.pin.pwm.write_value(self.pwm_output) pwm = Bool() def _pwm_changed(self): if self.pwm: self._pwm_output_changed() else: self._digital_output_changed() name = Str() mode = Enum(['INPUT', 'OUTPUT']) def _mode_changed(self): if not self.initmode: self.pin.write_mode(OUTPUT if (self.mode == 'OUTPUT') else INPUT) pullup = Bool() def _pullup_changed(self): self.pin.write_pullup(self.pullup) digital_input = Bool() digital_output = Bool() def _digital_output_changed(self): if not self.initmode: # TODO: self.pin.write_digital_value(self.digital_output) analog_input = Any() # voltage = Any() def update(self): '' if self.mode == 'INPUT': self.analog_input = self.pin.analog_value # self.voltage = an.voltage self.digital_input = bool(self.pin.read_digital_value()) traits_view = View( HGroup( Item( 'name', show_label=False, style='readonly', ), Item( 'avr_pin', show_label=False, style='readonly', format_func=lambda x: '(%s)' % (x), ), 'mode', Item( 'pwm', visible_when='mode=="OUTPUT"', defined_when='pin.pwm.available', ), HGroup( Item( 'digital_input', defined_when='pin.is_digital', enabled_when='0', ), Item( 'analog_input', defined_when='pin.is_analog', style='readonly', ), # Item('voltage', # defined_when='pin.is_analog', # style='readonly', # ), Item('pullup', ), visible_when='mode=="INPUT"', ), Item( 'digital_output', visible_when='mode=="OUTPUT" and not pwm', ), HGroup( Item('pwm_frequency', ), Item( name='pwm_output', editor=RangeEditor( mode='slider', low=0, high=255, ), style='custom', ), visible_when='mode=="OUTPUT" and pwm', defined_when='pin.pwm.available', ), Item( 'timer', defined_when='timer', style='readonly', ), Item( 'function', defined_when='function', style='readonly', ), Item( 'usb', defined_when='usb', style='readonly', ), ), )