def GetFont(self, root, configType, section):
        """Retrieve a font from configuration (font, font-size, font-bold)
        Intercept the special value 'TkFixedFont' and substitute
        the actual font, factoring in some tweaks if needed for
        appearance sakes.

        The 'root' parameter can normally be any valid Tkinter widget.

        Return a tuple (family, size, weight) suitable for passing
        to tkinter.Font
        """
        family = self.GetOption(configType, section, 'font', default='courier')
        size = self.GetOption(configType, section, 'font-size', type='int',
                              default='10')
        bold = self.GetOption(configType, section, 'font-bold', default=0,
                              type='bool')
        if (family == 'TkFixedFont'):
            if TkVersion < 8.5:
                family = 'Courier'
            else:
                f = Font(name='TkFixedFont', exists=True, root=root)
                actualFont = Font.actual(f)
                family = actualFont['family']
                size = actualFont['size']
                if size <= 0:
                    size = 10  # if font in pixels, ignore actual size
                bold = actualFont['weight']=='bold'
        return (family, size, 'bold' if bold else 'normal')
Esempio n. 2
0
class TkFont():
    def __init__(self,
                 family="Calibri",
                 weight=NORMAL,
                 slant=ROMAN,
                 overstrike=0,
                 underline=0,
                 size=12):
        '''
        family: 字符集
        size: 字体大小
        weight: "bold" for boldface, "normal" for regular weight.        
        slant: "italic" for italic, "roman" for unslanted.        
        underline: 1 for underlined text, 0 for normal.
        overstrike: 1 for overstruck text, 0 for normal.
        '''
        self.font = Font(family=family,
                         weight=weight,
                         slant=slant,
                         overstrike=overstrike,
                         underline=underline,
                         size=size)

    def get_actual_font_info(self):
        return self.font.actual()

    def config(self, **kw):
        self.font.config(**kw)
    def GetFont(self, root, configType, section):
        """Retrieve a font from configuration (font, font-size, font-bold)
        Intercept the special value 'TkFixedFont' and substitute
        the actual font, factoring in some tweaks if needed for
        appearance sakes.

        The 'root' parameter can normally be any valid Tkinter widget.

        Return a tuple (family, size, weight) suitable for passing
        to tkinter.Font
        """
        family = self.GetOption(configType, section, 'font', default='courier')
        size = self.GetOption(configType, section, 'font-size', type='int',
                              default='10')
        bold = self.GetOption(configType, section, 'font-bold', default=0,
                              type='bool')
        if (family == 'TkFixedFont'):
            if TkVersion < 8.5:
                family = 'Courier'
            else:
                f = Font(name='TkFixedFont', exists=True, root=root)
                actualFont = Font.actual(f)
                family = actualFont['family']
                size = actualFont['size']
                if size < 0:
                    size = 10  # if font in pixels, ignore actual size
                bold = actualFont['weight']=='bold'
        return (family, size, 'bold' if bold else 'normal')
 def findfont(self, faces, sz=11, boldflg=False, italicflg=False):
     for face in faces:
         font = Font(root=self.root,
                     family=face,
                     size=sz,
                     weight='bold' if boldflg else 'normal',
                     slant='italic' if italicflg else 'roman')
         if face == font.actual('family'):
             return font
 def findfont(self, faces, sz=11, boldflg=False, italicflg=False):
     for face in faces:
         font = Font(root=self.root,
                     family=face,
                     size=sz,
                     weight = 'bold' if boldflg else 'normal',
                     slant = 'italic' if italicflg else 'roman')
         if face == font.actual('family'):
             return font
Esempio n. 6
0
class TkFont():
    
    def __init__(self, family = "Calibri", weight = NORMAL, slant = ROMAN, overstrike = 0, underline = 0, size = 12):
        '''
        family: 字符集
        size: 字体大小
        weight: "bold" for boldface, "normal" for regular weight.        
        slant: "italic" for italic, "roman" for unslanted.        
        underline: 1 for underlined text, 0 for normal.
        overstrike: 1 for overstruck text, 0 for normal.
        '''
        self.font = Font(family = family, weight = weight, slant = slant, overstrike = overstrike, underline = underline, size = size)
    
    def get_actual_font_info(self):
        return self.font.actual()
    
    def config(self,**kw):
        self.font.config(**kw)
Esempio n. 7
0
def get_font_name(font):
    # create font name
    # i.e. "helvetica 12" -> ("helvetica", 12, "roman", "normal")
    from tkFont import Font
    font_name = None
    try:
        f = Font(font=font)
    except:
        print_err(_('invalid font name: ') + font)
        if DEBUG:
            traceback.print_exc()
    else:
        fa = f.actual()
        font_name = (fa['family'],
                     fa['size'],
                     fa['slant'],
                     fa['weight'])
    return font_name
Esempio n. 8
0
def get_font_name(font):
    # create font name
    # i.e. "helvetica 12" -> ("helvetica", 12, "roman", "normal")
    from tkFont import Font
    font_name = None
    try:
        f = Font(font=font)
    except:
        print_err(_('invalid font name: ') + font)
        if DEBUG:
            traceback.print_exc()
    else:
        fa = f.actual()
        font_name = (fa['family'],
                     fa['size'],
                     fa['slant'],
                     fa['weight'])
    return font_name
Esempio n. 9
0
import Tkinter
from tkFont import Font

# weight/slant
NORMAL = "normal"
BOLD   = "bold"
ITALIC = "italic"

root = Tkinter.Tk()

def families(root=None):
    "Get font families (as a tuple)"
    if not root:
        root = Tkinter._default_root
    return root.tk.splitlist(root.tk.call("font", "families"))
def names(root=None):
    "Get names of defined fonts (as a tuple)"
    if not root:
        root = Tkinter._default_root
    return root.tk.splitlist(root.tk.call("font", "names"))
# create a font
f = Font(family="times", size=30, weight=NORMAL)
print f.actual()
print f.actual("family")
print f.actual("weight")
print f.config()
print f.cget("family")
print f.cget("weight")
print names()
Esempio n. 10
0
import Tkinter
from tkFont import Font
# weight/slant
NORMAL = "normal"
BOLD = "bold"
ITALIC = "italic"
root = Tkinter.Tk()

def families(root=None):
    "Get font families (as a tuple)"
    if not root:
        root = Tkinter._default_root
    return root.tk.splitlist(root.tk.call("font", "families"))

def names(root=None):
    "Get names of defined fonts (as a tuple)"
    if not root:
        root = Tkinter._default_root
    return root.tk.splitlist(root.tk.call("font", "names"))

# create a font
f = Font(family="times", size=30, weight=NORMAL)
print f.actual()
print f.actual("family")
print f.actual("weight")
print f.config()
print f.cget("family")
print f.cget("weight")
print names()
print f.measure("hello"), f.metrics("linespace")