33# pylint: disable=import-outside-toplevel
44from __future__ import annotations
55
6- import json
6+ import logging
77import sys
88from pathlib import Path
99from typing import Any
1515import yaml
1616from PySimpleGUI import Element , Window
1717
18- from .. import c2gtypes
19- from .pysimplegui2args import argFormat
20- from .widgets import Widgets
18+ from cli2gui import types
19+ from cli2gui . application .pysimplegui2args import argFormat
20+ from cli2gui . application .widgets import Widgets
2121
2222
2323def themeFromFile (themeFile : str ) -> list [str ]:
@@ -163,14 +163,14 @@ def setupWidgets(gui: str, sizes: dict[str, Any], pySimpleGui: Any) -> Widgets:
163163
164164
165165def addItemsAndGroups (
166- section : c2gtypes .Group ,
166+ section : types .Group ,
167167 argConstruct : list [list [Element ]],
168168 widgets : Widgets ,
169169):
170170 """Add arg_items and groups to the argConstruct list.
171171
172172 Args:
173- section (c2gtypes .Group): contents/ section containing name, arg_items
173+ section (types .Group): contents/ section containing name, arg_items
174174 and groups
175175 argConstruct (list[list[Element]]): list of widgets to
176176 add to the program window
@@ -185,57 +185,24 @@ def addItemsAndGroups(
185185 if item ["type" ] == "RadioGroup" :
186186 rGroup = item ["_other" ]["radio" ]
187187 for rElement in rGroup :
188- argConstruct .append (
189- widgets .helpFlagWidget (
190- rElement ["display_name" ],
191- rElement ["commands" ],
192- rElement ["help" ],
193- rElement ["dest" ],
194- )
195- )
196- elif item ["type" ] == "Bool" :
197- argConstruct .append (
198- widgets .helpFlagWidget (
199- item ["display_name" ], item ["commands" ], item ["help" ], item ["dest" ]
200- )
201- )
202- elif item ["type" ] == "File" :
203- argConstruct .append (
204- widgets .helpFileWidget (
205- item ["display_name" ], item ["commands" ], item ["help" ], item ["dest" ]
206- )
207- )
208- elif item ["type" ] == "Dropdown" :
209- argConstruct .append (
210- widgets .helpDropdownWidget (
211- item ["display_name" ],
212- item ["commands" ],
213- item ["help" ],
214- item ["dest" ],
215- item ["choices" ],
216- )
217- )
188+ argConstruct .append (widgets .helpFlagWidget (rElement ))
218189 else :
219- argConstruct .append (
220- widgets .helpTextWidget (
221- item ["display_name" ], item ["commands" ], item ["help" ], item ["dest" ]
222- )
223- )
190+ argConstruct .append (widgets .addWidgetFromItem (item ))
224191 for group in section ["groups" ]:
225192 argConstruct = addItemsAndGroups (group , argConstruct , widgets )
226193 return argConstruct
227194
228195
229196def generatePopup (
230- buildSpec : c2gtypes .FullBuildSpec ,
197+ buildSpec : types .FullBuildSpec ,
231198 values : dict [Any , Any ] | list [Any ],
232199 widgets : Widgets ,
233200 pySimpleGui : Any ,
234201) -> Window :
235202 """Create the popup window.
236203
237204 Args:
238- buildSpec (c2gtypes .FullBuildSpec): [description]
205+ buildSpec (types .FullBuildSpec): [description]
239206 values (Union[dict[Any, Any]): Returned when a button is clicked. Such
240207 as the menu
241208 widgets (Widgets): class to build widgets
@@ -296,15 +263,15 @@ def generatePopup(
296263
297264
298265def createLayout (
299- buildSpec : c2gtypes .FullBuildSpec ,
266+ buildSpec : types .FullBuildSpec ,
300267 widgets : Widgets ,
301268 pySimpleGui : Any ,
302269 menu : str | list [str ],
303270) -> list [list [Element ]]:
304271 """Create the pysimplegui layout from the build spec.
305272
306273 Args:
307- buildSpec (c2gtypes .FullBuildSpec): build spec containing widget
274+ buildSpec (types .FullBuildSpec): build spec containing widget
308275 widgets (Widgets): class to build widgets
309276 pySimpleGui (Any): version of PySimpleGui to use
310277 menu (list[str]]): menu data
@@ -358,11 +325,11 @@ def createLayout(
358325 return layout
359326
360327
361- def run (buildSpec : c2gtypes .FullBuildSpec ):
328+ def run (buildSpec : types .FullBuildSpec ):
362329 """Main entry point for the application.
363330
364331 Args:
365- buildSpec (c2gtypes .FullBuildSpec): args that customise the application such as the theme
332+ buildSpec (types .FullBuildSpec): args that customise the application such as the theme
366333 or the function to run
367334 """
368335 import PySimpleGUI as psg # pylint: disable=reimported
@@ -410,4 +377,4 @@ def run(buildSpec: c2gtypes.FullBuildSpec):
410377 return args
411378 buildSpec ["run_function" ](args )
412379 except Exception as exception : # pylint: disable=broad-except
413- print ( repr ( exception ) )
380+ logging . exception ( exception )
0 commit comments