editor/

delegates.*

class ts2.editor.delegates.PlacesDelegate[source]

Bases: PyQt5.QtWidgets.QStyledItemDelegate

PlacesDelegate is a delegate that provides a combo box for selecting a Place.

createEditor(parent, option, index)[source]

Creates the editor, i.e. a combo box for selecting a place.

setEditorData(editor, index)[source]

Sets the values from the model in the combo box

setModelData(editor, model, index)[source]

Sets the values from the combo box to the model after editing

updateEditorGeometry(editor, option, index)[source]

Sets the editor geometry.

class ts2.editor.delegates.PropertyValuesDelegate[source]

Bases: PyQt5.QtWidgets.QStyledItemDelegate

PropertyValuesDelegate is a delegate that provides different editing delegates for property values depending on the property propType.

createEditor(parent, option, index)[source]

Creates the editor, i.e. a combo box for selecting an end direction.

setEditorData(editor, index)[source]

Sets the values from the model in the combo box

setModelData(editor, model, index)[source]

Sets the values from the combo box to the model after editing

updateEditorGeometry(editor, option, index)[source]

Sets the editor geometry.

class ts2.editor.delegates.ServicesDelegate[source]

Bases: PyQt5.QtWidgets.QStyledItemDelegate

ServicesDelegate is a delegate that provides a combo box for selecting a Service.

createEditor(parent, option, index)[source]

Creates the editor, i.e. a combo box for selecting a service.

setEditorData(editor, index)[source]

Sets the values from the model in the combo box

setModelData(editor, model, index)[source]

Sets the values from the combo box to the model after editing

updateEditorGeometry(editor, option, index)[source]

Sets the editor geometry.

class ts2.editor.delegates.TrainTypesDelegate[source]

Bases: PyQt5.QtWidgets.QStyledItemDelegate

TrainTypesDelegate is a delegate that provides a combo box for selecting a TrainType.

createEditor(parent, option, index)[source]

Creates the editor, i.e. a combo box for selecting a train type.

setEditorData(editor, index)[source]

Sets the values from the model in the combo box

setModelData(editor, model, index)[source]

Sets the values from the combo box to the model after editing

updateEditorGeometry(editor, option, index)[source]

Sets the editor geometry.

editor.*

class ts2.editor.editor.Editor(options=None, trackItems=None, routes=None, trainTypes=None, services=None, trns=None, messageLogger=None, fileName=None)[source]

Bases: ts2.simulation.Simulation

The Editor class holds all the logic behind the simulation editor. It is a subclass of the Simulation class.

__init__(options=None, trackItems=None, routes=None, trainTypes=None, services=None, trns=None, messageLogger=None, fileName=None)[source]

Constructor for the Editor class

addItemToSelection(ti, selected=True)[source]

Add the trackItem ti to the selection if selected is True and remove it if it is False.

addNewTrain()[source]

Adds an empty train to the editor and returns that train

addRoute()[source]

Adds the route that is selected on the scene to the routes.

Todo

Maybe this should return Error string or None

addService(code)[source]

Adds an empty Service to the services list.

addServiceLine(service, index)[source]

Adds a service line to service at the current index

addTrainType(code)[source]

Adds an empty TrainType to the trainTypes list.

adjustSceneBackground()[source]

Adjusts the EditorSceneBackground to 300px around all trackitems of the scene

checkSimulation()[source]

Checks that the simulation is valid.

:return : a tuple (ok, message) where ok is True if the simulation is
valid, and False otherwise. If the simulation is not valid, message describes the error.
clearSelection()[source]

Clears the graphicsItem selection so that the trackItem selection will get updated.

context

Reimplemented from Simulation to return the EDITOR Context

copyToClipboard()[source]

Copy the current selection to the clipboard

createTrackItem(tiType, pos, posEnd=None)[source]

Creates a TrackItem of type type at the position pos.

Parameters:
  • tiType (str) – The type of the TrackItem to create (class name)
  • pos (QtCore.QPointF) – the position at which to create the item
  • posEnd – the position of the other end of the item (when

applicable) :type posEnd: QtCore.QPointF

deleteRoute(routeNum)[source]

Deletes the route defined by routeNum

deleteSelection()[source]

