Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from import_raw import get_raw_data
- from select_sequences import filter_data
- from interactive_plot import setup_interactive_plot, interactive_update
- import matplotlib
- import matplotlib.pyplot as plt
- import matplotlib.backends.backend_tkagg as tkagg
- import tkinter as tk
- # next button
- def on_next(current_plot_index):
- current_plot_index = (current_plot_index + 1) % len(filtered_data)
- interactive_update(filtered_data[current_plot_index], figure, canvas, stats_frame)
- update_buttons()
- # previous button
- def on_previous(current_plot_index):
- current_plot_index = (current_plot_index - 1) % len(filtered_data)
- interactive_update(filtered_data[current_plot_index], figure, canvas, stats_frame)
- update_buttons()
- # finish button (to do)
- def on_finish():
- window.quit() # replace with call to data reduction script
- # exit button
- def on_exit():
- window.quit()
- # dynamic button logic
- def update_buttons():
- prev_button.pack_forget()
- next_button.pack_forget()
- finish_button.pack_forget()
- # exclude previous button on first index
- if current_plot_index > 0:
- prev_button.pack(side=tk.LEFT)
- # replace next with finish on the last index
- if current_plot_index == len(filtered_data) - 1:
- finish_button.pack(side=tk.RIGHT)
- else:
- next_button.pack(side=tk.RIGHT)
- ### main code below ###
- matplotlib.use('TkAgg') # forces TkAgg backend to matplotlib (for MacOSX development)
- # get and filter raw data
- global filtered_data
- all_data, sequence_data = get_raw_data() # get all raw data and group into sequences
- filtered_data = filter_data(all_data, sequence_data) # filter out only the selected sequences
- # initiate GUI
- window = tk.Tk()
- window.title('HeMan - Alphachron Data Reduction')
- # define and pack main frame
- main_frame = tk.Frame(window)
- main_frame.pack(fill=tk.BOTH, expand=True)
- # define and pack frame for statistics panel on the left
- stats_frame = tk.Frame(main_frame, borderwidth=2, relief=tk.SUNKEN)
- stats_frame.pack(side=tk.LEFT, fill=tk.Y)
- # define and pack frame for data plot and buttons on the right
- right_frame = tk.Frame(main_frame)
- right_frame.pack(side=tk.RIGHT, fill=tk.X, expand=True)
- # define and pack frame for buttons
- button_frame = tk.Frame(right_frame)
- button_frame.pack(side=tk.BOTTOM, fill=tk.X)
- # define and pack frame for data
- data_frame = tk.Frame(right_frame)
- data_frame.pack(side=tk.TOP, fill=tk.BOTH, expand=True)
- # initialize and pack the data frame
- global canvas
- figure = plt.figure(figsize=(15,8))
- canvas = tkagg.FigureCanvasTkAgg(figure, master=data_frame)
- canvas.draw()
- canvas.get_tk_widget().pack(side=tk.TOP, fill=tk.BOTH, expand=True)
- # set current_plot_index and make it globally available
- current_plot_index = 0
- # initialize and pack buttons
- global prev_button, exit_button, next_button, finish_button
- button_options = {'width': 10, 'height': 2}
- exit_button = tk.Button(button_frame, text="Exit", command=lambda: on_exit(), **button_options)
- prev_button = tk.Button(button_frame, text="Previous", command=lambda: on_previous(current_plot_index), **button_options)
- next_button = tk.Button(button_frame, text="Next", command=lambda: on_next(current_plot_index), **button_options)
- finish_button = tk.Button(button_frame, text="Finish", command=lambda: on_finish(), **button_options)
- prev_button.pack(side=tk.LEFT)
- exit_button.pack(side=tk.LEFT)
- next_button.pack(side=tk.RIGHT)
- finish_button.pack(side=tk.RIGHT)
- # update the panes
- update_buttons()
- setup_interactive_plot(filtered_data[current_plot_index], figure, canvas, stats_frame)
- # main window loop
- window.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement