def test_str_to_font(self): # Simple from_str = str_to_font("modern 10") from_ctor = Font(family=MODERN, size=10) self.assertEqual(from_ctor, from_str) # Some complexity from_str = str_to_font("roman bold italic 12") from_ctor = Font(family=ROMAN, weight=WEIGHT_BOLD, style=ITALIC, size=12) self.assertEqual(from_ctor, from_str) # Lots of complexity from_str = str_to_font("Times roman bold italic underline 72") from_ctor = Font( "Times", family=ROMAN, weight=WEIGHT_BOLD, style=ITALIC, size=72, underline=1, ) self.assertEqual(from_ctor, from_str)
def _get_font(self, name, default_size=10): xn = getattr(self, "{}_font_name".format(name)) xs = getattr(self, "{}_font_size".format(name)) if xn is None: xn = FONTS[0] if xs is None: xs = default_size return str_to_font("{} {}".format(xn, xs))
def _get_font(self, name, default_size=10): xn = getattr(self, '{}_font_name'.format(name)) xs = getattr(self, '{}_font_size'.format(name)) if xn is None: xn = FONTS[0] if xs is None: xs = default_size return str_to_font('{} {}'.format(xn, xs))
def overlay(self, other_component, gc, view_bounds=None, mode="normal"): with gc: comp = self.component gc.clip_to_rect(comp.x, comp.y, comp.width, comp.height) # gc.set_fill_color((1, 0, 1)) if self._cached_pts is None: self._cached_pts = self._gather_points() gc.set_font(str_to_font('modern 10')) for i, (x, y, pts) in enumerate(self._cached_pts): self._render_hole(gc, str(i + 1), x, y, pts) gc.stroke_path()
def draw(self, component, gc): r = 6 gc.set_font(str_to_font('modern 10')) with gc: gc.translate_ctm(component.x + 20, component.y2 - 50) # monitor with gc: gc.set_line_width(1) gc.set_fill_color((0, 0, 0)) gc.arc(0, 30, r, 0, 360) x = 0 y = 30 gc.move_to(x, y - r) gc.line_to(x, y + r) gc.stroke_path() gc.move_to(x - r, y) gc.line_to(x + r, y) gc.stroke_path() gc.set_text_position(10, 26) gc.show_text('Monitor') # irradiated with gc: gc.set_line_width(1) gc.set_fill_color(self.loaded_color_) gc.arc(0, 16, r, 0, 360) gc.fill_path() gc.set_text_position(10, 12) gc.show_text('Irradiated') # measured with gc: gc.set_line_width(1) gc.set_fill_color(self.loaded_color_) gc.arc(0, 0, r, 0, 360) gc.fill_path() with gc: gc.set_line_width(2) gc.set_stroke_color(self.measured_color_) gc.arc(0, 0, r + 1, 0, 360) gc.stroke_path() gc.set_text_position(10, -5) gc.show_text('Measured')
def _draw_container_mainlayer(self, gc, view_bounds, mode="default"): 'Draws a filled container with the word "Container" in the center' if not self._font: self._font = str_to_font("modern 10") with gc: gc.set_fill_color(self.bgcolor_) gc.rect(self.x, self.y, self.width, self.height) gc.draw_path() self._draw_border(gc) gc.set_font(self._font) gc.set_fill_color((1.0, 1.0, 1.0, 1.0)) tx, ty, tw, th = gc.get_text_extent("Container") tx = self.x + self.width / 2.0 - tw / 2.0 ty = self.y + self.height / 2.0 - th / 2.0 gc.show_text_at_point("Container", tx, ty)
def draw(self, gc, **kwargs): if not self._font: self._font = str_to_font("modern 48") gc.clear((0.5, 0.5, 0.5)) mx = self.x + self.width / 2.0 my = self.y + self.height / 2.0 with gc: gc.set_fill_color((1.0, 1.0, 0.0, 1.0)) gc.arc(mx, my, 100, 0, 2 * math.pi) gc.fill_path() gc.set_font(self._font) tx, ty, tw, th = gc.get_text_extent(self.quote) tx = mx - tw / 2.0 ty = my - th / 2.0 gc.set_fill_color((0.0, 0.0, 0.0, 1.0)) gc.show_text_at_point(self.quote, tx, ty)
def _get_gfont(self): return str_to_font(self.font)
def gfont(self): return str_to_font(self.font)