[Python-checkins] python/dist/src/Lib/lib-tk tkFont.py,1.5,1.6
loewis at users.sourceforge.net
loewis at users.sourceforge.net
Wed Aug 18 13:07:18 CEST 2004
Update of /cvsroot/python/python/dist/src/Lib/lib-tk
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11140/Lib/lib-tk
Modified Files:
tkFont.py
Log Message:
Patch #764217: Add nametofont function, exists parameter.
Index: tkFont.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/lib-tk/tkFont.py,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** tkFont.py 14 Jun 2003 21:40:04 -0000 1.5
--- tkFont.py 18 Aug 2004 11:06:44 -0000 1.6
***************
*** 26,29 ****
--- 26,34 ----
ITALIC = "italic"
+ def nametofont(name):
+ """Given the name of a tk named font, returns a Font representation.
+ """
+ return Font(name=name, exists=True)
+
class Font:
***************
*** 33,38 ****
font -- font specifier (name, system font, or (family, size, style)-tuple)
! or any combination of
family -- font 'family', e.g. Courier, Times, Helvetica
--- 38,47 ----
font -- font specifier (name, system font, or (family, size, style)-tuple)
+ name -- name to use for this font configuration (defaults to a unique name)
+ exists -- does a named font by this name already exist?
+ Creates a new named font if False, points to the existing font if True.
+ Raises _tkinter.TclError if the assertion is false.
! the following are ignored if font is specified:
family -- font 'family', e.g. Courier, Times, Helvetica
***************
*** 42,46 ****
underline -- font underlining: false (0), true (1)
overstrike -- font strikeout: false (0), true (1)
! name -- name to use for this font configuration (defaults to a unique name)
"""
--- 51,55 ----
underline -- font underlining: false (0), true (1)
overstrike -- font strikeout: false (0), true (1)
!
"""
***************
*** 64,68 ****
return options
! def __init__(self, root=None, font=None, name=None, **options):
if not root:
root = Tkinter._default_root
--- 73,77 ----
return options
! def __init__(self, root=None, font=None, name=None, exists=False, **options):
if not root:
root = Tkinter._default_root
***************
*** 75,79 ****
name = "font" + str(id(self))
self.name = name
! root.tk.call("font", "create", name, *font)
# backlinks!
self._root = root
--- 84,101 ----
name = "font" + str(id(self))
self.name = name
!
! if exists:
! self.delete_font = False
! # confirm font exists
! if self.name not in root.tk.call("font", "names"):
! raise Tkinter._tkinter.TclError, "named font %s does not already exist" % (self.name,)
! # if font config info supplied, apply it
! if font:
! print "font=%r" % font
! root.tk.call("font", "configure", self.name, *font)
! else:
! # create new font (raises TclError if the font exists)
! root.tk.call("font", "create", self.name, *font)
! self.delete_font = True
# backlinks!
self._root = root
***************
*** 84,93 ****
return self.name
def __del__(self):
try:
! self._call("font", "delete", self.name)
except (AttributeError, Tkinter.TclError):
pass
!
def copy(self):
"Return a distinct copy of the current font"
--- 106,125 ----
return self.name
+ def __eq__(self, other):
+ return self.name == other.name and isinstance(other, Font)
+
+ def __getitem__(self, key):
+ return self.cget(key)
+
+ def __setitem__(self, key, value):
+ self.configure(**{key: value})
+
def __del__(self):
try:
! if self.delete_font:
! self._call("font", "delete", self.name)
except (AttributeError, Tkinter.TclError):
pass
!
def copy(self):
"Return a distinct copy of the current font"
More information about the Python-checkins
mailing list