Skip to content

xpuz.pages ¤

BrowserPage ¤

BrowserPage(master: Base)

Bases: CTkFrame, Addons

Provides an interface to view available crosswords, set a preference for the word count, generate a crossword based on the selected parameters, and launch the crossword webapp to complete the generated crossword.

Source code in src/xpuz/pages/browser.py
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
def __init__(self, master: Base) -> None:
    super().__init__(
        Base.base_container,
        fg_color=(Colour.Light.MAIN, Colour.Dark.MAIN),
    )
    self.master = master
    self.master._set_dim()
    self._set_fonts()
    self._width, self._height = (
        self.master.winfo_width(),
        self.master.winfo_height(),
    )

    self.grid_rowconfigure(0, minsize=self._height * 0.15, weight=1)
    self.grid_rowconfigure(1, minsize=self._height * 0.85, weight=1)
    self.grid_columnconfigure(0, weight=1)

    if (
        not CrosswordWrapper.helper
    ):  # Set the CrosswordWrapper helper method
        CrosswordWrapper.helper = GUIHelper

    self.launch_options_on: bool = False
    self.webapp_on: bool = False

    self.wc_pref: IntVar = IntVar()  # Word count preference
    self.wc_pref.set(-1)

    self.browser_views = [_("Categorised"), _("Flattened")]
    self.browser_view_pref: StringVar = (
        StringVar()
    )  # Browser view preference
    self.browser_view_pref.set(_(Base.cfg.get("m", "browser_view")))

    self.app_views = [_("Browser"), _("Embedded")]
    self.app_view_pref: StringVar = StringVar()  # App view preference
    self.app_view_pref.set(_(Base.cfg.get("m", "app_view")))

    self.exports = [_("PDF"), _("ipuz")]
    self.export_pref: StringVar = StringVar()  # Export preference
    self.export_pref.set(_(Base.cfg.get("m", "export")))

    self.webview = None  # Store webview instance
    self.webview_open: bool = False

    # Notify user the first time they open this page
    if Base.cfg.get("misc", "browser_opened") == "0":
        GUIHelper.show_messagebox(first_time_browser=True)
        _update_cfg(Base.cfg, "misc", "browser_opened", "1")

_configure_word_count_prefs ¤

_configure_word_count_prefs(state: str) -> None

Configure all the word_count preference widgets to an either an interactive or disabled state (interactive when selecting a crossword, disabled when a crossword has been loaded).

Source code in src/xpuz/pages/browser.py
524
525
526
527
528
529
530
531
532
def _configure_word_count_prefs(self, state: str) -> None:
    """Configure all the word_count preference widgets to an either an
    interactive or disabled state (interactive when selecting a crossword,
    disabled when a crossword has been loaded).
    """
    self.l_wc_prefs.configure(state=state)
    self.rb_max_wc.configure(state=state)
    self.rb_custom_wc.configure(state=state)
    self.opts_custom_wc.configure(state=state)

_handle_scroll ¤

_handle_scroll(
    event: Event, container: CTkScrollableFrame
) -> None

Scroll the center scroll frame only if the viewable width is greater than the scroll region. This prevents weird scroll behaviour in cases where the above condition is inverted.

Source code in src/xpuz/pages/browser.py
464
465
466
467
468
469
470
471
472
473
474
475
def _handle_scroll(
    self, event: Event, container: CTkScrollableFrame
) -> None:
    """Scroll the center scroll frame only if the viewable width is greater
    than the scroll region. This prevents weird scroll behaviour in cases
    where the above condition is inverted.
    """
    scroll_region = container._parent_canvas.cget("scrollregion")
    viewable_width = container._parent_canvas.winfo_width()
    if scroll_region and int(scroll_region.split(" ")[2]) > viewable_width:
        # -1 * event.delta emulates a "natural" scrolling motion
        container._parent_canvas.xview("scroll", -1 * event.delta, "units")

_load ¤

_load() -> None

Gather data and use _create_app to initialise the Flask app on a new thread.

