def __init__(self, parent, simulation): super().__init__(parent) self.setWindowTitle( self.tr("Choose a service to assign to this train")) self.serviceListView = servicelistview.ServiceListView(self) self.serviceListView.setupServiceList(simulation) buttonBox = QtGui.QDialogButtonBox(QtGui.QDialogButtonBox.Ok | QtGui.QDialogButtonBox.Cancel) layout = QtGui.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)
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): super().__init__() MainWindow._self = self self.setWindowState(Qt.WindowMaximized) self.setGeometry(100, 100, 800, 600) self.setWindowTitle(self.tr("ts2 - Train Signalling Simulation")) # Simulation self.simulation = None # Actions self.openAction = QtGui.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.loadSimulation) self.saveGameAsAction = QtGui.QAction(self.tr("&Save game as..."), 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) self.propertiesAction = QtGui.QAction(self.tr("&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) self.quitAction = QtGui.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 = QtGui.QAction(self.tr("&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.aboutAction = QtGui.QAction(self.tr("&About TS2..."), self) self.aboutAction.setToolTip(self.tr("About TS2")) self.aboutAction.triggered.connect(self.showAboutBox) self.aboutQtAction = QtGui.QAction(self.tr("About Qt..."), self) self.aboutQtAction.setToolTip(self.tr("About Qt")) self.aboutQtAction.triggered.connect(QtGui.QApplication.aboutQt) # Menu self.fileMenu = self.menuBar().addMenu(self.tr("&File")) self.fileMenu.addAction(self.openAction) self.fileMenu.addAction(self.saveGameAsAction) self.fileMenu.addSeparator() self.fileMenu.addAction(self.propertiesAction) self.fileMenu.addSeparator() self.fileMenu.addAction(self.quitAction) self.editorMenu = self.menuBar().addAction(self.editorAction) self.helpMenu = self.menuBar().addMenu(self.tr("&Help")) self.helpMenu.addAction(self.aboutAction) self.helpMenu.addAction(self.aboutQtAction) self.menuBar().setCursor(Qt.PointingHandCursor) # Dock Widgets self.trainInfoPanel = QtGui.QDockWidget(self.tr("Train Information"), self) self.trainInfoPanel.setFeatures( QtGui.QDockWidget.DockWidgetMovable | QtGui.QDockWidget.DockWidgetFloatable) self.trainInfoView = QtGui.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) self.serviceInfoPanel = QtGui.QDockWidget( self.tr("Service Information"), self) self.serviceInfoPanel.setFeatures( QtGui.QDockWidget.DockWidgetMovable | QtGui.QDockWidget.DockWidgetFloatable) self.serviceInfoView = QtGui.QTreeView(self) self.serviceInfoView.setItemsExpandable(False) self.serviceInfoView.setRootIsDecorated(False) self.serviceInfoPanel.setWidget(self.serviceInfoView) self.addDockWidget(Qt.RightDockWidgetArea, self.serviceInfoPanel) self.placeInfoPanel = QtGui.QDockWidget(self.tr("Station Information"), self) self.placeInfoPanel.setFeatures( QtGui.QDockWidget.DockWidgetMovable | QtGui.QDockWidget.DockWidgetFloatable) self.placeInfoView = QtGui.QTreeView(self) self.placeInfoView.setItemsExpandable(False) self.placeInfoView.setRootIsDecorated(False) self.placeInfoView.setModel(placeitem.Place.selectedPlaceModel) self.placeInfoPanel.setWidget(self.placeInfoView) self.addDockWidget(Qt.RightDockWidgetArea, self.placeInfoPanel) self.trainListPanel = QtGui.QDockWidget(self.tr("Trains"), self) self.trainListPanel.setFeatures( QtGui.QDockWidget.DockWidgetMovable | QtGui.QDockWidget.DockWidgetFloatable) self.trainListView = trainlistview.TrainListView(self) self.simulationLoaded.connect(self.trainListView.setupTrainList) self.trainListPanel.setWidget(self.trainListView) self.addDockWidget(Qt.BottomDockWidgetArea, self.trainListPanel) self.serviceListPanel = QtGui.QDockWidget(self.tr("Services"), self) self.serviceListPanel.setFeatures( QtGui.QDockWidget.DockWidgetMovable | QtGui.QDockWidget.DockWidgetFloatable) 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) self.loggerPanel = QtGui.QDockWidget(self.tr("Messages"), self) self.loggerPanel.setFeatures(QtGui.QDockWidget.DockWidgetMovable | QtGui.QDockWidget.DockWidgetFloatable) self.loggerView = QtGui.QTreeView(self) self.loggerView.setItemsExpandable(False) self.loggerView.setRootIsDecorated(False) self.loggerView.setHeaderHidden(True) self.loggerView.setPalette(QtGui.QPalette(Qt.black)) self.loggerView.setVerticalScrollMode( QtGui.QAbstractItemView.ScrollPerItem) self.loggerPanel.setWidget(self.loggerView) self.addDockWidget(Qt.BottomDockWidgetArea, self.loggerPanel) # board self.board = QtGui.QWidget(self) # Canvas self.view = QtGui.QGraphicsView(self.board) self.view.setInteractive(True) self.view.setRenderHint(QtGui.QPainter.Antialiasing, False) self.view.setDragMode(QtGui.QGraphicsView.ScrollHandDrag) self.view.setPalette(QtGui.QPalette(Qt.black)) # Panel # Loaded with simulation self.panel = widgets.Panel(self.board, self) self.panel.zoomChanged.connect(self.zoom) # Display self.grid = QtGui.QVBoxLayout() self.grid.addWidget(self.view) self.grid.addWidget(self.panel) self.grid.setMargin(0) self.grid.setSpacing(0) self.board.setLayout(self.grid) self.setCentralWidget(self.board) # Editor self.editorOpened = False