Skip to content

Commit

Permalink
release: 2022.3
Browse files Browse the repository at this point in the history
  • Loading branch information
FredHappyface committed Dec 31, 2022
1 parent 009c629 commit a5fbbf4
Show file tree
Hide file tree
Showing 33 changed files with 615 additions and 500 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,19 @@
All major and minor version changes will be documented in this file. Details of
patch-level version changes can be found in [commit messages](../../commits/master).

## 2022.3 - 2022/12/31

- Feature, support defaults https://github.com/FHPythonUtils/Cli2Gui/issues/11
- Use full module namespace in-place of relative imports
- Use `Enum` for widget types. eg. `types.ItemType.Bool`
- Update internal types
- Add more supported types for other parsers. e.g `click`
- Argparse supports: Bool, Int, Choice, File, Text
- Click supports: Bool, Int, Choice, Text
- DocOpt supports: Bool, Text
- GetOpt supports: Bool, Text
- Optparse supports: Bool, Int, Choice, Text

## 2022.2.1 - 2022/12/30

- Fix https://github.com/FHPythonUtils/Cli2Gui/issues/13
Expand Down
141 changes: 0 additions & 141 deletions DATA_STRUCTURES.md

This file was deleted.

2 changes: 1 addition & 1 deletion cli2gui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
"""
from __future__ import annotations

from .decorators import *
from cli2gui.decorators import *
63 changes: 15 additions & 48 deletions cli2gui/application/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# pylint: disable=import-outside-toplevel
from __future__ import annotations

import json
import logging
import sys
from pathlib import Path
from typing import Any
Expand All @@ -15,9 +15,9 @@
import yaml
from PySimpleGUI import Element, Window

from .. import c2gtypes
from .pysimplegui2args import argFormat
from .widgets import Widgets
from cli2gui import types
from cli2gui.application.pysimplegui2args import argFormat
from cli2gui.application.widgets import Widgets


def themeFromFile(themeFile: str) -> list[str]:
Expand Down Expand Up @@ -163,14 +163,14 @@ def setupWidgets(gui: str, sizes: dict[str, Any], pySimpleGui: Any) -> Widgets:


def addItemsAndGroups(
section: c2gtypes.Group,
section: types.Group,
argConstruct: list[list[Element]],
widgets: Widgets,
):
"""Add arg_items and groups to the argConstruct list.
Args:
section (c2gtypes.Group): contents/ section containing name, arg_items
section (types.Group): contents/ section containing name, arg_items
and groups
argConstruct (list[list[Element]]): list of widgets to
add to the program window
Expand All @@ -185,57 +185,24 @@ def addItemsAndGroups(
if item["type"] == "RadioGroup":
rGroup = item["_other"]["radio"]
for rElement in rGroup:
argConstruct.append(
widgets.helpFlagWidget(
rElement["display_name"],
rElement["commands"],
rElement["help"],
rElement["dest"],
)
)
elif item["type"] == "Bool":
argConstruct.append(
widgets.helpFlagWidget(
item["display_name"], item["commands"], item["help"], item["dest"]
)
)
elif item["type"] == "File":
argConstruct.append(
widgets.helpFileWidget(
item["display_name"], item["commands"], item["help"], item["dest"]
)
)
elif item["type"] == "Dropdown":
argConstruct.append(
widgets.helpDropdownWidget(
item["display_name"],
item["commands"],
item["help"],
item["dest"],
item["choices"],
)
)
argConstruct.append(widgets.helpFlagWidget(rElement))
else:
argConstruct.append(
widgets.helpTextWidget(
item["display_name"], item["commands"], item["help"], item["dest"]
)
)
argConstruct.append(widgets.addWidgetFromItem(item))
for group in section["groups"]:
argConstruct = addItemsAndGroups(group, argConstruct, widgets)
return argConstruct


def generatePopup(
buildSpec: c2gtypes.FullBuildSpec,
buildSpec: types.FullBuildSpec,
values: dict[Any, Any] | list[Any],
widgets: Widgets,
pySimpleGui: Any,
) -> Window:
"""Create the popup window.
Args:
buildSpec (c2gtypes.FullBuildSpec): [description]
buildSpec (types.FullBuildSpec): [description]
values (Union[dict[Any, Any]): Returned when a button is clicked. Such
as the menu
widgets (Widgets): class to build widgets
Expand Down Expand Up @@ -296,15 +263,15 @@ def generatePopup(


def createLayout(
buildSpec: c2gtypes.FullBuildSpec,
buildSpec: types.FullBuildSpec,
widgets: Widgets,
pySimpleGui: Any,
menu: str | list[str],
) -> list[list[Element]]:
"""Create the pysimplegui layout from the build spec.
Args:
buildSpec (c2gtypes.FullBuildSpec): build spec containing widget
buildSpec (types.FullBuildSpec): build spec containing widget
widgets (Widgets): class to build widgets
pySimpleGui (Any): version of PySimpleGui to use
menu (list[str]]): menu data
Expand Down Expand Up @@ -358,11 +325,11 @@ def createLayout(
return layout


def run(buildSpec: c2gtypes.FullBuildSpec):
def run(buildSpec: types.FullBuildSpec):
"""Main entry point for the application.
Args:
buildSpec (c2gtypes.FullBuildSpec): args that customise the application such as the theme
buildSpec (types.FullBuildSpec): args that customise the application such as the theme
or the function to run
"""
import PySimpleGUI as psg # pylint: disable=reimported
Expand Down Expand Up @@ -410,4 +377,4 @@ def run(buildSpec: c2gtypes.FullBuildSpec):
return args
buildSpec["run_function"](args)
except Exception as exception: # pylint: disable=broad-except
print(repr(exception))
logging.exception(exception)
7 changes: 4 additions & 3 deletions cli2gui/application/pysimplegui2args.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import argparse
from typing import Any

from ..c2gtypes import ParserType
from cli2gui.types import ParserType


def argparseFormat(values: dict[str, Any]) -> argparse.Namespace:
Expand Down Expand Up @@ -52,8 +52,9 @@ def clickFormat(values: dict[str, Any]) -> list[Any]:
"""Format args for click."""
args = []
for key in values:
if not callable(key) and len(values[key]) > 0:
args.extend([key, values[key]])
val = str(values[key])
if not callable(key) and len(val) > 0:
args.extend([key, val])
return args


Expand Down
Loading

0 comments on commit a5fbbf4

Please sign in to comment.