happyscript 0.0.25__tar.gz → 0.0.26__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. {happyscript-0.0.25 → happyscript-0.0.26}/PKG-INFO +1 -1
  2. {happyscript-0.0.25 → happyscript-0.0.26}/happyscript/__init__.py +6 -2
  3. {happyscript-0.0.25 → happyscript-0.0.26}/happyscript/charts/histogram_chart.py +2 -2
  4. {happyscript-0.0.25 → happyscript-0.0.26}/happyscript/charts/histogram_series.py +4 -4
  5. {happyscript-0.0.25 → happyscript-0.0.26}/happyscript/charts/matplotlib_chart.py +9 -5
  6. {happyscript-0.0.25 → happyscript-0.0.26}/happyscript/charts/scatter_chart.py +2 -2
  7. {happyscript-0.0.25 → happyscript-0.0.26}/happyscript/charts/scatter_series.py +3 -3
  8. {happyscript-0.0.25 → happyscript-0.0.26}/happyscript/charts/time_chart.py +2 -2
  9. {happyscript-0.0.25 → happyscript-0.0.26}/happyscript/charts/time_series.py +3 -3
  10. {happyscript-0.0.25 → happyscript-0.0.26}/happyscript/scriptcontrol.py +29 -9
  11. {happyscript-0.0.25 → happyscript-0.0.26}/happyscript/scriptgui.py +28 -17
  12. {happyscript-0.0.25 → happyscript-0.0.26}/happyscript.egg-info/PKG-INFO +1 -1
  13. {happyscript-0.0.25 → happyscript-0.0.26}/pyproject.toml +1 -1
  14. {happyscript-0.0.25 → happyscript-0.0.26}/README.md +0 -0
  15. {happyscript-0.0.25 → happyscript-0.0.26}/happyscript/charts/__init__.py +0 -0
  16. {happyscript-0.0.25 → happyscript-0.0.26}/happyscript/charts/chart.py +0 -0
  17. {happyscript-0.0.25 → happyscript-0.0.26}/happyscript/charts/panel_charts.py +0 -0
  18. {happyscript-0.0.25 → happyscript-0.0.26}/happyscript/forms/form_askchoice.py +0 -0
  19. {happyscript-0.0.25 → happyscript-0.0.26}/happyscript/forms/form_askimage.py +0 -0
  20. {happyscript-0.0.25 → happyscript-0.0.26}/happyscript/forms/form_main.py +0 -0
  21. {happyscript-0.0.25 → happyscript-0.0.26}/happyscript/forms/form_ontestfailure.py +0 -0
  22. {happyscript-0.0.25 → happyscript-0.0.26}/happyscript/forms/form_serials.py +0 -0
  23. {happyscript-0.0.25 → happyscript-0.0.26}/happyscript/forms/form_stop.py +0 -0
  24. {happyscript-0.0.25 → happyscript-0.0.26}/happyscript/forms/formsbase.py +0 -0
  25. {happyscript-0.0.25 → happyscript-0.0.26}/happyscript/imglib.py +0 -0
  26. {happyscript-0.0.25 → happyscript-0.0.26}/happyscript/panels/panel_log.py +0 -0
  27. {happyscript-0.0.25 → happyscript-0.0.26}/happyscript/panels/panel_messages.py +0 -0
  28. {happyscript-0.0.25 → happyscript-0.0.26}/happyscript/panels/panel_scripts2.py +0 -0
  29. {happyscript-0.0.25 → happyscript-0.0.26}/happyscript/panels/panel_tests.py +0 -0
  30. {happyscript-0.0.25 → happyscript-0.0.26}/happyscript/panels/panelsbase.py +0 -0
  31. {happyscript-0.0.25 → happyscript-0.0.26}/happyscript/scriptartwork.py +0 -0
  32. {happyscript-0.0.25 → happyscript-0.0.26}/happyscript/scriptexceptions.py +0 -0
  33. {happyscript-0.0.25 → happyscript-0.0.26}/happyscript/scriptinfo.py +0 -0
  34. {happyscript-0.0.25 → happyscript-0.0.26}/happyscript/scriptmanager.py +0 -0
  35. {happyscript-0.0.25 → happyscript-0.0.26}/happyscript/scriptparams.py +0 -0
  36. {happyscript-0.0.25 → happyscript-0.0.26}/happyscript/scriptreader.py +0 -0
  37. {happyscript-0.0.25 → happyscript-0.0.26}/happyscript/scriptrunner.py +0 -0
  38. {happyscript-0.0.25 → happyscript-0.0.26}/happyscript/splashmenu/forms.py +0 -0
  39. {happyscript-0.0.25 → happyscript-0.0.26}/happyscript/splashmenu/splashmenuform.py +0 -0
  40. {happyscript-0.0.25 → happyscript-0.0.26}/happyscript/splashmenu/splashmenumain.py +0 -0
  41. {happyscript-0.0.25 → happyscript-0.0.26}/happyscript/testlog/global_log_handler.py +0 -0
  42. {happyscript-0.0.25 → happyscript-0.0.26}/happyscript/testlog/log_to_text.py +0 -0
  43. {happyscript-0.0.25 → happyscript-0.0.26}/happyscript/testlog/logtoxml.py +0 -0
  44. {happyscript-0.0.25 → happyscript-0.0.26}/happyscript/testlog/printredirect.py +0 -0
  45. {happyscript-0.0.25 → happyscript-0.0.26}/happyscript.egg-info/SOURCES.txt +0 -0
  46. {happyscript-0.0.25 → happyscript-0.0.26}/happyscript.egg-info/dependency_links.txt +0 -0
  47. {happyscript-0.0.25 → happyscript-0.0.26}/happyscript.egg-info/top_level.txt +0 -0
  48. {happyscript-0.0.25 → happyscript-0.0.26}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: happyscript
