def __init__(self, ios_routers, parent): QtGui.QWizard.__init__(self, parent) self.setupUi(self) self.setPixmap(QtGui.QWizard.LogoPixmap, QtGui.QPixmap(":/symbols/router.normal.svg")) self.setWizardStyle(QtGui.QWizard.ModernStyle) if sys.platform.startswith("darwin"): # we want to see the cancel button on OSX self.setOptions(QtGui.QWizard.NoDefaultButton) self.uiRemoteRadioButton.toggled.connect(self._remoteServerToggledSlot) self.uiLoadBalanceCheckBox.toggled.connect(self._loadBalanceToggledSlot) self.uiIOSImageToolButton.clicked.connect(self._iosImageBrowserSlot) self.uiTestIOSImagePushButton.clicked.connect(self._testIOSImageSlot) self.uiIdlePCFinderPushButton.clicked.connect(self._idlePCFinderSlot) self.uiEtherSwitchCheckBox.stateChanged.connect(self._etherSwitchSlot) self.uiPlatformComboBox.currentIndexChanged[str].connect(self._platformChangedSlot) self.uiPlatformComboBox.addItems(list(PLATFORMS_DEFAULT_RAM.keys())) self._router = None # Validate the Idle PC value self._idle_valid = False idle_pc_rgx = QtCore.QRegExp("^(0x[0-9a-fA-F]{8})?$") validator = QtGui.QRegExpValidator(idle_pc_rgx, self) self.uiIdlepcLineEdit.setValidator(validator) self.uiIdlepcLineEdit.textChanged.connect(self._idlePCValidateSlot) self.uiIdlepcLineEdit.textChanged.emit(self.uiIdlepcLineEdit.text()) # location of the base config templates self._base_startup_config_template = get_resource(os.path.join("configs", "ios_base_startup-config.txt")) self._base_private_config_template = get_resource(os.path.join("configs", "ios_base_private-config.txt")) self._base_etherswitch_startup_config_template = get_resource(os.path.join("configs", "ios_etherswitch_startup-config.txt")) # FIXME: hide because of issue on Windows. self.uiTestIOSImagePushButton.hide() # Mandatory fields self.uiNamePlatformWizardPage.registerField("name*", self.uiNameLineEdit) self.uiIOSImageWizardPage.registerField("image*", self.uiIOSImageLineEdit) self._widget_slots = {0: self.uiSlot0comboBox, 1: self.uiSlot1comboBox, 2: self.uiSlot2comboBox, 3: self.uiSlot3comboBox, 4: self.uiSlot4comboBox, 5: self.uiSlot5comboBox, 6: self.uiSlot6comboBox} self._widget_wics = {0: self.uiWic0comboBox, 1: self.uiWic1comboBox, 2: self.uiWic2comboBox} self._ios_routers = ios_routers if Dynamips.instance().settings()["use_local_server"]: # skip the server page if we use the local server self.setStartId(1) if not ENABLE_CLOUD: self.uiCloudRadioButton.hide()
def __init__(self, parent): super().__init__(parent) self.setupUi(self) self.setWizardStyle(QtWidgets.QWizard.ModernStyle) if sys.platform.startswith("darwin"): # we want to see the cancel button on OSX self.setOptions(QtWidgets.QWizard.NoDefaultButton) self._server = Servers.instance().localServer() self.uiGNS3VMDownloadLinkUrlLabel.setText('') self.uiRefreshPushButton.clicked.connect(self._refreshVMListSlot) self.uiVmwareRadioButton.clicked.connect(self._listVMwareVMsSlot) self.uiVirtualBoxRadioButton.clicked.connect(self._listVirtualBoxVMsSlot) self.uiVMwareBannerButton.clicked.connect(self._VMwareBannerButtonClickedSlot) settings = parent.settings() self.uiShowCheckBox.setChecked(settings["hide_setup_wizard"]) # by default all radio buttons are unchecked self.uiVmwareRadioButton.setAutoExclusive(False) self.uiVirtualBoxRadioButton.setAutoExclusive(False) self.uiVmwareRadioButton.setChecked(False) self.uiVirtualBoxRadioButton.setChecked(False) if sys.platform.startswith("darwin"): self.uiVMwareBannerButton.setIcon(QtGui.QIcon(":/images/vmware_fusion_banner.jpg")) else: self.uiVMwareBannerButton.setIcon(QtGui.QIcon(":/images/vmware_workstation_banner.jpg"))
def _refreshInfo(self, iou_device): self.uiIOUDeviceInfoTreeWidget.clear() # fill out the General section section_item = self._createSectionItem("General") QtGui.QTreeWidgetItem(section_item, ["Name:", iou_device["name"]]) QtGui.QTreeWidgetItem(section_item, ["Server:", iou_device["server"]]) QtGui.QTreeWidgetItem(section_item, ["Image:", iou_device["image"]]) if iou_device["initial_config"]: QtGui.QTreeWidgetItem(section_item, ["Initial config:", iou_device["initial_config"]]) if iou_device["use_default_iou_values"]: QtGui.QTreeWidgetItem(section_item, ["RAM:", "default"]) QtGui.QTreeWidgetItem(section_item, ["NVRAM:", "default"]) else: QtGui.QTreeWidgetItem(section_item, ["RAM:", "{} MiB".format(iou_device["ram"])]) QtGui.QTreeWidgetItem(section_item, ["NVRAM:", "{} KiB".format(iou_device["nvram"])]) # fill out the Network section section_item = self._createSectionItem("Network") QtGui.QTreeWidgetItem(section_item, ["Ethernet adapters:", "{} ({} interfaces)".format(iou_device["ethernet_adapters"], iou_device["ethernet_adapters"] * 4)]) QtGui.QTreeWidgetItem(section_item, ["Serial adapters:", "{} ({} interfaces)".format(iou_device["serial_adapters"], iou_device["serial_adapters"] * 4)]) self.uiIOUDeviceInfoTreeWidget.expandAll() self.uiIOUDeviceInfoTreeWidget.resizeColumnToContents(0) self.uiIOUDeviceInfoTreeWidget.resizeColumnToContents(1)
def _qemuVMNewSlot(self): """ Creates a new VM. """ wizard = QemuVMWizard(self._qemu_vms, parent=self) wizard.show() if wizard.exec_(): new_vm_settings = wizard.getSettings() key = "{server}:{name}".format(server=new_vm_settings["server"], name=new_vm_settings["name"]) if key in self._qemu_vms: QtGui.QMessageBox.critical( self, "New QEMU VM", "VM name {} already exists".format( new_vm_settings["name"])) return self._qemu_vms[key] = QEMU_VM_SETTINGS.copy() self._qemu_vms[key].update(new_vm_settings) item = QtGui.QTreeWidgetItem(self.uiQemuVMsTreeWidget) item.setText(0, self._qemu_vms[key]["name"]) item.setIcon(0, QtGui.QIcon(self._qemu_vms[key]["default_symbol"])) item.setData(0, QtCore.Qt.UserRole, key) self._items.append(item) self.uiQemuVMsTreeWidget.setCurrentItem(item) if self._qemu_vms[key]["server"] == 'cloud': self._qemu_vms[key]["options"] = "-nographic" self._uploadImages(new_vm_settings)
def _populateGraphicsViewSettingWidgets(self, settings): """ Populates the widgets with the settings. :param settings: Graphics view settings """ self.uiSceneWidthSpinBox.setValue(settings["scene_width"]) self.uiSceneHeightSpinBox.setValue(settings["scene_height"]) self.uiNodeGridSizeSpinBox.setValue(settings["grid_size"]) self.uiDrawingGridSizeSpinBox.setValue(settings["drawing_grid_size"]) self.uiRectangleSelectedItemCheckBox.setChecked(settings["draw_rectangle_selected_item"]) self.uiDrawLinkStatusPointsCheckBox.setChecked(settings["draw_link_status_points"]) self.uiShowInterfaceLabelsOnNewProject.setChecked(settings["show_interface_labels_on_new_project"]) self.uiLimitSizeNodeSymbolCheckBox.setChecked(settings["limit_size_node_symbols"]) self.uiShowGridOnNewProject.setChecked(settings["show_grid_on_new_project"]) self.uiSnapToGridOnNewProject.setChecked(settings["snap_to_grid_on_new_project"]) qt_font = QtGui.QFont() if qt_font.fromString(settings["default_label_font"]): self.uiDefaultLabelStylePlainTextEdit.setFont(qt_font) qt_color = QtGui.QColor(settings["default_label_color"]) if qt_color.isValid(): self._default_label_color = qt_color self.uiDefaultLabelStylePlainTextEdit.setStyleSheet("color : {}".format(qt_color.name())) qt_font = QtGui.QFont() if qt_font.fromString(settings["default_note_font"]): self.uiDefaultNoteStylePlainTextEdit.setFont(qt_font) qt_color = QtGui.QColor(settings["default_note_color"]) if qt_color.isValid(): self._default_note_color = qt_color self.uiDefaultNoteStylePlainTextEdit.setStyleSheet("color : {}".format(qt_color.name()))
def __init__(self, ios_routers, parent): super().__init__(ios_routers, Dynamips.instance().settings()["use_local_server"], parent) self.setPixmap(QtWidgets.QWizard.LogoPixmap, QtGui.QPixmap(":/symbols/router.svg")) self.uiTestIOSImagePushButton.clicked.connect(self._testIOSImageSlot) self.uiIdlePCFinderPushButton.clicked.connect(self._idlePCFinderSlot) self.uiEtherSwitchCheckBox.stateChanged.connect(self._etherSwitchSlot) self.uiPlatformComboBox.currentIndexChanged[str].connect( self._platformChangedSlot) self.uiPlatformComboBox.addItems(list(PLATFORMS_DEFAULT_RAM.keys())) self._router = None # Validate the Idle PC value self._idle_valid = False idle_pc_rgx = QtCore.QRegExp("^(0x[0-9a-fA-F]{8})?$") validator = QtGui.QRegExpValidator(idle_pc_rgx, self) self.uiIdlepcLineEdit.setValidator(validator) self.uiIdlepcLineEdit.textChanged.connect(self._idlePCValidateSlot) self.uiIdlepcLineEdit.textChanged.emit(self.uiIdlepcLineEdit.text()) # location of the base config templates self._base_startup_config_template = get_resource( os.path.join("configs", "ios_base_startup-config.txt")) self._base_etherswitch_startup_config_template = get_resource( os.path.join("configs", "ios_etherswitch_startup-config.txt")) # FIXME: hide because of issue on Windows. self.uiTestIOSImagePushButton.hide() # Mandatory fields self.uiNameWizardPage.registerField("name*", self.uiNameLineEdit) self.uiIOSImageWizardPage.registerField("image*", self.uiIOSImageLineEdit) self._widget_slots = { 0: self.uiSlot0comboBox, 1: self.uiSlot1comboBox, 2: self.uiSlot2comboBox, 3: self.uiSlot3comboBox, 4: self.uiSlot4comboBox, 5: self.uiSlot5comboBox, 6: self.uiSlot6comboBox } self._widget_wics = { 0: self.uiWic0comboBox, 1: self.uiWic1comboBox, 2: self.uiWic2comboBox } from ..pages.ios_router_preferences_page import IOSRouterPreferencesPage self.addImageSelector(self.uiIOSExistingImageRadioButton, self.uiIOSImageListComboBox, self.uiIOSImageLineEdit, self.uiIOSImageToolButton, IOSRouterPreferencesPage.getIOSImage)
def _typeChangedSlot(self, vm_type): """ When the type of QEMU VM is changed. :param vm_type: type of VM """ if vm_type == "IOSv": self.setPixmap(QtGui.QWizard.LogoPixmap, QtGui.QPixmap(":/symbols/iosv_virl.normal.svg")) self.uiNameLineEdit.setText("vIOS") self.uiHdaDiskImageLabel.setText("IOSv VDMK file:") elif vm_type == "IOSv-L2": self.setPixmap(QtGui.QWizard.LogoPixmap, QtGui.QPixmap(":/symbols/iosv_l2_virl.normal.svg")) self.uiNameLineEdit.setText("vIOS-L2") self.uiHdaDiskImageLabel.setText("IOSv-L2 VDMK file:") elif vm_type == "ASA 8.4(2)": self.setPixmap(QtGui.QWizard.LogoPixmap, QtGui.QPixmap(":/symbols/asa.normal.svg")) self.uiNameLineEdit.setText("ASA") elif vm_type == "IDS": self.setPixmap(QtGui.QWizard.LogoPixmap, QtGui.QPixmap(":/symbols/ids.normal.svg")) self.uiNameLineEdit.setText("IDS") self.uiHdaDiskImageLabel.setText("Disk image (hda):") else: self.setPixmap(QtGui.QWizard.LogoPixmap, QtGui.QPixmap(":/icons/qemu.svg")) self.uiHdaDiskImageLabel.setText("Disk image (hda):") self.uiNameLineEdit.setText("")
def _getStyleIcon(self, normal_file, active_file): icon = QtGui.QIcon() icon.addPixmap(QtGui.QPixmap(normal_file), QtGui.QIcon.Normal, QtGui.QIcon.Off) icon.addPixmap(QtGui.QPixmap(active_file), QtGui.QIcon.Active, QtGui.QIcon.Off) return icon
def _iouDeviceNewSlot(self): """ Creates a new IOU device. """ wizard = IOUDeviceWizard(self._iou_devices, parent=self) wizard.show() if wizard.exec_(): new_device_settings = wizard.getSettings() key = "{server}:{name}".format( server=new_device_settings["server"], name=new_device_settings["name"]) self._iou_devices[key] = IOU_DEVICE_SETTINGS.copy() self._iou_devices[key].update(new_device_settings) item = QtGui.QTreeWidgetItem(self.uiIOUDevicesTreeWidget) item.setText(0, self._iou_devices[key]["name"]) item.setIcon(0, QtGui.QIcon(self._iou_devices[key]["default_symbol"])) item.setData(0, QtCore.Qt.UserRole, key) self._items.append(item) self.uiIOUDevicesTreeWidget.setCurrentItem(item) if new_device_settings["server"] == 'cloud': import logging log = logging.getLogger(__name__) # Start uploading the image to cloud files self._upload_image_progress_dialog = QtGui.QProgressDialog( "Uploading image file {}".format( new_device_settings['image']), "Cancel", 0, 0, parent=self) self._upload_image_progress_dialog.setWindowModality( QtCore.Qt.WindowModal) self._upload_image_progress_dialog.setWindowTitle( "IOU image upload") self._upload_image_progress_dialog.show() try: src = self._iou_devices[key]['path'] # Eg: images/IOU/i86.bin dst = 'images/IOU/{}'.format( self._iou_devices[key]['image']) upload_thread = UploadFilesThread( self, MainWindow.instance().cloudSettings(), [(src, dst)]) upload_thread.completed.connect(self._imageUploadComplete) upload_thread.start() except Exception as e: self._upload_image_progress_dialog.reject() log.error(e) QtGui.QMessageBox.critical( self, "IOU image upload", "Error uploading IOU image: {}".format(e))
def _refreshInfo(self, vbox_vm): self.uiVirtualBoxVMInfoTreeWidget.clear() # fill out the General section section_item = self._createSectionItem("General") QtGui.QTreeWidgetItem(section_item, ["VM name:", vbox_vm["vmname"]]) QtGui.QTreeWidgetItem(section_item, ["RAM:", str(vbox_vm["ram"])]) QtGui.QTreeWidgetItem(section_item, ["Server:", vbox_vm["server"]]) QtGui.QTreeWidgetItem(section_item, [ "Remote console enabled:", "{}".format( vbox_vm["enable_remote_console"]) ]) QtGui.QTreeWidgetItem( section_item, ["Headless mode enabled:", "{}".format(vbox_vm["headless"])]) QtGui.QTreeWidgetItem( section_item, ["Linked base VM:", "{}".format(vbox_vm["linked_base"])]) # fill out the Network section section_item = self._createSectionItem("Network") QtGui.QTreeWidgetItem( section_item, ["Adapters:", str(vbox_vm["adapters"])]) QtGui.QTreeWidgetItem( section_item, ["Use any adapter:", "{}".format(vbox_vm["use_any_adapter"])]) QtGui.QTreeWidgetItem(section_item, ["Type:", vbox_vm["adapter_type"]]) self.uiVirtualBoxVMInfoTreeWidget.expandAll() self.uiVirtualBoxVMInfoTreeWidget.resizeColumnToContents(0) self.uiVirtualBoxVMInfoTreeWidget.resizeColumnToContents(1)
def _showContextualMenu(self): """ Contextual menu. """ menu = QtGui.QMenu() change_symbol_action = QtGui.QAction("Change symbol", menu) change_symbol_action.setIcon(QtGui.QIcon(":/icons/node_conception.svg")) self.connect(change_symbol_action, QtCore.SIGNAL('triggered()'), self._changeSymbolSlot) menu.addAction(change_symbol_action) menu.exec_(QtGui.QCursor.pos())
def _typeChangedSlot(self, image_type): """ When the type of IOU device is changed. :param image_type: type of image (L2 or L3) """ if image_type == "L2 image": # L2 image self.setPixmap(QtWidgets.QWizard.LogoPixmap, QtGui.QPixmap(":/symbols/multilayer_switch.svg")) else: # L3 image self.setPixmap(QtWidgets.QWizard.LogoPixmap, QtGui.QPixmap(":/symbols/router.svg"))
def setClassicStyle(self): """ Sets the classic GUI style. """ self._mw.setStyleSheet("") self._mw.uiNewProjectAction.setIcon(self._getStyleIcon(":/classic_icons/new-project.svg", ":/classic_icons/new-project-hover.svg")) self._mw.uiOpenProjectAction.setIcon(self._getStyleIcon(":/classic_icons/open.svg", ":/classic_icons/open-hover.svg")) self._mw.uiOpenApplianceAction.setIcon(self._getStyleIcon(":/classic_icons/open.svg", ":/classic_icons/open-hover.svg")) self._mw.uiNewTemplateAction.setIcon(self._getStyleIcon(":/classic_icons/plus.svg", ":/classic_icons/plus-hover.svg")) self._mw.uiSaveProjectAsAction.setIcon(self._getStyleIcon(":/classic_icons/save-as-project.svg", ":/classic_icons/save-as-project-hover.svg")) self._mw.uiEditProjectAction.setIcon(self._getStyleIcon(":/classic_icons/edit.svg", ":/classic_icons/edit-hover.svg")) self._mw.uiImportExportConfigsAction.setIcon(self._getStyleIcon(":/classic_icons/import_export_configs.svg", ":/classic_icons/import_export_configs-hover.svg")) self._mw.uiImportProjectAction.setIcon(self._getStyleIcon(":/classic_icons/import.svg", ":/classic_icons/import-hover.svg")) self._mw.uiExportProjectAction.setIcon(self._getStyleIcon(":/classic_icons/export.svg", ":/classic_icons/export-hover.svg")) self._mw.uiDeleteProjectAction.setIcon(self._getStyleIcon(":/classic_icons/delete.svg", ":/classic_icons/delete-hover.svg")) self._mw.uiScreenshotAction.setIcon(self._getStyleIcon(":/classic_icons/camera-photo.svg", ":/classic_icons/camera-photo-hover.svg")) self._mw.uiSnapshotAction.setIcon(self._getStyleIcon(":/classic_icons/snapshot.svg", ":/classic_icons/snapshot-hover.svg")) self._mw.uiQuitAction.setIcon(self._getStyleIcon(":/classic_icons/quit.svg", ":/classic_icons/quit-hover.svg")) self._mw.uiPreferencesAction.setIcon(self._getStyleIcon(":/classic_icons/preferences.svg", ":/classic_icons/preferences-hover.svg")) self._mw.uiZoomInAction.setIcon(self._getStyleIcon(":/classic_icons/zoom-in.svg", ":/classic_icons/zoom-in-hover.svg")) self._mw.uiZoomOutAction.setIcon(self._getStyleIcon(":/classic_icons/zoom-out.svg", ":/classic_icons/zoom-out-hover.svg")) self._mw.uiShowPortNamesAction.setIcon(self._getStyleIcon(":/classic_icons/show-interface-names.svg", ":/classic_icons/show-interface-names-hover.svg")) self._mw.uiStartAllAction.setIcon(self._getStyleIcon(":/classic_icons/start.svg", ":/classic_icons/start-hover.svg")) self._mw.uiSuspendAllAction.setIcon(self._getStyleIcon(":/classic_icons/pause.svg", ":/classic_icons/pause-hover.svg")) self._mw.uiStopAllAction.setIcon(self._getStyleIcon(":/classic_icons/stop.svg", ":/classic_icons/stop-hover.svg")) self._mw.uiReloadAllAction.setIcon(self._getStyleIcon(":/classic_icons/reload.svg", ":/classic_icons/reload-hover.svg")) self._mw.uiAuxConsoleAllAction.setIcon(self._getStyleIcon(":/classic_icons/aux-console.svg", ":/classic_icons/aux-console-hover.svg")) self._mw.uiConsoleAllAction.setIcon(self._getStyleIcon(":/classic_icons/console.svg", ":/classic_icons/console-hover.svg")) self._mw.uiAddNoteAction.setIcon(self._getStyleIcon(":/classic_icons/add-note.svg", ":/classic_icons/add-note-hover.svg")) self._mw.uiInsertImageAction.setIcon(self._getStyleIcon(":/classic_icons/image.svg", ":/classic_icons/image-hover.svg")) self._mw.uiDrawRectangleAction.setIcon(self._getStyleIcon(":/classic_icons/rectangle.svg", ":/classic_icons/rectangle-hover.svg")) self._mw.uiDrawEllipseAction.setIcon(self._getStyleIcon(":/classic_icons/ellipse.svg", ":/classic_icons/ellipse-hover.svg")) self._mw.uiDrawLineAction.setIcon(self._getStyleIcon(":/classic_icons/line.svg", ":/classic_icons/line-hover.svg")) self._mw.uiEditReadmeAction.setIcon(self._getStyleIcon(":/classic_icons/edit.svg", ":/classic_icons/edit-hover.svg")) self._mw.uiOnlineHelpAction.setIcon(self._getStyleIcon(":/classic_icons/help.svg", ":/classic_icons/help-hover.svg")) self._mw.uiBrowseRoutersAction.setIcon(self._getStyleIcon(":/classic_icons/router.svg", ":/classic_icons/router-hover.svg")) self._mw.uiBrowseSwitchesAction.setIcon(self._getStyleIcon(":/classic_icons/switch.svg", ":/classic_icons/switch-hover.svg")) self._mw.uiBrowseEndDevicesAction.setIcon(self._getStyleIcon(":/classic_icons/pc.svg", ":/classic_icons/pc-hover.svg")) self._mw.uiBrowseSecurityDevicesAction.setIcon(self._getStyleIcon(":/classic_icons/firewall.svg", ":/classic_icons/firewall-hover.svg")) self._mw.uiBrowseAllDevicesAction.setIcon(self._getStyleIcon(":/classic_icons/browse-all-icons.svg", ":/classic_icons/browse-all-icons-hover.svg")) icon = QtGui.QIcon() icon.addPixmap(QtGui.QPixmap(":/classic_icons/add-link.svg"), QtGui.QIcon.Normal, QtGui.QIcon.Off) icon.addPixmap(QtGui.QPixmap(":/classic_icons/add-link-hover.svg"), QtGui.QIcon.Active, QtGui.QIcon.Off) icon.addPixmap(QtGui.QPixmap(":/classic_icons/add-link-cancel.svg"), QtGui.QIcon.Normal, QtGui.QIcon.On) self._mw.uiAddLinkAction.setIcon(icon) # Lock action has 4 different icons icon = QtGui.QIcon() icon.addPixmap(QtGui.QPixmap(":/classic_icons/lock.svg"), QtGui.QIcon.Normal, QtGui.QIcon.On) icon.addPixmap(QtGui.QPixmap(":/classic_icons/lock-hover.svg"), QtGui.QIcon.Active, QtGui.QIcon.On) icon.addPixmap(QtGui.QPixmap(":/classic_icons/unlock.svg"), QtGui.QIcon.Normal, QtGui.QIcon.Off) icon.addPixmap(QtGui.QPixmap(":/classic_icons/unlock-hover.svg"), QtGui.QIcon.Active, QtGui.QIcon.Off) self._mw.uiLockAllAction.setIcon(icon)
def _remoteServerAddSlot(self): """ Adds a new remote server. """ if len(self._remote_servers) == 1: QtGui.QMessageBox.critical( self, "Remote server", "Sorry we do not support multiple remote servers yet!") return host = self.uiRemoteServerPortLineEdit.text() port = self.uiRemoteServerPortSpinBox.value() # check if the remote server is already defined remote_server = "{host}:{port}".format(host=host, port=port) if remote_server in self._remote_servers: QtGui.QMessageBox.critical( self, "Remote server", "Remote server {} is already defined.".format(remote_server)) return # add a new entry in the tree widget item = QtGui.QTreeWidgetItem(self.uiRemoteServersTreeWidget) item.setText(0, host) item.setText(1, str(port)) # keep track of this remote server self._remote_servers[remote_server] = {"host": host, "port": port} self.uiRemoteServerPortSpinBox.setValue( self.uiRemoteServerPortSpinBox.value() + 1) self.uiRemoteServersTreeWidget.resizeColumnToContents(0)
def __init__(self, parent=None): QtGui.QWidget.__init__(self) self.setupUi(self) self._remote_servers = {} self._preferences_dialog = parent # Load the pre-configured console commands for name, cmd in sorted(PRECONFIGURED_TELNET_CONSOLE_COMMANDS.items()): self.uiTelnetConsolePreconfiguredCommandComboBox.addItem(name, cmd) for name, cmd in sorted(PRECONFIGURED_SERIAL_CONSOLE_COMMANDS.items()): self.uiSerialConsolePreconfiguredCommandComboBox.addItem(name, cmd) # Display the path of the config file config_file_path = LocalConfig.instance().configFilePath() self.uiConfigurationFileLabel.setText(config_file_path) self.uiProjectsPathToolButton.clicked.connect(self._projectsPathSlot) self.uiImagesPathToolButton.clicked.connect(self._imagesPathSlot) self.uiImportConfigurationFilePushButton.clicked.connect( self._importConfigurationFileSlot) self.uiExportConfigurationFilePushButton.clicked.connect( self._exportConfigurationFileSlot) self.uiRestoreDefaultsPushButton.clicked.connect( self._restoreDefaultsSlot) self.uiTelnetConsolePreconfiguredCommandPushButton.clicked.connect( self._telnetConsolePreconfiguredCommandSlot) self.uiSerialConsolePreconfiguredCommandPushButton.clicked.connect( self._serialConsolePreconfiguredCommandSlot) self.uiDefaultLabelFontPushButton.clicked.connect( self._setDefaultLabelFontSlot) self.uiDefaultLabelColorPushButton.clicked.connect( self._setDefaultLabelColorSlot) self._default_label_color = QtGui.QColor(QtCore.Qt.black) self.uiStyleComboBox.addItems(STYLES)
def test_dump(): note = NoteItem() note.setPlainText("Test") font = QtGui.QFont() font.setPointSize(55) font.setFamily("Verdana") font.setBold(True) font.setItalic(True) font.setUnderline(True) font.setStrikeOut(True) note.setFont(font) note.setDefaultTextColor(QtCore.Qt.red) assert note.dump() == { "text": "Test", "x": 0, "y": 0, "rotation": 0, "style": "font-family: Verdana;font-size: 55;font-style: italic;font-weight: bold;text-decoration: line-through;fill: #ff0000;fill-opacity: 1.0;" }
def __init__(self, vpcs_nodes, parent): super().__init__(vpcs_nodes, parent) self.setPixmap(QtWidgets.QWizard.LogoPixmap, QtGui.QPixmap(":/symbols/vpcs_guest.svg")) self.uiNameWizardPage.registerField("name*", self.uiNameLineEdit)
def __init__(self, parent=None): super().__init__() self.setupUi(self) self._remote_servers = {} self._preferences_dialog = parent # Display the path of the config file config_file_path = LocalConfig.instance().configFilePath() self.uiConfigurationFileLabel.setText(config_file_path) self.uiProjectsPathToolButton.clicked.connect(self._projectsPathSlot) self.uiSymbolsPathToolButton.clicked.connect(self._symbolsPathSlot) self.uiImagesPathToolButton.clicked.connect(self._imagesPathSlot) self.uiConfigsPathToolButton.clicked.connect(self._configsPathSlot) self.uiImportConfigurationFilePushButton.clicked.connect( self._importConfigurationFileSlot) self.uiExportConfigurationFilePushButton.clicked.connect( self._exportConfigurationFileSlot) self.uiRestoreDefaultsPushButton.clicked.connect( self._restoreDefaultsSlot) self.uiTelnetConsolePreconfiguredCommandPushButton.clicked.connect( self._telnetConsolePreconfiguredCommandSlot) self.uiSerialConsolePreconfiguredCommandPushButton.clicked.connect( self._serialConsolePreconfiguredCommandSlot) self.uiVNCConsolePreconfiguredCommandPushButton.clicked.connect( self._vncConsolePreconfiguredCommandSlot) self.uiDefaultLabelFontPushButton.clicked.connect( self._setDefaultLabelFontSlot) self.uiDefaultLabelColorPushButton.clicked.connect( self._setDefaultLabelColorSlot) self._default_label_color = QtGui.QColor(QtCore.Qt.black) self.uiStyleComboBox.addItems(STYLES)
def _qemuVMEditSlot(self): """ Edits a QEMU VM. """ item = self.uiQemuVMsTreeWidget.currentItem() if item: key = item.data(0, QtCore.Qt.UserRole) qemu_vm = self._qemu_vms[key] dialog = ConfigurationDialog(qemu_vm["name"], qemu_vm, QemuVMConfigurationPage(), parent=self) dialog.show() if dialog.exec_(): # update the icon item.setIcon(0, QtGui.QIcon(qemu_vm["symbol"])) if qemu_vm["name"] != item.text(0): new_key = "{server}:{name}".format( server=qemu_vm["server"], name=qemu_vm["name"]) if new_key in self._qemu_vms: QtWidgets.QMessageBox.critical( self, "QEMU VM", "QEMU VM name {} already exists for server {}". format(qemu_vm["name"], qemu_vm["server"])) qemu_vm["name"] = item.text(0) return self._qemu_vms[new_key] = self._qemu_vms[key] del self._qemu_vms[key] item.setText(0, qemu_vm["name"]) item.setData(0, QtCore.Qt.UserRole, new_key) self._refreshInfo(qemu_vm)
def __init__(self): super().__init__() self.setupUi(self) self._widget_slots = {0: self.uiSlot0comboBox, 1: self.uiSlot1comboBox, 2: self.uiSlot2comboBox, 3: self.uiSlot3comboBox, 4: self.uiSlot4comboBox, 5: self.uiSlot5comboBox, 6: self.uiSlot6comboBox} self._widget_wics = {0: self.uiWic0comboBox, 1: self.uiWic1comboBox, 2: self.uiWic2comboBox} self.uiStartupConfigToolButton.clicked.connect(self._startupConfigBrowserSlot) self.uiPrivateConfigToolButton.clicked.connect(self._privateConfigBrowserSlot) self.uiSymbolToolButton.clicked.connect(self._symbolBrowserSlot) self.uiIOSImageToolButton.clicked.connect(self._iosImageBrowserSlot) self._server = None self._idle_valid = False idle_pc_rgx = QtCore.QRegExp("^(0x[0-9a-fA-F]{8})?$") validator = QtGui.QRegExpValidator(idle_pc_rgx, self) self.uiIdlepcLineEdit.setValidator(validator) self.uiIdlepcLineEdit.textChanged.connect(self._idlePCValidateSlot) self.uiIdlepcLineEdit.textChanged.emit(self.uiIdlepcLineEdit.text()) self._default_configs_dir = Servers.instance().localServerSettings()["configs_path"] # add the categories for name, category in Node.defaultCategories().items(): self.uiCategoryComboBox.addItem(name, category)
def loadPreferences(self): """ Loads the server preferences. """ servers = Servers.instance() # load the local server preferences local_server = servers.localServer() index = self.uiLocalServerHostComboBox.findData(local_server.host) if index != -1: self.uiLocalServerHostComboBox.setCurrentIndex(index) self.uiLocalServerPortSpinBox.setValue(local_server.port) self.uiLocalServerPathLineEdit.setText(servers.localServerPath()) self.uiLocalServerAutoStartCheckBox.setChecked( servers.localServerAutoStart()) # load remote server preferences self._remote_servers.clear() self.uiRemoteServersTreeWidget.clear() for server_id, server in servers.remoteServers().items(): host = server.host port = server.port self._remote_servers[server_id] = {"host": host, "port": port} item = QtGui.QTreeWidgetItem(self.uiRemoteServersTreeWidget) item.setText(0, host) item.setText(1, str(port)) self.uiRemoteServersTreeWidget.resizeColumnToContents(0)
def loadSettings(self, settings, node, group=False): """ Loads the ATM bridge settings. :param settings: the settings (dictionary) :param node: Node instance :param group: indicates the settings apply to a group """ if not group: self.uiNameLineEdit.setText(settings["name"]) else: self.uiNameLineEdit.setEnabled(False) self.uiMappingTreeWidget.clear() self._mapping = {} self._node = node for ethernet_port, destination in settings["mappings"].items(): item = QtGui.QTreeWidgetItem(self.uiMappingTreeWidget) item.setText(0, ethernet_port) item.setText(1, destination) self.uiMappingTreeWidget.addTopLevelItem(item) self._mapping[ethernet_port] = destination self.uiMappingTreeWidget.resizeColumnToContents(0) self.uiMappingTreeWidget.resizeColumnToContents(1)
def _addMappingSlot(self): """ Adds a new mapping. """ ethernet_port = self.uiEthernetPortSpinBox.value() atm_port = self.uiATMPortSpinBox.value() atm_vpi = self.uiATMVPISpinBox.value() atm_vci = self.uiATMVCISpinBox.value() if ethernet_port == atm_port: QtGui.QMessageBox.critical(self, self._node.name(), "Same source and destination ports") return destination = "{port}:{vpi}:{vci}".format(port=atm_port, vpi=atm_vpi, vci=atm_vci) if destination in self._mapping: QtGui.QMessageBox.critical(self, self._node.name(), "Mapping already defined") return item = QtGui.QTreeWidgetItem(self.uiMappingTreeWidget) item.setText(0, str(ethernet_port)) item.setText(1, destination) self.uiMappingTreeWidget.addTopLevelItem(item) self.uiEthernetPortSpinBox.setValue(ethernet_port + 1) self.uiATMPortSpinBox.setValue(atm_port + 1) self._mapping[ethernet_port] = destination
def savePreferences(self): """ Saves VPCS preferences. """ vpcs_path = self.uiVPCSPathLineEdit.text().strip() if vpcs_path and self.uiUseLocalServercheckBox.isChecked( ) and not self._checkVPCSPath(vpcs_path): return new_settings = { "vpcs_path": vpcs_path, "base_script_file": self.uiScriptFileEdit.text(), "use_local_server": self.uiUseLocalServercheckBox.isChecked(), "category": self.uiCategoryComboBox.itemData( self.uiCategoryComboBox.currentIndex()) } symbol_path = self.uiSymbolLineEdit.text() pixmap = QtGui.QPixmap(symbol_path) if pixmap.isNull(): QtWidgets.QMessageBox.critical( self, "Symbol", "Invalid file or format not supported") else: new_settings["symbol"] = symbol_path VPCS.instance().setSettings(new_settings)
def __init__(self, ethernet_hubs, parent): super().__init__(ethernet_hubs, parent) self.setPixmap(QtWidgets.QWizard.LogoPixmap, QtGui.QPixmap(":/symbols/hub.svg")) self.uiNameWizardPage.registerField("name*", self.uiNameLineEdit)
def _addMappingSlot(self): """ Adds a new mapping. """ source_port = self.uiSourcePortSpinBox.value() source_dlci = self.uiSourceDLCISpinBox.value() destination_port = self.uiDestinationPortSpinBox.value() destination_dlci = self.uiDestinationDLCISpinBox.value() if source_port == destination_port: QtGui.QMessageBox.critical(self, self._node.name(), "Same source and destination ports") return source = "{port}:{dlci}".format(port=source_port, dlci=source_dlci) destination = "{port}:{dlci}".format(port=destination_port, dlci=destination_dlci) if source in self._mapping or destination in self._mapping: QtGui.QMessageBox.critical(self, self._node.name(), "Mapping already defined") return item = QtGui.QTreeWidgetItem(self.uiMappingTreeWidget) item.setText(0, source) item.setText(1, destination) self.uiMappingTreeWidget.addTopLevelItem(item) self.uiSourcePortSpinBox.setValue(source_port + 1) self.uiSourceDLCISpinBox.setValue(source_dlci + 1) self.uiDestinationPortSpinBox.setValue(destination_port + 1) self.uiDestinationDLCISpinBox.setValue(destination_dlci + 1) self._mapping[source] = destination
def _iosRouterEditSlot(self): """ Edits an IOS router. """ item = self.uiIOSRoutersTreeWidget.currentItem() if item: key = item.data(0, QtCore.Qt.UserRole) ios_router = self._ios_routers[key] dialog = ConfigurationDialog(ios_router["name"], ios_router, IOSRouterConfigurationPage(), parent=self) dialog.show() if dialog.exec_(): # update the icon item.setIcon(0, QtGui.QIcon(ios_router["symbol"])) if ios_router["name"] != item.text(0): # rename the IOS router new_key = "{server}:{name}".format(server=ios_router["server"], name=ios_router["name"]) if new_key in self._ios_routers: QtWidgets.QMessageBox.critical(self, "IOS router", "IOS router name {} already exists for server {}".format(ios_router["name"], ios_router["server"])) ios_router["name"] = item.text(0) return self._ios_routers[new_key] = self._ios_routers[key] del self._ios_routers[key] item.setText(0, ios_router["name"]) item.setData(0, QtCore.Qt.UserRole, new_key) self._refreshInfo(ios_router)
def _addMappingSlot(self): """ Adds a new mapping. """ source_port = self.uiSourcePortSpinBox.value() source_vpi = self.uiSourceVPISpinBox.value() source_vci = self.uiSourceVCISpinBox.value() destination_port = self.uiDestinationPortSpinBox.value() destination_vpi = self.uiDestinationVPISpinBox.value() destination_vci = self.uiDestinationVCISpinBox.value() if self.uiVPICheckBox.checkState() == QtCore.Qt.Unchecked: source = "{port}:{vpi}:{vci}".format(port=source_port, vpi=source_vpi, vci=source_vci) destination = "{port}:{vpi}:{vci}".format(port=destination_port, vpi=destination_vpi, vci=destination_vci) else: source = "{port}:{vpi}".format(port=source_port, vpi=source_vpi) destination = "{port}:{vpi}".format(port=destination_port, vpi=destination_vpi) if source in self._mapping or destination in self._mapping: QtGui.QMessageBox.critical(self, self._node.name(), "Mapping already defined") return item = QtGui.QTreeWidgetItem(self.uiMappingTreeWidget) item.setText(0, source) item.setText(1, destination) self.uiMappingTreeWidget.addTopLevelItem(item) self.uiSourcePortSpinBox.setValue(source_port + 1) self.uiDestinationPortSpinBox.setValue(destination_port + 1) self._mapping[source] = destination
def _dockerImageEditSlot(self): """ Edits a Docker image """ item = self.uiDockerVMsTreeWidget.currentItem() if item: key = item.data(0, QtCore.Qt.UserRole) docker_image = self._docker_containers[key] dialog = ConfigurationDialog(docker_image["name"], docker_image, DockerVMConfigurationPage(), parent=self) dialog.show() if dialog.exec_(): # update the icon item.setIcon(0, QtGui.QIcon(docker_image["symbol"])) if docker_image["name"] != item.text(0): new_key = "{server}:{name}".format( server=docker_image["server"], name=docker_image["name"]) if new_key in self._docker_containers: QtWidgets.QMessageBox.critical( self, "Docker image", "Docker container name {} already exists for server {}" .format(docker_image["name"], docker_image["server"])) docker_image["name"] = item.text(0) return self._docker_containers[new_key] = self._docker_containers[ key] del self._docker_containers[key] item.setText(0, docker_image["name"]) item.setData(0, QtCore.Qt.UserRole, new_key) self._refreshInfo(docker_image)
def __init__(self, iou_devices, parent): super().__init__(iou_devices, IOU.instance().settings()["use_local_server"], parent) self.setPixmap(QtWidgets.QWizard.LogoPixmap, QtGui.QPixmap(":/symbols/multilayer_switch.svg")) self.uiTypeComboBox.currentIndexChanged[str].connect(self._typeChangedSlot) if sys.platform.startswith("win") or sys.platform.startswith("darwin"): # Cannot use IOU locally on Windows and Mac self.uiLocalRadioButton.setEnabled(False) # Available types self.uiTypeComboBox.addItems(["L2 image", "L3 image"]) # Mandatory fields self.uiNameWizardPage.registerField("name*", self.uiNameLineEdit) self.uiNameWizardPage.registerField("image*", self.uiIOUImageLineEdit) self.uiIOUImageLineEdit.textChanged.connect(self._imageLineEditTextChangedSlot) # location of the base config templates self._base_iou_l2_config_template = get_resource(os.path.join("configs", "iou_l2_base_startup-config.txt")) self._base_iou_l3_config_template = get_resource(os.path.join("configs", "iou_l3_base_startup-config.txt")) from ..pages.iou_device_preferences_page import IOUDevicePreferencesPage self.addImageSelector(self.uiExistingImageRadioButton, self.uiIOUImageListComboBox, self.uiIOUImageLineEdit, self.uiIOUImageToolButton, IOUDevicePreferencesPage.getIOUImage)