happyscript 0.0.12__tar.gz → 0.0.24__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 (74) hide show
  1. {happyscript-0.0.12 → happyscript-0.0.24}/PKG-INFO +2 -2
  2. happyscript-0.0.24/happyscript/__init__.py +10 -0
  3. {happyscript-0.0.12 → happyscript-0.0.24}/happyscript/charts/chart.py +109 -9
  4. happyscript-0.0.24/happyscript/charts/histogram_chart.py +67 -0
  5. happyscript-0.0.24/happyscript/charts/histogram_series.py +114 -0
  6. happyscript-0.0.24/happyscript/charts/matplotlib_chart.py +181 -0
  7. happyscript-0.0.24/happyscript/charts/panel_charts.py +242 -0
  8. happyscript-0.0.24/happyscript/charts/scatter_chart.py +47 -0
  9. happyscript-0.0.24/happyscript/charts/scatter_series.py +66 -0
  10. happyscript-0.0.24/happyscript/charts/time_chart.py +98 -0
  11. happyscript-0.0.24/happyscript/charts/time_series.py +76 -0
  12. {happyscript-0.0.12 → happyscript-0.0.24}/happyscript/forms/form_askchoice.py +41 -3
  13. happyscript-0.0.24/happyscript/forms/form_askimage.py +115 -0
  14. {happyscript-0.0.12 → happyscript-0.0.24}/happyscript/forms/form_main.py +160 -27
  15. {happyscript-0.0.12 → happyscript-0.0.24}/happyscript/forms/form_ontestfailure.py +38 -0
  16. {happyscript-0.0.12 → happyscript-0.0.24}/happyscript/forms/form_serials.py +92 -11
  17. happyscript-0.0.24/happyscript/forms/form_stop.py +30 -0
  18. happyscript-0.0.24/happyscript/forms/formsbase.py +709 -0
  19. {happyscript-0.0.12 → happyscript-0.0.24}/happyscript/imglib.py +73 -1
  20. {happyscript-0.0.12 → happyscript-0.0.24}/happyscript/panels/panel_log.py +62 -10
  21. happyscript-0.0.24/happyscript/panels/panel_messages.py +104 -0
  22. {happyscript-0.0.12 → happyscript-0.0.24}/happyscript/panels/panel_scripts2.py +54 -4
  23. {happyscript-0.0.12 → happyscript-0.0.24}/happyscript/panels/panel_tests.py +171 -49
  24. happyscript-0.0.24/happyscript/panels/panelsbase.py +505 -0
  25. {happyscript-0.0.12 → happyscript-0.0.24}/happyscript/scriptartwork.py +36 -8
  26. happyscript-0.0.24/happyscript/scriptcontrol.py +81 -0
  27. happyscript-0.0.24/happyscript/scriptexceptions.py +18 -0
  28. {happyscript-0.0.12 → happyscript-0.0.24}/happyscript/scriptgui.py +170 -11
  29. happyscript-0.0.24/happyscript/scriptinfo.py +170 -0
  30. happyscript-0.0.24/happyscript/scriptmanager.py +364 -0
  31. {happyscript-0.0.12 → happyscript-0.0.24}/happyscript/scriptparams.py +53 -9
  32. happyscript-0.0.24/happyscript/scriptreader.py +136 -0
  33. {happyscript-0.0.12 → happyscript-0.0.24}/happyscript/scriptrunner.py +114 -33
  34. happyscript-0.0.24/happyscript/splashmenu/forms.py +69 -0
  35. {happyscript-0.0.12 → happyscript-0.0.24}/happyscript/splashmenu/splashmenuform.py +77 -20
  36. happyscript-0.0.24/happyscript/splashmenu/splashmenumain.py +57 -0
  37. happyscript-0.0.24/happyscript/testlog/global_log_handler.py +107 -0
  38. {happyscript-0.0.12 → happyscript-0.0.24}/happyscript/testlog/log_to_text.py +50 -4
  39. {happyscript-0.0.12 → happyscript-0.0.24}/happyscript/testlog/logtoxml.py +36 -0
  40. happyscript-0.0.24/happyscript/testlog/printredirect.py +74 -0
  41. {happyscript-0.0.12 → happyscript-0.0.24}/happyscript.egg-info/PKG-INFO +2 -2
  42. {happyscript-0.0.12 → happyscript-0.0.24}/happyscript.egg-info/SOURCES.txt +0 -3
  43. {happyscript-0.0.12 → happyscript-0.0.24}/pyproject.toml +8 -2
  44. happyscript-0.0.12/copy_code.py +0 -196
  45. happyscript-0.0.12/happyscript/__init__.py +0 -3
  46. happyscript-0.0.12/happyscript/charts/histogram_chart.py +0 -39
  47. happyscript-0.0.12/happyscript/charts/histogram_series.py +0 -54
  48. happyscript-0.0.12/happyscript/charts/matplotlib_chart.py +0 -82
  49. happyscript-0.0.12/happyscript/charts/panel_charts.py +0 -110
  50. happyscript-0.0.12/happyscript/charts/scatter_chart.py +0 -27
  51. happyscript-0.0.12/happyscript/charts/scatter_series.py +0 -22
  52. happyscript-0.0.12/happyscript/charts/time_chart.py +0 -59
  53. happyscript-0.0.12/happyscript/charts/time_series.py +0 -26
  54. happyscript-0.0.12/happyscript/forms/form_askimage.py +0 -66
  55. happyscript-0.0.12/happyscript/forms/form_stop.py +0 -11
  56. happyscript-0.0.12/happyscript/forms/formsbase.py +0 -396
  57. happyscript-0.0.12/happyscript/panels/panel_messages.py +0 -56
  58. happyscript-0.0.12/happyscript/panels/panelsbase.py +0 -286
  59. happyscript-0.0.12/happyscript/scriptcontrol.py +0 -40
  60. happyscript-0.0.12/happyscript/scriptexceptions.py +0 -10
  61. happyscript-0.0.12/happyscript/scriptinfo.py +0 -94
  62. happyscript-0.0.12/happyscript/scriptmanager.py +0 -167
  63. happyscript-0.0.12/happyscript/scriptreader.py +0 -83
  64. happyscript-0.0.12/happyscript/splashmenu/forms.py +0 -30
  65. happyscript-0.0.12/happyscript/splashmenu/splashmenumain.py +0 -31
  66. happyscript-0.0.12/happyscript/testlog/global_log_handler.py +0 -61
  67. happyscript-0.0.12/happyscript/testlog/printredirect.py +0 -43
  68. happyscript-0.0.12/increment_version.py +0 -58
  69. happyscript-0.0.12/publish.bat +0 -6
  70. {happyscript-0.0.12 → happyscript-0.0.24}/README.md +0 -0
  71. {happyscript-0.0.12 → happyscript-0.0.24}/happyscript/charts/__init__.py +0 -0
  72. {happyscript-0.0.12 → happyscript-0.0.24}/happyscript.egg-info/dependency_links.txt +0 -0
  73. {happyscript-0.0.12 → happyscript-0.0.24}/happyscript.egg-info/top_level.txt +0 -0
  74. {happyscript-0.0.12 → happyscript-0.0.24}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.2
