happyscript 0.0.2__tar.gz → 0.0.7__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.
- {happyscript-0.0.2 → happyscript-0.0.7}/PKG-INFO +1 -1
- happyscript-0.0.7/copy_code.py +194 -0
- happyscript-0.0.7/happyscript/__init__.py +2 -0
- happyscript-0.0.7/happyscript/charts/__init__.py +0 -0
- happyscript-0.0.7/happyscript/charts/chart.py +129 -0
- happyscript-0.0.7/happyscript/charts/histogram_chart.py +39 -0
- happyscript-0.0.7/happyscript/charts/histogram_series.py +54 -0
- happyscript-0.0.7/happyscript/charts/matplotlib_chart.py +71 -0
- happyscript-0.0.7/happyscript/charts/panel_charts.py +108 -0
- happyscript-0.0.7/happyscript/charts/scatter_chart.py +27 -0
- happyscript-0.0.7/happyscript/charts/scatter_series.py +22 -0
- happyscript-0.0.7/happyscript/charts/time_chart.py +59 -0
- happyscript-0.0.7/happyscript/charts/time_series.py +26 -0
- happyscript-0.0.7/happyscript/forms/form_askchoice.py +38 -0
- happyscript-0.0.7/happyscript/forms/form_askimage.py +66 -0
- happyscript-0.0.7/happyscript/forms/form_main.py +230 -0
- happyscript-0.0.7/happyscript/forms/form_ontestfailure.py +28 -0
- happyscript-0.0.7/happyscript/forms/form_serials.py +105 -0
- happyscript-0.0.7/happyscript/forms/form_stop.py +11 -0
- happyscript-0.0.7/happyscript/forms/formsbase.py +396 -0
- happyscript-0.0.7/happyscript/imglib.py +971 -0
- happyscript-0.0.7/happyscript/panels/panel_log.py +76 -0
- happyscript-0.0.7/happyscript/panels/panel_messages.py +54 -0
- happyscript-0.0.7/happyscript/panels/panel_scripts2.py +58 -0
- happyscript-0.0.7/happyscript/panels/panel_tests.py +258 -0
- happyscript-0.0.7/happyscript/panels/panelsbase.py +286 -0
- happyscript-0.0.7/happyscript/scriptartwork.py +46 -0
- happyscript-0.0.7/happyscript/scriptcontrol.py +43 -0
- happyscript-0.0.7/happyscript/scriptexceptions.py +10 -0
- happyscript-0.0.7/happyscript/scriptgui.py +151 -0
- happyscript-0.0.7/happyscript/scriptinfo.py +80 -0
- happyscript-0.0.7/happyscript/scriptmanager.py +165 -0
- happyscript-0.0.7/happyscript/scriptparams.py +75 -0
- happyscript-0.0.7/happyscript/scriptreader.py +83 -0
- happyscript-0.0.7/happyscript/scriptrunner.py +98 -0
- happyscript-0.0.7/happyscript/testlog/global_log_handler.py +61 -0
- happyscript-0.0.7/happyscript/testlog/log_to_text.py +46 -0
- happyscript-0.0.7/happyscript/testlog/logtoxml.py +31 -0
- happyscript-0.0.7/happyscript/testlog/printredirect.py +43 -0
- {happyscript-0.0.2 → happyscript-0.0.7}/happyscript.egg-info/PKG-INFO +1 -1
- happyscript-0.0.7/happyscript.egg-info/SOURCES.txt +45 -0
- happyscript-0.0.7/increment_version.py +58 -0
- happyscript-0.0.7/pyproject.toml +24 -0
- happyscript-0.0.2/happyscript/happyscript.py +0 -3847
- happyscript-0.0.2/happyscript.egg-info/SOURCES.txt +0 -7
- happyscript-0.0.2/pyproject.toml +0 -12
- {happyscript-0.0.2 → happyscript-0.0.7}/README.md +0 -0
- {happyscript-0.0.2 → happyscript-0.0.7}/happyscript.egg-info/dependency_links.txt +0 -0
- {happyscript-0.0.2 → happyscript-0.0.7}/happyscript.egg-info/top_level.txt +0 -0
- {happyscript-0.0.2 → happyscript-0.0.7}/setup.cfg +0 -0
|
@@ -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
|
+
|
|
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,71 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
import wx
|
|
3
|
+
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas
|
|
4
|
+
from matplotlib.backends.backend_wxagg import NavigationToolbar2WxAgg as NavigationToolbar
|
|
5
|
+
from matplotlib.figure import Figure
|
|
6
|
+
import matplotlib.pyplot as plt
|
|
7
|
+
class MatPlotLibChart(wx.Panel):
|
|
8
|
+
def __init__(self, parent_control, name):
|
|
9
|
+
super().__init__(parent_control, -1)
|
|
10
|
+
self.__name = name
|
|
11
|
+
self.__dirty = False
|
|
12
|
+
self.__on_update_func = None
|
|
13
|
+
self.__figure = Figure(dpi=None, figsize=(2, 2))
|
|
14
|
+
self.__figure.set_tight_layout(True)
|
|
15
|
+
self.canvas = FigureCanvas(self, -1, self.__figure)
|
|
16
|
+
self.__toolbar = NavigationToolbar(self.canvas)
|
|
17
|
+
self.__toolbar.Realize()
|
|
18
|
+
sizer = wx.BoxSizer(wx.VERTICAL)
|
|
19
|
+
sizer.Add(self.canvas, 1, wx.EXPAND)
|
|
20
|
+
sizer.Add(self.__toolbar, 0, wx.LEFT | wx.EXPAND)
|
|
21
|
+
self.SetSizer(sizer)
|
|
22
|
+
@property
|
|
23
|
+
def name(self):
|
|
24
|
+
return self.__name
|
|
25
|
+
@property
|
|
26
|
+
def figure(self):
|
|
27
|
+
return self.__figure
|
|
28
|
+
def configure(self, /, x_label=None, y_label=None, title=None,
|
|
29
|
+
y_log=None, x_log=None, x_range=None, y_range=None):
|
|
30
|
+
if title is not None and isinstance(title, str):
|
|
31
|
+
if len(self.figure.axes)>0:
|
|
32
|
+
self.figure.axes[0].set_title(title)
|
|
33
|
+
self.update()
|
|
34
|
+
@property
|
|
35
|
+
def on_update(self):
|
|
36
|
+
return self.__on_update_func
|
|
37
|
+
@on_update.setter
|
|
38
|
+
def on_update(self, value):
|
|
39
|
+
if value is None or callable(value):
|
|
40
|
+
self.__on_update_func = value
|
|
41
|
+
@property
|
|
42
|
+
def dirty(self):
|
|
43
|
+
return self.__dirty
|
|
44
|
+
def update(self, / , antialiasing=False):
|
|
45
|
+
if antialiasing:
|
|
46
|
+
logging.warn("Antialiasing not supported for matplotlib chart")
|
|
47
|
+
self.__dirty = True
|
|
48
|
+
if self.__on_update_func is not None:
|
|
49
|
+
self.__on_update_func()
|
|
50
|
+
def redraw(self):
|
|
51
|
+
self.antiAlias = False
|
|
52
|
+
self.do_redraw()
|
|
53
|
+
self.__dirty = False
|
|
54
|
+
def do_redraw(self):
|
|
55
|
+
self.canvas.draw()
|
|
56
|
+
def clear(self):
|
|
57
|
+
try:
|
|
58
|
+
self.figure.clf()
|
|
59
|
+
except:
|
|
60
|
+
pass
|
|
61
|
+
pass
|
|
62
|
+
def delete_series(self, name):
|
|
63
|
+
logging.error("Deleting series not supported for matplotlib charts")
|
|
64
|
+
def add_series(self, name):
|
|
65
|
+
logging.error("Use matplotlib API for adding series")
|
|
66
|
+
def get_series(self, name):
|
|
67
|
+
logging.error("Getting series not supported for matplotlib charts")
|
|
68
|
+
return None
|
|
69
|
+
def get_data_as_text(self):
|
|
70
|
+
logging.error("Getting series not supported for matplotlib charts")
|
|
71
|
+
return "Data not available for matplotlib charts"
|
|
@@ -0,0 +1,108 @@
|
|
|
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
|
+
from ..charts.matplotlib_chart import MatPlotLibChart
|
|
8
|
+
class PanelCharts( PanelCharts_Base):
|
|
9
|
+
def __init__( self, parent):
|
|
10
|
+
super().__init__(parent)
|
|
11
|
+
self.__dirty = False
|
|
12
|
+
self.charts = dict()
|
|
13
|
+
self.default_savedir = os.getcwd()
|
|
14
|
+
def update(self):
|
|
15
|
+
self.__dirty = True
|
|
16
|
+
def OnRedrawTimer( self, event ):
|
|
17
|
+
if self.__dirty:
|
|
18
|
+
self.__dirty = False
|
|
19
|
+
for x in self.charts.values():
|
|
20
|
+
x.redraw()
|
|
21
|
+
def OnRadioBoxMouseMode( self, event ):
|
|
22
|
+
for chart in self.charts.values():
|
|
23
|
+
if self.m_rbxMouseMode.Selection==0:
|
|
24
|
+
chart.enableZoom = False
|
|
25
|
+
chart.enableDrag = False
|
|
26
|
+
elif self.m_rbxMouseMode.Selection==1:
|
|
27
|
+
chart.enableZoom = True
|
|
28
|
+
chart.enableDrag = False
|
|
29
|
+
else:
|
|
30
|
+
chart.enableDrag = True
|
|
31
|
+
chart.enableZoom = False
|
|
32
|
+
def BtnCopyDataClick( self, event ):
|
|
33
|
+
index = self.m_nbkPlots.GetSelection()
|
|
34
|
+
if index == wx.NOT_FOUND or self.m_nbkPlots.GetPageText(index) not in self.charts:
|
|
35
|
+
wx.MessageBox( "Cannot find chart on current page", "HappyScript", wx.OK | wx.ICON_ERROR )
|
|
36
|
+
chart = self.charts[self.m_nbkPlots.GetPageText(index)]
|
|
37
|
+
try:
|
|
38
|
+
clipdata = wx.TextDataObject()
|
|
39
|
+
lines = chart.get_data_as_text()
|
|
40
|
+
clipdata.SetText(lines)
|
|
41
|
+
wx.TheClipboard.Open()
|
|
42
|
+
wx.TheClipboard.SetData(clipdata)
|
|
43
|
+
wx.TheClipboard.Close()
|
|
44
|
+
wx.MessageBox( "Data written to clipboard", "HappyScript", wx.OK | wx.ICON_INFORMATION )
|
|
45
|
+
except:
|
|
46
|
+
wx.MessageBox( "Could not write text to clipboard", "HappyScript", wx.OK | wx.ICON_ERROR )
|
|
47
|
+
def OnMakePretty( self, event ):
|
|
48
|
+
index = self.m_nbkPlots.GetSelection()
|
|
49
|
+
if index == wx.NOT_FOUND or self.m_nbkPlots.GetPageText(index) not in self.charts:
|
|
50
|
+
wx.MessageBox( "Cannot find chart on current page", "HappyScript", wx.OK | wx.ICON_ERROR )
|
|
51
|
+
chart = self.charts[self.m_nbkPlots.GetPageText(index)]
|
|
52
|
+
chart.update(antialiasing = True)
|
|
53
|
+
def OnBtnSaveBitmap( self, event ):
|
|
54
|
+
index = self.m_nbkPlots.GetSelection()
|
|
55
|
+
if index == wx.NOT_FOUND or self.m_nbkPlots.GetPageText(index) not in self.charts:
|
|
56
|
+
wx.MessageBox( "Cannot find chart on current page", "HappyScript", wx.OK | wx.ICON_ERROR )
|
|
57
|
+
chart = self.charts[self.m_nbkPlots.GetPageText(index)]
|
|
58
|
+
try:
|
|
59
|
+
with wx.FileDialog(self, "Output file name", wildcard="PNG files(*.png)|*.png",
|
|
60
|
+
defaultDir = self.default_savedir,
|
|
61
|
+
style=wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT) as fdlg:
|
|
62
|
+
if fdlg.ShowModal() == wx.ID_OK:
|
|
63
|
+
filename = fdlg.GetPath()
|
|
64
|
+
chart.SaveFile(filename)
|
|
65
|
+
self.default_savedir = os.path.dirname(filename)
|
|
66
|
+
except:
|
|
67
|
+
wx.MessageBox( "Could not write bitmap", "HappyScript", wx.OK | wx.ICON_ERROR )
|
|
68
|
+
def get_chart(self, name):
|
|
69
|
+
if name in self.charts:
|
|
70
|
+
return self.charts[name]
|
|
71
|
+
else:
|
|
72
|
+
return None
|
|
73
|
+
def delete_chart(self, name):
|
|
74
|
+
if not name in self.charts:
|
|
75
|
+
return
|
|
76
|
+
ch = self.charts[name]
|
|
77
|
+
page_num = self.m_nbkPlots.FindPage(ch)
|
|
78
|
+
if page_num != wx.NOT_FOUND:
|
|
79
|
+
self.m_nbkPlots.DeletePage(page_num)
|
|
80
|
+
del self.charts[name]
|
|
81
|
+
def add_scatter_chart(self, name ):
|
|
82
|
+
self.delete_chart(name)
|
|
83
|
+
chart = ScatterChart(self.m_nbkPlots, name)
|
|
84
|
+
chart.on_update = self.update
|
|
85
|
+
self.charts[name] = chart
|
|
86
|
+
self.m_nbkPlots.AddPage( chart, name, True)
|
|
87
|
+
return chart
|
|
88
|
+
def add_time_chart(self, name ):
|
|
89
|
+
self.delete_chart(name)
|
|
90
|
+
chart = TimeChart(self.m_nbkPlots, name)
|
|
91
|
+
chart.on_update = self.update
|
|
92
|
+
self.charts[name] = chart
|
|
93
|
+
self.m_nbkPlots.AddPage( chart, name, True)
|
|
94
|
+
return chart
|
|
95
|
+
def add_histogram(self, name, binsize ):
|
|
96
|
+
self.delete_chart(name)
|
|
97
|
+
chart = HistogramChart(self.m_nbkPlots, name, binsize)
|
|
98
|
+
chart.on_update = self.update
|
|
99
|
+
self.charts[name] = chart
|
|
100
|
+
self.m_nbkPlots.AddPage( chart, name, True)
|
|
101
|
+
return chart
|
|
102
|
+
def add_matplotlib(self, name ):
|
|
103
|
+
self.delete_chart(name)
|
|
104
|
+
chart = MatPlotLibChart(self.m_nbkPlots, name)
|
|
105
|
+
chart.on_update = self.update
|
|
106
|
+
self.charts[name] = chart
|
|
107
|
+
self.m_nbkPlots.AddPage( chart, name, True)
|
|
108
|
+
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
|