Пример #1
0
def gui_ino_make(widget, ino_file="test.ino", verbose=True):
    """
    Collect unsorted channel events from entry fields

    Args:
        * widget: An obligatory GTK arg.

    Kwargs:
        * ino_file: Save results to this file (defaults to "test.ino").
        * verbose: Toggle verbose output (defaults to False).
        
    """
    try:
        assert type(ino_file) is str
    except AssertionError:
        if verbose:
            sys.stderr.write("gui_ino_make: ERROR: ino_file {} is not a string. Exiting.\n".format(ino_file))
        return 1
    events_unsorted = []
    if 1 > 0:   # TODO: user-chosen filename + check
        for chan_num in range(pbox.ARDUINO_CH_COUNT):
            if checks_chans[chan_num].get_active():     # if checkbox ticked
                # get data written into channel's entry field
                entry = entries_chans[chan_num].get_text().split(" ")
                if len(entry) > 0:  # checkbox can be ticked with no entry
                    # put data in a list beginning with channel number
                    chan_events = [["CH" + str(chan_num + 1)]]
                    chan_events.append(entry)
                    chan_events = sum(chan_events, [])  # flatten the list
                    # remove empty '' if present
                    for eachrun in range(chan_events.count('')):
                        chan_events.remove('')
                    # convert event times to int
                    chan_events[1:] = [int(x) for x in chan_events[1:]]
                    events_unsorted.append(chan_events)
        # TODO: improve status updates (success/fail, retcodes...)
        statusbar.push(1, "Making .ino...")
        events_sorted = pbox.ino_events_sort(events_unsorted)
        pbox.ino_make(ino_file, events_sorted, overwrite=True, verbose=True)
        statusbar.push(1, ".ino successfully created")
Пример #2
0
 def testAbsolute(self):
     self.events = [["CH1", 0, 20, 70, 90, 120, 200], ["CH2", 70, 130, 190, 210], ["CH3", 20, 70, 190, 230]]
     self.result = [[[1], 0], [[1, 3], 20], [[1, 2, 3], 50], [[1], 20], [[1], 30], [[2], 10], [[2, 3], 60],
                    [[1], 10], [[2], 10], [[3], 20]]
     assert pulsebox.ino_events_sort(self.events, relative=False) == self.result
Пример #3
0
 def testTypeError(self):
     with pytest.raises(TypeError):
         pulsebox.ino_events_sort(1)
     with pytest.raises(TypeError):
         pulsebox.ino_events_sort(0.1)
     with pytest.raises(TypeError):
         pulsebox.ino_events_sort("a")
     with pytest.raises(TypeError):
         pulsebox.ino_events_sort(True)
     with pytest.raises(TypeError):
         pulsebox.ino_events_sort([])
     with pytest.raises(TypeError):
         pulsebox.ino_events_sort([1])
     with pytest.raises(TypeError):
         pulsebox.ino_events_sort([["CH1", 1], 1])
     with pytest.raises(TypeError):
         pulsebox.ino_events_sort([["CH1", 1], ["CH2"]])
     with pytest.raises(TypeError):
         pulsebox.ino_events_sort([["CH1", 1], [1, 2]])
     with pytest.raises(TypeError):
         pulsebox.ino_events_sort([["CH1", 1], ["foo", 1]])
     with pytest.raises(TypeError):
         pulsebox.ino_events_sort([["CH1", 1], ["CHa", 1]])
     with pytest.raises(TypeError):
         pulsebox.ino_events_sort([["CH1", 1], ["CH2", 1, "a"]])
     with pytest.raises(TypeError):
         pulsebox.ino_events_sort([["CH1", 1], ["CH1", 1]])
     with pytest.raises(TypeError):
         pulsebox.ino_events_sort([["CH1", 1, 2, 3], ["CH2", 3, 2, 1]], relative=False)
Пример #4
0
 def testRelative(self):
     self.events = [["CH1", 0, 20, 50, 20, 30, 80], ["CH2", 70, 60, 60, 20], ["CH3", 20, 50, 120, 40]]
     self.result = [[[1], 0], [[1, 3], 20], [[1, 2, 3], 50], [[1], 20], [[1], 30], [[2], 10], [[2, 3], 60],
                    [[1], 10], [[2], 10], [[3], 20]]
     assert pulsebox.ino_events_sort(self.events) == self.result