Source code in src/xpuz/pages/browser.py
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
def _load(self) -> None:
    """Gather data and use ``_create_app`` to initialise the Flask app on a
    new thread.
    """
    (
        self.starting_word_positions,
        self.starting_word_matrix,
        self.definitions_a,
        self.definitions_d,
    ) = _interpret_cword_data(self.cwrapper.crossword)
    colour_palette: Dict[str, str] = _get_colour_palette(
        get_appearance_mode()
    )
    _create_app(
        locale=Base.locale,
        scaling=self.master._get_widget_scaling(),
        colour_palette=colour_palette,
        json_colour_palette=dumps(colour_palette),
        port=Base.cfg.get("misc", "webapp_port"),
        name=self.cwrapper.translated_name,
        category=self.cwrapper.category,
        difficulty=self.cwrapper.difficulty,
        empty=EMPTY,
        directions=[ACROSS, DOWN],
        # Tuples in intersections must be removed. Changing this in
        # ``crossword.py`` was annoying, so it is done here instead.
        intersections=[
            list(item) if isinstance(item, tuple) else item
            for sublist in self.cwrapper.crossword.intersections
            for item in sublist
        ],
        word_count=self.cwrapper.word_count,
        failed_insertions=self.cwrapper.crossword.fails,
        dimensions=self.cwrapper.crossword.dimensions,
        starting_word_positions=self.starting_word_positions,
        starting_word_matrix=self.starting_word_matrix,
        grid=self.cwrapper.crossword.grid,
        definitions_a=self.definitions_a,
        definitions_d=self.definitions_d,
        js_err_msgs=[
            _("To perform this operation, you must first select a cell.")
        ],
        uuid=str(uuid4()),
    )

_on_cword_selection ¤

_on_cword_selection(wrapper: CrosswordWrapper) -> None

Called by an instance of CrosswordBlock, which passes the data for its given crossword into this method. The method then saves this data, deselects any previous word count radiobutton selections, reconfigures the values of the custom word count optionmenu to be compatible with the newly selected crossword, and reconfigures the max word count label to show the correct maximum word count.

Source code in src/xpuz/pages/browser.py
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
def _on_cword_selection(self, wrapper: CrosswordWrapper) -> None:
    """Called by an instance of ``CrosswordBlock``, which passes the
    data for its given crossword into this method. The method then saves
    this data, deselects any previous word count radiobutton selections,
    reconfigures the values of the custom word count optionmenu to be
    compatible with the newly selected crossword, and reconfigures the
    max word count label to show the correct maximum word count.
    """
    if not self.launch_options_on:
        self._configure_word_count_prefs("normal")
        self.launch_options_on: bool = True

    self.b_load_cword.configure(state="disabled")
    self.opts_custom_wc.configure(state="disabled")
    self.wc_pref.set(-1)
    self.opts_custom_wc.set(_("Select word count"))

    self.cwrapper = wrapper

    self.opts_custom_wc.configure(
        values=[
            str(numbers.format_decimal(num, locale=Base.locale))
            for num in range(3, self.cwrapper.total_definitions + 1)
        ]
    )
    self.rb_max_wc.configure(
        text=f"{_('Maximum')}: "
        f"{numbers.format_decimal(self.cwrapper.total_definitions, locale=Base.locale)}"
    )
    self.rb_max_wc.invoke()

_on_wc_sel ¤

_on_wc_sel(button_name: str) -> None

Configure custom word count optionmenu based on radiobutton selection.

Source code in src/xpuz/pages/browser.py
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
def _on_wc_sel(self, button_name: str) -> None:
    """Configure custom word count optionmenu based on radiobutton selection."""
    if button_name == "max":
        self.cwrapper.set_word_count(self.cwrapper.total_definitions)

        self.opts_custom_wc.set(_("Select word count"))
        self.opts_custom_wc.configure(state="disabled")

    else:
        self.cwrapper.set_word_count(3)

        self.opts_custom_wc.set(
            f"{str(numbers.format_decimal(3, locale=Base.locale))}"
        )
        self.opts_custom_wc.configure(state="normal")

    self.b_load_cword.configure(state="normal")

