Skip to content

Commit 3b0c3a8

Browse files
committed
ruff fixes
1 parent bc6fcad commit 3b0c3a8

32 files changed

+197
-191
lines changed

cli2gui/application/application.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
import sys
77
from typing import Any
88

9-
from cli2gui import types
9+
from cli2gui import models
1010
from cli2gui.application.application2args import argFormat
1111
from cli2gui.gui import helpers
1212
from cli2gui.gui.dearpygui_wrapper import DearPyGuiWrapper
1313
from cli2gui.gui.pysimplegui_wrapper import PySimpleGUIWrapper
1414

1515

16-
def run(buildSpec: types.FullBuildSpec) -> Any:
16+
def run(buildSpec: models.FullBuildSpec) -> Any:
1717
"""Establish the main entry point.
1818
1919
Args:

cli2gui/application/application2args.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from pathlib import Path
88
from typing import Any
99

10-
from cli2gui.types import SEP, ParserType
10+
from cli2gui.models import SEP, ParserType
1111

1212

1313
def processValue(key: str, value: str) -> tuple[str, Any]:
@@ -44,44 +44,44 @@ def processValue(key: str, value: str) -> tuple[str, Any]:
4444
def argparseFormat(values: dict[str, Any]) -> argparse.Namespace:
4545
"""Format args for argparse."""
4646
args = {}
47-
for key in values:
48-
cleankey, value = processValue(key, values[key])
47+
for key, _value in values.items():
48+
cleankey, value = processValue(key, _value)
4949
args[cleankey] = value
5050
return argparse.Namespace(**args)
5151

5252

5353
def optparseFormat(values: dict[str, Any]) -> tuple[optparse.Values, list[str]]:
5454
"""Format args for optparse."""
5555
args = {}
56-
for key in values:
57-
cleankey, value = processValue(key, values[key])
56+
for key, _value in values.items():
57+
cleankey, value = processValue(key, _value)
5858
args[cleankey] = value
5959
return (optparse.Values(args), [])
6060

6161

6262
def getoptFormat(values: dict[str, Any]) -> tuple[list[Any], list[Any]]:
6363
"""Format args for getopt."""
64-
return ([processValue(key, values[key]) for key in values if values[key]], [])
64+
return ([processValue(key, _value) for key, _value in values.items() if _value], [])
6565

6666

6767
def docoptFormat(values: dict[str, Any]) -> dict[str, Any]:
6868
"""Format args for docopt."""
6969
import docopt
7070

7171
args = {}
72-
for key in values:
73-
cleankey, value = processValue(key, values[key])
72+
for key, _value in values.items():
73+
cleankey, value = processValue(key, _value)
7474
args[cleankey] = value
7575
return docopt.Dict(args)
7676

7777

7878
def clickFormat(values: dict[str, Any]) -> list[Any]:
7979
"""Format args for click."""
8080
args = []
81-
for key in values:
82-
val = str(values[key])
81+
for key, _value in values.items():
82+
val = str(_value)
8383
if not callable(key) and len(val) > 0:
84-
cleankey, value = processValue(key, values[key])
84+
cleankey, value = processValue(key, _value)
8585
args.extend([cleankey, value])
8686
return args
8787

cli2gui/decorators.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@
1313
from typing import Any, Iterable
1414

1515
from cli2gui.application import application
16+
from cli2gui.models import BuildSpec, FullBuildSpec, GUIType, ParserType
1617
from cli2gui.tojson import (
1718
argparse2json,
1819
click2json,
1920
docopt2json,
2021
getopt2json,
2122
optparse2json,
2223
)
23-
from cli2gui.types import BuildSpec, FullBuildSpec, GUIType, ParserType
2424

2525
DO_COMMAND = "--cli2gui"
2626
DO_NOT_COMMAND = "--disable-cli2gui"

cli2gui/gui/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
"""Package containing GUI classes and functionality, responsible for driving the various
2+
GUI backends supported by cli2gui."""

cli2gui/gui/abstract_gui.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,26 @@
1+
"""Abstract base class for GUI wrappers."""
2+
13
from __future__ import annotations
24

35
from abc import ABC, abstractmethod
6+
from typing import Any, Callable
47

5-
from cli2gui import types
8+
from cli2gui import models
69

710

811
class AbstractGUI(ABC):
912
"""Abstract base class for GUI wrappers."""
1013

1114
@abstractmethod
1215
def __init__(self) -> None:
13-
pass
16+
"""Abstract base class for GUI wrappers."""
1417

1518
@abstractmethod
1619
def main(
17-
self, buildSpec: types.FullBuildSpec, menu: list[str], quit_callback, run_callback
20+
self,
21+
buildSpec: models.FullBuildSpec,
22+
quit_callback: Callable[[], None],
23+
run_callback: Callable[[dict[str, Any]], None],
1824
) -> None:
1925
"""Abstract method for the main function."""
2026
raise NotImplementedError

cli2gui/gui/dearpygui_wrapper.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"""Wrapper class for Dear PyGui."""
2+
13
from __future__ import annotations
24

35
from pathlib import Path
@@ -7,7 +9,7 @@
79

810
from cli2gui.gui import helpers
911
from cli2gui.gui.abstract_gui import AbstractGUI
10-
from cli2gui.types import SEP, FullBuildSpec, Group, Item, ItemType
12+
from cli2gui.models import SEP, FullBuildSpec, Group, Item, ItemType
1113

1214
THISDIR = Path(__file__).resolve().parent
1315

@@ -25,6 +27,11 @@ class DearPyGuiWrapper(AbstractGUI):
2527
"""Wrapper class for Dear PyGui."""
2628

2729
def __init__(self, base24Theme: list[str]) -> None:
30+
"""Dearpygui wrapper class.
31+
32+
:param list[str] base24Theme: list representing a base24 theme. Containing 24 elements
33+
(of hex strings like "#e7e7e9")
34+
"""
2835
self.base24Theme = base24Theme
2936
super().__init__()
3037

cli2gui/gui/helpers.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
"""Basic helper package containing commonly used functions, such as isDarkMode,
2+
get_base24_theme etc."""
3+
14
from __future__ import annotations
25

36
from pathlib import Path

cli2gui/gui/pysimplegui_wrapper.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"""Wrapper class for PySimpleGUI."""
2+
13
from __future__ import annotations
24

35
import io
@@ -8,15 +10,19 @@
810

911
from cli2gui.gui import helpers
1012
from cli2gui.gui.abstract_gui import AbstractGUI
11-
from cli2gui.types import SEP, FullBuildSpec, Group, Item, ItemType
12-
13-
# ruff: noqa: ANN401
13+
from cli2gui.models import SEP, FullBuildSpec, Group, Item, ItemType
1414

1515

1616
class PySimpleGUIWrapper(AbstractGUI):
1717
"""Wrapper class for PySimpleGUI."""
1818

1919
def __init__(self, base24Theme: list[str], psg_lib: str) -> None:
20+
"""PySimpleGUI wrapper class.
21+
22+
:param list[str] base24Theme: list representing a base24 theme. Containing 24 elements
23+
(of hex strings like "#e7e7e9")
24+
:param str psg_lib: string representing the pysimplegui lib to use
25+
"""
2026
super().__init__()
2127

2228
if psg_lib == "psg":
@@ -138,14 +144,14 @@ def _fileBrowser(
138144
additional_properties: dict | None = None,
139145
) -> list[Any]:
140146
"""Return a fileBrowser button and field."""
141-
additional_properties = additional_properties or {}
147+
prop = additional_properties or {}
142148

143149
height = self.sizes["input_size"][1]
144150
width = self.sizes["input_size"][0]
145151

146152
key = f"{key}{SEP}{_type}"
147153
if _type in [ItemType.FileWrite, ItemType.File]:
148-
key += f";{additional_properties.get('file_mode')};{additional_properties.get('file_encoding')}"
154+
key += f";{prop.get('file_mode')};{prop.get('file_encoding')}"
149155

150156
browser = self.sg.FileBrowse(
151157
key="@@" + key,
@@ -394,15 +400,10 @@ def createLayout(
394400
) -> list[list[Any]]:
395401
"""Create the pysimplegui layout from the build spec.
396402
397-
Args:
398-
----
399-
buildSpec (FullBuildSpec): build spec containing widget
400-
self (self): class to build self
401-
403+
:param FullBuildSpec buildSpec: build spec containing widget
404+
:param str | list[str] menu: menu definition. containing menu keys
402405
403-
Returns:
404-
-------
405-
list[list[Any]]: list of self (layout list)
406+
:return list[list[Any]]: list of self (layout list)
406407
407408
"""
408409
argConstruct = []

cli2gui/types.py renamed to cli2gui/models.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,6 @@ class FullBuildSpec:
9898
class ParserType(str, Enum):
9999
"""Supported parser types.
100100
101-
OPTPARSE = "optparse"
102-
ARGPARSE = "argparse"
103-
DEPHELL_ARGPARSE = "dephell_argparse"
104-
DOCOPT = "docopt"
105-
GETOPT = "getopt"
106-
CLICK = "click"
107-
CUSTOM = "input()" # this seems like a pretty poor pattern to use
108101
"""
109102

110103
OPTPARSE = "optparse"
@@ -120,13 +113,12 @@ class ParserType(str, Enum):
120113
class GUIType(str, Enum):
121114
"""Supported gui types.
122115
123-
DEFAULT = "pysimplegui"
124-
WEB = "pysimpleguiweb"
125-
QT = "pysimpleguiqt"
126-
FSG = "freesimplegui"
127116
"""
128117

129-
DEFAULT = "pysimplegui"
118+
PSG = "pysimplegui"
130119
WEB = "pysimpleguiweb"
131120
QT = "pysimpleguiqt"
132121
FSG = "freesimplegui"
122+
FSGWEB = "freesimpleguiweb"
123+
FSGQT = "freesimpleguiqt"
124+
DPG = "dearpygui"

cli2gui/tojson/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
"""Package containing transforms for each supported parser/cli library, responsible for
2+
taking each parser representation (and BuildSpec) and generating a FullBuildSpec."""

0 commit comments

Comments
 (0)