def showFonts(self, event=None): """Open a tab in the log pane showing a font picker.""" c = self.c p = c.p picker = QtWidgets.QFontDialog() if p.h.startswith('@font'): (name, family, weight, slant, size) = leoConfig.parseFont(p.b) else: name, family, weight, slant, size = None, None, False, False, 12 try: font = QtGui.QFont() if family: font.setFamily(family) font.setBold(weight) font.setItalic(slant) font.setPointSize(size) picker.setCurrentFont(font) except ValueError: pass if not picker.exec_(): g.es("No font selected") else: font = picker.selectedFont() udata = c.undoer.beforeChangeNodeContents(p) comments = [x for x in g.splitLines(p.b) if x.strip().startswith('#')] defs = [ '\n' if comments else '', '%s_family = %s\n' % (name, font.family()), '%s_weight = %s\n' % (name, 'bold' if font.bold() else 'normal'), '%s_slant = %s\n' % (name, 'italic' if font.italic() else 'roman'), '%s_size = %s\n' % (name, font.pointSizeF()) ] p.b = ''.join(comments + defs) c.undoer.afterChangeNodeContents(p, 'change-font', udata)
def showFonts(self, event=None): '''Open a tab in the log pane showing a font picker.''' c = self.c; p = c.p picker = QtWidgets.QFontDialog() if p.h.startswith('@font'): (name, family, weight, slant, size) = leoConfig.parseFont(p.b) else: name, family, weight, slant, size = None, None, False, False, 12 try: font = QtGui.QFont() if family: font.setFamily(family) font.setBold(weight) font.setItalic(slant) font.setPointSize(size) picker.setCurrentFont(font) except ValueError: pass if not picker.exec_(): g.es("No font selected") else: font = picker.selectedFont() udata = c.undoer.beforeChangeNodeContents(p) comments = [x for x in g.splitLines(p.b) if x.strip().startswith('#')] defs = [ '\n' if comments else '', '%s_family = %s\n'%(name, font.family()), '%s_weight = %s\n'%(name, 'bold' if font.bold() else 'normal'), '%s_slant = %s\n'%(name, 'italic' if font.italic() else 'roman'), '%s_size = %s\n'%(name, font.pointSizeF()) ] p.b = g.u('').join(comments + defs) c.undoer.afterChangeNodeContents(p, 'change-font', udata)