_on_webview_close ¤

_on_webview_close() -> None

Update self.webview_open to false when the user closes the webview.

Source code in src/xpuz/pages/browser.py
534
535
536
537
538
def _on_webview_close(self) -> None:
    """Update ``self.webview_open`` to false when the user closes the
    webview.
    """
    self.webview_open = False

_open_app_embedded ¤

_open_app_embedded(url: str) -> None

Start a webview with the webview module.

Source code in src/xpuz/pages/browser.py
540
541
542
543
544
545
546
547
548
549
550
551
552
553
def _open_app_embedded(self, url: str) -> None:
    """Start a webview with the ``webview`` module."""
    import webview

    self.webview = webview.create_window(
        _("Crossword Puzzle - Game"),
        url,
        width=self.master.winfo_screenwidth(),
        height=int(self.master.winfo_screenheight() * 0.925),
        x=0,
        y=0,
    )
    self.webview.events.closed += self._on_webview_close
    webview.start()

_reset_scroll_frame ¤

_reset_scroll_frame() -> None

Set the x position of the center scroll frame to the start.

Source code in src/xpuz/pages/browser.py
414
415
416
def _reset_scroll_frame(self) -> None:
    """Set the x position of the center scroll frame to the start."""
    self.block_container._parent_canvas.xview("moveto", 0.0)
_reset_search() -> None

Remove all text from the search box and regenerate the placeholder text.

Source code in src/xpuz/pages/browser.py
406
407
408
409
410
411
412
def _reset_search(self) -> None:
    """Remove all text from the search box and regenerate the placeholder
    text.
    """
    self.master.focus_force()
    self.e_search.delete(0, "end")
    self.e_search.configure(placeholder_text=f"{_('Search')} [↵]")

_rollback_states ¤

_rollback_states() -> None

Set all the widgets back to their default states (seen when opening the crossword browser).

Source code in src/xpuz/pages/browser.py
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
def _rollback_states(self) -> None:
    """Set all the widgets back to their default states (seen when opening
    the crossword browser).
    """
    if hasattr(
        self, "cwrapper"
    ):  # User selected a crossword, meaning they
        # had a category open, so this must be done
        if self.cwrapper.category_object:
            self.cwrapper.category_object.b_close.configure(state="normal")
        CrosswordBlock._config_selectors(state="normal")

    self.sb_browser_view.configure(state="normal")
    self.opts_app_view.configure(state="disabled")
    self.opts_export.configure(state="disabled")
    self.l_app_view.configure(state="disabled")
    self.l_export.configure(state="disabled")
    self.b_terminate_webapp.configure(state="disabled")
    self.b_open_webapp.grid_forget()
    self.b_load_cword.grid(row=1, column=0, sticky="nsew", padx=30, pady=7)
    self.b_load_cword.configure(state="disabled")
    self.b_export.configure(state="disabled")
    self.b_export.configure(image=self.export_img_states[1])
    self._configure_word_count_prefs("disabled")
    self.rb_max_wc.configure(text=f"{_('Maximum')}:")
    self.opts_custom_wc.set(_("Select word count"))
    self.wc_pref.set(-1)
    self.launch_options_on: bool = False

_search_crossword ¤

_search_crossword(query: str) -> None

Regenerate all the crossword blocks based on a crossword name query.

Source code in src/xpuz/pages/browser.py
391
392
393
394
395
396
397
398
399
400
401
402
403
404
def _search_crossword(self, query: str) -> None:
    """Regenerate all the crossword blocks based on a crossword name query."""
    if self.browser_view_pref.get() != _(
        "Flattened"
    ):  # Only works in Flattened view
        return

    self._rollback_states()
    # Remove all blocks
    CategoryBlock._set_all(CategoryBlock._remove_block)
    CrosswordBlock._set_all(CrosswordBlock._remove_block)
    self._reset_scroll_frame()
    # Populate the info scroll container with all blocks that match ``query``
    CrosswordBlock._populate_all(self, query)

