Skip to content

Commit cdd51e4

Browse files
committed
Adding Comments to csvplotter file
1 parent 969246e commit cdd51e4

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

csvplotter.py

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
import plotly.graph_objects as go
55

66
class CSVPlotterApp:
7-
def __init__(self, root):
7+
def __init__(self, root): # Initialize the main application window
88
self.root = root
99
self.root.title("CSV Plotter GUI")
10-
self.filename = None
11-
self.data = None
12-
self.create_widgets()
10+
self.filename = None # Variable to store the selected CSV file name
11+
self.data = None # Variable to store the loaded data
12+
self.create_widgets() # Call the method to create widgets
1313

1414
def create_widgets(self):
1515
# Create a frame for buttons and file name display
@@ -41,19 +41,19 @@ def create_widgets(self):
4141
self.plot_button.pack(pady=10)
4242

4343
def load_csv(self):
44-
self.filename = filedialog.askopenfilename(filetypes=[("CSV files", "*.csv")])
44+
self.filename = filedialog.askopenfilename(filetypes=[("CSV files", "*.csv")]) # Open file dialog to select CSV file
4545
if self.filename:
4646
try:
47-
with open(self.filename, "r", encoding="utf-8") as f:
48-
lines = f.readlines()
47+
with open(self.filename, "r", encoding="utf-8") as f: # Open the selected CSV file
48+
lines = f.readlines() # Read all lines into a list for header detection
4949

50-
header_index = None # Find the row where 'Counter' appears
51-
for i, line in enumerate(lines):
50+
header_index = None # Initialize the variable to track where (Header)'Counter' appears
51+
for i, line in enumerate(lines): # Iterate through lines to find the header line
5252
if "Counter" in line:
53-
header_index = i
54-
break
53+
header_index = i # Store the index of the line containing 'Counter'
54+
break # If found, break the loop
5555

56-
if header_index is None:
56+
if header_index is None: # If no header row with 'Counter' was found, show error and exit
5757
messagebox.showerror("Error", "CSV file must contain a 'Counter' column.")
5858
return
5959

@@ -73,7 +73,7 @@ def load_csv(self):
7373
messagebox.showerror("Error", f"Could not load CSV file: {e}")
7474

7575
def setup_dropdown_menu(self):
76-
# Get available channel columns (Channel1 to Channel6)
76+
# Get available channel columns
7777
channel_columns = [col for col in self.data.columns if 'Channel' in col]
7878

7979
# Populate dropdown menu with available channels
@@ -82,6 +82,7 @@ def setup_dropdown_menu(self):
8282
self.channel_selection.set(channel_columns[0]) # Default selection to the first channel
8383

8484
def plot_data(self):
85+
"""Creates an interactive plot of the selected data channel using Plotly."""
8586
selected_channel = self.channel_selection.get() # Get the selected channel
8687
if not selected_channel:
8788
messagebox.showerror("Error", "No channel selected for plotting")
@@ -96,9 +97,9 @@ def plot_data(self):
9697
yaxis_title="Value",
9798
template="plotly_white"
9899
)
99-
fig.show()
100+
fig.show() # Display the plot in a new window
100101

101102
if __name__ == "__main__":
102-
root = tk.Tk()
103-
app = CSVPlotterApp(root)
104-
root.mainloop()
103+
root = tk.Tk() # Create the main Tkinter root window
104+
app = CSVPlotterApp(root) # Create an instance of the CSVPlotterApp class
105+
root.mainloop() # Start the Tkinter main loop

0 commit comments

Comments
 (0)