def __init__(self, observer: Observer, name: str, foreground_color="#ffffff", parent=None, item: TimerListItem=None): super().__init__(observer, name) self.parent = parent self.item = item self.observer = observer self.foreground_color = foreground_color self.setStyleSheet("QLabel { color : " + self.foreground_color + "; font: 30pt;}") self.hbox_layout = QHBoxLayout() self.timer_name = QLabel(self.item.get_name()) self.timer_value = QLabel(self.item.get_start_value_as_str()) self.start_button_state = False # Is active self.check_timer = QTimer(self) self.check_timer.setInterval(100) # .1 seconds self.check_timer.timeout.connect(lambda: self.update_count_down()) self.count_down_timer = QTimer(self) self.count_down_timer.setInterval(item.get_start_value_as_int()) self.count_down_timer.timeout.connect(lambda: self.count_down_end()) self.gui_button_builder = GuiButtonBuilder() self.gui_button_builder.set_color(foreground_color) self.gui_button_builder.set_size(30, 60) self.delete_button = self.gui_button_builder.create_button("Delete", Gui_Element.BUTTON_FULL_CIRCLE_TEXT) self.delete_button.clicked.connect(lambda: self.remove_item()) self.start_pause_button = self.gui_button_builder.create_button("Start", Gui_Element.BUTTON_FULL_CIRCLE_TEXT) self.start_pause_button.clicked.connect(lambda: self.start_button_pressed()) self.hbox_layout.addWidget(self.timer_name) self.hbox_layout.addWidget(self.timer_value) self.hbox_layout.addWidget(self.start_pause_button) self.hbox_layout.addWidget(self.delete_button) self.setLayout(self.hbox_layout)
class TimerOverview(Base): def __init__(self, observer: Observer, name: str, parent, foreground_color="#ffffff", font_name=""): super().__init__(observer, name) self.parent = parent self.observer = observer self.foreground_color = foreground_color self.background_color = "#050505" self.gui_button_builder = GuiButtonBuilder() self.timer_name = QLabel("Name:") self.timer_name_value = QLabel("Timer ") self.main_layout = QGridLayout() self.timer_list = QListWidget() self.timer_list.setStyleSheet( "QListWidget{background:" + self.background_color + "; border: 0px solid " + self.foreground_color + ";}") self.gui_button_builder.set_color(foreground_color) self.gui_button_builder.set_size(50, 100) self.button_add_timer = self.gui_button_builder.create_button("Create", Gui_Element.BUTTON_FULL_CIRCLE_TEXT) self.button_add_timer.clicked.connect(lambda: self.parent.switch_central_widget()) self.main_layout.addWidget(self.timer_list, 0, 0, 3, 4) self.main_layout.addWidget(self.button_add_timer, 4, 5) self.setLayout(self.main_layout) def add_timer(self, timer_config: dict): timer_item = TimerListItem(self.timer_list, timer_config) timer_item.setSizeHint(QSize(100, 50)) timer_widget_item = TimerListWidget(self.observer, "", self.foreground_color, self.timer_list, timer_item) self.timer_list.addItem(timer_item) self.timer_list.setItemWidget(timer_item, timer_widget_item) def delete_timer(self, item: TimerListItem): self.timer_list.removeItemWidget(item)
class Alarm(Base): def __init__(self, observer: Observer, name, foreground_color="#ffffff", parent=None): super().__init__(name, observer) self.parent = parent self.name = name self.main_layout = QGridLayout() self.font = QFont("LCARSGTJ3", 80, QFont.Bold) self.subscreen_name = QLabel("Subscreen:") self.subscreen_name.setFont(self.font) self.info_msg_label = QLabel("Alarm Reason") self.info_msg_label.setFont(self.font) self.info_msg_label.setStyleSheet("QLabel { color : " + self.foreground_color + ";}") self.foreground_color = foreground_color self.setStyleSheet("background-color : #775500;") self.gui_button_builder = GuiButtonBuilder() self.gui_button_builder.set_color(foreground_color) self.gui_button_builder.set_size(50, 100) self.main_layout.addWidget(self.subscreen_name, 1, 0, 1, 1, Qt.AlignHCenter) self.main_layout.addWidget(self.info_msg_label, 2, 0, 1, 1, Qt.AlignHCenter) self.close_button = self.gui_button_builder.create_button("Close", Gui_Element.BUTTON_FULL_CIRCLE_TEXT) self.main_layout.addWidget(self.close_button, 3, 2, 1, 2, Qt.AlignLeft) self.setLayout(self.main_layout) self.close_button.clicked.connect(lambda: self.close_alarm_widget()) def set_alarm_text(self, msg: dict): self.subscreen_name.setText(msg["subscreen_name"]) self.info_msg_label.setText(msg["msg"]) def close_alarm_widget(self): if self.parent is not None: self.parent.toggle_main_widget(0)
def __init__(self): super().__init__() self.foreground_color = "" self.button_height = 60 self.button_width = 96 self.config_reader = ConfigReader() self.gui_element_builder = GuiElementsBuilder() self.gui_button_builder = GuiButtonBuilder() self.button_counter = 0 self.buttons = []
class GuiMenuBuilder(QWidget): def __init__(self): super().__init__() self.foreground_color = "" self.button_height = 60 self.button_width = 96 self.config_reader = ConfigReader() self.gui_element_builder = GuiElementsBuilder() self.gui_button_builder = GuiButtonBuilder() self.button_counter = 0 self.buttons = [] def build_menu(self, config: dict, foreground_color) -> QLayout: self.foreground_color = foreground_color if type(config) == list: self.button_counter = len(config) # Menu ######################################################################################################### self.vbox_menu = QVBoxLayout() self.vbox_menu.setSizeConstraint(QLayout.SetFixedSize) # ToDo other header for menu depending on layout option self.vbox_menu.addWidget( self.gui_element_builder.get_svg_widget(Gui_Element.TOP_LEFT_SHORT, 61, 120, self.foreground_color), Qt.AlignTop) self.gui_button_builder.set_size(self.button_height, self.button_width) for i in range(0, self.button_counter): self.gui_button_builder.set_color(config[i]["Background"]) self.buttons.insert( i, self.gui_button_builder.create_button(config[i]["name"], Gui_Element.BUTTON_TEXT)) self.vbox_menu.addWidget(self.buttons[i]) # ToDo other footer for menu depending on layout option self.vbox_menu.addWidget( self.gui_element_builder.get_svg_widget(Gui_Element.BUTTON, 172, self.button_width, self.foreground_color)) self.vbox_menu.addWidget( self.gui_element_builder.get_svg_widget( Gui_Element.BOTTOM_LEFT_SHORT, 41, 120, self.foreground_color), Qt.AlignBottom) # End Menu ##################################################################################################### return self.vbox_menu def get_button_list(self) -> list: return self.buttons
def __init__(self, resolution: QRect, *args, **kwargs): super(MainWindow, self).__init__(*args, **kwargs) self.setWindowTitle("") self.screens_config = [] self.current_screen = 0 self.sub_screens = {} self.button = {} self.subscreen_stacked_widget = QStackedWidget() self.number_of_subs = 0 self.main_stack_widget = QStackedWidget() self.main_widget = QWidget() self.main_layout = QGridLayout() self.gui_element_builder = GuiElementsBuilder() self.gui_button_builder = GuiButtonBuilder() self.gui_subscreen_builder = GuiSubscreenBuilder() self.resolution = resolution self.alarm_observer = AlarmObserver(self) self.alarm_widget = Alarm(self.alarm_observer, "Alarm_Widget", "#550055", self)
def __init__(self, observer: Observer, name: str, parent, foreground_color="#ffffff", font_name=""): super().__init__(observer, name) self.parent = parent self.observer = observer self.foreground_color = foreground_color self.background_color = "#050505" self.gui_button_builder = GuiButtonBuilder() self.timer_name = QLabel("Name:") self.timer_name_value = QLabel("Timer ") self.main_layout = QGridLayout() self.timer_list = QListWidget() self.timer_list.setStyleSheet( "QListWidget{background:" + self.background_color + "; border: 0px solid " + self.foreground_color + ";}") self.gui_button_builder.set_color(foreground_color) self.gui_button_builder.set_size(50, 100) self.button_add_timer = self.gui_button_builder.create_button("Create", Gui_Element.BUTTON_FULL_CIRCLE_TEXT) self.button_add_timer.clicked.connect(lambda: self.parent.switch_central_widget()) self.main_layout.addWidget(self.timer_list, 0, 0, 3, 4) self.main_layout.addWidget(self.button_add_timer, 4, 5) self.setLayout(self.main_layout)
def __init__(self, parent, foreground_color="#ffffff", font_name=""): super(SetupWidget, self).__init__() self.name = "Setup" self.parent = parent self.main_layout = QVBoxLayout() self.font = QFont(font_name, 60, QFont.Bold) self.font_small = QFont(font_name, 30, QFont.Bold) self.font_extra_small = QFont(font_name, 20, QFont.Bold) self.foreground_color = foreground_color self.label_style = "QLabel { color : " + self.foreground_color + "; }" self.app_id_label = QLabel("AppID:") self.app_id_value = QLineEdit() self.head_line = QHBoxLayout() self.title_label = QLabel("Stadt hinzufügen") self.title_label.setFont(self.font_small) self.title_label.setStyleSheet(self.label_style) self.head_line.addStretch() self.head_line.addWidget(self.title_label) self.head_line.addStretch() self.combobox_line = QHBoxLayout() self.city_combobox = QComboBox() self.city_combobox.setFixedSize(200, 40) self.city_combobox.setEditable(False) self.city_combobox.setFont(self.font_extra_small) self.city_combobox.addItems(["Berlin", "Dresden", "Leipzig"]) self.combo_changed(self.city_combobox) self.combobox_line.addStretch(1) self.combobox_line.addWidget(self.city_combobox) self.gui_button_builder = GuiButtonBuilder() self.gui_button_builder.set_color(self.foreground_color) self.gui_button_builder.set_size(40, 80) self.add_button = self.gui_button_builder.create_button( "Neu", Gui_Element.BUTTON_FULL_CIRCLE_TEXT) self.unit_line = QHBoxLayout() self.unit_combobox = QComboBox() self.unit_combobox.setFixedSize(200, 40) self.unit_combobox.setFont(self.font_extra_small) self.combo_changed(self.unit_combobox) self.unit_combobox.setAutoFillBackground(True) self.unit_combobox.addItems( [UnitSystem.metric.name, UnitSystem.imperial.name]) self.combobox_line.addWidget(self.unit_combobox) self.combobox_line.addWidget(self.add_button) self.combobox_line.addStretch(1) self.main_layout.addLayout(self.head_line) self.main_layout.addSpacing(40) self.main_layout.addLayout(self.combobox_line) self.main_layout.addStretch() self.setLayout(self.main_layout) self.add_button.clicked.connect(lambda: self.add_new_city())
class MainWindow(QMainWindow): def __init__(self, resolution: QRect, *args, **kwargs): super(MainWindow, self).__init__(*args, **kwargs) self.setWindowTitle("") self.screens_config = [] self.current_screen = 0 self.sub_screens = {} self.button = {} self.subscreen_stacked_widget = QStackedWidget() self.number_of_subs = 0 self.main_stack_widget = QStackedWidget() self.main_widget = QWidget() self.main_layout = QGridLayout() self.gui_element_builder = GuiElementsBuilder() self.gui_button_builder = GuiButtonBuilder() self.gui_subscreen_builder = GuiSubscreenBuilder() self.resolution = resolution self.alarm_observer = AlarmObserver(self) self.alarm_widget = Alarm(self.alarm_observer, "Alarm_Widget", "#550055", self) def set_current_subscreen(self): source_button = self.sender() for i in range(0, self.number_of_subs): # print(source_button.text(), self.subscreen_stacked_widget.widget(i).get_name()) if self.subscreen_stacked_widget.widget( i).get_name() == source_button.text(): self.subscreen_stacked_widget.setCurrentIndex(i) def toggle_main_widget(self, index: int): max_value = self.main_stack_widget.count() self.main_stack_widget.setCurrentIndex(index % max_value) def close_main_window(self): self.close() def update_from_subscreen(self, msg: dict) -> None: print(msg) self.alarm_widget.set_alarm_text(msg) self.toggle_main_widget(1) def init_with_config(self, config: dict): self.screens_config = config # Set Title title = str(config['main']['name']) self.setWindowTitle(title) # Set window flag flags = Qt.CustomizeWindowHint # Small Frame # flags = Qt.FramelessWindowHint # No Frame self.setWindowFlags(flags) # Set Resolution ###################################################### # via config window_width = config['main']["resolution"][0] window_height = config['main']["resolution"][1] # via given screen geometry # window_width = self.resolution.width() # window_height = self.resolution.height() # Set Resolution End ################################################## button_width = config['main']["button-size"][0] button_height = config['main']["button-size"][1] front_color = config['main']["front_color"] background_color = config['main']["background_color"] font = config['main']["font"] self.number_of_subs = len(config['sub']) self.gui_element_builder.set_font(font) self.setFixedSize(window_width, window_height) self.main_widget.setLayout(self.main_layout) self.main_widget.setStyleSheet("background-color:" + background_color) vbox_menu = QVBoxLayout() vbox_menu.setSizeConstraint(QLayout.SetFixedSize) vbox_menu.addWidget( self.gui_element_builder.get_svg_widget(Gui_Element.TOP_LEFT_SHORT, 100, 191, front_color)) button_list_widget = QListWidget() vbox_menu.addWidget(button_list_widget) vbox_menu.addWidget( self.gui_element_builder.get_svg_widget( Gui_Element.BOTTOM_LEFT_SHORT, 100, 191, front_color)) # Header ################################################################# self.main_layout.addWidget( self.gui_element_builder.get_svg_widget(Gui_Element.BUTTON, 33, 712, front_color), 0, 1, 1, 1, Qt.AlignTop) self.main_layout.addWidget( self.gui_element_builder.get_svg_widget(Gui_Element.BUTTON, 33, 52, front_color), 0, 3, Qt.AlignTop) self.main_layout.addWidget( self.gui_element_builder.get_svg_widget(Gui_Element.END_RIGHT, 33, 33, front_color), 0, 4, Qt.AlignTop) # Header - END ########################################################### # Menu self.main_layout.addLayout(vbox_menu, 0, 0, 4, 1) # Central Window self.main_layout.addWidget(self.subscreen_stacked_widget, 1, 1, 2, 4) # Footer ################################################################# self.main_layout.addWidget( self.gui_element_builder.get_svg_widget(Gui_Element.BUTTON, 33, 712, front_color), 3, 1, Qt.AlignBottom) # Add Exit Button exit_button = QPushButton("EXIT") exit_button.setFont(QFont(font, 20, QFont.Bold)) exit_button.setFixedSize(52, 33) exit_button.setStyleSheet("background:#ff0000; border:1px solid " + front_color + ";") exit_button.clicked.connect(lambda state: self.close()) self.main_layout.addWidget(exit_button, 3, 3, Qt.AlignBottom) self.main_layout.addWidget( self.gui_element_builder.get_svg_widget(Gui_Element.END_RIGHT, 33, 33, front_color, font), 3, 4, Qt.AlignBottom) # Footer - END ########################################################### # button_ListWidget.setVerticalScrolllayout(QAbstractItemView.ScrollMode.ScrollPerItem) button_list_widget.setStyleSheet("QListWidget{background:" + background_color + "; border: 0px solid " + front_color + ";}") # Erstellen der linken Button-Leiste ############## button_width = button_width * window_width / 100 button_height = button_height * window_height / 100 button_size = QSize(button_width, button_height) for i in range(0, self.number_of_subs): sub_button_list_item = QListWidgetItem(button_list_widget) placeholder_list_item = QListWidgetItem(button_list_widget) placeholder_list_item.setSizeHint(QSize(button_width, 4)) placeholder_list_item.setBackground(QColor(background_color)) flag = placeholder_list_item.flags() & Qt.ItemIsUserCheckable placeholder_list_item.setFlags(flag) # Widgets ################################################################################################## self.subscreen_stacked_widget.insertWidget( i, self.gui_subscreen_builder.init_with_config( self.screens_config['sub'][i], self.alarm_observer)) # Buttons ################################################################################################## self.gui_button_builder.set_color( self.screens_config['sub'][i]["Background"]) self.gui_button_builder.set_size(button_height, button_width) self.button[i] = self.gui_button_builder.create_button( self.screens_config["sub"][i]["name"], Gui_Element.BUTTON_TEXT) sub_button_list_item.setSizeHint(button_size) button_list_widget.addItem(placeholder_list_item) button_list_widget.addItem(sub_button_list_item) button_list_widget.setItemWidget(sub_button_list_item, self.button[i]) # signals ################################################################################################## self.button[i].clicked.connect( lambda widget=self.subscreen_stacked_widget.widget( i): self.set_current_subscreen()) # button_list_widget.setMaximumWidth(1000) button_list_widget.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff) button_list_widget.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) button_list_widget.setMaximumWidth( button_list_widget.sizeHintForColumn(0)) ############################################# self.subscreen_stacked_widget.setCurrentIndex(0) self.main_stack_widget.insertWidget(0, self.main_widget) self.main_stack_widget.insertWidget(1, self.alarm_widget) self.main_stack_widget.setCurrentIndex(0) self.setCentralWidget(self.main_stack_widget)
class TimerListWidget(Base): def __init__(self, observer: Observer, name: str, foreground_color="#ffffff", parent=None, item: TimerListItem=None): super().__init__(observer, name) self.parent = parent self.item = item self.observer = observer self.foreground_color = foreground_color self.setStyleSheet("QLabel { color : " + self.foreground_color + "; font: 30pt;}") self.hbox_layout = QHBoxLayout() self.timer_name = QLabel(self.item.get_name()) self.timer_value = QLabel(self.item.get_start_value_as_str()) self.start_button_state = False # Is active self.check_timer = QTimer(self) self.check_timer.setInterval(100) # .1 seconds self.check_timer.timeout.connect(lambda: self.update_count_down()) self.count_down_timer = QTimer(self) self.count_down_timer.setInterval(item.get_start_value_as_int()) self.count_down_timer.timeout.connect(lambda: self.count_down_end()) self.gui_button_builder = GuiButtonBuilder() self.gui_button_builder.set_color(foreground_color) self.gui_button_builder.set_size(30, 60) self.delete_button = self.gui_button_builder.create_button("Delete", Gui_Element.BUTTON_FULL_CIRCLE_TEXT) self.delete_button.clicked.connect(lambda: self.remove_item()) self.start_pause_button = self.gui_button_builder.create_button("Start", Gui_Element.BUTTON_FULL_CIRCLE_TEXT) self.start_pause_button.clicked.connect(lambda: self.start_button_pressed()) self.hbox_layout.addWidget(self.timer_name) self.hbox_layout.addWidget(self.timer_value) self.hbox_layout.addWidget(self.start_pause_button) self.hbox_layout.addWidget(self.delete_button) self.setLayout(self.hbox_layout) def set_observer(self, observer: Observer): self.observer = observer def remove_item(self): row = self.parent.row(self.item) self.parent.takeItem(row) self.check_timer.stop() self.count_down_timer.stop() del self.item del self def start_button_pressed(self): if self.start_button_state: self.start_button_state = False self.start_pause_button.setText("Stop") self.start_pause_button.setLayout() self.check_timer.stop() self.count_down_timer.stop() else: self.start_button_state = True self.start_pause_button.setText("Start") self.check_timer.start() self.count_down_timer.start() def update_count_down(self): millis = self.count_down_timer.remainingTime() if millis < 0: self.timer_value.setText("00:00:00") return seconds = (millis / 1000) % 60 seconds = int(seconds) minutes = (millis / (1000 * 60)) % 60 minutes = int(minutes) hours = (millis / (1000 * 60 * 60)) % 24 string = "%02d:%02d:%02d" % (hours, minutes, seconds) self.timer_value.setText(string) def count_down_end(self): self.count_down_timer.stop() msg = { "subscreen_name": "TimerOverview", "msg": self.timer_name.text() + " expired" } self.observer.update_from_subscreen(msg)
def __init__(self, observer: Observer, name: str, parent, foreground_color="#ffffff", font_name=""): super().__init__(observer, name) self.parent = parent self.gui_button_builder = GuiButtonBuilder() self.timer_name = QLabel("Name:") self.timer_name_value = QLabel("Timer ") self.timer_counter = 0 self.timer_name_value.setText((self.timer_name_value.text()[:6]) + str(self.timer_counter)) self.main_layout = QGridLayout() self.hbox_titel = QHBoxLayout() self.hbox_up = QHBoxLayout() self.hbox_value = QHBoxLayout() self.hbox_down = QHBoxLayout() self.hbox_control = QHBoxLayout() self.hbox_placeholder = QHBoxLayout() self.hour = QLabel("0") self.minutes = QLabel("0") self.seconds = QLabel("0") self.setStyleSheet("QLabel { color : " + self.foreground_color + "; font: 30pt;}") self.gui_button_builder.set_color(foreground_color) self.gui_button_builder.set_size(50, 100) self.gui_button_builder.set_style("font-size: 30pt;") self.button_up_h = self.gui_button_builder.create_button("h+", Gui_Element.BUTTON_FULL_CIRCLE_TEXT) self.button_down_h = self.gui_button_builder.create_button("h-", Gui_Element.BUTTON_FULL_CIRCLE_TEXT) self.button_up_min = self.gui_button_builder.create_button("min+", Gui_Element.BUTTON_FULL_CIRCLE_TEXT) self.button_down_min = self.gui_button_builder.create_button("min-", Gui_Element.BUTTON_FULL_CIRCLE_TEXT) self.button_up_sec = self.gui_button_builder.create_button("sec+", Gui_Element.BUTTON_FULL_CIRCLE_TEXT) self.button_down_sec = self.gui_button_builder.create_button("sec-", Gui_Element.BUTTON_FULL_CIRCLE_TEXT) self.button_up_h.clicked.connect(lambda state, lab=self.hour: self.plus(lab, 23)) self.button_down_h.clicked.connect(lambda state, lab=self.hour: self.minus(lab, 23)) self.button_up_min.clicked.connect(lambda state, lab=self.minutes: self.plus(lab, 59)) self.button_down_min.clicked.connect(lambda state, lab=self.minutes: self.minus(lab, 59)) self.button_up_sec.clicked.connect(lambda state, lab=self.seconds: self.plus(lab, 59)) self.button_down_sec.clicked.connect(lambda state, lab=self.seconds: self.minus(lab, 59)) self.gui_button_builder.set_size(50, 100) self.button_add_timer = self.gui_button_builder.create_button("Add", Gui_Element.BUTTON_FULL_CIRCLE_TEXT) self.button_add_timer.clicked.connect(lambda: self.add_timer()) self.button_close = self.gui_button_builder.create_button("OK", Gui_Element.BUTTON_FULL_CIRCLE_TEXT) self.button_close.clicked.connect(lambda: self.parent.switch_central_widget()) # ToDo refactor layout self.hbox_titel.addStretch() self.hbox_titel.addWidget(self.timer_name) self.hbox_titel.addWidget(self.timer_name_value) self.hbox_titel.addStretch() self.hbox_up.addStretch() self.hbox_up.addWidget(self.button_up_h, 0, Qt.AlignHCenter) self.hbox_up.addStretch() self.hbox_up.addWidget(self.button_up_min, 0, Qt.AlignHCenter) self.hbox_up.addStretch() self.hbox_up.addWidget(self.button_up_sec, 0, Qt.AlignHCenter) self.hbox_up.addStretch() self.hbox_value.addStretch() self.hbox_value.addWidget(self.hour) self.hbox_value.addStretch() self.hbox_value.addWidget(self.minutes) self.hbox_value.addStretch() self.hbox_value.addWidget(self.seconds) self.hbox_value.addStretch() self.hbox_down.addStretch() self.hbox_down.addWidget(self.button_down_h) self.hbox_down.addStretch() self.hbox_down.addWidget(self.button_down_min) self.hbox_down.addStretch() self.hbox_down.addWidget(self.button_down_sec) self.hbox_down.addStretch() self.hbox_placeholder.addStretch() self.hbox_placeholder.addWidget(QLabel("")) self.hbox_control.addStretch() self.hbox_control.addWidget(self.button_add_timer) self.hbox_control.addWidget(self.button_close) self.main_layout.addLayout(self.hbox_titel, 0, 0) self.main_layout.addLayout(self.hbox_up, 1, 0) self.main_layout.addLayout(self.hbox_value, 2, 0) self.main_layout.addLayout(self.hbox_down, 3, 0) self.main_layout.addLayout(self.hbox_placeholder, 4, 0) self.main_layout.addLayout(self.hbox_control, 5, 0) self.setLayout(self.main_layout)