Delete all the items of the current selection.

deleteService(code)[source]

Deletes the service defined by code

deleteServiceLine(service, index)[source]

Deletes the service line of service defined by index

deleteTrackItem(tiId)[source]

Delete the TrackItem given by tiId.

Delete all links between TrackItems

deleteTrain(index)[source]

Deletes the train assigned to serviceCode

deleteTrainType(code)[source]

Deletes the trainType defined by code

deselectRoute()[source]

Desactivate the selected route in the routes editor

displayedPosition

Returns the position that is currently selected in this editor

expandBackgroundTo(trackItem)[source]

Expands the EditorSceneBackground to 300px around the given TrackItem, if it is not already the case.

exportServicesToFile(fileName)[source]

Exports the services to the file with the given fileName in ts2 services CSV format

getValidPosition()[source]

Returns an arbitrary valid position on the scenery. Returns None, if no valid position has been found.

grid

Returns the size of the grid for placing trackItems

importServicesFromFile(fileName)[source]

Imports the services from the ts2 formatted CSV file given by fileName, deleting any previous service in the editor if any.

initialize(editorWindow)[source]

Initialize the simulation.

invalidateScenery()[source]

Invalidates the scenery, i.e. removes all links between TrackItems, and set sceneryValidated to False

libraryScene

The pseudo-scene for the TrackItem “tool box”

moveTrackItem(tiId, pos, clickPos, point)[source]

Moves the TrackItem with id tiId to position pos.

Also moves the other trackItems that are currently selected.

Parameters:
  • pos (QtCore.QPointF) – position where to move the trackItem
  • clickPos – is the position in the item’s coordinates on which the

mouse was clicked. it is used only if point has “origin” in its name. point is the property of the TrackItem that will be modified.

option(key)[source]

Reimplemented from Simulation so as to provide editor specific defaults.

optionsModel

Returns the OptionsModel of this editor.

pasteFromClipboard()[source]

Paste the items of the clipboard on the scene.

place(placeCode)[source]

Returns the place defined by placeCode. Reimplemented from Simulation so as not to rely on the places dictionary.

placesModel

Returns the PlacesModel of this editor.

prepareRoute(signalId)[source]

Prepares the route starting with the SignalItem given by _selectedSignal and ending at signalId. Sets _selectedSignal to signalId if it is not set. Preparation means: - Check that the route leads to signalId, using the current directions of each PointsItem. - Set _preparedRoute to this route - Highlights the route if valid

realOptions

Returns a dictionary with the real options for the editor, i.e. without the title, description and version fields.

realOptionsLength

Returns the number of realOptions

registerGraphicsItem(graphicItem)[source]

Adds the graphicItem to the scene or to the libraryScene.

Reimplemented from Simulation. :param graphicItem: The graphic Item to add to the scene or library scene (if tiId < 0) :type graphicItem: QtCore.QGraphicsItem

removeItemFromSelection(ti)[source]

Remove the trackItem ti from the selection.

reverseSelectedTrain()[source]

Reverses the selectedTrain direction.

routesModel

Returns the RoutesModel of this editor instance

save()[source]

Saves the data of the simulation to the database

selectRoute(routeNum)[source]

Selects the route given by routeNum in the routes editor.

selectTrain(index)[source]

Selects the train given by index in the train editor, and sets the displayedPosition on the train’s head.

selectedItems

Returns the list of the selected items on the scene.

selectedRoute

Returns the selected route in the route editor.

serviceLinesModel

Returns the ServiceLinesModel of this editor

servicesModel

Returns the ServicesModel of this editor

setSelectedTrainHead(pos)[source]

Sets the trainHead of the selectedTrain to position if valid

setupTrainsFromServices()[source]

Removes all trains instances and creates a train for each relevant service, that is each service which is not following another one (i.e a service which is not the nextService of another service).

trainTypesModel

Returns the TrainTypesModel of this editor

trainsModel

Returns the TrainsModel of this editor

unselectTrains()[source]

Unselect all selected trains, and the associated displayedPosition

updateContext(tabNum)[source]

Updates the context of the editor, depending on the tab selected and given by tabNum.

updateSelection()[source]

Updates the trackItem selection.

validateScenery()[source]