2
2
  Name: happyscript
3
- Version: 0.0.12
3
+ Version: 0.0.24
4
4
  Summary: Framework for running scripts
5
5
  Requires-Python: >=3.5
6
6
  Description-Content-Type: text/markdown
@@ -0,0 +1,10 @@
1
+ """HappyScript - handy script launcher"""
2
+
3
+ __version__ = "0.0.24"
4
+
5
+ # With these statements, after doing 'import happyscript' you can do 'xxx = happyscript.ScriptManager()'
6
+ #from .scriptmanager import ScriptManager
7
+ #from .pytestsupport import *
8
+
9
+ from .scriptmanager import ScriptManager
10
+ from .splashmenu.splashmenumain import SplashMenu
@@ -1,34 +1,68 @@
1
+ # ____ _ _
2
+ # | _ \ ___| | _(_)_ __ ___ ___ Copyright | Title : Object to hold a chart shown on a panel_chart
3
+ # | | | |/ _ \ |/ / | '_ ` _ \ / _ \ (c) 2020 | Project : na
4
+ # | |_| | __/ <| | | | | | | (_) | Dekimo | Authors : MVR
5
+ # |____/ \___|_|\_\_|_| |_| |_|\___/ Products | Created : 2/1/2022
6
+ #__________________________________________________|_________________________________________________________
7
+ #
8
+ #
9
+
1
10
  import wx
2
11
  from wx.lib import plot as wxplot
12
+
3
13
  class Chart(wxplot.PlotCanvas):
