happyscript 0.0.1__tar.gz → 0.0.6__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 (49) hide show
  1. {happyscript-0.0.1 → happyscript-0.0.6}/PKG-INFO +1 -1
  2. happyscript-0.0.6/copy_code.py +194 -0
  3. happyscript-0.0.6/happyscript/__init__.py +2 -0
  4. happyscript-0.0.6/happyscript/charts/__init__.py +0 -0
  5. happyscript-0.0.6/happyscript/charts/chart.py +129 -0
  6. happyscript-0.0.6/happyscript/charts/histogram_chart.py +39 -0
  7. happyscript-0.0.6/happyscript/charts/histogram_series.py +54 -0
  8. happyscript-0.0.6/happyscript/charts/panel_charts.py +100 -0
  9. happyscript-0.0.6/happyscript/charts/scatter_chart.py +27 -0
  10. happyscript-0.0.6/happyscript/charts/scatter_series.py +22 -0
  11. happyscript-0.0.6/happyscript/charts/time_chart.py +59 -0
  12. happyscript-0.0.6/happyscript/charts/time_series.py +26 -0
  13. happyscript-0.0.6/happyscript/forms/form_askchoice.py +38 -0
  14. happyscript-0.0.6/happyscript/forms/form_askimage.py +66 -0
  15. happyscript-0.0.6/happyscript/forms/form_main.py +229 -0
  16. happyscript-0.0.6/happyscript/forms/form_ontestfailure.py +28 -0
  17. happyscript-0.0.6/happyscript/forms/form_serials.py +105 -0
  18. happyscript-0.0.6/happyscript/forms/form_stop.py +11 -0
  19. happyscript-0.0.6/happyscript/forms/formsbase.py +396 -0
  20. happyscript-0.0.6/happyscript/imglib.py +971 -0
  21. happyscript-0.0.6/happyscript/panels/panel_log.py +76 -0
  22. happyscript-0.0.6/happyscript/panels/panel_messages.py +54 -0
  23. happyscript-0.0.6/happyscript/panels/panel_scripts2.py +58 -0
  24. happyscript-0.0.6/happyscript/panels/panel_tests.py +258 -0
  25. happyscript-0.0.6/happyscript/panels/panelsbase.py +286 -0
  26. happyscript-0.0.6/happyscript/scriptartwork.py +46 -0
  27. happyscript-0.0.6/happyscript/scriptcontrol.py +43 -0
  28. happyscript-0.0.6/happyscript/scriptexceptions.py +10 -0
  29. happyscript-0.0.6/happyscript/scriptgui.py +147 -0
  30. happyscript-0.0.6/happyscript/scriptinfo.py +80 -0
  31. happyscript-0.0.6/happyscript/scriptmanager.py +165 -0
  32. happyscript-0.0.6/happyscript/scriptparams.py +75 -0
  33. happyscript-0.0.6/happyscript/scriptreader.py +83 -0
  34. happyscript-0.0.6/happyscript/scriptrunner.py +98 -0
  35. happyscript-0.0.6/happyscript/testlog/global_log_handler.py +61 -0
  36. happyscript-0.0.6/happyscript/testlog/log_to_text.py +46 -0
  37. happyscript-0.0.6/happyscript/testlog/logtoxml.py +31 -0
  38. happyscript-0.0.6/happyscript/testlog/printredirect.py +43 -0
  39. {happyscript-0.0.1 → happyscript-0.0.6}/happyscript.egg-info/PKG-INFO +1 -1
  40. happyscript-0.0.6/happyscript.egg-info/SOURCES.txt +44 -0
  41. happyscript-0.0.6/increment_version.py +58 -0
  42. happyscript-0.0.6/pyproject.toml +24 -0
  43. happyscript-0.0.1/happyscript/happyscript.py +0 -3847
  44. happyscript-0.0.1/happyscript.egg-info/SOURCES.txt +0 -7
  45. happyscript-0.0.1/pyproject.toml +0 -12
  46. {happyscript-0.0.1 → happyscript-0.0.6}/README.md +0 -0
  47. {happyscript-0.0.1 → happyscript-0.0.6}/happyscript.egg-info/dependency_links.txt +0 -0
  48. {happyscript-0.0.1 → happyscript-0.0.6}/happyscript.egg-info/top_level.txt +0 -0
  49. {happyscript-0.0.1 → happyscript-0.0.6}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: happyscript
