class TransactionsEditor(BaseWidget): def __init__(self, erd, transactions): super(TransactionsEditor, self).__init__() self.set_margin(20) self.transactions = transactions self.erd = erd self._transaction_list = ControlList() self._add_transaction_button = ControlButton('Dodaj transakcję') self._edit_transaction_button = ControlButton('Edytuj transakcję') self._remove_transaction_button = ControlButton('Usuń transakcję') self._add_transaction_button.value = self.__add_transaction_action self._edit_transaction_button.value = self.__edit_transaction_action self._remove_transaction_button.value = self.__remove_transaction_action self._transaction_list.readonly = True self.formset = [ '_transaction_list', ('_add_transaction_button', '_edit_transaction_button', '_remove_transaction_button') ] self.populate() def populate(self): self._transaction_list.clear() for transaction in self.transactions: self._transaction_list += [repr(transaction)] def __add_transaction_action(self): win = TransactionEditor(self.erd, self.transactions) win.parent = self win.show() def __edit_transaction_action(self): index = self._transaction_list.selected_row_index if index is not None: win = TransactionEditor(self.erd, self.transactions, self.transactions[index]) win.parent = self win.show() def __remove_transaction_action(self): index = self._transaction_list.selected_row_index if index is not None: del self._transaction_list[index] self.populate() def __remove_transaction_action(self): index = self._transaction_list.selected_row_index if index is not None: del self.transactions[index] self.populate()
class ForeignKeysEditor(BaseWidget): def __init__(self, erd): super(ForeignKeysEditor, self).__init__() self.erd = erd if self.erd.entities: self.entity = self.erd.entities[0] else: self.entity = Entity('', '', []) self._keys_list = ControlList() self._entity_combo = EntityCombo(self.erd.entities) self._entity_combo.parent = self self._add_fk_button = ControlButton('Dodaj klucz obcy') self._edit_fk_button = ControlButton('Edytuj klucz obcy') self._remove_fk_button = ControlButton('Usuń klucz obcy') self._add_fk_button.value = self.__add_fk_action self._edit_fk_button.value = self.__edit_fk_action self._remove_fk_button.value = self.__remove_fk_action self._keys_list.readonly = True self.formset = [ 'Etap 10 - sprawdz automatycznie wygenerowane klucz obce i w razie potrzeby je popraw', ('Wyświetlam klucz obec dla encji: ', '_entity_combo'), '_keys_list', ('_add_fk_button', '_edit_fk_button', '_remove_fk_button') ] self.populate() def populate(self): self._keys_list.clear() for attribute in self.entity.foreign_keys: self._keys_list += [attribute.name] def __add_fk_action(self): win = ForeignKeyEditor(self.erd) win.parent = self win.show() def __edit_fk_action(self): if self._entity_combo.current_index is not None and self._keys_list.selected_row_index is not None: win = ForeignKeyEditor( self.erd, self.erd.entities[self._entity_combo.current_index], self.entity.foreign_keys[self._keys_list.selected_row_index]) win.parent = self win.show() def __remove_fk_action(self): if self._keys_list.selected_row_index is not None: del self.entity.foreign_keys[self._keys_list.selected_row_index] self.populate()
class UsersEditor(BaseWidget): def __init__(self, erd, users): super(UsersEditor, self).__init__() self.set_margin(20) self.users = users self.erd = erd self._user_list = ControlList() self._add_user_button = ControlButton('Dodaj użytkownika') self._edit_user_button = ControlButton('Edytuj użytkownika') self._remove_user_button = ControlButton('Usuń użytkownika') self._add_user_button.value = self.__add_user_action self._edit_user_button.value = self.__edit_user_action self._remove_user_button.value = self.__remove_user_action self._user_list.readonly = True self.formset = [ '_user_list', ('_add_user_button', '_edit_user_button', '_remove_user_button') ] self.populate() def populate(self): self._user_list.clear() for user in self.users: self._user_list += [user.name] def __add_user_action(self): win = UserEditor(self.erd, self.users) win.parent = self win.show() def __edit_user_action(self): index = self._user_list.selected_row_index if index is not None: win = UserEditor(self.erd, self.users, self.users[index]) win.parent = self win.show() def __remove_user_action(self): index = self._user_list.selected_row_index if index is not None: del self.users[index] self.populate()
class PerspectivesEditor(BaseWidget): def __init__(self, perspectives, users): super(PerspectivesEditor, self).__init__() self.set_margin(20) self.perspectives = perspectives self.users = users self._perspectives_list = ControlList() self._add_perspective_button = ControlButton('Dodaj perspektywę') self._edit_perspective_button = ControlButton('Edytuj perspektywę') self._remove_perspective_button = ControlButton('Usuń perspektywę') self._add_perspective_button.value = self.__add_perspective_action self._edit_perspective_button.value = self.__edit_perspective_action self._remove_perspective_button.value = self.__remove_perspective_action self._perspectives_list.readonly = True self.formset = ['_perspectives_list', ('_add_perspective_button', '_edit_perspective_button', '_remove_perspective_button')] self.populate() def populate(self): self._perspectives_list.clear() for perspective in self.perspectives: self._perspectives_list += [perspective.name] def __add_perspective_action(self): win = PerspectiveEditor(self.perspectives) win.parent = self win.show() def __edit_perspective_action(self): index = self._perspectives_list.selected_row_index if index is not None: win = PerspectiveEditor(self.perspectives, perspective=self.perspectives[index]) win.parent = self win.show() def __remove_perspective_action(self): index = self._perspectives_list.selected_row_index if index is not None: del self.perspectives[index] self.populate()
class Stage4Window(BaseWidget): def __init__(self, erd, project, rules): super(Stage4Window, self).__init__('Etap 4') self.set_margin(20) self._entities_combo = CustomEntityCombo(erd.entities) self._rules_list = ControlList() self._add_rule_button = ControlButton('Dodaj regułę') self._fix_button = ControlButton('Popraw regułę') self._remove_rule_button = ControlButton('Usuń regułę') self._save_button = ControlButton('Zapisz') self.erd = erd self._project = project self.rules = rules self._save_button.value = self.__save_action self._fix_button.value = self.__fix_action self._add_rule_button.value = self.__add_rule_action self._remove_rule_button.value = self.__remove_rule_action self._rules_list.readonly = True self._entities_combo.parent = self self.formset = ['Etap 4 - popraw odmianę w automatycznie wygenerowanych regułach i dopisz kilka własnych', ('Wyświetlam reguły dla kategorii: ', '_entities_combo'), '_rules_list', ('_add_rule_button', '_fix_button', '_remove_rule_button'), '_save_button'] if not rules: self.populate_rules() self.populate() def populate_rules(self): # relationships = self.erd.get_relationships_without_associative_entities() for entity in self.erd.entities: rels = self.erd.get_relationships_connected_with_entity(entity.name_singular) for rel in rels: this_entity_name = entity.name_singular other_entity_name = rel.get_other_entity_name(entity.name_singular) if rel.get_other_ends_multiplicity(this_entity_name)[0] == '0': rule = Rule(this_entity_name + u' nie musi być powiązany z żadnym ' + other_entity_name, this_entity_name, other_entity_name) self.rules.append(rule) elif rel.get_other_ends_multiplicity(entity.name_singular)[0] == '1': rule = Rule(this_entity_name + u' musi być powiązany z przynajmniej jednym ' + other_entity_name, this_entity_name, other_entity_name) self.rules.append(rule) if rel.get_other_ends_multiplicity(entity.name_singular)[-1] == '1': rule = Rule(this_entity_name + u' jest powiązany z maksymalnie jednym ' + other_entity_name, this_entity_name, other_entity_name) self.rules.append(rule) elif rel.get_other_ends_multiplicity(entity.name_singular)[-1] == 'N': rule = Rule(this_entity_name + u' może być powiązany z wieloma ' + other_entity_name, this_entity_name, other_entity_name) self.rules.append(rule) def populate(self): self._rules_list.clear() if self._entities_combo.value is not None: curr_entity = self._entities_combo.value.name_singular filtered_rules = list(filter(lambda x: curr_entity == x.left_entity_name or curr_entity == x.right_entity_name, self.rules)) for rule in filtered_rules: self._rules_list += [rule.content] # TODO fix indexes, now they are not proper ones def __fix_action(self): entity = self._entities_combo.value entitys_rules = list(filter(lambda r: r.left_entity_name == entity.name_singular or r.right_entity_name == entity.name_singular, self.rules)) index = self._rules_list.selected_row_index if index is not None: win = RuleEditor(rule=entitys_rules[index], rules=self.rules) win.parent = self win.show() def __add_rule_action(self): win = RuleEditor(rules=self.rules, entity=self._entities_combo.value.name_singular) win.parent = self win.show() def __remove_rule_action(self): entity = self._entities_combo.value entitys_rules = list(filter(lambda r: r.left_entity_name == entity.name_singular or r.right_entity_name == entity.name_singular, self.rules)) index = self._rules_list.selected_row_index if index is not None: del entitys_rules[index] self.populate() def __save_action(self): if self._project.stages[4] is None: self.stage = Stage4(self.erd, self.rules) self._project.add_stage(self.stage) Saver.get_saver().save() self.parent.populate_buttons()
class EntityEditor(pyforms.BaseWidget): def __init__(self, erd, entity=None): super(EntityEditor, self).__init__() self.set_margin(10) self.erd = erd if entity is not None: self.entity = self.erd.get_entity_by_name(entity) else: self.entity = Entity('', '', []) self._entity_name_singular = ControlText() self._entity_name_plural = ControlText() self._add_attribute_button = ControlButton(u'Dodaj atrybut') self._edit_attribute_button = ControlButton(u'Edytuj atrybut') self._remove_attribute_button = ControlButton(u'Usuń atrybut') self._attributes_list = ControlList() self._description_edit_text = ControlText() self._is_strong_checkbox = ControlCheckBox( u'Jest silna (brak zaznaczenia - słaba)') self._save_entity_button = ControlButton(u'Zapisz') self._add_attribute_button.value = self.__add_attribute_button_action self._edit_attribute_button.value = self.__edit_attribute_button_action self._remove_attribute_button.value = self.__remove_attribute_action self._save_entity_button.value = self.__save_entity_button_action self._attributes_list.readonly = True self.formset = [ (u'Nazwa encji (liczba pojedyńcza): ', '_entity_name_singular'), (u'Nazwa encji (liczba mnoga):', '_entity_name_plural'), ('Opis encji: ', '_description_edit_text'), ('Atrybuty: ', '_attributes_list', '_add_attribute_button', '_edit_attribute_button', '_remove_attribute_button'), '_is_strong_checkbox', '_save_entity_button' ] self.populate() def populate(self): self._attributes_list.clear() self._entity_name_singular.value = self.entity.name_singular self._entity_name_plural.value = self.entity.name_plural self._description_edit_text.value = self.entity.description self._is_strong_checkbox.value = self.entity.is_strong for attribute in self.entity.attributes: self._attributes_list += [attribute.name] def __add_attribute_button_action(self): self.entity.name_singular = self._entity_name_singular.value self.entity.name_plural = self._entity_name_plural.value self.entity.description = self._description_edit_text.value self.entity.is_strong = self._is_strong_checkbox.value editor = AttributeEditor(self.entity.attributes) editor.parent = self editor.show() def __edit_attribute_button_action(self): self.entity.name_singular = self._entity_name_singular.value self.entity.name_plural = self._entity_name_plural.value self.entity.description = self._description_edit_text.value self.entity.is_strong = self._is_strong_checkbox.value if self._attributes_list.selected_row_index is not None: win = AttributeEditor( self.entity.attributes, self.entity.attributes[ self._attributes_list.selected_row_index]) win.parent = self win.show() def __remove_attribute_action(self): index = self._attributes_list.selected_row_index if index is not None: del self.entity.attributes[index] self.populate() def __save_entity_button_action(self): # TODO fix program crash when attributes_list is empty if self._entity_name_plural.value == '' or self._entity_name_plural.value == '': popup = Popup('Nazwy encji nie mogą być puste') popup.show() else: self.entity.name_singular = self._entity_name_singular.value self.entity.name_plural = self._entity_name_plural.value self.entity.description = self._description_edit_text.value self.entity.is_strong = self._is_strong_checkbox.value if self.erd.get_entity_by_name(self.entity.name_singular) is None: self.erd.entities.append(self.entity) self.parent._populate() Saver.get_saver().save() self.close()
class ErdReader(pyforms.BaseWidget): def __init__(self, erd): super( ErdReader, self, ).__init__('ERD reader') self.set_margin(20) self.erd = erd self._entity_list = ControlList('Encje', "1") self._relationship_list = ControlList('Związki', '1') self._entity_editor = ControlEmptyWidget() self._relationship_editor = ControlEmptyWidget() self._add_entity_button = ControlButton(u'Dodaj encję') self._edit_entity_button = ControlButton(u'Edytuj encję') self._remove_entity_button = ControlButton(u'Usuń encję') self._add_relationship_button = ControlButton(u'Dodaj związek') self._edit_relationship_button = ControlButton(u'Edytuj związek') self._remove_relationship_button = ControlButton(u'Usuń związek') self._add_entity_button.value = self.__add_entity_action self._add_relationship_button.value = self.__add_relationship_action self._edit_entity_button.value = self.__edit_entity_action self._edit_relationship_button.value = self.__edit_relationship_action self._remove_entity_button.value = self.__remove_entity_action self._remove_relationship_button.value = self.__remove_relationship_action self.formset = [ '_entity_list', ('_add_entity_button', '_edit_entity_button', '_remove_entity_button'), '_entity_editor', '_relationship_list', ('_add_relationship_button', '_edit_relationship_button', '_remove_relationship_button'), '_relationship_editor', ] self._entity_list.readonly = True self._entity_list.select_entire_row = True self._relationship_list.readonly = True self._relationship_list.select_entire_row = True self._populate() def _populate(self): self._entity_list.clear() self._relationship_list.clear() for entity in self.erd.entities: self._entity_list += [entity.name_singular, repr(entity)] for relationship in self.erd.relationships: self._relationship_list += [relationship.name, repr(relationship)] def __add_entity_action(self): entity_editor_win = EntityEditor(self.erd) entity_editor_win.parent = self entity_editor_win.show() def __edit_entity_action(self): if self._entity_list.selected_row_index is not None: index = self._entity_list.selected_row_index entity = self._entity_list.get_value(row=index, column=0) entity_editor_win = EntityEditor(self.erd, entity) entity_editor_win.parent = self entity_editor_win.show() def __remove_entity_action(self): indexes = self._entity_list.selected_rows_indexes indexes.sort(reverse=True) for index in indexes: self.erd.remove_entity(index) self._populate() Saver.get_saver().save() def __add_relationship_action(self): relationship_editor_win = RelationshipEditor(self.erd) relationship_editor_win.parent = self relationship_editor_win.show() def __edit_relationship_action(self): if self._relationship_list.selected_row_index is not None: index = self._relationship_list.selected_row_index relationship = self.erd.get_relationship_by_name( self._relationship_list.get_value(row=index, column=0)) win = RelationshipEditor(self.erd, relationship) win.parent = self win.show() def __remove_relationship_action(self): indexes = self._relationship_list.selected_rows_indexes indexes.sort(reverse=True) for index in indexes: self.erd.remove_relationship(index) self._populate() Saver.get_saver().save()