14
+ ''' Base object for all charts.
15
+ Derived chart has to implement :
16
+ * do_redraw (optionally)
17
+ * do_add_series
18
+ * get_data_as_text
19
+ '''
20
+
4
21
  COLORS = ( wx.Colour(68,114,196), wx.Colour(237,125,49), wx.Colour(165,165,165), wx.Colour(255,193,4),
5
22
  wx.Colour(91,155,213), wx.Colour(112,173,71), wx.Colour(38,68,120), wx.Colour(158,72,14),
6
23
  wx.Colour(99,99,99), wx.Colour(153,115,0), wx.Colour(37,94,145), wx.Colour(67,104,43),
7
24
  wx.Colour(105,142,208), wx.Colour(241,151,90), wx.Colour(183,183,183), wx.Colour(255,205,51),
8
25
  wx.Colour(124,175,221),
9
26
  )
27
+
28
+
10
29
  def __init__(self, parent_control, name):
30
+ '''
31
+ Constructor
32
+ '''
11
33
  super().__init__(parent_control, -1)
34
+
12
35
  self.__name = name
36
+
13
37
  self.enableLegend = True
14
38
  self.enableGrid = True
15
39
  self.antiAlias = False
40
+
16
41
  self._series = dict()
17
42
  self.__dirty = False
18
43
  self.__on_update_func = None
19
- self.__num_series_added = 0
44
+ self.__num_series_added = 0 # count num of series added, to select next color
45
+
20
46
  self._xrange = None
21
47
  self._yrange = None
22
48
  self.configure(title=name, x_label="", y_label="", x_log=False, y_log=False)
49
+
23
50
  def get_series_color(self):
51
+ ''' Get next color to use for a newly added series.
52
+ '''
24
53
  idx = self.__num_series_added % len(self.COLORS)
25
54
  self.__num_series_added += 1
26
55
  return self.COLORS[idx]
56
+
27
57
  @property
28
58
  def name(self):
29
59
  return self.__name
60
+
30
61
  def configure(self, /, x_label=None, y_label=None, title=None,
31
62
  y_log=None, x_log=None, x_range=None, y_range=None):
63
+ '''
64
+
65
+ '''
32
66
  if title is not None:
33
67
  self._title = title if isinstance(title, str) else str(title)
34
68
  self.enablePlotTitle = True if len(self._title)>0 else False
@@ -42,6 +76,7 @@ class Chart(wxplot.PlotCanvas):
42
76
  self._xlog = True if x_log else False
43
77
  if y_log is not None:
44
78
  self._ylog = True if y_log else False
79
+
45
80
  if x_range is not None:
46
81
  ok = False
47
82
  if type(x_range) is tuple and len(x_range)==2:
@@ -53,6 +88,7 @@ class Chart(wxplot.PlotCanvas):
53
88
  pass
54
89
  if not ok:
55
90
  print(f"x_range {x_range} is invalid")
91
+
56
92
  if y_range is not None:
57
93
  ok = False
58
94
  if type(y_range) is tuple and len(y_range)==2:
@@ -64,66 +100,130 @@ class Chart(wxplot.PlotCanvas):
64
100
  pass
65
101
  if not ok:
66
102
  print(f"y_range {y_range} is invalid")
103
+
67
104
  self.logScale = (self._xlog, self._ylog)
68
105
  if len(self._series)>0:
69
106
  self.update()
107
+
70
108
  @property
71
109
  def on_update(self):
110
+ ''' The callback function for when data is modified.
111
+ '''
72
112
  return self.__on_update_func
113
+
73
114
  @on_update.setter
74
115
  def on_update(self, value):
116
+ ''' Set the callback function for when data is modified.
117
+ '''
75
118
  if value is None or callable(value):
76
119
  self.__on_update_func = value
120
+
77
121
  @property
78
122
  def dirty(self):
123
+ ''' Returns if the chart needs updating or not.
124
+ '''
79
125
  return self.__dirty
126
+
80
127
  def update(self, / , antialiasing=False):
128
+ ''' Indicate that a chart should be updated. To be executed by a chart series when data is added.
129
+ The internal 'dirty' flag is set.
130
+ Also, the on_update callback function is called (if one is set).
131
+
132
+ In a a chart panel, the callback function will set a flag to indicate that the chart must
133
+ be updated.
134
+ '''
81
135
  self.antiAlias = antialiasing
82
136
  self.__dirty = True
83
137
  if self.__on_update_func is not None:
