Esempio n. 1
0
    def test_text_view_overlay_rotate(self):
        cnvs = canvas.BitmapCanvas(self.panel)
        self.add_control(cnvs, wx.EXPAND, proportion=1, clear=True)
        ol = vol.TextViewOverlay(cnvs)
        ol.canvas_padding = 0
        cnvs.add_view_overlay(ol)

        # Text should exactly overlap

        rl = ol.add_label(u"█ you should only see red",
                          pos=(0, 0),
                          font_size=20,
                          deg=0,
                          flip=False,
                          colour=hex_to_frgb(gui.FG_COLOUR_EDIT))
        test.gui_loop(0.05)

        sl = ol.add_label(u"█ you should only see red",
                          pos=(0, 0),
                          font_size=20,
                          colour=(1, 0, 0),
                          align=wx.ALIGN_LEFT)
        test.gui_loop(0.1)
        self.assertEqual(rl.render_pos, sl.render_pos)

        ol.clear_labels()

        ol.add_label(u"█ no rotate",
                     pos=(200, 0),
                     font_size=20,
                     colour=(1, 0, 0),
                     align=wx.ALIGN_LEFT)

        tl = ol.add_label(u"█ rotate left",
                          pos=(200, 25),
                          font_size=20,
                          deg=0,
                          flip=False,
                          colour=hex_to_frgb(gui.FG_COLOUR_EDIT))

        tr = ol.add_label(u"rotate right █",
                          pos=(200, 50),
                          font_size=20,
                          align=wx.ALIGN_RIGHT,
                          deg=0,
                          flip=False,
                          colour=hex_to_frgb(gui.FG_COLOUR_EDIT))

        tc = ol.add_label(u"rotate center █",
                          pos=(200, 75),
                          font_size=20,
                          align=wx.ALIGN_CENTRE_HORIZONTAL,
                          deg=0,
                          flip=False,
                          colour=hex_to_frgb(gui.FG_COLOUR_EDIT))

        test.gui_loop(1)

        for l in (tl, tr, tc):
            l.deg = 15
            test.gui_loop(0.5)
            cnvs.Refresh()
Esempio n. 2
0
    def test_roa_select_overlay(self):
        # but it should be a simple miccanvas
        cnvs = miccanvas.DblMicroscopeCanvas(self.panel)

        self.add_control(cnvs, wx.EXPAND, proportion=1, clear=True)

        rsol = wol.RepetitionSelectOverlay(cnvs)
        rsol.activate()
        cnvs.add_world_overlay(rsol)
        cnvs.scale = 400
        cnvs.update_drawing()

        test.gui_loop()
        wroi = [-0.1, 0.3, 0.2, 0.4]  # in m
        rsol.set_physical_sel(wroi)
        test.gui_loop()
        wroi_back = rsol.get_physical_sel()

        for o, b in zip(wroi, wroi_back):
            self.assertAlmostEqual(o, b, msg="wroi (%s) != bak (%s)" % (wroi, wroi_back))

        rsol.repetition = (3, 2)
        rsol.fill = wol.RepetitionSelectOverlay.FILL_POINT

        pos = cnvs.margins[0] + 10,  cnvs.margins[1] + 10
        rsol.add_label("Repetition fill will change in 2 seconds.",
                       pos, colour=(0.8, 0.2, 0.1))

        # cnvs.update_drawing()
        test.gui_loop(2)

        rsol.set_physical_sel((-0.1, -0.3, 0.4, 0.4))
        rsol.repetition = (50, 80)
        rsol.fill = wol.RepetitionSelectOverlay.FILL_GRID

        pos = cnvs.margins[0] + 10, cnvs.margins[1] + 10
        rsol.add_label("Repetition fill will change in 2 seconds.",
                       pos, colour=(0.8, 0.2, 0.1))

        # cnvs.update_drawing()
        test.gui_loop(2)

        # Fine grid => solid colour
        rsol.repetition = (500, 800)
        rsol.fill = wol.RepetitionSelectOverlay.FILL_GRID

        pos = cnvs.margins[0] + 10, cnvs.margins[1] + 10
        rsol.add_label("Repetition fill will change in 2 seconds.",
                       pos, colour=(0.8, 0.2, 0.1))

        # cnvs.update_drawing()
        test.gui_loop(2)

        tol = vol.TextViewOverlay(cnvs)
        tol.add_label("Right click to toggle tool")
        cnvs.add_view_overlay(tol)

        def toggle(evt):
            if rsol.active:
                rsol.deactivate()
            else:
                rsol.activate()
            evt.Skip()

        cnvs.Bind(wx.EVT_RIGHT_UP, toggle)

        test.gui_loop()
