updated
This commit is contained in:
+61
-46
@@ -1,3 +1,4 @@
|
||||
import sys
|
||||
import pandas as pd
|
||||
import plotly.graph_objects as go
|
||||
from plotly.subplots import make_subplots
|
||||
@@ -32,14 +33,18 @@ def load_scope_csv(filename):
|
||||
raise Exception("Signaldefinition nicht gefunden")
|
||||
|
||||
# Datenblock suchen
|
||||
# Entweder folgt auf den Header ein <br>-Trenner (aeltere Scope-Exporte),
|
||||
# oder die Daten folgen direkt nach dem Metadaten-Block. Im zweiten Fall
|
||||
# starten wir einfach hinter dem Header; die Metadaten-Zeilen sowie ein
|
||||
# moegliches EOF-Marker werden im numerischen Pruefschritt uebersprungen.
|
||||
data_start = None
|
||||
for i in range(header_idx, len(lines)):
|
||||
for i in range(header_idx + 1, len(lines)):
|
||||
if lines[i].startswith("<br>"):
|
||||
data_start = i + 1
|
||||
break
|
||||
|
||||
if data_start is None:
|
||||
raise Exception("Datenblock nicht gefunden")
|
||||
data_start = header_idx + 1
|
||||
|
||||
numeric_rows = []
|
||||
|
||||
@@ -130,65 +135,75 @@ def create_plot():
|
||||
|
||||
|
||||
# --------------------------------------------------
|
||||
# Datei auswählen
|
||||
# Hauptprogramm
|
||||
# --------------------------------------------------
|
||||
root = tk.Tk()
|
||||
root.withdraw()
|
||||
def main():
|
||||
global df, root, signal_vars, auto_scale_var, ymin_entry, ymax_entry
|
||||
|
||||
filename = filedialog.askopenfilename(
|
||||
title="TwinCAT Scope CSV auswählen",
|
||||
filetypes=[("CSV Dateien", "*.csv"), ("Alle Dateien", "*.*")]
|
||||
)
|
||||
# Datei auswählen
|
||||
if len(sys.argv) > 1:
|
||||
# Dateipfad als Kommandozeilenargument uebergeben
|
||||
filename = sys.argv[1]
|
||||
else:
|
||||
temp_root = tk.Tk()
|
||||
temp_root.withdraw()
|
||||
filename = filedialog.askopenfilename(
|
||||
title="TwinCAT Scope CSV auswählen",
|
||||
filetypes=[("CSV Dateien", "*.csv"), ("Alle Dateien", "*.*")]
|
||||
)
|
||||
temp_root.destroy()
|
||||
|
||||
if not filename:
|
||||
raise SystemExit
|
||||
if not filename:
|
||||
raise SystemExit
|
||||
|
||||
df = load_scope_csv(filename)
|
||||
df = load_scope_csv(filename)
|
||||
|
||||
# --------------------------------------------------
|
||||
# GUI
|
||||
# --------------------------------------------------
|
||||
root = tk.Tk()
|
||||
root.title("TwinCAT Scope Plotter")
|
||||
# GUI
|
||||
root = tk.Tk()
|
||||
root.title("TwinCAT Scope Plotter")
|
||||
|
||||
signal_vars = {}
|
||||
signal_vars = {}
|
||||
|
||||
tk.Label(root, text="Signale auswählen").pack(anchor="w")
|
||||
tk.Label(root, text="Signale auswählen").pack(anchor="w")
|
||||
|
||||
for col in df.columns[1:]:
|
||||
var = tk.BooleanVar(value=True)
|
||||
for col in df.columns[1:]:
|
||||
var = tk.BooleanVar(value=True)
|
||||
|
||||
tk.Checkbutton(
|
||||
root,
|
||||
text=col,
|
||||
variable=var
|
||||
).pack(anchor="w")
|
||||
|
||||
signal_vars[col] = var
|
||||
|
||||
auto_scale_var = tk.BooleanVar(value=True)
|
||||
|
||||
tk.Checkbutton(
|
||||
root,
|
||||
text=col,
|
||||
variable=var
|
||||
).pack(anchor="w")
|
||||
text="Automatische Y-Skalierung",
|
||||
variable=auto_scale_var
|
||||
).pack(anchor="w", pady=10)
|
||||
|
||||
signal_vars[col] = var
|
||||
frame = tk.Frame(root)
|
||||
frame.pack()
|
||||
|
||||
auto_scale_var = tk.BooleanVar(value=True)
|
||||
tk.Label(frame, text="Y-Min").grid(row=0, column=0)
|
||||
ymin_entry = tk.Entry(frame, width=10)
|
||||
ymin_entry.grid(row=0, column=1)
|
||||
|
||||
tk.Checkbutton(
|
||||
root,
|
||||
text="Automatische Y-Skalierung",
|
||||
variable=auto_scale_var
|
||||
).pack(anchor="w", pady=10)
|
||||
tk.Label(frame, text="Y-Max").grid(row=0, column=2)
|
||||
ymax_entry = tk.Entry(frame, width=10)
|
||||
ymax_entry.grid(row=0, column=3)
|
||||
|
||||
frame = tk.Frame(root)
|
||||
frame.pack()
|
||||
tk.Button(
|
||||
root,
|
||||
text="Plot anzeigen",
|
||||
command=create_plot
|
||||
).pack(pady=10)
|
||||
|
||||
tk.Label(frame, text="Y-Min").grid(row=0, column=0)
|
||||
ymin_entry = tk.Entry(frame, width=10)
|
||||
ymin_entry.grid(row=0, column=1)
|
||||
root.mainloop()
|
||||
|
||||
tk.Label(frame, text="Y-Max").grid(row=0, column=2)
|
||||
ymax_entry = tk.Entry(frame, width=10)
|
||||
ymax_entry.grid(row=0, column=3)
|
||||
|
||||
tk.Button(
|
||||
root,
|
||||
text="Plot anzeigen",
|
||||
command=create_plot
|
||||
).pack(pady=10)
|
||||
|
||||
root.mainloop()
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user