84
138
  self.__on_update_func()
139
+
85
140
  def redraw(self):
141
+ ''' Redraw the chart.
142
+ Updates of the charts are 'lazy' : they are not recalculated when data is added.
143
+ The GUI calls this function to ask for the chart to be redrawn.
144
+ The internal 'dirty' flag is cleared.
145
+ '''
86
146
  self.enableAntiAliasing = self.antiAlias
87
147
  self.antiAlias = False
88
148
  self.do_redraw()
149
+ # print(f"redraw {self.enableAntiAliasing}")
89
150
  self.__dirty = False
151
+
152
+
90
153
  def do_redraw(self):
154
+ ''' Is called when the chart must be redrawn.
155
+ Standard implementation below.
156
+ May be overridden for special kinds of charts.
157
+ '''
91
158
  plot_objects = list()
92
159
  try:
93
160
  for series in self._series.values():
94
161
  if len(series.get_points())>0:
95
162
  plot_objects.append( series.get_plot_object() )
96
- except RuntimeError:
163
+
164
+ except RuntimeError: # occurs sometimes when data is updated during redraw
97
165
  return
166
+
98
167
  if len(plot_objects)>0:
99
168
  pg = wxplot.PlotGraphics(plot_objects, self._title, self._xlabel, self._ylabel)
100
169
  try:
101
170
  self.Draw(pg, xAxis=self._xrange, yAxis=self._yrange)
102
171
  except:
103
172
  pass
173
+
174
+ # def clear(self):
175
+ # ''' remove all series from the chart
176
+ # '''
177
+ # for name in self._series.keys():
178
+ # del self._series[name] # delete it
179
+ # if hasattr(self, name):
180
+ # delattr(self, name) # delete member variable as well
181
+
104
182
  def delete_series(self, name):
105
- if name in self._series:
106
- del self._series[name]
183
+ ''' Remove a series from a chart.
184
+ '''
185
+ if name in self._series: # check if we have a series with that name
186
+ del self._series[name] # delete it
107
187
  if hasattr(self, name):
108
- delattr(self, name)
188
+ delattr(self, name) # delete member variable as well
189
+
109
190
  def add_series(self, name):
