def __init__(self, parent, train): """Constructor for the SplitTrainDialog.""" super().__init__(parent) self.setObjectName("split_train_dialog") self.setWindowTitle( self.tr("Split a train") ) layout = QtWidgets.QVBoxLayout() label0 = QtWidgets.QLabel(self) label0.setText(train.trainType.elements[0].description) layout.addWidget(label0) self.radioButtons = [] for element in train.trainType.elements[1:]: self.radioButtons.append(QtWidgets.QRadioButton( self.tr("Split here"), self) ) layout.addWidget(self.radioButtons[-1]) label = QtWidgets.QLabel(self) label.setText(element.description) layout.addWidget(label) self.radioButtons[0].setChecked(True) buttonBox = QtWidgets.QDialogButtonBox( QtWidgets.QDialogButtonBox.Ok | QtWidgets.QDialogButtonBox.Cancel ) layout.addWidget(buttonBox) self.setLayout(layout) self.setMinimumWidth(300) buttonBox.accepted.connect(self.accept) buttonBox.rejected.connect(self.reject) settings.restoreWindow(self)
def __init__(self, parent, train): """Constructor for the SplitTrainDialog.""" super().__init__(parent) self.setObjectName("split_train_dialog") self.setWindowTitle(self.tr("Split a train")) layout = QtWidgets.QVBoxLayout() label0 = QtWidgets.QLabel(self) label0.setText(train.trainType.elements[0].description) layout.addWidget(label0) self.radioButtons = [] for element in train.trainType.elements[1:]: self.radioButtons.append( QtWidgets.QRadioButton(self.tr("Split here"), self)) layout.addWidget(self.radioButtons[-1]) label = QtWidgets.QLabel(self) label.setText(element.description) layout.addWidget(label) self.radioButtons[0].setChecked(True) buttonBox = QtWidgets.QDialogButtonBox( QtWidgets.QDialogButtonBox.Ok | QtWidgets.QDialogButtonBox.Cancel) layout.addWidget(buttonBox) self.setLayout(layout) self.setMinimumWidth(300) buttonBox.accepted.connect(self.accept) buttonBox.rejected.connect(self.reject) settings.restoreWindow(self)
def __init__(self, parent, simulation): super().__init__(parent) self.setObjectName("service_assign_dialog") self.setWindowTitle( self.tr("Choose a service to assign to this train")) self.serviceListView = servicelistview.ServiceListView(self) self.serviceListView.setupServiceList(simulation) buttonBox = QtWidgets.QDialogButtonBox( QtWidgets.QDialogButtonBox.Ok | QtWidgets.QDialogButtonBox.Cancel) layout = QtWidgets.QVBoxLayout() layout.addWidget(self.serviceListView) layout.addWidget(buttonBox) self.setLayout(layout) self.resize(600, 300) buttonBox.accepted.connect(self.accept) buttonBox.rejected.connect(self.reject) self.serviceListView.doubleClicked.connect(self.accept) settings.restoreWindow(self)
def __init__(self, parent, simulation): super().__init__(parent) self.setObjectName("service_assign_dialog") self.setWindowTitle( self.tr("Choose a service to assign to this train") ) self.serviceListView = servicelistview.ServiceListView(self) self.serviceListView.setupServiceList(simulation) buttonBox = QtWidgets.QDialogButtonBox( QtWidgets.QDialogButtonBox.Ok | QtWidgets.QDialogButtonBox.Cancel ) layout = QtWidgets.QVBoxLayout() layout.addWidget(self.serviceListView) layout.addWidget(buttonBox) self.setLayout(layout) self.resize(600, 300) buttonBox.accepted.connect(self.accept) buttonBox.rejected.connect(self.reject) self.serviceListView.doubleClicked.connect(self.accept) settings.restoreWindow(self)
def __init__(self, args=None): super().__init__() MainWindow._self = self self.fileName = None if args: settings.setDebug(args.debug) if args.file: # TODO absolute paths self.fileName = args.file self.setObjectName("ts2_main_window") self.editorWindow = None self.setGeometry(100, 100, 800, 600) self.setWindowTitle(self.tr("ts2 - Train Signalling Simulation - %s") % __VERSION__) # Simulation self.simulation = None # Actions ====================================== self.openAction = QtWidgets.QAction(self.tr("&Open..."), self) self.openAction.setShortcut(QtGui.QKeySequence.Open) self.openAction.setToolTip(self.tr("Open a simulation or a " "previously saved game")) self.openAction.triggered.connect(self.onOpenSimulation) self.openRecentAction = QtWidgets.QAction(self.tr("Recent"), self) menu = QtWidgets.QMenu() self.openRecentAction.setMenu(menu) menu.triggered.connect(self.onRecent) self.saveGameAsAction = QtWidgets.QAction(self.tr("&Save game"), self) self.saveGameAsAction.setShortcut(QtGui.QKeySequence.SaveAs) self.saveGameAsAction.setToolTip(self.tr("Save the current game")) self.saveGameAsAction.triggered.connect(self.saveGame) self.saveGameAsAction.setEnabled(False) # Properties self.propertiesAction = QtWidgets.QAction(self.tr("Sim &Properties..."), self) self.propertiesAction.setShortcut( QtGui.QKeySequence(self.tr("Ctrl+P")) ) self.propertiesAction.setToolTip(self.tr("Edit simulation properties")) self.propertiesAction.triggered.connect(self.openPropertiesDialog) self.propertiesAction.setEnabled(False) # Settings self.settingsAction = QtWidgets.QAction(self.tr("Settings..."), self) self.settingsAction.setToolTip(self.tr("User Settings")) self.settingsAction.triggered.connect(self.openSettingsDialog) self.quitAction = QtWidgets.QAction(self.tr("&Quit"), self) self.quitAction.setShortcut(QtGui.QKeySequence(self.tr("Ctrl+Q"))) self.quitAction.setToolTip(self.tr("Quit TS2")) self.quitAction.triggered.connect(self.close) self.editorAction = QtWidgets.QAction(self.tr("&Open Editor"), self) self.editorAction.setShortcut(QtGui.QKeySequence(self.tr("Ctrl+E"))) self.editorAction.setToolTip(self.tr("Open the simulation editor")) self.editorAction.triggered.connect(self.openEditor) self.editorCurrAction = QtWidgets.QAction(self.tr("&Edit"), self) # self.editorCurrAction.setShortcut(QtGui.QKeySequence(self.tr("Ctrl+"))) self.editorCurrAction.setToolTip(self.tr("Open this sim in editor")) self.editorCurrAction.triggered.connect(self.onEditorCurrent) # Web Links self.actionGroupWwww = QtWidgets.QActionGroup(self) self.actionGroupWwww.triggered.connect(self.onWwwAction) self.aboutWwwHompage = QtWidgets.QAction(self.tr("&TS2 Homepage"), self) self.aboutWwwHompage.setProperty("url", __PROJECT_WWW__) self.actionGroupWwww.addAction(self.aboutWwwHompage) self.aboutWwwProject = QtWidgets.QAction(self.tr("&TS2 Project"), self) self.aboutWwwProject.setProperty("url", __PROJECT_HOME__) self.actionGroupWwww.addAction(self.aboutWwwProject) self.aboutWwwBugs = QtWidgets.QAction(self.tr("&TS2 Bugs && Feedback"), self) self.aboutWwwBugs.setProperty("url", __PROJECT_BUGS__) self.actionGroupWwww.addAction(self.aboutWwwBugs) # About self.aboutAction = QtWidgets.QAction(self.tr("&About TS2..."), self) self.aboutAction.setToolTip(self.tr("About TS2")) self.aboutAction.triggered.connect(self.showAboutBox) self.aboutQtAction = QtWidgets.QAction(self.tr("About Qt..."), self) self.aboutQtAction.setToolTip(self.tr("About Qt")) self.aboutQtAction.triggered.connect(QtWidgets.QApplication.aboutQt) # =============================================== # Menus # FileMenu self.fileMenu = self.menuBar().addMenu(self.tr("&File")) self.fileMenu.addAction(self.openAction) self.fileMenu.addAction(self.openRecentAction) self.fileMenu.addSeparator() self.fileMenu.addAction(self.saveGameAsAction) self.fileMenu.addSeparator() self.fileMenu.addAction(self.propertiesAction) self.fileMenu.addAction(self.settingsAction) self.fileMenu.addSeparator() self.fileMenu.addAction(self.quitAction) # Editor Menu self.editorMenu = self.menuBar().addMenu(self.tr("&Editor")) self.editorMenu.addAction(self.editorAction) self.editorMenu.addAction(self.editorCurrAction) # Help Menu self.helpMenu = self.menuBar().addMenu(self.tr("&Help")) self.helpMenu.addAction(self.aboutWwwHompage) self.helpMenu.addAction(self.aboutWwwProject) self.helpMenu.addAction(self.aboutWwwBugs) self.helpMenu.addSeparator() self.helpMenu.addAction(self.aboutAction) self.helpMenu.addAction(self.aboutQtAction) self.menuBar().setCursor(Qt.PointingHandCursor) # ============================================================== # ToolBars # ========= # Actions tbar, tbg = self._make_toolbar_group(self.tr("Simulation"), bg="#dddddd") self.addToolBar(tbar) tbg.addAction(self.openAction) tbg.addAction(self.editorCurrAction) # ========= # Speed tbar, tbg = self._make_toolbar_group(self.tr("Speed"), bg="#aaaaaa") self.addToolBar(tbar) # Time factor spinBox self.timeFactorSpinBox = QtWidgets.QSpinBox(self) self.timeFactorSpinBox.setRange(1, 10) self.timeFactorSpinBox.setSingleStep(1) self.timeFactorSpinBox.setValue(1) self.timeFactorSpinBox.setSuffix("x") tbg.addWidget(self.timeFactorSpinBox) # ========= # Zoom tbar, tbg = self._make_toolbar_group(self.tr("Zoom"), bg="white") self.addToolBar(tbar) tbg.setMaximumWidth(300) self.zoomWidget = widgets.ZoomWidget(self) self.zoomWidget.valueChanged.connect(self.zoom) tbg.addWidget(self.zoomWidget) # ========= # Score tbar, tbg = self._make_toolbar_group(self.tr("Penalty"), bg="#dddddd") self.addToolBar(tbar) # Score display self.scoreDisplay = QtWidgets.QLCDNumber(self) self.scoreDisplay.setFrameShape(QtWidgets.QFrame.NoFrame) self.scoreDisplay.setFrameShadow(QtWidgets.QFrame.Plain) self.scoreDisplay.setSegmentStyle(QtWidgets.QLCDNumber.Flat) self.scoreDisplay.setNumDigits(5) self.scoreDisplay.resize(70, 25) tbg.addWidget(self.scoreDisplay) # ========= # Clock tbar, tbg = self._make_toolbar_group(self.tr("Clock"), fg="Yellow", bg="#444444") self.addToolBar(tbar) # Pause button self.buttPause = QtWidgets.QToolButton(self) self.buttPause.setText(self.tr("Pause")) self.buttPause.setCheckable(True) self.buttPause.setAutoRaise(True) self.buttPause.setMaximumWidth(50) tbg.addWidget(self.buttPause) # Clock Widget self.clockWidget = widgets.ClockWidget(self) tbg.addWidget(self.clockWidget) # ==================== # Sim Title tbar = QtWidgets.QToolBar() tbar.setObjectName("toolbar_label_title") tbar.setFloatable(False) tbar.setMovable(False) self.addToolBar(tbar) self.lblTitle = QtWidgets.QLabel() lbl_sty = "background: qlineargradient(x1: 0, y1: 0, x2: 1, y2: 0," \ " stop: 0 #fefefe, stop: 1 #CECECE);" lbl_sty += " color: #333333; font-size: 16pt; padding: 1px;" self.lblTitle.setStyleSheet(lbl_sty) self.lblTitle.setAlignment(Qt.AlignRight | Qt.AlignVCenter) self.lblTitle.setText("no sim loaded") tbar.addWidget(self.lblTitle) tbar.layout().setSizeConstraint(QtWidgets.QLayout.SetMaximumSize) # =============================================================== # Dock Widgets # Train Info self.trainInfoPanel = QtWidgets.QDockWidget( self.tr("Train Information"), self ) self.trainInfoPanel.setObjectName("train_information") self.trainInfoPanel.setFeatures( QtWidgets.QDockWidget.DockWidgetMovable | QtWidgets.QDockWidget.DockWidgetFloatable ) self.trainInfoView = QtWidgets.QTreeView(self) self.trainInfoView.setItemsExpandable(False) self.trainInfoView.setRootIsDecorated(False) self.trainInfoView.setContextMenuPolicy(Qt.CustomContextMenu) self.trainInfoView.customContextMenuRequested.connect( self.showContextMenu ) self.trainInfoPanel.setWidget(self.trainInfoView) self.addDockWidget(Qt.RightDockWidgetArea, self.trainInfoPanel) # Service Info self.serviceInfoPanel = QtWidgets.QDockWidget( self.tr("Service Information"), self ) self.serviceInfoPanel.setObjectName("service_information") self.serviceInfoPanel.setFeatures( QtWidgets.QDockWidget.DockWidgetMovable | QtWidgets.QDockWidget.DockWidgetFloatable ) sty = "background-color: #444444; color: white; padding: 2px;" \ " font-size: 10pt" wid = QtWidgets.QScrollArea() self.serviceInfoPanel.setWidget(wid) grid = QtWidgets.QGridLayout() wid.setLayout(grid) self.lblServiceInfoCode = QtWidgets.QLabel() self.lblServiceInfoCode.setStyleSheet(sty) self.lblServiceInfoCode.setText("") self.lblServiceInfoCode.setMaximumWidth(100) grid.addWidget(self.lblServiceInfoCode, 0, 0) self.lblServiceInfoDescription = QtWidgets.QLabel() self.lblServiceInfoDescription.setText("") self.lblServiceInfoDescription.setStyleSheet(sty) self.lblServiceInfoDescription.setScaledContents(False) grid.addWidget(self.lblServiceInfoDescription, 0, 1) self.serviceInfoView = QtWidgets.QTreeView(self) self.serviceInfoView.setItemsExpandable(False) self.serviceInfoView.setRootIsDecorated(False) grid.addWidget(self.serviceInfoView, 1, 0, 1, 2) self.serviceInfoPanel.setWidget(wid) grid.setColumnStretch(0, 1) grid.setColumnStretch(1, 4) grid.setSpacing(0) grid.setContentsMargins(0, 0, 0, 0) self.addDockWidget(Qt.RightDockWidgetArea, self.serviceInfoPanel) # Stations + Places Info self.placeInfoPanel = QtWidgets.QDockWidget( self.tr("Station Information"), self ) self.placeInfoPanel.setObjectName("place_information") self.placeInfoPanel.setFeatures( QtWidgets.QDockWidget.DockWidgetMovable | QtWidgets.QDockWidget.DockWidgetFloatable ) wid = QtWidgets.QScrollArea() self.placeInfoPanel.setWidget(wid) hb = QtWidgets.QVBoxLayout() wid.setLayout(hb) self.lblPlaceInfoName = QtWidgets.QLabel() self.lblPlaceInfoName.setStyleSheet(sty) self.lblPlaceInfoName.setText("") hb.addWidget(self.lblPlaceInfoName) self.placeInfoView = QtWidgets.QTreeView(self) self.placeInfoView.setItemsExpandable(False) self.placeInfoView.setRootIsDecorated(False) self.placeInfoView.setModel(placeitem.Place.selectedPlaceModel) hb.addWidget(self.placeInfoView) hb.setSpacing(0) hb.setContentsMargins(0, 0, 0, 0) self.placeInfoPanel.setWidget(wid) self.addDockWidget(Qt.RightDockWidgetArea, self.placeInfoPanel) # Trains self.trainListPanel = QtWidgets.QDockWidget(self.tr("Trains"), self) self.trainListPanel.setFeatures( QtWidgets.QDockWidget.DockWidgetMovable | QtWidgets.QDockWidget.DockWidgetFloatable ) self.trainListPanel.setObjectName("trains_panel") self.trainListView = trainlistview.TrainListView(self) self.simulationLoaded.connect(self.trainListView.setupTrainList) self.trainListPanel.setWidget(self.trainListView) self.addDockWidget(Qt.BottomDockWidgetArea, self.trainListPanel) # Services self.serviceListPanel = QtWidgets.QDockWidget(self.tr("Services"), self) self.serviceListPanel.setFeatures( QtWidgets.QDockWidget.DockWidgetMovable | QtWidgets.QDockWidget.DockWidgetFloatable ) self.serviceListPanel.setObjectName("services_panel") self.serviceListView = servicelistview.ServiceListView(self) self.simulationLoaded.connect(self.serviceListView.setupServiceList) self.serviceListPanel.setWidget(self.serviceListView) self.addDockWidget(Qt.BottomDockWidgetArea, self.serviceListPanel) self.tabifyDockWidget(self.serviceListPanel, self.trainListPanel) # Message Logger self.loggerPanel = QtWidgets.QDockWidget(self.tr("Messages"), self) self.loggerPanel.setFeatures(QtWidgets.QDockWidget.DockWidgetMovable | QtWidgets.QDockWidget.DockWidgetFloatable) self.loggerPanel.setObjectName("logger_panel") self.loggerView = QtWidgets.QTreeView(self) self.loggerView.setItemsExpandable(False) self.loggerView.setRootIsDecorated(False) self.loggerView.setHeaderHidden(True) self.loggerView.setPalette(QtGui.QPalette(Qt.black)) self.loggerView.setVerticalScrollMode( QtWidgets.QAbstractItemView.ScrollPerItem ) self.loggerPanel.setWidget(self.loggerView) self.addDockWidget(Qt.BottomDockWidgetArea, self.loggerPanel) # =========================================== # Main Board self.board = QtWidgets.QWidget(self) # Canvas self.view = widgets.XGraphicsView(self.board) self.view.setInteractive(True) self.view.setRenderHint(QtGui.QPainter.Antialiasing, False) self.view.setDragMode(QtWidgets.QGraphicsView.ScrollHandDrag) self.view.setPalette(QtGui.QPalette(Qt.black)) self.view.wheelChanged.connect(self.onWheelChanged) # Display self.grid = QtWidgets.QVBoxLayout() self.grid.setContentsMargins(0, 0, 0, 0) self.grid.addWidget(self.view) self.grid.setSpacing(0) self.board.setLayout(self.grid) self.setCentralWidget(self.board) # Editor self.editorOpened = False self.setControlsDisabled(True) self.refreshRecent() settings.restoreWindow(self) if args and args.file: if args.edit: self.openEditor(args.file) # else: # here we call after window is shown QtCore.QTimer.singleShot(100, self.onAfterShow)
def __init__(self, args=None): super().__init__() MainWindow._self = self self.fileName = None self.simServer = args.server if args: settings.setDebug(args.debug) if args.file: # TODO absolute paths self.fileName = args.file self.setObjectName("ts2_main_window") self.editorWindow = None self.setGeometry(100, 100, 800, 600) self.setWindowTitle( self.tr("ts2 - Train Signalling Simulation - %s") % __VERSION__) # Simulation self.simulation = None self.webSocket = None self.serverPID = None if settings.debug: websocket.enableTrace(True) # Actions ====================================== self.openAction = QtWidgets.QAction(self.tr("&Open..."), self) self.openAction.setShortcut(QtGui.QKeySequence.Open) self.openAction.setToolTip( self.tr("Open a simulation or a " "previously saved game")) self.openAction.triggered.connect(self.onOpenSimulation) self.closeAction = QtWidgets.QAction(self.tr("&Close")) self.closeAction.setShortcut(QtGui.QKeySequence.Close) self.closeAction.setToolTip(self.tr("Close the current simulation")) self.closeAction.triggered.connect(self.simulationClose) self.openRecentAction = QtWidgets.QAction(self.tr("Recent"), self) menu = QtWidgets.QMenu() self.openRecentAction.setMenu(menu) menu.triggered.connect(self.onRecent) self.saveGameAsAction = QtWidgets.QAction(self.tr("&Save game"), self) self.saveGameAsAction.setShortcut(QtGui.QKeySequence.SaveAs) self.saveGameAsAction.setToolTip(self.tr("Save the current game")) self.saveGameAsAction.triggered.connect(self.saveGame) self.saveGameAsAction.setEnabled(False) # Properties self.propertiesAction = QtWidgets.QAction( self.tr("Sim &Properties..."), self) self.propertiesAction.setShortcut(QtGui.QKeySequence( self.tr("Ctrl+P"))) self.propertiesAction.setToolTip(self.tr("Edit simulation properties")) self.propertiesAction.triggered.connect(self.openPropertiesDialog) self.propertiesAction.setEnabled(False) # Settings self.settingsAction = QtWidgets.QAction(self.tr("Settings..."), self) self.settingsAction.setToolTip(self.tr("User Settings")) self.settingsAction.triggered.connect(self.openSettingsDialog) self.quitAction = QtWidgets.QAction(self.tr("&Quit"), self) self.quitAction.setShortcut(QtGui.QKeySequence(self.tr("Ctrl+Q"))) self.quitAction.setToolTip(self.tr("Quit TS2")) self.quitAction.triggered.connect(self.close) self.editorAction = QtWidgets.QAction(self.tr("&Open Editor"), self) self.editorAction.setShortcut(QtGui.QKeySequence(self.tr("Ctrl+E"))) self.editorAction.setToolTip(self.tr("Open the simulation editor")) self.editorAction.triggered.connect(self.openEditor) self.editorCurrAction = QtWidgets.QAction(self.tr("&Edit"), self) self.editorCurrAction.setToolTip(self.tr("Open this sim in editor")) self.editorCurrAction.triggered.connect(self.onEditorCurrent) # Web Links self.actionGroupWwww = QtWidgets.QActionGroup(self) self.actionGroupWwww.triggered.connect(self.onWwwAction) self.aboutWwwHompage = QtWidgets.QAction(self.tr("&TS2 Homepage"), self) self.aboutWwwHompage.setProperty("url", __PROJECT_WWW__) self.actionGroupWwww.addAction(self.aboutWwwHompage) self.aboutWwwProject = QtWidgets.QAction(self.tr("&TS2 Project"), self) self.aboutWwwProject.setProperty("url", __PROJECT_HOME__) self.actionGroupWwww.addAction(self.aboutWwwProject) self.aboutWwwBugs = QtWidgets.QAction(self.tr("&TS2 Bugs && Feedback"), self) self.aboutWwwBugs.setProperty("url", __PROJECT_BUGS__) self.actionGroupWwww.addAction(self.aboutWwwBugs) # About self.aboutAction = QtWidgets.QAction(self.tr("&About TS2..."), self) self.aboutAction.setToolTip(self.tr("About TS2")) self.aboutAction.triggered.connect(self.showAboutBox) self.aboutQtAction = QtWidgets.QAction(self.tr("About Qt..."), self) self.aboutQtAction.setToolTip(self.tr("About Qt")) self.aboutQtAction.triggered.connect(QtWidgets.QApplication.aboutQt) # =============================================== # Menus # FileMenu self.fileMenu = self.menuBar().addMenu(self.tr("&File")) self.fileMenu.addAction(self.openAction) self.fileMenu.addAction(self.openRecentAction) self.fileMenu.addAction(self.saveGameAsAction) self.fileMenu.addAction(self.closeAction) self.fileMenu.addSeparator() self.fileMenu.addAction(self.propertiesAction) self.fileMenu.addAction(self.settingsAction) self.fileMenu.addSeparator() self.fileMenu.addAction(self.quitAction) # Editor Menu self.editorMenu = self.menuBar().addMenu(self.tr("&Editor")) self.editorMenu.addAction(self.editorAction) self.editorMenu.addAction(self.editorCurrAction) # Help Menu self.helpMenu = self.menuBar().addMenu(self.tr("&Help")) self.helpMenu.addAction(self.aboutWwwHompage) self.helpMenu.addAction(self.aboutWwwProject) self.helpMenu.addAction(self.aboutWwwBugs) self.helpMenu.addSeparator() self.helpMenu.addAction(self.aboutAction) self.helpMenu.addAction(self.aboutQtAction) self.menuBar().setCursor(Qt.PointingHandCursor) # ============================================================== # ToolBars # ========= # Actions tbar, tbg = self._make_toolbar_group(self.tr("Simulation"), bg="#dddddd") self.addToolBar(tbar) tbg.addAction(self.openAction) tbg.addAction(self.editorCurrAction) # ========= # Speed tbar, tbg = self._make_toolbar_group(self.tr("Speed"), bg="#aaaaaa") self.addToolBar(tbar) # Time factor spinBox self.timeFactorSpinBox = QtWidgets.QSpinBox(self) self.timeFactorSpinBox.setRange(1, 10) self.timeFactorSpinBox.setSingleStep(1) self.timeFactorSpinBox.setValue(1) self.timeFactorSpinBox.setSuffix("x") tbg.addWidget(self.timeFactorSpinBox) # ========= # Zoom tbar, tbg = self._make_toolbar_group(self.tr("Zoom"), bg="white") self.addToolBar(tbar) tbg.setMaximumWidth(300) self.zoomWidget = widgets.ZoomWidget(self) self.zoomWidget.valueChanged.connect(self.zoom) tbg.addWidget(self.zoomWidget) # ========= # Score tbar, tbg = self._make_toolbar_group(self.tr("Penalty"), bg="#dddddd") self.addToolBar(tbar) # Score display self.scoreDisplay = QtWidgets.QLCDNumber(self) self.scoreDisplay.setFrameShape(QtWidgets.QFrame.NoFrame) self.scoreDisplay.setFrameShadow(QtWidgets.QFrame.Plain) self.scoreDisplay.setSegmentStyle(QtWidgets.QLCDNumber.Flat) self.scoreDisplay.setNumDigits(5) self.scoreDisplay.setMinimumHeight(30) tbg.addWidget(self.scoreDisplay) # ========= # Clock tbar, tbg = self._make_toolbar_group(self.tr("Clock"), fg="Yellow", bg="#444444") self.addToolBar(tbar) # Pause button self.buttPause = QtWidgets.QToolButton(self) self.buttPause.setText(self.tr("Pause")) self.buttPause.setCheckable(True) self.buttPause.setAutoRaise(True) self.buttPause.setMaximumWidth(50) self.buttPause.setChecked(True) tbg.addWidget(self.buttPause) # Clock Widget self.clockWidget = widgets.ClockWidget(self) tbg.addWidget(self.clockWidget) # ==================== # Sim Title tbar = QtWidgets.QToolBar() tbar.setObjectName("toolbar_label_title") tbar.setFloatable(False) tbar.setMovable(False) self.addToolBar(tbar) self.lblTitle = QtWidgets.QLabel() lbl_sty = "background: qlineargradient(x1: 0, y1: 0, x2: 1, y2: 0," \ " stop: 0 #fefefe, stop: 1 #CECECE);" lbl_sty += " color: #333333; font-size: 16pt; padding: 1px;" self.lblTitle.setStyleSheet(lbl_sty) self.lblTitle.setAlignment(Qt.AlignRight | Qt.AlignVCenter) self.lblTitle.setText("no sim loaded") tbar.addWidget(self.lblTitle) tbar.layout().setSizeConstraint(QtWidgets.QLayout.SetMaximumSize) # =============================================================== # Dock Widgets # Train Info self.trainInfoPanel = QtWidgets.QDockWidget( self.tr("Train Information"), self) self.trainInfoPanel.setObjectName("train_information") self.trainInfoPanel.setFeatures( QtWidgets.QDockWidget.DockWidgetMovable | QtWidgets.QDockWidget.DockWidgetFloatable) self.trainInfoView = QtWidgets.QTreeView(self) self.trainInfoView.setItemsExpandable(False) self.trainInfoView.setRootIsDecorated(False) self.trainInfoView.setContextMenuPolicy(Qt.CustomContextMenu) self.trainInfoView.customContextMenuRequested.connect( self.showContextMenu) self.trainInfoPanel.setWidget(self.trainInfoView) self.addDockWidget(Qt.RightDockWidgetArea, self.trainInfoPanel) # Service Info self.serviceInfoPanel = QtWidgets.QDockWidget( self.tr("Service Information"), self) self.serviceInfoPanel.setObjectName("service_information") self.serviceInfoPanel.setFeatures( QtWidgets.QDockWidget.DockWidgetMovable | QtWidgets.QDockWidget.DockWidgetFloatable) sty = "background-color: #444444; color: white; padding: 2px;" \ " font-size: 10pt" wid = QtWidgets.QScrollArea() self.serviceInfoPanel.setWidget(wid) grid = QtWidgets.QGridLayout() wid.setLayout(grid) self.lblServiceInfoCode = QtWidgets.QLabel() self.lblServiceInfoCode.setStyleSheet(sty) self.lblServiceInfoCode.setText("") self.lblServiceInfoCode.setMaximumWidth(100) grid.addWidget(self.lblServiceInfoCode, 0, 0) self.lblServiceInfoDescription = QtWidgets.QLabel() self.lblServiceInfoDescription.setText("") self.lblServiceInfoDescription.setStyleSheet(sty) self.lblServiceInfoDescription.setScaledContents(False) grid.addWidget(self.lblServiceInfoDescription, 0, 1) self.serviceInfoView = QtWidgets.QTreeView(self) self.serviceInfoView.setItemsExpandable(False) self.serviceInfoView.setRootIsDecorated(False) grid.addWidget(self.serviceInfoView, 1, 0, 1, 2) self.serviceInfoPanel.setWidget(wid) grid.setColumnStretch(0, 1) grid.setColumnStretch(1, 4) grid.setSpacing(0) grid.setContentsMargins(0, 0, 0, 0) self.addDockWidget(Qt.RightDockWidgetArea, self.serviceInfoPanel) # Stations + Places Info self.placeInfoPanel = QtWidgets.QDockWidget( self.tr("Station Information"), self) self.placeInfoPanel.setObjectName("place_information") self.placeInfoPanel.setFeatures( QtWidgets.QDockWidget.DockWidgetMovable | QtWidgets.QDockWidget.DockWidgetFloatable) wid = QtWidgets.QScrollArea() self.placeInfoPanel.setWidget(wid) hb = QtWidgets.QVBoxLayout() wid.setLayout(hb) self.lblPlaceInfoName = QtWidgets.QLabel() self.lblPlaceInfoName.setStyleSheet(sty) self.lblPlaceInfoName.setText("") hb.addWidget(self.lblPlaceInfoName) self.placeInfoView = QtWidgets.QTreeView(self) self.placeInfoView.setItemsExpandable(False) self.placeInfoView.setRootIsDecorated(False) self.placeInfoView.setModel(placeitem.Place.selectedPlaceModel) hb.addWidget(self.placeInfoView) hb.setSpacing(0) hb.setContentsMargins(0, 0, 0, 0) self.placeInfoPanel.setWidget(wid) self.addDockWidget(Qt.RightDockWidgetArea, self.placeInfoPanel) # Trains self.trainListPanel = QtWidgets.QDockWidget(self.tr("Trains"), self) self.trainListPanel.setFeatures( QtWidgets.QDockWidget.DockWidgetMovable | QtWidgets.QDockWidget.DockWidgetFloatable) self.trainListPanel.setObjectName("trains_panel") self.trainListView = trainlistview.TrainListView(self) self.simulationLoaded.connect(self.trainListView.setupTrainList) self.trainListPanel.setWidget(self.trainListView) self.addDockWidget(Qt.BottomDockWidgetArea, self.trainListPanel) # Services self.serviceListPanel = QtWidgets.QDockWidget(self.tr("Services"), self) self.serviceListPanel.setFeatures( QtWidgets.QDockWidget.DockWidgetMovable | QtWidgets.QDockWidget.DockWidgetFloatable) self.serviceListPanel.setObjectName("services_panel") self.serviceListView = servicelistview.ServiceListView(self) self.simulationLoaded.connect(self.serviceListView.setupServiceList) self.serviceListPanel.setWidget(self.serviceListView) self.addDockWidget(Qt.BottomDockWidgetArea, self.serviceListPanel) self.tabifyDockWidget(self.serviceListPanel, self.trainListPanel) # Message Logger self.loggerPanel = QtWidgets.QDockWidget(self.tr("Messages"), self) self.loggerPanel.setFeatures( QtWidgets.QDockWidget.DockWidgetMovable | QtWidgets.QDockWidget.DockWidgetFloatable) self.loggerPanel.setObjectName("logger_panel") self.loggerView = QtWidgets.QTreeView(self) self.loggerView.setItemsExpandable(False) self.loggerView.setRootIsDecorated(False) self.loggerView.setHeaderHidden(True) self.loggerView.setPalette(QtGui.QPalette(Qt.black)) self.loggerView.setVerticalScrollMode( QtWidgets.QAbstractItemView.ScrollPerItem) self.loggerPanel.setWidget(self.loggerView) self.addDockWidget(Qt.BottomDockWidgetArea, self.loggerPanel) # =========================================== # Main Board self.board = QtWidgets.QWidget(self) # Canvas self.view = widgets.XGraphicsView(self.board) self.view.setInteractive(True) self.view.setRenderHint(QtGui.QPainter.Antialiasing, False) self.view.setDragMode(QtWidgets.QGraphicsView.ScrollHandDrag) self.view.setPalette(QtGui.QPalette(Qt.black)) self.view.wheelChanged.connect(self.onWheelChanged) # Display self.grid = QtWidgets.QVBoxLayout() self.grid.setContentsMargins(0, 0, 0, 0) self.grid.addWidget(self.view) self.grid.setSpacing(0) self.board.setLayout(self.grid) self.setCentralWidget(self.board) # Editor self.editorOpened = False self.setControlsDisabled(True) self.refreshRecent() settings.restoreWindow(self) if args and args.file: if args.edit: self.openEditor(args.file) # else: # here we call after window is shown QtCore.QTimer.singleShot(100, self.onAfterShow)
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)
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)