|
21 | 21 | _FILE_DIR = os.path.abspath(__file__) |
22 | 22 |
|
23 | 23 |
|
24 | | -def _tk_dict_to_dict(d): |
25 | | - """Build a dictionary from a Tcl dictionary by parsing its str repr""" |
26 | | - # type: (tk._tkinter.Tcl_Obj) -> Dict[str, str] |
27 | | - string = str(d) # Every Tcl_Obj supports conversion to string |
28 | | - elements = string.split(" ") |
29 | | - results, key, brackets, total = dict(), None, False, str() |
30 | | - for e in elements: |
31 | | - if key is None: # New dictionary key |
32 | | - key = e |
33 | | - elif brackets is True: # Brackets were opened |
34 | | - if e.endswith("}"): # Closing brackets |
35 | | - brackets = False |
36 | | - results[key] = total + " " + e[:-1] |
37 | | - key, total = None, str() |
38 | | - else: # Still within brackets |
39 | | - total += " " + e |
40 | | - elif e.startswith("{"): # Open Brackets |
41 | | - brackets = True |
42 | | - total = e[1:] |
43 | | - else: # No brackets, just a simple value |
44 | | - results[key] = e |
45 | | - key = None |
46 | | - return results |
47 | | - |
48 | | - |
49 | 24 | @contextmanager |
50 | 25 | def chdir(target): |
51 | 26 | # type: (str) -> None |
@@ -102,7 +77,14 @@ def loaded_fonts(self) -> List[str]: |
102 | 77 |
|
103 | 78 | def font_info(self, fname: str) -> List[Dict[str, str]]: |
104 | 79 | """Return info of a font file""" |
105 | | - return list(map(_tk_dict_to_dict, self._tk.call("extrafont::nameinfo", fname))) |
| 80 | + tk_result_list = self._tk.splitlist( |
| 81 | + self._tk.call("extrafont::nameinfo", fname)[0] |
| 82 | + ) |
| 83 | + font_info_dict = {} |
| 84 | + |
| 85 | + for key, value in zip(tk_result_list[0::2], tk_result_list[1::2]): |
| 86 | + font_info_dict[key] = str(value) |
| 87 | + return font_info_dict |
106 | 88 |
|
107 | 89 | def is_font_available(self, font_name) -> bool: |
108 | 90 | """Return a boolean whether a font is available""" |
|
0 commit comments