_update_segbutton_text_colours ¤

_update_segbutton_text_colours(
    view: str, sb: CTkSegmentedButton
) -> None

Configure all segmented button colours in sb to have a black text colour if unselected, otherwise, set the text colour to white.

Source code in src/xpuz/pages/browser.py
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
def _update_segbutton_text_colours(
    self, view: str, sb: CTkSegmentedButton
) -> None:
    """Configure all segmented button colours in ``sb`` to have
    a black text colour if unselected, otherwise, set the text colour to
    white.
    """

    if get_appearance_mode().casefold() != "light":
        return

    for button in sb._buttons_dict.values():
        if button.cget("text") != _(view):
            button.configure(text_color="black")
        else:
            button.configure(text_color="white")

change_browser_view ¤

change_browser_view(callback: Optional = None) -> None

Change the browser view to Flattened or Categorical.

Source code in src/xpuz/pages/browser.py
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
def change_browser_view(self, callback: Optional = None) -> None:
    """Change the browser view to Flattened or Categorical."""

    self._rollback_states()
    # Remove existing blocks
    CategoryBlock._set_all(CategoryBlock._remove_block)
    CrosswordBlock._set_all(CrosswordBlock._remove_block)
    self._reset_scroll_frame()
    view = _get_english_string(
        BASE_ENG_BROWSER_VIEWS,
        self.browser_views,
        _(self.browser_view_pref.get()),
    )

    self._update_segbutton_text_colours(view, self.sb_browser_view)
    self._reset_search()
    if view == "Categorised":
        self.e_search.configure(
            state="disabled", placeholder_text_color=("gray72", "gray42")
        )
        CategoryBlock._populate(self)
    elif view == "Flattened":
        self.e_search.configure(
            state="normal", placeholder_text_color=("gray52", "gray62")
        )
        CrosswordBlock._populate_all(self)

    _update_cfg(Base.cfg, "m", "browser_view", view)

load ¤

load() -> None

Initialise the crossword and web app.

Source code in src/xpuz/pages/browser.py
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
def load(self) -> None:
    """Initialise the crossword and web app."""
    self.cwrapper.make()
    if self.cwrapper.err_flag:  # Error in crossword generation, exit func
        return

    # It is safe to update widget states as crossword generation was OK
    self.b_load_cword.grid_forget()
    if self.cwrapper.category_object:
        self.cwrapper.category_object.b_close.configure(state="disabled")
        self.cwrapper.category_object.selected_cword.set(-1)
    else:
        CrosswordBlock.global_selected_cword.set(-1)
    CrosswordBlock._config_selectors(state="disabled")
    self._configure_word_count_prefs("disabled")
    self.sb_browser_view.configure(state="disabled")
    self.e_search.configure(state="disabled")

    self._load()
    self.webapp_on: bool = True

    self.b_open_webapp.grid(
        row=1, column=0, sticky="nsew", padx=30, pady=7
    )
    self.b_terminate_webapp.configure(state="normal")
    self.opts_app_view.configure(state="normal")
    self.opts_export.configure(state="normal")
    self.l_app_view.configure(state="normal")
    self.l_export.configure(state="normal")
    self.b_export.configure(state="normal")
    self.b_export.configure(image=self.export_img_states[0])

open_app ¤

open_app() -> None

Open the crossword web app at a port read from Base.cfg.

Source code in src/xpuz/pages/browser.py
555
556
557
558
559
560
561
562
563
564
565
566
567
def open_app(self) -> None:
    """Open the crossword web app at a port read from ``Base.cfg``."""
    _read_cfg(Base.cfg)

    url = f"http://127.0.0.1:{Base.cfg.get('misc', 'webapp_port')}/"
    app_view = BASE_ENG_APP_VIEWS[
        self.app_views.index(self.opts_app_view.get())
    ]

    if app_view == BASE_ENG_APP_VIEWS[0]:
        open_new_tab(url)
    else:
        self._open_app_embedded(url)

