def __init__(self, fitting_data: FittingData, app: toga.App): """Initialize window.""" super().__init__(title="Choose Records", size=RECORD_WINDOW_SIZE) main_box = toga.Box(style=Pack(direction=COLUMN)) data_box = toga.Box() self.__checkboxes = [ toga.Switch( label="", is_on=fitting_data.is_selected(i), style=Pack(height=LINE_HEIGHT), ) for i in range(1, fitting_data.length + 1) ] data_box.add( toga.Box( style=Pack( flex=1, direction=COLUMN, padding_left=SMALL_PADDING, padding_right=SMALL_PADDING, ), children=[ toga.Label(text="Chosen", style=Pack(height=LINE_HEIGHT)) ] + self.__checkboxes, # noqa: W503 )) for header, column in fitting_data.data.items(): data_box.add( toga.Box( style=Pack( flex=1, direction=COLUMN, padding_left=SMALL_PADDING, padding_right=SMALL_PADDING, ), children=[ toga.Label(text=header, style=Pack(height=LINE_HEIGHT)) ] + [ # noqa: W503 toga.Label(text=element, style=Pack(height=LINE_HEIGHT)) for element in column ], )) main_box.add(data_box) main_box.add( LineBox(children=[ toga.Button(label="Save", on_press=self.save_action(fitting_data)) ], )) scroller = toga.ScrollContainer(content=main_box) self.content = scroller self.app = app
def __init__(self, fitting_data: FittingData, font_size: FontSize, app: toga.App): """Initialize window.""" super().__init__(title="Choose Records", size=RECORD_WINDOW_SIZE) self.__fitting_data = fitting_data main_box = toga.Box(style=Pack(direction=COLUMN)) data_box = toga.Box() statistics_box = toga.Box() font_size_value = FontSize.get_font_size(font_size) self.__update_on_check = True self.__statistics_labels = { (column, parameter): toga.Label( text=to_relevant_precision_string( getattr(fitting_data.statistics(column), parameter, 0)), style=Pack(height=LINE_HEIGHT, width=COLUMN_WIDTH, font_size=font_size_value), ) for column, parameter in itertools.product( fitting_data.all_columns, Statistics.parameters()) } self.__checkboxes = [ toga.Switch( label="", is_on=fitting_data.is_selected(i), on_toggle=self.select_records, style=Pack(height=LINE_HEIGHT, width=COLUMN_WIDTH, font_size=font_size_value), ) for i in range(1, fitting_data.length + 1) ] self.__all_checkbox = toga.Switch( label="", is_on=self.are_all_selected(), on_toggle=self.select_all, style=Pack(height=TITLES_LINE_HEIGHT, font_size=font_size_value), ) self.__selected_records_label = toga.Label( text="", style=Pack(font_size=font_size_value, width=COLUMN_WIDTH, height=TITLES_LINE_HEIGHT), ) data_box.add( toga.Box( style=Pack( flex=1, direction=COLUMN, padding_left=SMALL_PADDING, padding_right=SMALL_PADDING, ), children=[ toga.Box( style=Pack( height=TITLES_LINE_HEIGHT, font_size=font_size_value, ), children=[ self.__all_checkbox, self.__selected_records_label ], ), *self.__checkboxes, ], )) for header, column in fitting_data.data.items(): data_box.add( toga.Box( style=Pack( flex=1, direction=COLUMN, padding_left=SMALL_PADDING, padding_right=SMALL_PADDING, ), children=[ toga.Label( text=header, style=Pack( height=TITLES_LINE_HEIGHT, width=COLUMN_WIDTH, font_size=font_size_value, font_weight=BOLD, ), ), *[ toga.Label( text=to_relevant_precision_string(element), style=Pack( height=LINE_HEIGHT, width=COLUMN_WIDTH, font_size=font_size_value, ), ) for element in column ], ], )) main_box.add(data_box) main_box.add(toga.Divider()) statistics_box.add( toga.Box( style=Pack( flex=1, direction=COLUMN, padding_left=SMALL_PADDING, padding_right=SMALL_PADDING, ), children=[ toga.Label( text=parameter.replace("_", " ").title(), style=Pack( height=LINE_HEIGHT, width=COLUMN_WIDTH, font_size=font_size_value, font_weight=BOLD, ), ) for parameter in Statistics.parameters() ], )) for header, column in fitting_data.data.items(): statistics_box.add( toga.Box( style=Pack( flex=1, direction=COLUMN, padding_left=SMALL_PADDING, padding_right=SMALL_PADDING, ), children=[ self.__statistics_labels[(header, parameter)] for parameter in Statistics.parameters() ], )) main_box.add(statistics_box) main_box.add( LineBox(children=[ toga.Button(label="Close", on_press=lambda _: self.close()) ], )) scroller = toga.ScrollContainer(content=main_box) self.content = scroller self.app = app self.update()