Пример #1
0
 def __init__(self, parent, _canvas, figure):
     global settings_file
     global acquire_file
     global ESS_module
     self.parent = parent # whatever parent 
     self.save_file = None # initalize file for saving data
     self.scan_file = None #initialize Scan File for saving scan data
     self.scan_number = 1 # ID for saving to csv
     self.reference_number = 1 # ref ID for saving to csv
     self.exp_folder = '/home/pi/Desktop/Spectrometer' # experiment folder used for saving
     self.df = None # data frame array used for storing and plotting data
     self.df_scan = None
     self.serial_check = False #variable for flagging serial connection
     self.battery_check_flag = False
     self.battery_percent = 100
     
     # attributes to select data to be plotted
     self.ref = np.ones((288))*1000 # temporary reference
     self.scan_ref = None
     
     # plotting view attributes
     self.ratio_view_handler = False
     self.autoscale_handler = False
     self.prime_pump_handler = False  # handle turning on/off pump
         
     # these are two possible port names for the arduino attachment
     port = "/dev/ttyUSB0"
     port2 = "/dev/ttyUSB1"
     
     try:
         self.ser = serial.Serial(port, baudrate = 115200, timeout = 5)
     except:
         self.ser = serial.Serial(port2, baudrate = 115200, timeout =5)
     
     # two pseudo reads to initalize the spectrometer
     self.ser.write(b"read\n")
     data = self.ser.readline()
     self.ser.write(b"read\n")
     data = self.ser.readline()
     
     
     # intialize attributes for handling data and files
     self.acquire_file = acquire_file
     self.settings_file = settings_file
     self.canvas = _canvas
     self.fig = figure
     
     # create objects for different modules needs for some functions
     self.settings_func = _Settings(settings_file)
     (self.settings, self.wavelength) = self.settings_func.settings_read()
     self.add_remove_top = add_remove_popup(self.parent)
Пример #2
0
    def __init__(self, master):
        global settings_file
        self.root = master
        self.root.title("ESS Module 5 Frame")
        full_screen = False
        if full_screen:
            self.root.attributes('-fullscreen',
                                 True)  # fullscreen on touchscreen
        else:
            self.root.geometry('800x480')  # actual size of RPi touchscreen
        #self.root.attributes('-fullscreen',True)
        self.root.configure(bg="sky blue")
        self.root.minsize(800, 480)  # min size the window can be dragged to

        self.root.tk.call('wm', 'iconphoto', self.root._w,
                          PhotoImage(file="/home/pi/Desktop/BMO_Lab/ESS_png"))

        self.open_loop_stop = None  # control open Loop button

        # parameters for buttons and frames
        #create all the buttons onto to the main window
        button_width = 10
        button_big_height = 4
        button_small_height = 3
        sticky_to = 'nsew'  # allows all buttons to resize

        # setup Serial port-
        ## Graphing Frame and fake plot
        self.graph_frame = Frame(self.root, background="white")
        self.graph_frame.grid(row=2, column=0, sticky=sticky_to)

        #initalize figure
        self.fig = plt.figure()
        plt.xlabel('Wavelength (nm)')
        plt.ylabel('ADC Counts')
        plt.xlim(300, 900)
        plt.ylim(0, 66500)
        plt.subplots_adjust(bottom=0.14, right=0.95, top=0.96)

        #initalize canvas for plotting
        self.canvas = FigureCanvasTkAgg(
            self.fig, master=self.graph_frame)  # A tk.DrawingArea.
        # create toolbar for canvas
        toolbar = NavigationToolbar2Tk(self.canvas, self.graph_frame)
        toolbar.update()
        self.canvas.get_tk_widget().pack(fill=BOTH, expand=True)

        # create function object for calling functions
        settings_func = _Settings(settings_file)

        try:
            settings_func.create_settings()
        except:
            pass

        self.func = functions(self.root, self.canvas, self.fig)

        # allow buttons and frames to resize with the resizing of the root window
        # need to change this to however many rows/columns you hav
        self.root.grid_columnconfigure((0), weight=1)
        self.root.grid_rowconfigure((0, 1, 2), weight=1)

        # with all their corresponding functions (command)
        self.quit_button = Button(self.root,
                                  text="Quit",
                                  fg='Red',
                                  command=self.quit_button,
                                  width=button_width,
                                  height=button_big_height)
        self.quit_button.grid(row=1, column=0, padx=1, sticky=sticky_to)
