def test_bitmap_canvas(self): self.frame.SetSize((1000, 1000)) cnvs = canvas.BitmapCanvas(self.panel) cnvs.SetBackgroundColour("#00599B") self.add_control(cnvs, wx.EXPAND, proportion=1) im_data = generate_img_data(300, 300, 4) img = (im_data, (0.0, 0.0), (1.0, 1.0), True, None, None, 0, None, "bitmap test") cnvs.set_images([img, None]) cnvs.update_drawing() test.gui_loop(0.5)
def test_text_view_overlay_size(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) for f in (False, True): msg = "TextViewOverlay sizes test {} flip" size = 0 y = 0 for i in range(10): y += 12 + size size = 10 + i * 3 ol.add_label(msg.format("with" if f else "without"), font_size=size, pos=(0, y), flip=f, colour=hex_to_frgb(gui.FG_COLOUR_EDIT)) test.gui_loop(50) ol.clear_labels()
def test_bitmap_canvas(self): cnvs = canvas.BitmapCanvas(self.panel) cnvs.SetBackgroundColour("#00599B") self.add_control(cnvs, wx.EXPAND, proportion=1) img = (data.gettest_pattern_sImage(), (0.0, 0.0), 1.0, True, None) cnvs.set_images([img, None]) cnvs.update_drawing() test.gui_loop() test.sleep(500) self.remove_all() cnvs = canvas.DraggableCanvas(self.panel) cnvs.SetBackgroundColour("#3C9B00") self.add_control(cnvs, wx.EXPAND, proportion=1) cnvs.set_images([img, None]) cnvs.update_drawing() # cnvs.fit_view_to_content() test.gui_loop() test.sleep(500)
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(50) 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(50) 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(50) 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(50) # 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(50) 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(50) 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(50) 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(50) 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(50) 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(50)
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(50) 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(100) 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(1000) for l in (tl, tr, tc): l.deg = 15 test.gui_loop(500) cnvs.Refresh()