def __init_layout(self): """Initialize the central widget layout.""" main_widget = QWidget(self) self.setCentralWidget(main_widget) main_layout = QGridLayout() main_layout.setRowStretch(0, 1) main_layout.setRowStretch(1, 1) main_layout.setRowStretch(2, 20) main_layout.setRowStretch(3, 1) main_layout.setColumnStretch(0, 1) main_layout.setColumnStretch(1, 1) main_layout.setSpacing(0) main_layout.setContentsMargins(0, 0, 0, 0) header_layout = FlowLayout() self.year_edit = QSpinBox(self) self.year_edit.setMinimum(2010) self.year_edit.setMaximum(2050) self.year_edit.setValue(datetime.datetime.now().year) year_widget = QWidget(self) year_layout = QHBoxLayout() year_widget.setLayout(year_layout) year_label = QLabel(self.tr('Year'), self) year_layout.addWidget(year_label) year_layout.addWidget(self.year_edit) self.week_edit = QSpinBox(self) self.week_edit.setMinimum(1) self.__update_week_edit(self.year_edit.value()) self.week_edit.setValue(datetime.date.today().isocalendar()[1]) week_widget = QWidget(self) week_layout = QHBoxLayout() week_widget.setLayout(week_layout) week_label = QLabel(self.tr('Week'), self) week_layout.addWidget(week_label) week_layout.addWidget(self.week_edit) self.week_edit.valueChanged.connect(self.__week_changed) self.year_edit.valueChanged.connect(self.__year_changed) self.week_time_edit = DurationEdit(parent=self, hour_length=2) week_time_widget = QWidget(self) week_time_layout = QHBoxLayout() week_time_widget.setLayout(week_time_layout) week_time_label = QLabel(self.tr('Week time'), self) week_time_layout.addWidget(week_time_label) week_time_layout.addWidget(self.week_time_edit) self.week_time_edit.valueChanged.connect(self.__week_time_changed) self.man_day_edit = QTimeEdit(SettingModel.default_man_day_time(), self) man_day_widget = QWidget(self) man_day_layout = QHBoxLayout() man_day_widget.setLayout(man_day_layout) man_day_label = QLabel(self.tr('Man day time'), self) man_day_layout.addWidget(man_day_label) man_day_layout.addWidget(self.man_day_edit) self.man_day_edit.timeChanged.connect(self.__update_week_summary) header_layout.addWidget(year_widget) header_layout.addWidget(week_widget) header_layout.addWidget(week_time_widget) header_layout.addWidget(man_day_widget) main_layout.addLayout(header_layout, 0, 0, 1, 2) self.current_day_label = self.__build_title_label('') summary_label = self.__build_title_label(self.tr('Week summary')) main_layout.addWidget(self.current_day_label, 1, 0) main_layout.addWidget(summary_label, 1, 1) main_layout.addWidget(self.task_view, 2, 0) main_layout.addWidget(self.result_view, 2, 1) week_time_label = QLabel(self.tr('Week time'), self) self.week_time_lcd = self.__build_lcd_number_widget() remaining_week_label = QLabel(self.tr('Remaining week time'), self) self.remaining_week_time_lcd = self.__build_lcd_number_widget() day_label = QLabel(self.tr('Day time'), self) self.day_time_lcd = self.__build_lcd_number_widget() self.__change_day_color(QColor('#0000ff')) catch_up_label = QLabel(self.tr('Catch-up time'), self) self.catch_up_lcd = self.__build_lcd_number_widget() total_annual_label = QLabel(self.tr('Total annual time'), self) self.total_annual_lcd = self.__build_lcd_number_widget() footer_layout = QGridLayout() footer_layout.addWidget(day_label, 0, 0, Qt.AlignHCenter) footer_layout.addWidget(week_time_label, 0, 1, Qt.AlignHCenter) footer_layout.addWidget(remaining_week_label, 0, 2, Qt.AlignCenter) footer_layout.addWidget(catch_up_label, 0, 3, Qt.AlignCenter) footer_layout.addWidget(total_annual_label, 0, 4, Qt.AlignCenter) footer_layout.addWidget(self.day_time_lcd, 1, 0) footer_layout.addWidget(self.week_time_lcd, 1, 1) footer_layout.addWidget(self.remaining_week_time_lcd, 1, 2) footer_layout.addWidget(self.catch_up_lcd, 1, 3) footer_layout.addWidget(self.total_annual_lcd, 1, 4) main_layout.addLayout(footer_layout, 3, 0, 1, 2) main_widget.setLayout(main_layout)
def __update_settings(self): """Update user interface with new settings.""" self.__init_current_cell_color(self.task_view) self.__init_current_cell_color(self.result_view) self.__update_time() self.man_day_edit.setTime(SettingModel.default_man_day_time())
def __init__(self, parent=None): """Construct a settings dialog.""" super().__init__(parent) self.logger = logging.getLogger(__name__) self.logger.info('Opening setting dialog') self.setWindowTitle(self.tr('Edit preferences')) self.center() self.invalid_color = None self.valid_color = None self.current_cell_color = None self.__update_colors() week_time_label = QLabel(self.tr('Default week time'), self) self.week_time = DurationEdit(parent=self, hour_length=2) self.week_time.minutes = SettingModel.default_week_time() self.logger.info('Read default week time minutes: %s', SettingModel.default_week_time()) self.week_time.valueChanged.connect(self.__week_time_changed) man_day_time_label = QLabel(self.tr('Default man day time'), self) self.man_day_time = QTimeEdit(SettingModel.default_man_day_time(), self) self.logger.info('Read default man day time: %s', SettingModel.default_man_day_time().toString('hh:mm')) self.man_day_time.timeChanged.connect(self.__man_day_time_changed) invalid_color_label = QLabel(self.tr('Invalid color'), self) self.invalid_color_button = QPushButton(self.tr('Text'), self) self.invalid_color_button.clicked.connect( self.__open_invalid_color_dialog) valid_color_label = QLabel(self.tr('Valid color'), self) self.valid_color_button = QPushButton(self.tr('Text'), self) self.valid_color_button.clicked.connect(self.__open_valid_color_dialog) current_cell_color_label = QLabel(self.tr('Current cell color'), self) self.current_cell_color_button = QPushButton(self.tr('Text'), self) self.current_cell_color_button.clicked.connect( self.__open_current_cell_color_dialog) self.__update_buttons_colors() main_layout = QGridLayout() main_layout.addWidget(week_time_label, 0, 0) main_layout.addWidget(self.week_time, 0, 1) main_layout.addWidget(man_day_time_label, 1, 0) main_layout.addWidget(self.man_day_time, 1, 1) main_layout.addWidget(invalid_color_label, 2, 0) main_layout.addWidget(self.invalid_color_button, 2, 1) main_layout.addWidget(valid_color_label, 3, 0) main_layout.addWidget(self.valid_color_button, 3, 1) main_layout.addWidget(current_cell_color_label, 4, 0) main_layout.addWidget(self.current_cell_color_button, 4, 1) self.setLayout(main_layout)