Validates the scenery, i.e. tries to create all links between TrackItems, checks and set sceneryValidated to True if succeeded

class ts2.editor.editor.OptionsModel(editor)[source]

Bases: PyQt5.QtCore.QAbstractTableModel

Model for editing options in the editor.

__init__(editor)[source]

Constructor for the OptionsModel class

columnCount(parent=None, *args, **kwargs)[source]

Returns the number of columns of the model

data(index, role=0)[source]

Returns the data at the given index

flags(index)[source]

Returns the flags of the model

headerData(section, orientation, role=0)[source]

Returns the header labels

rowCount(parent=None, *args, **kwargs)[source]

Returns the number of rows of the model, corresponding to the number of real options.

setData(index, value, role=None)[source]

Updates data when modified in the view

class ts2.editor.editor.WhiteLineItem(x1, y1, x2, y2, parent, scene)[source]

Bases: PyQt5.QtWidgets.QGraphicsLineItem

Shortcut class to make a white line item and add to scene

__init__(x1, y1, x2, y2, parent, scene)[source]

Constructor for the WhiteLineItem class

ts2.editor.editor.json_hook(dct)[source]

Hook method for json.load().

ts2.editor.editor.load(editorWindow, jsonStream)[source]

Loads the simulation from jsonStream and returns it as an Editor.

The logic of loading is the following: 1. We create the graph of objects from json.load(). When initialized, each object stores its JSON data. 2. When all the objects are created, we call the initialize() method of the simulation which calls in turn the initialize() method of each object. This method will create all the missing links between the object and the simulation (and other objects).

ts2.editor.editor.translate(str, str, str disambiguation=None, int n=-1) → str

editorscenebackground.*

class ts2.editor.editorscenebackground.EditorSceneBackground(editor, x, y, width, height)[source]

Bases: PyQt5.QtWidgets.QGraphicsRectItem

The EditorSceneBackground is a graphics item set at the background of the editor scene to handle drag and drop events.

__init__(editor, x, y, width, height)[source]

Constructor for the EditorSceneBackground class

dragEnterEvent(event)[source]

dragEnterEvent handler for the EditorSceneBackground.

dragMoveEvent(event)[source]

dragMoveEvent handler for the EditorSceneBackground.

dropEvent(event)[source]

dropEvent handler for the EditorSceneBackground. If the dragged item is already on this scene, it moves the item. If the dragged item is dragged from the library scene, a new item is created.

mousePressEvent(event)[source]

Event handler for the mousePressEvent. Empties the current item selection if right button clicked.

editorwindow.*

class ts2.editor.editorwindow.EditorWindow(mainWindow, fileName=None)[source]

Bases: PyQt5.QtWidgets.QMainWindow

The EditorWindow class holds the main window of the editor

__init__(mainWindow, fileName=None)[source]

Constructor for the editor window

Params QMainWindow mainWindow:
 the parent main window
Params string fileName:
 Optional filename to open on start
addRouteBtnClicked()[source]

Adds a route in routesView when the add route button is clicked.

addServiceBtnClicked()[source]

Adds an empty service to the editor

addTrainBtnClicked()[source]

Adds an empty train to the editor

addTrainTypeBtnClicked()[source]

Adds an empty stock type to the editor

appendServiceLineBtnClicked()[source]

Appends a service line to this service at the end of the list

closeEvent(closeEvent)[source]

Called when the editor window is closed. Emits the closed signal.

closeSimulation()[source]

Closes the current simulation, and prepares for editing a new one

copyItems()[source]

Copy the current selection to the clipboard.

delRouteBtnClicked()[source]

Deletes the selected route in routesView when the delete route button is clicked.

delServiceBtnClicked()[source]

Removes the currently selected service from the simulation

delServiceLineBtnClicked()[source]

Removes the currently selected service line of this service

delTrainBtnClicked()[source]

Removes the currently selected train

delTrainTypeBtnClicked()[source]

Removes the currently selected stock type from the simulation

deleteItems()[source]

Delete the items of the current selection.

exportServicesBtnClicked()[source]

Calls a save file dialog for the user to give the filanme to which to export the services and asks the editor to actually do the export.

importServicesBtnClicked()[source]

