Пример #1
0
 def draw_text(self, context, h, w, factor):
     text = 'This is a text'
     dx = w / 2
     dy = h / 2
     font = toga.Font(family=SANS_SERIF, size=20)
     width, height = font.measure(text, tight=True)
     context.write_text(text, dx - width / 2, dy, font)
Пример #2
0
 def test_write_text_repr(self):
     font = toga.Font(family=SERIF, size=4)
     write_text = self.testing_canvas.write_text("hello", x=10, y=-4.2, font=font)
     self.assertEqual(
         repr(write_text),
         "WriteText(text=hello, x=10, y=-4.2, font=<Font: 4pt serif>)",
     )
Пример #3
0
 def test_font_default_has_all_attr_set(self):
     self.interface = toga.Font(self.font_family, self.font_size)
     self.native = self.interface._impl.native
     self.assertEqual(self.native.get_family(), SYSTEM)
     self.assertEqual(self.native.get_size() / Pango.SCALE, self.font_size)
     self.assertEqual(self.native.get_style(), Pango.Style.NORMAL)
     self.assertEqual(self.native.get_variant(), Pango.Variant.NORMAL)
     self.assertEqual(self.native.get_weight(), Pango.Weight.NORMAL)
Пример #4
0
 def test_font_default_has_all_attr_set(self):
     font = toga.Font(self.font_family, self.font_size)
     native = font.bind(gtk_factory).native
     self.assertEqual(native.get_family(), SYSTEM)
     self.assertEqual(native.get_size() / Pango.SCALE, self.font_size)
     self.assertEqual(native.get_style(), Pango.Style.NORMAL)
     self.assertEqual(native.get_variant(), Pango.Variant.NORMAL)
     self.assertEqual(native.get_weight(), Pango.Weight.NORMAL)
Пример #5
0
    def setUp(self):
        super().setUp()

        self.family = "sans-serif"
        self.size = 14

        self.font = toga.Font(self.family,
                              self.size,
                              factory=toga_dummy.factory)
Пример #6
0
 def draw_text(self):
     x = 32
     y = 185
     font = toga.Font(family=SANS_SERIF, size=20)
     width, height = self.canvas.measure_text('Tiberius', font, tight=True)
     with self.canvas.stroke(line_width=4.0) as rect_stroker:
         rect_stroker.rect(x - 2, y - height + 2, width, height + 2)
     with self.canvas.fill(color=rgb(149, 119, 73)) as text_filler:
         text_filler.write_text('Tiberius', x, y, font)
Пример #7
0
 def draw_text(self):
     x = 32
     y = 185
     font = toga.Font(family='sans-serif', size=20)
     width, height = font.measure('Tiberius', tight=True)
     with self.canvas.stroke():
         self.canvas.rect(x - 10, y - height + 2, width, height + 2)
     with self.canvas.fill():
         self.canvas.fill_style('rgba(149.0, 119, 73, 1)')
         self.canvas.write_text('Tiberius', x, y, font)
Пример #8
0
 def test_write_text_simple(self):
     test_font = toga.Font(family=SANS_SERIF, size=15)
     write_text = self.testing_canvas.write_text("test text", 0, 0, test_font)
     self.assertIn(write_text, self.testing_canvas.drawing_objects)
     self.assertActionPerformedWith(
         self.testing_canvas,
         "write text",
         text="test text",
         x=0,
         y=0,
         font=test_font,
     )
Пример #9
0
    def setUp(self):
        super().setUp()

        self.family = SANS_SERIF
        self.size = 14

        self.font = toga.Font(
            self.family,
            self.size,
        )

        # Bind the font to the dummy factory
        self.font.bind(toga_dummy.factory)
Пример #10
0
    def _2021_11_07b_startup(self):
        self.main_window = toga.MainWindow(title=self.name, size=(250, 250))
        self.canvas = toga.Canvas(style=Pack(flex=1))
        self.main_window.content = toga.Box(children=[self.canvas])

        x = 32
        y = 185
        font = toga.Font(family=SANS_SERIF, size=20)
        width, height = self.canvas.measure_text('Tiberius', font, tight=True)
        with self.canvas.stroke(line_width=4.0) as rect_stroker:
            rect_stroker.rect(x, y - height, width, height)
        with self.canvas.fill(color=rgb(149, 119, 73)) as text_filler:
            text_filler.write_text('Tiberius', x, y, font)
        # Show the main window
        self.main_window.show()
Пример #11
0
    def draw_instructions(self, context, factor):
        text = """Instructions:
1. Use the controls to modify the image
2. Press and drag to move the image
3. Double press to center the image at that position
4. Drag using the alternate (e.g. right) button to rotate the image
"""
        font = toga.Font(
            family=self.font_selection.value,
            size=self.font_size.value,
            weight=self.get_weight(),
            style=self.get_style(),
        )
        width, height = self.canvas.measure_text(text, font, tight=True)
        context.write_text(text, self.x_middle - width / 2, self.y_middle, font)
