Minor UI and bug fixes
This commit is contained in:
parent
6ad44be21c
commit
4bc34418bc
|
@ -1863,97 +1863,6 @@
|
||||||
<event name="OnUpdateUI"></event>
|
<event name="OnUpdateUI"></event>
|
||||||
</object>
|
</object>
|
||||||
</object>
|
</object>
|
||||||
<object class="gbsizeritem" expanded="0">
|
|
||||||
<property name="border">5</property>
|
|
||||||
<property name="colspan">1</property>
|
|
||||||
<property name="column">1</property>
|
|
||||||
<property name="flag">wxALL</property>
|
|
||||||
<property name="row">0</property>
|
|
||||||
<property name="rowspan">1</property>
|
|
||||||
<object class="wxButton" expanded="0">
|
|
||||||
<property name="BottomDockable">1</property>
|
|
||||||
<property name="LeftDockable">1</property>
|
|
||||||
<property name="RightDockable">1</property>
|
|
||||||
<property name="TopDockable">1</property>
|
|
||||||
<property name="aui_layer"></property>
|
|
||||||
<property name="aui_name"></property>
|
|
||||||
<property name="aui_position"></property>
|
|
||||||
<property name="aui_row"></property>
|
|
||||||
<property name="best_size"></property>
|
|
||||||
<property name="bg"></property>
|
|
||||||
<property name="caption"></property>
|
|
||||||
<property name="caption_visible">1</property>
|
|
||||||
<property name="center_pane">0</property>
|
|
||||||
<property name="close_button">1</property>
|
|
||||||
<property name="context_help"></property>
|
|
||||||
<property name="context_menu">1</property>
|
|
||||||
<property name="default">0</property>
|
|
||||||
<property name="default_pane">0</property>
|
|
||||||
<property name="dock">Dock</property>
|
|
||||||
<property name="dock_fixed">0</property>
|
|
||||||
<property name="docking">Left</property>
|
|
||||||
<property name="enabled">0</property>
|
|
||||||
<property name="fg"></property>
|
|
||||||
<property name="floatable">1</property>
|
|
||||||
<property name="font"></property>
|
|
||||||
<property name="gripper">0</property>
|
|
||||||
<property name="hidden">0</property>
|
|
||||||
<property name="id">wxID_ANY</property>
|
|
||||||
<property name="label">Plot</property>
|
|
||||||
<property name="max_size"></property>
|
|
||||||
<property name="maximize_button">0</property>
|
|
||||||
<property name="maximum_size"></property>
|
|
||||||
<property name="min_size"></property>
|
|
||||||
<property name="minimize_button">0</property>
|
|
||||||
<property name="minimum_size"></property>
|
|
||||||
<property name="moveable">1</property>
|
|
||||||
<property name="name">plot_but</property>
|
|
||||||
<property name="pane_border">1</property>
|
|
||||||
<property name="pane_position"></property>
|
|
||||||
<property name="pane_size"></property>
|
|
||||||
<property name="permission">protected</property>
|
|
||||||
<property name="pin_button">1</property>
|
|
||||||
<property name="pos"></property>
|
|
||||||
<property name="resize">Resizable</property>
|
|
||||||
<property name="show">1</property>
|
|
||||||
<property name="size"></property>
|
|
||||||
<property name="style"></property>
|
|
||||||
<property name="subclass">; ; forward_declare</property>
|
|
||||||
<property name="toolbar_pane">0</property>
|
|
||||||
<property name="tooltip"></property>
|
|
||||||
<property name="validator_data_type"></property>
|
|
||||||
<property name="validator_style">wxFILTER_NONE</property>
|
|
||||||
<property name="validator_type">wxDefaultValidator</property>
|
|
||||||
<property name="validator_variable"></property>
|
|
||||||
<property name="window_extra_style"></property>
|
|
||||||
<property name="window_name"></property>
|
|
||||||
<property name="window_style"></property>
|
|
||||||
<event name="OnButtonClick"></event>
|
|
||||||
<event name="OnChar"></event>
|
|
||||||
<event name="OnEnterWindow"></event>
|
|
||||||
<event name="OnEraseBackground"></event>
|
|
||||||
<event name="OnKeyDown"></event>
|
|
||||||
<event name="OnKeyUp"></event>
|
|
||||||
<event name="OnKillFocus"></event>
|
|
||||||
<event name="OnLeaveWindow"></event>
|
|
||||||
<event name="OnLeftDClick"></event>
|
|
||||||
<event name="OnLeftDown"></event>
|
|
||||||
<event name="OnLeftUp"></event>
|
|
||||||
<event name="OnMiddleDClick"></event>
|
|
||||||
<event name="OnMiddleDown"></event>
|
|
||||||
<event name="OnMiddleUp"></event>
|
|
||||||
<event name="OnMotion"></event>
|
|
||||||
<event name="OnMouseEvents"></event>
|
|
||||||
<event name="OnMouseWheel"></event>
|
|
||||||
<event name="OnPaint"></event>
|
|
||||||
<event name="OnRightDClick"></event>
|
|
||||||
<event name="OnRightDown"></event>
|
|
||||||
<event name="OnRightUp"></event>
|
|
||||||
<event name="OnSetFocus"></event>
|
|
||||||
<event name="OnSize"></event>
|
|
||||||
<event name="OnUpdateUI"></event>
|
|
||||||
</object>
|
|
||||||
</object>
|
|
||||||
</object>
|
</object>
|
||||||
</object>
|
</object>
|
||||||
<object class="sizeritem" expanded="0">
|
<object class="sizeritem" expanded="0">
|
||||||
|
|
|
@ -4,7 +4,7 @@ import matplotlib
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
from matplotlib.animation import FuncAnimation
|
from matplotlib.animation import FuncAnimation
|
||||||
import os, json, traceback, ui, wx
|
import os, json, traceback, ui, wx
|
||||||
matplotlib.use("WXAgg")
|
matplotlib.use("WXAgg") # for JetBrains IDE to force use the wx backend
|
||||||
|
|
||||||
class SerialPlotter:
|
class SerialPlotter:
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
|
@ -35,10 +35,10 @@ class SerialPlotter:
|
||||||
wx.MessageBox(f"File has saved as {os.path.split(file)[1]} under {os.path.split(file)[0]} directory!\n")
|
wx.MessageBox(f"File has saved as {os.path.split(file)[1]} under {os.path.split(file)[0]} directory!\n")
|
||||||
|
|
||||||
def animation(self, t:int) -> None:
|
def animation(self, t:int) -> None:
|
||||||
""" render a from of the animated graph """
|
""" render a frame of the animated graph """
|
||||||
# print("hi")
|
|
||||||
try:
|
try:
|
||||||
plt.cla() # clear previous frame
|
plt.cla() # clear previous frame
|
||||||
|
# read the last line from the .csv file, the data start from the second colunm so omit index # 0
|
||||||
file = open(self.settings["file_name"], "r")
|
file = open(self.settings["file_name"], "r")
|
||||||
ndata = np.array([np.asarray(line.split(", ")[1:], dtype=np.float32) for line in file])
|
ndata = np.array([np.asarray(line.split(", ")[1:], dtype=np.float32) for line in file])
|
||||||
if len(ndata) > 0:
|
if len(ndata) > 0:
|
||||||
|
@ -64,7 +64,7 @@ class SerialPlotter:
|
||||||
except:
|
except:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
|
|
||||||
def plotting(self) -> None:
|
def plotting(self) -> FuncAnimation:
|
||||||
ani = FuncAnimation(self.fig, self.animation, blit=False)
|
ani = FuncAnimation(self.fig, self.animation, blit=False)
|
||||||
return ani
|
return ani
|
||||||
|
|
||||||
|
|
38
test.py
38
test.py
|
@ -1,5 +1,5 @@
|
||||||
from ui import Frame
|
from ui import Frame
|
||||||
from threading import *
|
from multiprocessing import *
|
||||||
from read_arduino import *
|
from read_arduino import *
|
||||||
from serial_plotter import *
|
from serial_plotter import *
|
||||||
import os, json, wx, warnings
|
import os, json, wx, warnings
|
||||||
|
@ -11,7 +11,7 @@ warnings.filterwarnings("ignore", category=DeprecationWarning)
|
||||||
HEIGHT = 800
|
HEIGHT = 800
|
||||||
WIDTH = 800
|
WIDTH = 800
|
||||||
|
|
||||||
global ani
|
global ani, t1
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
@ -39,7 +39,6 @@ def main():
|
||||||
raise ValueError(f"expecting 5 resistor values, but got {len(resistors)}!!!")
|
raise ValueError(f"expecting 5 resistor values, but got {len(resistors)}!!!")
|
||||||
|
|
||||||
gen_settings(resistors, input_voltage, bit_rate, port, filename, window_size, delay)
|
gen_settings(resistors, input_voltage, bit_rate, port, filename, window_size, delay)
|
||||||
return filename
|
|
||||||
|
|
||||||
|
|
||||||
def gen_settings(resistors, input_voltage, bits, port, filename, window_size, delay):
|
def gen_settings(resistors, input_voltage, bits, port, filename, window_size, delay):
|
||||||
|
@ -68,34 +67,37 @@ def get_devices():
|
||||||
frame.dev_list.AppendItems(ports)
|
frame.dev_list.AppendItems(ports)
|
||||||
|
|
||||||
|
|
||||||
def runPlot(e):
|
def run(e):
|
||||||
global ani
|
"""
|
||||||
|
run the read_arduino.py and Serial Plotter in parallel
|
||||||
|
"""
|
||||||
|
global ani, t1 # the variables to call the plotter and the read_arduino.py, we want them to get tossed around between functions and even programs
|
||||||
|
main()
|
||||||
|
if 't1' in globals():
|
||||||
|
t1.terminate() # end the previous serial reads, if there is any
|
||||||
|
|
||||||
|
# place the read() function from read_arduino into another process to run it in background
|
||||||
|
t1 = Process(target=read, args=())
|
||||||
|
t1.start()
|
||||||
|
|
||||||
|
# run the plotter. Note that we should not put the plotter class, or function, in another process since
|
||||||
|
# matplot's FuncAnimation doesn't like that
|
||||||
plotter = SerialPlotter()
|
plotter = SerialPlotter()
|
||||||
ani = plotter.plotting()
|
ani = plotter.plotting()
|
||||||
plotter.fig.show()
|
plotter.fig.show()
|
||||||
|
|
||||||
|
frame.btLaunch.SetLabelText("Plot") # change the text on the "launch" button to "plot"
|
||||||
def run(e):
|
|
||||||
file = main()
|
|
||||||
t1 = Thread(target=read, args=())
|
|
||||||
t1.setDaemon(True)
|
|
||||||
t1.start()
|
|
||||||
|
|
||||||
runPlot(e)
|
|
||||||
frame.btLaunch.Enable(False)
|
|
||||||
frame.plot_but.Enable(True) # this might have some problem ... what happen if user spamming the plot button?
|
|
||||||
if not frame.show_msg.GetValue():
|
if not frame.show_msg.GetValue():
|
||||||
frame.Hide()
|
frame.Hide()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
global t1
|
||||||
app = wx.App()
|
app = wx.App()
|
||||||
frame = Frame(None)
|
frame = Frame(None)
|
||||||
get_devices()
|
get_devices()
|
||||||
frame.SetTitle("Cease your resistance! - alpha 0.1.1")
|
frame.SetTitle("Cease your resistance! - alpha 0.1.1")
|
||||||
frame.btLaunch.Bind(wx.EVT_BUTTON, run)
|
frame.btLaunch.Bind(wx.EVT_BUTTON, run)
|
||||||
frame.plot_but.Bind(wx.EVT_BUTTON,
|
|
||||||
runPlot) # There is one problem with this approch: what happen if user spamming the plot button?
|
|
||||||
if os.path.isfile("settings.json"):
|
if os.path.isfile("settings.json"):
|
||||||
print("Found existing settings.json, auto-fill previous inputs!")
|
print("Found existing settings.json, auto-fill previous inputs!")
|
||||||
settings = json.load(open('settings.json', 'r'))
|
settings = json.load(open('settings.json', 'r'))
|
||||||
|
@ -109,3 +111,5 @@ if __name__ == '__main__':
|
||||||
|
|
||||||
frame.Show()
|
frame.Show()
|
||||||
app.MainLoop()
|
app.MainLoop()
|
||||||
|
if 't1' in globals():
|
||||||
|
t1.terminate() # end the process if it has been started
|
8
ui.py
8
ui.py
|
@ -8,7 +8,6 @@
|
||||||
###########################################################################
|
###########################################################################
|
||||||
|
|
||||||
import wx
|
import wx
|
||||||
import wx.xrc
|
|
||||||
|
|
||||||
###########################################################################
|
###########################################################################
|
||||||
## Class Frame
|
## Class Frame
|
||||||
|
@ -92,7 +91,7 @@ class Frame ( wx.Frame ):
|
||||||
self.sizer_prompt.Wrap( -1 )
|
self.sizer_prompt.Wrap( -1 )
|
||||||
gbSizer8.Add( self.sizer_prompt, wx.GBPosition( 2, 0 ), wx.GBSpan( 1, 1 ), wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT, 5 )
|
gbSizer8.Add( self.sizer_prompt, wx.GBPosition( 2, 0 ), wx.GBSpan( 1, 1 ), wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT, 5 )
|
||||||
|
|
||||||
self.m_textCtrl26 = wx.TextCtrl( v_entre.GetStaticBox(), wx.ID_ANY, u"20", wx.DefaultPosition, wx.DefaultSize, 0 )
|
self.m_textCtrl26 = wx.TextCtrl( v_entre.GetStaticBox(), wx.ID_ANY, u"480", wx.DefaultPosition, wx.DefaultSize, 0 )
|
||||||
self.m_textCtrl26.SetToolTipString( u"Window size for the plot window. If want infinite/maximum size, type 0" )
|
self.m_textCtrl26.SetToolTipString( u"Window size for the plot window. If want infinite/maximum size, type 0" )
|
||||||
|
|
||||||
gbSizer8.Add( self.m_textCtrl26, wx.GBPosition( 2, 1 ), wx.GBSpan( 1, 1 ), wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_CENTER_HORIZONTAL|wx.TOP|wx.RIGHT|wx.LEFT, 5 )
|
gbSizer8.Add( self.m_textCtrl26, wx.GBPosition( 2, 1 ), wx.GBSpan( 1, 1 ), wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_CENTER_HORIZONTAL|wx.TOP|wx.RIGHT|wx.LEFT, 5 )
|
||||||
|
@ -137,11 +136,6 @@ class Frame ( wx.Frame ):
|
||||||
self.btLaunch.SetDefault()
|
self.btLaunch.SetDefault()
|
||||||
launch_opt.Add( self.btLaunch, wx.GBPosition( 0, 0 ), wx.GBSpan( 1, 1 ), wx.ALL|wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_CENTER_HORIZONTAL, 5 )
|
launch_opt.Add( self.btLaunch, wx.GBPosition( 0, 0 ), wx.GBSpan( 1, 1 ), wx.ALL|wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_CENTER_HORIZONTAL, 5 )
|
||||||
|
|
||||||
self.plot_but = wx.Button( self, wx.ID_ANY, u"Plot", wx.DefaultPosition, wx.DefaultSize, 0 )
|
|
||||||
self.plot_but.Enable( False )
|
|
||||||
|
|
||||||
launch_opt.Add( self.plot_but, wx.GBPosition( 0, 1 ), wx.GBSpan( 1, 1 ), wx.ALL, 5 )
|
|
||||||
|
|
||||||
|
|
||||||
bSizer1.Add( launch_opt, 0, wx.ALIGN_CENTER_HORIZONTAL, 5 )
|
bSizer1.Add( launch_opt, 0, wx.ALIGN_CENTER_HORIZONTAL, 5 )
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue