|
2 | 2 | # -*- coding:Utf-8 -*- |
3 | 3 | """ |
4 | 4 | MyNotes - Sticky notes/post-it |
5 | | -Copyright 2016-2018 Juliette Monsel <j_4321@protonmail.com> |
| 5 | +Copyright 2016-2019 Juliette Monsel <j_4321@protonmail.com> |
6 | 6 |
|
7 | 7 | MyNotes is free software: you can redistribute it and/or modify |
8 | 8 | it under the terms of the GNU General Public License as published by |
|
20 | 20 |
|
21 | 21 | Configuration Window |
22 | 22 | """ |
23 | | - |
24 | | - |
| 23 | +from time import strftime |
| 24 | +from tkinter import font |
25 | 25 | from tkinter import Toplevel, StringVar, Menu, Text, BooleanVar |
| 26 | +from tkinter.ttk import Label, Radiobutton, Button, Style, Separator, \ |
| 27 | + Notebook, Combobox, Frame, Menubutton, Checkbutton |
| 28 | + |
26 | 29 | from mynoteslib.messagebox import showinfo |
27 | 30 | from mynoteslib.autocomplete import AutoCompleteCombobox |
28 | | -from tkinter.ttk import Label, Radiobutton, Button, Style, Separator |
29 | | -from tkinter.ttk import Notebook, Combobox, Frame, Menubutton, Checkbutton |
30 | | -from mynoteslib.constants import CONFIG, save_config, COLORS, SYMBOLS,\ |
31 | | - LANGUAGES, REV_LANGUAGES, TOOLKITS, AUTOCORRECT |
| 31 | +from mynoteslib.constants import COLORS, SYMBOLS, LANGUAGES, REV_LANGUAGES, \ |
| 32 | + TOOLKITS, AUTOCORRECT, CONFIG, save_config, add_trace |
32 | 33 | from mynoteslib.autoscrollbar import AutoScrollbar |
33 | 34 | from .categories import CategoryManager |
34 | 35 | from .autocorrect import AutoCorrectConfig |
35 | 36 | from .opacity import OpacityFrame |
36 | | -from tkinter import font |
37 | | -from time import strftime |
| 37 | +from .font import FontFrame |
38 | 38 |
|
39 | 39 |
|
40 | 40 | class Config(Toplevel): |
@@ -117,18 +117,7 @@ def __init__(self, master): |
117 | 117 | command=self.ok).grid(row=1, column=0, padx=4, pady=10, sticky="e") |
118 | 118 | Button(okcancel_frame, text=_("Cancel"), |
119 | 119 | command=self.destroy).grid(row=1, column=1, padx=4, pady=10, sticky="w") |
120 | | - # --- bindings |
121 | | - self.font_family.bind('<<ComboboxSelected>>', self.update_preview) |
122 | | - self.font_family.bind('<Return>', self.update_mono_preview) |
123 | | - self.mono_family.bind('<<ComboboxSelected>>', self.update_preview) |
124 | | - self.mono_family.bind('<Return>', self.update_mono_preview) |
125 | | - self.font_size.bind('<<ComboboxSelected>>', self.update_preview, add=True) |
126 | | - self.font_size.bind('<Return>', self.update_preview, add=True) |
127 | | - self.fonttitle_family.bind('<<ComboboxSelected>>', self.update_preview_title) |
128 | | - self.fonttitle_size.bind('<<ComboboxSelected>>', self.update_preview_title, add=True) |
129 | | - self.fonttitle_family.bind('<Return>', self.update_preview_title) |
130 | | - self.fonttitle_size.bind('<Return>', self.update_preview_title, add=True) |
131 | | - |
| 120 | + |
132 | 121 | def _init_general(self): |
133 | 122 | general_settings = Frame(self.notebook, padding=4) |
134 | 123 | general_settings.columnconfigure(0, weight=1) |
@@ -274,111 +263,44 @@ def _init_font(self): |
274 | 263 | sticky="ewsn", padding=4) |
275 | 264 |
|
276 | 265 | # ---- title |
277 | | - fonttitle_frame = Frame(font_settings) |
278 | | - |
279 | 266 | title_size = CONFIG.get("Font", "title_size") |
280 | | - title_family = CONFIG.get("Font", "title_family") |
281 | | - |
282 | | - self.sampletitle = Label(fonttitle_frame, text=_("Sample text"), |
283 | | - anchor="center", |
284 | | - style="prev.TLabel", relief="groove") |
285 | | - |
286 | | - self.sampletitle.grid(row=2, columnspan=2, padx=4, pady=6, |
287 | | - ipadx=4, ipady=4, sticky="eswn") |
288 | | - self.fonts = list(set(font.families())) |
289 | | - self.fonts.append("TkDefaultFont") |
290 | | - self.fonts.sort() |
291 | | - |
292 | | - w = max([len(f) for f in self.fonts]) |
293 | | - self.sizes = ["%i" % i for i in (list(range(6, 17)) + list(range(18, 32, 2)))] |
294 | | - |
295 | | - self.fonttitle_family = AutoCompleteCombobox(fonttitle_frame, values=self.fonts, |
296 | | - width=(w * 2) // 3, |
297 | | - exportselection=False) |
298 | | - self._validate_title_size = self.register(lambda *args: self.validate_font_size(self.fonttitle_size, *args)) |
299 | | - self.fonttitle_family.current(self.fonts.index(title_family)) |
300 | | - self.fonttitle_family.grid(row=0, column=0, padx=4, pady=4) |
301 | | - self.fonttitle_size = Combobox(fonttitle_frame, values=self.sizes, width=5, |
302 | | - exportselection=False, |
303 | | - validate="key", |
304 | | - validatecommand=(self._validate_title_size, "%d", "%P", "%V")) |
305 | | - self.fonttitle_size.current(self.sizes.index(title_size)) |
306 | | - self.fonttitle_size.grid(row=0, column=1, padx=4, pady=4) |
307 | | - |
308 | | - frame_title_style = Frame(fonttitle_frame) |
309 | | - frame_title_style.grid(row=1, columnspan=2, padx=4, pady=6) |
310 | | - self.is_bold = Checkbutton(frame_title_style, text=_("Bold"), |
311 | | - command=self.update_preview_title) |
312 | | - self.is_italic = Checkbutton(frame_title_style, text=_("Italic"), |
313 | | - command=self.update_preview_title) |
314 | | - self.is_underlined = Checkbutton(frame_title_style, text=_("Underline"), |
315 | | - command=self.update_preview_title) |
316 | | - style = CONFIG.get("Font", "title_style") |
317 | | - if "bold" in style: |
318 | | - self.is_bold.state(("selected",)) |
319 | | - if "italic" in style: |
320 | | - self.is_italic.state(("selected",)) |
321 | | - if "underline" in style: |
322 | | - self.is_underlined.state(("selected",)) |
323 | | - self.is_bold.pack(side="left") |
324 | | - self.is_italic.pack(side="left") |
325 | | - self.is_underlined.pack(side="left") |
| 267 | + title_family = CONFIG.get("Font", "title_family").replace(" ", "\ ") |
| 268 | + font_title = '{} {}'.format(title_family, title_size) |
| 269 | + style = CONFIG.get("Font", "title_style").split(",") |
| 270 | + if style: |
| 271 | + font_title = font_title + " " + " ".join(style) |
326 | 272 |
|
| 273 | + self.title_font = FontFrame(font_settings, font_title, style=True) |
327 | 274 | # ---- text |
328 | 275 | size = CONFIG.get("Font", "text_size") |
329 | | - family = CONFIG.get("Font", "text_family") |
| 276 | + family = CONFIG.get("Font", "text_family").replace(" ", "\ ") |
330 | 277 |
|
331 | | - font_frame = Frame(font_settings) |
332 | | - self.sample = Label(font_frame, text=_("Sample text"), anchor="center", |
333 | | - style="prev.TLabel", relief="groove") |
334 | | - self.sample.grid(row=1, columnspan=2, padx=4, pady=6, |
335 | | - ipadx=4, ipady=4, sticky="eswn") |
336 | | - |
337 | | - self.font_family = AutoCompleteCombobox(font_frame, values=self.fonts, |
338 | | - width=(w * 2) // 3, |
339 | | - exportselection=False) |
340 | | - self._validate_size = self.register(lambda *args: self.validate_font_size(self.font_size, *args)) |
341 | | - self.font_family.current(self.fonts.index(family)) |
342 | | - self.font_family.grid(row=0, column=0, padx=4, pady=4) |
343 | | - self.font_size = Combobox(font_frame, values=self.sizes, width=5, |
344 | | - exportselection=False, |
345 | | - validate="key", |
346 | | - validatecommand=(self._validate_size, "%d", "%P", "%V")) |
347 | | - self.font_size.current(self.sizes.index(size)) |
348 | | - self.font_size.grid(row=0, column=1, padx=4, pady=4) |
| 278 | + self.text_font = FontFrame(font_settings, '{} {}'.format(family, size)) |
349 | 279 |
|
350 | 280 | # ---- mono |
351 | | - self.mono_fonts = [f for f in self.fonts if 'Mono' in f] |
352 | | - mono_family = CONFIG.get("Font", "mono") |
353 | | - |
354 | | - mono_frame = Frame(font_settings) |
355 | | - self.sample_mono = Label(mono_frame, text=_("Mono text"), anchor="center", |
356 | | - style="prev.TLabel", relief="groove") |
357 | | - self.sample_mono.grid(row=1, columnspan=2, padx=4, pady=6, |
358 | | - ipadx=4, ipady=4, sticky="eswn") |
| 281 | + mono_fonts = [f for f in set(font.families()) if 'Mono' in f] |
| 282 | + mono_family = CONFIG.get("Font", "mono").replace(" ", "\ ") |
359 | 283 |
|
360 | | - self.mono_family = AutoCompleteCombobox(mono_frame, values=self.mono_fonts, |
361 | | - width=(w * 2) // 3, |
362 | | - exportselection=False) |
363 | | - self.mono_family.current(self.mono_fonts.index(mono_family)) |
364 | | - self.mono_family.grid(row=0, column=0, padx=4, pady=4) |
| 284 | + self.mono_font = FontFrame(font_settings, |
| 285 | + '{} {}'.format(mono_family, size), |
| 286 | + size=False, font_list=mono_fonts) |
| 287 | + add_trace(self.text_font.font_size, 'write', |
| 288 | + lambda *args: self.mono_font._config_size(self.text_font.font_size, self.mono_font.font)) |
365 | 289 |
|
366 | 290 | # ---- placement |
367 | 291 | Label(font_settings, |
368 | 292 | text=_("Title")).grid(row=0, column=0, padx=4, pady=4, sticky="nw") |
369 | | - fonttitle_frame.grid(row=0, column=1, sticky="w", padx=20) |
| 293 | + self.title_font.grid(row=0, column=1, sticky="w", padx=20) |
370 | 294 | Separator(font_settings, orient="horizontal").grid(row=1, columnspan=2, |
371 | 295 | sticky="ew", pady=10) |
372 | 296 | Label(font_settings, |
373 | 297 | text=_("Text")).grid(row=2, column=0, padx=4, pady=4, sticky="nw") |
374 | | - font_frame.grid(row=2, column=1, sticky="w", padx=20) |
| 298 | + self.text_font.grid(row=2, column=1, sticky="w", padx=20) |
375 | 299 | Separator(font_settings, orient="horizontal").grid(row=3, columnspan=2, |
376 | 300 | sticky="ew", pady=10) |
377 | 301 | Label(font_settings, |
378 | 302 | text=_("Mono")).grid(row=4, column=0, padx=4, pady=4, sticky="nw") |
379 | | - mono_frame.grid(row=4, column=1, sticky="w", padx=20) |
380 | | - self.update_preview() |
381 | | - self.update_preview_title() |
| 303 | + self.mono_font.grid(row=4, column=1, sticky="w", padx=20) |
382 | 304 |
|
383 | 305 | def reset_symbols(self): |
384 | 306 | self.symbols.delete('1.0', 'end') |
@@ -415,52 +337,11 @@ def ok(self): |
415 | 337 | splash_supp = not self.splash_support.instate(('selected',)) |
416 | 338 | splash_change = splash_supp != CONFIG.getboolean("General", "splash_supported", fallback=True) |
417 | 339 | # --- font |
418 | | - # mono |
419 | | - mono = self.mono_family.get() |
420 | | - if mono not in self.fonts: |
421 | | - l = [i for i in self.fonts if i[:len(mono)] == mono] |
422 | | - if l: |
423 | | - family = l[0] |
424 | | - else: |
425 | | - family = 'TkDefaultFont' |
426 | | - # text family |
427 | | - family = self.font_family.get() |
428 | | - if family not in self.fonts: |
429 | | - l = [i for i in self.fonts if i[:len(family)] == family] |
430 | | - if l: |
431 | | - family = l[0] |
432 | | - else: |
433 | | - family = 'TkDefaultFont' |
434 | | - # text size |
435 | | - size = self.font_size.get() |
436 | | - try: |
437 | | - int(size) |
438 | | - except ValueError: |
439 | | - size = CONFIG.get("Font", "text_size") |
440 | | - # title family |
441 | | - familytitle = self.fonttitle_family.get() |
442 | | - if familytitle not in self.fonts: |
443 | | - l = [i for i in self.fonts if i[:len(familytitle)] == familytitle] |
444 | | - if l: |
445 | | - familytitle = l[0] |
446 | | - else: |
447 | | - familytitle = 'TkDefaultFont' |
448 | | - # title size |
449 | | - sizetitle = self.fonttitle_size.get() |
450 | | - try: |
451 | | - int(sizetitle) |
452 | | - except ValueError: |
453 | | - sizetitle = CONFIG.get("Font", "title_size") |
454 | | - # title style |
455 | | - style = "" |
456 | | - if self.is_bold.instate(("selected",)): |
457 | | - style += "bold," |
458 | | - if self.is_italic.instate(("selected",)): |
459 | | - style += "italic," |
460 | | - if self.is_underlined.instate(("selected",)): |
461 | | - style += "underline," |
462 | | - if style: |
463 | | - style = style[:-1] |
| 340 | + mono_font = self.mono_font.get_font()['family'] |
| 341 | + text_font = self.text_font.get_font() |
| 342 | + title_font = self.title_font.get_font() |
| 343 | + style = "{weight},{slant}".format(**title_font) |
| 344 | + style = style + ',underline' * title_font['underline'] |
464 | 345 |
|
465 | 346 | # --- opacity |
466 | 347 | opacity = "%i" % self.opacity.get() |
@@ -488,12 +369,12 @@ def ok(self): |
488 | 369 | CONFIG.set("General", "autocorrect", autocorrect) |
489 | 370 | CONFIG.set('General', 'splash_supported', str(splash_supp)) |
490 | 371 |
|
491 | | - CONFIG.set("Font", "text_size", size) |
492 | | - CONFIG.set("Font", "text_family", family) |
493 | | - CONFIG.set("Font", "title_family", familytitle) |
494 | | - CONFIG.set("Font", "title_size", sizetitle) |
| 372 | + CONFIG.set("Font", "text_size", str(text_font['size'])) |
| 373 | + CONFIG.set("Font", "text_family", text_font['family']) |
| 374 | + CONFIG.set("Font", "title_family", title_font['family']) |
| 375 | + CONFIG.set("Font", "title_size", str(title_font['size'])) |
495 | 376 | CONFIG.set("Font", "title_style", style) |
496 | | - CONFIG.set("Font", "mono", mono) |
| 377 | + CONFIG.set("Font", "mono", mono_font) |
497 | 378 |
|
498 | 379 | # --- notes config |
499 | 380 | col_changes = {} |
|
0 commit comments