Calls an open file dialog for the user to select the file to import services from and asks the editor to actually do the import

insertServiceLineBtnClicked()[source]

Add a service line to this service after the currently selected

loadSimulation(fileName=None)[source]

Loads the simulation from ts2 file

onSceneryViewWheelChanged(direction)[source]

Handle scrollwheel on canvas, sent from XGraphicsView

onServiceLinesViewSelectionChanged(current=None)[source]

Enable/Disable service line delete button.

onServiceViewSelectionChanged(serviceCode)[source]

Enable/Disable service delete button and service line append/insert buttons.

onTrainTypesSelectionChanged(current=None)[source]

Enables/disables train type delete button.

openReassignServiceWindow(trainId)[source]

To conform to Mainwindow morphism.

openSplitTrainWindow(trainId)[source]

To conform to Mainwindow morphism.

pasteItems()[source]

Paste the items of the clipboard on the scenery.

reverseTrainBtnClicked()[source]

Calls the editor to reverse the train direction (in fact the its trainHead direction)

saveAsSimulation()[source]

Saves the simulation to a different database

saveSimulation()[source]

Saves the simulation

selectAll()[source]

Select all the items on the scene.

setDirty(obj=None)[source]

Sets the diry flag to True, obj is for testing

setPanTool()[source]

Sets the pan tool.

setPropertiesModel()[source]

Sets the TrackPropertiesModel related to the selection on the properties view

setSelectionTool()[source]

Sets the selection tool.

setupTrainsBtnClicked()[source]

Calls the editor to setup the trains list from the services list.

showHideDockWidgets(index)[source]

Hides or Show the dock widgets depending on the selected tab

simulationConnect()[source]

Connects the signals and slots to the simulation.

simulationDisconnect()[source]

Disconnects all the signals of this editor.

updateDescription()[source]

Updates the description in the options hash when input is modified.

updateGeneralTab()[source]

Updates the data in the general tab with the simulation options.

updateMenus(index)[source]

Updates the enabled menu actions depending on the selected tab.

updateTitle()[source]

Updates the title in the options hash when input is modified.

validateSceneryBtnClicked()[source]

Validates the scenery by calling the editor to perform the task.

views.*

class ts2.editor.views.PropertiesView(parent)[source]

Bases: PyQt5.QtWidgets.QTableView

Table view with specific options for editing track items properties in the editor

__init__(parent)[source]

Constructor for the PropertiesView class

class ts2.editor.views.RoutesEditorView(parent)[source]

Bases: PyQt5.QtWidgets.QTableView

Table view with specific options for editing routes in the editor

__init__(parent)[source]

Constructor for the RoutesEditorView class

selectionChanged(selected, deselected)[source]

Called when the user changes the selection. Emits the routeSelected signal

class ts2.editor.views.ServiceLinesEditorView(parent)[source]

Bases: PyQt5.QtWidgets.QTableView

Table view with specific options for editing service lines in the editor.

class ts2.editor.views.ServicesEditorView(parent)[source]

Bases: PyQt5.QtWidgets.QTableView

QTable view with specific options for editing services in the editor

__init__(parent)[source]

Constructor for the ServicesEditorView class

selectionChanged(selected, deselected)[source]

Called when the user changes the selection. Emits the serviceSelected signal

serviceSelected

Signal emitted when a Row selected

setModel(model)[source]

Sets model and also setup cols

class ts2.editor.views.TrainTypesEditorView(parent)[source]

Bases: PyQt5.QtWidgets.QTableView

Table view with specific options for editing trainTypes in the editor

__init__(parent)[source]

Constructor for the TrainTypesEditorView class

class ts2.editor.views.TrainsEditorView(parent)[source]

Bases: PyQt5.QtWidgets.QTableView

Table view with specific options for editing trains in the editor

__init__(parent)[source]

Constructor for the TrainsEditorView class

selectionChanged(selected, deselected)[source]

Called when the user changes the selection. Emits the trainSelected signal

class ts2.editor.views.TrainsGraphicsView(parent)[source]

Bases: PyQt5.QtWidgets.QGraphicsView

Graphics view with specific options for editing train positions in the editor

__init__(parent)[source]

Constructor for the TrainsGraphicsView class