def on_button_choose_font(self, event): # wxGlade: TextProperty.<event_handler> font_data = wx.FontData() try: font_data.SetInitialFont(self.node.wxfont) font_data.SetColour(wx.Colour(swizzlecolor(self.node.fill))) dialog = wx.FontDialog(None, font_data) except AttributeError: dialog = wx.FontDialog(None, font_data) if dialog.ShowModal() == wx.ID_OK: data = dialog.GetFontData() font = data.GetChosenFont() try: color = data.GetColour() rgb = color.GetRGB() color = swizzlecolor(rgb) color = Color(color, 1.0) self.node.fill = color # Translate wxFont to SVG font.... self.node.wxfont = font wxfont_to_svg(self.node) self.node.modified() except AttributeError: # rgb get failed. pass self.update_label() self.refresh() dialog.Destroy() event.Skip()
def Control(self, event): menuname = xit_G.G_myOP._menudict[event.GetId()].GetName() if menuname == "新建(N)": xit_G.G_myOP.initMatrixUnit(3, 3) elif menuname == "打开...": MyFileOP().opendefault() elif menuname == "合并打开...": MyFileOP().openunion() elif menuname == "保存": MyFileOP().savedefault() elif menuname == "另存为...": MyFileOP().saveas() elif menuname == self._string + "字体设置...": data = wx.FontData() data.EnableEffects(True) win = None if self._string == "前置字符串": win = xit_G.G_myOP._notebook._pageList[1]._preText data.SetColour(xit_G.G_fontandcolour._precolour) data.SetInitialFont(xit_G.G_fontandcolour._prefont) dlg = wx.FontDialog(win, data) if dlg.ShowModal() == wx.ID_OK: data = dlg.GetFontData() font = data.GetChosenFont() colour = data.GetColour() win.SetFont(font) win.SetForegroundColour(colour) xit_G.G_fontandcolour._prefont = font xit_G.G_fontandcolour._precolour = colour elif self._string == "后置字符串": win = xit_G.G_myOP._notebook._pageList[1]._postText data.SetColour(xit_G.G_fontandcolour._postcolour) data.SetInitialFont(xit_G.G_fontandcolour._postfont) dlg = wx.FontDialog(win, data) if dlg.ShowModal() == wx.ID_OK: data = dlg.GetFontData() font = data.GetChosenFont() colour = data.GetColour() win.SetFont(font) win.SetForegroundColour(colour) xit_G.G_fontandcolour._postfont = font xit_G.G_fontandcolour._postcolour = colour elif self._string == "矩阵": win = xit_G.G_myOP._notebook._pageList[1]._myxitmatrixText data.SetColour(xit_G.G_fontandcolour._middlecolour) data.SetInitialFont(xit_G.G_fontandcolour._middlefont) dlg = wx.FontDialog(win, data) if dlg.ShowModal() == wx.ID_OK: data = dlg.GetFontData() font = data.GetChosenFont() colour = data.GetColour() win.SetFont(font) win.SetForegroundColour(colour) xit_G.G_fontandcolour._middlefont = font xit_G.G_fontandcolour._middlecolour = colour print("ok!")
def format_font(self, event): font_attr, color_attr = 'font', 'color' if event.GetId() == self.TITLE_FONT: texts = [self.client.title] elif event.GetId() == self.AXIS_FONT: texts = [self.client.x_title, self.client.y_title] #texts = [self.client.y_title] elif event.GetId() == self.LABEL_FONT: texts = [self.client.x_axis, self.client.y_axis] font_attr, color_attr = 'label_font', 'label_color' data = wx.FontData() current_color = get_color(getattr(texts[0], color_attr)) current_font = getattr(texts[0], font_attr) data.SetColour(current_color) data.SetInitialFont(current_font) dlg = wx.FontDialog(self, data) if dlg.ShowModal() == wx.ID_OK: data = dlg.GetFontData() font = data.GetChosenFont() color = data.GetColour() rgb = color.Red(), color.Green(), color.Blue() for text in texts: setattr(text, color_attr, rgb) setattr(text, font_attr, font) self.client.update() dlg.Destroy()
def OnSelectFont(self, evt): """ Запускает стандартное диалоговое окно для выбора шрифта. """ data = wx.FontData() data.EnableEffects(True) curFont = icFont(self.GetValue()) data.SetInitialFont(curFont) dlg = wx.FontDialog(self.nameValue.main, data) if dlg.ShowModal() == wx.ID_OK: data = dlg.GetFontData() font = data.GetChosenFont() self.nameValue.value['size'] = font.GetPointSize() self.nameValue.value['family'] = getICFamily(font) self.nameValue.value['style'] = getICFontStyle(font) self.nameValue.value['faceName'] = font.GetFaceName() self.nameValue.value['underline'] = font.GetUnderlined() self.nameValue.oldValue = self.nameValue.value self.nameValue.value_ctrl.SetLabel(self.nameValue.GetStr()) self.nameValue.edit_ctrl.SetValue(self.nameValue.GetStr()) self.nameValue.edit_ctrl.SetFocus() dlg.Destroy()
def OnSetFont(self, event): try: cur_size = int(self.config.Read('font size')) except: cur_size = 12 font = wx.Font(pointSize=cur_size, family=wx.FONTFAMILY_UNKNOWN, style=wx.FONTSTYLE_NORMAL, weight=wx.FONTWEIGHT_NORMAL, face=self.config.Read('font')) data = wx.FontData() data.EnableEffects(True) data.SetInitialFont(font) data.SetColour(self.config.Read('font color')) dlg = wx.FontDialog(self, data) if dlg.ShowModal() == wx.ID_OK: data = dlg.GetFontData() font_ = data.GetChosenFont() font = font_.GetFaceName() size = font_.GetPointSize() color_ = data.GetColour() color = color_.GetAsString(wx.C2S_HTML_SYNTAX) logging.debug('You selected: "%s", %d points, color %s\n' % (font, size, color)) self.config.Write("font", font) self.config.Write("font size", str(size)) self.config.Write("font color", color) self.config.Flush() self.Parent.ApplyStyle() dlg.Destroy()
def OnFontChange(self, event): # wxGlade: cNFODialog.<event_handler> data = wx.FontData() data.EnableEffects(False) data.SetInitialFont( wx.Font(Config.Config["NFO_Zoom"], Config.Config["NFO_Family"], Config.Config["NFO_Style"], Config.Config["NFO_Weight"], False, Config.Config["NFO_Face"], wx.FONTENCODING_CP437)) dlg = wx.FontDialog(self, data) if dlg.ShowModal() == wx.ID_OK: data = dlg.GetFontData() font = data.GetChosenFont() Config.Config["NFO_Zoom"] = font.GetPointSize() Config.Config["NFO_Family"] = font.GetFamily( ) #wx.FONTFAMILY_SWISS Config.Config["NFO_Style"] = font.GetStyle() Config.Config["NFO_Weight"] = font.GetWeight() Config.Config["NFO_Face"] = font.GetFaceName() font = wx.Font(Config.Config["NFO_Zoom"], Config.Config["NFO_Family"], Config.Config["NFO_Style"], Config.Config["NFO_Weight"], False, Config.Config["NFO_Face"], wx.FONTENCODING_CP437) self.NFO_Text.SetFont(font) self.Zoom_Size_Text.SetLabel(" Zoom Size : %d" % Config.Config["NFO_Zoom"]) # end of class cNFODialog
def OnSelectFont(self, evt): id = evt.GetId() if id == self.ide[15]: font = self.parent.tickMarkHoursFont font.SetPointSize(self.parent.markSizeHour) colour = self.parent.tickMarkHoursPen.GetColour() else: font = self.parent.tickMarkMinutesFont font.SetPointSize(self.parent.markSizeMin) colour = self.parent.tickMarkMinutesPen.GetColour() data = wx.FontData() data.EnableEffects(True) data.SetColour(colour) data.SetInitialFont(font) dlg = wx.FontDialog(self, data) if dlg.ShowModal() == wx.ID_OK: data = dlg.GetFontData() font = data.GetChosenFont() colour = data.GetColour() if id == self.ide[15]: self.parent.SetTickFonts(h=font) self.parent.SetTickColours(h=colour.Get()) else: self.parent.SetTickFonts(m=font) self.parent.SetTickColours(m=colour.Get()) dlg.Destroy() self.UpdateAll()
def font(self, event): default_font = wx.Font(12, wx.SWISS, wx.NORMAL, wx.NORMAL, False, "Calibri") data = wx.FontData() if sys.platform == 'win32': data.EnableEffects(True) data.SetInitialFont(default_font) dlg = wx.FontDialog(self, data) if dlg.ShowModal() == wx.ID_OK: data = dlg.GetFontData() font = data.GetChosenFont() self.rtc.BeginFont(font) self.rtc.BeginFontSize(font.GetPointSize()) colour = data.GetColour() if self.rtc.HasSelection( ): # If there is a selection, then change the selected text's font selection = self.rtc.GetSelectionRange() atr = TextAttrEx() atr.SetTextColour(colour) atr.SetFontFaceName(str(font)) self.rtc.SetStyle(selection, atr) else: # If not then start new text self.rtc.BeginTextColour(colour) text = 'Face: %s, Size: %d, Colour: %s' % ( font.GetFaceName(), font.GetPointSize(), colour.Get()) self.SetStatusText(text) dlg.Destroy()
def selectFont(self, e): data = wx.FontData() data.SetInitialFont(self.infos["font"]) #data.SetColour(canvasTextColour) dialog = wx.FontDialog(None, data) if dialog.ShowModal() == wx.ID_OK: data = dialog.GetFontData() font = data.GetChosenFont() colour = data.GetColour() self.infos['fontfamily'] = font.GetFaceName() self.infos['fontsize'] = font.GetPointSize() # weight weight = font.GetWeightString() if weight == "wxFONTWEIGHT_BOLD": self.infos['fontweight'] = cairo.FONT_WEIGHT_BOLD else: self.infos['fontweight'] = cairo.FONT_WEIGHT_NORMAL # style style = font.GetStyleString() if style == "wxFONTSTYLE_ITALIC": self.infos['fontstyle'] = cairo.FONT_SLANT_ITALIC else: self.infos['fontstyle'] = cairo.FONT_SLANT_NORMAL self.infos['font'] = font print self.infos, style self.updateGUI()
def OnDialogs(self, event): evId = event.GetId() if evId == 101: # wx.ColourDialog data = wx.ColourData() dlg = wx.ColourDialog(self, data) dlg.SetName("ColourDialog1") elif evId == 102: # wx.FontDialog data = wx.FontData() dlg = wx.FontDialog(self, data) dlg.SetName("FontDialog1") elif evId == 103: # wx.TextEntryDialog dlg = wx.TextEntryDialog( self, 'What is your favorite programming language?', 'Eh??', 'Python') dlg.SetValue("Python is the best!") dlg.SetName("TextEntryDialog1") self._persistMgr.RegisterAndRestore(dlg) if dlg.ShowModal() == wx.ID_OK: self._persistMgr.Save(dlg) self._persistMgr.Unregister(dlg) dlg.Destroy()
def on_select_font(self, event): """Open a dialog to choose a font, then fix it. :param event: (wx.Event) """ button = event.GetEventObject() data = wx.FontData() data.EnableEffects(True) data.SetColour(wx.GetApp().settings.fg_color) data.SetInitialFont(wx.GetApp().settings.text_font) dlg = wx.FontDialog(self, data) if dlg.ShowModal() == wx.ID_OK: data = dlg.GetFontData() font = data.GetChosenFont() if "content" in button.GetParent().GetName(): wx.GetApp().settings.set('text_font', font) elif "header" in button.GetParent().GetName(): wx.GetApp().settings.set('header_text_font', font) elif "action" in button.GetParent().GetName(): wx.GetApp().settings.set('action_text_font', font) dlg.Destroy()
def Select_font(self, e): dlg = wx.FontDialog(self) res = dlg.ShowModal() if res == wx.ID_OK: font = dlg.GetFontData().GetChosenFont() # wx.Font print(font.GetFaceName())
def OnFont(self, evt): """字体设置事件处理""" # 取得当前字体 curFont = self.tc.GetFont() # 设置字体数据 fontData = wx.FontData() fontData.SetInitialFont(curFont) # 创建字体选择对话框 dlg = wx.FontDialog(self, fontData) if dlg.ShowModal() == wx.ID_OK: # 取得选中的字体 data = dlg.GetFontData() font = data.GetChosenFont() # 将字体应用到文本框 self.tc.SetFont(font) # 取得颜色设置 colour = data.GetColour() # 将颜色应用于文本框 self.tc.SetForegroundColour(colour)
def onSelectFont(self, evt): btnLabel = self.btnFontPicker.GetLabel() fgColor = self.btnFontPicker.GetForegroundColour() fname = (btnLabel.split(',')[0]).strip() pntSize = btnLabel.split(',')[1] data = wx.FontData() f = wx.Font(pointSize=int(pntSize), family=wx.FONTFAMILY_DEFAULT, style=wx.FONTSTYLE_NORMAL, weight=wx.FONTWEIGHT_NORMAL, underline=False, faceName=fname, encoding=wx.FONTENCODING_DEFAULT) data.SetInitialFont(f) data.SetColour(fgColor) dialog = wx.FontDialog(self, data) if dialog.ShowModal() == wx.ID_OK: retData = dialog.GetFontData() font = retData.GetChosenFont() color = retData.GetColour() self.btnFontPicker.SetLabel(font.GetFaceName() + ',' + str(font.GetPointSize())) self.btnFontPicker.SetForegroundColour(color)
def fontDialog(parent=None, fontData=None, font=None): if fontData is None: fontData = wx.FontData() fontData.SetColour(wx.BLACK) fontData.SetInitialFont( wx.SystemSettings.GetFont(wx.SYS_DEFAULT_GUI_FONT)) if font is not None: fontData.SetInitialFont(font) dialog = wx.FontDialog(parent, fontData) result = DialogResults(dialog.ShowModal()) if result.accepted: fontData = dialog.GetFontData() result.fontData = fontData result.color = fontData.GetColour().Get() result.colour = result.color result.font = fontData.GetChosenFont() else: result.color = None result.colour = None result.font = None dialog.Destroy() return result
def FontEdtDlg(parent, value): """ Диалоговое окно для определения шрифта. @type parent: C{wx.Window} @param parent: Указатель на родительское окно. @type value: C{string} @param value: Текущее значение шрифта в виде словаря. """ data = wx.FontData() data.EnableEffects(True) if value: fnt = eval(value) else: fnt = {} curFont = icfont.icFont(fnt) data.SetInitialFont(curFont) dlg = wx.FontDialog(parent, data) if dlg.ShowModal() == wx.ID_OK: data = dlg.GetFontData() font = data.GetChosenFont() fnt = {} fnt['size'] = font.GetPointSize() fnt['family'] = icfont.getICFamily(font) fnt['style'] = icfont.getICFontStyle(font) fnt['faceName'] = font.GetFaceName() fnt['underline'] = font.GetUnderlined() dlg.Destroy() return str(fnt)
def OnFont(self, evt): if not self.rtc.HasSelection(): return r = self.rtc.GetSelectionRange() fontData = wx.FontData() fontData.EnableEffects(False) attr = rt.TextAttrEx() attr.SetFlags(rt.TEXT_ATTR_FONT) if self.rtc.GetStyle(self.rtc.GetInsertionPoint(), attr): fontData.SetInitialFont(attr.GetFont()) dlg = wx.FontDialog(self, fontData) if dlg.ShowModal() == wx.ID_OK: fontData = dlg.GetFontData() font = fontData.GetChosenFont() if font: attr.SetFlags(rt.TEXT_ATTR_FONT) attr.SetFont(font) if r[0] < 0 and r[1] < 0: self.styleChangeMode = 'paragraph' i = self.rtc.GetInsertionPoint() self.rtc.SetStyle((i, i + 1), attr) else: self.rtc.SetStyle(r, attr) dlg.Destroy()
def OnFont(self, evt): if not self.ctrl_texte.HasSelection(): dlg = wx.MessageDialog( self, _(u"Vous devez d'abord sélectionner un texte."), _(u"Police"), wx.OK | wx.ICON_INFORMATION) dlg.ShowModal() dlg.Destroy() return r = self.ctrl_texte.GetSelectionRange() fontData = wx.FontData() fontData.EnableEffects(False) attr = rt.RichTextAttr() attr.SetFlags(wx.TEXT_ATTR_FONT) if self.ctrl_texte.GetStyle(self.ctrl_texte.GetInsertionPoint(), attr): fontData.SetInitialFont(attr.GetFont()) dlg = wx.FontDialog(self, fontData) if dlg.ShowModal() == wx.ID_OK: fontData = dlg.GetFontData() font = fontData.GetChosenFont() if font: attr.SetFlags(wx.TEXT_ATTR_FONT) attr.SetFont(font) self.ctrl_texte.SetStyle(r, attr) dlg.Destroy()
def OnChooseFontButton(self, event): try: font, size = self.parent.get('Font').split(',') font = font.strip() size = eval(size.strip()) except: font = 'Courier' size = 10 data = wx.FontData() data.EnableEffects(False) data.SetInitialFont( wx.Font( pointSize=size, family=wx.FONTFAMILY_MODERN, style=wx.FONTSTYLE_NORMAL, weight=wx.FONTWEIGHT_NORMAL, face=font, )) dlg = wx.FontDialog(self, data) if dlg.ShowModal() == wx.ID_OK: data = dlg.GetFontData() font = data.GetChosenFont() self.parent.set( 'Font', '%s, %s' % (font.GetFaceName(), font.GetPointSize())) dlg.Destroy()
def choose_specific_font(self, event): data = wx.FontData() try: family = self.font_families_to[self.value[1]] style = self.font_styles_to[self.value[2]] weight = self.font_weights_to[self.value[3]] font = wx.Font(self.value[0], family, style, weight, self.value[4], self.value[5]) data.SetInitialFont(font) except AttributeError: pass dialog = wx.FontDialog(self, data) res = dialog.ShowModal() font = dialog.GetFontData().GetChosenFont() dialog.Destroy() if res != wx.ID_OK: return family = font.GetFamily() #for f in (wx.VARIABLE, wx.FIXED): # if family & f: family = family ^ f self.value = (font.GetPointSize(), self.font_families_from[family], self.font_styles_from[font.GetStyle()], self.font_weights_from[font.GetWeight()], font.GetUnderlined() and 1 or 0, font.GetFaceName()) self.EndModal(wx.ID_OK)
def onClick(self, event): event.Skip(False) dialog = wx.FontDialog(self, self.__newFontData()) if wx.ID_OK == dialog.ShowModal(): self.__readFontData(dialog.GetFontData()) self.__updateButton() self.__sendPickerEvent()
def OnChangeTickFont(self, evt): fd = wx.FontData() fd.EnableEffects(False) fd.SetInitialFont(self.ticker.GetFont()) dlg = wx.FontDialog(wx.GetTopLevelParent(self), fd) if dlg.ShowModal() == wx.ID_OK: data = dlg.GetFontData() self.SetTickFont(data.GetChosenFont())
def on_font_format_menu(self, event): active_child = self.get_active_child() if active_child is not None: dlg = wx.FontDialog(self, active_child.font_data) if dlg.ShowModal() == wx.ID_OK: font = dlg.GetFontData().GetChosenFont() active_child.font_data.SetInitialFont(font) active_child.m_text_editor.BeginFont(font)
def ClickOnFont(self, evt): dlg = wx.FontDialog(self, wx.FontData()) if dlg.ShowModal() == wx.ID_OK: data = dlg.GetFontData() #font = data.GetChosenFont() #colour = data.GetColour() self.SetFont(data.GetChosenFont()) dlg.Destroy()
def test_fontdlg1(self): data = wx.FontData() data.SetInitialFont(wx.FFont(15, wx.FONTFAMILY_TELETYPE)) self.assertEqual(data.InitialFont.Family, wx.FONTFAMILY_TELETYPE) dlg = wx.FontDialog(self.frame, data) # TODO: find a safe way to test ShowModal on native dialogs dlg.Destroy()
def onChangeFont(self, event): """ Change the panel text font.""" dlg = wx.FontDialog(self,wx.FontData()) if dlg.ShowModal() == wx.ID_OK: data = dlg.GetFontData() font = data.GetChosenFont() gv.iChartPanel0.textFont = font gv.iChartPanel1.textFont = font dlg.Destroy()
def on_font(self, e): with wx.FontDialog(self, wx.FontData()) as dlg: if dlg.ShowModal() == wx.ID_CANCEL: return data = dlg.GetFontData() Font = data.GetChosenFont() print(Font) self.textctrl.SetFont(Font)
def GetFont(self, event): print "here?" dlg = wx.FontDialog(self, self.fontObj) if dlg.ShowModal() == wx.ID_OK: font = dlg.GetFontData() self.font = font.GetChosenFont() fontstring = "%s - %s points"%(font.GetChosenFont().GetFaceName(), \ font.GetChosenFont().GetPointSize()) self.font_display.SetLabel(fontstring)
def on_menu_selection_select_font(self, event) -> None: font_data = wx.FontData() font_data.SetInitialFont(self.m_rich_text_code.GetFont()) dialog = wx.FontDialog(None, font_data) if dialog.ShowModal() == wx.ID_OK: font = dialog.GetFontData().GetChosenFont() self.set_font(font)
def on_button_bold(self, event): # wxGlade: TextProperty.<event_handler> dialog = wx.FontDialog(None, wx.FontData()) if dialog.ShowModal() == wx.ID_OK: data = dialog.GetFontData() font = data.GetChosenFont() color = data.GetColour() print(color) print('"%s", %d pt\n' % (font.GetFaceName(), font.GetPointSize())) dialog.Destroy()