terminate ¤

terminate() -> None

Reconfigure the states of the GUIs buttons and terminate the app.

Source code in src/xpuz/pages/browser.py
569
570
571
572
573
574
575
576
577
578
579
580
581
def terminate(self) -> None:
    """Reconfigure the states of the GUIs buttons and terminate the app."""
    self.b_open_webapp.grid_forget()
    self._rollback_states()
    if Base.cfg.get("m", "browser_view") == "Flattened":
        self.e_search.configure(state="normal")
    self.sb_browser_view.configure(state="normal")
    if self.webview:
        if self.webview_open:
            self.webview.destroy()
        self.webview = None
    _terminate_app()
    self.webapp_on: bool = False

unbind_ ¤

unbind_() -> None

Remove bindings which can be detected on different pages.

Source code in src/xpuz/pages/browser.py
386
387
388
389
def unbind_(self) -> None:
    """Remove bindings which can be detected on different pages."""
    self.block_container.unbind_all("<MouseWheel")
    self.e_search.unbind("<Return>")

EditorPage ¤

EditorPage(master: Base)

Bases: CTkFrame, Addons

Base page for editor.py. Consists of some utility methods required only by CrosswordPane and WordPane, as well as the title bar and contains for the aforementioned two classes.

Source code in src/xpuz/pages/editor.py
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
def __init__(self, master: Base) -> None:
    super().__init__(
        Base.base_container,
        fg_color=(Colour.Light.MAIN, Colour.Dark.MAIN),
    )
    self.master = master
    self.master._set_dim(dim=EDITOR_DIM)
    self._set_fonts()
    self.master.update()
    self._width, self._height = (
        self.master.winfo_width(),
        self.master.winfo_height(),
    )
    self.fp: PathLike = self._get_user_category_path()
    self.scaling: float = float(Base.cfg.get("m", "scale"))

    # Reset the form arrays to prevent duplicates when opening ``EditorPage``
    # more than once in a single instance
    Form.crossword_forms = []
    Form.word_forms = []

    self.grid_rowconfigure(0, minsize=self._height * 0.15, weight=1)
    self.grid_rowconfigure(1, minsize=self._height * 0.85, weight=1)
    self.grid_columnconfigure(0, weight=1)

    self.master.bind("<Return>", lambda e: self._handle_enter())

_get_user_category_path ¤

_get_user_category_path() -> PathLike

Find where to access categories from, whether that is in the package or in the system documents.

Source code in src/xpuz/pages/editor.py
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
def _get_user_category_path(self) -> PathLike:
    """Find where to access categories from, whether that is in the package
    or in the system documents.
    """
    fp: PathLike = path.join(BASE_CWORDS_PATH, "user")  # Assume the system
    # documents don't exist
    if _doc_data_routine(
        doc_callback=lambda: mkdir(DOC_CAT_PATH),
        local_callback=lambda: mkdir(fp),
        sublevel=DOC_CAT_PATH,
    ):  # Func returned true, meaning the system documents are accessible,
        # so reassign fp to the document category path
        fp = DOC_CAT_PATH
    _make_category_info_json(fp, "#FFFFFF")
    return fp

_handle_scroll ¤

_handle_scroll(event: Event) -> None

Scroll one of the two scrollable frames depending on the user's cursor position.

Source code in src/xpuz/pages/editor.py
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
def _handle_scroll(self, event: Event) -> None:
    """Scroll one of the two scrollable frames depending on the user's
    cursor position.
    """
    container: CTkFrame = (
        self.crossword_pane.preview
        # User's cursor is on the left half of the screen
        if event.x_root
        - self.master.winfo_rootx()  # Account for window offset
        <= EDITOR_DIM[0] * self.scaling / 2
        # Right half
        else self.word_pane.preview
    )
    scroll_region = container._parent_canvas.cget("scrollregion")
    viewable_height = container._parent_canvas.winfo_height()
    if (
        scroll_region
        and int(scroll_region.split(" ")[3]) > viewable_height
    ):
        container._parent_canvas.yview("scroll", -1 * event.delta, "units")