3
- Version: 0.0.25
3
+ Version: 0.0.26
4
4
  Summary: Framework for running scripts
5
5
  Requires-Python: >=3.5
6
6
  Description-Content-Type: text/markdown
@@ -1,10 +1,14 @@
1
1
  """HappyScript - handy script launcher"""
2
2
 
3
- __version__ = "0.0.25"
3
+ __version__ = "0.0.26"
4
4
 
5
5
  # With these statements, after doing 'import happyscript' you can do 'xxx = happyscript.ScriptManager()'
6
6
  #from .scriptmanager import ScriptManager
7
7
  #from .pytestsupport import *
8
8
 
9
9
  from .scriptmanager import ScriptManager
10
- from .splashmenu.splashmenumain import SplashMenu
10
+ from .splashmenu.splashmenumain import SplashMenu
11
+
12
+ from .scriptcontrol import ScriptControl as Ctrl
13
+ from .scriptgui import ScriptGui as Gui
14
+ from .scriptinfo import ScriptInfo as Info
@@ -21,13 +21,13 @@ class HistogramChart(Chart):
21
21
  self._xlabel = "Value"
22
22
  self._ylabel = "Count"
23
23
 
24
- def do_add_series(self, name):
24
+ def do_add_series(self, name:str) -> HistogramSeries:
25
25
  ''' Create a new series for this chart.
26
26
  Base class will add it to the list of series
27
27
  '''
28
28
  return HistogramSeries(self, name, self.__binsize, color=self.get_series_color() )
29
29
 
30
- def get_data_as_text(self):
30
+ def get_data_as_text(self) -> str:
31
31
  ''' Returns the data of all series as text.
32
32
  '''
33
33
  lines = "" # the resulting text
@@ -29,7 +29,7 @@ class HistogramSeries(object):
29
29
  return self.__name
30
30
 
31
31
  def get_plot_object(self):
32
- '''
32
+ ''' !!! Internal use only !!!
33
33
  Gets the object to draw on the chart.
34
34
  '''
35
35
  bs = self.__binsize # shorthand
@@ -74,7 +74,7 @@ class HistogramSeries(object):
74
74
 
75
75
  return line
76
76
 
77
- def add_value(self, x):
77
+ def add_value(self, x:float):
78
78
  ''' Add a value
79
79
  '''
80
80
 
@@ -88,8 +88,8 @@ class HistogramSeries(object):
88
88
 
89
89
  self.__chart.update()
90
90
 
91
- def add_values(self, data):
92
- ''' Add a value
91
+ def add_values(self, data:list[float]):
92
+ ''' Add all the values from a list.
93
93
  '''