3
- Version: 0.0.1
3
+ Version: 0.0.6
4
4
  Summary: Framework for running scripts
5
5
  Requires-Python: >=3.5
6
6
  Description-Content-Type: text/markdown
@@ -0,0 +1,194 @@
1
+
2
+ # import python_minify
3
+
4
+ import shutil
5
+ import os
6
+ import python_minifier
7
+ import io, tokenize
8
+
9
+
10
+ PYPI_DIR = os.path.dirname(os.path.realpath(__file__))
11
+ SOURCE_DIR = os.path.join(os.path.dirname(os.path.realpath(__file__)),"..","happyscript")
12
+
13
+ def delete_old_code():
14
+ ''' Delete all the code in the pypi\happyscript directory.
15
+ '''
16
+
17
+ assert os.path.isdir(PYPI_DIR), f"Strange... {PYPI_DIR} should be a directory."
18
+
19
+ folder = os.path.join(PYPI_DIR, "happyscript")
20
+
21
+ print(f"Deleting all files in {folder}")
22
+
23
+ for filename in os.listdir(folder):
24
+ file_path = os.path.join(folder, filename)
25
+ try:
26
+ if os.path.isfile(file_path) or os.path.islink(file_path):
27
+ os.remove(file_path)
28
+ elif os.path.isdir(file_path):
29
+ shutil.rmtree(file_path)
30
+ except Exception as e:
31
+ print('Failed to delete %s. Reason: %s' % (file_path, e))
32
+
33
+
34
+ def list_all_source_files():
35
+ ''' Return a list with all directories and with all source files (as a tuple dirs,files).
36
+ '''
37
+ dir_list = [] # lists for storing files and dirs found
38
+ file_list = []
39
+
40
+ for root, dirs, files in os.walk(SOURCE_DIR, topdown=False): # traverse entire directory
41
+
42
+ rel_path = os.path.relpath(root, start=SOURCE_DIR) # calculate relative path
43
+
44
+ for name in files:
45
+ _, ext = os.path.splitext(name) # get file extension
46
+ if ext in (".fbp", ): # skip specific extensions
47
+ continue
48
+
49
+ # print("FILE", os.path.join(rel_path, name) )
50
+ file_list.append( os.path.join(rel_path, name) ) # remember file using relative path
51
+
52
+ for name in dirs:
53
+ # print("DIR", os.path.join(rel_path, name) )
54
+ dir_list.append( os.path.join(rel_path, name) ) # remember dir using relative path
55
+
56
+ return dir_list, file_list
57
+
58
+ def copy_full(src,dst):
59
+ ''' Complete copy of the files, without obfuscation.
60
+ '''
61
+ # shutil.copyfile(src,dst)
62
+
63
+ with open(src, 'r') as rf:
64
+ old_code = rf.read()
65
+
66
+ with open(dst, 'w') as wf:
67
+ wf.write(old_code)
68
+
69
+
70
+ def copy_minified(src,dst):
71
+ ''' Copy file, with some obfuscation of the code.
72
+ '''
73
+ with open(src, 'r') as rf:
74
+ old_code = rf.read()
75
+
76
+ new_code = python_minifier.minify(old_code,
77
+ remove_annotations = True, # If type annotations should be removed where possible
78
+ remove_pass = True, # If Pass statements should be removed where possible
79
+ remove_literal_statements = True, # If statements consisting of a single literal should be removed, including docstrings
80
+ combine_imports = True, #Combine adjacent import statements where possible
81
+ hoist_literals = False, # If str and byte literals may be hoisted to the module level where possible.
82
+ rename_locals = False, # If local names may be shortened
83
+ preserve_locals = None, # Locals names to leave unchanged when rename_locals is True (list of strings)
84
+ rename_globals = False, # If global names may be shortened
85
+ preserve_globals = None, #Global names to leave unchanged when rename_globals is True (list of strings)
86
+ remove_object_base = False, #If object as a base class may be removed
87
+ convert_posargs_to_args = False, #If positional-only arguments will be converted to normal arguments
88
+ preserve_shebang = False, #Keep any shebang interpreter directive from the source in the minified output
89
+ remove_asserts = True, # If assert statements should be removed
90
+ remove_debug = True, # If conditional statements that test '__debug__ is True' should be removed
91
+ remove_explicit_return_none = True, # If explicit return None statements should be replaced with a bare return
92
+
93
+ )
94
+
95
+ with open(dst, 'w') as wf:
96
+ wf.write(new_code)
97
+
98
+
99
+ def remove_comments_and_docstrings(source):
100
+ io_obj = io.StringIO(source)
101
+ out = ""
102
+ prev_toktype = tokenize.INDENT
103
+ last_lineno = -1
104
+ last_col = 0
105
+ for tok in tokenize.generate_tokens(io_obj.readline):
106
+ token_type = tok[0]
107
+ token_string = tok[1]
108
+ start_line, start_col = tok[2]
109
+ end_line, end_col = tok[3]
110
+ ltext = tok[4]
111
+ if start_line > last_lineno:
112
+ last_col = 0
113
+ if start_col > last_col:
114
+ out += (" " * (start_col - last_col))
115
+ if token_type == tokenize.COMMENT:
116
+ if token_string.startswith("#stop-amalgamation"):
117
+ break
118
+ elif token_type == tokenize.STRING:
119
+ if prev_toktype != tokenize.INDENT:
120
+ if prev_toktype != tokenize.NEWLINE:
121
+ if start_col > 0:
122
+ out += token_string
123
+ else:
124
+ out += token_string
125
+ prev_toktype = token_type
126
+ last_col = end_col
127
+ last_lineno = end_line
128
+ out = '\n'.join(l for l in out.splitlines() if l.strip())
129
+ return out
130
+
131
+
132
+ def copy_without_comments(src,dst):
133
+ """ Copy with comments and empty lines removed
134
+ """
135
+
136
+ inFile = open(src)
137
+ theCode = inFile.read()
138
+ theCode = theCode.replace("\t", " ")
139
+
140
+ theCode = remove_comments_and_docstrings(theCode)
141
+
142
+ with open(dst, 'w') as wf:
143
+ for line in theCode.splitlines():
144
+ if not line.strip():
145
+ continue
146
+ if line.startswith("#stop-amalgamation"):
147
+ break
148
+ if line.strip().startswith('#'):
149
+ continue
150
+
151
+ wf.write(line.rstrip())
152
+ wf.write('\n')
153
+
154
+ def copy_all_code():
155
+ ''' Copy all sources to the pypi folder.
156
+ Code wordt van commentaar gestript met een 'minifier' :
157
+ https://dflook.github.io/python-minifier/installation.html
158
+
159
+ '''
160
+ assert os.path.isdir(PYPI_DIR), f"Strange... {PYPI_DIR} should be a directory."
161
+ assert os.path.isdir(SOURCE_DIR), f"Strange... {SOURCE_DIR} should be a directory."
162
+
163
+ print(f"Copying source files from {SOURCE_DIR} to {PYPI_DIR}")
164
+
165
+ dir_list, file_list = list_all_source_files()
166
+
167
+ for name in dir_list:
168
+ if "__pycache__" in name:
169
+ continue
170
+ new_dir = os.path.join(PYPI_DIR,"happyscript",name)
171
+ print(f"Creating dir {new_dir}")
172
+ os.makedirs( new_dir, exist_ok=True )
173
+
174
+ for name in file_list:
175
+ if "__pycache__" in name:
176
+ continue
177
+ new_file = os.path.join(PYPI_DIR,"happyscript",name)
178
+ old_file = os.path.join(SOURCE_DIR,name)
179
+
180
+ assert os.path.isfile(old_file), f"Strange... {old_file} should exist"
181
+ assert not os.path.isfile(new_file), f"Strange... {new_file} should not exist"
182
+
183
+ print(f"Copying file {name}")
184
+
185
+ # copy_full(old_file,new_file)
186
+ # copy_minified(old_file,new_file)
187
+ copy_without_comments(old_file,new_file)
188
+
189
+
190
+ if __name__=="__main__":
191
+ delete_old_code()
192
+ copy_all_code()
193
+ print("Done")
194
+
@@ -0,0 +1,2 @@
1
+ __version__ = "0.0.6"
2
+ from .scriptmanager import ScriptManager
File without changes
@@ -0,0 +1,129 @@
1
+ import wx
2
+ from wx.lib import plot as wxplot
3
+ class Chart(wxplot.PlotCanvas):
4
+ COLORS = ( wx.Colour(68,114,196), wx.Colour(237,125,49), wx.Colour(165,165,165), wx.Colour(255,193,4),
5
+ wx.Colour(91,155,213), wx.Colour(112,173,71), wx.Colour(38,68,120), wx.Colour(158,72,14),
6
+ wx.Colour(99,99,99), wx.Colour(153,115,0), wx.Colour(37,94,145), wx.Colour(67,104,43),
7
+ wx.Colour(105,142,208), wx.Colour(241,151,90), wx.Colour(183,183,183), wx.Colour(255,205,51),
8
+ wx.Colour(124,175,221),
9
+ )
10
+ def __init__(self, parent_control, name):
11
+ super().__init__(parent_control, -1)
12
+ self.__name = name
13
+ self.enableLegend = True
14
+ self.enableGrid = True
15
+ self.antiAlias = False
16
+ self._series = dict()
17
+ self.__dirty = False
18
+ self.__on_update_func = None
19
+ self.__num_series_added = 0
20
+ self._xrange = None
21
+ self._yrange = None
22
+ self.configure(title=name, x_label="", y_label="", x_log=False, y_log=False)
23
+ def get_series_color(self):
24
+ idx = self.__num_series_added % len(self.COLORS)
25
+ self.__num_series_added += 1
26
+ return self.COLORS[idx]
27
+ @property
28
+ def name(self):
29
+ return self.__name
30
+ def configure(self, /, x_label=None, y_label=None, title=None,
31
+ y_log=None, x_log=None, x_range=None, y_range=None):
32
+ if title is not None:
33
+ self._title = title if isinstance(title, str) else str(title)
34
+ self.enablePlotTitle = True if len(self._title)>0 else False
35
+ if x_label is not None:
36
+ self._xlabel = x_label if isinstance(x_label, str) else str(x_label)
37
+ self.enableXAxisLabel = True if len(self._xlabel)>0 else False
38
+ if y_label is not None:
39
+ self._ylabel = y_label if isinstance(y_label, str) else str(y_label)
40
+ self.enableYAxisLabel = True if len(self._ylabel)>0 else False
41
+ if x_log is not None:
42
+ self._xlog = True if x_log else False
43
+ if y_log is not None:
44
+ self._ylog = True if y_log else False
45
+ if x_range is not None:
46
+ ok = False
47
+ if type(x_range) is tuple and len(x_range)==2:
48
+ try:
49
+ if x_range[0]+1 < x_range[1]+1:
50
+ self._xrange = x_range
51
+ ok = True
52
+ except:
53
+ pass
54
+ if not ok:
55
+ print(f"x_range {x_range} is invalid")
56
+ if y_range is not None:
57
+ ok = False
58
+ if type(y_range) is tuple and len(y_range)==2:
59
+ try:
60
+ if y_range[0]+1 < y_range[1]+1:
61
+ self._yrange = y_range
62
+ ok = True
63
+ except:
64
+ pass
65
+ if not ok:
66
+ print(f"y_range {y_range} is invalid")
67
+ self.logScale = (self._xlog, self._ylog)
68
+ if len(self._series)>0:
69
+ self.update()
70
+ @property
71
+ def on_update(self):
72
+ return self.__on_update_func
73
+ @on_update.setter
74
+ def on_update(self, value):
75
+ if value is None or callable(value):
76
+ self.__on_update_func = value
77
+ @property
78
+ def dirty(self):
79
+ return self.__dirty
80
+ def update(self, / , antialiasing=False):
81
+ self.antiAlias = antialiasing
82
+ self.__dirty = True
83
+ if self.__on_update_func is not None:
84
+ self.__on_update_func()
85
+ def redraw(self):
86
+ self.enableAntiAliasing = self.antiAlias
87
+ self.antiAlias = False
88
+ self.do_redraw()
89
+ self.__dirty = False
90
+ def do_redraw(self):
91
+ plot_objects = list()
92
+ try:
93
+ for series in self._series.values():
94
+ if len(series.get_points())>0:
95
+ plot_objects.append( series.get_plot_object() )
96
+ except RuntimeError:
97
+ return
98
+ if len(plot_objects)>0:
99
+ pg = wxplot.PlotGraphics(plot_objects, self._title, self._xlabel, self._ylabel)
100
+ try:
101
+ self.Draw(pg, xAxis=self._xrange, yAxis=self._yrange)
102
+ except:
103
+ pass
104
+ def delete_series(self, name):
105
+ if name in self._series:
106
+ del self._series[name]
107
+ if hasattr(self, name):
108
+ delattr(self, name)
109
+ def add_series(self, name):
110
+ if ( not name.isidentifier() or
111
+ name in ['update', 'redraw', 'add_series', 'delete_series'] or
112
+ ( hasattr(self, name) and name not in self._series) ):
113
+ raise ValueError("Series name '%s' is invalid" % name)
114
+ self.delete_series(name)
115
+ series = self.do_add_series(name)
116
+ if series is not None:
117
+ self._series[name] = series
118
+ setattr(self, name, series)
119
+ self.update()
120
+ return series
121
+ def do_add_series(self, name):
122
+ return None
123
+ def get_series(self, name):
124
+ if name in self._series:
125
+ return self._series[name]
126
+ else:
127
+ return None
128
+ def get_data_as_text(self):
129
+ return ""
@@ -0,0 +1,39 @@
1
+ from .histogram_series import HistogramSeries
2
+ from .chart import Chart
3
+ class HistogramChart(Chart):
4
+ def __init__(self, parent_control, name, binsize):
5
+ super().__init__(parent_control, name)
6
+ self.__binsize = binsize
7
+ self._xlabel = "Value"
8
+ self._ylabel = "Count"
9
+ def do_add_series(self, name):
10
+ return HistogramSeries(self, name, self.__binsize, color=self.get_series_color() )
11
+ def get_data_as_text(self):
12
+ lines = ""
13
+ data = list()
14
+ min_x = None
15
+ max_x = None
16
+ line = "Value"
17
+ for ser in self._series:
18
+ line += "\t" + ser
19
+ lines += line.strip() + "\r\n"
20
+ for ser in self._series.values():
21
+ points = ser.get_points()
22
+ if min_x is None:
23
+ min_x = min(points.keys())
24
+ else:
25
+ min_x = min( min_x, min(points.keys()))
26
+ if max_x is None:
27
+ max_x = max(points.keys())
28
+ else:
29
+ max_x = max( max_x, max(points.keys()))
30
+ data.append( points )
31
+ for x in range(min_x,max_x+1):
32
+ line = str( x * self.__binsize )
33
+ for pts in data:
34
+ if x in pts:
35
+ line += "\t%d" % pts[x]
36
+ else:
37
+ line += "\t0"
38
+ lines += line.strip() + "\r\n"
39
+ return lines
@@ -0,0 +1,54 @@
1
+ import wx
2
+ from wx.lib import plot as wxplot
3
+ class HistogramSeries(object):
4
+ def __init__(self, chart, name, binsize, color):
5
+ self.__chart = chart
6
+ self.__name = name
7
+ self.__points = dict()
8
+ self.__binsize = binsize
9
+ self.__color = color
10
+ @property
11
+ def name(self):
12
+ return self.__name
13
+ def get_plot_object(self):
14
+ bs = self.__binsize
15
+ data = list()
16
+ prev = None
17
+ prev_val = None
18
+ for k in sorted(self.__points.keys()):
19
+ if prev is None:
20
+ data.append( (k*bs,0) )
21
+ data.append( (k*bs, self.__points[k]) )
22
+ elif k != prev+1:
23
+ data.append( ((prev+1)*bs,0) )
24
+ data.append( (k*bs,0) )
25
+ data.append( (k*bs, self.__points[k]) )
26
+ else:
27
+ if prev_val != self.__points[k]:
28
+ data.append( (k*bs, self.__points[k]) )
29
+ data.append( ((k+1) * bs, self.__points[k]) )
30
+ prev_val = self.__points[k]
31
+ prev = k
32
+ data.append( ((prev+1)*bs,0) )
33
+ line = wxplot.PolyLine(data, colour=self.__color, width=2, style=wx.PENSTYLE_SOLID, legend=self.name)
34
+ return line
35
+ def add_value(self, x):
36
+ binnum = int( x / self.__binsize )
37
+ if binnum in self.__points:
38
+ self.__points[binnum] = self.__points[binnum] + 1
39
+ else:
40
+ self.__points[binnum] = 1
41
+ self.__chart.update()
42
+ def add_values(self, data):
43
+ for x in data:
44
+ binnum = int( x / self.__binsize )
45
+ if binnum in self.__points:
46
+ self.__points[binnum] = self.__points[binnum] + 1
47
+ else:
48
+ self.__points[binnum] = 1
49
+ self.__chart.update()
50
+ def clear(self):
51
+ self.__points = [0 for _ in range(100)]
52
+ self.__chart.update()
53
+ def get_points(self):
54
+ return self.__points
@@ -0,0 +1,100 @@
1
+ import wx
2
+ import os
3
+ from ..panels.panelsbase import PanelCharts_Base
4
+ from ..charts.scatter_chart import ScatterChart
5
+ from ..charts.time_chart import TimeChart
6
+ from ..charts.histogram_chart import HistogramChart
7
+ class PanelCharts( PanelCharts_Base):
8
+ def __init__( self, parent):
9
+ super().__init__(parent)
10
+ self.__dirty = False
11
+ self.charts = dict()
12
+ self.default_savedir = os.getcwd()
13
+ def update(self):
14
+ self.__dirty = True
15
+ def OnRedrawTimer( self, event ):
16
+ if self.__dirty:
17
+ self.__dirty = False
18
+ for x in self.charts.values():
19
+ x.redraw()
20
+ def OnRadioBoxMouseMode( self, event ):
21
+ for chart in self.charts.values():
22
+ if self.m_rbxMouseMode.Selection==0:
23
+ chart.enableZoom = False
24
+ chart.enableDrag = False
25
+ elif self.m_rbxMouseMode.Selection==1:
26
+ chart.enableZoom = True
27
+ chart.enableDrag = False
28
+ else:
29
+ chart.enableDrag = True
30
+ chart.enableZoom = False
31
+ def BtnCopyDataClick( self, event ):
32
+ index = self.m_nbkPlots.GetSelection()
33
+ if index == wx.NOT_FOUND or self.m_nbkPlots.GetPageText(index) not in self.charts:
34
+ wx.MessageBox( "Cannot find chart on current page", "HappyScript", wx.OK | wx.ICON_ERROR )
35
+ chart = self.charts[self.m_nbkPlots.GetPageText(index)]
36
+ try:
37
+ clipdata = wx.TextDataObject()
38
+ lines = chart.get_data_as_text()
39
+ clipdata.SetText(lines)
40
+ wx.TheClipboard.Open()
41
+ wx.TheClipboard.SetData(clipdata)
42
+ wx.TheClipboard.Close()
43
+ wx.MessageBox( "Data written to clipboard", "HappyScript", wx.OK | wx.ICON_INFORMATION )
44
+ except:
45
+ wx.MessageBox( "Could not write text to clipboard", "HappyScript", wx.OK | wx.ICON_ERROR )
46
+ def OnMakePretty( self, event ):
47
+ index = self.m_nbkPlots.GetSelection()
48
+ if index == wx.NOT_FOUND or self.m_nbkPlots.GetPageText(index) not in self.charts:
49
+ wx.MessageBox( "Cannot find chart on current page", "HappyScript", wx.OK | wx.ICON_ERROR )
50
+ chart = self.charts[self.m_nbkPlots.GetPageText(index)]
51
+ chart.update(antialiasing = True)
52
+ def OnBtnSaveBitmap( self, event ):
53
+ index = self.m_nbkPlots.GetSelection()
54
+ if index == wx.NOT_FOUND or self.m_nbkPlots.GetPageText(index) not in self.charts:
55
+ wx.MessageBox( "Cannot find chart on current page", "HappyScript", wx.OK | wx.ICON_ERROR )
56
+ chart = self.charts[self.m_nbkPlots.GetPageText(index)]
57
+ try:
58
+ with wx.FileDialog(self, "Output file name", wildcard="PNG files(*.png)|*.png",
59
+ defaultDir = self.default_savedir,
60
+ style=wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT) as fdlg:
61
+ if fdlg.ShowModal() == wx.ID_OK:
62
+ filename = fdlg.GetPath()
63
+ chart.SaveFile(filename)
64
+ self.default_savedir = os.path.dirname(filename)
65
+ except:
66
+ wx.MessageBox( "Could not write bitmap", "HappyScript", wx.OK | wx.ICON_ERROR )
67
+ def get_chart(self, name):
68
+ if name in self.charts:
69
+ return self.charts[name]
70
+ else:
71
+ return None
72
+ def delete_chart(self, name):
73
+ if not name in self.charts:
74
+ return
75
+ ch = self.charts[name]
76
+ page_num = self.m_nbkPlots.FindPage(ch)
77
+ if page_num != wx.NOT_FOUND:
78
+ self.m_nbkPlots.DeletePage(page_num)
79
+ del self.charts[name]
80
+ def add_scatter_chart(self, name ):
81
+ self.delete_chart(name)
82
+ chart = ScatterChart(self.m_nbkPlots, name)
83
+ chart.on_update = self.update
84
+ self.charts[name] = chart
85
+ self.m_nbkPlots.AddPage( chart, name, True)
86
+ return chart
87
+ def add_time_chart(self, name ):
88
+ self.delete_chart(name)
89
+ chart = TimeChart(self.m_nbkPlots, name)
90
+ chart.on_update = self.update
91
+ self.charts[name] = chart
92
+ self.m_nbkPlots.AddPage( chart, name, True)
93
+ return chart
94
+ def add_histogram(self, name, binsize ):
95
+ self.delete_chart(name)
96
+ chart = HistogramChart(self.m_nbkPlots, name, binsize)
97
+ chart.on_update = self.update
98
+ self.charts[name] = chart
99
+ self.m_nbkPlots.AddPage( chart, name, True)
100
+ return chart
@@ -0,0 +1,27 @@
1
+ from .scatter_series import ScatterSeries
2
+ from .chart import Chart
3
+ class ScatterChart(Chart):
4
+ def do_add_series(self, name):
5
+ return ScatterSeries(self, name, color=self.get_series_color() )
6
+ def get_data_as_text(self):
7
+ lines = ""
8
+ all_data = list()
9
+ data_lengths = list()
10
+ line = ""
11
+ for (k,v) in self._series.items():
12
+ line += k + "_x\t" + k + "_y\t"
13
+ data = v.get_points()
14
+ all_data.append(data)
15
+ data_lengths.append(len(data))
16
+ lines += line.strip() + "\r\n"
17
+ num_series = len(data_lengths)
18
+ num_lines = max(data_lengths)
19
+ for i in range(num_lines):
20
+ line = ""
21
+ for j in range(num_series):
22
+ if data_lengths[j]>i:
23
+ line += "\t".join(map(str,all_data[j][i]))+"\t"
24
+ else:
25
+ line += "\t\t"
26
+ lines += line.strip() + "\r\n"
27
+ return lines
@@ -0,0 +1,22 @@
1
+ import wx
2
+ from wx.lib import plot as wxplot
3
+ class ScatterSeries(object):
4
+ def __init__(self, chart, name, color):
5
+ self.__chart = chart
6
+ self.__name = name
7
+ self.__points = list()
8
+ self.__color = color
9
+ @property
10
+ def name(self):
11
+ return self.__name
12
+ def get_plot_object(self):
13
+ line = wxplot.PolyLine(self.__points, colour=self.__color, width=2, style=wx.PENSTYLE_SOLID, legend=self.name)
14
+ return line
15
+ def add_point(self, x, y):
16
+ self.__points.append( (x, y) )
17
+ self.__chart.update()
18
+ def clear(self):
19
+ self.__points = list()
20
+ self.__chart.update()
21
+ def get_points(self):
22
+ return self.__points
@@ -0,0 +1,59 @@
1
+ import time
2
+ from .time_series import TimeSeries
3
+ from .chart import Chart
4
+ class TimeChart(Chart):
5
+ start_time = None
6
+ def do_add_series(self, name):
7
+ if self.start_time is None:
8
+ self.start_time = time.time()
9
+ return TimeSeries(self, name, self.get_series_color(), self.start_time)
10
+ def get_data_as_text(self):
11
+ lines = ""
12
+ all_data = list()
13
+ data_lengths = list()
14
+ next_t = list()
15
+ data_pos = list()
16
+ line = "time\t"
17
+ for (k,v) in self._series.items():
18
+ line += k + "\t"
19
+ data = v.get_points()
20
+ all_data.append(data)
21
+ data_lengths.append(len(data))
22
+ data_pos.append(0)
23
+ next_t.append(None)
24
+ lines += line.strip() + "\r\n"
25
+ num_series = len(data_lengths)
26
+ max_lines = sum(data_lengths)
27
+ for j in range(num_series):
28
+ if data_lengths[j]>0:
29
+ next_t[j] = all_data[j][0][0]
30
+ for _ in range(max_lines):
31
+ try:
32
+ t = min(x for x in next_t if x is not None)
33
+ except:
34
+ break
35
+ line = "%f" % t
36
+ for j in range(num_series):
37
+ if next_t[j] is None:
38
+ line += "\t"
39
+ continue
40
+ if next_t[j] <= t+0.0001:
41
+ pos = data_pos[j]
42
+ line += "\t" + str(all_data[j][pos][1])
43
+ pos += 1
44
+ if pos<data_lengths[j]:
45
+ data_pos[j] = pos
46
+ next_t[j] = all_data[j][pos][0]
47
+ else:
48
+ next_t[j] = None
49
+ else:
50
+ line += "\t"
51
+ lines += line.strip() + "\r\n"
52
+ return lines
53
+ def add_values(self, t=None, **values):
54
+ if t is None:
55
+ t = time.time()
56
+ for name, value in values.items():
57
+ series = self.get_series(name)
58
+ if series is not None:
59
+ series.add_value(value, t)
@@ -0,0 +1,26 @@
1
+ import time
2
+ import wx
3
+ from wx.lib import plot as wxplot
4
+ class TimeSeries(object):
5
+ def __init__(self, chart, name, color, start_time=None):
6
+ self.__chart = chart
7
+ self.__name = name
8
+ self.__points = list()
9
+ self.__color = color
10
+ self.__start_time = time.time() if start_time is None else start_time
11
+ @property
12
+ def name(self):
13
+ return self.__name
14
+ def get_plot_object(self):
15
+ line = wxplot.PolyLine(self.__points, colour=self.__color, width=2, style=wx.PENSTYLE_SOLID, legend=self.name)
16
+ return line
17
+ def add_value(self, value, t=None):
18
+ if t is None:
19
+ t = time.time()
20
+ self.__points.append( (t-self.__start_time, value) )
21
+ self.__chart.update()
22
+ def clear(self):
23
+ self.__points = list()
24
+ self.__chart.update()
25
+ def get_points(self):
26
+ return self.__points