_reset_forms ¤

_reset_forms(
    forms: List[Form], set_invalid: bool = False
) -> None

Remove all the content from the forms in forms.

Source code in src/xpuz/pages/editor.py
458
459
460
461
462
463
464
465
def _reset_forms(
    self, forms: List[Form], set_invalid: bool = False
) -> None:
    """Remove all the content from the forms in ``forms``."""
    for form in forms:
        form.wipe()
        if set_invalid:  # Set to true when adding a new crossword
            form.set_invalid()

_set_form_defaults ¤

_set_form_defaults(*args, forms: List[Form])

Set the default of each form in forms to the respective value in args. Requires len(args) to be equal to len(forms).

Source code in src/xpuz/pages/editor.py
467
468
469
470
471
472
def _set_form_defaults(self, *args, forms: List[Form]):
    """Set the default of each form in ``forms`` to the respective value
    in ``args``. Requires len(args) to be equal to len(forms).
    """
    for i, form in enumerate(forms):
        form.set_default(args[i])

_toggle_forms ¤

_toggle_forms(state: str, forms: List[Form]) -> None

Enable or disable all the forms in forms.

Source code in src/xpuz/pages/editor.py
451
452
453
454
455
456
def _toggle_forms(self, state: str, forms: List[Form]) -> None:
    """Enable or disable all the forms in ``forms``."""
    for form in forms:
        form.set_state(state)
        form.set_valid()
        form.unfocus()

_write_data ¤

_write_data(toplevel: PathLike, data: Dict, type_: str)

Write data to a crossword's info.json or definitions.json.

Source code in src/xpuz/pages/editor.py
474
475
476
477
478
def _write_data(self, toplevel: PathLike, data: Dict, type_: str):
    """Write ``data`` to a crossword's info.json or definitions.json."""
    file = "info.json" if type_ == "info" else "definitions.json"
    with open(path.join(toplevel, file), "w") as f:
        dump(data, f, indent=4)

unbind_ ¤

unbind_() -> None

Remove bindings which can be detected on different pages.

Source code in src/xpuz/pages/editor.py
391
392
393
394
395
396
def unbind_(self) -> None:
    """Remove bindings which can be detected on different pages."""
    self.crossword_pane.preview.unbind_all("<MouseWheel>")
    for form in [*Form.crossword_forms, *Form.word_forms]:
        form.unbind_()
    self.master.unbind("<Return>")

HomePage ¤

HomePage(master)

Bases: CTkFrame, Addons

Class that serves as a homescreen for the program, providing global setting configuration, exit functionality and the ability to view the currently available crossword puzzles.

Source code in src/xpuz/pages/home.py
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
def __init__(self, master) -> None:
    super().__init__(
        Base.base_container,
        fg_color=(Colour.Light.MAIN, Colour.Dark.MAIN),
    )
    self.master = master
    self.master._set_dim()
    self._set_fonts()

    self.appearances: List[str] = [_("light"), _("dark"), _("system")]
    self.cword_qualities: List[str] = [
        _("terrible"),
        _("poor"),
        _("average"),
        _("great"),
        _("perfect"),
    ]

    self._start_version_checking()

_start_version_checking ¤

_start_version_checking() -> None

Create a new event loop and begin checking for a new version of xpuz asynchronously.

Source code in src/xpuz/pages/home.py
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
def _start_version_checking(self) -> None:
    """Create a new event loop and begin checking for a new version of
    ``xpuz`` asynchronously."""
    loop = new_event_loop()

    def _start_loop() -> None:
        """Begin an new async event loop"""
        set_event_loop(loop)
        loop.run_forever()

    # Start new event loop in separate thread
    Thread(target=_start_loop, daemon=True).start()

    # Attempt to get a new version asynchronously in the new loop
    self.master.after(
        1, lambda: run_coroutine_threadsafe(self.check_version(), loop)
    )

change_appearance ¤

