happyscript 0.0.34__tar.gz → 0.0.37__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.34 → happyscript-0.0.37}/PKG-INFO +2 -2
- {happyscript-0.0.34 → happyscript-0.0.37}/happyscript/__init__.py +1 -1
- happyscript-0.0.37/happyscript/userpanel/userpanel.py +191 -0
- happyscript-0.0.37/happyscript/userpanel/userpanelvalue.py +50 -0
- happyscript-0.0.34/happyscript/userpanel/userpanel.py → happyscript-0.0.37/happyscript-widgets-main/SmartFrame.py +36 -34
- happyscript-0.0.34/happyscript/userpanel/userpanelvalue.py → happyscript-0.0.37/happyscript-widgets-main/SmartInput.py +1 -2
- happyscript-0.0.37/happyscript-widgets-main/main.py +56 -0
- {happyscript-0.0.34 → happyscript-0.0.37}/happyscript.egg-info/PKG-INFO +2 -2
- {happyscript-0.0.34 → happyscript-0.0.37}/happyscript.egg-info/SOURCES.txt +3 -1
- happyscript-0.0.37/happyscript.egg-info/top_level.txt +2 -0
- {happyscript-0.0.34 → happyscript-0.0.37}/pyproject.toml +1 -1
- happyscript-0.0.34/happyscript/userpanel/userpaneltimer.py +0 -46
- happyscript-0.0.34/happyscript.egg-info/top_level.txt +0 -1
- {happyscript-0.0.34 → happyscript-0.0.37}/README.md +0 -0
- {happyscript-0.0.34 → happyscript-0.0.37}/happyscript/charts/__init__.py +0 -0
- {happyscript-0.0.34 → happyscript-0.0.37}/happyscript/charts/chart.py +0 -0
- {happyscript-0.0.34 → happyscript-0.0.37}/happyscript/charts/histogram_chart.py +0 -0
- {happyscript-0.0.34 → happyscript-0.0.37}/happyscript/charts/histogram_series.py +0 -0
- {happyscript-0.0.34 → happyscript-0.0.37}/happyscript/charts/matplotlib_chart.py +0 -0
- {happyscript-0.0.34 → happyscript-0.0.37}/happyscript/charts/panel_charts.py +0 -0
- {happyscript-0.0.34 → happyscript-0.0.37}/happyscript/charts/scatter_chart.py +0 -0
- {happyscript-0.0.34 → happyscript-0.0.37}/happyscript/charts/scatter_series.py +0 -0
- {happyscript-0.0.34 → happyscript-0.0.37}/happyscript/charts/time_chart.py +0 -0
- {happyscript-0.0.34 → happyscript-0.0.37}/happyscript/charts/time_series.py +0 -0
- {happyscript-0.0.34 → happyscript-0.0.37}/happyscript/forms/form_askchoice.py +0 -0
- {happyscript-0.0.34 → happyscript-0.0.37}/happyscript/forms/form_askimage.py +0 -0
- {happyscript-0.0.34 → happyscript-0.0.37}/happyscript/forms/form_main.py +0 -0
- {happyscript-0.0.34 → happyscript-0.0.37}/happyscript/forms/form_ontestfailure.py +0 -0
- {happyscript-0.0.34 → happyscript-0.0.37}/happyscript/forms/form_serials.py +0 -0
- {happyscript-0.0.34 → happyscript-0.0.37}/happyscript/forms/form_stop.py +0 -0
- {happyscript-0.0.34 → happyscript-0.0.37}/happyscript/forms/formsbase.py +0 -0
- {happyscript-0.0.34 → happyscript-0.0.37}/happyscript/imglib.py +0 -0
- {happyscript-0.0.34 → happyscript-0.0.37}/happyscript/panels/panel_log.py +0 -0
- {happyscript-0.0.34 → happyscript-0.0.37}/happyscript/panels/panel_messages.py +0 -0
- {happyscript-0.0.34 → happyscript-0.0.37}/happyscript/panels/panel_scripts2.py +0 -0
- {happyscript-0.0.34 → happyscript-0.0.37}/happyscript/panels/panel_tests.py +0 -0
- {happyscript-0.0.34 → happyscript-0.0.37}/happyscript/panels/panelsbase.py +0 -0
- {happyscript-0.0.34 → happyscript-0.0.37}/happyscript/scriptartwork.py +0 -0
- {happyscript-0.0.34 → happyscript-0.0.37}/happyscript/scriptcontrol.py +0 -0
- {happyscript-0.0.34 → happyscript-0.0.37}/happyscript/scriptexceptions.py +0 -0
- {happyscript-0.0.34 → happyscript-0.0.37}/happyscript/scriptgui.py +0 -0
- {happyscript-0.0.34 → happyscript-0.0.37}/happyscript/scriptinfo.py +0 -0
- {happyscript-0.0.34 → happyscript-0.0.37}/happyscript/scriptmanager.py +0 -0
- {happyscript-0.0.34 → happyscript-0.0.37}/happyscript/scriptparams.py +0 -0
- {happyscript-0.0.34 → happyscript-0.0.37}/happyscript/scriptreader.py +0 -0
- {happyscript-0.0.34 → happyscript-0.0.37}/happyscript/scriptrunner.py +0 -0
- {happyscript-0.0.34 → happyscript-0.0.37}/happyscript/splashmenu/exit.png +0 -0
- {happyscript-0.0.34 → happyscript-0.0.37}/happyscript/splashmenu/forms.py +0 -0
- {happyscript-0.0.34 → happyscript-0.0.37}/happyscript/splashmenu/splashmenuform.py +0 -0
- {happyscript-0.0.34 → happyscript-0.0.37}/happyscript/splashmenu/splashmenumain.py +0 -0
- {happyscript-0.0.34 → happyscript-0.0.37}/happyscript/testlog/global_log_handler.py +0 -0
- {happyscript-0.0.34 → happyscript-0.0.37}/happyscript/testlog/log_to_text.py +0 -0
- {happyscript-0.0.34 → happyscript-0.0.37}/happyscript/testlog/logtoxml.py +0 -0
- {happyscript-0.0.34 → happyscript-0.0.37}/happyscript/testlog/printredirect.py +0 -0
- {happyscript-0.0.34 → happyscript-0.0.37}/happyscript.egg-info/dependency_links.txt +0 -0
- {happyscript-0.0.34 → happyscript-0.0.37}/happyscript.egg-info/requires.txt +0 -0
- {happyscript-0.0.34 → happyscript-0.0.37}/setup.cfg +0 -0
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import wx
|
|
2
|
+
import wx.xrc
|
|
3
|
+
from .userpanelvalue import UserPanelValue
|
|
4
|
+
import time
|
|
5
|
+
|
|
6
|
+
class UserPanel(wx.Panel):
|
|
7
|
+
"""
|
|
8
|
+
Public methods
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
def __init__(self, parent):
|
|
12
|
+
"""GUI builder for widgets to be used with happyscript
|
|
13
|
+
|
|
14
|
+
Keyword Arguments:
|
|
15
|
+
parent -- The window parent. This may be, and often is, None.
|
|
16
|
+
"""
|
|
17
|
+
wx.Panel.__init__(self, parent=parent, id = wx.ID_ANY, pos = wx.DefaultPosition, style = wx.TAB_TRAVERSAL, name = wx.EmptyString )
|
|
18
|
+
self.__mainbox = wx.BoxSizer(wx.VERTICAL)
|
|
19
|
+
self.SetSizer(self.__mainbox)
|
|
20
|
+
self.Layout()
|
|
21
|
+
|
|
22
|
+
self.__current_top_box = None # StaticBoxSizer with label to group controls
|
|
23
|
+
self.__timers=[]
|
|
24
|
+
self.Bind(wx.EVT_CLOSE, self.__on_close) # for stopping all the timers
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def add_box(self, title:str) -> None:
|
|
28
|
+
"""adds a box with a title to be used to contain the widgets
|
|
29
|
+
|
|
30
|
+
Arguments:
|
|
31
|
+
title: label for the box
|
|
32
|
+
"""
|
|
33
|
+
self.__current_top_box = wx.StaticBoxSizer(wx.StaticBox(self, label=title), wx.VERTICAL)
|
|
34
|
+
self.__mainbox.Add(self.__current_top_box, 0, wx.EXPAND, 5)
|
|
35
|
+
|
|
36
|
+
def add_buttons(self, label, event, button_labels : list[str]) -> None:
|
|
37
|
+
"""adds a horizontal row of buttons, which trigger the button_event(button_label) callback)
|
|
38
|
+
|
|
39
|
+
Arguments:
|
|
40
|
+
label: label to be placed left of the buttons, or None to have no label
|
|
41
|
+
event: callback triggered on button presses
|
|
42
|
+
button_labels -- list of labels (one for each button)
|
|
43
|
+
"""
|
|
44
|
+
self.__current_sub_box = self.__create_boxsizer()
|
|
45
|
+
if label is not None:
|
|
46
|
+
self.__insert_label(label, 1)
|
|
47
|
+
for button_label in button_labels:
|
|
48
|
+
event_wrapper = lambda *args, x=button_label: event(x)
|
|
49
|
+
proportion = 1 if (label is None) else 0
|
|
50
|
+
self.__insert_button(button_label, event_wrapper, proportion)
|
|
51
|
+
|
|
52
|
+
def add_slider(self, label:str, event, value:int, min_val:int, max_val:int) -> UserPanelValue:
|
|
53
|
+
""" Adds a slider for the user to set a value.
|
|
54
|
+
event function is called when the 'set' button is pressed, with the slider value as parameter
|
|
55
|
+
|
|
56
|
+
Arguments:
|
|
57
|
+
label: label to be placed left of the slider
|
|
58
|
+
event: callback triggered when pressing the 'set' button
|
|
59
|
+
value: slider initial value
|
|
60
|
+
min_val: slider minimum value
|
|
61
|
+
max_val: slider maximum value
|
|
62
|
+
|
|
63
|
+
Returns: object to access the slider value
|
|
64
|
+
"""
|
|
65
|
+
self.__current_sub_box= self.__create_boxsizer()
|
|
66
|
+
self.__insert_label(label)
|
|
67
|
+
slider_obj = self.__insert_slider(value, min_val, max_val, 1)
|
|
68
|
+
label_obj = self.__insert_label(str(value))
|
|
69
|
+
smart_input = UserPanelValue(slider_obj,
|
|
70
|
+
on_set=event,
|
|
71
|
+
on_update=lambda *args: label_obj.SetLabel(str(slider_obj.GetValue())) )
|
|
72
|
+
self.__insert_button("Set", lambda *args: smart_input.do_set(), 0)
|
|
73
|
+
slider_obj.Bind(wx.EVT_SLIDER, lambda *args: smart_input.update())
|
|
74
|
+
return smart_input
|
|
75
|
+
|
|
76
|
+
def add_combo_box(self, label:str, event, choices : list[str]) -> UserPanelValue:
|
|
77
|
+
""" Adds a combo box for the user to set a value.
|
|
78
|
+
event function is called when the 'set' button is pressed, with the combo box value as parameter
|
|
79
|
+
|
|
80
|
+
Arguments:
|
|
81
|
+
label: label to be placed left of the combo box
|
|
82
|
+
event: callback triggered when pressing the 'set' button
|
|
83
|
+
choices: list of options to be presented in the combo box
|
|
84
|
+
|
|
85
|
+
Returns: object to access the combo box value
|
|
86
|
+
"""
|
|
87
|
+
self.__current_sub_box = self.__create_boxsizer()
|
|
88
|
+
self.__insert_label(label)
|
|
89
|
+
combo_obj = self.__insert_combo_box(choices, 1)
|
|
90
|
+
smart_input = UserPanelValue(combo_obj, event)
|
|
91
|
+
self.__insert_button("Set", lambda *args: smart_input.do_set(), 0)
|
|
92
|
+
return smart_input
|
|
93
|
+
|
|
94
|
+
def add_spin_control(self, label:str, event, value:int, min_val:int, max_val:int):
|
|
95
|
+
""" Adds a spin control for the user to set a value.
|
|
96
|
+
event function is called when the 'set' button is pressed, with the spin control value as parameter.
|
|
97
|
+
|
|
98
|
+
Arguments:
|
|
99
|
+
label: label to be placed left of the spin control
|
|
100
|
+
event: callback triggered when pressing the 'set' button
|
|
101
|
+
value: spin control initial value
|
|
102
|
+
min_val: spin control minimum value
|
|
103
|
+
max_val: spin control maximum value
|
|
104
|
+
|
|
105
|
+
Returns: object to access the spin control value
|
|
106
|
+
"""
|
|
107
|
+
self.__current_sub_box = self.__create_boxsizer()
|
|
108
|
+
self.__insert_label(label)
|
|
109
|
+
spin_obj = self.__insert_spin_control(value, min_val, max_val, 1)
|
|
110
|
+
smart_input = UserPanelValue(spin_obj, event)
|
|
111
|
+
self.__insert_button("Set", lambda *args: smart_input.do_set(), 0)
|
|
112
|
+
return smart_input
|
|
113
|
+
|
|
114
|
+
def add_timer_control(self, label, event, interval_s):
|
|
115
|
+
""" allows the user to periodically trigger a callback
|
|
116
|
+
the timer interval is set with a spin control, in seconds
|
|
117
|
+
pressing start or stop will (re)start or stop the interval timer
|
|
118
|
+
|
|
119
|
+
Arguments:
|
|
120
|
+
label -- label to be placed on the left
|
|
121
|
+
event -- callback to be triggered each interval
|
|
122
|
+
interval_s -- interval default value
|
|
123
|
+
"""
|
|
124
|
+
# Timer info: https://www.blog.pythonlibrary.org/2009/08/25/wxpython-using-wx-timers/
|
|
125
|
+
self.__current_sub_box = self.__create_boxsizer()
|
|
126
|
+
self.__insert_label(label, 1)
|
|
127
|
+
spin_obj = self.__insert_spin_control(interval_s, 1, 86400, 1)
|
|
128
|
+
self.__insert_label("s")
|
|
129
|
+
|
|
130
|
+
new_timer = wx.Timer(spin_obj)
|
|
131
|
+
spin_obj.Bind(wx.EVT_TIMER, lambda ev: event(), new_timer)
|
|
132
|
+
self.__timers.append(new_timer)
|
|
133
|
+
self.__insert_button("Start", lambda *args: new_timer.Start(1000 * spin_obj.GetValue()), 0)
|
|
134
|
+
self.__insert_button("Stop", lambda *args: new_timer.Stop(), 0)
|
|
135
|
+
|
|
136
|
+
"""
|
|
137
|
+
private methods
|
|
138
|
+
"""
|
|
139
|
+
|
|
140
|
+
def __create_boxsizer(self, orientation=wx.HORIZONTAL, proportion=0):
|
|
141
|
+
"""setup for a BoxSizer
|
|
142
|
+
"""
|
|
143
|
+
if self.__current_top_box is None:
|
|
144
|
+
self.add_box("Miscellaneous")
|
|
145
|
+
box = wx.BoxSizer(orientation)
|
|
146
|
+
self.__current_top_box.Add(box, proportion, wx.EXPAND, 5)
|
|
147
|
+
return box
|
|
148
|
+
|
|
149
|
+
def __insert_label(self, label_text, proportion=0):
|
|
150
|
+
"""setup for a label
|
|
151
|
+
"""
|
|
152
|
+
label = wx.StaticText(self.__current_top_box.GetStaticBox(), label=label_text)
|
|
153
|
+
label.Wrap(-1)
|
|
154
|
+
self.__current_sub_box.Add(label, proportion, wx.ALL, 5)
|
|
155
|
+
return label
|
|
156
|
+
|
|
157
|
+
def __insert_button(self, button_label, button_event, proportion):
|
|
158
|
+
"""setup for a button
|
|
159
|
+
"""
|
|
160
|
+
button = wx.Button(self.__current_top_box.GetStaticBox(), label=button_label)
|
|
161
|
+
button.Bind(wx.EVT_BUTTON, button_event)
|
|
162
|
+
self.__current_sub_box.Add(button, proportion, wx.ALL, 5)
|
|
163
|
+
return button
|
|
164
|
+
|
|
165
|
+
def __insert_slider(self, initial, min, max, proportion):
|
|
166
|
+
"""setup for a slider
|
|
167
|
+
"""
|
|
168
|
+
slider = wx.Slider(self.__current_top_box.GetStaticBox(), value=initial, minValue=min, maxValue=max)
|
|
169
|
+
self.__current_sub_box.Add(slider, proportion, wx.ALL | wx.EXPAND, 5)
|
|
170
|
+
return slider
|
|
171
|
+
|
|
172
|
+
def __insert_combo_box(self, option_list, proportion):
|
|
173
|
+
"""setup for a combo box
|
|
174
|
+
"""
|
|
175
|
+
combo = wx.ComboBox(self.__current_top_box.GetStaticBox(), value=option_list[0], choices=option_list)
|
|
176
|
+
self.__current_sub_box.Add(combo, proportion, wx.ALL, 5)
|
|
177
|
+
return combo
|
|
178
|
+
|
|
179
|
+
def __insert_spin_control(self, initial, min, max, proportion):
|
|
180
|
+
"""setup for a spin control
|
|
181
|
+
"""
|
|
182
|
+
spin = wx.SpinCtrl(self.__current_top_box.GetStaticBox(), initial=initial, min=min, max=max)
|
|
183
|
+
self.__current_sub_box.Add(spin, proportion, wx.ALL, 5)
|
|
184
|
+
return spin
|
|
185
|
+
|
|
186
|
+
def __on_close(self, wxEvent):
|
|
187
|
+
"""cancels the running timer threads
|
|
188
|
+
"""
|
|
189
|
+
for timer in self.__timers:
|
|
190
|
+
timer.Stop()
|
|
191
|
+
self.Destroy()
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
|
|
2
|
+
class UserPanelValue():
|
|
3
|
+
def __init__(self, value_source, on_set=None, on_update=None):
|
|
4
|
+
"""initialiser method
|
|
5
|
+
SmartInput objects are used to keep track of GUI input values
|
|
6
|
+
|
|
7
|
+
Arguments:
|
|
8
|
+
value_source -- GUI object to retreive self.value from
|
|
9
|
+
|
|
10
|
+
Keyword Arguments:
|
|
11
|
+
on_set -- callback to be run after self.set(), receives self.value as its first argument (default: {None})
|
|
12
|
+
"""
|
|
13
|
+
self.__value_source = value_source
|
|
14
|
+
self.__on_set = on_set
|
|
15
|
+
self.__on_update = on_update
|
|
16
|
+
|
|
17
|
+
def do_set(self, value=None):
|
|
18
|
+
""" Event handler for the 'set' button.
|
|
19
|
+
Can also be use to set the value and trigger the on_set callback.
|
|
20
|
+
"""
|
|
21
|
+
if value is None: # no value given -> take value from GUI object
|
|
22
|
+
value = self.value
|
|
23
|
+
else: # value given -> set it to GUI object
|
|
24
|
+
self.value = value
|
|
25
|
+
|
|
26
|
+
if self.__on_set is not None:
|
|
27
|
+
self.__on_set(value)
|
|
28
|
+
|
|
29
|
+
@property
|
|
30
|
+
def value(self):
|
|
31
|
+
''' Gets the value of the GUI object.
|
|
32
|
+
'''
|
|
33
|
+
return self.__value_source.GetValue()
|
|
34
|
+
|
|
35
|
+
@value.setter
|
|
36
|
+
def value(self, value):
|
|
37
|
+
''' Sets the value of the GUI object immediately.
|
|
38
|
+
If an 'update' method is defined, it will be called.
|
|
39
|
+
'''
|
|
40
|
+
self.__value_source.SetValue(value)
|
|
41
|
+
self.update()
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def update(self):
|
|
45
|
+
''' Calls the 'on_update' method if it was defined.
|
|
46
|
+
This is typically used to update a label related to the GUI object.
|
|
47
|
+
'''
|
|
48
|
+
if self.__on_update is not None:
|
|
49
|
+
value = self.__value_source.GetValue()
|
|
50
|
+
self.__on_update(value)
|
|
@@ -1,25 +1,27 @@
|
|
|
1
1
|
import wx
|
|
2
2
|
import wx.xrc
|
|
3
|
-
from
|
|
4
|
-
from happyscript.happyscript.userpanel.userpanelvalue import UserPanelValue
|
|
3
|
+
from SmartInput import SmartInput
|
|
5
4
|
|
|
6
5
|
|
|
7
|
-
class
|
|
6
|
+
class SmartFrame(wx.Frame):
|
|
8
7
|
"""
|
|
9
8
|
Public methods
|
|
10
9
|
"""
|
|
11
10
|
|
|
12
|
-
def __init__(self, parent):
|
|
11
|
+
def __init__(self, parent=None, size=(500, 500), size_y=500):
|
|
13
12
|
"""GUI builder for widgets to be used with happyscript
|
|
14
13
|
|
|
15
14
|
Keyword Arguments:
|
|
16
15
|
parent -- The window parent. This may be, and often is, None. (default: {None})
|
|
16
|
+
size -- tuple (x,y) containing the window size (default: {500})
|
|
17
17
|
"""
|
|
18
|
-
wx.
|
|
18
|
+
wx.Frame.__init__(self, parent, size=wx.Size(size[0], size[1]))
|
|
19
|
+
self.Bind(wx.EVT_CLOSE, self.__on_close)
|
|
20
|
+
self.SetSizeHints(wx.DefaultSize, wx.DefaultSize)
|
|
19
21
|
self.__mainbox = wx.BoxSizer(wx.VERTICAL)
|
|
20
22
|
self.SetSizer(self.__mainbox)
|
|
21
23
|
self.Layout()
|
|
22
|
-
|
|
24
|
+
self.Centre(wx.BOTH)
|
|
23
25
|
self.__timers=[]
|
|
24
26
|
|
|
25
27
|
def add_box(self, title):
|
|
@@ -69,7 +71,7 @@ class UserPanel(wx.Panel):
|
|
|
69
71
|
self.__insert_label(label, 0)
|
|
70
72
|
slider_obj = self.__insert_slider(initial, min, max, 1)
|
|
71
73
|
label_obj = self.__insert_label(str(initial), 0)
|
|
72
|
-
smart_input =
|
|
74
|
+
smart_input = SmartInput(slider_obj, set_event)
|
|
73
75
|
self.__insert_button("Set", lambda *args: smart_input.set(), 0)
|
|
74
76
|
slider_obj.Bind(wx.EVT_SCROLL, lambda *args: label_obj.SetLabel(str(slider_obj.GetValue())))
|
|
75
77
|
return smart_input
|
|
@@ -91,7 +93,7 @@ class UserPanel(wx.Panel):
|
|
|
91
93
|
self.__current_sub_box = self.__create_boxsizer(wx.HORIZONTAL, 0)
|
|
92
94
|
self.__insert_label(label, 0)
|
|
93
95
|
combo_obj = self.__insert_combo_box(option_list, 1)
|
|
94
|
-
smart_input =
|
|
96
|
+
smart_input = SmartInput(combo_obj, set_event)
|
|
95
97
|
self.__insert_button("Set", lambda *args: smart_input.set(), 0)
|
|
96
98
|
return smart_input
|
|
97
99
|
|
|
@@ -114,29 +116,29 @@ class UserPanel(wx.Panel):
|
|
|
114
116
|
self.__current_sub_box = self.__create_boxsizer(wx.HORIZONTAL, 0)
|
|
115
117
|
self.__insert_label(label, 0)
|
|
116
118
|
spin_obj = self.__insert_spin_control(initial, min, max, 1)
|
|
117
|
-
smart_input =
|
|
119
|
+
smart_input = SmartInput(spin_obj, set_event)
|
|
118
120
|
self.__insert_button("Set", lambda *args: smart_input.set(), 0)
|
|
119
121
|
return smart_input
|
|
120
122
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
123
|
+
def add_timer_control(self, default, interval_callback, *args, **kwargs):
|
|
124
|
+
"""allows the user to periodically trigger a callback
|
|
125
|
+
the timer interval is set with a spin control
|
|
126
|
+
pressing start or stop will (re)start or stop the interval timer
|
|
127
|
+
Timer info: https://www.blog.pythonlibrary.org/2009/08/25/wxpython-using-wx-timers/
|
|
128
|
+
|
|
129
|
+
Arguments:
|
|
130
|
+
default -- inverval default value
|
|
131
|
+
interval_callback -- callback to be triggered each interval. any number of arguments can be passed via *args and **kwargs (interval_callback(*args, **kwargs))
|
|
132
|
+
"""
|
|
133
|
+
self.__current_sub_box = self.__create_boxsizer(wx.HORIZONTAL, 0)
|
|
134
|
+
self.__insert_label("Interval (s)", 0)
|
|
135
|
+
spin_obj = self.__insert_spin_control(default, 1, 86400, 1)
|
|
136
|
+
|
|
137
|
+
new_timer = wx.Timer(spin_obj)
|
|
138
|
+
spin_obj.Bind(wx.EVT_TIMER, lambda ev: interval_callback(*args, **kwargs), new_timer)
|
|
139
|
+
self.__timers.append(new_timer)
|
|
140
|
+
self.__insert_button("Start", lambda *args: new_timer.Start(1000 * spin_obj.GetValue()), 0)
|
|
141
|
+
self.__insert_button("Stop", lambda *args: new_timer.Stop(), 0)
|
|
140
142
|
|
|
141
143
|
"""
|
|
142
144
|
private methods
|
|
@@ -186,9 +188,9 @@ class UserPanel(wx.Panel):
|
|
|
186
188
|
self.__current_sub_box.Add(spin, proportion, wx.ALL, 5)
|
|
187
189
|
return spin
|
|
188
190
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
191
|
+
def __on_close(self, wxEvent):
|
|
192
|
+
"""cancels the running timer threads
|
|
193
|
+
"""
|
|
194
|
+
for timer in self.__timers:
|
|
195
|
+
timer.Stop()
|
|
196
|
+
self.Destroy()
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import wx
|
|
2
|
+
from SmartFrame import SmartFrame
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class MyFrame(SmartFrame):
|
|
6
|
+
def __init__(self):
|
|
7
|
+
super().__init__()
|
|
8
|
+
|
|
9
|
+
self.add_box("Buttons")
|
|
10
|
+
self.add_buttons(["Button 3", "Button 2", "Button 1"], self.on_buttons)
|
|
11
|
+
|
|
12
|
+
self.add_box("Slider")
|
|
13
|
+
self.slider1 = self.add_slider("Speed", 50, 0, 100, self.on_slider1_set)
|
|
14
|
+
|
|
15
|
+
self.add_box("Slider and buttons")
|
|
16
|
+
self.slider2 = self.add_slider("Speed", 50, 0, 100, self.on_slider2_set)
|
|
17
|
+
self.add_buttons(["Reverse", "Stop", "Forward"], self.on_buttons)
|
|
18
|
+
|
|
19
|
+
self.add_box("More examples")
|
|
20
|
+
self.add_buttons(["Automatic", "Normal", "Single"], self.on_buttons, label="Trigger mode")
|
|
21
|
+
self.add_buttons(["AC", "DC"], self.on_buttons, label="Coupling")
|
|
22
|
+
self.combo = self.add_combo_box("Bandwidth", ["Full", "100 MHz", "20 MHz"], self.on_combo_set)
|
|
23
|
+
self.spin = self.add_spin_control("Trigger level (V)", 5, 0, 10, self.on_spin_set)
|
|
24
|
+
self.add_timer_control(60, self.on_timer_done)
|
|
25
|
+
|
|
26
|
+
def on_buttons(self, label):
|
|
27
|
+
print(label, "pressed")
|
|
28
|
+
|
|
29
|
+
def on_slider1_set(self, value):
|
|
30
|
+
print("Slider set to", value)
|
|
31
|
+
|
|
32
|
+
def on_slider2_set(self, value):
|
|
33
|
+
print("Slider set to", value)
|
|
34
|
+
print(f"Slider1= {self.slider1.value}")
|
|
35
|
+
|
|
36
|
+
def on_combo_set(self, value):
|
|
37
|
+
print("Combo box set to", value)
|
|
38
|
+
|
|
39
|
+
def on_spin_set(self, value):
|
|
40
|
+
print("Spin Control set to", value)
|
|
41
|
+
|
|
42
|
+
def on_timer_done(self):
|
|
43
|
+
print("Timer done")
|
|
44
|
+
|
|
45
|
+
def print_inputs(self):
|
|
46
|
+
print("slider 1:", self.slider1.value)
|
|
47
|
+
print("slider 2:", self.slider2.value)
|
|
48
|
+
print("combo box:", self.combo.value)
|
|
49
|
+
print("spin control:", self.spin.value)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
if __name__ == "__main__":
|
|
53
|
+
app = wx.App(False)
|
|
54
|
+
my_frame = MyFrame()
|
|
55
|
+
my_frame.Show()
|
|
56
|
+
app.MainLoop()
|
|
@@ -11,6 +11,9 @@ happyscript/scriptmanager.py
|
|
|
11
11
|
happyscript/scriptparams.py
|
|
12
12
|
happyscript/scriptreader.py
|
|
13
13
|
happyscript/scriptrunner.py
|
|
14
|
+
happyscript-widgets-main/SmartFrame.py
|
|
15
|
+
happyscript-widgets-main/SmartInput.py
|
|
16
|
+
happyscript-widgets-main/main.py
|
|
14
17
|
happyscript.egg-info/PKG-INFO
|
|
15
18
|
happyscript.egg-info/SOURCES.txt
|
|
16
19
|
happyscript.egg-info/dependency_links.txt
|
|
@@ -47,5 +50,4 @@ happyscript/testlog/log_to_text.py
|
|
|
47
50
|
happyscript/testlog/logtoxml.py
|
|
48
51
|
happyscript/testlog/printredirect.py
|
|
49
52
|
happyscript/userpanel/userpanel.py
|
|
50
|
-
happyscript/userpanel/userpaneltimer.py
|
|
51
53
|
happyscript/userpanel/userpanelvalue.py
|
|
@@ -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.
|
|
20
|
+
version = "0.0.37"
|
|
21
21
|
readme = "README.md"
|
|
22
22
|
requires-python = ">=3.5"
|
|
23
23
|
dependencies = [ "wxpython", "numpy" ]
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
from threading import Timer
|
|
2
|
-
|
|
3
|
-
class UserPanelTimer(object):
|
|
4
|
-
def __init__(self, interval_source, function, *args, **kwargs):
|
|
5
|
-
"""interval timer that repeatedly calls a callback function
|
|
6
|
-
based on: https://stackoverflow.com/a/13151299
|
|
7
|
-
|
|
8
|
-
Arguments:
|
|
9
|
-
interval_source -- SmartInput object to retrieve the interval in seconds from
|
|
10
|
-
function -- callback function to run every interval
|
|
11
|
-
"""
|
|
12
|
-
self._timer = None
|
|
13
|
-
self.interval_source = interval_source
|
|
14
|
-
self.function = function
|
|
15
|
-
self.args = args
|
|
16
|
-
self.kwargs = kwargs
|
|
17
|
-
self.is_running = False
|
|
18
|
-
|
|
19
|
-
def __run(self):
|
|
20
|
-
"""callback to run after timer completes
|
|
21
|
-
"""
|
|
22
|
-
self.is_running = False
|
|
23
|
-
self.start()
|
|
24
|
-
self.function(*self.args, **self.kwargs)
|
|
25
|
-
|
|
26
|
-
def start(self):
|
|
27
|
-
"""starts the timer
|
|
28
|
-
"""
|
|
29
|
-
if not self.is_running:
|
|
30
|
-
self._timer = Timer(self.interval_source.set(), self.__run)
|
|
31
|
-
self._timer.start()
|
|
32
|
-
self.is_running = True
|
|
33
|
-
|
|
34
|
-
def restart(self):
|
|
35
|
-
"""restarts the timer
|
|
36
|
-
"""
|
|
37
|
-
if self.is_running:
|
|
38
|
-
self.stop()
|
|
39
|
-
self.start()
|
|
40
|
-
|
|
41
|
-
def stop(self):
|
|
42
|
-
"""stops the timer
|
|
43
|
-
"""
|
|
44
|
-
if self._timer is not None:
|
|
45
|
-
self._timer.cancel()
|
|
46
|
-
self.is_running = False
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
happyscript
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|