Пример #3
0
    def __init__(self, master):
        global settings_file
        self.root = master
        self.root.title("ESS System Interface")
        full_screen = False
        if full_screen:
            self.root.attributes('-fullscreen',
                                 True)  # fullscreen on touchscreen
        else:
            self.root.geometry('800x480')  # actual size of RPi touchscreen
        #self.root.attributes('-fullscreen',True)
        self.root.configure(bg="sky blue")
        self.root.minsize(800, 480)  # min size the window can be dragged to

        self.root.tk.call('wm', 'iconphoto', self.root._w,
                          PhotoImage(file="/home/pi/Desktop/BMO_Lab/ESS_png"))

        self.open_loop_stop = None  # control open Loop button

        # parameters for buttons and frames
        #create all the buttons onto to the main window
        button_width = 10
        button_big_height = 4
        button_small_height = 3
        sticky_to = 'nsew'  # allows all buttons to resize

        # setup Serial port-
        ## Graphing Frame and fake plot
        self.graph_frame = Frame(self.root, background="white")
        self.graph_frame.grid(row=1,
                              column=1,
                              columnspan=6,
                              rowspan=5,
                              padx=1,
                              pady=3,
                              sticky=sticky_to)

        #initalize figure
        self.fig = plt.figure()
        plt.xlabel('Wavelength (nm)')
        plt.ylabel('ADC Counts')
        plt.xlim(300, 900)
        plt.ylim(0, 66500)
        plt.subplots_adjust(bottom=0.14, right=0.95, top=0.96)

        #initalize canvas for plotting
        self.canvas = FigureCanvasTkAgg(
            self.fig, master=self.graph_frame)  # A tk.DrawingArea.
        # create toolbar for canvas
        toolbar = NavigationToolbar2Tk(self.canvas, self.graph_frame)
        toolbar.update()
        self.canvas.get_tk_widget().pack(fill=BOTH, expand=True)

        # create function object for calling functions
        settings_func = _Settings(settings_file)

        try:
            settings_func.create_settings()
        except:
            pass

        #(self.settings, self.wavelength) = settings_func.settings_read()
        self.func = functions(self.root, self.canvas, self.fig)

        # allow buttons and frames to resize with the resizing of the root window
        self.root.grid_columnconfigure((0, 1, 2, 3, 4, 5, 6), weight=1)
        self.root.grid_rowconfigure((0, 1, 2, 3, 4, 5, 6), weight=1)

        # with all their corresponding functions (command)
        self.quit_button = Button(self.root,
                                  text="Quit",
                                  fg='Red',
                                  command=self.quit_button,
                                  width=button_width,
                                  height=button_big_height)
        self.quit_button.grid(row=0, column=6, padx=1, sticky=sticky_to)

        self.help_button = Button(self.root,
                                  text="Help",
                                  fg='black',
                                  command=self.func.plot_selected,
                                  width=button_width,
                                  height=button_big_height)
        self.help_button.grid(row=0, column=5, sticky=sticky_to)

        self.settings_button = Button(
            self.root,
            text="Settings",
            fg='black',
            command=lambda: self.window_popup(self.root),
            width=button_width,
            height=button_big_height)
        self.settings_button.grid(row=0,
                                  column=4,
                                  padx=(8, 1),
                                  sticky=sticky_to)

        self.save_spectra_button = Button(self.root,
                                          text="Save as Spectra",
                                          wraplength=80,
                                          fg='black',
                                          command=self.func.save_spectra,
                                          width=button_width,
                                          height=button_big_height,
                                          state=NORMAL)
        self.save_spectra_button.grid(row=0,
                                      column=3,
                                      padx=(1, 8),
                                      sticky=sticky_to)

        self.save_reference_button = Button(self.root,
                                            text="Save as Reference",
                                            wraplength=80,
                                            fg='black',
                                            command=self.func.save_reference,
                                            width=button_width,
                                            height=button_big_height,
                                            state=NORMAL)
        self.save_reference_button.grid(row=0,
                                        column=2,
                                        padx=(10, 0),
                                        sticky=sticky_to)

        self.open_new_button = Button(self.root,
                                      text="New Experiment",
                                      wraplength=80,
                                      fg='black',
                                      command=self.func.open_new_experiment,
                                      width=button_width,
                                      height=button_big_height)
        self.open_new_button.grid(row=0,
                                  column=1,
                                  padx=(0, 5),
                                  sticky=sticky_to)

        self.open_experiment_button = Button(self.root,
                                             text="Open Experiment",
                                             wraplength=80,
                                             fg='black',
                                             command=self.func.OpenFile,
                                             width=button_width,
                                             height=button_big_height)
        self.open_experiment_button.grid(row=0, column=0, sticky=sticky_to)

        self.acquire_button = Button(
            self.root,
            text="Acquire",
            wraplength=80,
            fg='black',
            command=lambda: self.func.acquire(save=False),
            width=button_width,
            height=button_big_height)
        self.acquire_button.grid(row=1,
                                 column=0,
                                 pady=(3, 1),
                                 sticky=sticky_to)

        self.acquire_save_button = Button(
            self.root,
            text="Acquire and Save",
            fg='black',
            wraplength=80,
            command=lambda: self.func.acquire(save=True),
            width=button_width,
            height=button_big_height,
            state=NORMAL)
        self.acquire_save_button.grid(row=2,
                                      column=0,
                                      pady=(0, 1),
                                      sticky=sticky_to)

        self.autorange_button = Button(self.root,
                                       text="Auto-Range",
                                       fg='black',
                                       wraplength=80,
                                       command=self.func.autorange,
                                       width=button_width,
                                       height=button_big_height)
        self.autorange_button.grid(row=3,
                                   column=0,
                                   pady=(0, 5),
                                   sticky=sticky_to)

        self.open_loop_button = Button(self.root,
                                       text="Open Loop",
                                       fg='black',
                                       state=NORMAL,
                                       command=self.open_loop,
                                       width=button_width,
                                       height=button_big_height)
        self.open_loop_button.grid(row=4,
                                   column=0,
                                   pady=(5, 1),
                                   sticky=sticky_to)

        self.sequence_button = Button(
            self.root,
            text="Sequence",
            fg='black',
            wraplength=80,
            command=lambda: self.func.sequence(save=False),
            width=button_width,
            height=button_big_height)
        self.sequence_button.grid(row=5, column=0, sticky=sticky_to)

        self.sequence_save_button = Button(
            self.root,
            text="Sequence and Save",
            fg='black',
            wraplength=80,
            command=lambda: self.func.sequence(save=True),
            width=button_width,
            height=button_big_height)
        self.sequence_save_button.grid(row=6, column=0, sticky=sticky_to)

        self.scan_button = Button(self.root,
                                  text="Scan",
                                  fg='black',
                                  wraplength=80,
                                  command=lambda: self.func.scan(save=True),
                                  width=button_width,
                                  height=button_small_height)
        self.scan_button.grid(row=6, column=1, padx=1, sticky=sticky_to)

        self.ratio_view_button = Button(self.root,
                                        text="Ratio View",
                                        fg='black',
                                        wraplength=80,
                                        command=self.ratio_view_toggle,
                                        width=button_width,
                                        height=button_small_height,
                                        state=NORMAL)
        self.ratio_view_button.grid(row=6, column=2, padx=1, sticky=sticky_to)

        self.autoscale_button = Button(self.root,
                                       text="Autoscale",
                                       fg='black',
                                       wraplength=80,
                                       command=self.autoscale_toggle,
                                       width=button_width,
                                       height=button_small_height)
        self.autoscale_button.grid(row=6, column=3, padx=1, sticky=sticky_to)

        self.plot_selected_button = Button(self.root,
                                           text="Plot Selected",
                                           fg='black',
                                           wraplength=80,
                                           command=self.func.plot_selected,
                                           state=NORMAL,
                                           width=button_width,
                                           height=button_small_height)
        self.plot_selected_button.grid(row=6,
                                       column=4,
                                       padx=1,
                                       sticky=sticky_to)

        self.clear_button = Button(self.root,
                                   text="Clear",
                                   fg='black',
                                   wraplength=80,
                                   command=self.func.clear,
                                   width=button_width,
                                   height=button_small_height)
        self.clear_button.grid(row=6, column=5, padx=1, sticky=sticky_to)

        self.add_remove_button = Button(self.root,
                                        text="Add/Remove Plots",
                                        fg='black',
                                        wraplength=85,
                                        state=NORMAL,
                                        command=self.func.add_remove_func,
                                        width=button_width,
                                        height=button_small_height)
        self.add_remove_button.grid(row=6,
                                    column=6,
                                    padx=5,
                                    pady=1,
                                    sticky=sticky_to)