change_appearance(appearance: str) -> None

Ensures the user is not selecting the same appearance, then sets the appearance. Some list indexing is required to make the program compatible with non-english languages.

Source code in src/xpuz/pages/home.py
266
267
268
269
270
271
272
273
274
275
276
277
278
def change_appearance(self, appearance: str) -> None:
    """Ensures the user is not selecting the same appearance, then sets
    the appearance. Some list indexing is required to make the program
    compatible with non-english languages.
    """
    eng_appearance_name: str = _get_english_string(
        BASE_ENG_APPEARANCES, self.appearances, appearance
    )
    if eng_appearance_name == Base.cfg.get("m", "appearance"):
        return GUIHelper.show_messagebox(same_appearance=True)

    set_appearance_mode(eng_appearance_name)
    _update_cfg(Base.cfg, "m", "appearance", eng_appearance_name)

change_crossword_quality ¤

change_crossword_quality(quality: str) -> None

Ensures the user is not selecting the same crossword quality, then updates the crossword quality in config.ini.

Source code in src/xpuz/pages/home.py
307
308
309
310
311
312
313
314
315
316
317
def change_crossword_quality(self, quality: str) -> None:
    """Ensures the user is not selecting the same crossword quality, then
    updates the crossword quality in ``config.ini``.
    """
    eng_quality_name: str = _get_english_string(
        BASE_ENG_CWORD_QUALITIES, self.cword_qualities, quality
    )
    if eng_quality_name == Base.cfg.get("m", "cword_quality"):
        return GUIHelper.show_messagebox(same_quality=True)

    _update_cfg(Base.cfg, "m", "cword_quality", eng_quality_name)

change_lang ¤

change_lang(lang: str) -> None

Ensures the user is not selecting the same language, then creates a new locale variable based on the English name of the language (retrieved from self.localised_lang_db). The method then installs a new set of translations with gettext and regenerates the content of the GUI.

Source code in src/xpuz/pages/home.py
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
def change_lang(self, lang: str) -> None:
    """Ensures the user is not selecting the same language, then creates a
    new ``locale`` variable based on the English name of the language
    (retrieved from ``self.localised_lang_db``). The method then installs a
    new set of translations with gettext and regenerates the content of the
    GUI.
    """
    lang = Base.lang_info[0][lang]
    if lang == Base.cfg.get("m", "language"):
        return GUIHelper.show_messagebox(same_lang=True)

    Base.locale = Locale.parse(lang)
    GUIHelper._install_translations(Base.locale)
    _update_cfg(Base.cfg, "m", "language", lang)

    self._route("HomePage", self.master, _(PAGE_MAP["HomePage"]))

change_scale ¤

change_scale(scale: str) -> None

Ensures the user is not selecting the same scale, then sets the scale.

Source code in src/xpuz/pages/home.py
280
281
282
283
284
285
286
287
288
def change_scale(self, scale: str) -> None:
    """Ensures the user is not selecting the same scale, then sets the scale."""
    scale = float(numbers.parse_decimal(scale, locale=Base.locale))
    if scale == float(Base.cfg.get("m", "scale")):
        return GUIHelper.show_messagebox(same_scale=True)

    set_widget_scaling(scale)
    _update_cfg(Base.cfg, "m", "scale", str(scale))
    self.master._set_dim()

check_version async ¤

check_version() -> None

Coroutine to execute utils._check_version asynchronously.

Source code in src/xpuz/pages/home.py
347
348
349
350
351
352
353
354
async def check_version(self) -> None:
    """Coroutine to execute ``utils._check_version`` asynchronously."""
    loop = get_running_loop()

    with ThreadPoolExecutor() as executor:
        ver = await loop.run_in_executor(executor, _check_version)
        if ver:
            self._make_version_label(__version__, ver)

unbind_ ¤

unbind_() -> None

Remove bindings which can be detected on different pages.

Source code in src/xpuz/pages/home.py
262
263
264
def unbind_(self) -> None:
    """Remove bindings which can be detected on different pages."""
    pass