11"""Application here uses PySimpleGUI.
22"""
3- # pylint: disable=import-outside-toplevel
3+
44from __future__ import annotations
55
66import logging
1111try :
1212 from getostheme import isDarkMode
1313except ImportError :
14- isDarkMode = lambda : True
14+
15+ def isDarkMode () -> bool :
16+ """Monkeypatch for getostheme.isDarkMode."""
17+ return True
18+
19+
1520import yaml
1621from PySimpleGUI import Element , Window
1722
@@ -24,13 +29,15 @@ def themeFromFile(themeFile: str) -> list[str]:
2429 """Set the base24 theme from a base24 scheme.yaml to the application.
2530
2631 Args:
32+ ----
2733 themeFile (str): path to file
2834
2935 Returns:
36+ -------
3037 list[str]: theme to set
3138 """
3239 schemeDictTheme = yaml .safe_load (Path (themeFile ).read_text (encoding = "utf-8" ))
33- return ["#" + schemeDictTheme [f"base{ x :02X} " ] for x in range (0 , 24 )]
40+ return ["#" + schemeDictTheme [f"base{ x :02X} " ] for x in range (24 )]
3441
3542
3643def setBase24Theme (
@@ -41,6 +48,7 @@ def setBase24Theme(
4148 """Set the base24 theme to the application.
4249
4350 Args:
51+ ----
4452 theme (Union[str, list[str]]): the light theme
4553 darkTheme (Union[str, list[str]]): the dark theme
4654 pySimpleGui (Any): pysimplegui module
@@ -119,18 +127,20 @@ def setBase24Theme(
119127 "SLIDER_DEPTH" : 0 ,
120128 "PROGRESS_DEPTH" : 0 ,
121129 }
122- pySimpleGui .theme ("theme" ) # type: ignore
130+ pySimpleGui .theme ("theme" )
123131
124132
125133def setupWidgets (gui : str , sizes : dict [str , Any ], pySimpleGui : Any ) -> Widgets :
126134 """Set the widget sizes to the application.
127135
128136 Args:
137+ ----
129138 gui (str): user selected gui eg. pysimpleguiqt
130139 sizes (Union[dict[str, Any]]): widget sizes
131140 pySimpleGui (Any): pysimplegui module
132141
133142 Returns:
143+ -------
134144 Widgets: widgets object all set up nicely
135145 """
136146 if sizes :
@@ -166,10 +176,11 @@ def addItemsAndGroups(
166176 section : types .Group ,
167177 argConstruct : list [list [Element ]],
168178 widgets : Widgets ,
169- ):
179+ ) -> list [ list [ Element ]] :
170180 """Add arg_items and groups to the argConstruct list.
171181
172182 Args:
183+ ----
173184 section (types.Group): contents/ section containing name, arg_items
174185 and groups
175186 argConstruct (list[list[Element]]): list of widgets to
@@ -178,7 +189,8 @@ def addItemsAndGroups(
178189 argConstruct
179190
180191 Returns:
181- list: updated argConstruct
192+ -------
193+ list[list[Element]]: updated argConstruct
182194 """
183195 argConstruct .append ([widgets .label (widgets .stringTitlecase (section ["name" ], " " ), 14 )])
184196 for item in section ["arg_items" ]:
@@ -202,13 +214,15 @@ def generatePopup(
202214 """Create the popup window.
203215
204216 Args:
217+ ----
205218 buildSpec (types.FullBuildSpec): [description]
206219 values (Union[dict[Any, Any]): Returned when a button is clicked. Such
207220 as the menu
208221 widgets (Widgets): class to build widgets
209222 pySimpleGui (Any): PySimpleGui class
210223
211224 Returns:
225+ -------
212226 pySimpleGui.Window: A PySimpleGui Window
213227 """
214228 maxLines = 30 if buildSpec ["gui" ] == "pysimpleguiqt" else 200
@@ -220,7 +234,7 @@ def generatePopup(
220234 popupText = "\n " .join (lines [:maxLines ]) + "\n \n MORE TEXT IN SRC FILE"
221235 else :
222236 popupText = "\n " .join (lines )
223- except :
237+ except ImportError :
224238 popupText = Path (buildSpec ["menu" ][values [0 ]]).read_text (encoding = "utf-8" )
225239 if buildSpec ["gui" ] == "pysimplegui" :
226240 popupLayout = [
@@ -271,12 +285,14 @@ def createLayout(
271285 """Create the pysimplegui layout from the build spec.
272286
273287 Args:
288+ ----
274289 buildSpec (types.FullBuildSpec): build spec containing widget
275290 widgets (Widgets): class to build widgets
276291 pySimpleGui (Any): version of PySimpleGui to use
277292 menu (list[str]]): menu data
278293
279294 Returns:
295+ -------
280296 list[list[Element]]: list of widgets (layout list)
281297 """
282298 argConstruct = []
@@ -325,20 +341,21 @@ def createLayout(
325341 return layout
326342
327343
328- def run (buildSpec : types .FullBuildSpec ):
329- """Main entry point for the application .
344+ def run (buildSpec : types .FullBuildSpec ) -> None :
345+ """Establish the main entry point .
330346
331347 Args:
348+ ----
332349 buildSpec (types.FullBuildSpec): args that customise the application such as the theme
333350 or the function to run
334351 """
335- import PySimpleGUI as psg # pylint: disable=reimported
352+ import PySimpleGUI as psg
336353
337354 if buildSpec ["gui" ] == "pysimpleguiqt" :
338355 import PySimpleGUIQt as psg
339356 elif buildSpec ["gui" ] == "pysimpleguiweb" :
340357 import PySimpleGUIWeb as psg
341- pySimpleGui : Any = psg # type: ignore
358+ pySimpleGui : Any = psg
342359
343360 # Set the theme
344361 setBase24Theme (buildSpec ["theme" ], buildSpec ["darkTheme" ], pySimpleGui )
@@ -358,7 +375,7 @@ def run(buildSpec: types.FullBuildSpec):
358375
359376 # While the application is running
360377 while True :
361- eventAndValues : tuple [Any , dict [Any , Any ] | list [Any ]] = window .read () # type: ignore
378+ eventAndValues : tuple [Any , dict [Any , Any ] | list [Any ]] = window .read ()
362379 event , values = eventAndValues
363380 if event in (None , "Exit" ):
364381 sys .exit (0 )
@@ -367,7 +384,7 @@ def run(buildSpec: types.FullBuildSpec):
367384 if values is not None :
368385 if 0 in values and values [0 ] is not None :
369386 popup = generatePopup (buildSpec , values , widgets , pySimpleGui )
370- popup .read () # type: ignore
387+ popup .read ()
371388 args = {}
372389 for key in values :
373390 if key != 0 :
@@ -376,5 +393,5 @@ def run(buildSpec: types.FullBuildSpec):
376393 if not buildSpec ["run_function" ]:
377394 return args
378395 buildSpec ["run_function" ](args )
379- except Exception as exception : # pylint: disable=broad-except
380- logging .exception (exception )
396+ except Exception :
397+ logging .exception ("Something went wrong: " )
0 commit comments