def test_click_button_widget(self):
        """
        request widgets + click
        """
        counter = 0
        def button_click():
            nonlocal counter
            counter += 1

        track = lambda _: None
        paint = lambda _: None
        paintOverlay = lambda _: None
        shutdown = lambda _: None
        keep_running = lambda t: t != "5"

        def request_widgets():
            return[biotracker.Button("ClickMe", button_click)]

        _thread.start_new(test_server.widget_request_with_click, ())
        biotracker.run_client(
            track,
            paint,
            paintOverlay,
            shutdown,
            keep_running=keep_running,
            request_widgets=request_widgets
        )
        time.sleep(4)
        self.assertEqual(counter, 1)

    #def test_button_callback(self):
        """
    def test_request_widgets(self):
        """
        make sure that the widgets reach the server
        """
        track = lambda _: None
        paint = lambda _: None
        paintOverlay = lambda _: None
        shutdown = lambda _: None
        keep_running = lambda t: t != "4"

        def request_widgets():
            widgets = []
            widgets.append(biotracker.Button('Click', lambda _: None))
            widgets.append(biotracker.Divider())
            return widgets

        result = dict()
        _thread.start_new(test_server.send_widget_request, (result,))
        biotracker.run_client(
            track,
            paint,
            paintOverlay,
            shutdown,
            keep_running=keep_running,
            request_widgets=request_widgets)
        time.sleep(5)
        widgetsStr = result['widgets'].split(';')
        self.assertEqual(len(widgetsStr), 2)
        self.assertEqual(widgetsStr[1], "d()")
        btnTxt = widgetsStr[0].split(",")[1]
        self.assertEqual(btnTxt, "Click)")
    def test_full_paint_cycle(self):
        """

        """
        send_frame = 10

        def track():
            pass

        def paint(f):
            self.assertEqual(f, send_frame)

        def paintOverlay(qpainter):
            qpainter.drawRect((0, 1, 10, 5))

        def shutdown():
            pass

        def keep_running(msg_type):
                return msg_type != "3"

        result = dict()
        _thread.start_new(test_server.send_complete_paint, (send_frame, result))

        biotracker.run_client(
            track,
            paint,
            paintOverlay,
            shutdown,
            keep_running=keep_running)
        time.sleep(5)
        self.assertEqual(result['qpainter'], "r(0,1,10,5)")
    def test_wrong_function_registration(self):
        """
        test that we can only register functions
        """
        def track():
            pass

        def paint():
            pass
        shutdown = "hello"

        def paintOverlay():
            pass

        try:
            biotracker.run_client(track, paint, paintOverlay, shutdown)
            self.assertTrue(False)
        except:
            self.assertTrue(True)
    qpainter.drawRect((20, 20, 60, 60))


def shutdown():
    Signals.notify_gui("shutdown")


def btn_click():
    Signals.notify_gui("button click")


def btn2_click():
    Signals.notify_gui("button2 click")

def slider_changed(value):
    Signals.notify_gui("slider changed " + str(value))

def request_widgets():
    return [
        Button("ClickMe", btn_click),
        Button("ClickMeToo", btn2_click),
        Slider("Slide me", 0, 100, 25, slider_changed),
        Text("Funny text:")]

run_client(
    track,
    paint,
    paint_overlay,
    shutdown,
    request_widgets=request_widgets)
Mat = None


def track(frame, M):
    global Mat
    if M is not None:
        Mat = np.absolute(M - 50) 
        print("track " + str(frame) + str(Mat.shape))


def paint(frame):
    global Mat
    print("paint " + str(frame))


def paint_overlay(qpainter):
    qpainter.setPen(255, 255, 0, 255)
    qpainter.drawRect((20, 20, 60, 60))

def shutdown():
    print("shutdown")

def request_widgets():
    return []

biotracker.run_client(
    track,
    paint,
    paint_overlay,
    shutdown)
Пример #7
0

def paint(frame):
    global Mat
    return Mat


def paint_overlay(qpainter):
    qpainter.setPen((255, 0, 0))
    qpainter.drawRect((100, 50, 100, 50))
    pass


def button_click():
    Signals.notify_gui("Button clicked")


def request_widgets():
    return [Button("Hello", button_click)]


def shutdown():
    pass


run_client(track,
           paint,
           paint_overlay,
           shutdown,
           request_widgets=request_widgets)