Пример #4
0
    def __init__(self, master):
        global settings_file
        self.root = master
        self.root.title("ESS System Interface")
        full_screen = True
        if full_screen:
            self.root.attributes('-fullscreen',
                                 True)  # fullscreen on touchscreen
        else:
            self.root.geometry('800x480')  # actual size of RPi touchscreen
        #self.root.attributes('-fullscreen',True)
        self.root.configure(bg="sky blue")
        self.root.minsize(800, 480)  # min size the window can be dragged to

        self.root.tk.call('wm', 'iconphoto', self.root._w,
                          PhotoImage(file="/home/pi/Desktop/BMO_Lab/ESS_png"))

        self.open_loop_stop = None  # control open Loop button

        # module message/label

        # parameters for buttons and frames
        #create all the buttons onto to the main window
        button_width = 10
        button_big_height = 8
        button_small_height = 3
        sticky_to = 'nsew'  # allows all buttons to resize

        # setup Serial port-
        ## Graphing Frame and fake plot
        self.graph_frame = Frame(self.root, background="white")
        self.graph_frame.grid(row=2,
                              column=0,
                              columnspan=7,
                              padx=1,
                              pady=3,
                              sticky=sticky_to)

        #initalize figure
        self.fig = plt.figure()
        plt.xlabel('Wavelength (nm)')
        plt.ylabel('ADC Counts')
        plt.xlim(300, 900)
        plt.ylim(0, 66500)
        plt.subplots_adjust(bottom=0.14, right=0.95, top=0.96)

        #initalize canvas for plotting
        self.canvas = FigureCanvasTkAgg(
            self.fig, master=self.graph_frame)  # A tk.DrawingArea.
        # create toolbar for canvas
        toolbar = NavigationToolbar2Tk(self.canvas, self.graph_frame)
        toolbar.update()
        self.canvas.get_tk_widget().pack(fill=BOTH, expand=True)

        # create function object for calling functions
        settings_func = _Settings(settings_file)

        try:
            settings_func.create_settings()
        except:
            pass

        #(self.settings, self.wavelength) = settings_func.settings_read()
        self.func = functions(self.root, self.canvas, self.fig)
        self.func.home()

        module_button = Button(self.root,
                               text="Module 1: Scanning ESS",
                               bg='sky blue',
                               bd=0,
                               highlightthickness=0,
                               width=button_width,
                               height=7)
        module_button.grid(row=0,
                           column=0,
                           columnspan=7,
                           padx=1,
                           sticky=sticky_to)

        # with all their corresponding functions (command)
        self.quit_button = Button(self.root,
                                  text="Quit",
                                  fg='Red',
                                  command=self.quit_button,
                                  width=button_width,
                                  height=button_big_height)
        self.quit_button.grid(row=1,
                              column=6,
                              padx=1,
                              pady=1,
                              sticky=sticky_to)

        self.help_button = Button(self.root,
                                  text="Help",
                                  fg='black',
                                  command=self.func.plot_selected,
                                  width=button_width,
                                  height=button_big_height)
        self.help_button.grid(row=1,
                              column=5,
                              padx=1,
                              pady=1,
                              sticky=sticky_to)

        self.settings_button = Button(
            self.root,
            text="Settings",
            fg='black',
            command=lambda: self.window_popup(self.root),
            width=button_width,
            height=button_big_height)
        self.settings_button.grid(row=1,
                                  column=4,
                                  padx=1,
                                  pady=1,
                                  sticky=sticky_to)

        self.save_reference_button = Button(
            self.root,
            text="Save as Reference",
            wraplength=80,
            fg='black',
            command=self.func.save_scan_reference,
            width=button_width,
            height=button_big_height)
        self.save_reference_button.grid(row=1,
                                        column=3,
                                        padx=1,
                                        pady=1,
                                        sticky=sticky_to)

        self.acquire_button = Button(
            self.root,
            text="Acquire",
            wraplength=80,
            fg='black',
            command=lambda: self.func.acquire(save=False),
            width=button_width,
            height=button_big_height)
        self.acquire_button.grid(row=1,
                                 column=2,
                                 pady=1,
                                 padx=1,
                                 sticky=sticky_to)

        self.scan_button = Button(self.root,
                                  text="Scan",
                                  fg='black',
                                  wraplength=80,
                                  command=self.func.scan,
                                  width=button_width,
                                  height=button_big_height)

        self.scan_button.grid(row=1,
                              column=1,
                              padx=1,
                              pady=1,
                              sticky=sticky_to)

        self.open_scan_file_button = Button(self.root,
                                            text='Create Scan File',
                                            fg='black',
                                            wraplength=80,
                                            command=self.func.new_scan,
                                            width=button_width,
                                            height=button_big_height)
        self.open_scan_file_button.grid(row=1,
                                        column=0,
                                        padx=1,
                                        pady=1,
                                        sticky=sticky_to)

        # allow buttons and frames to resize with the resizing of the root window
        self.root.grid_columnconfigure((0, 1, 2, 3, 4, 5, 6), weight=1)
        self.root.grid_rowconfigure((0, 1, 2), weight=1)
