def _zoom_labels(self, zoom): """Adjust grid label font to zoom factor""" labelfont = self.grid.GetLabelFont() default_fontsize = get_default_font().GetPointSize() labelfont.SetPointSize(max(1, int(round(default_fontsize * zoom)))) self.grid.SetLabelFont(labelfont)
def OnDrawItem(self, dc, rect, item, flags): if item == wx.NOT_FOUND: return default_font_size = get_default_font().GetPointSize() context = wx.lib.wxcairo.ContextFromDC(dc) context.rectangle(*rect) context.clip() pangocairo_context = pangocairo.CairoContext(context) pangocairo_context.set_antialias(cairo.ANTIALIAS_SUBPIXEL) layout = pangocairo_context.create_layout() fontname = self.GetString(item) font = pango.FontDescription("{} {}".format(fontname, default_font_size)) layout.set_font_description(font) layout.set_text(fontname) color = tuple( [c / 255.0 for c in get_color(config["text_color"]).Get()]) context.set_source_rgb(*color) height = layout.get_pixel_extents()[1][3] y_adjust = int((rect.height - height) / 2.0) context.translate(rect.x + 3, rect.y + y_adjust) pangocairo_context.update_layout(layout) pangocairo_context.show_layout(layout)
def OnDrawItem(self, dc, rect, item, flags): if item == wx.NOT_FOUND: return default_font_size = get_default_font().GetPointSize() context = wx.lib.wxcairo.ContextFromDC(dc) context.rectangle(*rect) context.clip() pangocairo_context = pangocairo.CairoContext(context) pangocairo_context.set_antialias(cairo.ANTIALIAS_SUBPIXEL) layout = pangocairo_context.create_layout() fontname = self.GetString(item) font = pango.FontDescription("{} {}".format(fontname, default_font_size)) layout.set_font_description(font) layout.set_text(fontname) context.set_source_rgb(0, 0, 0) height = layout.get_pixel_extents()[1][3] y_adjust = int((rect.height - height) / 2.0) context.translate(rect.x + 3, rect.y + y_adjust) pangocairo_context.update_layout(layout) pangocairo_context.show_layout(layout)
def get_font_from_data(fontdata): """Returns wx.Font from fontdata string""" textfont = get_default_font() if fontdata != "": nativefontinfo = wx.NativeFontInfo() nativefontinfo.FromString(fontdata) # OS X does not like a PointSize of 0 # Therefore, it is explicitly set to the system default font point size if not nativefontinfo.GetPointSize(): nativefontinfo.SetPointSize(get_default_font().GetPointSize()) textfont.SetNativeFontInfo(nativefontinfo) return textfont
def OnTextSize(self, event): """Text size combo text event handler""" try: size = int(event.GetString()) except Exception: size = get_default_font().GetPointSize() post_command_event(self, self.FontSizeMsg, size=size)
def get_font_from_data(fontdata): """Returns wx.Font from fontdata string""" textfont = get_default_font() if fontdata != "": nativefontinfo = wx.NativeFontInfo() nativefontinfo.FromString(fontdata) textfont.SetNativeFontInfo(nativefontinfo) return textfont
def _create_font_size_combo(self): """Creates font size combo box""" self.std_font_sizes = config["font_default_sizes"] font_size = str(get_default_font().GetPointSize()) self.font_size_combo = wx.ComboBox(self, -1, value=font_size, size=(60, -1), choices=map(unicode, self.std_font_sizes), style=wx.CB_DROPDOWN | wx.TE_PROCESS_ENTER) self.AddControl(self.font_size_combo) self.Bind(wx.EVT_COMBOBOX, self.OnTextSize, self.font_size_combo) self.Bind(wx.EVT_TEXT_ENTER, self.OnTextSize, self.font_size_combo)
def _create_font_size_combo(self): """Creates font size combo box""" self.std_font_sizes = config["font_default_sizes"] font_size = str(get_default_font().GetPointSize()) self.font_size_combo = \ wx.ComboBox(self, -1, value=font_size, size=(60, -1), choices=map(unicode, self.std_font_sizes), style=wx.CB_DROPDOWN | wx.TE_PROCESS_ENTER) self.font_size_combo.SetToolTipString(_(u"Text size\n(points)")) self.AddControl(self.font_size_combo) self.Bind(wx.EVT_COMBOBOX, self.OnTextSize, self.font_size_combo) self.Bind(wx.EVT_TEXT_ENTER, self.OnTextSize, self.font_size_combo)
def test_get_font(self, pointsize, fontweight, fontstyle, easyxf): """Test _get_font method""" pys_style = { 'textfont': get_default_font().GetFaceName(), 'pointsize': pointsize, 'fontweight': fontweight, 'fontstyle': fontstyle, } font = self.xls_in._get_font(pys_style) style = xlwt.easyxf(easyxf) assert font.bold == style.font.bold assert font.italic == style.font.italic assert font.height == style.font.height
def OnDrawItem(self, dc, rect, item, flags): if item == wx.NOT_FOUND: return __rect = wx.Rect(*rect) # make a copy __rect.Deflate(3, 5) font_string = self.GetString(item) font = get_default_font() font.SetFaceName(font_string) font.SetFamily(wx.FONTFAMILY_SWISS) dc.SetFont(font) text_width, text_height = dc.GetTextExtent(font_string) text_x = __rect.x text_y = __rect.y + int((__rect.height - text_height) / 2.0) # Draw the example text in the combobox dc.DrawText(font_string, text_x, text_y)