Skip to content

xpuz.pages.home ¤

Default GUI page for xpuz. Provides global configuration options and routing buttons to other available pages.

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