110
- if ( not name.isidentifier() or
191
+ ''' Create a new series for this chart.
192
+ First checks if name is valid, then calls do_add_series of derived class to create the series.
193
+ Series is added as attribute to the chart itself.
194
+ '''
195
+ if ( not name.isidentifier() or # first check if name is valid
111
196
  name in ['update', 'redraw', 'add_series', 'delete_series'] or
112
197
  ( hasattr(self, name) and name not in self._series) ):
113
198
  raise ValueError("Series name '%s' is invalid" % name)
114
- self.delete_series(name)
115
- series = self.do_add_series(name)
199
+
200
+ self.delete_series(name) # delete old series if necessary
201
+
202
+ series = self.do_add_series(name) # create the series and remember it
203
+
116
204
  if series is not None:
117
205
  self._series[name] = series
118
- setattr(self, name, series)
206
+ setattr(self, name, series) # also set it as a member variable
207
+
119
208
  self.update()
120
209
  return series
210
+
121
211
  def do_add_series(self, name):
212
+ ''' To be implemented by derived class.
213
+ '''
122
214
  return None
215
+
123
216
  def get_series(self, name):
217
+ ''' Return a series by name, or None if it doesn't exist
218
+ '''
124
219
  if name in self._series:
125
220
  return self._series[name]
126
221
  else:
127
222
  return None
223
+
128
224
  def get_data_as_text(self):
225
+ ''' Returns the data of all series as text.
226
+ TO BE IMPLEMENTED FOR EACH CHART TYPE
227
+ Data must be separated by a tab for easy Excel import
228
+ '''
129
229
  return ""
@@ -0,0 +1,67 @@
1
+ # ____ _ _
2
+ # | _ \ ___| | _(_)_ __ ___ ___ Copyright | Title : Object to hold a chart shown on a panel_chart
3
+ # | | | |/ _ \ |/ / | '_ ` _ \ / _ \ (c) 2020 | Project : na
4
+ # | |_| | __/ <| | | | | | | (_) | Dekimo | Authors : MVR
5
+ # |____/ \___|_|\_\_|_| |_| |_|\___/ Products | Created : 2/1/2022
6
+ #__________________________________________________|_________________________________________________________
7
+ #
8
+ #
9
+ # https://medium.com/@maxmarkovvision/optimal-number-of-bins-for-histograms-3d7c48086fde
10
+
11
+ from .histogram_series import HistogramSeries
12
+ from .chart import Chart
13
+
14
+ class HistogramChart(Chart):
15
+
16
+ def __init__(self, parent_control, name, binsize):
17
+
18
+ super().__init__(parent_control, name)
19
+ self.__binsize = binsize
20
+
21
+ self._xlabel = "Value"
22
+ self._ylabel = "Count"
23
+
24
+ def do_add_series(self, name):
25
+ ''' Create a new series for this chart.
26
+ Base class will add it to the list of series
27
+ '''
28
+ return HistogramSeries(self, name, self.__binsize, color=self.get_series_color() )
29
+
30
+ def get_data_as_text(self):
31
+ ''' Returns the data of all series as text.
32
+ '''
33
+ lines = "" # the resulting text
34
+ data = list() # the data for each series
35
+ min_x = None
36
+ max_x = None
37
+
38
+ line = "Value" # add line with all the names
39
+ for ser in self._series:
40
+ line += "\t" + ser
41
+ lines += line.strip() + "\r\n"
42
+
43
+ for ser in self._series.values(): # get data and min/max of all series
44
+ points = ser.get_points()
45
+ if min_x is None:
46
+ min_x = min(points.keys())
47
+ else:
48
+ min_x = min( min_x, min(points.keys()))
49
+
50
+ if max_x is None:
51
+ max_x = max(points.keys())
52
+ else:
53
+ max_x = max( max_x, max(points.keys()))
54
+
55
+ data.append( points )
56
+
57
+ for x in range(min_x,max_x+1): # write out all the data points
58
+
59
+ line = str( x * self.__binsize )
60
+ for pts in data:
61
+ if x in pts:
62
+ line += "\t%d" % pts[x]
63
+ else:
64
+ line += "\t0"
65
+ lines += line.strip() + "\r\n"
66
+
67
+ return lines
@@ -0,0 +1,114 @@
1
+ # ____ _ _
2
+ # | _ \ ___| | _(_)_ __ ___ ___ Copyright | Title : Series for a chart
3
+ # | | | |/ _ \ |/ / | '_ ` _ \ / _ \ (c) 2020 | Project : na
4
+ # | |_| | __/ <| | | | | | | (_) | Dekimo | Authors : MVR
5
+ # |____/ \___|_|\_\_|_| |_| |_|\___/ Products | Created : 2/1/2022
6
+ #__________________________________________________|_________________________________________________________
7
+ #
8
+ # A data series to show on a chart
9
+ #
10
+
11
+ import wx
12
+ from wx.lib import plot as wxplot
13
+
14
+
15
+ class HistogramSeries(object):
16
+
17
+ def __init__(self, chart, name, binsize, color):
18
+ '''
19
+ Constructor
20
+ '''
21
+ self.__chart = chart
22
+ self.__name = name
23
+ self.__points = dict()
24
+ self.__binsize = binsize
25
+ self.__color = color
26
+
27
+ @property
28
+ def name(self):
29
+ return self.__name
30
+
31
+ def get_plot_object(self):
32
+ '''
33
+ Gets the object to draw on the chart.
34
+ '''
35
+ bs = self.__binsize # shorthand
36
+ data = list() # list with all points for the plot
37
+
38
+ # prev = 0.5
39
+ # for k in sorted(self.__points.keys()): # go over all points by key value
40
+ #
41
+ # if k != prev+1: # if gap between previous point
42
+ # data.append( ((prev+1)*bs,0) ) # add a 0 after previous point
43
+ # if k != prev+2:
44
+ # data.append( ((k-1)*bs,0) ) # and also before new point if gap > 2
45
+ # data.append( (k * bs, self.__points[k]) ) # add data point
46
+ # prev = k
47
+ # data.append( ((prev+1)*bs,0) ) # add final 0 after last point
48
+ #
49
+ # line = wxplot.PolySpline(data, colour=self.__color, width=2, style=wx.PENSTYLE_SOLID, legend=self.name)
50
+
51
+ prev = None
52
+ prev_val = None
53
+ for k in sorted(self.__points.keys()): # go over all points by key value
54
+
55
+ if prev is None: # start at 0 for first point
56
+ data.append( (k*bs,0) )
57
+ data.append( (k*bs, self.__points[k]) ) # add data point on left
58
+ elif k != prev+1: # if gap between previous point
59
+ data.append( ((prev+1)*bs,0) ) # add a 0 after previous point
60
+ data.append( (k*bs,0) ) # this series starts at 0
61
+ data.append( (k*bs, self.__points[k]) ) # add data point on left
62
+ else: # no gap
63
+ if prev_val != self.__points[k]: # new value is different
64
+ data.append( (k*bs, self.__points[k]) ) # add data point on left
65
+
66
+ data.append( ((k+1) * bs, self.__points[k]) ) # add data point on right
67
+
68
+ prev_val = self.__points[k]
69
+ prev = k
70
+
71
+ data.append( ((prev+1)*bs,0) ) # add final 0 after last point
72
+
73
+ line = wxplot.PolyLine(data, colour=self.__color, width=2, style=wx.PENSTYLE_SOLID, legend=self.name)
74
+
75
+ return line
76
+
77
+ def add_value(self, x):
78
+ ''' Add a value
79
+ '''
80
+
81
+ binnum = int( x / self.__binsize )
82
+ # if binnum>0 and binnum<100:
83
+ # self.__points[binnum] = self.__points[binnum] + 1
84
+ if binnum in self.__points:
85
+ self.__points[binnum] = self.__points[binnum] + 1
86
+ else:
87
+ self.__points[binnum] = 1
88
+
89
+ self.__chart.update()
90
+
91
+ def add_values(self, data):
92
+ ''' Add a value
93
+ '''
94
+
95
+ for x in data:
96
+ binnum = int( x / self.__binsize )
97
+ if binnum in self.__points:
98
+ self.__points[binnum] = self.__points[binnum] + 1
99
+ else:
100
+ self.__points[binnum] = 1
101
+
102
+ self.__chart.update()
103
+
104
+ def clear(self):
105
+ ''' Clear the data points.
106
+ '''
107
+ self.__points = [0 for _ in range(100)]
108
+ self.__chart.update()
109
+
110
+ def get_points(self):
111
+ ''' Returns all the data points.
112
+ '''
113
+ return self.__points
114
+
@@ -0,0 +1,181 @@
1
+ # ____ _ _
2
+ # | _ \ ___| | _(_)_ __ ___ ___ Copyright | Title : Object to hold a chart shown on a panel_chart
3
+ # | | | |/ _ \ |/ / | '_ ` _ \ / _ \ (c) 2020 | Project : na
4
+ # | |_| | __/ <| | | | | | | (_) | Dekimo | Authors : MVR
5
+ # |____/ \___|_|\_\_|_| |_| |_|\___/ Products | Created : 2/1/2022
6
+ #__________________________________________________|_________________________________________________________
7
+ #
8
+ #
9
+ import logging
10
+ import wx
11
+
12
+ try:
13
+ from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas
14
+ from matplotlib.backends.backend_wxagg import NavigationToolbar2WxAgg as NavigationToolbar
15
+ from matplotlib.figure import Figure
16
+ import matplotlib.pyplot as plt
17
+ HAVE_MATPLOTLIB = True
18
+ except ImportError:
19
+ HAVE_MATPLOTLIB = False
20
+
21
+
22
+ # fig_canvas_toolbar = dict()
23
+ #
24
+ # old_panels = dict()
25
+
26
+ class MatPlotLibChart(wx.Panel):
27
+
28
+ # @classmethod
29
+ # def create(cls, parent_control, name):
30
+ #
31
+ # if not name in old_panels:
32
+ # panel = MatPlotLibChart(parent_control, name)
33
+ # old_panels[name] = panel
34
+ #
35
+ # return old_panels[name]
36
+
37
+
38
+ def __init__(self, parent_control, name):
39
+ '''
40
+ Constructor
41
+ '''
42
+ super().__init__(parent_control, -1)
43
+
44
+ self.__name = name
45
+
46
+ self.__dirty = False
47
+ self.__on_update_func = None
48
+
49
+ if not HAVE_MATPLOTLIB:
50
+ logging.error("Matplotlib is not installed.")
51
+ self.__figure = None
52
+ return
53
+
54
+ # if name in fig_canvas_toolbar:
55
+ # f,c,t = fig_canvas_toolbar[name]
56
+ # f.clf()
57
+ # self.__figure = f
58
+ # self.canvas = c
59
+ # self.__toolbar = t
60
+ # else:
61
+ self.__figure = Figure(dpi=None, figsize=(2, 2))
62
+ # plt.figure(self.__figure)
63
+ # self.__figure = plt.figure(name, dpi=None, figsize=(2, 2))
64
+ # try:
65
+ # plt.clf()
66
+ # except:
67
+ # pass
68
+ self.__figure.set_tight_layout(True)
69
+ self.canvas = FigureCanvas(self, -1, self.__figure)
70
+ self.__toolbar = NavigationToolbar(self.canvas)
71
+ self.__toolbar.Realize()
72
+ # self.__toolbar = None
73
+
74
+ # fig_canvas_toolbar[name] = (self.__figure, self.canvas, self.__toolbar)
75
+
76
+ sizer = wx.BoxSizer(wx.VERTICAL)
77
+ sizer.Add(self.canvas, 1, wx.EXPAND)
78
+ sizer.Add(self.__toolbar, 0, wx.LEFT | wx.EXPAND)
79
+ self.SetSizer(sizer)
80
+
81
+ @property
82
+ def name(self):
83
+ return self.__name
84
+
85
+ @property
86
+ def figure(self):
87
+ return self.__figure
88
+
89
+ def configure(self, /, x_label=None, y_label=None, title=None,
90
+ y_log=None, x_log=None, x_range=None, y_range=None):
91
+ '''
92
+ '''
93
+ if not HAVE_MATPLOTLIB: return
94
+
95
+ if title is not None and isinstance(title, str):
96
+ if len(self.figure.axes)>0:
97
+ self.figure.axes[0].set_title(title)
98
+ self.update()
99
+
100
+ @property
101
+ def on_update(self):
102
+ ''' The callback function for when data is modified.
103
+ '''
104
+ return self.__on_update_func
105
+
106
+ @on_update.setter
107
+ def on_update(self, value):
108
+ ''' Set the callback function for when data is modified.
109
+ '''
110
+ if value is None or callable(value):
111
+ self.__on_update_func = value
112
+
113
+ @property
114
+ def dirty(self):
115
+ ''' Returns if the chart needs updating or not.
116
+ '''
117
+ return self.__dirty
118
+
119
+ def update(self, / , antialiasing=False):
120
+ ''' Indicate that a chart should be updated. To be executed by a chart series when data is added.
121
+ The internal 'dirty' flag is set.
122
+ Also, the on_update callback function is called (if one is set).
123
+
124
+ In a a chart panel, the callback function will set a flag to indicate that the chart must
125
+ be updated.
126
+ '''
127
+ if antialiasing:
128
+ logging.warn("Antialiasing not supported for matplotlib chart")
129
+
130
+ self.__dirty = True
131
+ if self.__on_update_func is not None:
132
+ self.__on_update_func()
133
+
134
+ def redraw(self):
135
+ ''' Redraw the chart.
136
+ Updates of the charts are 'lazy' : they are not recalculated when data is added.
137
+ The GUI calls this function to ask for the chart to be redrawn.
138
+ The internal 'dirty' flag is cleared.
139
+ '''
140
+ # self.enableAntiAliasing = self.antiAlias
141
+ self.antiAlias = False
142
+ self.do_redraw()
143
+ self.__dirty = False
144
+
145
+ def do_redraw(self):
146
+ ''' Is called when the chart must be redrawn.
147
+ Standard implementation below.
148
+ May be overridden for special kinds of charts.
149
+ '''
150
+ if not HAVE_MATPLOTLIB: return
151
+
152
+ self.canvas.draw()
153
+
154
+ def clear(self):
155
+ ''' remove all series from the chart
156
+ '''
157
+ if not HAVE_MATPLOTLIB: return
158
+
159
+ try:
160
+ self.figure.clf()
161
+ except:
162
+ pass
163
+ # # plt.figure(self.name)
164
+ # # plt.clf()
165
+ # # plt.close()
166
+ pass
167
+
168
+ def delete_series(self, name):
169
+ logging.error("Deleting series not supported for matplotlib charts")
170
+
171
+ def add_series(self, name):
172
+ logging.error("Use matplotlib API for adding series")
173
+
174
+ def get_series(self, name):
175
+ logging.error("Getting series not supported for matplotlib charts")
176
+ return None
177
+
178
+ def get_data_as_text(self):
179
+ logging.error("Getting series not supported for matplotlib charts")
180
+ return "Data not available for matplotlib charts"
181
+