class MenuView(Frame): def __init__(self, callback, parent=None): self.config = ConfigValues() Frame.__init__(self, parent, bg=self.config.values['colors']['darkBlue']) self.callback = callback Internationalization() def update(self, settings): self.exit_btn.checkTimeout() self.exit_btn.setEnabled(not settings.start) if settings.start: self.exit_btn.setText( _("Shutdown Disabled\n(Stop Ventilator First)")) else: self.exit_btn.setText(_("Shutdown")) def fill_frame(self, settings): close_btn = FlatButton(self, self.callback, MenuViewActions.NONE, self.config.values['colors']['lightBlue'], fontSize=20) close_btn.setText(_("Close")) close_btn.grid(row=0, column=3, sticky=N + S + E + W, padx=10, pady=20) self.exit_btn = FlatButton(self, self.callback, MenuViewActions.SHUTDOWN, self.config.values['colors']['lightBlue'], fontSize=20, timeout=4) self.exit_btn.grid(row=2, column=2, columnspan=2, sticky=N + S + E + W, padx=(40, 0), pady=40) if settings.start: self.exit_btn.setEnabled(False) self.rowconfigure(0, weight=1) self.rowconfigure(1, weight=1) self.rowconfigure(2, weight=2) self.rowconfigure(3, weight=1) self.rowconfigure(4, weight=1) for i in range(0, 4): self.columnconfigure(i, weight=1)
def fill_frame(self, settings): close_btn = FlatButton(self, self.callback, MenuViewActions.NONE, self.config.values['colors']['lightBlue'], fontSize=20) close_btn.setText(_("Close")) close_btn.grid(row=0, column=3, sticky=N + S + E + W, padx=10, pady=20) self.exit_btn = FlatButton(self, self.callback, MenuViewActions.SHUTDOWN, self.config.values['colors']['lightBlue'], fontSize=20, timeout=4) self.exit_btn.grid(row=2, column=2, columnspan=2, sticky=N + S + E + W, padx=(40, 0), pady=40) if settings.start: self.exit_btn.setEnabled(False) self.rowconfigure(0, weight=1) self.rowconfigure(1, weight=1) self.rowconfigure(2, weight=2) self.rowconfigure(3, weight=1) self.rowconfigure(4, weight=1) for i in range(0, 4): self.columnconfigure(i, weight=1)
class MainView(Frame): def __init__(self, width, height, settings, sensordata, callback, parent=None): self.config = ConfigValues() Frame.__init__(self, parent, width=width, height=height, bg=self.config.values['colors']['darkBlue']) self.settings = settings self.sensordata = sensordata self.callback = callback self.pressureQueue = deque(maxlen=self.config.values['defaultSettings']['pressureQueueLen']) self.alarms = AlarmController() Internationalization() self.fill_frame() def getBtnColor(self, low_alarm, high_alarm): if self.alarms.hasActiveAlarm(low_alarm) or self.alarms.hasActiveAlarm(high_alarm): return self.config.values['colors']['alarmColor'] return self.config.values['colors']['lightBlue'] def getCanvasColor(self, *args): if any(self.alarms.hasActiveAlarm(arg) is True for arg in args): return self.config.values['colors']['alarmColor'] return self.config.values['colors']['darkBlue'] def update(self, settings, sensordata): self.settings = settings self.sensordata = sensordata if not self.oxy_btn: return start_stop_text = "" if self.settings.start: self.switch_btn.timeout = 4 self.switch_btn.checkTimeout() start_stop_text = _("STOP") else: self.switch_btn.timeout = 0 start_stop_text = _("START") if self.alarms.present(): self.alarm_overview_btn.setBackground(self.config.values['colors']['alarmColor']) else: self.alarm_overview_btn.setBackground() self.pressureQueue.append(self.sensordata.pressure) self.switch_btn.setText(start_stop_text) self.peep_btn.setText(_("PEEP") + '\n' + str(self.settings.peep) + " " + _("[cm H2O]")) self.peep_btn.setBackground(self.getBtnColor(AlarmType.PEEP_TOO_LOW, AlarmType.PEEP_TOO_HIGH)) self.freq_btn.setText(_("Frequency") + '\n' + str(self.settings.freq) + " " + _("[1/min]")) self.pres_btn.setText(_("PC above PEEP") + '\n' + str(self.settings.pressure) + " " + _("[cm H2O]")) self.pres_btn.setBackground(self.getBtnColor(AlarmType.PRESSURE_TOO_LOW, AlarmType.PRESSURE_TOO_HIGH)) self.oxy_btn.setText(_("Oxygen (O2)") + '\n' + str(self.settings.oxygen) + " [%]") self.oxy_btn.setBackground(self.getBtnColor(AlarmType.OXYGEN_TOO_LOW, AlarmType.OXYGEN_TOO_HIGH)) self.inspHold_btn.setEnabled(settings.start) if sensordata.inspiratory_hold_result: self.inspHold_btn.setText(_("Inspiration Hold") + "\n{0:.2g} ".format(sensordata.inspiratory_hold_result) + _("[cm H2O]")) self.expHold_btn.setEnabled(settings.start) if sensordata.expiratory_hold_result: self.expHold_btn.setText(_("Expiration Hold") + "\n{0:.2g} ".format(sensordata.expiratory_hold_result) + _("[cm H2O]")) ppeak = max(self.pressureQueue) pmean = sum(self.pressureQueue)/len(self.pressureQueue) self.ppeak_label.setText(_("Ppeak") + "\n" + _("[cm H2O]"), [ppeak, pmean]) ppeep = min(self.pressureQueue) self.pmean_label.setText(_("Ppeep") + "\n" + _("[cm H2O]"), ppeep) self.oxy_label.setText(_("O2") + " [%]", self.sensordata.oxygen) self.tvinexp_label.setText(_("TV in/exp") + " \n" + _("[mL]"), str(self.sensordata.tidal_volume_inhale) + "/" + str(self.sensordata.tidal_volume_exhale)) self.tv_label1.setText(_("min.vol."), str(round(self.sensordata.minute_volume)) + " " + _("[L]")) batt_status = self.sensordata.ups_status if batt_status == (UPSStatus.UNKNOWN or UPSStatus.FAIL): self.batt_label.setTitle(_("Pwr. Err.")) else: self.batt_label.setTitle("") self.batt_label.setBackgroundColor(self.getCanvasColor(AlarmType.RUN_ON_BATTERY, AlarmType.LOW_BATTERY)) self.flowgraph.update(-1 * self.sensordata.flow) self.pressuregraph.update(self.sensordata.pressure) def getFrame(self): return self.frame def drawGraphs(self): # Parameters pressure_x_len = 150 # Number of points to display pressure_y_range = [0, 40] # Range of possible Y values to display self.pressuregraph = GraphView(_("Pressure"), _("[cm H2O]"), self.sensordata.pressure, pressure_y_range, pressure_x_len, self.config.values['colors']['pressurePlot'], self) self.pressuregraph.getPlot().grid(row=1, column=2, rowspan=4, columnspan=2, sticky=N + S + E + W) # Parameters flow_x_len = 150 # Number of points to display flow_y_range = [-60, 0] # Range of possible Y values to display self.flowgraph = GraphView(_("Flow"), _("[L / min]"), self.sensordata.flow, flow_y_range, flow_x_len, self.config.values['colors']['flowPlot'], self) self.flowgraph.getPlot().grid(row=5, column=2, rowspan=4, columnspan=2, sticky=N + S + E + W) def fill_frame(self): # Buttons on the top and left self.air_btn = FlatButton(self, self.callback, MainViewActions.MENU, self.config.values['colors']['lightBlue']) self.air_btn.setText(_("Menu")) self.air_btn.grid(row=0, column=0, sticky=N + S + E + W, padx=(0,2), pady=(2,0)) self.alarm_btn = FlatButton(self, self.callback, MainViewActions.ALARM, self.config.values['colors']['lightBlue']) self.alarm_btn.setText(_("Alarm")) self.alarm_btn.grid(row=0, column=1, sticky=N + S + E + W, padx=(0,2), pady=(2,0)) self.alarm_overview_btn = FlatButton(self, self.callback, MainViewActions.VIEW_ALARMS, self.config.values['colors']['lightBlue']) self.alarm_overview_btn.setText(_("Alarm Overview")) self.alarm_overview_btn.grid(row=0, column=2, sticky=N + S + E + W, padx=(0,2), pady=(2,0)) self.patient_btn = FlatButton(self, self.callback, MainViewActions.PATIENT, self.config.values['colors']['lightBlue']) # self.patient_btn.setText(_("Patient")) self.patient_btn.setText("") self.patient_btn.grid(row=0, column=3, sticky=N + S + E + W, padx=(0,2), pady=(2, 0)) self.switch_btn = FlatButton(self, self.callback, MainViewActions.STARTSTOP, self.config.values['colors']['lightBlue'], timeout=4) self.switch_btn.grid(row=0, column=4, sticky=N + S + E + W, padx=(0,2), pady=(2, 0)) self.peep_btn = FlatButton(self, self.callback, MainViewActions.PEEP, self.config.values['colors']['lightBlue']) self.peep_btn.grid(row=1, column=0, columnspan=2, rowspan=3, sticky=N + S + E + W, padx=(0,2), pady=(2,0)) self.freq_btn = FlatButton(self, self.callback, MainViewActions.FREQ, self.config.values['colors']['lightBlue']) self.freq_btn.grid(row=4, column=0,columnspan=2, rowspan=3, sticky=N + S + E + W, padx=(0,2), pady=(2,0)) self.pres_btn = FlatButton(self, self.callback, MainViewActions.PRESSURE, self.config.values['colors']['lightBlue']) self.pres_btn.grid(row=7, column=0, columnspan=2, rowspan=3, sticky=N + S + E + W, padx=(0,2), pady=(2,0)) self.oxy_btn = FlatButton(self, self.callback, MainViewActions.OXYGEN, self.config.values['colors']['lightBlue']) self.oxy_btn.grid(row=10, column=0, columnspan=2, rowspan=3, sticky=N + S + E + W, padx=(0,2), pady=(2,0)) # Labels on the right side next to the graphs self.ppeak_label = CurrentValueCanvas(self, _("Ppeak"), 100, self.config.values['colors']['pressurePlot']) self.ppeak_label.grid(row=1, column=4, rowspan=2, sticky=N + S + E + W) self.pmean_label = CurrentValueCanvas(self, _("Pmean"), 50, self.config.values['colors']['pressurePlot']) self.pmean_label.grid(row=3, column=4, rowspan=2, sticky=N + S + E + W) self.oxy_label = CurrentValueCanvas(self, _("O2"), self.sensordata.oxygen, 'white') self.oxy_label.grid(row=5, column=4, rowspan=2, sticky=N + S + E + W) self.tvinexp_label = CurrentValueCanvas(self, _("TV in/exp"), 0, self.config.values['colors']['green']) self.tvinexp_label.grid(row=7, column=4, rowspan=2, sticky=N + S + E + W) self.tv_label1 = CurrentValueCanvas(self, _("min.vol"), [self.sensordata.tidal_volume_inhale, self.sensordata.tidal_volume_exhale], self.config.values['colors']['green']) self.tv_label1.grid(row=9, column=4, rowspan=2, sticky=N + S + E + W) self.batt_label = CurrentValueCanvas(self, _("Batt. [%]"), self.sensordata.battery_percentage, 'white') self.batt_label.grid(row=11, column=4, rowspan=2, sticky=N + S + E + W) # Buttons under graphs self.inspHold_btn = FlatButton(self, self.callback, MainViewActions.INSP_HOLD_STOP, self.config.values['colors']['lightBlue']) self.inspHold_btn.setCustomPressArgument(MainViewActions.INSP_HOLD_START) self.inspHold_btn.setText(_("Inspiration Hold\n(Hold to measure)")) self.inspHold_btn.grid(row=10, column=2, columnspan=1, rowspan=3, sticky=N + S + E + W, padx=(0,2), pady=(2,0)) self.expHold_btn = FlatButton(self, self.callback, MainViewActions.EXP_HOLD_STOP, self.config.values['colors']['lightBlue']) self.expHold_btn.setCustomPressArgument(MainViewActions.EXP_HOLD_START) self.expHold_btn.setText(_("Expiration Hold\n(Hold to measure)")) self.expHold_btn.grid(row=10, column=3, columnspan=1, rowspan=3, sticky=N + S + E + W, padx=(0,2), pady=(2,0)) self.rowconfigure(0, weight=5) for i in range(1, 10): self.rowconfigure(i, weight=1) for i in range(9, 13): self.rowconfigure(i, weight=3) self.columnconfigure(0, weight=2) self.columnconfigure(1, weight=2) self.columnconfigure(2, weight=5) self.columnconfigure(3, weight=5) self.columnconfigure(4, weight=2) self.drawGraphs()
class ChangeDoubleSettingView(Frame): Internationalization() # bound (Bool): Are the two variables linked? (Can variable 2 be less than variable 1) def __init__(self, stype, min_current, min_min, min_max, step1, max_current, max_min, max_max, step2, description, callback, label1=_("Minimum\nValue"), label2=_("Maximum\nValue"), bound=True, parent=None): self.config = ConfigValues() Frame.__init__(self, parent, bg=self.config.values['colors']['darkBlue']) self.type = stype self.bound = bound self.step1 = step1 self.label1 = label1 self.min_current = min_current self.min_min = min_min self.min_max = min_max self.label2 = label2 self.step2 = step2 self.max_current = max_current self.max_min = max_min self.max_max = max_max self.description = description self.callback = callback self.fill_frame() def confirmSetting(self, stype): self.callback(stype, self.min_current, self.max_current) def valueChange(self, action): if action == ChangeAlarmViewActions.MINMINUS: if self.min_current - self.step1 >= self.min_min: if self.min_current % self.step1 != 0: self.min_current = self.min_current - (self.min_current % self.step1) else: self.min_current = self.min_current - self.step1 else: self.min_current = self.min_min elif action == ChangeAlarmViewActions.MINPLUS: if (not self.bound or self.max_current - self.min_current > self.step1): if self.min_current + self.step1 <= self.min_max: self.min_current = self.min_current + self.step1 - ( self.min_current % self.step1) elif action == ChangeAlarmViewActions.MAXMINUS and self.max_current - self.step2 >= self.max_min and ( not self.bound or self.max_current - self.min_current > self.step2): if self.max_current % self.step2 != 0: self.max_current = self.max_current - (self.max_current % self.step2) else: self.max_current = self.max_current - self.step2 elif action == ChangeAlarmViewActions.MAXPLUS: if self.max_current + self.step2 <= self.max_max: self.max_current = self.max_current + self.step2 - ( self.max_current % self.step2) else: self.max_current = self.max_max self.min_value_btn.setText(self.min_current) self.max_value_btn.setText(self.max_current) def fill_frame(self): pad = 1 desc_btn = FlatButton(self, None, None, self.config.values['colors']['darkBlue'], fontSize=30) desc_btn.setText(self.description) desc_btn.grid(row=0, column=1, columnspan=2, sticky=N + S + E + W) close_btn = FlatButton(self, self.confirmSetting, SettingType.NONE, self.config.values['colors']['lightBlue'], fontSize=20) close_btn.setText(_("Close")) close_btn.grid(row=0, column=3, sticky=N + S + E + W, padx=10, pady=10) min_desc_btn = FlatButton(self, None, None, self.config.values['colors']['darkBlue'], fontSize=20) min_desc_btn.setText(self.label1) min_desc_btn.grid(row=1, column=0, sticky=N + S + E + W) minminus_btn = FlatButton(self, self.valueChange, ChangeAlarmViewActions.MINMINUS, self.config.values['colors']['lightBlue'], fontSize=30) minminus_btn.setText("-") minminus_btn.grid(row=1, column=1, sticky=N + S + E + W, padx=pad, pady=pad) minplus_btn = FlatButton(self, self.valueChange, ChangeAlarmViewActions.MINPLUS, self.config.values['colors']['lightBlue'], fontSize=30) minplus_btn.setText("+") minplus_btn.grid(row=1, column=2, sticky=N + S + E + W, padx=pad, pady=pad) self.min_value_btn = FlatButton( self, None, None, self.config.values['colors']['darkBlue'], fontSize=30) self.min_value_btn.setText(self.min_current) self.min_value_btn.grid(row=1, column=3, sticky=N + S + E + W) max_desc_btn = FlatButton(self, None, None, self.config.values['colors']['darkBlue'], fontSize=20) max_desc_btn.setText(self.label2) max_desc_btn.grid(row=2, column=0, sticky=N + S + E + W) maxminus_btn = FlatButton(self, self.valueChange, ChangeAlarmViewActions.MAXMINUS, self.config.values['colors']['lightBlue'], fontSize=30) maxminus_btn.setText("-") maxminus_btn.grid(row=2, column=1, sticky=N + S + E + W, padx=pad, pady=pad) maxplus_btn = FlatButton(self, self.valueChange, ChangeAlarmViewActions.MAXPLUS, self.config.values['colors']['lightBlue'], fontSize=30) maxplus_btn.setText("+") maxplus_btn.grid(row=2, column=2, sticky=N + S + E + W, padx=pad, pady=pad) self.max_value_btn = FlatButton( self, None, None, self.config.values['colors']['darkBlue'], fontSize=30) self.max_value_btn.setText(self.max_current) self.max_value_btn.grid(row=2, column=3, sticky=N + S + E + W) confirm_btn = FlatButton(self, self.confirmSetting, self.type, self.config.values['colors']['green'], fontSize=40) confirm_btn.setText(_("Confirm"), "white") confirm_btn.grid(row=3, column=0, columnspan=4, sticky=N + S + E + W, padx=20, pady=(60, 20)) for i in range(0, 4): self.columnconfigure(i, weight=1) self.rowconfigure(0, weight=1) for i in range(1, 4): self.rowconfigure(i, weight=2)
def fill_frame(self): # Buttons on the top and left self.air_btn = FlatButton(self, self.callback, MainViewActions.MENU, self.config.values['colors']['lightBlue']) self.air_btn.setText(_("Menu")) self.air_btn.grid(row=0, column=0, sticky=N + S + E + W, padx=(0,2), pady=(2,0)) self.alarm_btn = FlatButton(self, self.callback, MainViewActions.ALARM, self.config.values['colors']['lightBlue']) self.alarm_btn.setText(_("Alarm")) self.alarm_btn.grid(row=0, column=1, sticky=N + S + E + W, padx=(0,2), pady=(2,0)) self.alarm_overview_btn = FlatButton(self, self.callback, MainViewActions.VIEW_ALARMS, self.config.values['colors']['lightBlue']) self.alarm_overview_btn.setText(_("Alarm Overview")) self.alarm_overview_btn.grid(row=0, column=2, sticky=N + S + E + W, padx=(0,2), pady=(2,0)) self.patient_btn = FlatButton(self, self.callback, MainViewActions.PATIENT, self.config.values['colors']['lightBlue']) # self.patient_btn.setText(_("Patient")) self.patient_btn.setText("") self.patient_btn.grid(row=0, column=3, sticky=N + S + E + W, padx=(0,2), pady=(2, 0)) self.switch_btn = FlatButton(self, self.callback, MainViewActions.STARTSTOP, self.config.values['colors']['lightBlue'], timeout=4) self.switch_btn.grid(row=0, column=4, sticky=N + S + E + W, padx=(0,2), pady=(2, 0)) self.peep_btn = FlatButton(self, self.callback, MainViewActions.PEEP, self.config.values['colors']['lightBlue']) self.peep_btn.grid(row=1, column=0, columnspan=2, rowspan=3, sticky=N + S + E + W, padx=(0,2), pady=(2,0)) self.freq_btn = FlatButton(self, self.callback, MainViewActions.FREQ, self.config.values['colors']['lightBlue']) self.freq_btn.grid(row=4, column=0,columnspan=2, rowspan=3, sticky=N + S + E + W, padx=(0,2), pady=(2,0)) self.pres_btn = FlatButton(self, self.callback, MainViewActions.PRESSURE, self.config.values['colors']['lightBlue']) self.pres_btn.grid(row=7, column=0, columnspan=2, rowspan=3, sticky=N + S + E + W, padx=(0,2), pady=(2,0)) self.oxy_btn = FlatButton(self, self.callback, MainViewActions.OXYGEN, self.config.values['colors']['lightBlue']) self.oxy_btn.grid(row=10, column=0, columnspan=2, rowspan=3, sticky=N + S + E + W, padx=(0,2), pady=(2,0)) # Labels on the right side next to the graphs self.ppeak_label = CurrentValueCanvas(self, _("Ppeak"), 100, self.config.values['colors']['pressurePlot']) self.ppeak_label.grid(row=1, column=4, rowspan=2, sticky=N + S + E + W) self.pmean_label = CurrentValueCanvas(self, _("Pmean"), 50, self.config.values['colors']['pressurePlot']) self.pmean_label.grid(row=3, column=4, rowspan=2, sticky=N + S + E + W) self.oxy_label = CurrentValueCanvas(self, _("O2"), self.sensordata.oxygen, 'white') self.oxy_label.grid(row=5, column=4, rowspan=2, sticky=N + S + E + W) self.tvinexp_label = CurrentValueCanvas(self, _("TV in/exp"), 0, self.config.values['colors']['green']) self.tvinexp_label.grid(row=7, column=4, rowspan=2, sticky=N + S + E + W) self.tv_label1 = CurrentValueCanvas(self, _("min.vol"), [self.sensordata.tidal_volume_inhale, self.sensordata.tidal_volume_exhale], self.config.values['colors']['green']) self.tv_label1.grid(row=9, column=4, rowspan=2, sticky=N + S + E + W) self.batt_label = CurrentValueCanvas(self, _("Batt. [%]"), self.sensordata.battery_percentage, 'white') self.batt_label.grid(row=11, column=4, rowspan=2, sticky=N + S + E + W) # Buttons under graphs self.inspHold_btn = FlatButton(self, self.callback, MainViewActions.INSP_HOLD_STOP, self.config.values['colors']['lightBlue']) self.inspHold_btn.setCustomPressArgument(MainViewActions.INSP_HOLD_START) self.inspHold_btn.setText(_("Inspiration Hold\n(Hold to measure)")) self.inspHold_btn.grid(row=10, column=2, columnspan=1, rowspan=3, sticky=N + S + E + W, padx=(0,2), pady=(2,0)) self.expHold_btn = FlatButton(self, self.callback, MainViewActions.EXP_HOLD_STOP, self.config.values['colors']['lightBlue']) self.expHold_btn.setCustomPressArgument(MainViewActions.EXP_HOLD_START) self.expHold_btn.setText(_("Expiration Hold\n(Hold to measure)")) self.expHold_btn.grid(row=10, column=3, columnspan=1, rowspan=3, sticky=N + S + E + W, padx=(0,2), pady=(2,0)) self.rowconfigure(0, weight=5) for i in range(1, 10): self.rowconfigure(i, weight=1) for i in range(9, 13): self.rowconfigure(i, weight=3) self.columnconfigure(0, weight=2) self.columnconfigure(1, weight=2) self.columnconfigure(2, weight=5) self.columnconfigure(3, weight=5) self.columnconfigure(4, weight=2) self.drawGraphs()
def drawPlusButtons(self): first_plus = FlatButton(self, self.changeTimeCallback, (0, 1), self.config.values['colors']['lightBlue'], fontSize=40) first_plus.setText("+") first_plus.grid(row=1, column=0, sticky=N+S+E+W, padx=10, pady=10) second_plus = FlatButton(self, self.changeTimeCallback, (1, 1), self.config.values['colors']['lightBlue'], fontSize=40) second_plus.setText("+") second_plus.grid(row=1, column=1, sticky=N+S+E+W, padx=10, pady=10) third_plus = FlatButton(self, self.changeTimeCallback, (2, 1), self.config.values['colors']['lightBlue'], fontSize=40) third_plus.setText("+") third_plus.grid(row=1, column=3, sticky=N+S+E+W, padx=10, pady=10) fourth_plus = FlatButton(self, self.changeTimeCallback, (3, 1), self.config.values['colors']['lightBlue'], fontSize=40) fourth_plus.setText("+") fourth_plus.grid(row=1, column=4, sticky=N+S+E+W, padx=10, pady=10)
def fill_frame(self): pad = 1 desc_btn = FlatButton(self, None, None, self.config.values['colors']['darkBlue'], fontSize=30) desc_btn.setText(self.description) desc_btn.grid(row=0, column=1, columnspan=2, sticky=N + S + E + W) close_btn = FlatButton(self, self.confirmSetting, SettingType.NONE, self.config.values['colors']['lightBlue'], fontSize=20) close_btn.setText(_("Close")) close_btn.grid(row=0, column=3, sticky=N + S + E + W, padx=10, pady=10) min_desc_btn = FlatButton(self, None, None, self.config.values['colors']['darkBlue'], fontSize=20) min_desc_btn.setText(self.label1) min_desc_btn.grid(row=1, column=0, sticky=N + S + E + W) minminus_btn = FlatButton(self, self.valueChange, ChangeAlarmViewActions.MINMINUS, self.config.values['colors']['lightBlue'], fontSize=30) minminus_btn.setText("-") minminus_btn.grid(row=1, column=1, sticky=N + S + E + W, padx=pad, pady=pad) minplus_btn = FlatButton(self, self.valueChange, ChangeAlarmViewActions.MINPLUS, self.config.values['colors']['lightBlue'], fontSize=30) minplus_btn.setText("+") minplus_btn.grid(row=1, column=2, sticky=N + S + E + W, padx=pad, pady=pad) self.min_value_btn = FlatButton( self, None, None, self.config.values['colors']['darkBlue'], fontSize=30) self.min_value_btn.setText(self.min_current) self.min_value_btn.grid(row=1, column=3, sticky=N + S + E + W) max_desc_btn = FlatButton(self, None, None, self.config.values['colors']['darkBlue'], fontSize=20) max_desc_btn.setText(self.label2) max_desc_btn.grid(row=2, column=0, sticky=N + S + E + W) maxminus_btn = FlatButton(self, self.valueChange, ChangeAlarmViewActions.MAXMINUS, self.config.values['colors']['lightBlue'], fontSize=30) maxminus_btn.setText("-") maxminus_btn.grid(row=2, column=1, sticky=N + S + E + W, padx=pad, pady=pad) maxplus_btn = FlatButton(self, self.valueChange, ChangeAlarmViewActions.MAXPLUS, self.config.values['colors']['lightBlue'], fontSize=30) maxplus_btn.setText("+") maxplus_btn.grid(row=2, column=2, sticky=N + S + E + W, padx=pad, pady=pad) self.max_value_btn = FlatButton( self, None, None, self.config.values['colors']['darkBlue'], fontSize=30) self.max_value_btn.setText(self.max_current) self.max_value_btn.grid(row=2, column=3, sticky=N + S + E + W) confirm_btn = FlatButton(self, self.confirmSetting, self.type, self.config.values['colors']['green'], fontSize=40) confirm_btn.setText(_("Confirm"), "white") confirm_btn.grid(row=3, column=0, columnspan=4, sticky=N + S + E + W, padx=20, pady=(60, 20)) for i in range(0, 4): self.columnconfigure(i, weight=1) self.rowconfigure(0, weight=1) for i in range(1, 4): self.rowconfigure(i, weight=2)
def fill_frame(self): label_btn = FlatButton(self, None, None, self.config.values['colors']['darkBlue'], fontSize=25) label_btn.setText(_("Set the Time")) label_btn.grid(row=0, column=0, columnspan=5, sticky=N+S+E+W, padx=10, pady=10) self.drawPlusButtons() self.drawTime() self.drawMinusButtons() confirm_btn = FlatButton(self, self.returnTimeCallback, SetTimeCallback.SET_TIME, self.config.values['colors']['green'], fontSize=40) confirm_btn.setText(_("Confirm"), "white") confirm_btn.grid(row=4, column=0, columnspan=5, sticky=N + S + E + W, padx=20, pady=(60, 20)) for i in range(0, 5): self.columnconfigure(i, weight=5) self.columnconfigure(2, weight=1) self.rowconfigure(0, weight=1) for i in range(1, 5): self.rowconfigure(i, weight=2)
class SetTimeView(Frame): # bound (Bool): Are the two variables linked? (Can variable 2 be less than variable 1) def __init__(self, callback, parent=None): self.config = ConfigValues() Frame.__init__(self, parent, bg=self.config.values['colors']['darkBlue']) self.callback = callback now = datetime.now() dt = now.strftime("%H%M") self.time = [int(dt[0]), int(dt[1]), int(dt[2]), int(dt[3])] Internationalization() self.fill_frame() def getTime(self): return str(self.time[0]) + str(self.time[1]) + ":" + str(self.time[2]) + str(self.time[3]) def returnTimeCallback(self, ttype): self.callback(ttype, self.getTime()) def makeValid(self, time, index, change): if index == 0: time[0] += change if time[0] == -1 or time[0] == 3: time[0] += (-1*change*3) if time[0] == 2 and time[1] > 3: time[1] = 3 if index == 1: time[1] += change if time[0] == 2 and time[1] == 4: time[1] = 0 elif time[1] == -1: if time[0] == 2: time[1] = 3 else: time[1] = 9 elif time[1] > 9: time[1] = 0 if index == 2: time[2] += change if time[2] in [-1, 6]: time[2] += (-1*change*6) if index == 3: time[3] += change if time[3] in [-1, 10]: time[3] += (-1*change*10) return time def update(self): self.first_digit.setText(self.time[0]) self.second_digit.setText(self.time[1]) self.third_digit.setText(self.time[2]) self.fourth_digit.setText(self.time[3]) def changeTimeCallback(self, arg): (index, change) = arg newtime = self.time[:] self.time = self.makeValid(newtime, index, change) self.update() def drawPlusButtons(self): first_plus = FlatButton(self, self.changeTimeCallback, (0, 1), self.config.values['colors']['lightBlue'], fontSize=40) first_plus.setText("+") first_plus.grid(row=1, column=0, sticky=N+S+E+W, padx=10, pady=10) second_plus = FlatButton(self, self.changeTimeCallback, (1, 1), self.config.values['colors']['lightBlue'], fontSize=40) second_plus.setText("+") second_plus.grid(row=1, column=1, sticky=N+S+E+W, padx=10, pady=10) third_plus = FlatButton(self, self.changeTimeCallback, (2, 1), self.config.values['colors']['lightBlue'], fontSize=40) third_plus.setText("+") third_plus.grid(row=1, column=3, sticky=N+S+E+W, padx=10, pady=10) fourth_plus = FlatButton(self, self.changeTimeCallback, (3, 1), self.config.values['colors']['lightBlue'], fontSize=40) fourth_plus.setText("+") fourth_plus.grid(row=1, column=4, sticky=N+S+E+W, padx=10, pady=10) def drawTime(self): self.first_digit = FlatButton(self, None, None, self.config.values['colors']['darkBlue'], fontSize=40) self.first_digit.grid(row=2, column=0, sticky=N+S+E+W, padx=10, pady=10) self.second_digit = FlatButton(self, None, None, self.config.values['colors']['darkBlue'], fontSize=40) self.second_digit.grid(row=2, column=1, sticky=N + S + E + W, padx=10, pady=10) dots = FlatButton(self, self.changeTimeCallback, (1, 1), self.config.values['colors']['darkBlue'], fontSize=40) dots.setText(":") dots.grid(row=2, column=2, sticky=N + S + E + W, padx=10, pady=10) self.third_digit = FlatButton(self, None, None, self.config.values['colors']['darkBlue'], fontSize=40) self.third_digit.grid(row=2, column=3, sticky=N + S + E + W, padx=10, pady=10) self.fourth_digit = FlatButton(self, None, None, self.config.values['colors']['darkBlue'], fontSize=40) self.fourth_digit.grid(row=2, column=4, sticky=N + S + E + W, padx=10, pady=10) self.update() def drawMinusButtons(self): first_miuns = FlatButton(self, self.changeTimeCallback, (0, -1), self.config.values['colors']['lightBlue'], fontSize=40) first_miuns.setText("-") first_miuns.grid(row=3, column=0, sticky=N+S+E+W, padx=10, pady=10) second_miuns = FlatButton(self, self.changeTimeCallback, (1, -1), self.config.values['colors']['lightBlue'], fontSize=40) second_miuns.setText("-") second_miuns.grid(row=3, column=1, sticky=N+S+E+W, padx=10, pady=10) third_miuns = FlatButton(self, self.changeTimeCallback, (2, -1), self.config.values['colors']['lightBlue'], fontSize=40) third_miuns.setText("-") third_miuns.grid(row=3, column=3, sticky=N+S+E+W, padx=10, pady=10) fourth_miuns = FlatButton(self, self.changeTimeCallback, (3, -1), self.config.values['colors']['lightBlue'], fontSize=40) fourth_miuns.setText("-") fourth_miuns.grid(row=3, column=4, sticky=N+S+E+W, padx=10, pady=10) def fill_frame(self): label_btn = FlatButton(self, None, None, self.config.values['colors']['darkBlue'], fontSize=25) label_btn.setText(_("Set the Time")) label_btn.grid(row=0, column=0, columnspan=5, sticky=N+S+E+W, padx=10, pady=10) self.drawPlusButtons() self.drawTime() self.drawMinusButtons() confirm_btn = FlatButton(self, self.returnTimeCallback, SetTimeCallback.SET_TIME, self.config.values['colors']['green'], fontSize=40) confirm_btn.setText(_("Confirm"), "white") confirm_btn.grid(row=4, column=0, columnspan=5, sticky=N + S + E + W, padx=20, pady=(60, 20)) for i in range(0, 5): self.columnconfigure(i, weight=5) self.columnconfigure(2, weight=1) self.rowconfigure(0, weight=1) for i in range(1, 5): self.rowconfigure(i, weight=2)
def drawTime(self): self.first_digit = FlatButton(self, None, None, self.config.values['colors']['darkBlue'], fontSize=40) self.first_digit.grid(row=2, column=0, sticky=N+S+E+W, padx=10, pady=10) self.second_digit = FlatButton(self, None, None, self.config.values['colors']['darkBlue'], fontSize=40) self.second_digit.grid(row=2, column=1, sticky=N + S + E + W, padx=10, pady=10) dots = FlatButton(self, self.changeTimeCallback, (1, 1), self.config.values['colors']['darkBlue'], fontSize=40) dots.setText(":") dots.grid(row=2, column=2, sticky=N + S + E + W, padx=10, pady=10) self.third_digit = FlatButton(self, None, None, self.config.values['colors']['darkBlue'], fontSize=40) self.third_digit.grid(row=2, column=3, sticky=N + S + E + W, padx=10, pady=10) self.fourth_digit = FlatButton(self, None, None, self.config.values['colors']['darkBlue'], fontSize=40) self.fourth_digit.grid(row=2, column=4, sticky=N + S + E + W, padx=10, pady=10) self.update()
def fill_frame(self): pad = 1 close_btn = FlatButton(self, self.confirmSetting, SettingType.NONE, self.config.values['colors']['lightBlue'], fontSize=20) close_btn.setText(_("Close")) close_btn.grid(row=0, column=3, sticky=N + S + E + W, padx=10, pady=10) desc_btn = FlatButton(self, None, None, self.config.values['colors']['darkBlue'], fontSize=20) desc_btn.setText(self.description) desc_btn.grid(row=1, column=0, sticky=N + S + E + W) minus_btn = FlatButton(self, self.valueChange, ButtonAction.MINUS, self.config.values['colors']['lightBlue'], fontSize=30) minus_btn.setText("-") minus_btn.grid(row=1, column=1, sticky=N + S + E + W, padx=pad, pady=80) plus_btn = FlatButton(self, self.valueChange, ButtonAction.PLUS, self.config.values['colors']['lightBlue'], fontSize=30) plus_btn.setText("+") plus_btn.grid(row=1, column=2, sticky=N + S + E + W, padx=pad, pady=80) self.value_btn = FlatButton(self, None, None, self.config.values['colors']['darkBlue'], fontSize=30) self.value_btn.setText(self.current) self.value_btn.grid(row=1, column=3, sticky=N + S + E + W) confirm_btn = FlatButton(self, self.confirmSetting, self.type, self.config.values['colors']['green'], fontSize=40) confirm_btn.setText(_("Confirm"), "white") confirm_btn.grid(row=2, column=0, columnspan=4, sticky=N + S + E + W, padx=20, pady=(20, 20)) self.columnconfigure(0, weight=2) for i in range(1, 3): self.columnconfigure(i, weight=1) self.columnconfigure(3, weight=2) self.rowconfigure(0, weight=1) self.rowconfigure(1, weight=3) self.rowconfigure(2, weight=2)
class ChangeSingleSettingView(Frame): def __init__(self, stype, current, min, max, step, description, callback, parent=None): self.config = ConfigValues() Frame.__init__(self, parent, bg=self.config.values['colors']['darkBlue']) self.type = stype self.current = current self.min = min self.max = max self.step = step self.description = description self.callback = callback Internationalization() self.fill_frame() def confirmSetting(self, stype): self.callback(stype, self.current) def valueChange(self, action): if action == ButtonAction.MINUS: if self.current - self.step >= self.min: if self.current % self.step != 0: self.current = self.current - (self.current % self.step) else: self.current = self.current - self.step else: self.current = self.min elif action == ButtonAction.PLUS: if self.current + self.step <= self.max: self.current = self.current + self.step - (self.current % self.step) else: self.current = self.max self.value_btn.setText(self.current) def fill_frame(self): pad = 1 close_btn = FlatButton(self, self.confirmSetting, SettingType.NONE, self.config.values['colors']['lightBlue'], fontSize=20) close_btn.setText(_("Close")) close_btn.grid(row=0, column=3, sticky=N + S + E + W, padx=10, pady=10) desc_btn = FlatButton(self, None, None, self.config.values['colors']['darkBlue'], fontSize=20) desc_btn.setText(self.description) desc_btn.grid(row=1, column=0, sticky=N + S + E + W) minus_btn = FlatButton(self, self.valueChange, ButtonAction.MINUS, self.config.values['colors']['lightBlue'], fontSize=30) minus_btn.setText("-") minus_btn.grid(row=1, column=1, sticky=N + S + E + W, padx=pad, pady=80) plus_btn = FlatButton(self, self.valueChange, ButtonAction.PLUS, self.config.values['colors']['lightBlue'], fontSize=30) plus_btn.setText("+") plus_btn.grid(row=1, column=2, sticky=N + S + E + W, padx=pad, pady=80) self.value_btn = FlatButton(self, None, None, self.config.values['colors']['darkBlue'], fontSize=30) self.value_btn.setText(self.current) self.value_btn.grid(row=1, column=3, sticky=N + S + E + W) confirm_btn = FlatButton(self, self.confirmSetting, self.type, self.config.values['colors']['green'], fontSize=40) confirm_btn.setText(_("Confirm"), "white") confirm_btn.grid(row=2, column=0, columnspan=4, sticky=N + S + E + W, padx=20, pady=(20, 20)) self.columnconfigure(0, weight=2) for i in range(1, 3): self.columnconfigure(i, weight=1) self.columnconfigure(3, weight=2) self.rowconfigure(0, weight=1) self.rowconfigure(1, weight=3) self.rowconfigure(2, weight=2)
def fill_frame(self): close_btn = FlatButton(self, self.callback, None, self.config.values['colors']['lightBlue'], fontSize=20) close_btn.setText(_("Close")) close_btn.grid(row=0, column=3, sticky=N + S + E + W, padx=10, pady=10) peep_btn = FlatButton(self, self.callback, SettingType.PEEP, self.config.values['colors']['lightBlue'], fontSize=20) peep_btn.setText( _("PEEP") + "\n" + str(self.settings.min_peep) + "-" + str(self.settings.max_peep)) peep_btn.grid(row=1, column=0, sticky=N + S + E + W, padx=(40, 0), pady=80) press_btn = FlatButton(self, self.callback, SettingType.PRESSURE, self.config.values['colors']['lightBlue'], fontSize=20) press_btn.setText( _("Pressure") + "\n" + str(self.settings.min_pressure) + "-" + str(self.settings.max_pressure)) press_btn.grid(row=1, column=1, sticky=N + S + E + W, padx=(2, 0), pady=80) tidal_btn = FlatButton(self, self.callback, SettingType.TIDAL, self.config.values['colors']['lightBlue'], fontSize=20) tidal_btn.setText( _("Tidal Volume") + "\n" + str(self.settings.min_tv) + "-" + str(self.settings.max_tv)) tidal_btn.grid(row=1, column=2, sticky=N + S + E + W, padx=(2, 0), pady=80) oxy_btn = FlatButton(self, self.callback, SettingType.OXYGEN, self.config.values['colors']['lightBlue'], fontSize=20) oxy_btn.setText( _("Oxygen") + "\n" + str(self.settings.min_fio2) + "-" + str(self.settings.max_fio2)) oxy_btn.grid(row=1, column=3, sticky=N + S + E + W, padx=(2, 40), pady=80) self.rowconfigure(0, weight=1) self.rowconfigure(1, weight=3) self.rowconfigure(2, weight=1) for i in range(0, 4): self.columnconfigure(i, weight=1)
def fill_frame(self): for btn in self.alarm_btns: btn.destroy() self.alarm_btns.clear() clear_btn = FlatButton(self, self.callback, AlarmType.CLEAR, self.config.values['colors']['lightBlue'], fontSize=15) clear_btn.setText(_("Clear\nInactive Alarms")) clear_btn.grid(row=0, column=0, sticky=N + S + E + W, padx=10, pady=10) close_btn = FlatButton(self, self.callback, AlarmType.NONE, self.config.values['colors']['lightBlue'], fontSize=20) close_btn.setText(_("Close")) close_btn.grid(row=0, column=3, sticky=N + S + E + W, padx=10, pady=10) for i in range(0, len(self.alarms.alarms)): color = self.config.values['colors']['lightBlue'] if self.alarms.alarms[i].active: color = self.config.values['colors']['alarmColor'] if self.alarms.alarms[i].type == AlarmType.RUN_ON_BATTERY: self.alarm_btns.append( FlatButton(self, self.callback, self.alarms.alarms[i].type, color, fontSize=20, pressable=False)) else: self.alarm_btns.append( FlatButton(self, self.callback, self.alarms.alarms[i].type, color, fontSize=20)) self.alarm_btns[i].setText(self.alarms.alarms[i]) self.alarm_btns[i].grid(row=i + 1, column=0, columnspan=4, sticky=N + S + E + W, padx=10, pady=10) for i in range(0, len(self.alarms.alarms) + 1): self.rowconfigure(i, weight=1) for i in range(0, 4): self.columnconfigure(i, weight=1)