class MultidayTab(Tab): def __init__(self, parent): self.widget = QWidget() self.layout = QFormLayout(parent) self.item_races = AdvComboBox() self.fill_race_list() max_button_width = 100 def select_race(): index = self.item_races.currentIndex() set_current_race_index(index) GlobalAccess().get_main_window().refresh() self.item_races.currentIndexChanged.connect(select_race) self.layout.addRow(self.item_races) def add_race_function(): add_race() self.fill_race_list() self.item_new = QPushButton(_('New')) self.item_new.clicked.connect(add_race_function) self.item_new.setMaximumWidth(max_button_width) self.layout.addRow(self.item_new) def copy_race_function(): copy_race() self.fill_race_list() self.item_copy = QPushButton(_('Copy')) self.item_copy.clicked.connect(copy_race_function) self.item_copy.setMaximumWidth(max_button_width) self.layout.addRow(self.item_copy) def move_up_race_function(): move_up_race() self.fill_race_list() self.item_move_up = QPushButton(_('Move up')) self.item_move_up.clicked.connect(move_up_race_function) self.item_move_up.setMaximumWidth(max_button_width) self.layout.addRow(self.item_move_up) def move_down_race_function(): move_down_race() self.fill_race_list() self.item_move_down = QPushButton(_('Move down')) self.item_move_down.clicked.connect(move_down_race_function) self.item_move_down.setMaximumWidth(max_button_width) self.layout.addRow(self.item_move_down) def del_race_function(): del_race() self.fill_race_list() self.item_del = QPushButton(_('Delete')) self.item_del.clicked.connect(del_race_function) self.item_del.setMaximumWidth(max_button_width) self.layout.addRow(self.item_del) self.widget.setLayout(self.layout) def save(self): pass def fill_race_list(self): race_list = [] index = get_current_race_index() self.item_races.clear() for cur_race in races(): assert isinstance(cur_race, Race) race_list.append(str(cur_race.data.get_start_datetime())) self.item_races.addItems(race_list) self.item_races.setCurrentIndex(index)
class SportOrgImportDialog(QDialog): def __init__(self, races, current_race=0): super().__init__(GlobalAccess().get_main_window()) self.races = races self.current_race = current_race def exec_(self): self.init_ui() self.set_values() return super().exec_() def init_ui(self): self.setWindowTitle(_('Import')) self.setWindowIcon(QIcon(config.ICON)) self.setSizeGripEnabled(False) self.setModal(True) self.layout = QFormLayout(self) self.item_races = AdvComboBox() self.layout.addRow(QLabel(_('Choose race')), self.item_races) self.unique_id_box = QGroupBox(_('Unique id')) self.unique_id_box_layout = QFormLayout() self.unique_id_item_id = QRadioButton(_('Id')) self.unique_id_item_id.setChecked(True) self.unique_id_box_layout.addRow(self.unique_id_item_id) self.unique_id_item_name = QRadioButton(_('Name')) self.unique_id_item_name.setDisabled(True) self.unique_id_box_layout.addRow(self.unique_id_item_name) self.unique_id_box.setLayout(self.unique_id_box_layout) self.layout.addRow(self.unique_id_box) self.import_action_box = QGroupBox(_('Action')) self.import_action_box_layout = QFormLayout() self.import_action_item_add = QRadioButton(_('Add')) self.import_action_box_layout.addRow(self.import_action_item_add) self.import_action_item_overwrite = QRadioButton(_('Overwrite')) self.import_action_item_overwrite.setChecked(True) self.import_action_box_layout.addRow(self.import_action_item_overwrite) self.import_action_box.setLayout(self.import_action_box_layout) self.layout.addRow(self.import_action_box) def cancel_changes(): self.close() def apply_changes(): try: self.apply_changes_impl() except Exception as e: logging.error(str(e)) self.close() button_box = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) self.button_ok = button_box.button(QDialogButtonBox.Ok) self.button_ok.setText(_('OK')) self.button_ok.clicked.connect(apply_changes) self.button_cancel = button_box.button(QDialogButtonBox.Cancel) self.button_cancel.setText(_('Cancel')) self.button_cancel.clicked.connect(cancel_changes) self.layout.addRow(button_box) self.show() def set_values(self): self.fill_race_list() def apply_changes_impl(self): import_race = self.races[self.item_races.currentIndex()] unique_id = 'id' if self.unique_id_item_name.isChecked(): unique_id = 'name' action = 'add' if self.import_action_item_overwrite.isChecked(): action = 'overwrite' obj = race() if unique_id == 'id' and action == 'overwrite': import_race.id = obj.id obj.update_data(import_race.to_dict()) return if unique_id == 'id' and action == 'add': organizations = [] for org in import_race.organizations: old_org = find(obj.organizations, id=org.id) old_org_by_name = find(obj.organizations, name=org.name) if old_org is None: if old_org_by_name is not None: org.name = '_' + org.name organizations.append(org) obj.organizations.extend(organizations) courses = [] for course in import_race.courses: old_course = find(obj.courses, id=course.id) old_course_by_name = find(obj.courses, name=course.name) if old_course is None: if old_course_by_name is not None: course.name = '_' + course.name courses.append(course) obj.courses.extend(courses) groups = [] for group in import_race.groups: old_group = find(obj.groups, id=group.id) old_group_by_name = find(obj.groups, name=group.name) if old_group is None: if old_group_by_name is not None: group.name = '_' + group.name if group.course: group.course = find(obj.courses, id=group.course.id) groups.append(group) obj.groups.extend(groups) persons = [] for person in import_race.persons: if find(obj.persons, id=person.id) is None: if person.group: person.group = find(obj.groups, id=person.group.id) if person.organization: person.organization = find(obj.organizations, id=person.organization.id) persons.append(person) obj.persons.extend(persons) results = [] for result in import_race.results: if find(obj.results, id=result.id) is None: if result.person: result.person = find(obj.persons, id=result.person.id) results.append(result) obj.results.extend(results) return def fill_race_list(self): race_list = [] self.item_races.clear() for cur_race in self.races: assert isinstance(cur_race, Race) race_list.append(str(cur_race.data.get_start_datetime())) self.item_races.addItems(race_list) self.item_races.setCurrentIndex(self.current_race)
class GroupEditDialog(QDialog): def __init__(self, group, is_new=False): super().__init__(GlobalAccess().get_main_window()) assert (isinstance(group, Group)) self.current_object = group self.is_new = is_new self.time_format = 'hh:mm:ss' def exec_(self): self.init_ui() self.set_values_from_model() return super().exec_() def init_ui(self): self.setWindowTitle(_('Group properties')) self.setWindowIcon(QIcon(config.ICON)) self.setSizeGripEnabled(False) self.setModal(True) self.layout = QFormLayout(self) self.label_name = QLabel(_('Name')) self.item_name = QLineEdit() self.item_name.textChanged.connect(self.check_name) self.layout.addRow(self.label_name, self.item_name) self.label_full_name = QLabel(_('Full name')) self.item_full_name = QLineEdit() self.layout.addRow(self.label_full_name, self.item_full_name) self.label_course = QLabel(_('Course')) self.item_course = AdvComboBox() self.item_course.addItems(get_race_courses()) self.layout.addRow(self.label_course, self.item_course) self.label_is_any_course = QLabel(_('Is any course')) self.item_is_any_course = QCheckBox() self.item_is_any_course.stateChanged.connect(self.is_any_course_update) self.layout.addRow(self.label_is_any_course, self.item_is_any_course) self.label_sex = QLabel(_('Sex')) self.item_sex = AdvComboBox() self.item_sex.addItems(Sex.get_titles()) self.layout.addRow(self.label_sex, self.item_sex) self.label_age_min = QLabel(_('Min age')) self.item_age_min = QSpinBox() # self.layout.addRow(self.label_age_min, self.item_age_min) self.label_age_max = QLabel(_('Max age')) self.item_age_max = QSpinBox() # self.layout.addRow(self.label_age_max, self.item_age_max) self.label_year_min = QLabel(_('Min year')) self.item_year_min = QSpinBox() self.item_year_min.setMaximum(date.today().year) self.item_year_min.editingFinished.connect(self.year_change) self.layout.addRow(self.label_year_min, self.item_year_min) self.label_year_max = QLabel(_('Max year')) self.item_year_max = QSpinBox() self.item_year_max.setMaximum(date.today().year) self.item_year_max.editingFinished.connect(self.year_change) self.layout.addRow(self.label_year_max, self.item_year_max) self.label_max_time = QLabel(_('Max time')) self.item_max_time = QTimeEdit() self.item_max_time.setDisplayFormat(self.time_format) self.layout.addRow(self.label_max_time, self.item_max_time) self.label_corridor = QLabel(_('Start corridor')) self.item_corridor = QSpinBox() self.layout.addRow(self.label_corridor, self.item_corridor) self.label_corridor_order = QLabel(_('Order in corridor')) self.item_corridor_order = QSpinBox() self.layout.addRow(self.label_corridor_order, self.item_corridor_order) self.label_start_interval = QLabel(_('Start interval')) self.item_start_interval = QTimeEdit() self.item_start_interval.setDisplayFormat(self.time_format) self.layout.addRow(self.label_start_interval, self.item_start_interval) self.label_price = QLabel(_('Start fee')) self.item_price = QSpinBox() self.item_price.setSingleStep(50) self.item_price.setMaximum(Limit.PRICE) self.layout.addRow(self.label_price, self.item_price) self.type_label = QLabel(_('Type')) self.type_combo = AdvComboBox() self.type_combo.addItems(RaceType.get_titles()) self.layout.addRow(self.type_label, self.type_combo) self.rank_checkbox = QCheckBox(_('Rank calculation')) self.rank_button = QPushButton(_('Configuration')) self.layout.addRow(self.rank_checkbox, self.rank_button) def cancel_changes(): self.close() def apply_changes(): try: self.apply_changes_impl() except Exception as e: logging.error(str(e)) self.close() button_box = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) self.button_ok = button_box.button(QDialogButtonBox.Ok) self.button_ok.setText(_('OK')) self.button_ok.clicked.connect(apply_changes) self.button_cancel = button_box.button(QDialogButtonBox.Cancel) self.button_cancel.setText(_('Cancel')) self.button_cancel.clicked.connect(cancel_changes) self.layout.addRow(button_box) self.show() self.button_ok.setFocus() def check_name(self): name = self.item_name.text() self.button_ok.setDisabled(False) if name and name != self.current_object.name: group = find(race().groups, name=name) if group: self.button_ok.setDisabled(True) def year_change(self): """ Convert 2 digits of year to 4 2 -> 2002 11 - > 2011 33 -> 1933 56 -> 1956 98 - > 1998 0 -> 0 exception! """ widget = self.sender() assert isinstance(widget, QSpinBox) year = widget.value() if 0 < year < 100: cur_year = date.today().year new_year = cur_year - cur_year % 100 + year if new_year > cur_year: new_year -= 100 widget.setValue(new_year) def is_any_course_update(self): if self.item_is_any_course.isChecked(): self.item_course.setDisabled(True) else: self.item_course.setDisabled(False) def set_values_from_model(self): self.item_name.setText(self.current_object.name) if self.current_object.long_name: self.item_full_name.setText(self.current_object.long_name) if self.current_object.course: self.item_course.setCurrentText(self.current_object.course.name) if self.current_object.sex: self.item_sex.setCurrentText(self.current_object.sex.get_title()) if self.current_object.min_age: self.item_age_min.setValue(self.current_object.min_age) if self.current_object.max_age: self.item_age_max.setValue(self.current_object.max_age) if self.current_object.min_year: self.item_year_min.setValue(self.current_object.min_year) if self.current_object.max_year: self.item_year_max.setValue(self.current_object.max_year) if self.current_object.max_time: self.item_max_time.setTime( time_to_qtime(self.current_object.max_time)) if self.current_object.start_interval: self.item_start_interval.setTime( time_to_qtime(self.current_object.start_interval)) if self.current_object.start_corridor: self.item_corridor.setValue(self.current_object.start_corridor) if self.current_object.order_in_corridor: self.item_corridor_order.setValue( self.current_object.order_in_corridor) if self.current_object.price: self.item_price.setValue(self.current_object.price) self.item_is_any_course.setChecked(self.current_object.is_any_course) self.rank_checkbox.setChecked(self.current_object.ranking.is_active) self.type_combo.setCurrentText(race().get_type( self.current_object).get_title()) def rank_configuration(): group = self.current_object GroupRankingDialog(group).exec_() self.rank_button.clicked.connect(rank_configuration) def apply_changes_impl(self): group = self.current_object assert (isinstance(group, Group)) if self.is_new: race().groups.insert(0, group) if group.name != self.item_name.text(): group.name = self.item_name.text() if group.long_name != self.item_full_name.text(): group.long_name = self.item_full_name.text() if (group.course is not None and group.course.name != self.item_course.currentText()) \ or (group.course is None and len(self.item_course.currentText()) > 0): group.course = find(race().courses, name=self.item_course.currentText()) if group.sex.get_title() != self.item_sex.currentText(): group.sex = Sex(self.item_sex.currentIndex()) if group.min_age != self.item_age_min.value(): group.min_age = self.item_age_min.value() if group.max_age != self.item_age_max.value(): group.max_age = self.item_age_max.value() if group.min_year != self.item_year_min.value(): group.min_year = self.item_year_min.value() if group.max_year != self.item_year_max.value(): group.max_year = self.item_year_max.value() if group.start_corridor != self.item_corridor.value(): group.start_corridor = self.item_corridor.value() if group.order_in_corridor != self.item_corridor_order.value(): group.order_in_corridor = self.item_corridor_order.value() if group.price != self.item_price.value(): group.price = self.item_price.value() time = time_to_otime(self.item_start_interval.time()) if group.start_interval != time: group.start_interval = time time = time_to_otime(self.item_max_time.time()) if group.max_time != time: group.max_time = time if group.ranking.is_active != self.rank_checkbox.isChecked(): group.ranking.is_active = self.rank_checkbox.isChecked() t = RaceType.get_by_name(self.type_combo.currentText()) selected_type = t if t is not None else group.get_type() if group.get_type() != selected_type: group.set_type(selected_type) group.is_any_course = self.item_is_any_course.isChecked() ResultCalculation(race()).set_rank(group) Teamwork().send(group.to_dict())