Пример #5
0
    def __init__(self, master):
        global settings_file
        self.root = master
        self.root.title("ESS Module 4 Frame")
        full_screen = False
        if full_screen:
            self.root.attributes('-fullscreen',
                                 True)  # fullscreen on touchscreen
        else:
            self.root.geometry('800x480')  # actual size of RPi touchscreen
        #self.root.attributes('-fullscreen',True)
        self.root.configure(bg="sky blue")
        self.root.minsize(800, 480)  # min size the window can be dragged to

        self.percent = 0  # battery percent variable
        self.battery_array = []
        self.charging = False
        self.open_loop_stop = None  # control open Loop button
        battery_font = tkFont.Font(family="Lucida Grande", size=8)
        label_font = tkFont.Font(family="Lucida Grande", size=12)
        warning_font = tkFont.Font(family="Lucida Grande", size=24)
        # parameters for buttons and frames
        #create all the buttons onto to the main window
        button_width = 8
        button_big_height = 8
        button_small_height = 3
        sticky_to = 'nsew'  # allows all buttons to resize

        # setup Serial port-
        ## Graphing Frame and fake plot
        self.graph_frame = Frame(self.root, background="white")
        self.graph_frame.grid(row=1, column=0, columnspan=5, sticky='nsew')

        #initalize figure
        self.fig = plt.figure()
        plt.xlabel('Wavelength (nm)')
        plt.ylabel('ADC Counts')
        plt.xlim(300, 900)
        plt.ylim(0, 66500)
        plt.subplots_adjust(bottom=0.14, right=0.95, top=0.96)

        #initalize canvas for plotting
        self.canvas = FigureCanvasTkAgg(
            self.fig, master=self.graph_frame)  # A tk.DrawingArea.
        # create toolbar for canvas
        toolbar = NavigationToolbar2Tk(self.canvas, self.graph_frame)
        toolbar.update()
        self.canvas.get_tk_widget().pack(fill=BOTH, expand=True)

        # create function object for calling functions
        settings_func = _Settings(settings_file)

        try:
            settings_func.create_settings()
        except:
            pass

        self.func = functions(self.root, self.canvas, self.fig)

        self.open_new_button = Button(self.root,
                                      text="New Experiment",
                                      wraplength=80,
                                      fg='black',
                                      command=self.func.open_new_experiment,
                                      width=button_width,
                                      height=button_big_height)
        self.open_new_button.grid(row=0,
                                  column=0,
                                  padx=(0, 1),
                                  sticky=sticky_to)

        self.open_experiment_button = Button(
            self.root,
            text="Open Experiment",
            wraplength=80,
            fg='black',
            command=self.check_scan_number_open_file,
            width=button_width,
            height=button_big_height)
        self.open_experiment_button.grid(row=0, column=1, sticky=sticky_to)

        self.module_label = Label(self.root,
                                  bg='sky blue',
                                  wraplength=80,
                                  text="Module 4: TBD",
                                  width=button_width,
                                  height=button_big_height)
        self.module_label.grid(row=0, column=4, padx=1, sticky='nsew')

        # with all their corresponding functions (command)
        self.quit_button = Button(self.root,
                                  text="Quit",
                                  fg='Red',
                                  command=self.quit_button,
                                  width=button_width,
                                  height=button_big_height)
        self.quit_button.grid(row=0, column=2, padx=1, sticky='nsew')

        #battery Frame to show battery level and scan number
        self.battery_frame = Frame(self.root, bg='sky blue', width=4)
        self.battery_frame.grid(row=0, column=3, sticky='nsew')

        # allow buttons and frames to resize with the resizing of the root window
        # need to change this to however many rows/columns you hav
        self.root.grid_columnconfigure((0, 1, 2, 3, 4), weight=1)
        self.root.grid_rowconfigure((0, 1), weight=1)

        battery_width = 6

        self.battery_label_1 = Label(self.battery_frame,
                                     bg="green",
                                     height=1,
                                     width=battery_width)
        self.battery_label_1.grid(row=0, column=0, padx=1, sticky='nsew')

        self.battery_label_2 = Label(self.battery_frame,
                                     text="%",
                                     font=battery_font,
                                     height=1,
                                     bg="green",
                                     width=battery_width)
        self.battery_label_2.grid(row=1, column=0, padx=1, sticky='nsew')

        self.battery_label_3 = Label(self.battery_frame,
                                     bg="green",
                                     height=1,
                                     width=battery_width)
        self.battery_label_3.grid(row=2, column=0, padx=1, sticky='nsew')

        self.battery_label_4 = Label(self.battery_frame,
                                     bg="green",
                                     height=1,
                                     width=battery_width)
        self.battery_label_4.grid(row=3, column=0, padx=1, sticky='nsew')

        self.scan_label = Label(self.battery_frame,
                                bg='sky blue',
                                text="Scan: ",
                                font=battery_font,
                                height=1,
                                width=battery_width,
                                wraplength=80)
        self.scan_label.grid(row=4, column=0, padx=1, sticky='nsew')

        self.battery_frame.grid_rowconfigure((0, 1, 2, 3, 4), weight=1)
        self.battery_frame.grid_columnconfigure((0), weight=1)

        # show module connected
        #messagebox.showinfo('Module #','Module 0: Base ESS System connected (No attachments)')

        # check battery percent from arduino
        def battery_percent_check():
            self.percent = self.func.battery_check()
            self.charging = False
            # check for charging and then add percent to array for averaging
            if int(self.percent) == 1000:
                self.charging = True
            self.battery_array.append(int(self.percent))
            if len(self.battery_array) > 10:
                del self.battery_array[0]

            #average battery_array
            self.percent = int(
                sum(self.battery_array) / (len(self.battery_array)))

            if self.charging:
                self.battery_label_1.configure(bg='green')
                self.battery_label_2.configure(font=battery_font,
                                               text="Charging",
                                               bg='green')
                self.battery_label_3.configure(bg='green')
                self.battery_label_4.configure(bg='green')
            else:
                if int(self.percent) >= 75:

                    self.battery_label_1.configure(bg='green')
                    self.battery_label_2.configure(font=battery_font,
                                                   text=str(self.percent) +
                                                   " %",
                                                   bg='green')
                    self.battery_label_3.configure(bg='green')
                    self.battery_label_4.configure(bg='green')

                elif int(self.percent) < 75 and int(self.percent) >= 50:
                    self.battery_label_2.configure(font=battery_font,
                                                   text=str(self.percent) +
                                                   " %",
                                                   bg='green')
                    self.battery_label_1.configure(bg='red')
                    self.battery_label_3.configure(bg='green')
                    self.battery_label_4.configure(bg='green')

                elif int(self.percent) < 50 and int(self.percent) >= 25:
                    self.battery_label_1.configure(bg='red')
                    self.battery_label_2.configure(font=battery_font,
                                                   text=str(self.percent) +
                                                   " %",
                                                   bg='red')
                    self.battery_label_3.configure(bg='green')
                    self.battery_label_4.configure(bg='green')

                elif int(self.percent) < 25 and int(self.percent) >= 15:
                    self.battery_label_1.configure(bg='red')
                    self.battery_label_2.configure(font=battery_font,
                                                   text=str(self.percent) +
                                                   " %",
                                                   bg='red')
                    self.battery_label_3.configure(bg='red')
                    self.battery_label_4.configure(bg='yellow')
                else:
                    self.battery_label_1.configure(bg='red')
                    self.battery_label_2.configure(font=battery_font,
                                                   text="LOW",
                                                   bg='red')
                    self.battery_label_3.configure(bg='red')
                    self.battery_label_4.configure(bg='red')

                    error_top = Toplevel(self.root, bg="red")
                    message = Label(
                        error_top,
                        bg="white",
                        text="Low Battery! Plug In device and Save Data",
                        font=warning_font,
                        wraplength=250)
                    message.grid(row=0, column=0, padx=10, pady=10)
                    error_top.title("Warning")
                    error_top.lift()

                    error_top.after(3000, error_top.destroy)

            try:
                self.root.after(10000, battery_percent_check)
            except:
                pass

        battery_percent_check()
