def __init__(self, x, y, controller): super().__init__() self.controller = controller self.x, self.y = x, y self.setWindowTitle('Multiple nodes') nb_nodes = QLabel('Number of nodes') self.nb_nodes_edit = QLineEdit() self.nb_nodes_edit.setMaximumWidth(120) # list of node type node_type = QLabel('Type of node') self.node_subtype_list = QObjectComboBox() self.node_subtype_list.addItems(node_name_to_obj) # confirmation button confirmation_button = QPushButton() confirmation_button.setText('OK') confirmation_button.clicked.connect(self.create_nodes) # cancel button cancel_button = QPushButton() cancel_button.setText('Cancel') # position in the grid layout = QGridLayout() layout.addWidget(nb_nodes, 0, 0, 1, 1) layout.addWidget(self.nb_nodes_edit, 0, 1, 1, 1) layout.addWidget(node_type, 1, 0, 1, 1) layout.addWidget(self.node_subtype_list, 1, 1, 1, 1) layout.addWidget(confirmation_button, 2, 0, 1, 1) layout.addWidget(cancel_button, 2, 1, 1, 1) self.setLayout(layout)
def __init__(self, graph_type, controller): super().__init__() self.controller = controller self.graph_type = graph_type self.setWindowTitle('Graph generation') layout = QGridLayout() self.node_subtype_list = QObjectComboBox() self.node_subtype_list.addItems(node_name_to_obj) number_of_nodes = QLabel('Nodes') self.nodes_edit = QLineEdit() self.nodes_edit.setMaximumWidth(120) if graph_type in ('kneser', 'petersen'): number_of_subset = QLabel('Subsets') self.subset_edit = QLineEdit() self.subset_edit.setMaximumWidth(120) # confirmation button confirmation_button = QPushButton(self) confirmation_button.setText('OK') confirmation_button.clicked.connect(self.confirm) layout.addWidget(self.node_subtype_list, 0, 0, 1, 2) layout.addWidget(number_of_nodes, 1, 0, 1, 1) layout.addWidget(self.nodes_edit, 1, 1, 1, 1) if graph_type in ('kneser', 'petersen'): layout.addWidget(number_of_subset, 2, 0, 1, 1) layout.addWidget(self.subset_edit, 2, 1, 1, 1) layout.addWidget(confirmation_button, 3, 0, 1, 2) self.setLayout(layout)
class GraphDimensionWindow(QWidget): def __init__(self, graph_type, controller): super().__init__() self.controller = controller self.graph_type = graph_type self.setWindowTitle('Graph generation') layout = QGridLayout() self.node_subtype_list = QObjectComboBox() self.node_subtype_list.addItems(node_name_to_obj) number_of_nodes = QLabel('Nodes') self.nodes_edit = QLineEdit() self.nodes_edit.setMaximumWidth(120) if graph_type in ('kneser', 'petersen'): number_of_subset = QLabel('Subsets') self.subset_edit = QLineEdit() self.subset_edit.setMaximumWidth(120) # confirmation button confirmation_button = QPushButton(self) confirmation_button.setText('OK') confirmation_button.clicked.connect(self.confirm) layout.addWidget(self.node_subtype_list, 0, 0, 1, 2) layout.addWidget(number_of_nodes, 1, 0, 1, 1) layout.addWidget(self.nodes_edit, 1, 1, 1, 1) if graph_type in ('kneser', 'petersen'): layout.addWidget(number_of_subset, 2, 0, 1, 1) layout.addWidget(self.subset_edit, 2, 1, 1, 1) layout.addWidget(confirmation_button, 3, 0, 1, 2) self.setLayout(layout) @update_paths def confirm(self, _): nodes = int(self.nodes_edit.text()) - 1 subtype = node_name_to_obj[self.node_subtype_list.currentText()] if self.graph_type in ('kneser', 'petersen'): subset = int(self.subset_edit.text()) function = { 'kneser': self.network.kneser, 'petersen': self.network.petersen }[self.graph_type] objects = function(nodes, subset, subtype) else: function = { 'star': self.network.star, 'ring': self.network.ring, 'full-mesh': self.network.full_mesh, 'tree': self.network.tree, 'square-tiling': self.network.square_tiling, 'hypercube': self.network.hypercube, }[self.graph_type] objects = function(nodes, subtype) self.view.draw_objects(*objects) self.close() # we close the graph generation window as well, as we usually don't # need to create two graphs in a row self.controller.graph_generation_window.hide()
class ASCreation(QWidget): @update_paths def __init__(self, nodes, links, controller): super().__init__() self.controller = controller self.nodes = nodes self.links = links self.setWindowTitle('Create AS') # AS type AS_type = QLabel('Type') self.AS_type_list = QObjectComboBox() self.AS_type_list.addItems(AS_subtypes) # AS name AS_name = QLabel('Name') self.name_edit = QLineEdit() self.name_edit.setMaximumWidth(120) # AS ID AS_id = QLabel('ID') self.id_edit = QLineEdit() self.id_edit.setMaximumWidth(120) # confirmation button button_create_AS = QPushButton() button_create_AS.setText('Create AS') button_create_AS.clicked.connect(self.create_AS) # cancel button cancel_button = QPushButton() cancel_button.setText('Cancel') # position in the grid layout = QGridLayout() layout.addWidget(AS_type, 0, 0, 1, 1) layout.addWidget(self.AS_type_list, 0, 1, 1, 1) layout.addWidget(AS_name, 1, 0, 1, 1) layout.addWidget(self.name_edit, 1, 1, 1, 1) layout.addWidget(AS_id, 2, 0, 1, 1) layout.addWidget(self.id_edit, 2, 1, 1, 1) layout.addWidget(button_create_AS, 3, 0, 1, 1) layout.addWidget(cancel_button, 3, 1, 1, 1) self.setLayout(layout) def create_AS(self): # automatic initialization of the AS id in case it is empty id = self.id_edit.text() id = int(id) if id else len(self.network.pnAS) + 1 new_AS = self.network.AS_factory( self.AS_type_list.text, self.name_edit.text(), id, self.links, self.nodes ) self.close()
class MultipleNodes(QWidget): def __init__(self, x, y, controller): super().__init__() self.controller = controller self.x, self.y = x, y self.setWindowTitle('Multiple nodes') nb_nodes = QLabel('Number of nodes') self.nb_nodes_edit = QLineEdit() self.nb_nodes_edit.setMaximumWidth(120) # list of node type node_type = QLabel('Type of node') self.node_subtype_list = QObjectComboBox() self.node_subtype_list.addItems(node_name_to_obj) # confirmation button confirmation_button = QPushButton() confirmation_button.setText('OK') confirmation_button.clicked.connect(self.create_nodes) # cancel button cancel_button = QPushButton() cancel_button.setText('Cancel') # position in the grid layout = QGridLayout() layout.addWidget(nb_nodes, 0, 0, 1, 1) layout.addWidget(self.nb_nodes_edit, 0, 1, 1, 1) layout.addWidget(node_type, 1, 0, 1, 1) layout.addWidget(self.node_subtype_list, 1, 1, 1, 1) layout.addWidget(confirmation_button, 2, 0, 1, 1) layout.addWidget(cancel_button, 2, 1, 1, 1) self.setLayout(layout) @update_paths def create_nodes(self, _): nb_nodes = int(self.nb_nodes_edit.text()) subtype = node_name_to_obj[self.node_subtype_list.currentText()] self.view.draw_objects(*self.network.multiple_nodes(nb_nodes, subtype)) self.close()
def __init__(self, nodes, links, controller): super().__init__() self.controller = controller self.nodes = nodes self.links = links self.setWindowTitle('Create AS') # AS type AS_type = QLabel('Type') self.AS_type_list = QObjectComboBox() self.AS_type_list.addItems(AS_subtypes) # AS name AS_name = QLabel('Name') self.name_edit = QLineEdit() self.name_edit.setMaximumWidth(120) # AS ID AS_id = QLabel('ID') self.id_edit = QLineEdit() self.id_edit.setMaximumWidth(120) # confirmation button button_create_AS = QPushButton() button_create_AS.setText('Create AS') button_create_AS.clicked.connect(self.create_AS) # cancel button cancel_button = QPushButton() cancel_button.setText('Cancel') # position in the grid layout = QGridLayout() layout.addWidget(AS_type, 0, 0, 1, 1) layout.addWidget(self.AS_type_list, 0, 1, 1, 1) layout.addWidget(AS_name, 1, 0, 1, 1) layout.addWidget(self.name_edit, 1, 1, 1, 1) layout.addWidget(AS_id, 2, 0, 1, 1) layout.addWidget(self.id_edit, 2, 1, 1, 1) layout.addWidget(button_create_AS, 3, 0, 1, 1) layout.addWidget(cancel_button, 3, 1, 1, 1) self.setLayout(layout)
def __init__(self, obj, controller): super().__init__() self.setWindowTitle('Properties') self.current_obj = obj # dictionnary containing all global properties entries / combobox self.dict_global_properties = {} # dictionnary containing all per-AS properties self.dict_perAS_properties = {} # global properties global_properties = QGroupBox('Global properties') global_properties_layout = QGridLayout(global_properties) for index, property in enumerate(object_properties[obj.subtype]): # too much trouble handling interfaces here if property.name in ('interfaceS', 'interfaceD'): continue # creation of the label associated to the property label = QLabel(property.pretty_name) # value of the property: drop-down list or entry if property.multiple_values and property.choose_one_value: pvalue = QObjectComboBox() pvalue.addItems(property.values) elif property.subtype == 'dict': pvalue = QDictTreeView() else: # s = 'readonly' if property in self.read_only else 'normal' pvalue = QLineEdit() if property.hide_view: pvalue.setEchoMode(QLineEdit.Password) self.dict_global_properties[property] = pvalue global_properties_layout.addWidget(label, index + 1, 0, 1, 1) global_properties_layout.addWidget(pvalue, index + 1, 1, 1, 1) if obj.subtype in self.perAS_properties: # global properties perAS_properties = QGroupBox('Per-AS properties') perAS_properties_layout = QGridLayout(perAS_properties) self.dict_perAS_properties = {} # AS combobox self.AS_list = QComboBox() self.AS_list.addItems(obj.AS) self.AS_list.activated.connect(self.update_AS_properties) for index, property in enumerate(perAS_properties[obj.subtype]): # creation of the label associated to the property label = QLabel(property.pretty_name) pvalue = QLineEdit() self.dict_perAS_properties[property] = pvalue perAS_properties_layout.addWidget(label, index + 1, 0) perAS_properties_layout.addWidget(pvalue, index + 1, 1) # update all properties with the selected object properties self.update() layout = QGridLayout() layout.addWidget(global_properties, 0, 0) if obj.subtype in self.perAS_properties: layout.addWidget(perAS_properties, 1, 0) self.setLayout(layout)