Skip to content

Commit 7129495

Browse files
committed
add gui class docstrings
1 parent ead8651 commit 7129495

File tree

2 files changed

+89
-10
lines changed

2 files changed

+89
-10
lines changed

pypop/notebook_interface/fileselector.py

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,22 @@
2020

2121

2222
class ValidatingChooser(VBox):
23+
"""IPyWidgets GUI Element for file selection with validation
24+
"""
2325

2426
_container_layout = Layout(margin="1em 0em 1em 0em")
2527
_msgbox_layout = Layout()
2628

2729
def __init__(self, starting_file=None, starting_path=None, **kwargs):
30+
"""\
31+
Parameters
32+
----------
33+
starting_file: str or None
34+
If not None, file that is initially selected.
35+
starting_path: str or None
36+
Starting directory for filechooser. If none, defaults to value of
37+
`os.getcwd()`
38+
"""
2839

2940
if starting_file is None:
3041
starting_file = ""
@@ -61,6 +72,9 @@ def selected(self):
6172

6273

6374
class FileSelector(VBox):
75+
"""IPyWidgets GUI Element for selecting arbitrary numbers of files with callback
76+
support
77+
"""
6478

6579
_button_container_layout = Layout(
6680
display="flex",
@@ -77,13 +91,29 @@ class FileSelector(VBox):
7791

7892
def __init__(
7993
self,
80-
base_dir=".",
94+
base_dir=None,
8195
starting_files=None,
8296
calculation_callback=None,
8397
analysis_state=None,
8498
**kwargs
8599
):
86-
self._base_dir = base_dir
100+
"""\
101+
Parameters
102+
----------
103+
104+
base_dir: str or None
105+
Starting directory for filechooser. If None defaults to `os.getcwd()`.
106+
starting_files: list of str or None
107+
List of files to be initially selected.
108+
calculation_callback: callable
109+
Function to be executed when calculation button is pressed. Should have the
110+
standard IPyWidgets Button callback signature `f(WidgetInstance)`
111+
analysis_state: AnalysisState
112+
Saved analysis state to be passed in (overrides default options
113+
with those saved)
114+
"""
115+
116+
self._base_dir = base_dir if base_dir else getcwd()
87117
self._files = (
88118
[None]
89119
if starting_files is None

pypop/notebook_interface/wizard.py

Lines changed: 57 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@
1515
from pypop.utils.exceptions import ExtraePRVNoOnOffEventsError
1616

1717
class TypeAsserter:
18+
"""Parent class for type asserter objects
19+
20+
Asserter classes provide a callable which can be used to assert the validity of an
21+
object.
22+
23+
Subclasses should implement a check_type function returning true/false as needed.
24+
"""
1825

1926
_expected = None
2027

@@ -26,23 +33,44 @@ def __call__(self, testobj):
2633
return True
2734

2835
def check_type(self, testobj):
36+
"""Return true if object is valid
37+
38+
Parameters
39+
----------
40+
testobj: object
41+
Object to be validated.
42+
"""
2943
raise NotImplementedError()
3044

3145

3246
class SimpleAsserter(TypeAsserter):
47+
"""Assert that an object is of a given type
48+
49+
Provides a callable object which asserts the provided object is of the required type.
50+
"""
51+
52+
def __init__(self, assert_class):
53+
"""Define class to be validated
54+
55+
Parameters
56+
----------
57+
assert_class: class
58+
Reference class to be compared to.
59+
"""
60+
self._assert_cls = assert_class
61+
self._exepceted = assert_class.__name__
62+
63+
3364
def check_type(self, testobj):
3465
if isinstance(testobj, self._assert_cls):
3566
return True
3667

37-
@staticmethod
38-
def create(assert_cls):
39-
asserter = SimpleAsserter()
40-
asserter._assert_cls = assert_cls
41-
asserter._expected = assert_cls.__name__
42-
return asserter
43-
4468

4569
class ListofStrAsserter(TypeAsserter):
70+
"""Assert that an object is a list of strings
71+
72+
Provides a callable object which asserts a provided object is a list of strings.
73+
"""
4674
_expected = "list of str"
4775

4876
def check_type(self, testobj):
@@ -51,10 +79,14 @@ def check_type(self, testobj):
5179

5280

5381
class AnalysisState:
82+
"""Object containing analysis settings
83+
84+
This is an internal class and not intended for direct use.
85+
"""
5486

5587
_required_params = {
5688
"trace_files": ListofStrAsserter(),
57-
"metrics_object": SimpleAsserter.create(pm.MetricSet),
89+
"metrics_object": SimpleAsserter(pm.MetricSet),
5890
}
5991

6092
_optional_params = {}
@@ -109,7 +141,24 @@ def __setitem__(self, key, value):
109141

110142

111143
class MetricsWizard(Tab):
144+
"""IPyWidgets GUI Element providing an analysis Wizard.
145+
"""
112146
def __init__(self, metric_calc="auto", base_dir=".", starting_files=None, **kwargs):
147+
"""
148+
149+
Parameters
150+
----------
151+
152+
metric_calc: class MetricSet or 'auto'
153+
Provide a specific metric calculator class. If 'auto' is passed then try to
154+
choose a suitable default.
155+
156+
base_dir: str
157+
Starting directory for the filechooser. Defaults to result of `os.getcwd()`.
158+
159+
starting_files: list of str
160+
List of files that should be preselected in the file chooser.
161+
"""
113162

114163
self._metrics_display = None
115164
self._scaling_plot = None

0 commit comments

Comments
 (0)