Пример #6
0
    def __init__(self, master):
        global settings_file
        self.root = master
        self.root.title("ESS System Interface")
        full_screen = True
        if full_screen:
            self.root.attributes('-fullscreen',
                                 True)  # fullscreen on touchscreen
        else:
            self.root.geometry('800x480')  # actual size of RPi touchscreen
        #self.root.attributes('-fullscreen',True)
        self.root.configure(bg="sky blue")
        self.root.minsize(800, 480)  # min size the window can be dragged to

        self.open_loop_stop = None  # control open Loop button
        # parameters for buttons and frames
        #create all the buttons onto to the main window
        button_width = 8
        button_big_height = 4
        button_small_height = 3
        sticky_to = 'nsew'  # allows all buttons to resize

        # battery check functions
        self.percent = 0  # battery percent variable
        self.charging = False
        self.battery_array = []
        battery_font = tkFont.Font(family="Lucida Grande", size=9)
        label_font = tkFont.Font(family="Lucida Grande", size=12)
        warning_font = tkFont.Font(family="Lucida Grande", size=24)
        module_message = 'Module 0: Base ESS'
        # setup Serial port-
        ## Graphing Frame and fake plot
        self.graph_frame = Frame(self.root, background="white")
        self.graph_frame.grid(row=1,
                              column=1,
                              columnspan=7,
                              rowspan=5,
                              padx=1,
                              pady=3,
                              sticky=sticky_to)

        #initalize figure
        self.fig = plt.figure()
        plt.xlabel('Wavelength (nm)')
        plt.ylabel('ADC Counts')
        plt.xlim(300, 900)
        plt.ylim(0, 66500)
        plt.subplots_adjust(bottom=0.14, right=0.95, top=0.96)

        #initalize canvas for plotting
        self.canvas = FigureCanvasTkAgg(
            self.fig, master=self.graph_frame)  # A tk.DrawingArea.
        # create toolbar for canvas
        NavigationToolbar2Tk.toolitems = [
            t for t in NavigationToolbar2Tk.toolitems
            if t[0] not in ('Subplots', )
        ]
        self.toolbar = NavigationToolbar2Tk(self.canvas, self.graph_frame)
        self.toolbar.update()
        self.canvas.get_tk_widget().pack(fill=BOTH, expand=True)

        #toolbar.children['Subplots'].pack_forget()
        # create function object for calling functions
        settings_func = _Settings(settings_file)

        try:
            settings_func.create_settings()
        except:
            pass

        #(self.settings, self.wavelength) = settings_func.settings_read()
        self.func = functions(self.root, self.canvas, self.fig)
        #self.func.home()

        # allow buttons and frames to resize with the resizing of the root window
        self.root.grid_columnconfigure((0, 1, 2, 3, 4, 5, 6, 7), weight=1)
        self.root.grid_rowconfigure((0, 1, 2, 3, 4, 5, 6), weight=1)

        # __________________________    Create all buttons for the main GUI page _______________________________ #
        # with all their corresponding functions (command)
        self.quit_button = Button(self.root,
                                  text="Quit",
                                  fg='Red',
                                  command=self.quit_button,
                                  width=button_width,
                                  height=button_big_height)
        self.quit_button.grid(row=0, column=6, padx=1, sticky=sticky_to)

        self.help_button = Button(self.root,
                                  text="Help",
                                  fg='black',
                                  command=self.func.plot_selected,
                                  width=button_width,
                                  height=button_big_height)
        self.help_button.grid(row=0, column=5, sticky=sticky_to)

        self.settings_button = Button(
            self.root,
            text="Settings",
            fg='black',
            command=lambda: self.window_popup(self.root),
            width=button_width,
            height=button_big_height)
        self.settings_button.grid(row=0,
                                  column=4,
                                  padx=(1, 1),
                                  sticky=sticky_to)

        self.save_spectra_button = Button(self.root,
                                          text="Save as Spectra",
                                          wraplength=80,
                                          fg='black',
                                          command=self.check_spectra,
                                          width=button_width,
                                          height=button_big_height,
                                          state=NORMAL)
        self.save_spectra_button.grid(row=0,
                                      column=3,
                                      padx=(1, 1),
                                      sticky=sticky_to)

        self.save_reference_button = Button(self.root,
                                            text="Save as Reference",
                                            wraplength=80,
                                            fg='black',
                                            command=self.check_ref_number,
                                            width=button_width,
                                            height=button_big_height,
                                            state=NORMAL)
        self.save_reference_button.grid(row=0,
                                        column=2,
                                        padx=(1, 0),
                                        sticky=sticky_to)

        self.open_new_button = Button(self.root,
                                      text="New Experiment",
                                      wraplength=80,
                                      fg='black',
                                      command=self.func.open_new_experiment,
                                      width=button_width,
                                      height=button_big_height)
        self.open_new_button.grid(row=0,
                                  column=1,
                                  padx=(0, 1),
                                  sticky=sticky_to)

        self.open_experiment_button = Button(
            self.root,
            text="Open Experiment",
            wraplength=80,
            fg='black',
            command=self.check_scan_number_open_file,
            width=button_width,
            height=button_big_height)
        self.open_experiment_button.grid(row=0, column=0, sticky=sticky_to)

        self.acquire_button = Button(
            self.root,
            text="Acquire",
            wraplength=80,
            fg='black',
            command=lambda: self.func.acquire(save=False),
            width=button_width,
            height=button_big_height)
        self.acquire_button.grid(row=1,
                                 column=0,
                                 pady=(3, 1),
                                 sticky=sticky_to)

        self.acquire_save_button = Button(self.root,
                                          text="Acquire and Save",
                                          fg='black',
                                          wraplength=80,
                                          command=self.check_scan_number,
                                          width=button_width,
                                          height=button_big_height,
                                          state=NORMAL)
        self.acquire_save_button.grid(row=2,
                                      column=0,
                                      pady=(0, 1),
                                      sticky=sticky_to)

        self.autorange_button = Button(self.root,
                                       text="Auto-Range",
                                       fg='black',
                                       wraplength=80,
                                       command=self.func.autorange,
                                       width=button_width,
                                       height=button_big_height)
        self.autorange_button.grid(row=3,
                                   column=0,
                                   pady=(0, 5),
                                   sticky=sticky_to)

        self.open_loop_button = Button(self.root,
                                       text="Open Loop",
                                       fg='black',
                                       state=NORMAL,
                                       command=self.open_loop,
                                       width=button_width,
                                       height=button_big_height)
        self.open_loop_button.grid(row=4,
                                   column=0,
                                   pady=(5, 1),
                                   sticky=sticky_to)

        self.sequence_button = Button(
            self.root,
            text="Sequence",
            fg='black',
            wraplength=80,
            command=lambda: self.func.sequence(save=False),
            width=button_width,
            height=button_big_height)
        self.sequence_button.grid(row=5, column=0, sticky=sticky_to)

        self.sequence_save_button = Button(self.root,
                                           text="Sequence and Save",
                                           fg='black',
                                           wraplength=80,
                                           command=self.check_seq_number,
                                           width=button_width,
                                           height=button_big_height)
        self.sequence_save_button.grid(row=6, column=0, sticky=sticky_to)

        #self.scan_button = Button(self.root, text = "Scan", fg = 'black', wraplength = 80, command = lambda: self.func.scan(save = True), width = button_width, height = button_small_height)
        #self.scan_button.grid(row = 6, column = 1, padx = 1, sticky = sticky_to)

        self.ratio_view_button = Button(self.root,
                                        text="Ratio View",
                                        fg='black',
                                        wraplength=80,
                                        command=self.ratio_view_toggle,
                                        width=button_width,
                                        height=button_small_height,
                                        state=NORMAL)
        self.ratio_view_button.grid(row=6, column=1, padx=1, sticky=sticky_to)

        self.autoscale_button = Button(self.root,
                                       text="Autoscale",
                                       fg='black',
                                       wraplength=80,
                                       command=self.autoscale_toggle,
                                       width=button_width,
                                       height=button_small_height)
        self.autoscale_button.grid(row=6, column=2, padx=1, sticky=sticky_to)

        self.plot_selected_button = Button(self.root,
                                           text="Plot Selected",
                                           fg='black',
                                           wraplength=80,
                                           command=self.func.plot_selected,
                                           state=NORMAL,
                                           width=button_width,
                                           height=button_small_height)
        self.plot_selected_button.grid(row=6,
                                       column=3,
                                       padx=1,
                                       sticky=sticky_to)

        self.clear_button = Button(self.root,
                                   text="Clear",
                                   fg='black',
                                   wraplength=80,
                                   command=self.func.clear,
                                   width=button_width,
                                   height=button_small_height)
        self.clear_button.grid(row=6, column=4, padx=1, sticky=sticky_to)

        self.add_remove_button = Button(self.root,
                                        text="Add/Remove Plots",
                                        fg='black',
                                        wraplength=85,
                                        state=NORMAL,
                                        command=self.func.add_remove_func,
                                        width=button_width,
                                        height=button_small_height)
        self.add_remove_button.grid(row=6,
                                    column=5,
                                    columnspan=2,
                                    padx=5,
                                    pady=1,
                                    sticky=sticky_to)

        module_label = Label(self.root,
                             bg='sky blue',
                             text=module_message,
                             wraplength=80,
                             font=label_font)
        module_label.grid(row=6, column=7, padx=5, pady=1, sticky=sticky_to)

        #### Provide scan number in the top right of the GUI page
        self.scan_label = Label(self.root,
                                bg='sky blue',
                                text="Scan: ",
                                wraplength=80)
        self.scan_label.grid(row=0, column=7, padx=5, pady=1, sticky='nsew')

        ####### Battery label depending if its the battery powered system
        '''