def test_fontutil(self): f1 = wx.FFont(12, wx.FONTFAMILY_SWISS) i1 = f1.GetNativeFontInfo() st = i1.ToString() i2 = wx.NativeFontInfo() i2.FromString(st) f2 = wx.Font(i2) self.assertTrue(f1 == f2)
def test_fontutilProperties(self): nfi = wx.NativeFontInfo() nfi.InitFromFont(wx.NORMAL_FONT) nfi.Encoding nfi.FaceName nfi.Family nfi.PointSize #nfi.PixelSize nfi.Style nfi.Underlined nfi.Weight
def UpdateSampleFont(self): nativeFont = wx.NativeFontInfo() nativeFont.FromString(self._textFont.GetNativeFontInfoDesc()) font = wx.NullFont font.SetNativeFontInfo(nativeFont) font.SetPointSize(self._sampleTextCtrl.GetFont().GetPointSize()) # Use the standard point size self._sampleTextCtrl.SetFont(font) self._sampleTextCtrl.SetForegroundColour(self._textColor) self._sampleTextCtrl.SetValue(_("%d pt. %s") % (self._textFont.GetPointSize(), self._textFont.GetFaceName())) self._sampleTextCtrl.Refresh() self.Layout()
def _GetFontAndColorFromConfig(self): font = wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.NORMAL) config = wx.ConfigBase_Get() fontData = config.Read("TextEditorFont", "") if fontData: nativeFont = wx.NativeFontInfo() nativeFont.FromString(fontData) font.SetNativeFontInfo(nativeFont) color = wx.BLACK colorData = config.Read("TextEditorColor", "") if colorData: red = int("0x" + colorData[0:2], 16) green = int("0x" + colorData[2:4], 16) blue = int("0x" + colorData[4:6], 16) color = wx.Colour(red, green, blue) return font, color
def __init__(self, parent, ID=-1, validator=wx.DefaultValidator): style = wx.TE_MULTILINE | wx.TE_PROCESS_ENTER | wx.TE_PROCESS_TAB | wx.TE_RICH2 wx.TextCtrl.__init__(self, parent, ID, style=style, validator=validator) ttFont = self.GetFont() ttFont.SetFamily(wx.FONTFAMILY_TELETYPE) if "wxMSW" in wx.PlatformInfo: # see http://aspn.activestate.com/ASPN/Mail/Message/wxPython-users/1690364 for explanation e = wx.NativeFontInfo() e.FromString("0;-11;0;0;0;400;0;0;0;0;3;2;1;49;Courier New") ttFont.SetNativeFontInfo(e) self.SetFont(ttFont) self.Bind(wx.EVT_CONTEXT_MENU, self.OnContextMenu) self._InitPopupMenu()
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 __init__(self, parent, id): wx.Panel.__init__(self, parent, id) SPACE = 10 HALF_SPACE = 5 config = wx.ConfigBase_Get() self._textFont = wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.NORMAL) fontData = config.Read("TextEditorFont", "") if fontData: nativeFont = wx.NativeFontInfo() nativeFont.FromString(fontData) self._textFont.SetNativeFontInfo(nativeFont) self._originalTextFont = self._textFont self._textColor = wx.BLACK colorData = config.Read("TextEditorColor", "") if colorData: red = int("0x" + colorData[0:2], 16) green = int("0x" + colorData[2:4], 16) blue = int("0x" + colorData[4:6], 16) self._textColor = wx.Colour(red, green, blue) self._originalTextColor = self._textColor parent.AddPage(self, _("Text")) fontLabel = wx.StaticText(self, -1, _("Font:")) self._sampleTextCtrl = wx.TextCtrl(self, -1, "", size=(125, -1)) self._sampleTextCtrl.SetEditable(False) chooseFontButton = wx.Button(self, -1, _("Choose Font...")) wx.EVT_BUTTON(self, chooseFontButton.GetId(), self.OnChooseFont) self._wordWrapCheckBox = wx.CheckBox(self, -1, _("Wrap words inside text area")) self._wordWrapCheckBox.SetValue(wx.ConfigBase_Get().ReadInt( "TextEditorWordWrap", True)) textPanelBorderSizer = wx.BoxSizer(wx.VERTICAL) textPanelSizer = wx.BoxSizer(wx.VERTICAL) textFontSizer = wx.BoxSizer(wx.HORIZONTAL) textFontSizer.Add(fontLabel, 0, wx.ALIGN_LEFT | wx.RIGHT | wx.TOP, HALF_SPACE) textFontSizer.Add(self._sampleTextCtrl, 0, wx.ALIGN_LEFT | wx.EXPAND | wx.RIGHT, HALF_SPACE) textFontSizer.Add(chooseFontButton, 0, wx.ALIGN_RIGHT | wx.LEFT, HALF_SPACE) textPanelSizer.Add(textFontSizer, 0, wx.ALL, HALF_SPACE) textPanelSizer.Add(self._wordWrapCheckBox, 0, wx.ALL, HALF_SPACE) textPanelBorderSizer.Add(textPanelSizer, 0, wx.ALL, SPACE) self.SetSizer(textPanelBorderSizer) self.UpdateSampleFont()
def __init__(self, cfgGl): if not ConfigGui.constantsInited: ConfigGui.bluePen = wx.Pen(wx.Colour(0, 0, 255)) ConfigGui.redColor = wx.Colour(255, 0, 0) ConfigGui.blackColor = wx.Colour(0, 0, 0) ConfigGui.constantsInited = True # convert cfgGl.MyColor -> cfgGui.wx.Colour for it in cfgGl.cvars.color.itervalues(): c = getattr(cfgGl, it.name) tmp = wx.Colour(c.r, c.g, c.b) setattr(self, it.name, tmp) # key = line type, value = wx.Colour self._lt2textColor = {} for t in getTIs(): self._lt2textColor[t.lt] = getattr(self, "text%sColor" % t.name) self.textPen = wx.Pen(self.textColor) self.textHdrPen = wx.Pen(self.textHdrColor) self.workspaceBrush = wx.Brush(self.workspaceColor) self.workspacePen = wx.Pen(self.workspaceColor) self.textBgBrush = wx.Brush(self.textBgColor) self.textBgPen = wx.Pen(self.textBgColor) self.pageBorderPen = wx.Pen(self.pageBorderColor) self.pageShadowPen = wx.Pen(self.pageShadowColor) self.selectedBrush = wx.Brush(self.selectedColor) self.selectedPen = wx.Pen(self.selectedColor) self.searchBrush = wx.Brush(self.searchColor) self.searchPen = wx.Pen(self.searchColor) self.cursorBrush = wx.Brush(self.cursorColor) self.cursorPen = wx.Pen(self.cursorColor) self.noteBrush = wx.Brush(self.noteColor) self.notePen = wx.Pen(self.noteColor) self.autoCompPen = wx.Pen(self.autoCompFgColor) self.autoCompBrush = wx.Brush(self.autoCompBgColor) self.autoCompRevPen = wx.Pen(self.autoCompBgColor) self.autoCompRevBrush = wx.Brush(self.autoCompFgColor) self.pagebreakPen = wx.Pen(self.pagebreakColor) self.pagebreakNoAdjustPen = wx.Pen(self.pagebreakNoAdjustColor, style=wx.DOT) self.tabTextPen = wx.Pen(self.tabTextColor) self.tabBorderPen = wx.Pen(self.tabBorderColor) self.tabBarBgBrush = wx.Brush(self.tabBarBgColor) self.tabBarBgPen = wx.Pen(self.tabBarBgColor) self.tabNonActiveBgBrush = wx.Brush(self.tabNonActiveBgColor) self.tabNonActiveBgPen = wx.Pen(self.tabNonActiveBgColor) # a 4-item list of FontInfo objects, indexed by the two lowest # bits of pml.TextOp.flags. self.fonts = [] for fname in [ "fontNormal", "fontBold", "fontItalic", "fontBoldItalic" ]: fi = FontInfo() s = getattr(cfgGl, fname) # evil users can set the font name to empty by modifying the # config file, and some wxWidgets ports crash hard when trying # to create a font from an empty string, so we must guard # against that. if s: nfi = wx.NativeFontInfo() nfi.FromString(s) nfi.SetEncoding(wx.FONTENCODING_ISO8859_1) fi.font = wx.FontFromNativeInfo(nfi) # likewise, evil users can set the font name to "z" or # something equally silly, resulting in an # invalid/non-existent font. on wxGTK2 and wxMSW we can # detect this by checking the point size of the font. # wxGTK1 chooses some weird chinese font and I can't find # a way to detect that, but it's irrelevant since we'll # rip out support for it in a few months. if fi.font.GetPointSize() == 0: fi.font = None # if either of the above failures happened, create a dummy # font and use it. this sucks but is preferable to crashing or # displaying an empty screen. if not fi.font: fi.font = wx.Font(10, wx.MODERN, wx.NORMAL, wx.NORMAL, encoding=wx.FONTENCODING_ISO8859_1) setattr(cfgGl, fname, fi.font.GetNativeFontInfo().ToString()) fx, fy = util.getTextExtent(fi.font, "O") fi.fx = max(1, fx) fi.fy = max(1, fy) self.fonts.append(fi)