| 66 | return options |
| 67 | |
| 68 | def __init__(self, root=None, font=None, name=None, exists=False, |
| 69 | **options): |
| 70 | if root is None: |
| 71 | root = tkinter._get_default_root('use font') |
| 72 | tk = getattr(root, 'tk', root) |
| 73 | if font: |
| 74 | # get actual settings corresponding to the given font |
| 75 | font = tk.splitlist(tk.call("font", "actual", font)) |
| 76 | else: |
| 77 | font = self._set(options) |
| 78 | if not name: |
| 79 | name = "font" + str(next(self.counter)) |
| 80 | self.name = name |
| 81 | |
| 82 | if exists: |
| 83 | self.delete_font = False |
| 84 | # confirm font exists |
| 85 | if self.name not in tk.splitlist(tk.call("font", "names")): |
| 86 | raise tkinter._tkinter.TclError( |
| 87 | "named font %s does not already exist" % (self.name,)) |
| 88 | # if font config info supplied, apply it |
| 89 | if font: |
| 90 | tk.call("font", "configure", self.name, *font) |
| 91 | else: |
| 92 | # create new font (raises TclError if the font exists) |
| 93 | tk.call("font", "create", self.name, *font) |
| 94 | self.delete_font = True |
| 95 | self._tk = tk |
| 96 | self._split = tk.splitlist |
| 97 | self._call = tk.call |
| 98 | |
| 99 | def __str__(self): |
| 100 | return self.name |