44
55from configparser import ConfigParser
66from platform import system
7- from typing import Dict , List , Tuple
7+ from typing import Dict , List , Union , Tuple , Callable , Literal
88
99from babel import Locale
1010from customtkinter import (
@@ -26,6 +26,7 @@ class Addons:
2626 """Convenience and utility methods for all page classes."""
2727
2828 def _set_fonts (self ) -> None :
29+ """Initialise this instance with all the required CTkFont objects."""
2930 self .TITLE_FONT = CTkFont (size = 31 , weight = "bold" , slant = "roman" )
3031 self .SUBHEADING_FONT = CTkFont (size = 24 , weight = "normal" , slant = "roman" )
3132 self .TEXT_FONT = CTkFont (size = 15 , weight = "normal" , slant = "roman" )
@@ -40,11 +41,20 @@ def _set_fonts(self) -> None:
4041 def _confirm_route (
4142 self ,
4243 * ,
43- action : bool = None ,
44+ action : Callable = None ,
4445 condition : bool = None ,
4546 confirmation : Dict [str , bool ] = {"close" : True },
4647 ) -> bool :
47- """Allow the user to confirm if they wish to route through a messagebox."""
48+ """Allow the user to confirm if they wish to route through a messagebox.
49+
50+ Args:
51+ action: A function to call if the user confirms to route.
52+ condition: Only perform the confirmation if `True`.
53+ confirmation: Passed in `**kwargs` syntax to the [messagebox helper](utils.md#xpuz.utils.GUIHelper.confirm_with_messagebox)
54+
55+ Returns:
56+ The status of the route confirmation; whether it was accepted or not.
57+ """
4858
4959 if (
5060 condition
@@ -60,15 +70,24 @@ def _confirm_route(
6070
6171 def _route (
6272 self ,
63- page_ref : str , # Name of the page instance
64- base : "Base" , # Reference to base instance
65- title : str , # Title of the new page
66- ** kwargs ,
73+ page_ref : Literal ,
74+ base : CTk ,
75+ title : str ,
76+ ** kwargs : Dict [ str , bool ] ,
6777 ) -> bool :
6878 """Method for all page-related classes to simplify navigation.
6979
7080 All class instances that use ``_route`` must have their content packed
71- and contain 4 content generation methods, as seen below.
81+ and contain 4 content generation methods, as seen in the source code.
82+
83+ Args:
84+ page_ref: The new page's name, used to retrieve the corresponding class from `locals()`.
85+ base: The main app instance.
86+ title: The new page's title.
87+ **kwargs: Confirmation dictionary routed to [_confirm_route](base.md#xpuz.base.Addons._confirm_route).
88+
89+ Returns:
90+ Status of the route; whether it was performed or not.
7291 """
7392 if (
7493 kwargs
@@ -107,13 +126,19 @@ class Base(CTk, Addons):
107126 """The main app instance. Contains methods used by all pages."""
108127
109128 base_container : CTkFrame = None
110- lang_info : Tuple [Dict [str , str ], List [str ]] = []
111- locale : Locale = None
112- cfg : ConfigParser = None
129+ lang_info : Tuple [Dict [str , str ], List [str ]] = []
130+ locale : Locale = None
131+ cfg : ConfigParser = None
113132 fullscreen : bool = False
114133 page_inst : object = None
115134
116- def __init__ (self , ** kwargs ) -> None :
135+ def __init__ (self , ** kwargs : Dict [str , Union [Tuple [Dict [str , str ], List [str ]], Locale , ConfigParser ]]) -> None :
136+ """Initialise the base instance and container and apply widget scaling,
137+ theme and appearance.
138+
139+ Args:
140+ **kwargs: `lang_info`, `cfg`, and `locale` objects passed from [main](__main__.md#xpuz.__main__.main).
141+ """
117142 super ().__init__ ()
118143
119144 base_container = CTkFrame (self )
@@ -141,6 +166,11 @@ def __init__(self, **kwargs) -> None:
141166 self ._route (page , self , _ (PAGE_MAP [page ]))
142167
143168 def _set_dim (self , dim : Tuple [int , int ] = DIM ) -> None :
169+ """Set the dimensions of the program during runtime.
170+
171+ Args:
172+ dim: The dimensions.
173+ """
144174 scale = float (Base .cfg .get ("m" , "scale" ))
145175 new_width = dim [0 ] * scale
146176 new_height = dim [1 ] * scale
@@ -152,6 +182,7 @@ def _set_dim(self, dim: Tuple[int, int] = DIM) -> None:
152182 self .update ()
153183
154184 def _toggle_fullscreen (self ) -> None :
185+ """Enable or disabled fullscreen mode."""
155186 Base .fullscreen = not Base .fullscreen
156187 if self .fullscreen :
157188 self .maxsize (self .winfo_screenwidth (), self .winfo_screenheight ())
@@ -171,9 +202,13 @@ def _increment_launches(self) -> None:
171202 def _exit_handler (
172203 self , restart : bool = False , webapp_on : bool = False
173204 ) -> None :
174- """Called when the event " WM_DELETE_WINDOW" occurs or when the the
205+ """Called when the event ` WM_DELETE_WINDOW` occurs or when the the
175206 program must be restarted, in which case the ``restart`` default
176207 parameter is overridden.
208+
209+ Args:
210+ restart: Whether to perform a restart or not.
211+ webapp_on: Whether the `Flask` web app is running or not.
177212 """
178213 # If user wants to exit/restart
179214 if GUIHelper .confirm_with_messagebox (exit_ = True , restart = restart ):
0 commit comments