def _make_toolbar_group(self, title, bg=None, fg=None): """Creates a toolbar containing a `ToolBarGroup`""" tbar = QtWidgets.QToolBar() tbar.setObjectName("toolbar_" + title) tbar.setFloatable(False) tbar.setMovable(True) tbg = widgets.ToolBarGroup(self, title=title, bg=bg, fg=fg) tbar.addWidget(tbg) return tbar, tbg
def __init__(self, mainWindow, fileName=None): """Constructor for the editor window :params QMainWindow mainWindow: the parent main window :params string fileName: Optional filename to open on start """ super().__init__(mainWindow) self.setObjectName("editor_window") self.setGeometry(100, 100, 1024, 768) self.setWindowTitle( self.tr("ts2 - Train Signalling Simulation - Editor")) self._mainWindow = mainWindow self._dirty = False # Editor self.editor = editor.Editor(fileName=fileName) self.editor.initialize(self) # Actions self.newAction = QtWidgets.QAction(self.tr("&New"), self) self.newAction.setShortcut(QtGui.QKeySequence.New) newActionTip = self.tr("Create a new simulation") self.newAction.setToolTip(newActionTip) self.newAction.setStatusTip(newActionTip) self.newAction.triggered.connect(self.closeSimulation) self.openAction = QtWidgets.QAction(self.tr("&Open..."), self) self.openAction.setShortcut(QtGui.QKeySequence.Open) openActionTip = self.tr("Open a simulation") self.openAction.setToolTip(openActionTip) self.openAction.setStatusTip(openActionTip) self.openAction.triggered.connect(self.loadSimulation) self.saveAction = QtWidgets.QAction(self.tr("&Save"), self) self.saveAction.setShortcut(QtGui.QKeySequence.Save) saveActionTip = self.tr("Save the current simulation") self.saveAction.setToolTip(saveActionTip) self.saveAction.setStatusTip(saveActionTip) self.saveAction.triggered.connect(self.saveSimulation) self.saveAsAction = QtWidgets.QAction(self.tr("&Save as..."), self) self.saveAsAction.setShortcut(QtGui.QKeySequence.SaveAs) saveAsActionTip = self.tr( "Save the current simulation with a different file name") self.saveAsAction.setToolTip(saveAsActionTip) self.saveAsAction.setStatusTip(saveAsActionTip) self.saveAsAction.triggered.connect(self.saveAsSimulation) self.closeAction = QtWidgets.QAction(self.tr("&Close"), self) self.closeAction.setShortcut(QtGui.QKeySequence.Close) closeActionTip = self.tr("Close the editor") self.closeAction.setToolTip(closeActionTip) self.closeAction.setStatusTip(closeActionTip) self.closeAction.triggered.connect(self.close) self.panToolAction = QtWidgets.QAction(self.tr("&Pan tool"), self) panToolActionTip = self.tr("Set the pan tool") self.panToolAction.setToolTip(panToolActionTip) self.panToolAction.setStatusTip(panToolActionTip) self.panToolAction.setCheckable(True) self.panToolAction.triggered.connect(self.setPanTool) self.selectionToolAction = QtWidgets.QAction( self.tr("&Selection tool"), self) selectionToolActionTip = self.tr("Set the selection tool") self.selectionToolAction.setToolTip(selectionToolActionTip) self.selectionToolAction.setStatusTip(selectionToolActionTip) self.selectionToolAction.setCheckable(True) self.selectionToolAction.triggered.connect(self.setSelectionTool) self.toolActions = QtWidgets.QActionGroup(self) self.toolActions.addAction(self.panToolAction) self.toolActions.addAction(self.selectionToolAction) self.panToolAction.setChecked(True) self.copyAction = QtWidgets.QAction(self.tr("&Copy"), self) self.copyAction.setShortcut(QtGui.QKeySequence.Copy) copyActionTip = self.tr("Copy the current selection to the clipboard") self.copyAction.setToolTip(copyActionTip) self.copyAction.setStatusTip(copyActionTip) self.copyAction.triggered.connect(self.copyItems) self.pasteAction = QtWidgets.QAction(self.tr("&Paste"), self) self.pasteAction.setShortcut(QtGui.QKeySequence.Paste) pasteActionTip = self.tr("Paste the items of the clipboard") self.pasteAction.setToolTip(pasteActionTip) self.pasteAction.setStatusTip(pasteActionTip) self.pasteAction.triggered.connect(self.pasteItems) self.deleteAction = QtWidgets.QAction(self.tr("&Delete"), self) self.deleteAction.setShortcut(QtGui.QKeySequence.Delete) deleteActionTip = self.tr("Delete the selected items") self.deleteAction.setToolTip(deleteActionTip) self.deleteAction.setStatusTip(deleteActionTip) self.deleteAction.triggered.connect(self.deleteItems) self.selectAllAction = QtWidgets.QAction(self.tr("&Select All"), self) self.selectAllAction.setShortcut(QtGui.QKeySequence.SelectAll) selectAllActionTip = self.tr("Select all the items") self.selectAllAction.setToolTip(selectAllActionTip) self.selectAllAction.setStatusTip(selectAllActionTip) self.selectAllAction.triggered.connect(self.selectAll) self.aboutAction = QtWidgets.QAction(self.tr("&About TS2..."), self) aboutActionTip = self.tr("About TS2") self.aboutAction.setToolTip(aboutActionTip) self.aboutAction.setStatusTip(aboutActionTip) self.aboutAction.triggered.connect(self._mainWindow.showAboutBox) self.aboutQtAction = QtWidgets.QAction(self.tr("About Qt..."), self) aboutQtTip = self.tr("About Qt") self.aboutQtAction.setToolTip(aboutQtTip) self.aboutQtAction.setStatusTip(aboutQtTip) self.aboutQtAction.triggered.connect(QtWidgets.QApplication.aboutQt) # Menu self.fileMenu = self.menuBar().addMenu(self.tr("&File")) self.fileMenu.addAction(self.newAction) self.fileMenu.addAction(self.openAction) self.fileMenu.addAction(self.saveAction) self.fileMenu.addAction(self.saveAsAction) self.fileMenu.addSeparator() self.fileMenu.addAction(self.closeAction) self.editMenu = self.menuBar().addMenu(self.tr("&Edit")) self.editMenu.addAction(self.panToolAction) self.editMenu.addAction(self.selectionToolAction) self.editMenu.addSeparator() self.editMenu.addAction(self.copyAction) self.editMenu.addAction(self.pasteAction) self.editMenu.addAction(self.deleteAction) self.editMenu.addSeparator() self.editMenu.addAction(self.selectAllAction) self.helpMenu = self.menuBar().addMenu(self.tr("&Help")) self.helpMenu.addAction(self.aboutAction) self.helpMenu.addAction(self.aboutQtAction) self.menuBar().setCursor(Qt.PointingHandCursor) self.updateMenus(0) # Status bar statusBar = QtWidgets.QStatusBar() self.setStatusBar(statusBar) # Dock Widgets # >> TrackItems panel: TI Library self.toolsPanel = QtWidgets.QDockWidget(self.tr("Tools"), self) self.toolsPanel.setObjectName("toolsPanel") self.toolsPanel.setFeatures( QtWidgets.QDockWidget.DockWidgetMovable | QtWidgets.QDockWidget.DockWidgetFloatable) self.trackItemsLibraryView = QtWidgets.QGraphicsView(self) self.trackItemsLibraryView.setBackgroundBrush(QtGui.QBrush(Qt.black)) self.trackItemsLibraryView.setInteractive(True) self.trackItemsLibraryView.setRenderHint(QtGui.QPainter.Antialiasing, False) self.trackItemsLibraryView.setDragMode( QtWidgets.QGraphicsView.ScrollHandDrag) self.trackItemsLibraryView.setAlignment(Qt.AlignLeft | Qt.AlignTop) # >> TrackItems panel: layout toolBoard = QtWidgets.QWidget(self) toolGrid = QtWidgets.QVBoxLayout() toolGrid.addWidget(self.trackItemsLibraryView) toolGrid.setSpacing(5) toolBoard.setLayout(toolGrid) self.toolsPanel.setWidget(toolBoard) self.addDockWidget(Qt.RightDockWidgetArea, self.toolsPanel) # >> Properties panel self.propertiesPanel = QtWidgets.QDockWidget(self.tr("Properties"), self) self.propertiesPanel.setObjectName("propertiesPanel") self.propertiesPanel.setFeatures( QtWidgets.QDockWidget.DockWidgetMovable | QtWidgets.QDockWidget.DockWidgetFloatable) self.propertiesView = ts2.editor.views.PropertiesView(self) self.propertiesPanel.setWidget(self.propertiesView) self.addDockWidget(Qt.RightDockWidgetArea, self.propertiesPanel) # Central tab widget self.tabWidget = QtWidgets.QTabWidget(self) # ========================================== # General tab generalTab = QtWidgets.QWidget() titleLabel = QtWidgets.QLabel(self.tr("Simulation title: "), generalTab) self.titleTxt = QtWidgets.QLineEdit(generalTab) self.titleTxt.editingFinished.connect(self.updateTitle) descriptionLabel = QtWidgets.QLabel(self.tr("Description: "), generalTab) self.descriptionTxt = QtWidgets.QPlainTextEdit(generalTab) self.descriptionTxt.textChanged.connect(self.updateDescription) optionsLabel = QtWidgets.QLabel(self.tr("Options: ")) self.optionsView = QtWidgets.QTableView(generalTab) fgrid = QtWidgets.QGridLayout() row = 0 fgrid.addWidget(titleLabel, row, 0, Qt.AlignRight | Qt.AlignTop) fgrid.addWidget(self.titleTxt, row, 1) row += 1 fgrid.addWidget(descriptionLabel, row, 0, Qt.AlignRight | Qt.AlignTop) fgrid.addWidget(self.descriptionTxt, row, 1) row += 1 fgrid.addWidget(optionsLabel, row, 0, Qt.AlignRight | Qt.AlignTop) fgrid.addWidget(self.optionsView, row, 1) generalTab.setLayout(fgrid) fgrid.setColumnStretch(0, 0) fgrid.setColumnStretch(1, 4) fgrid.setRowStretch(0, 0) fgrid.setRowStretch(1, 1) fgrid.setRowStretch(2, 2) self.tabWidget.addTab(generalTab, self.tr("General")) # ========================================== # Scenery tab self.sceneryWidget = widgets.VBoxWidget() toolbarScenery = QtWidgets.QToolBar() self.sceneryWidget.addWidget(toolbarScenery) self.unlockSceneryBtn = QtWidgets.QPushButton( self.tr("Unlock Scenery"), self.sceneryWidget) self.unlockSceneryBtn.setEnabled(False) toolbarScenery.addWidget(self.unlockSceneryBtn) self.validateSceneryBtn = QtWidgets.QPushButton( self.tr("Validate Scenery"), self.sceneryWidget) self.validateSceneryBtn.clicked.connect(self.validateSceneryBtnClicked) toolbarScenery.addWidget(self.validateSceneryBtn) self.zoomWidget = widgets.ZoomWidget(self.sceneryWidget) self.zoomWidget.valueChanged.connect(self.zoom) toolbarScenery.addWidget(self.zoomWidget) self.sceneryView = widgets.XGraphicsView(self.sceneryWidget) self.sceneryView.setInteractive(True) self.sceneryView.setRenderHint(QtGui.QPainter.Antialiasing, False) self.sceneryView.setDragMode(QtWidgets.QGraphicsView.ScrollHandDrag) self.sceneryView.setAcceptDrops(True) self.sceneryView.setBackgroundBrush(QtGui.QBrush(Qt.black)) self.sceneryView.wheelChanged.connect(self.onSceneryViewWheelChanged) self.sceneryWidget.addWidget(self.sceneryView) self.tabWidget.addTab(self.sceneryWidget, self.tr("Scenery")) # ========================================== # Routes tab self.routesWidget = widgets.VBoxWidget() sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding) sizePolicy.setVerticalStretch(1) self.routesGraphicView = QtWidgets.QGraphicsView(self.routesWidget) self.routesGraphicView.setInteractive(True) self.routesGraphicView.setRenderHint(QtGui.QPainter.Antialiasing, False) self.routesGraphicView.setDragMode( QtWidgets.QGraphicsView.ScrollHandDrag) self.routesGraphicView.setAcceptDrops(True) self.routesGraphicView.setBackgroundBrush(QtGui.QBrush(Qt.black)) self.routesGraphicView.setSizePolicy(sizePolicy) self.addRouteBtn = QtWidgets.QPushButton(self.tr("Add Route"), self.routesWidget) self.addRouteBtn.clicked.connect(self.addRouteBtnClicked) self.delRouteBtn = QtWidgets.QPushButton(self.tr("Delete Route"), self.routesWidget) self.delRouteBtn.clicked.connect(self.delRouteBtnClicked) hgrid = QtWidgets.QHBoxLayout() hgrid.setContentsMargins(0, 0, 0, 0) hgrid.addWidget(self.addRouteBtn) hgrid.addWidget(self.delRouteBtn) hgrid.addStretch() self.routesView = ts2.editor.views.RoutesEditorView(self.routesWidget) self.routesWidget.addWidget(self.routesGraphicView) self.routesWidget.addLayout(hgrid) self.routesWidget.addWidget(self.routesView) self.routesWidget.setEnabled(False) self.tabWidget.addTab(self.routesWidget, self.tr("Routes")) # ========================================== # Train types tab self.trainTypesWidget = widgets.VBoxWidget() tbar = QtWidgets.QToolBar() self.trainTypesWidget.addWidget(tbar) tbg = widgets.ToolBarGroup(title="Train Types") tbar.addWidget(tbg) # add train self.addTrainTypeBtn = QtWidgets.QToolButton(self.trainTypesWidget) self.addTrainTypeBtn.setText(self.tr("Add new")) self.addTrainTypeBtn.clicked.connect(self.addTrainTypeBtnClicked) tbg.addWidget(self.addTrainTypeBtn) # remove train self.delTrainTypeBtn = QtWidgets.QToolButton(self.trainTypesWidget) self.delTrainTypeBtn.setText(self.tr("Remove")) self.delTrainTypeBtn.clicked.connect(self.delTrainTypeBtnClicked) tbg.addWidget(self.delTrainTypeBtn) self.trainTypesView = ts2.editor.views.TrainTypesEditorView( self.trainTypesWidget) self.trainTypesWidget.addWidget(self.trainTypesView) self.tabWidget.addTab(self.trainTypesWidget, self.tr("Rolling Stock")) # =============================================================== # Services tab # =============================================================== self.servicesTabWidget = widgets.VBoxWidget() tbarServices = QtWidgets.QToolBar() self.servicesTabWidget.addWidget(tbarServices) # ================ # Service CRUD tbg = widgets.ToolBarGroup(title=self.tr("Services")) tbarServices.addWidget(tbg) # Add Service self.addServiceBtn = QtWidgets.QToolButton(self.servicesTabWidget) self.addServiceBtn.setText(self.tr("Add new")) self.addServiceBtn.clicked.connect(self.addServiceBtnClicked) tbg.addWidget(self.addServiceBtn) # Remove Service self.delServiceBtn = QtWidgets.QToolButton(self.servicesTabWidget) self.delServiceBtn.setText(self.tr("Remove")) self.delServiceBtn.clicked.connect(self.delServiceBtnClicked) tbg.addWidget(self.delServiceBtn) tbarServices.addSeparator() # ================ # CSV tbg = widgets.ToolBarGroup(title=self.tr("CSV")) tbarServices.addWidget(tbg) # Export CSV self.exportServicesBtn = QtWidgets.QToolButton(self.servicesTabWidget) self.exportServicesBtn.setText(self.tr("Export")) self.exportServicesBtn.clicked.connect(self.exportServicesBtnClicked) tbg.addWidget(self.exportServicesBtn) # Import CSV self.importServicesBtn = QtWidgets.QToolButton(self.servicesTabWidget) self.importServicesBtn.setText(self.tr("Import")) self.importServicesBtn.clicked.connect(self.importServicesBtnClicked) tbg.addWidget(self.importServicesBtn) # Services Table self.servicesView = ts2.editor.views.ServicesEditorView( self.servicesTabWidget) self.servicesTabWidget.addWidget(self.servicesView) tbarServiceLines = QtWidgets.QToolBar() self.servicesTabWidget.addWidget(tbarServiceLines) tbg = widgets.ToolBarGroup() tbg.setTitle(self.tr("Lines")) tbarServiceLines.addWidget(tbg) # Append line button self.appendServiceLineBtn = QtWidgets.QToolButton( self.servicesTabWidget) self.appendServiceLineBtn.setText(self.tr("Append New")) self.appendServiceLineBtn.clicked.connect( self.appendServiceLineBtnClicked) tbg.addWidget(self.appendServiceLineBtn) # Insert line button self.insertServiceLineBtn = QtWidgets.QToolButton( self.servicesTabWidget) self.insertServiceLineBtn.setText(self.tr("Insert New")) self.insertServiceLineBtn.clicked.connect( self.insertServiceLineBtnClicked) tbg.addWidget(self.insertServiceLineBtn) # Delete line button self.deleteServiceLineBtn = QtWidgets.QToolButton( self.servicesTabWidget) self.deleteServiceLineBtn.setText(self.tr("Remove")) self.deleteServiceLineBtn.clicked.connect( self.delServiceLineBtnClicked) tbg.addWidget(self.deleteServiceLineBtn) # ServiceLines table self.serviceLinesView = ts2.editor.views.ServiceLinesEditorView( self.servicesTabWidget) self.serviceLinesView.setSelectionBehavior( QtWidgets.QAbstractItemView.SelectRows) self.serviceLinesView.setSelectionMode( QtWidgets.QAbstractItemView.SingleSelection) self.servicesTabWidget.addWidget(self.serviceLinesView) self.tabWidget.addTab(self.servicesTabWidget, self.tr("Services")) # =============================================================== # Train tab # =============================================================== trainsTab = QtWidgets.QWidget() self.setupTrainsBtn = QtWidgets.QPushButton( self.tr("Setup trains from services"), trainsTab) self.setupTrainsBtn.clicked.connect(self.setupTrainsBtnClicked) hgride = QtWidgets.QHBoxLayout() hgride.addWidget(self.setupTrainsBtn) hgride.addStretch() self.trainsGraphicsView = ts2.editor.views.TrainsGraphicsView( trainsTab) self.reverseTrainBtn = QtWidgets.QPushButton( self.tr("Reverse train direction"), trainsTab) self.reverseTrainBtn.clicked.connect(self.reverseTrainBtnClicked) hgridr = QtWidgets.QHBoxLayout() hgridr.addWidget(self.reverseTrainBtn) hgridr.addStretch() self.trainsView = ts2.editor.views.TrainsEditorView(trainsTab) self.addTrainBtn = QtWidgets.QPushButton(self.tr("Add new train"), trainsTab) self.addTrainBtn.clicked.connect(self.addTrainBtnClicked) self.delTrainBtn = QtWidgets.QPushButton(self.tr("Remove train"), trainsTab) self.delTrainBtn.clicked.connect(self.delTrainBtnClicked) hgrid = QtWidgets.QHBoxLayout() hgrid.addWidget(self.addTrainBtn) hgrid.addWidget(self.delTrainBtn) hgrid.addStretch() grid = QtWidgets.QVBoxLayout() grid.addLayout(hgride) grid.addWidget(self.trainsGraphicsView) grid.addLayout(hgridr) grid.addWidget(self.trainsView) grid.addLayout(hgrid) trainsTab.setLayout(grid) self.tabWidget.addTab(trainsTab, self.tr("Trains")) self.setCentralWidget(self.tabWidget) sbar = widgets.StatusBar() self.setStatusBar(sbar) settings.restoreWindow(self) self.onServiceViewSelectionChanged(None) self.onServiceLinesViewSelectionChanged() self.onTrainTypesSelectionChanged() if fileName: QtCore.QTimer.singleShot(100, self.onStartupTimeout)