Пример #12
0
    def setUp(self):
        super().setUp()

        self.family = SANS_SERIF
        self.size = 14
        self.style = ITALIC
        self.variant = SMALL_CAPS
        self.weight = BOLD

        self.font = toga.Font(family=self.family,
                              size=self.size,
                              style=self.style,
                              variant=self.variant,
                              weight=self.weight)

        # Bind the font to the dummy factory
        self.font.bind(toga_dummy.factory)
Пример #13
0
 def test_write_text_modify(self):
     write_text = self.testing_canvas.write_text("test text")
     modify_font = toga.Font(family=SERIF, size=1.2)
     write_text.text, write_text.x, write_text.y, write_text.font = (
         "hello again",
         10,
         -1999,
         modify_font,
     )
     self.testing_canvas.redraw()
     self.assertActionPerformedWith(
         self.testing_canvas,
         "write text",
         text="hello again",
         x=10,
         y=-1999,
         font=modify_font,
     )
Пример #14
0
 def test_font_variant_small_caps(self):
     font = toga.Font(self.font_family, self.font_size, variant=SMALL_CAPS)
     native = font.bind(gtk_factory).native
     self.assertEqual(native.get_variant(), Pango.Variant.SMALL_CAPS)
Пример #15
0
 def test_font_style_oblique(self):
     font = toga.Font(self.font_family, self.font_size, style=OBLIQUE)
     native = font.bind(gtk_factory).native
     self.assertEqual(native.get_style(), Pango.Style.OBLIQUE)
Пример #16
0
 def test_font_style_italic(self):
     font = toga.Font(self.font_family, self.font_size, style=ITALIC)
     native = font.bind(gtk_factory).native
     self.assertEqual(native.get_style(), Pango.Style.ITALIC)
Пример #17
0
 def test_font_size(self):
     self.font_size = 22
     font = toga.Font(self.font_family, self.font_size)
     native = font.bind(gtk_factory).native
     self.assertEqual(native.get_size() / Pango.SCALE, self.font_size)
Пример #18
0
 def test_font_size(self):
     self.font_size = 22
     self.interface = toga.Font(self.font_family, self.font_size)
     self.native = self.interface._impl.native
     self.assertEqual(self.native.get_size() / Pango.SCALE, self.font_size)
Пример #19
0
 def test_font_family_defaults_to_system(self):
     font = toga.Font(CURSIVE, self.font_size)
     native = font.bind(gtk_factory).native
     self.assertIn(CURSIVE, native.get_family())
     self.assertIn(SYSTEM, native.get_family())
Пример #20
0
 def test_write_text(self):
     test_font = toga.Font(family=SANS_SERIF, size=15)
     self.testing_canvas.write_text('test text', 0, 0, test_font)
     self.assertActionPerformedWith(self.testing_canvas, 'write text', text='test text', x=0, y=0, font=test_font)
Пример #21
0
 def test_font_style_italic(self):
     self.interface = toga.Font(self.font_family,
                                self.font_size,
                                style=ITALIC)
     self.native = self.interface._impl.native
     self.assertEqual(self.native.get_style(), Pango.Style.ITALIC)
Пример #22
0
 def test_font_style_oblique(self):
     self.interface = toga.Font(self.font_family,
                                self.font_size,
                                style=OBLIQUE)
     self.native = self.interface._impl.native
     self.assertEqual(self.native.get_style(), Pango.Style.OBLIQUE)
Пример #23
0
 def test_font_variant_small_caps(self):
     self.interface = toga.Font(self.font_family,
                                self.font_size,
                                variant=SMALL_CAPS)
     self.native = self.interface._impl.native
     self.assertEqual(self.native.get_variant(), Pango.Variant.SMALL_CAPS)
Пример #24
0
 def test_font_weight_bold(self):
     self.interface = toga.Font(self.font_family,
                                self.font_size,
                                weight=BOLD)
     self.native = self.interface._impl.native
     self.assertEqual(self.native.get_weight(), Pango.Weight.BOLD)
Пример #25
0
 def test_font_weight_bold(self):
     font = toga.Font(self.font_family, self.font_size, weight=BOLD)
     native = font.bind(gtk_factory).native
     self.assertEqual(native.get_weight(), Pango.Weight.BOLD)
Пример #26
0
 def test_font_cache(self):
     font = toga.Font(self.font_family, self.font_size)
     self.impl = gtk_fonts.Font(font)
     self.cache = gtk_fonts._FONT_CACHE
     self.assertEqual(self.cache[font], self.impl.native)
Пример #27
0
def build(app):
    font = toga.Font('Helvetica', 40)
    return toga.Box(children=[toga.Button('Button')])
Пример #28
0
 def test_font_family_defaults_to_system(self):
     self.interface = toga.Font(CURSIVE, self.font_size)
     self.native = self.interface._impl.native
     self.assertIn(CURSIVE, self.native.get_family())
     self.assertIn(SYSTEM, self.native.get_family())
Пример #29
0
 def test_font_cache(self):
     self.interface = toga.Font(self.font_family, self.font_size)
     self.impl = gtk_font.Font(self.interface)
     self.cache = gtk_font._FONT_CACHE
     self.assertEqual(self.cache[self.interface], self.impl.native)