Esempio n. 3
0
    def test_text_view_overlay_align(self):
        cnvs = canvas.BitmapCanvas(self.panel)
        self.add_control(cnvs, wx.EXPAND, proportion=1, clear=True)

        ol = vol.TextViewOverlay(cnvs)
        cnvs.add_view_overlay(ol)

        ol.add_label("TextViewOverlay left",
                     pos=(ol.view_width / 2, 10),
                     colour=hex_to_frgb(gui.FG_COLOUR_EDIT))
        test.gui_loop(0.05)

        ol.add_label("TextViewOverlay right",
                     pos=(ol.view_width / 2, 26),
                     align=wx.ALIGN_RIGHT,
                     colour=hex_to_frgb(gui.FG_COLOUR_EDIT))
        test.gui_loop(0.05)

        ol.add_label("TextViewOverlay center",
                     pos=(ol.view_width / 2, 42),
                     align=wx.ALIGN_CENTER_HORIZONTAL,
                     colour=hex_to_frgb(gui.FG_COLOUR_EDIT))
        test.gui_loop(0.05)

        ol.add_label("|",
                     pos=(ol.view_width / 2, 58),
                     align=wx.ALIGN_CENTER_HORIZONTAL,
                     colour=hex_to_frgb(gui.FG_COLOUR_EDIT))
        ol.add_label("|",
                     pos=(ol.view_width / 2, 74),
                     align=wx.ALIGN_CENTER_HORIZONTAL,
                     colour=hex_to_frgb(gui.FG_COLOUR_EDIT))
        ol.add_label("Relative to the center",
                     pos=(ol.view_width / 2, 90),
                     align=wx.ALIGN_CENTER_HORIZONTAL,
                     colour=hex_to_frgb(gui.FG_COLOUR_EDIT))
        test.gui_loop(0.05)

        # Example on how a right aligned label can be kept on the right on resize
        def realign(evt):
            for label in ol.labels:
                label.pos = (ol.view_width / 2, label.pos[1])
            evt.Skip()

        cnvs.Bind(wx.EVT_SIZE, realign)

        ol.canvas_padding = 0

        ol.add_label("top left",
                     pos=(0, 0),
                     align=wx.ALIGN_LEFT,
                     colour=hex_to_frgb(gui.FG_COLOUR_EDIT))
        test.gui_loop(0.05)

        ol.add_label("top right",
                     pos=(ol.view_width, 0),
                     align=wx.ALIGN_RIGHT,
                     colour=hex_to_frgb(gui.FG_COLOUR_EDIT))
        test.gui_loop(0.05)

        ol.add_label("bottom left",
                     pos=(0, ol.view_height),
                     align=wx.ALIGN_BOTTOM,
                     colour=hex_to_frgb(gui.FG_COLOUR_EDIT))
        test.gui_loop(0.05)

        ol.add_label("bottom right",
                     pos=(ol.view_width, ol.view_height),
                     align=wx.ALIGN_RIGHT | wx.ALIGN_BOTTOM,
                     flip=False,
                     colour=hex_to_frgb(gui.FG_COLOUR_EDIT))
        test.gui_loop(0.05)

        ol.add_label("SHOULD NOT BE SEEN!",
                     pos=(ol.view_width, ol.view_height / 2),
                     align=wx.ALIGN_LEFT,
                     flip=False,
                     colour=hex_to_frgb(gui.FG_COLOUR_EDIT))
        test.gui_loop(0.05)

        ol.add_label("Visible because of flip",
                     pos=(ol.view_width, ol.view_height / 2),
                     align=wx.ALIGN_LEFT,
                     flip=True,
                     colour=hex_to_frgb(gui.FG_COLOUR_EDIT))
        test.gui_loop(0.05)