Advertisement
Guest User

Untitled

a guest
May 5th, 2024
42
0
2 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.66 KB | None | 0 0
  1. from import_raw import get_raw_data
  2. from select_sequences import filter_data
  3. from interactive_plot import setup_interactive_plot, interactive_update
  4. import matplotlib
  5. import matplotlib.pyplot as plt
  6. import matplotlib.backends.backend_tkagg as tkagg
  7. import tkinter as tk
  8.  
  9.  
  10. # next button
  11. def on_next(current_plot_index):
  12.     current_plot_index = (current_plot_index + 1) % len(filtered_data)
  13.     interactive_update(filtered_data[current_plot_index], figure, canvas, stats_frame)
  14.     update_buttons()
  15.  
  16.  
  17. # previous button
  18. def on_previous(current_plot_index):
  19.     current_plot_index = (current_plot_index - 1) % len(filtered_data)
  20.     interactive_update(filtered_data[current_plot_index], figure, canvas, stats_frame)
  21.     update_buttons()
  22.  
  23.  
  24. # finish button (to do)
  25. def on_finish():
  26.     window.quit() # replace with call to data reduction script
  27.  
  28.  
  29. # exit button
  30. def on_exit():
  31.     window.quit()
  32.  
  33.  
  34. # dynamic button logic
  35. def update_buttons():
  36.     prev_button.pack_forget()
  37.     next_button.pack_forget()
  38.     finish_button.pack_forget()
  39.  
  40.     # exclude previous button on first index
  41.     if current_plot_index > 0:
  42.         prev_button.pack(side=tk.LEFT)
  43.    
  44.     # replace next with finish on the last index
  45.     if current_plot_index == len(filtered_data) - 1:
  46.         finish_button.pack(side=tk.RIGHT)
  47.     else:  
  48.         next_button.pack(side=tk.RIGHT)
  49.  
  50.  
  51.  
  52. ### main code below ###
  53.  
  54.  
  55. matplotlib.use('TkAgg') # forces TkAgg backend to matplotlib (for MacOSX development)
  56.  
  57. # get and filter raw data
  58. global filtered_data
  59. all_data, sequence_data = get_raw_data() # get all raw data and group into sequences
  60. filtered_data           = filter_data(all_data, sequence_data) # filter out only the selected sequences
  61.  
  62. # initiate GUI
  63. window = tk.Tk()
  64. window.title('HeMan - Alphachron Data Reduction')
  65.  
  66. # define and pack main frame
  67. main_frame = tk.Frame(window)
  68. main_frame.pack(fill=tk.BOTH, expand=True)
  69.  
  70. # define and pack frame for statistics panel on the left
  71. stats_frame = tk.Frame(main_frame, borderwidth=2, relief=tk.SUNKEN)
  72. stats_frame.pack(side=tk.LEFT, fill=tk.Y)
  73.  
  74. # define and pack frame for data plot and buttons on the right
  75. right_frame = tk.Frame(main_frame)
  76. right_frame.pack(side=tk.RIGHT, fill=tk.X, expand=True)
  77.  
  78. # define and pack frame for buttons
  79. button_frame = tk.Frame(right_frame)
  80. button_frame.pack(side=tk.BOTTOM, fill=tk.X)
  81.  
  82. # define and pack frame for data
  83. data_frame = tk.Frame(right_frame)
  84. data_frame.pack(side=tk.TOP, fill=tk.BOTH, expand=True)
  85.  
  86. # initialize and pack the data frame
  87. global canvas
  88. figure = plt.figure(figsize=(15,8))
  89. canvas = tkagg.FigureCanvasTkAgg(figure, master=data_frame)
  90. canvas.draw()
  91. canvas.get_tk_widget().pack(side=tk.TOP, fill=tk.BOTH, expand=True)
  92.  
  93. # set current_plot_index and make it globally available
  94. current_plot_index = 0
  95.  
  96. # initialize and pack buttons
  97. global prev_button, exit_button, next_button, finish_button
  98. button_options = {'width': 10, 'height': 2}
  99. exit_button    = tk.Button(button_frame, text="Exit", command=lambda: on_exit(), **button_options)
  100. prev_button    = tk.Button(button_frame, text="Previous", command=lambda: on_previous(current_plot_index), **button_options)
  101. next_button    = tk.Button(button_frame, text="Next", command=lambda: on_next(current_plot_index), **button_options)
  102. finish_button  = tk.Button(button_frame, text="Finish", command=lambda: on_finish(), **button_options)
  103. prev_button.pack(side=tk.LEFT)
  104. exit_button.pack(side=tk.LEFT)
  105. next_button.pack(side=tk.RIGHT)
  106. finish_button.pack(side=tk.RIGHT)
  107.  
  108. # update the panes
  109. update_buttons()
  110. setup_interactive_plot(filtered_data[current_plot_index], figure, canvas, stats_frame)
  111.  
  112. # main window loop
  113. window.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement