示例#1
0
        self.first = 1.0
        self.second = 2.0
        self.result = 3.0
        self.op = 'add'

    def do_it(self):
        if self.op == 'add':
            self.result = operator.add(self.first, self.second)
        elif self.op == 'subtract':
            self.result = operator.sub(self.first, self.second)

        print('{0} {1} {2} = {3}'.format(self.first, self.op, self.second,
                                         self.result))
        pv.update()


# Create a view
textctrl_first = pv.TextCtrl('first', label='First', dtype=float)
textctrl_second = pv.TextCtrl('second', label='Second', dtype=float)
textctrl_result = pv.TextCtrl('result', label='Result', dtype=float)

button_do_it = pv.Button('do_it', label='Do it!')
combo_op = pv.ComboBox('op', item_list=['add', 'subtract'], label='Operation:')

view = pv.View([[textctrl_first, textctrl_second, textctrl_result], [combo_op],
                [button_do_it]],
               title='Small Calculator')

# Run the program
pv.run(model, view)
示例#2
0
            time.sleep(self.rate)
            self.arduino.digital[self.pin].write(0)
            time.sleep(self.rate)

            if self.want_to_abort: break

    def stop(self):
        self.want_to_abort = True


# Create a view
textctrl_port = pv.TextCtrl('port', label='Port:')
textctrl_rate = pv.TextCtrl('rate', label='Rate (s):', dtype=float)

combo_pin = pv.ComboBox('pin', [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13],
                        label='Pin:',
                        dtype=int)

button_start = pv.Button('start', label='Start!')
button_stop = pv.Button('stop', label='Stop', single_threaded=False)
button_load_arduino = pv.Button('load_arduino',
                                label='Load',
                                single_threaded=False)

view = pv.View([[textctrl_port, button_load_arduino],
                [button_start, button_stop], [combo_pin, textctrl_rate]],
               title='Arduino Blinker')

# Run the program
pv.run(model, view)
示例#3
0
    def start(self):
        self.want_to_abort = False

        while True:
            self.count += 1
            self.ind.append(self.count)
            self.result.append(np.random.randn(1))

            pv.update()

            time.sleep(0.1)
            if self.want_to_abort: break

    def stop(self):
        self.want_to_abort = True


# Create a view
axes_params = dict(ylabel='Magnitude',
                   xlabel='Data Point #',
                   title='Data Generator')
plot = pv.Plot(x='ind', y='result', plot_type='plot', axes_params=axes_params)

button_start = pv.Button('start', label='Start!')
button_stop = pv.Button('stop', label='Stop', single_threaded=False)

view = pv.View([[plot], [button_start, button_stop]], title='Random Data!')

# Run the program
pv.run(model, view)
示例#4
0
        self.want_to_abort = True



# Create a view
axes_params = dict(ylabel='Magnitude',
                   xlabel='Data Point #',
                   title='Analog Pin Value')
plot = pv.Plot(x='ind', y='result', plot_type='plot', axes_params=axes_params) 

textctrl_port = pv.TextCtrl('port', label='Port:')
textctrl_rate = pv.TextCtrl('rate', label='Rate (s):', dtype=float)

combo_pin = pv.ComboBox('pin', [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13], dtype=int)

button_start = pv.Button('start', label='Start!')
button_stop = pv.Button('stop', label='Stop', single_threaded=False)
button_load_arduino = pv.Button('load_arduino', label='Load')


view = pv.View([[textctrl_port, button_load_arduino],
                [plot],
                [button_start, button_stop],
                [combo_pin, textctrl_rate]],
                title='Arduino Analog-in')

# Run the program
pv.run(model, view)


示例#5
0
            res = operator.sub(self.first, self.second)

        self.count += 1
        self.ind.append(self.count)
        self.result.append(res)

        print('{0} {1} {2} = {3}'.format(self.first, self.op, self.second,
                                         res))
        pv.update()


# Create a view
axes_params = dict(ylabel='Magnitude',
                   xlabel='Calc #',
                   title='History of Calculations')

plot = pv.Plot(x='ind', y='result', plot_type='plot', axes_params=axes_params)

textctrl_first = pv.TextCtrl('first', label='First', dtype=float)
textctrl_second = pv.TextCtrl('second', label='Second', dtype=float)

button_do_it = pv.Button('do_it', label='Do it!')
combo_op = pv.ComboBox('op', item_list=['add', 'subtract'], label='Operation:')

view = pv.View(
    [[plot], [textctrl_first, textctrl_second], [combo_op], [button_do_it]],
    title='Small Graph Calculator')

# Run the program
pv.run(model, view)