class LEDDemo(HasTraits): # A counter to display: counter1 = Int # A floating point value to display: counter2 = Float # The traits view: view = View( Item('counter1', label='Left aligned', editor=LEDEditor(alignment='left') ), Item('counter1', label='Center aligned', editor=LEDEditor(alignment='center') ), Item('counter1', label='Right aligned', editor=LEDEditor() # default = 'right' aligned ), Item('counter2', label='Float value', editor=LEDEditor(format_str='%.3f') ), '_', HGroup( Item('counter1', label='Left', height=-40, width=120, editor=LEDEditor(alignment='left') ), spring, Item('counter1', label='Center', height=-40, width=120, editor=LEDEditor(alignment='center') ), spring, Item('counter1', label='Right', height=-40, width=120, editor=LEDEditor() # default = 'right' aligned ), spring, Item('counter2', label='Float', height=-40, width=120, editor=LEDEditor(format_str='%.3f') ) ), title='LED Editor Demo', buttons=['OK'], handler=LEDDemoHandler )
class WattsUp( HasTraits ): power = Float(0.0, label='Watts', height=-40, editor=LEDEditor(format_str='%5.1f') ) voltage = Float(0.0, label='Volts', height=-40, editor=LEDEditor(format_str='%5.1f') ) current = Float(0.0, label='Amps', height=-40, editor=LEDEditor(format_str='%5.3f') ) interval = Int(1, desc='Sample interval in seconds', label='Sample interval (s)') mode = Enum('Simulated', 'External', 'Internal', desc='Meter logging mode', label='Mode') port = String('/dev/tty.usbserial-A1000wT3', desc='Serial port location', label='Serial port') button_label = String('Start') start = Event logging_thread = Instance(LoggingThread) figure = Instance(Figure, ()) def update_data(self, W, V, A): self.power = W self.voltage = V self.current = A def _figure_default(self): figure = Figure() figure.add_axes([0.1, 0.15, 0.5, 0.75]) return figure def _start_fired(self): if self.logging_thread and self.logging_thread.isAlive(): self.logging_thread.wants_abort = True self.button_label = 'Start' else: self.logging_thread = LoggingThread() self.logging_thread.wants_abort = False self.logging_thread.update_data = self.update_data self.logging_thread.plot_power = self.plot_power self.logging_thread.figure = self.figure self.logging_thread.start() self.button_label = 'Stop' def plot_power(self, p): t = np.linspace(0, len(p) / 60.0, len(p)) # should multiply by interval # print t.size, len(p) self.figure.axes[0].clear() self.figure.axes[0].plot(t, p, 'r') self.figure.axes[0].set_xlabel('Time (minutes)') self.figure.axes[0].set_ylabel('Power (W)') wx.CallAfter(self.figure.canvas.draw) view = View(HSplit(Group(Item('power', height=-40), Item('voltage', height=-40), Item('current', height=-40), 'interval', 'mode', 'port', Item('start', label='Logging', editor=ButtonEditor(label_value='button_label'))), Item('figure', editor=MPLFigureEditor(), dock='vertical', height=-400, width=-800, resizable=True), show_labels=False))