94
94
 
95
95
  for x in data:
@@ -83,7 +83,7 @@ class MatPlotLibChart(wx.Panel):
83
83
  return self.__name
84
84
 
85
85
  @property
86
- def figure(self):
86
+ def figure(self) -> Figure:
87
87
  return self.__figure
88
88
 
89
89
  def configure(self, /, x_label=None, y_label=None, title=None,
@@ -99,20 +99,23 @@ class MatPlotLibChart(wx.Panel):
99
99
 
100
100
  @property
101
101
  def on_update(self):
102
- ''' The callback function for when data is modified.
102
+ ''' !!! Internal use only !!!!
103
+ The callback function for when data is modified.
103
104
  '''
104
105
  return self.__on_update_func
105
106
 
106
107
  @on_update.setter
107
108
  def on_update(self, value):
108
- ''' Set the callback function for when data is modified.
109
+ ''' !!! Internal use only !!!!
110
+ Set the callback function for when data is modified.
109
111
  '''
110
112
  if value is None or callable(value):
111
113
  self.__on_update_func = value
112
114
 
113
115
  @property
114
116
  def dirty(self):
115
- ''' Returns if the chart needs updating or not.
117
+ ''' !!! Internal use only !!!!
118
+ Returns if the chart needs updating or not.
116
119
  '''
117
120
  return self.__dirty
118
121
 
@@ -143,7 +146,8 @@ class MatPlotLibChart(wx.Panel):
143
146
  self.__dirty = False
144
147
 
145
148
  def do_redraw(self):
146
- ''' Is called when the chart must be redrawn.
149
+ ''' !!! Internal use only !!!!
150
+ Is called when the chart must be redrawn.
147
151
  Standard implementation below.
148
152
  May be overridden for special kinds of charts.
149
153
  '''
@@ -12,13 +12,13 @@ from .chart import Chart
12
12
 
13
13
  class ScatterChart(Chart):
14
14
 
15
- def do_add_series(self, name):
15
+ def do_add_series(self, name:str) -> ScatterSeries:
16
16
  ''' Create a new series for this chart.
17
17
  Base class will add it to the list of series
18
18
  '''
19
19
  return ScatterSeries(self, name, color=self.get_series_color() )
20
20
 
21
- def get_data_as_text(self):
21
+ def get_data_as_text(self)->str:
22
22
  ''' Returns the data of all series as text.
23
23
  '''
24
24
  lines = "" # the resulting text
@@ -28,20 +28,20 @@ class ScatterSeries(object):
28
28
  return self.__name
29
29
 
30
30
  def get_plot_object(self):
31
- '''
31
+ ''' !!! Internal use only !!!
32
32
  Gets the object to draw on the chart.
33
33
  '''
34
34
  line = wxplot.PolyLine(self.__points, colour=self.__color, width=2, style=wx.PENSTYLE_SOLID, legend=self.name)
35
35
 
36
36
  return line
37
37
 
38
- def add_point(self, x, y):
38
+ def add_point(self, x:float, y:float):
39
39
  ''' Add a data point (for a scatter graph)
40
40
  '''
41
41
  self.__points.append( (x, y) )
42
42
  self.__chart.update()
43
43
 
44
- def add_points(self, xypoints):
44
+ def add_points(self, xypoints:list):
45
45
  ''' Add a list of data points (for a scatter graph)
46
46
  xypoints must be a list of tuples (x, y)
47
47
  '''
@@ -15,7 +15,7 @@ class TimeChart(Chart):
15
15
 
16
16
  start_time = None
17
17
 
18
- def do_add_series(self, name):
18
+ def do_add_series(self, name:str) -> TimeSeries:
19
19
  ''' Create a new series for this chart.
20
20
  Base class will add it to the list of series
21
21
  '''
@@ -23,7 +23,7 @@ class TimeChart(Chart):
23
23
  self.start_time = time.time()
24
24
  return TimeSeries(self, name, self.get_series_color(), self.start_time)
25
25
 
26
- def get_data_as_text(self):
26
+ def get_data_as_text(self)->str:
27
27
  ''' Returns the data of all series as text.
28
28
  '''
29
29
  lines = "" # the resulting text
@@ -29,14 +29,14 @@ class TimeSeries(object):
29
29
  return self.__name
30
30
 
31
31
  def get_plot_object(self):
32
- '''
32
+ ''' !!! Internal use only !!!
33
33
  Gets the object to draw on the chart.
34
34
  '''
35
35
  line = wxplot.PolyLine(self.__points, colour=self.__color, width=2, style=wx.PENSTYLE_SOLID, legend=self.name)
36
36
 
37
37
  return line
38
38
 
39
- def add_value(self, value, t=None):
39
+ def add_value(self, value:float, t:float=None):
40
40
  ''' Add a value for a time chart.
41
41
  Time is by default the actual time. Any time as returned by time.time() can be used.
42
42
  The start time of creating the chart is subtracted from the time.
@@ -47,7 +47,7 @@ class TimeSeries(object):
47
47
  self.__points.append( (t-self.__start_time, value) )
48
48
  self.__chart.update()
49
49
 
50
- def add_values(self, value_time_list):
50
+ def add_values(self, value_time_list:list):
51
51
  ''' Add a list of data points (for a time series graph)
52
52
  timevalue_time_list_value_points must be a list of tuples with value as first element
53
53
  and time as second element.
@@ -19,41 +19,53 @@ class ScriptControl:
19
19
  self._script_runner = None
20
20
 
21
21
  def set_script_runner(self, runner):
22
- ''' sets the ScriptRunner object that is used for running scripts
22
+ ''' !!! Internal use only !!!
23
+ sets the ScriptRunner object that is used for running scripts
23
24
  '''
24
25
  self._script_runner = runner
25
26
 
26
27
  def set_busy(self, is_busy):
28
+ ''' !!! Internal use only !!!
29
+ '''
27
30
  self._is_busy = is_busy
28
31
  self.m_stop_script = False
29
32
 
30
33
  def is_busy(self):
34
+ ''' !!! Internal use only !!!
35
+ '''
31
36
  return self._is_busy
32
37
 
33
38
  def stop(self):
39
+ ''' !!! Internal use only !!!
40
+ '''
34
41
  if self._is_busy:
35
42
  print("'stop' flag is set. Scripts may stop soon.")
36
43
  else:
37
44
  print("Normally no script is active, but I'll set the 'stop' flag anyway.")
38
45
  self.m_stop_script = True
39
46
 
40
- def ok(self):
41
- ''' For use in a loop with blocking functions. ok() will return True until the 'stop' button
42
- is pressed. Exit your script loop when ok() returns False
47
+ def ok(self) -> bool:
48
+ ''' To test if the script should stop. ok() will return True until the 'stop' button
49
+ is pressed. Exit your script loop when ok() returns False.
43
50
  '''
44
51
  # wx.Yield()
45
52
  return not self.m_stop_script
46
53
 
47
54
  def check(self):
48
- ''' For use in a loop with blocking functions. check() will raise an exception when the 'abort'
49
- button is pressed
55
+ ''' This function will check if the 'stop' button is pressed.
56
+ If it is, an exception is raised, which will stop the script, and the script will
57
+ be considered to have failed.
58
+ Typically you call this regularly in a loop, so the script can be stopped
59
+ without having to write a lot of code for error handling.
50
60
  '''
51
61
  # wx.Yield()
52
62
  if self.m_stop_script:
53
63
  raise ScriptUserAbortException( "Script stopping on user request" )
54
64
 
55
- def sleep(self, time_in_seconds):
56
- ''' Allows a script to pause for some time, while still providing a fast "abort".
65
+ def sleep(self, time_in_seconds : float):
66
+ ''' Sleeps for the specified number of seconds.
67
+ When the stop button is pressed, an exception will be raised and the
68
+ script will be stopped (almost) immediately.
57
69
  '''
58
70
  t = time_in_seconds
59
71
 
@@ -69,8 +81,16 @@ class ScriptControl:
69
81
  if self.m_stop_script:
70
82
  raise ScriptUserAbortException( "Script stopping on user request" )
71
83
 
72
- def run(self, script_name, **argv):
84
+ def run(self, script_name:str, **argv):
73
85
  ''' Execute a script from within another script.
86
+ The script will be run in the same way as if it was started from the GUI.
87
+ The script will run in the same thread as the calling script, so the calling
88
+ script will be paused until the called script is finished.
89
+
90
+ script_name is of the form "directory.file.function"
91
+
92
+ You may pass arguments to the script using keyword arguments. If the script
93
+ needs additional parameters, ScriptManager will try to find these out by itself.
74
94
  '''
75
95
  assert self._script_runner is not None, "Internal error: scriptrunner is not set"
76
96
  return self._script_runner.run_script(script_name, **argv)
@@ -13,6 +13,12 @@ from .forms.form_askimage import FormAskImage
13
13
  from .forms.form_askchoice import FormAskChoice
14
14
  from .forms.form_stop import FormStop
15
15
 
16
+ from .charts.histogram_chart import HistogramChart
17
+ from .charts.scatter_chart import ScatterChart
18
+ from .charts.time_chart import TimeChart
19
+ from .charts.matplotlib_chart import MatPlotLibChart
20
+ from .charts.chart import Chart
21
+
16
22
  class ScriptGui:
17
23
  ''' Object with various functions to interact with the user / operator.
18
24
  '''
@@ -27,7 +33,8 @@ class ScriptGui:
27
33
  self.m_stop_dialog = None
28
34
 
29
35
  def on_gui_timer(self):
30
- ''' timer function called regularly from the mainform in the GUI thread.
36
+ ''' !!! Internal use only !!!
37
+ timer function called regularly from the mainform in the GUI thread.
31
38
  Used as a way to start dialogs from a thread in the GUI thread.
32
39
  '''
33
40
  if self.__func is not None: # if __func is filled in, it means we must do something
@@ -58,7 +65,8 @@ class ScriptGui:
58
65
  return self.__reply # normal reply
59
66
 
60
67
  def do_func(self, func, *params):
61
- ''' Runs the given function in the GUI thread if necessary.
68
+ ''' !!! Internal use only !!!
69
+ Runs the given function in the GUI thread if necessary.
62
70
  '''
63
71
  assert not threading.currentThread().getName().startswith("Parallel"), "GUI functions cannot be called from a parallel thread"
64
72
 
@@ -70,9 +78,10 @@ class ScriptGui:
70
78
  else:
71
79
  return func(*params)
72
80
 
73
- def ask(self, message, default_value="" ):
74
- ''' Allows the script to ask for user feedback.
75
- User can press cancel to stop the script.
81
+ def ask(self, message:str, default_value:str="" )->str:
82
+ ''' Asks user feedback using a text field.
83
+ User can press cancel, which will raise an exception.
84
+ The given text is returned.
76
85
  '''
77
86
  assert not threading.currentThread().getName().startswith("Parallel"), "GUI functions cannot be called from a parallel thread"
78
87
 
@@ -91,9 +100,10 @@ class ScriptGui:
91
100
 
92
101
  return result
93
102
 
94
- def ask_number(self, message, default_value=None ):
95
- ''' Allows the script to ask for user feedback.
96
- User can press cancel to stop the script.
103
+ def ask_number(self, message:str, default_value:int=None )->int:
104
+ ''' Ask user feedback using a numeric field.
105
+ User can press cancel, which will raise an exception.
106
+ The given number is returned.
97
107
  '''
98
108
  assert not threading.currentThread().getName().startswith("Parallel"), "GUI functions cannot be called from a parallel thread"
99
109
 
@@ -126,9 +136,10 @@ class ScriptGui:
126
136
 
127
137
  return result
128
138
 
129
- def ask_yesno(self, message, cancel = False):
139
+ def ask_yesno(self, message:str, cancel:bool = False) -> bool:
130
140
  ''' Ask for user feedback using a yes/no question.
131
141
  Cancel button is optional. It will raise an exception.
142
+ Returns True for 'yes', False for 'no'.
132
143
  '''
133
144
  assert not threading.currentThread().getName().startswith("Parallel"), "GUI functions cannot be called from a parallel thread"
134
145
 
@@ -147,7 +158,7 @@ class ScriptGui:
147
158
 
148
159
  raise ScriptUserAbortException( "User did not answer yes/no dialog" )
149
160
 
150
- def ask_image(self, message, filename, arrow_pos=None, yesno=False, cancel=False, numeric=False):
161
+ def ask_image(self, message:str, filename:str, arrow_pos=None, yesno=False, cancel=False, numeric=False):
151
162
  ''' Ask user feedback while showing a picture.
152
163
  Feedback could be a text, numeric value or yes/no.
153
164
  An arrow can be drawn on the image to point the user to something.
@@ -183,7 +194,7 @@ class ScriptGui:
183
194
 
184
195
  return result
185
196
 
186
- def ask_choice(self, message, choices, do_assert = True):
197
+ def ask_choice(self, message:str, choices:list, do_assert:bool = True)->int:
187
198
  ''' Ask user to select option from a list
188
199
 
189
200
  @param message Message for user. Use \n to make a multi-line message.
@@ -264,7 +275,7 @@ class ScriptGui:
264
275
  self.m_stop_dialog.Destroy()
265
276
  self.m_stop_dialog = None
266
277
 
267
- def add_scatter_chart(self, name):
278
+ def add_scatter_chart(self, name) -> ScatterChart:
268
279
  ''' Adds a scatter chart to the main dialog.
269
280
  '''
270
281
  assert not threading.currentThread().getName().startswith("Parallel"), "GUI functions cannot be called from a parallel thread"
@@ -274,7 +285,7 @@ class ScriptGui:
274
285
 
275
286
  return self._mngr.charts.add_scatter_chart(name)
276
287
 
277
- def add_time_chart(self, name):
288
+ def add_time_chart(self, name) -> TimeChart:
278
289
  ''' Adds a time chart to the main dialog.
279
290
  '''
280
291
  assert not threading.currentThread().getName().startswith("Parallel"), "GUI functions cannot be called from a parallel thread"
@@ -284,7 +295,7 @@ class ScriptGui:
284
295
 
285
296
  return self._mngr.charts.add_time_chart(name)
286
297
 
287
- def add_histogram(self, name, binsize):
298
+ def add_histogram(self, name:str, binsize:float) -> HistogramChart:
288
299
  ''' Adds a histogram chart to the main dialog.
289
300
  '''
290
301
  assert not threading.currentThread().getName().startswith("Parallel"), "GUI functions cannot be called from a parallel thread"
@@ -294,7 +305,7 @@ class ScriptGui:
294
305
 
295
306
  return self._mngr.charts.add_histogram(name, binsize)
296
307
 
297
- def add_matplotlib(self, name):
308
+ def add_matplotlib(self, name:str) -> MatPlotLibChart:
298
309
  ''' Adds a matplotlib chart
299
310
  '''
300
311
  assert not threading.currentThread().getName().startswith("Parallel"), "GUI functions cannot be called from a parallel thread"
@@ -305,7 +316,7 @@ class ScriptGui:
305
316
  return self._mngr.charts.add_matplotlib(name)
306
317
 
307
318
 
308
- def get_chart(self, name):
319
+ def get_chart(self, name:str) -> Chart:
309
320
  ''' Returns an object representing a previously defined chart.
310
321
  @return chart object, or None if given chart was not yet defined.
311
322
  '''
@@ -313,7 +324,7 @@ class ScriptGui:
313
324
 
314
325
  return self._mngr.charts.get_chart(name)
315
326
 
316
- def delete_chart(self, name):
327
+ def delete_chart(self, name:str):
317
328
  ''' Deletes the chart with the give name
318
329
  '''
319
330
  assert not threading.currentThread().getName().startswith("Parallel"), "GUI functions cannot be called from a parallel thread"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: happyscript
3
- Version: 0.0.25
3
+ Version: 0.0.26
4
4
  Summary: Framework for running scripts
5
5
  Requires-Python: >=3.5
6
6
  Description-Content-Type: text/markdown
@@ -17,7 +17,7 @@ build-backend = "setuptools.build_meta"
17
17
  [project]
18
18
  name = "happyscript"
19
19
  description = "Framework for running scripts"
20
- version = "0.0.25"
20
+ version = "0.0.26"
21
21
  readme = "README.md"
22
22
  requires-python = ">=3.5"
23
23
  dependencies = [ ]
File without changes
File without changes