Ejemplo n.º 1
0
    def __init__(self, parent, controller):
        # Tkinter Fame Setup
        tk.Frame.__init__(self, parent)
        self.parent = parent
        self.controller = controller
        self.columnconfigure(0, weight=1)

        # Find the current operating mode
        self.mode = [] if modes.getCurrentMode() is None else modes.getCurrentMode()

        if self.mode == []:
            # should not reach here
            tm.showerror(
                "Unexpected Error, no current operating mode for pacemaker")

        label = tk.Label(self, text='DCM', font=settings.LARGE_FONT)
        label.grid(row=0, column=0, columnspan=2, pady=20)

        # Dynamically create widgets for various parameters
        x = 1
        for key in self.mode.params:
            dcm_data_label = tk.Label(
                self, text='{} :'.format(key), font=settings.NORM_FONT)
            dcm_value_label = tk.Label(self, text='{}'.format(
                self.mode.params[key]), font=settings.NORM_FONT)
            dcm_data_label.grid(row=x, column=0, sticky="nsew")
            dcm_value_label.grid(row=x, column=1, sticky="nsew")
            x += 1

        # Button Widgets
        b1 = ttk.Button(self, text="Edit Parameters", command=lambda: self.edit_params())
        b2 = ttk.Button(self, text="Change Mode", command=lambda: self.change_mode())
        b3 = ttk.Button(self, text="Heart Monitor", command=lambda: self.show_heartview())
        bx = ttk.Button(self, text="Exit Session", command=lambda: exit_session(controller))

        # Alignment of Widgets
        b1.grid(row=x+1, column=0, sticky="ns", columnspan=1, pady=5)
        b2.grid(row=x+2, column=0, sticky="ns", columnspan=1, pady=5)
        b3.grid(row=x+3, column=0, sticky="ns", columnspan=1, pady=5)

        bx.grid(row=x+4, column=1)
Ejemplo n.º 2
0
    def __init__(self, parent, controller):
        # Tkinter Fame Setup
        tk.Frame.__init__(self, parent)
        self.columnconfigure(0, weight=1)
        self.parent = parent
        self.controller = controller

        # Get the current mode
        self.mode = [] if modes.getCurrentMode() is None else modes.getCurrentMode()

        if self.mode == []:
            # should not reach here
            tm.showerror(
                "Unexpected Error", "No current operating mode for pacemaker")

        # placeholders for labels and entries
        self.entries = []
        self.labels = []

        label = tk.Label(self, text='DCM', font=settings.LARGE_FONT)
        label.grid(row=0, column=0)

        # display all the mode paramters with entry widgets
        x = 1
        for key in self.mode.params:
            text = tk.StringVar(self, value=self.mode.params[key])
            dcm_data_label = tk.Label(
                self, text='{} :'.format(key), font=settings.NORM_FONT)
            dcm_value = tk.Entry(self, textvariable=text)
            dcm_data_label.grid(row=x, column=0, sticky="nsew")
            dcm_value.grid(row=x, column=1, sticky="nsew")

            # store the entries and their labels to rebuild param array
            self.entries.append(dcm_value)
            self.labels.append(dcm_data_label)
            x += 1

        b1 = ttk.Button(self, text="Save", command=lambda: self.save())

        b1.grid(row=x+1, column=2)
Ejemplo n.º 3
0
    def save(self):

        # recreate the param dict
        params = self.get_param_dict()

        # Save paramters and handle any errors the backend returns
        try:
            status = modes.saveParamValues(modes.getCurrentMode(), params)
            if status == []:
                tm.showinfo("Success", "Successfully changed mode paramters")
                c.setPacemakerMode(modes.getCurrentMode())
            elif type(status) == list and len(status) > 0:
                err_msg = "These paramters are invalid:"
                for i in status:
                    err_msg = err_msg + "\n{}".format(str(i))
                tm.showerror("Error", err_msg)
                return None
            elif status == 1:
                tm.showerror("Error", "The given mode is not valid!")
                return None
            elif status == 2:
                tm.showerror(
                    "Error", "The parameters provided are of wrong datatype")
                return None
            else:
                tm.showerror("Error", settings.cfError)
                return None
        except Exception as e:
            tm.showerror("Error", str(e) + "\n\n" + str(traceback.print_exc()))
            return None

        # Recreate the Monitor frame which was deleted
        F = pages.customDataFrame["Monitor"]
        frame = F(parent=self.parent, controller=self.controller)
        frame.grid(row=0, column=0, sticky="NSEW")
        frame.tkraise()
        self.destroy()
Ejemplo n.º 4
0
 def update_mode(self):
     c = com.Com(settings.COMPORT)
     update_mode = c.getPacemakerMode()
     if type(update_mode) == int and update_mode == 0:
         tm.showerror(
             "Error",
             "Unable to connect to pacemaker to get current mode. Please restart the DCM with the pacemaker connected"
         )
     elif update_mode.code == -1:
         tm.showerror(
             "Error",
             "Mode was not set due to an invalid call. Please restart the DCM"
         )
     else:
         modes.setCurrentMode(modes.allModes()[update_mode.code])
         modes.saveParamValues(modes.getCurrentMode(), update_mode.params)
Ejemplo n.º 5
0
    def set_mode(self, controller, mode):
        mode_selected = mode.get()

        # Ensure a valid choice is considered
        if mode_selected != "Choose":
            # Get the mode we want to select. setCurrentMode requires a Mode object
            for mode in modes.allModes():
                if mode.name == mode_selected:
                    # Calls the backend function setCurrentMode()
                    modes.setCurrentMode(mode)

                    c.setPacemakerMode(modes.getCurrentMode())

                    # dynamic loading of the next frame
                    # This is because the data does not exist until after
                    F = pages.customDataFrame["Monitor"]
                    frame = F(parent=self.parent, controller=self.controller)
                    frame.grid(row=0, column=0, sticky="NSEW")
                    frame.tkraise()
                    break