Welcome to Spine Toolbox’s User Guide!¶
Spine Toolbox is an application, which provides means to define, manage, and execute complex data processing and computation tasks, such as energy system models.
If you are new to Spine Toolbox, Getting Started section is a good place to start. If you want to run SpineOpt.jl using Spine Toolbox, How to set up SpineOpt.jl provides the step-by-step instructions on how to get started. For information on how to set up Python, Julia, and Gams for Spine Toolbox, see Setting up External Tools. Please see Settings chapter for information on user customizable Spine Toolbox settings. If you need help in understanding the terms we use throughout the app and this User Guide, please check the Terminology section. If you want to contribute to this project, please see the Contribution Guide for Spine Toolbox. The last section contains the complete code reference of Spine Toolbox.
Getting Started¶
Welcome to the Spine Toolbox’s getting started guide. In this guide you will learn two ways of running a “Hello, World!” program on Spine Toolbox. If you need help on how to run SpineOpt.jl using Spine Toolbox, see chapter How to set up SpineOpt.jl.
This chapter introduces the following topics:
Spine Toolbox Interface¶
The central element in Spine Toolbox’s interface is the Design View, which allows you to visualize and manipulate your project workflow. In addition to the Design View there are a few ‘dock widgets’ that provide additional functionality:
Project provides a more concise view of your project, including the Items that are currently in the project, grouped by category: Data Stores, Data Connections, Tools, Views, Importers, Exporters and Manipulators.
Properties provides an interface to interact with the currently selected project item.
Event Log shows relevant messages about user performed actions and the status of executions.
Item Execution Log shows the output of executed project items.
Python console provides an interface to interact with the Python programming language, and also allows Spine Toolbox to execute Python Tools.
Julia console provides an interface to interact with the Julia programming language, and also allows Spine Toolbox to execute Julia Tools.
Executions shows a list of parallel executions available in the project.
In addition to the Design view and the dock widgets, the main window contains a toolbar split into two sections. The Main section contains the project items that you can drag-and-drop onto the Design View and the Execute section has buttons related to executing the project.
Tip
You can drag-and-drop the dock widgets around the screen, customizing the interface at your will. Also, you can select which ones are shown/hidden using either the View/Dock Widgets menu, or the main menu toolbar’s context menu. Spine Toolbox remembers your configuration between sessions. Selecting Restore Dock Widgets from the View/Dock Widgets menu restores the widgets back to their default location.
Tip
Most elements in the Spine Toolbox’s interface are equipped with tool tips. Leave your mouse cursor over an element (button, checkbox, list, etc.) for a moment to make the tool tip appear.
Creating a Project¶
To create a new project, please do one of the following:
From the application main menu, select File -> New project…
Press Ctrl+N.
The Select project directory (New project…) dialog will show up. Browse to a folder of your choice and create a new directory called ‘hello world’ there. Then select the ‘hello world’ directory and press Enter. Spine Toolbox will populate the selected directory with some files and directories it needs to store the project’s data.
Congratulations, you have created your first Spine Toolbox project.
Creating a Tool specification¶
Note
Spine Toolbox is designed to run and connect multiple tools, which are specified using Tool specifications. You may think of a Tool specification as a self-contained program specification including a list of source files, required and optional input files, and expected output files. Once a Tool specification is added to a project, it can then be associated to a Tool item for its execution as part of the project workflow.
Note
Just like the main window, the Tool specification editor consists of dock widgets that you can reorganize however you like.
In the toolbar, click on the icon next to the Tool icon
, to reveal the Tool
specification list. Since there are none in the project yet, click on the
button to open the Tool specification
editor. Follow the instructions below to create a minimal Tool specification:
Type ‘hello_world’ into the Name: field.
Select ‘Python’ from the Tool type dropdown list,
Click on the
button next to the Main program file text in the Program files dock widget. A Create new main program file file browser dialog opens. Name the file hello_world.py and save it e.g. directly to the ‘hello world’ project directory or to a folder of your choice.
We have just created a ‘hello_world.py’ Python script file, but at the moment the file is empty. Spine Toolbox provides an mini IDE where you can view and edit the contents of Tool specification files. Let’s try it out.
Select ‘hello_world.py’ below the Main Program File. Click on the (black) editor dock widget with the title ‘hello_world.py’.
Type in the following:
print("Hello, world!")
Now, whenever hello_world.py is executed, the sentence ‘Hello, World!’ will be printed to the standard output.
The Tool specification editor should be looking similar to this now:

Note that the program file (hello_world.py) and the Tool specification (hello world) now have unsaved changes. This is indicated by the star (*) character next to hello_world.py* and the Tool specification name in the tabbar (hello world*).
Save changes to both by either pressing Ctrl-s or by mouse clicking on Save in the hamburger menu in the upper right hand corner.
Close Tool specification editor by pressing Alt-F4 or by clicking on ‘X’ in the top right hand corner of the window.
Your main window should look similar to this now.

Tool specifications are saved in JSON format by default into a dedicated directory under the project directory. If you want you can open the newly created hello_world.json file by clicking on the file path in the Event log message. The file will open in an external editor provided that you have selected a default program for files with the .json extension (e.g in Windows 10 you can do this in Windows Settings->Apps->Default apps). In general, you don’t need to worry about the contents of the JSON Tool specification files. Editing these is done under the hood by the app.
If you want to save the ‘hello_world.json’ file somewhere else, you can do this by clicking the white [Change] link after the path in the Event Log.
Tip
Saving the Tool specification into a file allows you to add and use the same Tool specification in
another project. To do this, you just need to click add tool specification from file… button
() in the toolbar and select the tool specification file (.json) from your system.
Congratulations, you have just created your first Tool specification.
Adding a Tool item to the project¶
Note
The Tool project item is used to run Tool specifications.
Let’s add a Tool item to our project, so that we’re able to run the Tool specification we created above.
To add a Tool item drag-and-drop the Tool icon from the toolbar onto the Design View.
The Add Tool form will popup. Change name of the Tool to ‘say hello world’, and select ‘hello_world’ from the dropdown list just below, and click Ok. Now you should see the newly added Tool item as an icon in the Design View, and also as an entry in the Project dock widget, Items list, under the ‘Tools’ category. It should look similar to this:

Another way to do the same thing is to drag the with the ‘hello world’ text from the toolbar onto
the Design View. Similarly, the Add Tool form will popup but the ‘hello world’ tool specification is already
selected from the dropdown list.
Note
The Tool specification is now saved to disk but the project itself is not. Remember to save the project every once in a while when you are working. You can do this from the main window File->Save project button or by pressing Ctrl-s when the main window is active.
Executing a Tool¶
Select the ‘say hello world’ Tool on Design View, and you will see its Properties in the dedicated dock widget. It looks similar to this:

Press execute project button on the toolbar. This will execute the ‘say hello world’ Tool project item
which now has the ‘hello world’ Tool specification associated to it. In actuality, this will run the main program
file hello_world.py in a dedicated process.
Once the execution is finished, you can see the item execution details in the Item Execution Log and the details about the whole execution in Event Log.

Note
For more information about execution modes in Spine Toolbox, please see Setting up External Tools for help.
Congratulations, you just executed your first Spine Toolbox project.
Editing a Tool specification¶
To make things more interesting, we will now specify an input file for our ‘hello_world’ Tool specification.
Note
Input files specified in the Tool specification can be used by the program source files, to obtain input data for the Tool’s execution. When executed, a Tool item looks for input files in Data Connection, Data Store, Gdx Exporter, Exporter, and Data Transformer project items connected to its input.
Open the Tool specification editor for the ‘hello world’ Tool spec. You can do this for example, by double-clicking the ‘say hello world’ Tool, or by selecting Edit specification from the ‘hello world’ Tool specification context menu in the toolbar, or from the ‘say hello world’ Tool context-menu (Specification…->Edit specification).
In Input & Output files dock widget, click the button next to the Input Files text. A dialog appears,
that lets you enter a name for an input file. Type ‘input.txt’ and press Enter.
So far so good. Now let’s use this input file in our program. Still in the Tool specification editor, replace the text in the main program file (hello_world.py), with the following:
with open("input.txt") as input_file:
print(input_file.read())
Now, whenever hello_world.py is executed, it will look for a file called ‘input.txt’ in the current directory, and print its content to the standard output.
The editor should now look like this:

Save the specification and close the editor by pressing Ctrl-s and then Alt-F4.
Note
See Tool specification editor for more information on editing Tool specifications.
Back in the main window, note the exclamation mark on the Tool icon in Design View, if you hover the mouse over
this mark, you will see a tooltip telling you in detail what is wrong. If you want you can try and execute the
Tool anyway by pressing in the toolbar. The execution will fail. because the file ‘input.txt’ is not
made available for the Tool:

Adding a Data Connection item to the project¶
Note
The Data Connection item is used to hold generic data files, so that other items, notably Importer and Tool items, can make use of that data.
Let’s add a Data Connection item to our project, so that we’re able to pass the file ‘input.txt’ to
‘say hello world’. To add a Data Connection item, drag-and-drop the Data Connection icon () from the toolbar
onto the Design View.
The Add Data Connection form will show up. Type ‘pass input txt’ in the name field and click Ok. The newly added Data Connection item is now in the Design View, and also as an entry in the Project dock widgets items list, under the ‘Data Connections’ category. It should look similar to this:
Adding data files to a Data Connection¶
Select the ‘pass input txt’ Data Connection item to view its properties in the Properties dock widget.

Right click anywhere within the Data box and select New file… from the context menu. When prompted to enter a name for the new file, type ‘input.txt’ and click Ok.
There’s now a new file in the Data list:

Double click this file to open it in your default text editor. Then enter the following into the file’s content:
Hello again, World!
Save the file.
Connecting project items¶
As mentioned above, a Tool item looks for input files in Data Connections connected to its input. Thus you now need to create a connection from ‘pass input txt’ to ‘say hello world’. To do this, click on one of the connector slots at the edges of ‘pass input txt’ in the Design view, and then on a similar slot in ‘say hello world’. This will create an arrow pointing from one to another, as seen below:

Press once again. The project will be executed successfully this time:

That’s all for now. I hope you’ve enjoyed following this guide as much as I enjoyed writing it. See you next time.
Where to next: If you need help on how to set up and run SpineOpt.jl using Spine Toolbox, see chapter How to set up SpineOpt.jl.
How to set up SpineOpt.jl¶
Install Julia (v1.2 or later) from https://julialang.org/downloads/ if you don’t have one. See latest SpineOpt.jl Julia compatibility information here.
Start Spine Toolbox
Create a new project (File->New project…)
Select File->Settings from the main menu and open the Tools page.
Set a path to a Julia executable to the appropriate line edit (e.g. C:\Julia-1.5.4\bin\julia.exe). Your selections should look similar to this now.
[Optional] If you want to install and run SpineOpt in a specific Julia project environment (the place for Project.toml and Manifest.toml), you can set the path to the environment folder to the line edit just below the Julia executable (the one that says Using Julia default project).
Next, you need to install SpineOpt.jl package for the Julia you just selected for Spine Toolbox. You can do this manually by following the instructions or you can install SpineOpt.jl by clicking the Add/Update SpineOpt button. After clicking the button, an install/upgrade Spineopt wizard appears. Click Next twice and finally Install SpineOpt. Wait until the process has finished and you are greeted with this screen.
Close the wizard.
Click Ok to close the Settings window
Back in the main window, select PlugIns->Install plugin… from the menu
Select SpineOpt and click Ok. After a short while, a red SpineOpt Plugin Toolbar appears on the main window.
Spine Toolbox and Julia are now correctly set up for running SpineOpt.jl. Next step is to Create a project workflow using SpineOpt.jl (takes you to SpineOpt documentation). See also Tutorials for more advanced use cases. For more information on how to select a specific Python or Julia version, see Setting up External Tools).
Note
The SpineOpt Plugin Toolbar contains two predefined Tools that make use of SpineOpt.jl. The SpineOpt Plugin is not a requirement to run SpineOpt.jl, they are provided just for convenience and as examples to get you started quickly.
Tutorials¶
Welcome to the Spine Toolbox’s tutorials page. The following tutorials are available:
Case Study A5 tutorial¶
Welcome to Spine Toolbox’s Case Study A5 tutorial. Case Study A5 is one of the Spine Project case studies designed to verify Toolbox and Model capabilities. To this end, it reproduces an already existing study about hydropower on the Skellefte river, which models one week of operation of the fifteen power stations along the river.
This tutorial provides a step-by-step guide to run Case Study A5 on Spine Toolbox and is organized as follows:
Introduction¶
Model assumptions¶
For each power station in the river, the following information is known:
The capacity, or maximum electricity output. This datum also provides the maximum water discharge as per the efficiency curve (see next point).
The efficiency curve, or conversion rate from water to electricity. In this study, a piece-wise linear efficiency with two segments is assumed. Moreover, this curve is monotonically decreasing, i.e., the efficiency in the first segment is strictly greater than the efficiency in the second segment.
The maximum magazine level, or amount of water that can be stored in the reservoir.
The magazine level at the beginning of the simulation period, and at the end.
The minimum amount of water that the plant needs to discharge at every hour. This is usually zero (except for one of the plants).
The minimum amount of water that needs to be spilled at every hour. Spilled water does not go through the turbine and thus does not serve to produce electricity; it just helps keeping the magazine level at bay.
The downstream plant, or next plant in the river course.
The time that it takes for the water to reach the downstream plant. This time can be different depending on whether the water is discharged (goes through the turbine) or spilled.
The local inflow, or amount of water that naturally enters the reservoir at every hour. In this study, it is assumed constant over the entire simulation period.
The hourly average water discharge. It is assumed that before the beginning of the simulation, this amount of water has constantly been discharged at every hour.
The system is operated so as to maximize total profit over the week, while respecting capacity constraints, maximum magazine level constrains, and so on. Hourly profit per plant is simply computed as the product of the electricity price and the production, minus a penalty for changes on the water discharge in two consecutive hours. This penalty is computed as the product of a constant penalty factor, common to all plants, and the absolute value of the difference in discharge with respect to the previous hour.
Modelling choices¶
The model of the electric system is fairly simple, only two elements are needed:
A common electricity node.
A load unit that takes electricity from that node.
On the contrary, the model of the river system is more detailed. Each power station in the river is modelled using the following elements:
An upper water node, located at the entrance of the station.
A lower water node, located at the exit of the station.
A power plant unit, that discharges water from the upper node into the lower node, and feeds electricity produced in the process to the common electricity node.
A spillway connection, that takes spilled water from the upper node and releases it to the downstream upper node.
A discharge connection, that takes water from the lower node and releases it to the downstream upper node.
Below is a schematic of the model. For clarity, only the Rebnis station is presented in full detail:

Guide¶
Installing requirements¶
Note
This tutorial is written for latest Spine Toolbox and SpineOpt development versions.
Follow the instructions here to install Spine Toolbox and SpineOpt in your system.
Creating a new project¶
Each Spine Toolbox project resides in its own directory, where the user can store data, programming scripts and other necessary material. The Toolbox application also creates its own special subdirectory .spinetoolbox, for project settings, etc.
To create a new project, select File -> New project… from Spine Toolbox main menu. Browse to a location where you want to create the project and create a new folder for it, called e.g. ‘Case Study A5’, and then click Open.
Configuring SpineOpt¶
To use SpineOpt in your project, you need to create a Tool specification for it. Click on the small arrow next to the Tool icon
(in the Main section of the tool bar), and press New… The Tool specification editor will popup:
Type ‘SpineOpt’ as the name of the specification and select ‘Julia’ as the type. Unselect Execute in work directory.
Press
next to Main program file to create a new Julia file. Enter a file name, e.g. ‘run_spineopt.jl’, and click Save.
Back in the Tool specification editor form, select the file you just created under Main program file. Then, enter the following text in the text editor to the right:
using SpineOpt run_spineopt(ARGS...)
At this point, the form should be looking similar to this:
Press Ctrl+S to save everything, then close the Tool specification editor.
Setting up project¶
Drag the Data Store icon
from the tool bar and drop it into the Design View. This will open the Add Data Store dialog. Type ‘input’ as the Data Store name and click Ok.
Repeat the above procedure to create a Data Store called ‘output’.
Create a database for the ‘input‘ Data Store:
Select the input Data Store item in the Design View to show the Data Store Properties (on the right side of the window, usually).
In Data Store Properties, select the sqlite dialect at the top, and hit New Spine db.
Repeat the above procedure to create a database for the ‘output’ Data Store.
Click on the small arrow next to the Tool icon
and drag the ‘SpineOpt’ item from the drop-down menu into the Design View. This will open the Add Tool dialog. Type ‘SpineOpt’ as the Tool name and click Ok.
Note
Each item in the Design view is equipped with three connectors (the small squares at the item boundaries).
Click on one of ‘input’ connectors and then on one of ‘SpineOpt’ connectors. This will create a connection from the former to the latter.
Repeat the procedure to create a connection from SpineOpt to output. It should look something like this:
Setup the arguments for the SpineOpt Tool:
Select the SpineOpt Tool to show the Tool Properties (on the right side of the window, usually). You should see two elements listed under Available resources,
{db_url@input}
and{db_url@output}
.Drag the first resource,
{db_url@input}
, and drop it in Command line arguments, just as shown in the image below.Drag the second resource,
{db_url@output}
, and drop it right below the previous one. The panel should be now looking like this:Double-check that the order of the arguments is correct: first,
{db_url@input}
, and second,{db_url@output}
. (You can drag and drop to reorganize them if needed.)
From the main menu, select File -> Save project.
Entering input data¶
Importing the SpineOpt database template¶
Download the SpineOpt database template (right click on the link, then select Save link as…)
Select the input Data Store item in the Design View.
Go to Data Store Properties and hit Open editor. This will open the newly created database in the Spine DB editor, looking similar to this:
Note
The Spine DB editor is a dedicated interface within Spine Toolbox for visualizing and managing Spine databases.
Press Alt + F to display the main menu, select File -> Import…, and then select the template file you previously downloaded. The contents of that file will be imported into the current database, and you should then see classes like ‘commodity’, ‘connection’ and ‘model’ under the root node in the Object tree (on the left).
From the main menu, select Session -> Commit. Enter ‘Import SpineOpt template’ as message in the popup dialog, and click Commit.
Note
The SpineOpt template contains the fundamental object and relationship classes, as well as parameter definitions, that SpineOpt recognizes and expects. You can think of it as the generic structure of the model, as opposed to the specific data for a particular instance. In the remainder of this section, we will add that specific data for the Skellefte river.
Creating objects¶
Add power plants to the model. Create objects of class
unit
as follows:Select the list of plant names from the text-box below and copy it to the clipboard (Ctrl+C):
Rebnis_pwr_plant Sadva_pwr_plant Bergnäs_pwr_plant Slagnäs_pwr_plant Bastusel_pwr_plant Grytfors_pwr_plant Gallejaur_pwr_plant Vargfors_pwr_plant Rengård_pwr_plant Båtfors_pwr_plant Finnfors_pwr_plant Granfors_pwr_plant Krångfors_pwr_plant Selsfors_pwr_plant Kvistforsen_pwr_plant
Go to Object tree (on the top left of the window, usually), right-click on
unit
and select Add objects from the context menu. This will open the Add objects dialog.Select the first cell under the object name column and press Ctrl+V. This will paste the list of plant names from the clipboard into that column; the object class name column will be filled automatically with ‘unit‘. The form should now be looking similar to this:
Click Ok.
Back in the Spine DB editor, under Object tree, double click on
unit
to confirm that the objects are effectively there.Commit changes with the message ‘Add power plants’.
Add discharge and spillway connections. Create objects of class
connection
with the following names:Rebnis_to_Bergnäs_disch Sadva_to_Bergnäs_disch Bergnäs_to_Slagnäs_disch Slagnäs_to_Bastusel_disch Bastusel_to_Grytfors_disch Grytfors_to_Gallejaur_disch Gallejaur_to_Vargfors_disch Vargfors_to_Rengård_disch Rengård_to_Båtfors_disch Båtfors_to_Finnfors_disch Finnfors_to_Granfors_disch Granfors_to_Krångfors_disch Krångfors_to_Selsfors_disch Selsfors_to_Kvistforsen_disch Kvistforsen_to_downstream_disch Rebnis_to_Bergnäs_spill Sadva_to_Bergnäs_spill Bergnäs_to_Slagnäs_spill Slagnäs_to_Bastusel_spill Bastusel_to_Grytfors_spill Grytfors_to_Gallejaur_spill Gallejaur_to_Vargfors_spill Vargfors_to_Rengård_spill Rengård_to_Båtfors_spill Båtfors_to_Finnfors_spill Finnfors_to_Granfors_spill Granfors_to_Krångfors_spill Krångfors_to_Selsfors_spill Selsfors_to_Kvistforsen_spill Kvistforsen_to_downstream_spill
Add water nodes. Create objects of class
node
with the following names:Rebnis_upper Sadva_upper Bergnäs_upper Slagnäs_upper Bastusel_upper Grytfors_upper Gallejaur_upper Vargfors_upper Rengård_upper Båtfors_upper Finnfors_upper Granfors_upper Krångfors_upper Selsfors_upper Kvistforsen_upper Rebnis_lower Sadva_lower Bergnäs_lower Slagnäs_lower Bastusel_lower Grytfors_lower Gallejaur_lower Vargfors_lower Rengård_lower Båtfors_lower Finnfors_lower Granfors_lower Krångfors_lower Selsfors_lower Kvistforsen_lower
Next, create the following objects (all names in lower-case):
instance
of classmodel
.water
andelectricity
of classcommodity
.electricity_node
of classnode
.electricity_load
of classunit
.some_week
of classtemporal_block
.deterministic
of classstochastic_structure
.realization
of classstochastic_scenario
.
Finally, create the following objects to get results back from Spine Opt (again, all names in lower-case):
my_report
of classreport
.unit_flow
,connection_flow
, andnode_state
of classoutput
.
Note
To modify an object after you enter it, right click on it and select Edit… from the context menu.
Specifying object parameter values¶
Specify the general behaviour of our model. Enter
model
parameter values as follows:Select the model parameter value data from the text-box below and copy it to the clipboard (Ctrl+C):
model instance duration_unit Base "hour" model instance model_end Base {"type": "date_time", "data": "2019-01-08T00:00:00"} model instance model_start Base {"type": "date_time", "data": "2019-01-01T00:00:00"}
Go to Object parameter value (on the top-center of the window, usually). Make sure that the columns in the table are ordered as follows:
object_class_name | object_name | parameter_name | alternative_name | value | database
Select the first empty cell under
object_class_name
and press Ctrl+V. This will paste the model parameter value data from the clipboard into the table. The form should be looking like this:
Specify the resolution of our temporal block. Repeat the same procedure with the data below:
temporal_block some_week resolution Base {"type": "duration", "data": "1h"}
Specify the behaviour of all system nodes. Repeat the same procedure with the data below, where:
demand
represents the local inflow (negative in most cases).fix_node_state
represents fixed reservoir levels (at the beginning and the end).has_state
indicates whether or not the node is a reservoir (true for all the upper nodes).state_coeff
is the reservoir ‘efficienty’ (always 1, meaning that there aren’t any loses).node_state_cap
is the maximum level of the reservoirs.
node Bastusel_upper demand Base -0.2579768519 node Bergnäs_upper demand Base -22.29 node Båtfors_upper demand Base -2 node Finnfors_upper demand Base 0 node Gallejaur_upper demand Base 15.356962963 node Granfors_upper demand Base 0 node Grytfors_upper demand Base -3.78 node Krångfors_upper demand Base 0 node Kvistforsen_upper demand Base -1.3273809524 node Rebnis_upper demand Base -3.68 node Rengård_upper demand Base -10.37 node Sadva_upper demand Base -5.43 node Selsfors_upper demand Base 0 node Slagnäs_upper demand Base 0 node Vargfors_upper demand Base -3.5584953704 node Bastusel_upper fix_node_state Base {"type": "time_series", "data": {"2019-01-01T00:00:00": 5581.44, "2019-01-01T01:00:00": NaN, "2019-01-07T23:00:00": 5417.28}} node Bergnäs_upper fix_node_state Base {"type": "time_series", "data": {"2019-01-01T00:00:00": 114543.6, "2019-01-01T01:00:00": NaN, "2019-01-07T23:00:00": 105898.8}} node Båtfors_upper fix_node_state Base {"type": "time_series", "data": {"2019-01-01T00:00:00": 1117.2, "2019-01-01T01:00:00": NaN, "2019-01-07T23:00:00": 891.1}} node Finnfors_upper fix_node_state Base {"type": "time_series", "data": {"2019-01-01T00:00:00": 234.0, "2019-01-01T01:00:00": NaN, "2019-01-07T23:00:00": 234.0}} node Gallejaur_upper fix_node_state Base {"type": "time_series", "data": {"2019-01-01T00:00:00": 1224.0, "2019-01-01T01:00:00": NaN, "2019-01-07T23:00:00": 2808.0}} node Granfors_upper fix_node_state Base {"type": "time_series", "data": {"2019-01-01T00:00:00": 232.4, "2019-01-01T01:00:00": NaN, "2019-01-07T23:00:00": 212.8}} node Grytfors_upper fix_node_state Base {"type": "time_series", "data": {"2019-01-01T00:00:00": 1060.8, "2019-01-01T01:00:00": NaN, "2019-01-07T23:00:00": 1110.72}} node Krångfors_upper fix_node_state Base {"type": "time_series", "data": {"2019-01-01T00:00:00": 201.3, "2019-01-01T01:00:00": NaN, "2019-01-07T23:00:00": 207.9}} node Kvistforsen_upper fix_node_state Base {"type": "time_series", "data": {"2019-01-01T00:00:00": 769.066666704, "2019-01-01T01:00:00": NaN, "2019-01-07T23:00:00": 560.0}} node Rebnis_upper fix_node_state Base {"type": "time_series", "data": {"2019-01-01T00:00:00": 70243.509200184, "2019-01-01T01:00:00": NaN, "2019-01-07T23:00:00": 59524.122689676}} node Rengård_upper fix_node_state Base {"type": "time_series", "data": {"2019-01-01T00:00:00": 1022.0, "2019-01-01T01:00:00": NaN, "2019-01-07T23:00:00": 770.0}} node Sadva_upper fix_node_state Base {"type": "time_series", "data": {"2019-01-01T00:00:00": 99057.7777728, "2019-01-01T01:00:00": NaN, "2019-01-07T23:00:00": 93831.111108}} node Selsfors_upper fix_node_state Base {"type": "time_series", "data": {"2019-01-01T00:00:00": 40.0, "2019-01-01T01:00:00": NaN, "2019-01-07T23:00:00": 200.0}} node Slagnäs_upper fix_node_state Base {"type": "time_series", "data": {"2019-01-01T00:00:00": 384.0, "2019-01-01T01:00:00": NaN, "2019-01-07T23:00:00": 537.6}} node Vargfors_upper fix_node_state Base {"type": "time_series", "data": {"2019-01-01T00:00:00": 3386.76, "2019-01-01T01:00:00": NaN, "2019-01-07T23:00:00": 3847.68}} node Bastusel_upper has_state Base true node Bergnäs_upper has_state Base true node Båtfors_upper has_state Base true node Finnfors_upper has_state Base true node Gallejaur_upper has_state Base true node Granfors_upper has_state Base true node Grytfors_upper has_state Base true node Krångfors_upper has_state Base true node Kvistforsen_upper has_state Base true node Rebnis_upper has_state Base true node Rengård_upper has_state Base true node Sadva_upper has_state Base true node Selsfors_upper has_state Base true node Slagnäs_upper has_state Base true node Vargfors_upper has_state Base true node Bastusel_upper state_coeff Base 1 node Bergnäs_upper state_coeff Base 1 node Båtfors_upper state_coeff Base 1 node Finnfors_upper state_coeff Base 1 node Gallejaur_upper state_coeff Base 1 node Granfors_upper state_coeff Base 1 node Grytfors_upper state_coeff Base 1 node Krångfors_upper state_coeff Base 1 node Kvistforsen_upper state_coeff Base 1 node Rebnis_upper state_coeff Base 1 node Rengård_upper state_coeff Base 1 node Sadva_upper state_coeff Base 1 node Selsfors_upper state_coeff Base 1 node Slagnäs_upper state_coeff Base 1 node Vargfors_upper state_coeff Base 1 node Bastusel_upper node_state_cap Base 8208 node Bergnäs_upper node_state_cap Base 216120 node Båtfors_upper node_state_cap Base 1330 node Finnfors_upper node_state_cap Base 300 node Gallejaur_upper node_state_cap Base 3600 node Granfors_upper node_state_cap Base 280 node Grytfors_upper node_state_cap Base 1248 node Krångfors_upper node_state_cap Base 330 node Kvistforsen_upper node_state_cap Base 1120 node Rebnis_upper node_state_cap Base 205560 node Rengård_upper node_state_cap Base 1400 node Sadva_upper node_state_cap Base 168000 node Selsfors_upper node_state_cap Base 500 node Slagnäs_upper node_state_cap Base 768 node Vargfors_upper node_state_cap Base 4008
Establishing relationships¶
Tip
To enter the same text on several cells, copy the text into the clipboard, then select all target cells and press Ctrl+V.
Establish that (i) power plant units receive water from the station’s upper node, and (ii) the electricity load unit takes electricity from the common electricity node. Create relationships of class
unit__from_node
as follows:Select the list of unit and node names from the text-box below and copy it to the clipboard (Ctrl+C).
Rebnis_pwr_plant Rebnis_upper Sadva_pwr_plant Sadva_upper Bergnäs_pwr_plant Bergnäs_upper Slagnäs_pwr_plant Slagnäs_upper Bastusel_pwr_plant Bastusel_upper Grytfors_pwr_plant Grytfors_upper Gallejaur_pwr_plant Gallejaur_upper Vargfors_pwr_plant Vargfors_upper Rengård_pwr_plant Rengård_upper Båtfors_pwr_plant Båtfors_upper Finnfors_pwr_plant Finnfors_upper Granfors_pwr_plant Granfors_upper Krångfors_pwr_plant Krångfors_upper Selsfors_pwr_plant Selsfors_upper Kvistforsen_pwr_plant Kvistforsen_upper electricity_load electricity_node
Go to Relationship tree (on the bottom left of the window, usually), right-click on
unit__from_node
and select Add relationships from the context menu. This will open the Add relationships dialog.Select the first cell under the unit column and press Ctrl+V. This will paste the list of plant and node names from the clipboard into the table. The form should be looking like this:
Click Ok.
Back in the Spine DB editor, under Relationship tree, double click on
unit__from_node
to confirm that the relationships are effectively there.From the main menu, select Session -> Commit to open the Commit changes dialog. Enter ‘Add from nodes of power plants‘ as the commit message and click Commit.
Establish that (i) power plant units release water to the station’s lower node, and (ii) power plant units inject electricity to the common electricity node. Repeate the above procedure to create relationships of class
unit__to_node
with the following data:Rebnis_pwr_plant Rebnis_lower Sadva_pwr_plant Sadva_lower Bergnäs_pwr_plant Bergnäs_lower Slagnäs_pwr_plant Slagnäs_lower Bastusel_pwr_plant Bastusel_lower Grytfors_pwr_plant Grytfors_lower Gallejaur_pwr_plant Gallejaur_lower Vargfors_pwr_plant Vargfors_lower Rengård_pwr_plant Rengård_lower Båtfors_pwr_plant Båtfors_lower Finnfors_pwr_plant Finnfors_lower Granfors_pwr_plant Granfors_lower Krångfors_pwr_plant Krångfors_lower Selsfors_pwr_plant Selsfors_lower Kvistforsen_pwr_plant Kvistforsen_lower Rebnis_pwr_plant electricity_node Sadva_pwr_plant electricity_node Bergnäs_pwr_plant electricity_node Slagnäs_pwr_plant electricity_node Bastusel_pwr_plant electricity_node Grytfors_pwr_plant electricity_node Gallejaur_pwr_plant electricity_node Vargfors_pwr_plant electricity_node Rengård_pwr_plant electricity_node Båtfors_pwr_plant electricity_node Finnfors_pwr_plant electricity_node Granfors_pwr_plant electricity_node Krångfors_pwr_plant electricity_node Selsfors_pwr_plant electricity_node Kvistforsen_pwr_plant electricity_node
Note
At this point, you might be wondering what’s the purpose of the
unit__node__node
relationship class. Shouldn’t it be enough to haveunit__from_node
andunit__to_node
to represent the topology of the system? The answer is yes; but in addition to topology, we also need to represent the conversion process that happens in the unit, where the water from one node is turned into electricty for another node. And for this purpose, we use a relationship parameter value on theunit__node__node
relationships (see Specifying relationship parameter values).Establish that (i) discharge connections take water from the lower node of the upstream station, and (ii) spillway connections take water from the upper node of the upstream station. Repeat the procedure to create relationships of class
connection__from_node
with the following data:Bastusel_to_Grytfors_disch Bastusel_lower Bergnäs_to_Slagnäs_disch Bergnäs_lower Båtfors_to_Finnfors_disch Båtfors_lower Finnfors_to_Granfors_disch Finnfors_lower Gallejaur_to_Vargfors_disch Gallejaur_lower Granfors_to_Krångfors_disch Granfors_lower Grytfors_to_Gallejaur_disch Grytfors_lower Krångfors_to_Selsfors_disch Krångfors_lower Kvistforsen_to_downstream_disch Kvistforsen_lower Rebnis_to_Bergnäs_disch Rebnis_lower Rengård_to_Båtfors_disch Rengård_lower Sadva_to_Bergnäs_disch Sadva_lower Selsfors_to_Kvistforsen_disch Selsfors_lower Slagnäs_to_Bastusel_disch Slagnäs_lower Vargfors_to_Rengård_disch Vargfors_lower Bastusel_to_Grytfors_spill Bastusel_upper Bergnäs_to_Slagnäs_spill Bergnäs_upper Båtfors_to_Finnfors_spill Båtfors_upper Finnfors_to_Granfors_spill Finnfors_upper Gallejaur_to_Vargfors_spill Gallejaur_upper Granfors_to_Krångfors_spill Granfors_upper Grytfors_to_Gallejaur_spill Grytfors_upper Krångfors_to_Selsfors_spill Krångfors_upper Kvistforsen_to_downstream_spill Kvistforsen_upper Rebnis_to_Bergnäs_spill Rebnis_upper Rengård_to_Båtfors_spill Rengård_upper Sadva_to_Bergnäs_spill Sadva_upper Selsfors_to_Kvistforsen_spill Selsfors_upper Slagnäs_to_Bastusel_spill Slagnäs_upper Vargfors_to_Rengård_spill Vargfors_upper
Establish that both discharge and spillway connections release water onto the upper node of the downstream station. Repeat the procedure to create
connection__to_node
relationships with the following data:Bastusel_to_Grytfors_disch Grytfors_upper Bastusel_to_Grytfors_spill Grytfors_upper Bergnäs_to_Slagnäs_disch Slagnäs_upper Bergnäs_to_Slagnäs_spill Slagnäs_upper Båtfors_to_Finnfors_disch Finnfors_upper Båtfors_to_Finnfors_spill Finnfors_upper Finnfors_to_Granfors_disch Granfors_upper Finnfors_to_Granfors_spill Granfors_upper Gallejaur_to_Vargfors_disch Vargfors_upper Gallejaur_to_Vargfors_spill Vargfors_upper Granfors_to_Krångfors_disch Krångfors_upper Granfors_to_Krångfors_spill Krångfors_upper Grytfors_to_Gallejaur_disch Gallejaur_upper Grytfors_to_Gallejaur_spill Gallejaur_upper Krångfors_to_Selsfors_disch Selsfors_upper Krångfors_to_Selsfors_spill Selsfors_upper Rebnis_to_Bergnäs_disch Bergnäs_upper Rebnis_to_Bergnäs_spill Bergnäs_upper Rengård_to_Båtfors_disch Båtfors_upper Rengård_to_Båtfors_spill Båtfors_upper Sadva_to_Bergnäs_disch Bergnäs_upper Sadva_to_Bergnäs_spill Bergnäs_upper Selsfors_to_Kvistforsen_disch Kvistforsen_upper Selsfors_to_Kvistforsen_spill Kvistforsen_upper Slagnäs_to_Bastusel_disch Bastusel_upper Slagnäs_to_Bastusel_spill Bastusel_upper Vargfors_to_Rengård_disch Rengård_upper Vargfors_to_Rengård_spill Rengård_upper
Note
At this point, you might be wondering what’s the purpose of the
connection__node__node
relationship class. Shouldn’t it be enough to haveconnection__from_node
andconnection__to_node
to represent the topology of the system? The answer is yes; but in addition to topology, we also need to represent the delay in the river branches. And for this purpose, we use a relationship parameter value on theconnection__node__node
relationships (see Specifying relationship parameter values).Establish that water nodes balance water and the electricity node balances electricity. Repeat the procedure to create
node__commodity
relationships between all upper and lower reservoir nodes and thewater
commodity, as well as between theelectricity_node
andelectricity
.Rebnis_upper water Sadva_upper water Bergnäs_upper water Slagnäs_upper water Bastusel_upper water Grytfors_upper water Gallejaur_upper water Vargfors_upper water Rengård_upper water Båtfors_upper water Finnfors_upper water Granfors_upper water Krångfors_upper water Selsfors_upper water Kvistforsen_upper water Rebnis_lower water Sadva_lower water Bergnäs_lower water Slagnäs_lower water Bastusel_lower water Grytfors_lower water Gallejaur_lower water Vargfors_lower water Rengård_lower water Båtfors_lower water Finnfors_lower water Granfors_lower water Krångfors_lower water Selsfors_lower water Kvistforsen_lower water electricity_node electricity
Establish that all nodes are balanced at each time slice in the one week horizon. Create relationships of class
model__default_temporal_block
between the modelinstance
and the temporal_blocksome_week
.Establish that this model is deterministic. Create a relationships of class
model__default_stochastic_structure
between the modelinstance
anddeterministic
, and a relationship of classstochastic_structure__stochastic_scenario
betweendeterministic
andrealization
.Finally, create one relationship of class
report__output
betweenmy_report
and each of the followingoutput
objects:unit_flow
,connection_flow
, andnode_state
, as well as one relationship of classmodel__report
betweeninstance
andmy_report
. This is so results from running Spine Opt are written to the ouput database.
Specifying relationship parameter values¶
Specify (i) the capacity of hydro power plants, and (ii) the variable operating cost of the electricity unit (equal to the negative electricity price). Enter
unit__from_node
parameter values as follows:Select the parameter value data from the text-box below and copy it to the clipboard (Ctrl+C):
unit__from_node Bastusel_pwr_plant,Bastusel_upper unit_capacity Base 127.5 unit__from_node Bergnäs_pwr_plant,Bergnäs_upper unit_capacity Base 120 unit__from_node Båtfors_pwr_plant,Båtfors_upper unit_capacity Base 210 unit__from_node Finnfors_pwr_plant,Finnfors_upper unit_capacity Base 176.25 unit__from_node Gallejaur_pwr_plant,Gallejaur_upper unit_capacity Base 228.75 unit__from_node Granfors_pwr_plant,Granfors_upper unit_capacity Base 180 unit__from_node Grytfors_pwr_plant,Grytfors_upper unit_capacity Base 123.75 unit__from_node Krångfors_pwr_plant,Krångfors_upper unit_capacity Base 180 unit__from_node Kvistforsen_pwr_plant,Kvistforsen_upper minimum_operating_point Base 0.0888888888889 unit__from_node Kvistforsen_pwr_plant,Kvistforsen_upper unit_capacity Base 225 unit__from_node Rebnis_pwr_plant,Rebnis_upper unit_capacity Base 60 unit__from_node Rengård_pwr_plant,Rengård_upper unit_capacity Base 165 unit__from_node Sadva_pwr_plant,Sadva_upper unit_capacity Base 52.5 unit__from_node Selsfors_pwr_plant,Selsfors_upper unit_capacity Base 225 unit__from_node Slagnäs_pwr_plant,Slagnäs_upper unit_capacity Base 120 unit__from_node Vargfors_pwr_plant,Vargfors_upper unit_capacity Base 232.5 unit__from_node electricity_load,electricity_node vom_cost Base {"type": "time_series", "index": {"start": "2019-01-01 00:00:00", "resolution": "1h", "ignore_year": false, "repeat": false}, "data": [-162.03, -156.36, -151.06, -153.52, -158.91, -164.02, -175.56, -283.11, -278.76, -299.57, -285.28, -207.34, -194.95, -190.41, -185.4, -183.41, -191.54, -202.9, -197.69, -195.33, -186.72, -178.87, -174.71, -168.75, -172.89, -172.13, -171.66, -173.27, -176.97, -179.63, -226.41, -271.96, -399.3, -402.53, -353.28, -330.79, -294.54, -271.29, -248.71, -226.79, -240.93, -374.44, -255.54, -210.47, -186.65, -178.21, -173.18, -166.44, -165.09, -162.91, -161.11, -162.53, -166.04, -169.16, -174.28, -185.37, -195.79, -189.92, -187.74, -181.96, -179.12, -178.36, -177.13, -177.03, -177.69, -184.8, -187.27, -179.49, -175.23, -172.67, -169.07, -165.37, -170.06, -171.48, -171.58, -174.14, -180.3, -185.89, -195.37, -328.65, -365.91, -315.0, -242.68, -230.73, -225.33, -225.8, -213.38, -207.32, -215.37, -243.81, -243.53, -215.56, -192.05, -187.88, -181.15, -172.15, -174.16, -171.05, -170.77, -174.82, -179.62, -178.87, -191.49, -229.64, -336.07, -242.07, -228.5, -201.85, -196.67, -192.34, -190.36, -187.44, -186.68, -190.26, -191.21, -187.53, -179.34, -171.9, -166.53, -160.59, -166.08, -157.74, -145.36, -145.64, -147.42, -149.77, -153.33, -141.33, -145.08, -150.52, -153.42, -159.43, -159.05, -149.49, -147.89, -150.52, -157.08, -172.37, -174.06, -171.15, -160.46, -147.8, -141.61, -134.39, -144.41, -140.19, -138.59, -140.0, -139.53, -140.28, -144.03, -146.57, -149.39, -156.24, -157.93, -156.43, -155.21, -149.86, -148.07, -147.13, -148.82, -162.53, -174.74, -170.89, -163.94, -157.93, -150.7, -143.94]}
Go to Relationship parameter value (on the bottom-center of the window, usually). Make sure that the columns in the table are ordered as follows:
relationship_class_name | object_name_list | parameter_name | alternative_name | value | database
Select the first empty cell under
relationship_class_name
and press Ctrl+V. This will paste the parameter value data from the clipboard into the table.
Specify the conversion ratio from water to electricity and from water to water of different hydro power plants (the latter being equal to 1). Repeat the same procedure with the data below:
unit__node__node Bastusel_pwr_plant,electricity_node,Bastusel_upper fix_ratio_out_in_unit_flow Base 0.577810871184 unit__node__node Bergnäs_pwr_plant,electricity_node,Bergnäs_upper fix_ratio_out_in_unit_flow Base 0.0506329113924 unit__node__node Båtfors_pwr_plant,electricity_node,Båtfors_upper fix_ratio_out_in_unit_flow Base 0.148282097649 unit__node__node Finnfors_pwr_plant,electricity_node,Finnfors_upper fix_ratio_out_in_unit_flow Base 0.180985725828 unit__node__node Gallejaur_pwr_plant,electricity_node,Gallejaur_upper fix_ratio_out_in_unit_flow Base 0.730442000415 unit__node__node Granfors_pwr_plant,electricity_node,Granfors_upper fix_ratio_out_in_unit_flow Base 0.164556962025 unit__node__node Grytfors_pwr_plant,electricity_node,Grytfors_upper fix_ratio_out_in_unit_flow Base 0.190257000384 unit__node__node Krångfors_pwr_plant,electricity_node,Krångfors_upper fix_ratio_out_in_unit_flow Base 0.274261603376 unit__node__node Kvistforsen_pwr_plant,electricity_node,Kvistforsen_upper fix_ratio_out_in_unit_flow Base 0.472573839662 unit__node__node Rebnis_pwr_plant,electricity_node,Rebnis_upper fix_ratio_out_in_unit_flow Base 0.810126582278 unit__node__node Rengård_pwr_plant,electricity_node,Rengård_upper fix_ratio_out_in_unit_flow Base 0.165707710012 unit__node__node Sadva_pwr_plant,electricity_node,Sadva_upper fix_ratio_out_in_unit_flow Base 0.448462929476 unit__node__node Selsfors_pwr_plant,electricity_node,Selsfors_upper fix_ratio_out_in_unit_flow Base 0.209282700422 unit__node__node Slagnäs_pwr_plant,electricity_node,Slagnäs_upper fix_ratio_out_in_unit_flow Base 0.0443037974684 unit__node__node Vargfors_pwr_plant,electricity_node,Vargfors_upper fix_ratio_out_in_unit_flow Base 0.34299714169 unit__node__node Bastusel_pwr_plant,Bastusel_lower,Bastusel_upper fix_ratio_out_in_unit_flow Base 1 unit__node__node Bergnäs_pwr_plant,Bergnäs_lower,Bergnäs_upper fix_ratio_out_in_unit_flow Base 1 unit__node__node Båtfors_pwr_plant,Båtfors_lower,Båtfors_upper fix_ratio_out_in_unit_flow Base 1 unit__node__node Finnfors_pwr_plant,Finnfors_lower,Finnfors_upper fix_ratio_out_in_unit_flow Base 1 unit__node__node Gallejaur_pwr_plant,Gallejaur_lower,Gallejaur_upper fix_ratio_out_in_unit_flow Base 1 unit__node__node Granfors_pwr_plant,Granfors_lower,Granfors_upper fix_ratio_out_in_unit_flow Base 1 unit__node__node Grytfors_pwr_plant,Grytfors_lower,Grytfors_upper fix_ratio_out_in_unit_flow Base 1 unit__node__node Krångfors_pwr_plant,Krångfors_lower,Krångfors_upper fix_ratio_out_in_unit_flow Base 1 unit__node__node Kvistforsen_pwr_plant,Kvistforsen_lower,Kvistforsen_upper fix_ratio_out_in_unit_flow Base 1 unit__node__node Rebnis_pwr_plant,Rebnis_lower,Rebnis_upper fix_ratio_out_in_unit_flow Base 1 unit__node__node Rengård_pwr_plant,Rengård_lower,Rengård_upper fix_ratio_out_in_unit_flow Base 1 unit__node__node Sadva_pwr_plant,Sadva_lower,Sadva_upper fix_ratio_out_in_unit_flow Base 1 unit__node__node Selsfors_pwr_plant,Selsfors_lower,Selsfors_upper fix_ratio_out_in_unit_flow Base 1 unit__node__node Slagnäs_pwr_plant,Slagnäs_lower,Slagnäs_upper fix_ratio_out_in_unit_flow Base 1 unit__node__node Vargfors_pwr_plant,Vargfors_lower,Vargfors_upper fix_ratio_out_in_unit_flow Base 1
specify the average discharge and spillage in the first hours of the simulation. Repeat the same procedure with the data below:
connection__from_node Bastusel_to_Grytfors_disch,Bastusel_lower fix_connection_flow Base {"type": "time_series", "index": {"start": "2018-12-30 00:00:00", "resolution": "2D"}, "data": [110.7, 110.7]} connection__from_node Bergnäs_to_Slagnäs_disch,Bergnäs_lower fix_connection_flow Base {"type": "time_series", "index": {"start": "2018-12-30 00:00:00", "resolution": "2D"}, "data": [105.0, 105.0]} connection__from_node Båtfors_to_Finnfors_disch,Båtfors_lower fix_connection_flow Base {"type": "time_series", "index": {"start": "2018-12-30 00:00:00", "resolution": "2D"}, "data": [150.2, 150.2]} connection__from_node Finnfors_to_Granfors_disch,Finnfors_lower fix_connection_flow Base {"type": "time_series", "index": {"start": "2018-12-30 00:00:00", "resolution": "2D"}, "data": [155.3, 155.3]} connection__from_node Gallejaur_to_Vargfors_disch,Gallejaur_lower fix_connection_flow Base {"type": "time_series", "index": {"start": "2018-12-30 00:00:00", "resolution": "2D"}, "data": [118.2, 118.2]} connection__from_node Granfors_to_Krångfors_disch,Granfors_lower fix_connection_flow Base {"type": "time_series", "index": {"start": "2018-12-30 00:00:00", "resolution": "2D"}, "data": [155.6, 155.6]} connection__from_node Grytfors_to_Gallejaur_disch,Grytfors_lower fix_connection_flow Base {"type": "time_series", "index": {"start": "2018-12-30 00:00:00", "resolution": "2D"}, "data": [117.2, 117.2]} connection__from_node Krångfors_to_Selsfors_disch,Krångfors_lower fix_connection_flow Base {"type": "time_series", "index": {"start": "2018-12-30 00:00:00", "resolution": "2D"}, "data": [156.0, 156.0]} connection__from_node Kvistforsen_to_downstream_disch,Kvistforsen_lower fix_connection_flow Base {"type": "time_series", "index": {"start": "2018-12-30 00:00:00", "resolution": "2D"}, "data": [158.5, 158.5]} connection__from_node Rebnis_to_Bergnäs_disch,Rebnis_lower fix_connection_flow Base {"type": "time_series", "index": {"start": "2018-12-30 00:00:00", "resolution": "2D"}, "data": [21.5, 21.5]} connection__from_node Rengård_to_Båtfors_disch,Rengård_lower fix_connection_flow Base {"type": "time_series", "index": {"start": "2018-12-30 00:00:00", "resolution": "2D"}, "data": [141.5, 141.5]} connection__from_node Sadva_to_Bergnäs_disch,Sadva_lower fix_connection_flow Base {"type": "time_series", "index": {"start": "2018-12-30 00:00:00", "resolution": "2D"}, "data": [34.6, 34.6]} connection__from_node Selsfors_to_Kvistforsen_disch,Selsfors_lower fix_connection_flow Base {"type": "time_series", "index": {"start": "2018-12-30 00:00:00", "resolution": "2D"}, "data": [158.4, 158.4]} connection__from_node Slagnäs_to_Bastusel_disch,Slagnäs_lower fix_connection_flow Base {"type": "time_series", "index": {"start": "2018-12-30 00:00:00", "resolution": "2D"}, "data": [106.6, 106.6]} connection__from_node Vargfors_to_Rengård_disch,Vargfors_lower fix_connection_flow Base {"type": "time_series", "index": {"start": "2018-12-30 00:00:00", "resolution": "2D"}, "data": [119.6, 119.6]} connection__from_node Bastusel_to_Grytfors_spill,Bastusel_upper fix_connection_flow Base {"type": "time_series", "index": {"start": "2018-12-30 00:00:00", "resolution": "2D"}, "data": [0.0, 0.0]} connection__from_node Bergnäs_to_Slagnäs_spill,Bergnäs_upper fix_connection_flow Base {"type": "time_series", "index": {"start": "2018-12-30 00:00:00", "resolution": "2D"}, "data": [0.0, 0.0]} connection__from_node Båtfors_to_Finnfors_spill,Båtfors_upper fix_connection_flow Base {"type": "time_series", "index": {"start": "2018-12-30 00:00:00", "resolution": "2D"}, "data": [0.0, 0.0]} connection__from_node Finnfors_to_Granfors_spill,Finnfors_upper fix_connection_flow Base {"type": "time_series", "index": {"start": "2018-12-30 00:00:00", "resolution": "2D"}, "data": [0.0, 0.0]} connection__from_node Gallejaur_to_Vargfors_spill,Gallejaur_upper fix_connection_flow Base {"type": "time_series", "index": {"start": "2018-12-30 00:00:00", "resolution": "2D"}, "data": [0.0, 0.0]} connection__from_node Granfors_to_Krångfors_spill,Granfors_upper fix_connection_flow Base {"type": "time_series", "index": {"start": "2018-12-30 00:00:00", "resolution": "2D"}, "data": [0.0, 0.0]} connection__from_node Grytfors_to_Gallejaur_spill,Grytfors_upper fix_connection_flow Base {"type": "time_series", "index": {"start": "2018-12-30 00:00:00", "resolution": "2D"}, "data": [0.0, 0.0]} connection__from_node Krångfors_to_Selsfors_spill,Krångfors_upper fix_connection_flow Base {"type": "time_series", "index": {"start": "2018-12-30 00:00:00", "resolution": "2D"}, "data": [0.0, 0.0]} connection__from_node Kvistforsen_to_downstream_spill,Kvistforsen_upper fix_connection_flow Base {"type": "time_series", "index": {"start": "2018-12-30 00:00:00", "resolution": "2D"}, "data": [0.0, 0.0]} connection__from_node Rebnis_to_Bergnäs_spill,Rebnis_upper fix_connection_flow Base {"type": "time_series", "index": {"start": "2018-12-30 00:00:00", "resolution": "2D"}, "data": [0.0, 0.0]} connection__from_node Rengård_to_Båtfors_spill,Rengård_upper fix_connection_flow Base {"type": "time_series", "index": {"start": "2018-12-30 00:00:00", "resolution": "2D"}, "data": [0.0, 0.0]} connection__from_node Sadva_to_Bergnäs_spill,Sadva_upper fix_connection_flow Base {"type": "time_series", "index": {"start": "2018-12-30 00:00:00", "resolution": "2D"}, "data": [0.0, 0.0]} connection__from_node Selsfors_to_Kvistforsen_spill,Selsfors_upper fix_connection_flow Base {"type": "time_series", "index": {"start": "2018-12-30 00:00:00", "resolution": "2D"}, "data": [0.0, 0.0]} connection__from_node Slagnäs_to_Bastusel_spill,Slagnäs_upper fix_connection_flow Base {"type": "time_series", "index": {"start": "2018-12-30 00:00:00", "resolution": "2D"}, "data": [0.0, 0.0]} connection__from_node Vargfors_to_Rengård_spill,Vargfors_upper fix_connection_flow Base {"type": "time_series", "index": {"start": "2018-12-30 00:00:00", "resolution": "2D"}, "data": [0.0, 0.0]}
Finally, specify the delay and transfer ratio of different water connections (the latter being equal to 1). Repeat the same procedure with the data below:
connection__node__node Bastusel_to_Grytfors_disch,Grytfors_upper,Bastusel_lower connection_flow_delay Base {"type": "duration", "data": "1h"} connection__node__node Bastusel_to_Grytfors_spill,Grytfors_upper,Bastusel_upper connection_flow_delay Base {"type": "duration", "data": "150m"} connection__node__node Bergnäs_to_Slagnäs_disch,Slagnäs_upper,Bergnäs_lower connection_flow_delay Base {"type": "duration", "data": "1h"} connection__node__node Bergnäs_to_Slagnäs_spill,Slagnäs_upper,Bergnäs_upper connection_flow_delay Base {"type": "duration", "data": "1h"} connection__node__node Båtfors_to_Finnfors_disch,Finnfors_upper,Båtfors_lower connection_flow_delay Base {"type": "duration", "data": "3h"} connection__node__node Båtfors_to_Finnfors_spill,Finnfors_upper,Båtfors_upper connection_flow_delay Base {"type": "duration", "data": "3h"} connection__node__node Finnfors_to_Granfors_disch,Granfors_upper,Finnfors_lower connection_flow_delay Base {"type": "duration", "data": "3h"} connection__node__node Finnfors_to_Granfors_spill,Granfors_upper,Finnfors_upper connection_flow_delay Base {"type": "duration", "data": "3h"} connection__node__node Gallejaur_to_Vargfors_disch,Vargfors_upper,Gallejaur_lower connection_flow_delay Base {"type": "duration", "data": "30m"} connection__node__node Gallejaur_to_Vargfors_spill,Vargfors_upper,Gallejaur_upper connection_flow_delay Base {"type": "duration", "data": "150m"} connection__node__node Granfors_to_Krångfors_disch,Krångfors_upper,Granfors_lower connection_flow_delay Base {"type": "duration", "data": "3h"} connection__node__node Granfors_to_Krångfors_spill,Krångfors_upper,Granfors_upper connection_flow_delay Base {"type": "duration", "data": "3h"} connection__node__node Grytfors_to_Gallejaur_disch,Gallejaur_upper,Grytfors_lower connection_flow_delay Base {"type": "duration", "data": "15m"} connection__node__node Grytfors_to_Gallejaur_spill,Gallejaur_upper,Grytfors_upper connection_flow_delay Base {"type": "duration", "data": "15m"} connection__node__node Krångfors_to_Selsfors_disch,Selsfors_upper,Krångfors_lower connection_flow_delay Base {"type": "duration", "data": "3h"} connection__node__node Krångfors_to_Selsfors_spill,Selsfors_upper,Krångfors_upper connection_flow_delay Base {"type": "duration", "data": "3h"} connection__node__node Rebnis_to_Bergnäs_disch,Bergnäs_upper,Rebnis_lower connection_flow_delay Base {"type": "duration", "data": "2D"} connection__node__node Rebnis_to_Bergnäs_spill,Bergnäs_upper,Rebnis_upper connection_flow_delay Base {"type": "duration", "data": "2D"} connection__node__node Rengård_to_Båtfors_disch,Båtfors_upper,Rengård_lower connection_flow_delay Base {"type": "duration", "data": "3h"} connection__node__node Rengård_to_Båtfors_spill,Båtfors_upper,Rengård_upper connection_flow_delay Base {"type": "duration", "data": "3h"} connection__node__node Sadva_to_Bergnäs_disch,Bergnäs_upper,Sadva_lower connection_flow_delay Base {"type": "duration", "data": "2D"} connection__node__node Sadva_to_Bergnäs_spill,Bergnäs_upper,Sadva_upper connection_flow_delay Base {"type": "duration", "data": "2D"} connection__node__node Selsfors_to_Kvistforsen_disch,Kvistforsen_upper,Selsfors_lower connection_flow_delay Base {"type": "duration", "data": "3h"} connection__node__node Selsfors_to_Kvistforsen_spill,Kvistforsen_upper,Selsfors_upper connection_flow_delay Base {"type": "duration", "data": "3h"} connection__node__node Slagnäs_to_Bastusel_disch,Bastusel_upper,Slagnäs_lower connection_flow_delay Base {"type": "duration", "data": "4h"} connection__node__node Slagnäs_to_Bastusel_spill,Bastusel_upper,Slagnäs_upper connection_flow_delay Base {"type": "duration", "data": "4h"} connection__node__node Vargfors_to_Rengård_disch,Rengård_upper,Vargfors_lower connection_flow_delay Base {"type": "duration", "data": "3h"} connection__node__node Vargfors_to_Rengård_spill,Rengård_upper,Vargfors_upper connection_flow_delay Base {"type": "duration", "data": "3h"} connection__node__node Bastusel_to_Grytfors_disch,Grytfors_upper,Bastusel_lower fix_ratio_out_in_connection_flow Base 1 connection__node__node Bastusel_to_Grytfors_spill,Grytfors_upper,Bastusel_upper fix_ratio_out_in_connection_flow Base 1 connection__node__node Bergnäs_to_Slagnäs_disch,Slagnäs_upper,Bergnäs_lower fix_ratio_out_in_connection_flow Base 1 connection__node__node Bergnäs_to_Slagnäs_spill,Slagnäs_upper,Bergnäs_upper fix_ratio_out_in_connection_flow Base 1 connection__node__node Båtfors_to_Finnfors_disch,Finnfors_upper,Båtfors_lower fix_ratio_out_in_connection_flow Base 1 connection__node__node Båtfors_to_Finnfors_spill,Finnfors_upper,Båtfors_upper fix_ratio_out_in_connection_flow Base 1 connection__node__node Finnfors_to_Granfors_disch,Granfors_upper,Finnfors_lower fix_ratio_out_in_connection_flow Base 1 connection__node__node Finnfors_to_Granfors_spill,Granfors_upper,Finnfors_upper fix_ratio_out_in_connection_flow Base 1 connection__node__node Gallejaur_to_Vargfors_disch,Vargfors_upper,Gallejaur_lower fix_ratio_out_in_connection_flow Base 1 connection__node__node Gallejaur_to_Vargfors_spill,Vargfors_upper,Gallejaur_upper fix_ratio_out_in_connection_flow Base 1 connection__node__node Granfors_to_Krångfors_disch,Krångfors_upper,Granfors_lower fix_ratio_out_in_connection_flow Base 1 connection__node__node Granfors_to_Krångfors_spill,Krångfors_upper,Granfors_upper fix_ratio_out_in_connection_flow Base 1 connection__node__node Grytfors_to_Gallejaur_disch,Gallejaur_upper,Grytfors_lower fix_ratio_out_in_connection_flow Base 1 connection__node__node Grytfors_to_Gallejaur_spill,Gallejaur_upper,Grytfors_upper fix_ratio_out_in_connection_flow Base 1 connection__node__node Krångfors_to_Selsfors_disch,Selsfors_upper,Krångfors_lower fix_ratio_out_in_connection_flow Base 1 connection__node__node Krångfors_to_Selsfors_spill,Selsfors_upper,Krångfors_upper fix_ratio_out_in_connection_flow Base 1 connection__node__node Rebnis_to_Bergnäs_disch,Bergnäs_upper,Rebnis_lower fix_ratio_out_in_connection_flow Base 1 connection__node__node Rebnis_to_Bergnäs_spill,Bergnäs_upper,Rebnis_upper fix_ratio_out_in_connection_flow Base 1 connection__node__node Rengård_to_Båtfors_disch,Båtfors_upper,Rengård_lower fix_ratio_out_in_connection_flow Base 1 connection__node__node Rengård_to_Båtfors_spill,Båtfors_upper,Rengård_upper fix_ratio_out_in_connection_flow Base 1 connection__node__node Sadva_to_Bergnäs_disch,Bergnäs_upper,Sadva_lower fix_ratio_out_in_connection_flow Base 1 connection__node__node Sadva_to_Bergnäs_spill,Bergnäs_upper,Sadva_upper fix_ratio_out_in_connection_flow Base 1 connection__node__node Selsfors_to_Kvistforsen_disch,Kvistforsen_upper,Selsfors_lower fix_ratio_out_in_connection_flow Base 1 connection__node__node Selsfors_to_Kvistforsen_spill,Kvistforsen_upper,Selsfors_upper fix_ratio_out_in_connection_flow Base 1 connection__node__node Slagnäs_to_Bastusel_disch,Bastusel_upper,Slagnäs_lower fix_ratio_out_in_connection_flow Base 1 connection__node__node Slagnäs_to_Bastusel_spill,Bastusel_upper,Slagnäs_upper fix_ratio_out_in_connection_flow Base 1 connection__node__node Vargfors_to_Rengård_disch,Rengård_upper,Vargfors_lower fix_ratio_out_in_connection_flow Base 1 connection__node__node Vargfors_to_Rengård_spill,Rengård_upper,Vargfors_upper fix_ratio_out_in_connection_flow Base 1
When you’re ready, commit all changes to the database.
Executing the workflow¶
Once the workflow is defined and input data is in place, the project is ready
to be executed. Hit the Execute project button on
the tool bar.
You should see ‘Executing All Directed Acyclic Graphs’ printed in the Event log (on the lower left by default). SpineOpt output messages will appear in the Process Log panel in the middle. After some processing, ‘DAG 1/1 completed successfully’ appears and the execution is complete.
Examining the results¶
Select the output data store and open the Spine DB editor.

To checkout the flow on the electricity load (i.e., the total electricity production in the system),
go to Object tree, expand the unit
object class,
and select electricity_load
, as illustrated in the picture above.
Next, go to Relationship parameter value and double-click the first cell under value.
The Parameter value editor will pop up. You should see something like this:

Setting up External Tools¶
This section describes the default Python used by Spine Toolbox and how to change that. Here you can also find the instructions on how to set up Julia and Gams for executing Julia and Gams Tools. To get started with SpineOpt.jl, see How to set up SpineOpt.jl. See also Executing Projects and Execution Modes.
Python¶
No set up required! Python Tools are executed using the default Python, which depends on how you installed Spine Toolbox. The installation options are:
Using a single-file installation bundle (e.g. spine-toolbox-0.6.0-final.2-x64.exe or newer). You can find this file and all releases from Spine Toolbox releases. The installation bundles are only available for Windows at the moment.
Cloning Spine Toolbox Git repository from https://github.com/Spine-project/Spine-Toolbox. Checkout branch release-0.6 or master and run pip install -r requirements.txt in the repo root.
Tip
You can always see the current Python configured for Spine Toolbox from the Tools page in File->Settings….
Default Python for Spine Toolbox installed using an installation bundle¶
The default Python is the Python in your PATH environment variable. If Python is not in your PATH, the default Python is an ‘embedded’ Python that is shipped with the installation bundle. The ‘embedded’ Python is located in <install_dir>\tools\python.exe, where <install_dir> is C:\Program Files\Spine Toolbox if you installed Spine Toolbox to the default directory for all users.
Important
If you want access to spinedb_api package from Tools and Consoles in Spine Toolbox, bear in mind that the version of spinedb_api must be compatible with the version of Spine Toolbox you are using! Spine Toolbox v0.6.0 is shipped with spinedb_api v0.12.1. If you want to use the Python in your PATH, you must install the correct version of spinedb_api for this Python manually. The correct version in this case is in the release-0.12 branch of spinedb_api git repo (https://github.com/Spine-project/Spine-Database-API/tree/release-0.12). To avoid this additional step, it is recommended that you use the ‘embedded’ Python interpreter that is shipped with the application. You can set up this Python for Spine Toolbox by opening the Tools page of File->Settings… and replacing the path of the Python Interpreter with <install_dir>\tools\python.exe. The ‘embedded’ Python interpreter has access to `spinedb_api` that is shipped with the application.
Here are the recommended settings

Default Python for Spine Toolbox installed using Git¶
The default Python is the Python that was used in launching the application (i.e. sys.executable). When you start the app for the first time (or if you clear the path), the path to the default Python is shown as placeholder (gray) text in the line edit like this:

The default Python has access to the spinedb_api version that was installed with the application (the one in in <python_dir>\lib\site-packages\spinedb_api).
Changing the default Python¶
If you want to use another Python than the default, you can use existing Pythons in your system or you can
download additional Pythons from https://www.python.org/downloads/. You can change the default Python
on the Tools page of File->Settings… by clicking the button and selecting the Python interpreter
(python.exe on Windows) you want. You can use any Python in your system.
Note
Executing Python Tools using the Jupyter Console supports Python versions from 2.7 all the way to newest one. Executing Python Tools without using the Jupyter Console supports even earlier Pythons than 2.7. You can start Spine Toolbox only with Python 3.7 or with 3.8, but you can set up a Jupyter Console in Spine Toolbox that uses e.g. Python 2.7. This means, that if you still have some old Python 2.7 scripts lying around, you can incorporate those into a Spine Toolbox project workflow and execute them without modifications.
Important
If you want to have access to spinedb_api, you need to install it manually for the Python you select here.
Julia¶
Executing Julia Tools in Spine Toolbox requires that Julia is installed on your system. Julia downloads are available from https://julialang.org/downloads/. You can see the current Julia on the Tools page in File->Settings…. The default Julia is the Julia in your PATH environment variable. Setting some other Julia to the line edit overrides the Julia in PATH. If you want to use a specific Julia project environment (the place for Project.toml and Manifest.toml), you can set the path to the environment folder to the line edit just below the Julia executable line edit (the one that says Using Julia default project when empty).
If you are trying to execute Julia Tools and you see an error message in Event Log complaining about not finding Julia, you either don’t have a Julia installation in your PATH, or the Julia path in Settings is invalid.
GAMS¶
Executing Gams Tools and the GDXExporter Project Item requires an installation of Gams on your system. You can download Gams from https://www.gams.com/download/.
Note
You do not need to own a Gams license as the demo version works just as well.
As with Julia, the default Gams is the Gams in your PATH environment variable. You can see the one that is currently in use from the Tools page in File->Settings…. The placeholder text shows the Gams in your PATH if found. You can also override the default Gams by setting some other gams.exe path to the line edit (e.g. C:\GAMS\win64\28.2\gams.exe).
Important
The bitness (32 or 64bit) of Gams has to match the bitness of the Python interpreter.
Main Window¶
This section describes the different components in the application main window.
The first time you start the application you will see the main window like this.

The application main window contains six dock widgets (Project, Properties, Event Log, Process Log, Julia Console, and Python Console), a tool bar, a Design View, and a menu bar with File, Edit, View, and Help menus. The Project dock widget contains a list of project items and Tool specifications that are available in your project. The Properties dock widget shows the properties of the selected project item. Event Log shows messages depending on what you do in Spine Toolbox. Process Log shows messages from processes that are spawned by the application, i.e. it shows the stdout and stderr streams of GAMS, Julia, Python (if Tools are executed without embedded Julia and Python Consoles, see Settings section), and executable programs. Julia and Python Consoles provide full iJulia and a iPython consoles. If you choose to execute Julia tools in the embedded Julia Console, the Julia code will be included into the Julia Console and executed there. You can interact with the iJulia in the Julia Console like you would with any iJulia you use.
Tip
You can configure the Julia and Python versions you want to use in File->Settings
.
The menu bar in the top of the application contains File, Edit, View, and Help menus. In the File menu
you can create a new project, open an existing project, save the project, upgrade an old project to modern
directory-based project, and open the application Settings among other things.
Spine Toolbox is project based, which means that you need to create
a new project or open an existing one before you can do anything. You can create a new project by selecting
File->New project...
from the menu bar. Drag & Drop Icon tool bar contains the available
project item types. The button can be used to remove all items from your project.
The Execute icons control the execution of the items in the Design view where you build your project.
The
button executes all Directed-Acyclic Graphs (DAG) in the project in a row. The
button
executes the selected project items only. The
button terminates the execution (if running).
You can add a new project item to your project by pointing your mouse cursor on any of the draggable items in the Drag & Drop Icon tool bar, then click-and-drag the item on to the Design view. After this you will be presented a dialog, which asks you to fill in basic information about the new project item (name, description, etc.).
The main window is very customizable so you can e.g. close the dock widgets that you do not need and/or you can resize the views to fit your needs and display size or resolution.
Note
If you want to restore all dock widgets to their default place use the menu item
View->Dock Widgets->Restore Dock Widgets
.
This will show all hidden dock widgets and restore them to the main window.
Below is an example on how you can customize the main window. In the picture, a user has created a project My First Project, and created one project item from each of the seven categories. A Data Store called Database, a Data Connection called Data files, A Tool called Julia model, a View called View, an Importer called Importer, an Exporter called Exporter, and a Manipulator called Combiner. The project items are also listed in the Project dock widget.

Project Items¶
Project items in the Design view and the connections between them make up the graph (Directed Acyclic
Graph, DAG) that is executed when the or
buttons are pressed.
See Executing Projects for more information on how a DAG is processed by Spine Toolbox. Those interested in looking under the hood can check the Project item development section.
Project Item Properties¶
Each project item has its own set of Properties. You can view and edit them by selecting a project
item on the Design View. The Properties are displayed in the Properties dock widget on the main
window. Project item properties are saved into the project save file (project.json
), which can be
found in <proj_dir>/.spinetoolbox/
directory, where <proj_dir>
is your current project
directory.
In addition, each project item has it’s own directory in the <proj_dir>/.spinetoolbox/items/
directory. You can quickly open the project item directory in a file explorer by clicking on the
button located in the lower right corner of each Properties form.
Project Item Descriptions¶
The following items are currently available:
Data Store
¶
A Data store item represents a connection to a (Spine) database. Currently, the item supports sqlite and mysql dialects. The database can be accessed and modified in Spine db editor available by double-clicking a Data store on the Design view, from the item’s properties, or from a right-click context menu.
Data Connection
¶
A Data connection item provides access to data files. The item has two categories of files: references connect to files anywhere on the file system while data files reside in the item’s own data directory.
Tool
¶
Tool is the heart of a DAG. It is usually the actual model to be executed in Spine Toolbox but can be an arbitrary script or executable as well. A tool is specified by its specification.
Gimlet
¶
While being able to run most scripts and copyable executables, Tool cannot handle system commands or executables meant to run from system’s path. This is a job for Gimlet. A Gimlet can execute an arbitrary system command with given command line arguments, input files and work directory.
Data Transformer
¶
Data transformers set up database manipulators for successor items in a DAG. They do not transform data themselves; rather, Spine Database API does the transformations configured by Data transformers when the database is accessed. Currently supported transformations include entity class and parameter renaming.
View
¶
A View item is meant for inspecting data from multiple sources using the Spine db editor. Note that the data is opened in read-only mode so modifications are not possible from the View item.
Importer
¶
This item provides the user a chance to define a mapping from tabulated data such as comma separated values or Excel to the Spine data model. See Importing and exporting data for more information.
Exporter
¶
Exporter outputs database data into tabulated file formats that can be consumed by Tool or used e.g. by external software for analysis. See Importing and exporting data for more information.
GdxExporter
¶
Note
GdxExporter is pending for removal and its use in new projects is discouraged. Use Exporter instead.
This item exports databases contained in a Data Store into .gdx
format for GAMS Tools.
See Importing and exporting data for more information.
Tool specification editor¶
This section describes how to make a new Tool specification and how to edit existing Tool specifications.
To execute a Julia, Python, GAMS, or an executable script in Spine Toolbox, you must first create a Tool specification for your project. You can open the Tool specification editor in several ways. One way is to press the arrow next to the Tool icon in the toolbar to expand the Tool specifications, and then press the New… button.

When you press New… the following form pops up;

Start by giving the Tool specification a name. Then select the type of the Tool. You have four options (Julia,
Python, GAMS or Executable). Then select, whether you want the Tool specification to be executed in the work directory or
in its source directory (See Terminology section). You can give the Tool specification a description,
describing what the Tool specification does. Main program file is the main file of your tool, i.e. a
script that can be passed to Julia, Python, GAMS, or the system shell.
You can create a blank file by pressing the button,
or you can browse to find an existing main program file by pressing the
button.
Command line arguments can be appended to the actual command that
Spine Toolbox executes in the background. For example, you may have a Windows batch file called do_things.bat,
which accepts command line arguments a and b.
Writing a b
on the command line arguments field in the tool specification editor is the equivalent
of running the batch file in command prompt with the command do_things.bat a b
.
Additional source files is a list of files that the main program requires in order to run. You can add individual files or whole directories at once to this list.
Tip
You can also drag&drop a directory from your operating systems File Explorer into the Additional source files list.
Input files is a list of input data files that the program requires in order to execute. You can also add directories and subdirectories. Wildcards are not supported (see Optional input files).
Examples:
data.csv -> File is copied to the same work directory as the main program
input/data.csv -> Creates directory input/ to the work directory and copies file data.csv there
output/ -> Creates an empty directory output/ into the work directory
Optional input files are files that may be utilized by your program if they are found. Unix-style wildcards ? and * are supported.
Examples:
data.csv -> If found, file is copied to the same work directory as the main program
*.csv -> All found .csv files are copied to the same work directory as the main program
input/data_?.dat -> All found files matching the pattern data_?.dat are copied into input/ directory in the work directory.
Output files are files that will be archived into a timestamped result directory of the Tool’s project directory after the Tool specification has finished execution. Unix-style wildcards ? and * are supported.
Examples:
results.csv -> File is copied from work directory into results directory
*.csv -> All .csv files from work directory are copied into results directory
output/*.gdx -> All GDX files from the work directory’s output/ subdirectory will be copied to into output/ subdirectory in the results directory.
When you are happy with your Tool specification, press Ctrl+S to save it. You will see a message in the Event log (back in the main Spine Toolbox window), specifying the path of the saved specification file. The Tool specification file is a text file in JSON format and has an extension .json You can change the location by pressing [change]. Also, you need to save your project for the specification to stick.
Tip
Only name, type, and main program file fields are required to make a Tool specification. The other fields are optional.
Here is a minimal Tool specification for a Julia script script.jl

Note
Under the hood, the contents of the Tool specification are saved to a Tool specification file in JSON format. Users do not need to worry about the contents of these files since reading and writing them is managed by the app. For the interested, here are the contents of the Tool specification file that we just created.:
{
"name": "Example Tool specification",
"description": "",
"tooltype": "julia",
"execute_in_work": true,
"includes": [
"script.jl"
],
"inputfiles": [],
"inputfiles_opt": [],
"outputfiles": [],
"cmdline_args": ""
}
After you have saved the specification, the new Tool specification has been added to the project.

To edit this Tool specification, just right-click on the Tool specification name and select Edit specification from the context-menu.
You are now ready to execute the Tool specification in Spine Toolbox. You just need to select a Tool item in the
Design view, set the specification Example Tool specification for it, and click or
button.
Executing Projects¶
This section describes how executing a project works and what resources are passed between project
items at execution time. Execution happens by pressing the
(Execute project) or the
(Execute selection) buttons in the main window tool bar.
A project consists of project items and connections (yellow arrows) that are visualized on the
Design View. You use the project items and the connections to build a Directed Acyclic Graph
(DAG), with the project items as nodes and the connections as edges. A DAG is traversed using
the breadth-first-search algorithm.
Rules of DAGs:
A single project item with no connections is a DAG.
All project items that are connected, are considered as a single DAG (no matter, which direction the arrows go). If there is a path between two items, they are considered as belonging to the same DAG.
Loops are not allowed (this is what acyclic means).
You can connect the nodes in the Design View how ever you want but you cannot execute the resulting DAGs if they break the rules above. Here is an example project with three DAGs.

DAG 1: items: a, b, c, d. connections: a-b, a-c, b-d, c-d
DAG 2: items: e, f. connections: e-f
DAG 3: items: g. connections: None
The numbers on the upper left corners of the icons show the item’s execution ranks which roughly tell the order of execution within a DAG. Execution order of DAG 1 is a->b->c->d or a->c->b->d because b and c are siblings which is also indicated by their equal execution rank. DAG 2 execution order is e->f and DAG 3 is just g. All three DAGs are executed in a row though which DAG gets executed first is undefined. Therefore all DAGs have their execution ranks starting from 1.
After you press the button, you can follow the progress
and the current executed item in the Event Log.
Design view also animates the execution.
Items in a DAG that breaks the rules above are marked by X as their rank. Such DAGs are skipped during execution. The image below shows such a DAG where the items form a loop.

We use the words predecessor and successor to refer to project items that are upstream or downstream from a project item. Direct predecessor is a project item that is the immediate predecessor while Direct Successor is a project item that is the immediate successor. For example, in DAG 1 above, the successors of a are project items b, c and d. The direct successor of b is d. The predecessor of b is a, which is also its direct predecessor.
You can also execute only the selected parts of a project by multi-selecting the items you want to
execute and pressing the button in the tool bar. For example, to execute only items
b, d and f, select the items in Design View or in the project item list in Project dock
widget and then press the
button.
Tip
You can select multiple project items by holding the Ctrl-key down and clicking on desired items or by drawing a rectangle on the Design view.
Example DAG¶
When you have created at least one Tool specification, you can execute a Tool as part of the DAG. The Tool specification defines the process that is executed by the Tool project item. As an example, below we have two project items; Data File Data Connection and Julia Model Tool connected to each other.

In ths example, Data File has a single file reference data.csv
.
Data Connections make their files visible to direct successors
and thus the connection between Data File and Julia Model provides data.csv
to the latter.
Selecting the Julia Model shows its properties in the Properties dock widget.

In the top of the Tool Properties, there is a specification drop-down menu.
From this drop-down menu, you can select the Tool specification for this particular Tool item.
The Julia Model Specification tool specification has been selected for Julia Model.
Below the drop-down menu, you can choose a precompiled sysimage
and edit Tool’s command line arguments.
Note that the command line argument editor already ‘sees’ the data.csv
file provided by Data File.
Results… button opens the Tool’s result archive directory in system’s file browser
(all Tools have their own result directory).
The Execute in radio buttons control, whether this Tool is first copied to a work directory and executed
there, or if the execution should happen in the source directory where the main program file is located.
When you click on the button, the execution starts from the Data File Data Connection
as indicated by the execution rank numbers.
When executed, Data Connection items advertise their files and references
to project items that are their direct successors.
In this particular example,
data.csv
contained in Data File
is also a required input file in Julia Model Specification.
When it is the Julia Model tool’s turn to be executed, it checks if it finds the data.csv
from
its direct predecessor items that have already been executed.
Once the input file has been found the Tool starts processing the main program file script.jl.
Note that if the connection would be the other way around (from Julia Model to Data File)
execution would start from the Julia Model and it would fail because it cannot find the required data.csv
.
The same thing happens if there is no connection between the two project items.
In this case the project items would be in separate DAGs.
Since the Tool specification type was set as Julia and the main program is a Julia script, Spine Toolbox starts the execution in the Julia Console (if you have selected this in the application Settings, See Settings section).
Execution Modes¶
You can execute Python or Julia Tools in the Jupyter Console or as in the shell. Gams Tools are only executed as in the shell.
Python¶
Shell execution (default)¶
On Tools page in File->Settings…, check the Run Python Tools in a subprocess radiobutton (release-0.6) or uncheck the Jupyter Console check box (master). This is the default execution mode for Python Tools.
Jupyter Console / Python Console execution¶
If you want to use the embedded Python Console (Jupyter Console). Check the Run Python Tools in embedded console radiobutton (release-0.6) or check the Jupyter Console check box (master). There is an extra step involved since the Jupyter Console requires a couple of extra packages (ipykernel and its dependencies) to be installed on the selected Python. In addition, kernel specifications for the selected Python need to be installed beforehand. Spine Toolbox can install these for you, from the Kernel Spec Editor widget that you can open from the Tools page in File->Settings.. by clicking the Kernel Spec Editor button. In the Kernel Spec Editor, give the spec a name and click Make kernel specification button.
Note
You can install Python kernel specifications manually and Spine Toolbox will find them. You can select the kernel spec used in the Jupyter Console from the drop-down menu Select Python kernel spec….
Julia¶
Shell execution (default)¶
On Tools page in File->Settings…, check the Run Julia Tools in a subprocess radiobutton (release-0.6) or uncheck the Jupyter Console check box (master). This is the default execution mode for Julia Tools.
Jupyter Console / Julia Console execution¶
Like the Python Console, Julia Console requires some extra setting up. The Julia Console requires a couple of additional packages (IJulia, etc.) to be installed and built. Spine Toolbox can set this up for you automatically. Just click the Kernel spec Editor button, give the spec a name and click Make kernel specification button.
Note
You can install Julia kernel specifications manually and Spine Toolbox will find them. You can select the kernel spec used in the Jupyter Console from the drop-down menu Select Julia kernel spec….
Settings¶
Note
The images and some of the text are outdated. See tooltips in the app for up-to-date information.
You can open Spine Toolbox settings from the main window menu File->Settings…, or by pressing F1. Settings are categorized into four tabs; General, Project, Tools, and View. In addition to application settings, each Project item has user adjustable properties (See Project Items)
General settings¶

The General tab contains the general application settings.
Open previous project at startup If checked, application opens the project at startup that was open the last time the application was shut down. If left unchecked, application starts without a project open.
Show confirm exit prompt If checked, confirm exit prompt is shown. If unchecked, application exits without prompt.
Save project at exit Unchecked: Does not save project and does not show message box. Partially checked: Shows message box (default). Checked: Saves project and does not show message box.
Show date and time in Event Log messages If checked, every Event Log message is prepended with a date and time ‘tag’.
Delete data when project item is removed from project Check this box to delete project item’s data when a project item is removed from project. This means, that the project item directory and its contents will be deleted from your hard drive. You can find the project item directories from the
<proj_dir>/.spinetoolbox/items/
directory, where<proj_dir>
is your current project directory.Work directory Directory where processing the Tool takes place. Default place (if left empty) is the
/work
subdirectory of Spine Toolbox install directory. You can change this directory. Make sure to clean up the directory every now and then.Smooth zoom Controls the way zooming (by using the mouse wheel) behaves in Design View and in Spine database editor. Controls if the zoom in/out is continuous or discrete. On older computers, smooth zoom is not recommended (because it may be slower).
Curved links Controls the look of the arrows (connections) on Design View.
Design View background Choosing grid shows a black grid as the Design View background. Choosing Solid and then clicking on the square next to it let’s you choose the background color.
Data flow animation speed This slider controls the speed of the ‘arrow’ animation on Design View when execution is about to start.
Project settings¶

These settings affect the project that is currently open. To save the project to a new directory
use the File->Save project as...
menu item. Or you can simply copy the project directory anywhere
on your file system.
Name The default name for new projects is the name of the project directory. You can change the project name here.
Description You can type a description for your project here.
Tools settings¶

GAMS executable Path to GAMS executable you wish to use to execute GdxExporter project items and Tool project items that use a GAMS Tool specification. See Setting up External Tools.
Julia executable Path to Julia executable you wish to use to execute Tool project items that use a Julia Tool specification. See Setting up External Tools.
Julia home project Set the Julia home project here.
Use embedded Julia Console Check this box to execute Tool project items that use a Julia Tool specification in the built-in Julia Console. If you leave this un-checked, Julia Tool specifications will be executed as in the shell. I.e on Windows this would be the equivalent to running command
julia.exe example_script.jl
in the command prompt. If you decide to use the embedded Julia Console, theexample_script.jl
is included into the console and executed there.Python interpreter Path to Python executable you wish to use to execute Tool project items that use a Python Tool specification. See Setting up External Tools.
Use embedded Python Console Check this box to execute Python Tool specifications in the embedded Python Console. If you un-check this box, Python Tool specifications will be executed as in the shell. I.e on Windows this would be the equivalent to running command
python.exe script.py
in the command prompt. If you decide to use the embedded Python Console,script.py
is executed there instead.
View settings¶

Commit session when view is closed This checkbox controls what happens when you close the Spine database editor which has uncommitted changes. When this is unchecked, all changes are discarded without notice. When this is partially checked (default), a message box warning you about uncommitted changes is shown. When this is checked, a commit message box is shown immediately without first showing the message box.
Sticky selection in object tree Controls how selecting items in Spine database editor’s Object tree using the left mouse button works. If unchecked, single selection is enabled and pressing the Ctrl-button down enables multiple selection. If checked, Multiple selection is enabled and pressing the Ctrl-button down enables single selection.
Application preferences¶
Spine Toolbox remembers the size, location, and placement of most of the application windows from the previous session (i.e. when closing and restarting the app).
Where are the application settings stored?¶
Application settings and preferences (see above) are saved to a location that depends on your
operating system. On Windows, they are stored into registry key
HKEY_CURRENT_USER\Software\SpineProject\Spine Toolbox
. It is safe to delete this key if you
want to reset Spine Toolbox to factory defaults.
Note
If you are looking for information on project item properties, see Project Items.
Welcome to Spine database editor’s User Guide!¶
Spine database editor is a dedicated component of Spine Toolbox, that you can use to visualize and edit data in one or more Spine databases.
Getting started¶
Launching the editor¶
From Spine Toolbox¶
To open a single database in Spine database editor:
Create a Data Store project item.
Select the Data Store.
Enter the url of the database in Data Store Properties.
Press the Open editor button in Data Store Properties.
To open multiple databases in Spine database editor:
Repeat steps 1 to 3 above for each database.
Create a View project item.
Connect each Data Store item to the View item.
Select the View item.
Press Open editor in View Properties.
From the command line¶
To open a single SQLite database in Spine database editor, use the spine_db_editor.py
script
in the bin
folder:
spine_db_editor.py "...path of the database file..."
Knowing the UI¶
The form has the following main UI components:
Entity trees (Object tree and Relationship tree): they present the structure of classes and entities in all databases in the shape of a tree.
Stacked tables (Object parameter value, Object parameter definition, Relationship parameter value, and Relationship parameter definition): they present object and relationship parameter data in the form of stacked tables.
Pivot table and Frozen table: they present data for a given class in the form of a pivot table, optionally with frozen dimensions.
Entity graph: it presents the structure of classes and entities in the shape of a graph.
Tool/Feature tree: it presents tools, features, and methods defined in the databases.
Parameter value list: it presents parameter value lists available in the databases.
Alternative/Scenario tree: it presents scenarios and alternatives defined in the databases.
Parameter tag: it presents parameter tags defined in the databases.
Tip
You can customize the UI from the View and Pivot sections in the hamburger menu.
Viewing data¶
This section describes the available tools to view data.
Viewing entities and classes¶
Using Entity trees¶
Entity trees present the structure of classes and entities in all databases in the shape of a tree:

In Object tree:
To view all object classes from all databases, expand the root item (automatically expanded when loading the form).
To view all objects of a class, expand the corresponding object class item.
To view all relationship classes involving an object class, expand any objects of that class.
To view all relationships of a class involving a given object, expand the corresponding relationship class item under the corresponding object item.
In Relationship tree:
To view all relationship classes from all databases, expand the root item (automatically expanded when loading the form).
To view all relationships of a class, expand the corresponding relationship class item.
Note
To expand an item in Object tree or Relationship tree, double-click on the item or press the right arrow while it’s active. Items in gray don’t have any children, thus they cannot be expanded. To collapse an expanded item, double-click on it again or press the left arrow while it’s active.
Tip
To expand or collapse an item and all its descentants in Object tree or Relationship tree, right click on the item to display the context menu, and select Fully expand or Fully collapse.
Tip
In Object tree, the same relationship appears in many places (as many as it has dimensions). To jump to the next ocurrence of a relationship item, either double-click on the item, or right-click on it to display the context menu, and select Find next.
Using Entity graph¶
Entity graph presents the structure of classes and entities from one database in the shape of a graph:

Tip
To see it in action, check out this video.
Building the graph¶
To build the graph, select any number of items in either Object tree or Relationship tree. What is included in the graph depends on the specific selection you make:
To include all objects and relationships from the database, select the root item in either Object tree or Relationship tree.
To include all objects of a class, select the corresponding class item in Object tree.
To include all relationships of a class, select the corresponding class item in Relationship tree.
To include all relationships of a specific class involving a specific object, select the corresponding relationship class item under the corresponding object item in Object tree.
To include specific objects or relationships, select the corresponding item in either Object tree or Relationship tree.
Note
In Entity graph, a small unnamed vertex represents a relationship, whereas a bigger named vertex represents an object. An arc between a relationship and an object indicates that the object is a member in that relationship.
The graph automatically includes relationships whenever all the member objects are included (even if these relationships are not selected in Object tree or Relationship tree). You can change this behavior to automatically include relationships whenever any of the member objects are included. To do this, enable Auto-expand objects via the Graph menu, or via Entity graph’s context menu.
Tip
To extend the selection in Object tree or Relationship tree, press and hold the Ctrl key while clicking on the items.
Tip
Object tree and Relationship tree also support Sticky selection, which allows one to extend the selection by clicking on items without pressing Ctrl. To enable Sticky selection, select Settings from the hamburger menu, and check the corresponding box.
Manipulating the graph¶
You can move items in the graph by dragging them with your mouse. By default, each items moves individually. To make relationship items move along with their member objects, select Settings from the hamburger menu and check the box next to, Move relationships along with objects in Entity graph.
To display Entity graph’s context menu, just right-click on an empty space in the graph.
To save the position of items into the database, select the items in the graph and choose Save positions from the context menu. To clear saved positions, select the items again and choose Clear saved positions from the context menu.
To hide part of the graph, select the items you want to hide and choose Hide from context menu. To show the hidden items again, select Show hidden from the context menu.
To prune the graph, select the items you want to prune and then choose Prune entities or Prune classes from the context menu. To restore specific prunned items, display the context menu, hover Restore and select the items you want to restore from the popup menu. To restore all prunned items at once, select Restore all from the context menu.
To zoom in and out, scroll your mouse wheel over Entity graph or use Zoom buttons in the context menu.
To rotate clockwise or anti-clockwise, press and hold the Shift key while scrolling your mouse wheel, or use the Rotate buttons in the context menu.
To adjust the arcs’ lenght, use the Arc length buttons in the context menu.
To rebuild the graph after moving items around, select Rebuild graph from the context menu.
To export the current graph as a PDF file, select Export graph as PDF from the context menu.
Note
Entity graph supports extended selection and rubber-band selection. To extend a selection, press and hold Ctrl while clicking on the items. To perform rubber-band selection, press and hold Ctrl while dragging your mouse around the items you want to select.
Note
Prunned items are remembered across graph builds.
To display an object or relationship item’s context menu, just right-click on it.
To expand or collapse relationships for an object item, hover Expand or Collapse and select the relationship class from the popup menu.
Viewing parameter definitions and values¶
Using Stacked tables¶
Stacked tables present object and relationship parameter data from all databases in the form of stacked tables:

To filter Stacked tables by any entities and/or classes, select the corresponding items in either Object tree, Relationship tree, or Entity graph. To remove all these filters, select the root item in either Object tree or Relationship tree.
To filter parameter definitions and values by certain parameter tags, select those tags in Parameter tag toolbar.
To apply a custom filter on a Stacked table, click on any horizontal header. A menu will pop up listing the items in the corresponding column:

Uncheck the items you don’t want to see in the table and press Ok. Additionally, you can type in the search bar at the top of the menu to filter the list of items. To remove the current filter, select Remove filters.
To filter a Stacked table according to a selection of items in the table itself, right-click on the selection to show the context menu, and then select Filter by or Filter excluding. To remove these filters, select Remove filters from the header menus of the filtered columns.
Tip
You can rearrange columns in Stacked tables by dragging the headers with your mouse. The ordering will be remembered the next time you open Spine DB editor.
Viewing parameter values and relationships¶
Using Pivot table and Frozen table¶
Pivot table and Frozen table present data for an individual class from one database in the form of a pivot table, optionally with frozen dimensions:

To populate the tables with data for a certain class, just select the corresponding class item in either Object tree or Relationship tree.
Selecting the input type¶
Pivot table and Frozen table support four different input types:
Parameter value (the default): it shows objects, parameter definitions, alternatives, and databases in the headers, and corresponding parameter values in the table body.
Index expansion: Similar to the above, but it also shows parameter indexes in the headers. Indexes are extracted from special parameter values, such as time-series.
Relationship: it shows objects, and databases in the headers, and corresponding relationships in the table body. It only works when selecting a relationship class in Relationship tree.
Scenario: it shows scenarios, alternatives, and databases in the header, and corresponding rank in the table body.
You can select the input type from the Pivot section in the hamburger menu.
Note
In Pivot table, header blocks in the top-left area indicate what is shown in each horizontal and vertical header. For example, in Parameter value input type, by default, the horizontal header has two rows, listing alternative and parameter names, respectively; whereas the vertical header has one or more columns listing object names.
Pivoting and freezing¶
To pivot the data, drag a header block across the top-left area of the table. You can turn a horizontal header into a vertical header and viceversa, as well as rearrange headers vertically or horizontally.
To freeze a dimension, drag the corresponding header block from Pivot table into Frozen table. To unfreeze a frozen dimension, just do the opposite.
Note
Your pivoting and freezing selections for any class will be remembered when switching to another class.
Filtering¶
To apply a custom filter on Pivot table, click on the arrow next to the name of any header block. A menu will pop up listing the items in the corresponding row or column:

Uncheck the items you don’t want to see in the table and press Ok. Additionally, you can type in the search bar at the top of the menu to filter the list of items. To remove the current filter, select Remove filters.
To filter the pivot table by an individual vector across the frozen dimensions, select the corresponding row in Frozen table.
Viewing alternatives and scenarios¶
You can find alternatives and scenarios from all databases under Alternative/Scenario tree:

To view the alternatives and scenarios from each database, expand the root item for that database. To view all alternatives, expand the alternative item. To view all scenarios, expand the scenario item. To view the alternatives for a particular scenario, expand the scenario_alternative item under the corresponding scenario item.
Viewing tools and features¶
You can find tools, features, and methods from all databases under Tool/Feature tree:

To view the features and tools from each database, expand the root item for that database. To view all features, expand the feature item. To view all tools, expand the tool item. To view the features for a particular tool, expand the tool_feature item under the corresponding tool item. To view the methods for a particular tool-feature, expand the tool_feature_method item under the corresponding tool-feature item.
Viewing parameter value lists¶
You can find parameter value lists from all databases under Parameter value list:

To view the parameter value lists from each database, expand the root item for that database. To view the values for each list, expand the corresponding list item.
Adding data¶
This section describes the available tools to add new data.
Adding object classes¶
From Object tree¶
Right-click on the root item in Object tree to display the context menu, and select Add object classes.
The Add object classes dialog will pop up:

Enter the names of the classes you want to add under the object class name column. Optionally, you can enter a description for each class under the description column. To select icons for your classes, double click on the corresponding cell under the display icon column. Finally, select the databases where you want to add the classes under databases. When you’re ready, press Ok.
Adding objects¶
From Object tree or Entity graph¶
Right-click on an object class item in Object tree, or on an empty space in the Entity graph, and select Add objects from the context menu.
The Add objects dialog will pop up:

Enter the names of the object classes under object class name, and the names of the objects under object name. To display a list of available classes, start typing or double click on any cell under the object class name column. Optionally, you can enter a description for each object under the description column. Finally, select the databases where you want to add the objects under databases. When you’re ready, press Ok.
From Pivot table¶
To add an object to a specific class, bring the class to Pivot table using any input type (see Using Pivot table and Frozen table). Then, enter the object name in the last cell of the header corresponding to that class.
Duplicating objects¶
To duplicate an existing object with all its relationships and parameter values, right-click over the corresponding object item in Object tree to display the context menu, and select Duplicate object. Enter a name for the duplicate and press Ok.
Adding object groups¶
Right-click on an object class item in Object tree, and select Add object group from the context menu.
The Add object group dialog will pop up:

Enter the name of the group, adn select the database where you want the group to be created. Select the member objects under Non members, and press the button in the middle that has a plus sign. Multiple selection works.
When you’re happy with your selections, press Ok to add the group to the database.
Adding relationship classes¶
From Object tree or Relationship tree¶
Right-click on an object class item in Object tree, or on the root item in Relationship tree, and select Add relationship classes from the context menu.
The Add relationship classes dialog will pop up:

Select the number of dimensions using the spinbox at the top; then, enter the names of the object classes for each dimension under each object class name column, and the names of the relationship classes under relationship class name. To display a list of available object classes, start typing or double click on any cell under the object class name columns. Optionally, you can enter a description for each relationship class under the description column. Finally, select the databases where you want to add the relationship classes under databases. When you’re ready, press Ok.
Adding relationships¶
From Object tree or Relationship tree¶
Right-click on a relationship class item either in Object tree or Relationship tree, and select Add relationships from the context menu.
The Add relationships dialog will pop up:

Select the relationship class from the combo box at the top; then, enter the names of the objects for each member object class under the corresponding column, and the name of the relationship under relationship name. To display a list of available objects for a member class, start typing or double click on any cell under that class’s column. Finally, select the databases where you want to add the relationships under databases. When you’re ready, press Ok.
From Pivot table¶
To add a relationship for a specific class, bring the class to Pivot table using the Relationship input type (see Using Pivot table and Frozen table). The Pivot table headers will be populated with all possible combinations of objects across the member classes. Locate the objects you want as members in the new relationship, and check the corresponding box in the table body.
From Entity graph¶
Make sure all the objects you want as members in the new relationship are in the graph. To start the relationship, either double click on one of the object items, or right click on it to display the context menu, and choose Add relationships. A menu will pop up showing the available relationship classes. Select the class you want; the mouse cursor will adopt a cross-hairs shape. Click on each of the remaining member objects, one by one and in the right order, to add them to the relationship. Once you’ve added enough objects for the relationship class, a dialog will pop up. Check the boxes next to the relationships you want to add, and press Ok.
Tip
All the Add… dialogs support pasting tabular (spreadsheet) data from the clipboard. Just select any cell in the table and press Ctrl+V. If needed, the table will grow to accommodate the exceeding data. To paste data on multiple cells, select all the cells you want to paste on and press Ctrl+V.
Adding parameter definitions¶
From Stacked tables¶
To add new parameter definitions for an object class, just fill the last empty row of Object parameter definition. Enter the name of the class under object_class_name, and the name of the parameter under parameter_name. To display a list of available object classes, start typing or double click under the object_class_name column. Optionally, you can also specify a default value, a parameter value list, or any number of parameter tags under the appropriate columns. The parameter is added when the background of the cells under object_class_name and parameter_name become gray.
To add new parameter definitions for a relationship class, just fill the last empty row of Relationship parameter definition, following the same guidelines as above.
From Pivot table¶
To add a new parameter definition for a class, bring the corresponding class to Pivot table using the Parameter value input type (see Using Pivot table and Frozen table). The parameter header of Pivot table will be populated with existing parameter definitions for the class. Enter a name for the new parameter in the last cell of that header.
Adding parameter values¶
From Stacked tables¶
To add new parameter values for an object, just fill the last empty row of Object parameter value. Enter the name of the class under object_class_name, the name of the object under object_name, the name of the parameter under parameter_name, and the name of the alternative under alternative_name. Optionally, you can also specify the parameter value right away under the value column. To display a list of available object classes, objects, parameters, or alternatives, just start typing or double click under the appropriate column. The parameter value is added when the background of the cells under object_class_name, object_name, and parameter_name become gray.
To add new parameter values for a relationship class, just fill the last empty row of Relationship parameter value, following the same guidelines as above.
Note
To add parameter values for an object, the object has to exist beforehand. However, when adding parameter values for a relationship, you can specify any valid combination of objects under object_name_list, and a relationship will be created among those objects if one doesn’t yet exist.
From Pivot table¶
To add parameter value for any object or relationship, bring the corresponding class to Pivot table using the Parameter value input type (see Using Pivot table and Frozen table). Then, enter the parameter value in the corresponding cell in the table body.
Tip
All Stacked tables and Pivot table support pasting tabular (e.g., spreadsheet) data from the clipboard. Just select any cell in the table and press Ctrl+V. If needed, Stacked tables will grow to accommodate the exceeding data. To paste data on multiple cells, select all the cells you want to paste on and press Ctrl+V.
Adding tools, features, and methods¶
To add a new feature, go to Tool/Feature tree and select the last item under feature in the appropriate database, start typing or press F2 to display available parameter definitions, and select the one you want to become a feature.
Note
Only parameter definitions that have associated a parameter value list can become features.
To add a new tool, just select the last item under tool in the appropriate database, and enter the name of the tool.
To add a feature for a particular tool, drag the feature item and drop it over the tool_feature list under the corresponding tool.
To add a new method for a tool-feature, select the last item under tool_feature_method (in the appropriate database), start typing or press F2 to display available methods, and select the one you want to add.
Adding alternatives and scenarios¶
From Alternative/Scenario tree¶
To add a new alternative, just select the last item under alternative in the appropriate database, and enter the name of the alternative.
To add a new scenario, just select the last item under scenario in the appropriate database, and enter the name of the scenario.
To add an alternative for a particular scenario, drag the alternative item and drop it over the scenario_alternative list under the corresponding scenario. The position where you drop it determines the alternative’s rank within the scenario.
Note
Alternatives with higher rank have priority when determining the parameter value for a certain scenario. If the parameter value is specified for two alternatives, and both of them happen to coexist in a same scenario, the value from the alternative with the higher rank is picked.
From Pivot table¶
Select the Scenario input type (see Using Pivot table and Frozen table). To add a new scenario, enter a name in the last cell of the scenario header. To add a new alternative, enter a name in the last cell of the alternative header.
Adding parameter value lists¶
To add a new parameter value list, go to Parameter value list and select the last item under the appropriate database, and enter the name of the list.
To add new values for the list, select the last empty item under the corresponding list item, and enter the value. To enter a complex value, right-click on the empty item and select Open editor from the context menu.
Note
To be actually added to the database, a parameter value list must have at least one value.
Updating data¶
This section describes the available tools to update existing data.
Updating entities and classes¶
From Object tree, Relationship tree, or Entity graph¶
Select any number of entity and/or class items in Object tree or Relationship tree, or any number of object and/or relationship items in Entity graph. Then, right-click on the selection and choose Edit… from the context menu.
One separate Edit… dialog will pop up for each selected entity or class type, and the tables will be filled with the current data of selected items. E.g.:

Modify the field(s) you want under the corresponding column(s). Specify the databases where you want to update each item under the databases column. When you’re ready, press Ok.
From Pivot table¶
To rename an object of a specific class, bring the class to Pivot table using any input type (see Using Pivot table and Frozen table). Then, just edit the appropriate cell in the corresponding class header.
Updating parameter definitions and values¶
From Stacked tables¶
To update parameter data, just go to the appropriate Stacked table and edit the corresponding row.
From Pivot table¶
To rename parameter definitions for a class, bring the corresponding class to Pivot table using the Parameter value input type (see Using Pivot table and Frozen table). Then, just edit the appropriate cell in the parameter header.
To modify parameter values for an object or relationship, bring the corresponding class to Pivot table using the Parameter value input type (see Using Pivot table and Frozen table). Then, just edit the appropriate cell in the table body.
Updating alternatives and scenarios¶
From Pivot table¶
Select the Scenario input type (see Using Pivot table and Frozen table). To rename a scenario, just edit the proper cell in the scenario header. To rename an alternative, just edit the proper cell in the alternative header.
From Alternative/Scenario tree¶
To rename a scenario or alternative, just edit the appropriate item in Alternative/Scenario tree. To change scenario alternative ranks, just drag and drop the items under scenario_alternatives.
Updating tools and features¶
To change a feature or method, or rename a tool, just edit the appropriate item in Tool/Feature tree.
Updating parameter value lists¶
To rename a parameter value list or change any of its values, just edit the appropriate item in Parameter value list.
Removing data¶
This section describes the available tools to remove data.
Removing entities and classes¶
From Object tree, Relationship tree, or Entity graph¶
Select the items in Object tree, Relationship tree, or Entity graph, corresponding to the entities and classes you want to remove. Then, right-click on the selection and choose Remove from the context menu.
The Remove items dialog will popup:

Specify the databases from where you want to remove each item under the databases column, and press Ok.
From Pivot table¶
To remove objects or relationships from a specific class, bring the class to Pivot table using the Parameter value input type (see Using Pivot table and Frozen table), and select the cells in the table headers corresponding to the objects and/or relationships you want to remove. Then, right-click on the selection and choose the corresponding Remove option from the context menu.
Alternatively, to remove relationships for a specific class, bring the class to Pivot table using the Relationship input type (see Using Pivot table and Frozen table). The Pivot table headers will be populated with all possible combinations of objects across the member classes. Locate the member objects of the relationship you want to remove, and uncheck the corresponding box in the table body.
Removing parameter definitions and values¶
From Stacked tables¶
To remove parameter definitions or values, go to the relevant Stacked table and select any cell in the row corresponding to the items you want to remove Then, right-click on the selection and choose the appropriate Remove option from the context menu.
From Pivot table¶
To remove parameter definitions and/or values for a certain class, bring the corresponding class to Pivot table using the Parameter value input type (see Using Pivot table and Frozen table). Then:
Select the cells in the parameter header corresponding to the parameter definitions you want to remove, right-click on the selection and choose Remove parameter definitions from the context menu
Select the cells in the table body corresponding to the parameter values you want to remove, right-click on the selection and choose Remove parameter values from the context menu.
Purging items¶
To remove all items of specific types, select Edit -> Purge from the hamburger menu. The Purge items dialog will pop up:

Select the databases from where you want to remove the items under Databases, and the type of items you want to remove under Items. Then, press Ok.
Removing alternatives and scenarios¶
From Pivot table¶
Select the Scenario input type (see Using Pivot table and Frozen table). To remove scenarios, just select the proper cells in the scenario header, right-click on the selection and chose Remove from the context menu. To remove alternatives, just edit the proper cells in the alternative header, right-click on the selection and chose Remove from the context menu.
From Alternative/Scenario tree¶
To remove a scenario or alternative, just select the correspoding items in Alternative/Scenario tree, right-click on the selection and chose Remove from the context menu.
Removing tools and features¶
To remove a feature, tool, or method, just select the correspoding items in Tool/Feature tree, right-click on the selection and chose Remove from the context menu.
Removing parameter value lists¶
To remove a parameter value list or any of its values, just select the correspoding items in Parameter value list, right-click on the selection and chose Remove from the context menu.
Managing data¶
This section describes the available tools to manage data, i.e., adding, updating or removing data at the same time.
Managing object groups¶
To modify object groups, expand the corresponding item in Object tree to display the members item, right-click on the latter and select Manage members from the context menu. The Manage parameter tags dialog will pop up:

To add new member objects, select them under Non members, and press the button in the middle that has a plus sign. To remove current member objects, select them under Members, and press the button in the middle that has a minus sign. Multiple selection works in both lists.
When you’re happy, press Ok.
Note
Changes made using the Manage members dialog are not applied to the database until you press Ok.
Managing relationships¶
Select Edit -> Manage relationships from the menu bar. The Manage relationships dialog will pop up:

To get started, select a relationship class and a database from the combo boxes at the top.
To add relationships, select the member objects for each class under Available objects and press the Add relationships button at the middle of the form. The relationships will appear at the top of the table under Existing relationships.
To add multiple relationships at the same time, select multiple objects for one or more of the classes.
Tip
To extend the selection of objects for a class, press and hold the Ctrl key while clicking on more items.
Note
The set of relationships to add is determined by applying the product operation over the objects selected for each class.
To remove relationships, select the appropriate rows under Existing relationships and press the Remove relationships button on the right.
When you’re happy with your changes, press Ok.
Note
Changes made using the Manage relationships dialog are not applied to the database until you press Ok.
Importing and exporting data¶
This section describes the available tools to import and export data.
Overview¶
Spine database editor supports importing and exporting data in three different formats: SQLite, JSON, and Excel. The SQLite import/export uses the Spine database format. The JSON and Excel import/export use a specific format described below.
Tip
To create a template file with the JSON or Excel format you can simply export an existing Spine database into one of those formats.
Excel format¶
The Excel format consists of one sheet per object and relationship class. Each sheet can have one of four different formats:
Object class with scalar parameter data:
Object class with indexed parameter data:
Relationship class with scalar parameter data:
Relationship class with indexed parameter data:
JSON format¶
The JSON format consists of a single JSON object with the following OPTIONAL
keys:
object_classes: the value of this key
MUST
be a JSON array, representing a list of object classes. Each element in this arrayMUST
be itself a JSON array andMUST
have three elements:The first element
MUST
be a JSON string, indicating the object class name.The second element
MUST
be either a JSON string, indicating the object class description, or null.The third element
MUST
be either a JSON integer, indicating the object class icon code, or null.
relationship_classes: the value of this key
MUST
be a JSON array, representing a list of relationships classes. Each element in this arrayMUST
be itself a JSON array andMUST
have three elements:The first element
MUST
be a JSON string, indicating the relationship class name.The second element
MUST
be a JSON array, indicating the member object classes. Each element in this arrayMUST
be a JSON string, indicating the object class name.The third element
MUST
be either a JSON string, indicating the relationship class description, or null.
parameter_value_lists: the value of this key
MUST
be a JSON array, representing a list of parameter value lists. Each element in this arrayMUST
be itself a JSON array andMUST
have two elements:The first element
MUST
be a JSON string, indicating the parameter value list name.The second element
MUST
be a JSON array, indicating the values in the list. Each element in this arrayMUST
be either a JSON object, string, number, or null, indicating the value.
object_parameters: the value of this key
MUST
be a JSON array, representing a list of object parameter definitions. Each element in this arrayMUST
be itself a JSON array andMUST
have five elements:The first element
MUST
be a JSON string, indicating the object class name.The second element
MUST
be a JSON string, indicating the parameter name.The third element
MUST
be either a JSON object, string, number, or null, indicating the parameter default value.The fourth element
MUST
be a JSON string, indicating the associated parameter value list, or null.The last element
MUST
be either a JSON string, indicating the parameter description, or null.
relationship_parameters: the value of this key
MUST
be a JSON array, representing a list of relationship parameter definitions. Each element in this arrayMUST
be itself a JSON array andMUST
have five elements:The first element
MUST
be a JSON string, indicating the relationship class name.The second element
MUST
be a JSON string, indicating the parameter name.The third element
MUST
be either a JSON object, string, number, or null, indicating the parameter default value.The fourth element
MUST
be a JSON string, indicating the associated parameter value list, or nullThe last element
MUST
be either a JSON string, indicating the parameter description, or null.
objects: the value of this key
MUST
be a JSON array, representing a list of objects. Each element in this arrayMUST
be itself a JSON array andMUST
have three elements:The first element
MUST
be a JSON string, indicating the object class name.The second element
MUST
be a JSON string, indicating the object name.The third element
MUST
be either a JSON string, indicating the object description, or null.
relationships: the value of this key
MUST
be a JSON array, representing a list of relationships. Each element in this arrayMUST
be itself a JSON array andMUST
have two elements:The first element
MUST
be a JSON string, indicating the relationship class name.The second element
MUST
be a JSON array, indicating the member objects. Each element in this arrayMUST
be a JSON string, indicating the object name.
object_parameter_values: the value of this key
MUST
be a JSON array, representing a list of object parameter values. Each element in this arrayMUST
be itself a JSON array andMUST
have four elements:The first element
MUST
be a JSON string, indicating the object class name.The second element
MUST
be a JSON string, indicating the object name.The third element
MUST
be a JSON string, indicating the parameter name.The fourth element
MUST
be either a JSON object, string, number, or null, indicating the parameter value.
relationship_parameter_values: the value of this key
MUST
be a JSON array, representing a list of relationship parameter values. Each element in this arrayMUST
be itself a JSON array andMUST
have four elements:The first element
MUST
be a JSON string, indicating the relationship class name.The second element
MUST
be a JSON array, indicating the relationship’s member objects. Each element in this arrayMUST
be a JSON string, indicating the object name.The third element
MUST
be a JSON string, indicating the parameter name.The fourth element
MUST
be either a JSON object, string, number, or null, indicating the parameter value.
Example:
{
"object_classes": [
["connection", "An entity where an energy transfer takes place", 280378317271233],
["node", "An entity where an energy balance takes place", 280740554077951],
["unit", "An entity where an energy conversion process takes place", 281470681805429],
],
"relationship_classes": [
["connection__node__node", ["connection", "node", "node"] , null],
["unit__from_node", ["unit", "node"], null],
["unit__to_node", ["unit", "node"], null],
],
"parameter_value_lists": [
["balance_type_list", ["\"balance_type_node\"", "\"balance_type_group\"", "\"balance_type_none\""]],
["truth_value_list", ["\"value_false\"", "\"value_true\""]],
],
"object_parameters": [
["connection", "connection_availability_factor", 1.0, null, null],
["node", "balance_type", "balance_type_node", "balance_type_list", null],
],
"relationship_parameters": [
["connection__node__node", "connection_flow_delay", {"type": "duration", "data": "0h"}, null, null],
["unit__from_node", "unit_capacity", null, null, null],
["unit__to_node", "unit_capacity", null, null, null],
],
"objects": [
["connection", "Bastusel_to_Grytfors_disch", null],
["node", "Bastusel_lower", null],
["node", "Bastusel_upper", null],
["node", "Grytfors_upper", null],
["unit", "Bastusel_pwr_plant", null],
],
"relationships": [
["connection__node__node", ["Bastusel_to_Grytfors_disch", "Grytfors_upper", "Bastusel_lower"]],
["unit__from_node", ["Bastusel_pwr_plant", "Bastusel_upper"]],
["unit__to_node", ["Bastusel_pwr_plant", "Bastusel_lower"]],
],
"object_parameter_values": [
["node", "Bastusel_upper", "demand", -0.2579768519],
["node", "Bastusel_upper", "fix_node_state", {"type": "time_series", "data": {"2018-12-31T23:00:00": 5581.44, "2019-01-07T23:00:00": 5417.28}}],
["node", "Bastusel_upper", "has_state", "value_true"],
],
"relationship_parameter_values": [
["connection__node__node", ["Bastusel_to_Grytfors_disch", "Grytfors_upper", "Bastusel_lower"], "connection_flow_delay", {"type": "duration", "data": "1h"}],
["unit__from_node", ["Bastusel_pwr_plant", "Bastusel_upper"], "unit_capacity", 127.5],
]
}
Importing¶
To import a file, select File –> Import from the hamburger menu. The Import file dialog will pop up. Select the file type (SQLite, JSON, or Excel), enter the path of the file to import, and accept the dialog.
Tip
You can undo import operations using Edit -> Undo.
Exporting¶
Mass export¶
To export items in mass, select File –> Export from the hamburger menu. The Export items dialog will pop up:

Select the databases you want to export under Databases, and the type of items under Items, then press Ok. The Export file dialog will pop up now. Select the file type (SQLite, JSON, or Excel), enter the path of the file to export, and accept the dialog.
Selective export¶
To export a specific subset of items, select the corresponding items in either Object tree and Relationship tree, right click on the selection to bring the context menu, and select Export.
The Export file dialog will pop up. Select the file type (SQLite, JSON, or Excel), enter the path of the file to export, and accept the dialog.
Session export¶
To export only uncommitted changes made in the current session, select File –> Export session from the hamburger menu.
The Export file dialog will pop up. Select the file type (SQLite, JSON, or Excel), enter the path of the file to export, and accept the dialog.
Note
Export operations include all uncommitted changes.
Accessing/using exported files¶
Whenever you successfully export a file, a button with the file name is created in the Exports bar at the bottom of the form. To open the file in your registered program, press that button. To open the containing folder, click on the arrow next to the file name and select Open containing folder from the popup menu.
Committing and rolling back¶
Note
Changes are not immediately saved to the database(s). They need to be committed separately.
To commit your changes, select Session -> Commit from the hamburger menu, enter a commit message and press Commit. Any changes made in the current session will be saved into the database.
To undo all changes since the last commit, select Session -> Rollback from the hamburger menu.
Tip
To undo/redo individual changes, use the Undo and Redo actions from the Edit menu.
Plotting¶
Basic data visualization is available in the Spine database editors. Currently, it is possible to plot scalar values as well as time series, arrays and one dimensional maps with some limitations.
To plot a column, select the values from a table and then Plot from the right click popup menu.


Selecting data in multiple columns plots the selection in a single window.
To add a plot to an existing window select the target plot window from the Plot in window submenu.


X column in pivot table¶
It is possible to plot a column of scalar values against a designated X column in the pivot table.
To set a column as the X column right click the top empty area above the column header and select Use as X from the popup menu. (X) in the topmost cell indicates that the column is designated as the X axis.

When selecting and plotting other columns in the same table the data will be plotted against the values in the X column instead of row numbers.
Parameter value editor¶
Parameter value editor is used to edit object and relationship parameter values such as time series, time patterns or durations. It can also convert between different value types, e.g. from a time series to a time pattern.
The editor is available from a right click popup menu or by double clicking a parameter value in one of the Spine database editors.
Choosing value type¶

The combo box at the top of the editor window allows changing the type of the current value.
Plain values¶
The simplest parameter values are of the Plain value type. The editor window lets you to write a number or string directly to the input field or set it to true, false or null as needed.

Maps¶
Maps are versatile nested data structures designed to contain complex data including one and multi dimensional indexed arrays. In Parameter value editor a map is shown as a table where the last non-empty cell on each row contains the value while the preceding cells contain the value’s indexes.

The extra gray column on the right allows expanding the map with a new dimension. You can append a value to the map by editing the bottom gray row. The reddish cells are merely a guide for the eye to indicate that the map has different nesting depths.
A Right click popup menu gives options to open a value editor for individual cells, to add/insert/remove rows or columns (effectively changing map’s dimensions), or to trim empty columns from the right hand side.
Copying and pasting data between cells and external programs works using the usual Ctrl-C and Ctrl-V keyboard shortcuts.
Convert leaves to time series ‘compacts’ the map by converting the last dimension into time series. This works only if the last dimension’s type is datetime. For example the following map contains two time dimensions. Since the indexes are datetimes, the ‘inner’ dimension can be converted to time series.

After clicking Convert leaves to time series the map looks like this:

Time series¶
There are two types of time series: variable and fixed resolution. Variable resolution means that the time stamps can be arbitrary while in fixed resolution series the time steps between consecutive stamps are fixed.


The editor window is split into two in both cases. The left side holds all the options and a table with all the data while the right side shows a plot of the series. The plot is not editable and is for visualization purposes only.
In the table rows can be added or removed from a popup menu available by a right click. Editing the last gray row appends a new value to the series. Data can be copied and pasted by Ctrl-C and Ctrl-V. Copying from/to an external spreadsheet program is supported.
The time steps of a fixed resolution series are edited by the Start time and Resolution fields. The format for the start time is ISO8601. The Resolution field takes a single time step or a comma separated list of steps. If a list of resolution steps is provided then the steps are repeated so as to fit the data in the table.
The Ignore year option available for both variable and fixed resolution time series allows the time series to be used independent of the year. Only the month, day and time information is used by the model.
The Repeat option means that the time series is cycled, i.e. it starts from the beginning once the time steps run out.
Time patterns¶
The time pattern editor holds a single table which shows the time period on the right column and the corresponding values on the left. Inserting/removing rows and copy-pasting works as in the time series editor.

Arrays¶
Arrays are lists of values of a single type. Their editor is split into two: the left side holds the actual array while the right side contains a plot of the array values versus the values’ positions within the array. Note that not all value types can be plotted. The type can be selected from the Value type combobox. Inserting/removing rows and copy-pasting works as in the time series editor.

Datetimes¶
The datetime value should be entered in ISO8601 format. Clicking small arrow on the input field pops up a calendar that can be used to select a date.

Durations¶
A single value or a comma separated list of time durations can be entered to the Duration field.

Importing and exporting data¶
This section explains the different ways of importing and exporting data to and from a Spine database.
Importing data with Importer¶
Data importing is handled by the Importer project item which can import tabulated and to some degree tree-structured data into a Spine database from various formats. The same functionality is also available in Spine database editor from File->Import but using an Importer item is preferred because then the process is documented and repeatable.
Tip
A Tool item can also be connected to Importer to import tool’s output files to a database.
The heart of Importer is the Import Editor window in which the mappings from source data to Spine database entities are set up. The editor window can be accessed by the Import Editor… button in Importer’s Properties dock. Note, that you have to select one of the files in the Source files list before clicking the button.

The Import Editor windows is divided into two parts: Sources shows all the ‘sheets’ contained in the file, some options for reading the file correctly, and a preview table to visualize and configure how the data on the selected sheet would be mapped. Mappings, on the other hand, shows the actual importing settings, the mappings from the input data to database entities.

The options in the Mappings part declare if the currently selected sheet will be imported as an object or relationship and what type of parameters, if any, the sheet contains. The table can be used to configure how the input data is interpreted: which row or column contains the entity class names, parameter values, time stamps and so on.

It might be helpful to fill in the mapping options using the preview table in the Sources part. Right clicking on the table cells shows a popup menu that lets one to configure how the rows and colunms are read upon importing.

An important aspect of data import is whether each item in the input data should be read as a string, a number, a time stamp, or something else. By default all input data is read as strings. However, more often than not things like parameter values are actually numbers. It is possible to control what type of data each column (and, sometimes, each row) contains from the preview table. Clicking the data type indicator button on column headers pops up a menu with a selection of available data types. Right clicking the column header also gives the opportunity to change the data type of all columns at once.

Exporting data with Exporter¶
Exporter writes database data into regular files that can be used by Tools and external software that do not read the Spine database format. Various tabulated file formats are supported some of which require specific export settings; see below for more details.
At its heart Exporter maps database items such as entity class or entity names to an output table. Each item has a user given output position on the table, for example a column number. By default data is mapped to columns but it is also possible to create pivot tables.
Exporter saves its settings or export mappings as a specification
that can be reused by other exporters or even other projects.
The specification can be edited in Exporter specification editor
which is accessible by the button in the item’s Properties dock
or by double clicking exporter’s icon on the Design view.
A specification that is not associated with any specific Exporter project item can be created
and edited from the Main toolbar.
Properties dock¶
Exporter’s Properties dock controls project item specific settings that are not part of the item’s specification.

Specification used by the active Exporter item can be selected from the Specification combobox.
The button opens Exporter specification editor
where it is possible to edit the specification.
Databases available for export from connected project items such as Data stores are listed in separate boxes below the Specification combobox. An output filename is required for each database.
Checking the Time stamp output directories box adds a time stamp to the item’s output directories preventing output files from being overwritten. This may be useful for debugging purposes.
The Cancel export on error checkbox controls whether execution bails out on errors that may be otherwise non-fatal.
Exporter’s data directory can be opened in system’s file browser by the button.
The output files are written in data directory’s
output
subdirectory.
Exporter specification editor¶
Specification editor is used to create mappings that define how data is exported to the output file. Mappings define one or more tables and their contents but are otherwise output format agnostic. Some output formats, e.g. SQL and gdx, interpret the tables in specific ways, however. Other formats which inherently cannot write multiple tables into a single file, such as csv, may end up exporting multiple files. See the sections below for format specific intricacies.
When opened for the first time Specification editor looks like in the figure below. The window is tabbed allowing multiple specifications to be edited at the same time. Each tab consists of dock widgets which can be reorganized to suit the user’s needs. The ‘hamburger’ menu on the top right corner gives access to some important actions such as Save and Close. Undo and redo can be found from the menu as well.

The only requirement for a specification is a name. This can be given on the Name field field on the top bar. The Description field allows for an additional explanatory text.
The current output format can be changed by the Format combobox on Export options dock.

Specification’s mappings are listed in the Mappings dock shown above. The Add button adds a new mapping while the Remove button removes selected mappings. Mappings can be renamed by double clicking their names on the list. The checkbox in front of mapping’s name shows if the mapping is currently enabled. Use the Toggle enabled button to toggle the enabled state of all mappings at once.
The tables defined by the mappings are written in the order shown on the mapping list’s Write order column. This may be important if the tables need to be in certain order in the output file or when multiple mappings output to a single table. Mappings can be sorted by their write order by clicking the header of the Write order column. The Write earlier and Write later buttons move the currently selected mapping up and down the list.


Currently selected mapping is edited using the controls in Mapping options and Mapping specification docks. The Mapping options dock contains controls that apply to the mapping as a whole, e.g. what data the output tables contain. Mapping specification, on the other hand, contains a table which defines the structure of the mapping’s output tables.
What database items the mapping outputs is chosen using the Item type combobox in Mapping options dock. For instance, the Object classes option outputs object classes, objects and, optionally, object parameters and related items while the Relationship classes option outputs relationship classes and relationships. Checking the Always export header checkbox outputs a table that has fixed headers even if the table is otherwise empty. If Item type is Relationship class, the Relationship dimensions spinbox can be used to specify the maximum number of relationships’ dimensions that the mapping is able to handle. Parameters can be outputted by choosing their value type using the Parameter type combobox. The Value choice adds rows to Mapping specification for parameter values associated with individual entities while Default value allows outputting parameters’ default values. The maximum number of value dimensions in case of indexed values (time series, maps, time patterns, arrays) the mapping can handle is controlled by the Parameter dimensions spinbox. The Fixed table name checkbox enables giving a user defined table name to the mapping’s output table. In case the mapping is pivoted and Mapping specification contains items that are hidden, it is possible that a number of data elements end up in the same output table cell. The Group function combobox offers some basic functions to aggregate such data into the cells.
The contents of the table on the Mapping specification dock depends on choices on Mapping options, e.g. the item type, parameter type or dimensions. Each row corresponds to an item in the database: object class names, object names, parameter values etc. The item’s name is given in the Mapping type column. The colors help to identify the corresponding elements in the preview. The Map to column defines the position of the item, that is, where the item is written or otherwise used when the output tables are generated. By default, a plain integral number in this column means that the item is written to that column in the output table. From the other choices, hidden means that the item will not show on the output. Table name, on the other hand, uses the item as output table names. For example, outputting object classes as table names will generate one new table for every object class in the database, each named after the class. Each table in turn will contain the parameters and objects of the table’s object class. If multiple mappings generate a table with a common name then each mapping appends to the same table in the order specified by the Write order column on Mappings dock. The column header position makes the item a column header for a buddy item. Buddy items have some kind of logical relationship with their column header, for instance the buddy of an object class is its objects; setting the object class to column header will write the name of the class as the objects’ column header.
Note
Currently, buddies are fixed and defined only for a small set database items. Therefore, column header will not always produce sensible results.
Changing the column and pivot header row positions leaves sometimes gaps in the output table. If such gaps are not desirable the Compact button reorders the positions by removing the gaps. This may be useful when the output format requires such gapless tables.
The checkboxes in Pivoted column on the Mapping specification dock toggle the mapping into pivoted mode. One or more items on the table can be set as pivoted. They then act as a pivot header for the data item which is the last non-hidden item on the list. Once checked as pivoted, an item’s position column defines a pivot header row instead of output column.
By default a row ends up in the output table only when all mapping items yield some data. For example, when exporting object classes and objects, only classes that have objects get written to output. However, sometimes it is useful to export ‘empty’ object classes as well. For this purpose a mapping can be set as nullable in the Nullable column. Continuing the example, checking the Nullable checkbox for Objects would produce an output table with all object classes including ones without objects. The position where objects would normally be outputted are left empty for those classes.
Besides the column header position it is possible give fixed column headers to items using the Header column in Mapping specification dock. Note that checking the Always export header option in the Mapping options dock outputs the fixed headers even if there is no other data in a table.
The Mapping specification dock’s Filter column provides refined control on which database items the mapping outputs. The column uses regular expressions to filter what gets outputted. See Basic regular expression for filtering.

A preview of what will be written to the output is available in the preview dock widgets. A database connection is needed to generate the preview. The Preview controls dock provides widgets to choose an existing database or to load one from a file. Once a database is available and the preview is enabled the mappings and the tables they would output are listed on the Preview tables dock. Selecting a table from the list shows the table’s contents on the Preview contents dock. The colors on the table correspond to the colors in Mapping specification dock.
Basic regular expressions for filtering¶
The Filter field in Mapping specification accepts regular expressions to filter what data gets outputted by that mapping item. Below are examples on how to create some basic filters.
Single item
Writing the item’s name to the field filters out all other items.
For example, to output the object class called ‘node’ only, write node
to the Filter field.
OR operator
The vertical bar |
serves as the OR operator.
node|unit
as a filter for object classes would output classes named ‘node’ and ‘unit’.
Excluding an item
While perhaps not the most suitable task for regular expressions it is still possible to ‘negate’ a filter. ^(?!node). would exclude all items names of which start with ‘node’.
Csv and multiple tables¶
Csv files are flat text files and therefore do not directly support multiple tables. Instead, multiple tables are handled as separate output files.
Only mappings that output an anonymous table
actually write to the file specified on the Exporter’s properties dock.
Named tables get written to files named after the table plus the .csv
extension.
For example, a table named node
would result in a file called node.csv.
SQL export¶
Note
Currently only sqlite is supported.
The SQL backend writes the tables to the target database in a relatively straightforward way:
Tables are named after the table name provided by the mappings. Anonymous tables are not supported.
The first row of each table is used as column names in the database. Thus, each column in a mapping should have a fixed header or a header produced by an item set to column header position.
Column data types are sniffed from the second row. Empty values or a missing row result in string type.
There must be an item assigned to each column. Empty columns confuse the SQL backend.
Pivot tables do not generally make sense with the SQL backend unless the resulting table somehow follows the above rules.
GAMS gdx export¶
Note
You need to have GAMS installed to use this functionality. However, you do not need to own a GAMS license as the demo version works just as well.
Note
The bitness (32 or 64bit) of GAMS must match the bitness of the Python interpreter.
The gdx backend turns the output tables to GAMS sets, parameters and scalars following the rules below:
Table names correspond the names of sets, parameters and scalars. Thus, anonymous tables are not supported.
There must be an item assigned to each column. Empty columns confuse the gdx backend.
Pivot tables do not generally make sense with the gdx backend unless the resulting table somehow follows the rules listed here.
Sets:
Everything that is not identified as parameter or scalar is considered a GAMS set.
Each column corresponds to a dimension.
The first row is used to name the dimension’s domain. Thus, each column in a mapping should have a fixed header or a header produced by an item set to column header position. Note that
*
is a valid fixed header and means that the dimension has no specific domain.
Parameters:
A table that contains numerical values as the last (rightmost) column is considered a GAMS parameter.
The last column should contain the parameter’s values while the other columns contain the values’ dimension.
Dimensions’ domains are taken from the header row, see Sets above. Note, that the value column does not need a header.
Scalars:
A table that contains a numerical value in the top left cell is considered a GAMS scalar. Everything else (except the table name) is ignored.
The data in the top left cell is the scalar’s value.
Exporting to GAMS with GdxExporter¶
Note
GdxExporter is pending for removal and its use in new projects is discouraged. Use Exporter instead.
Note
You need to have GAMS installed to use this functionality. However, you do not need to own a GAMS license as the demo version works just as well.
Note
The bitness (32 or 64bit) of GAMS has to match the bitness of the Python interpreter.
Databases can be exported to GAMS .gdx
files by the GdxExporter project item.
When a project is executed, GdxExporter writes its output files to its data folder
and forwards file paths to project items downstream.
If a Tool is to use such a file, remember to add the file as one of the Tool specification’s input files!
The mapping between entities in a Spine database and GAMS is as follows:
Database entity |
GAMS entity |
---|---|
Object class |
Universal set (or domain) |
Object |
Universal set member |
Object parameter |
Parameter |
Relationship class |
Subset of universal sets |
Relationship |
Subset member |
Relationship parameter |
Parameter |
Note
Currently, it is not possible to use subsets (relationship classes) as dimensions for other subsets due to technical limitations. For example, if there is a domain A(*) and a subset foo(A), a subset of foo has to be expressed as bar(A) instead of bar(foo).
It is also possible to designate a single object class as a Global parameter. The parameters of the objects of that class will be exported as GAMS scalars.
Some GAMS models need their data to be in a specific order in the .gdx
.
This is not directly supported by the database.
Rather, user has to specify the desired exporting order using the GdxExporter item’s settings.
GdxExporter Project Item¶
The image below shows the properties dock of GdxExporter with two Data Sources connected to it.

For each connected Data Store a box with the database’s URL and export file name field is shown on the dock. The Settings… buttons open Gdx Export settings windows to allow editing database specific export parameters such as the order in which entities are exported from the database.

The Gdx Export settings window (see above) contains a Sets list which shows all GAMS sets (gray background) and subsets that are available in the database. The sets are exported in the order they are shown in the list. The Move Up and Move Down buttons can be used to move the selected set around. Note that you cannot mix sets with subsets so all sets always get exported before the subsets.
The checkbox next to the set name is used to control which sets are actually exported. Note that it is not possible to change this setting for certain sets. Global parameters domain is never exported, only its parameters which become GAMS scalars. Further, sets created for Indexed paramaters are always exported.
The Set Contents box lists the members of the selected set or subset. Their order of export can be changed the same way as with sets by Move Up and Move Down. The Alphabetic button sorts the members alphabetically.
Time series and time patterns cannot be exported as-is. They need to be tied up to a GAMS set. This can be achieved from the window that opens from the Indexed parameters… button. See the Exporting time series and patterns section below for more information.
Finally, one of the sets can be designated as the global parameter set. This is achieved by choosing the set’s name in the Global parameters domain box. Note that this set is not exported, only its parameters are. They end up as GAMS scalars.
Exporting time series and patterns¶
Since GAMS has no notion of time series or time patterns these types need special handling when exported
to a .gdx
file. Namely, the time stamps or time periods (i.e. parameter indexes) need be available
as GAMS sets in the exported file. It is possible to use an existing set or create a new one for this purpose.
The functionality is available in Gdx Parameter Indexing Settings window
accessible from the Indexed Parameters… button.

The above figure shows the indexing settings when an existing GAMS set is used to replace the original time stamps of a time series in a parameter called ‘size’. The choice between using an existing set or creating a new one can be changed by the Use existing domain and Create new index domain radio buttons. When using an existing set it is selected by the combobox. In the above figure, ALL TS set is used for indexing.
In case of existing set it is possible that not all the set’s contents are used for indexing. The table occupying the right side of the above figure shows which of the set’s keys index which parameter values. The first column contains the keys of the currently selected set whereas the other columns contain the parameter’s values, one column for each object that has the parameter. Selecting and deselecting rows in the table changes the indexing as only the keys on selected rows are used to index the parameter. Shift, ctrl and ctrl-A help in manual selection. If the selected indexes have certain pattern it might be useful to utilize the Label picking expression field which selects the set keys using a Python expression returning a boolean value. Some examples:
Expression |
Effect |
---|---|
|
Select the third row only |
|
Select even rows |
|
Select odd rows except row 9 |
The Indexing domains list allows to shuffle the order of the parameter’s dimensions. The bold dimension is the new dimension that is added to the parameter. It can be moved around by the Move Left and Move Right buttons.

It is possible to create a new indexing set by choosing Create new index domain as shown in the figure above. Domain name is mandatory for the new domain. A Description can also be provided but it is optional. There are two options to generate the index keys: extract the time stamps or time periods from the parameter itself or generate them using a Python expression. The Extract index from parameter button can be used to extract the keys from the parameter. The Generator expression field, on the other hand, is used to generate index keys for the new set. The expression should return Python object that is convertible to string. Below are some example expressions:
Expression |
Keys |
---|---|
|
1, 2, 3,… |
|
0000, 0001, 0002,… |
|
T001, T002, T003,… |
Spine datapackage editor¶
Note
This section is a work in progress.
This section describes the Spine datapackage editor, used to interact with tabular data and export it into Spine format.
To open the Spine datapackage editor, select a Data Connection with CSV files in it, and press the Datapackage button in its Properties:


Terminology¶
Here is a list of definitions related to Spine project, SpineOpt.jl, and Spine Toolbox.
Arc Graph theory term. See Connection.
Case study Spine project has 13 case studies that help to improve, validate and deploy different aspects of the SpineOpt.jl and Spine Toolbox.
Connection an arrow on Spine Toolbox Design View that is used to connect project items to each other to form a DAG.
Data Connection is a project item used to store a collection of data files that may or may not be in Spine data format. It facilitates data transfer from original data sources e.g. spreadsheet files to Spine Toolbox. The original data source file does not need to conform to the format that Spine Toolbox is capable of reading, since there we can use an interpreting layer (Importer) between the raw data and the Spine format database (Data Store).
Data Package is a data container format consisting of a metadata descriptor file (
datapackage.json
) and resources such as data files.Data sources are all the original, unaltered, sources of data that are used to generate necessary input data for Spine Toolbox tools.
Data Store is a project item. It’s a Spine Toolbox internal data container which follows the Spine data model. A data store is implemented using a database, it may be, for example, an SQL database.
Design View A sub-window on Spine Toolbox main window, where project items and connections are visualized.
Direct predecessor Immediate predecessor. E.g. in DAG x->y->z, direct predecessor of node z is node y. See also predecessor.
Direct successor Immediate successor. E.g. in DAG x->y->z, direct successor of node x is node y. See also successor.
Directed Acyclic Graph (DAG) Finite directed graph with no directed cycles. It consists of vertices and edges. In Spine Toolbox, we use project items as vertices and connections as edges to build a DAG that represents a data processing chain (workflow).
Edge Graph theory term. See Connection
GdxExporter is a project item that allows exporting a Spine data structure from a Data Store into a .gdx file which can be used as an input file in a Tool.
Importer is a project item that can be used to import data from e.g. an Excel file, transform it to Spine data structure, and into a Data Store.
Node Graph theory term. See Project item.
Predecessor Graph theory term that is also used in Spine Toolbox. Preceding project items of a certain project item in a DAG. For example, in DAG x->y->z, nodes x and y are the predecessors of node z.
Project in Spine Toolbox consists of project items and connections, which are used to build a data processing chain for solving a particular problem. Data processing chains are built and executed using the rules of Directed Acyclic Graphs. There can be any number of project items in a project.
Project item Spine Toolbox projects consist of project items. Project items together with connections are used to build Directed Acyclic Graphs (DAG). Project items act as nodes and connections act as edges in the DAG. See Project Items for an up-to-date list on project items available in Spine Toolbox.
Scenario A scenario is a meaningful data set for the target tool.
Spine data structure Spine data structure defines the format for storing and moving data within Spine Toolbox. A generic data structure allows representation of many different modelling entities. Data structures have a class defining the type of entity they represent, can have properties and can be related to other data structures. Spine data structures can be manipulated and visualized within Spine Toolbox while SpineOpt.jl will be able to directly utilize as well as output them.
SpineOpt.jl An interpreter, which formulates a solver-ready mixed-integer optimization problem based on the input data and the equations defined in the SpineOpt.jl. Outputs the solver results.
Source directory In context of Tool specifications, a source directory is the directory where the main program file of the Tool specification is located. This is also the recommended place for saving the Tool specification file (.json).
Successor Graph theory term that is also used in Spine Toolbox. Following project items of a certain project item in a DAG. For example, in DAG x->y->z, nodes y and z are the successors of node x.
Tool is a project item that is used to execute Python, Julia, GAMS, executable scripts, or simulation models. This is done by creating a Tool specification defining the script or program the user wants to execute in Spine Toolbox. Then you need to attach the Tool specification to a Tool project item. Tools can be used to execute a computational process or a simulation model, or it can also be a process that converts data or calculates a new variable. In general, Tools may take some data as input and produce an output.
Tool specification is a JSON structure that contains metadata required by Spine Toolbox to execute a computational process or a simulation model. The metadata contains; type of the program (Python, Julia, GAMS, executable), main program file (which can be e.g. a Windows batch (.bat) file or for Python scripts this would be the .py file where the __main__() method is located), All additional required program files, any optional input files (e.g. data), and output files. Also any command line arguments can be defined in a Tool specification. SpineOpt.jl is a Tool specification from Spine Toolbox’s point-of-view.
Use case Potential way to use Spine Toolbox. Use cases together are used to test the functionality and stability of Spine Toolbox and SpineOpt.jl under different potential circumstances.
Vertice Graph theory term. See Project item.
View A project item that can be used for visualizing project data.
Work directory Tool specifications can be executed in Source directory or in work directory. When a Tool specification is executed in a work directory, Spine Toolbox creates a new work directory, copies all required and optional files needed for running the Tool specification to this directory and executes it there. After execution has finished, output or result files can be copied into a timestamped (archive) directory from the work directory.
Dependencies¶
Spine Toolbox requires Python 3.7 or Python 3.8. Python 3.9 is not supported yet.
The dependencies have been split to required packages and development packages. The required packages must be installed for the application to start. The development packages contain tools that are recommended for developers. If you want to deploy the application yourself by using the provided cx_Freeze_setup.py file, you need to install the cx_Freeze package (v6.6 or newer recommended).
At the moment, Spine Toolbox depends on four main packages (spinetoolbox, spine-engine, spine-items, and spinedb-api) developed in Spine project. For version number limitations, please see requirements.txt and setup.py files in spinetoolbox, spine-engine, spine-items, and spinedb-api packages
Dependencies by package¶
spinetoolbox¶
Package name |
License |
---|---|
spinedb-api |
LGPL |
spine_engine |
LGPL |
spine_items* |
LGPL |
pyside2 |
LGPL |
datapackage |
MIT |
jupyter-client |
BSD |
qtconsole |
BSD |
sqlalchemy |
MIT |
numpy |
BSD |
matplotlib |
BSD |
scipy |
BSD |
networkx |
BSD |
cx_Oracle |
BSD |
pandas |
BSD |
pymysql |
MIT |
pyodbc |
MIT |
psycopg2 |
LGPL |
jill |
MIT |
* spine-items is not a ‘hard’ requirement of Spine Toolbox. The app does start without spine-items but the features in that case are quite limited.
spinedb-api¶
Package name |
License |
---|---|
sqlalchemy |
MIT |
alembic |
MIT |
faker |
MIT |
python-dateutil |
PSF |
numpy |
BSD |
openpyxl |
MIT/Expat |
gdx2py |
MIT |
ijson |
BSD |
spine-engine¶
Package name |
License |
---|---|
spinedb-api |
LGPL |
dagster |
Apache-2.0 |
sqlalchemy |
MIT |
numpy |
BSD |
datapackage |
MIT |
spine-items¶
Package name |
License |
---|---|
spinetoolbox |
LGPL |
spinedb-api |
LGPL |
spine-engine |
LGPL |
Development packages¶
Below is a list of development packages in dev-requirements.txt. Sphinx and sphinx_rtd_theme packages are needed for building the user guide. Black is used for code formatting while pylint does linting. Pre-commit hook enables automatic code formatting at git commit.
Package name |
License |
---|---|
black |
MIT |
pre-commit |
MIT |
pyYAML |
GPL |
pylint |
GPL |
sphinx |
BSD |
sphinx_rtd_theme |
MIT |
recommonmark |
MIT |
sphinx-autoapi |
MIT |
Contribution Guide for Spine Toolbox¶
All are welcome to contribute! This guide is based on a set of best practices for open source projects [JF18].
Reporting Bugs¶
Due Diligence¶
Before submitting a bug report, please do the following:
Perform basic troubleshooting steps.
Make sure you’re on the latest version. If you’re not on the most recent version, your problem may have been solved already! Upgrading is always the best first step.
Try older versions. If you’re already on the latest release, try rolling back a few minor versions (e.g. if on 1.7, try 1.5 or 1.6) and see if the problem goes away. This will help the devs narrow down when the problem first arose in the commit log.
Try switching up dependency versions. If you think the problem may be due to a problem with a dependency (other libraries, etc.). Try upgrading/downgrading those as well.
Search the project’s bug/issue tracker to make sure it’s not a known issue. If you don’t find a pre-existing issue, consider checking with the maintainers in case the problem is non-bug-related. Spine Toolbox issue tracker is here.
What to Put in Your Bug Report¶
Make sure your report gets the attention it deserves: bug reports with missing information may be ignored or punted back to you, delaying a fix. The below constitutes a bare minimum; more info is almost always better:
What version of the Python interpreter are you using? E.g. Python 2.7.3, Python 3.6?
What operating system are you on? Windows? (Vista, 7, 8, 8.1, 10). 32-bit or 64-bit? Mac OS X? (e.g. 10.7.4, 10.9.0) Linux (Which distro? Which version of that distro? 32 or 64 bits?) Again, more detail is better.
Which version or versions of the software are you using? If you have forked the project from Git, which branch and which commit? Otherwise, supply the application version number (Help->About menu). Also, ideally you followed the advice above and have ruled out (or verified that the problem exists in) a few different versions.
How can the developers recreate the bug? What were the steps used to invoke it. A screenshot demonstrating the bug is usually the most helpful thing you can report (if applicable) Relevant output from the Event Log or debug messages from the console of your run, should also be included.
Feature Requests¶
The developers of Spine Toolbox are happy to hear new ideas for features or improvements to existing functionality. The format for requesting new features is free. Just fill out the required fields on the issue tracker and give a description of the new feature. A picture accompanying the description is a good way to get your idea into development faster. But before you make a new issue, check that there isn’t a related idea already open in the issue tracker. If you have an idea on how to improve an existing idea, just join the conversation.
Submitting features/bugfixes¶
If you feel like you can fix a bug that’s been bothering you or you want to add a new feature to the application but the devs seem to be too busy with something else, please follow the instructions in the following sections on how to contribute code.
Coding Style¶
Follow the style you see used in the repository! Consistency with the rest of the project always trumps other considerations. It doesn’t matter if you have your own style or if the rest of the code breaks with the greater community - just follow along.
Spine Toolbox coding style follows PEP-8 style guide for Python code with the following variations:
Maximum line length is 120 characters. Longer lines are acceptable for a good reason.
Google style docstrings with the title and input parameters are required for all classes, functions, and methods. For small functions or methods only the summary is necessary. Return types are highly recommended but not required if it is obvious what the function or method returns.
Other deviations from PEP-8 can be discussed.
Commit messages¶
The commit message should tell what was changed and why. Details on how it was done can usually be left out, if the code itself is self-explanatory (remember source comments too!). Separate the subject line from the body with a blank line. The subjet line (max. 50 chars) should explain in condensed form what happened using imperative mood, i.e. using verbs like ‘change’, ‘fix’ or ‘add’. Start the subject line with a capital letter. Do not use the issue number on the subject line, as it does not tell much to a person who’s not aware of that particular issue. For more info see Chris Beams’ ‘Seven rules of of a great Git commit message’ [CB14].
A good example (insipred by [CB14])
Fix bugs when updating parameters in foo and bar
Body of the commit message starts after a blank line. Explain here in more
detail the reasons why you made the change, how things worked before and how they work now.
Also explain why
You can use hyphens to make bulleted lists:
- Foo was added because of bar
- Baz was not used so it was deleted
Add references to issue tracker (if any) at the end.
Solves: #123
See also: #456, #789
Contributing to the User Guide¶
Spine Toolbox uses Sphinx to create HTML pages from restructured text (.rst) files. The .rst files are
plain text files that are formatted in a way that Sphinx understands and is able to turn them into HTML.
Please see this brief introduction for more on reStructured text.
You can modify the existing or create new .rst files into docs/source
directory. When you are done editing, run
bin/build_doc.bat
on Windows or bin/build_doc.sh
on Linux to build the HTML pages to check the result before
making a commit. The created pages are found in docs/build/html
directory. After a commit, the User Guide is built
automatically by readthedocs.org. The latest User Guide is available in
https://spine-toolbox.readthedocs.io/en/latest/.
Contributing to the Spine Toolbox Graphical User Interface¶
If you want to change or add new widgets into the application, you need to use the bin\build_ui.bat
(Windows) or
bin/build_ui.sh
(Linux) scripts. The main design of the widgets should be done with Qt Designer (designer.exe
or designer
) that is included with PySide2. The files produced by Qt Designer are XML files (.ui). You can
also embed graphics (e.g. icons, logos, etc.) into the application by using Qt Designer. When you are done
modifying widgets in the designer, you need to run the build_ui
script for the changes to take effect.
This script uses tools provided in the PySide2 package to turn .ui files into Python files, in essence
rebuilding the whole Spine Toolbox user interface.
Styling the widgets should be done with Qt Style Sheets in code. Please avoid using style sheets in Qt Designer.
Version Control Branching¶
Always make a new branch for your work, no matter how small. This makes it easy for others to take just that one set of changes from your repository, in case you have multiple unrelated changes floating around. A corollary: don’t submit unrelated changes in the same branch/pull request! The maintainer shouldn’t have to reject your awesome bugfix because the feature you put in with it needs more review.
Name your new branch descriptively, e.g. issue#XXX-fixing-a-serious-bug
or issue#ZZZ-cool-new-feature
.
New branches should in general be based on the latest master
branch.
In case you want to include a new feature still in development, you can also start working from its branch.
The developers will backport any relevant bug-fixes to previous or upcoming releases under preparation.
If you need to use code from an upstream branch, please use
git-rebase if you have not shared your work with
others yet. For example: You started working on an issue, but now the upstream branch (master
) has some
new commits you would like to have in your branch too. If you have not yet pushed your branch, you can now
rebase your changes on top of the upstream branch:
$ git pull origin master:master
$ git checkout my_branch
$ git rebase master
Avoid merging the upstream branch to your issue branch if it’s not necessary. This will lead to a more linear and cleaner history.
Finally, make a pull request from your branch so that the developers can review your changes. You might be asked to make additional changes or clarifications or add tests to prove the new feature works as intended.
Test-driven development is your friend¶
Any bug fix that doesn’t include a test proving the existence of the bug being fixed, may be suspect. Ditto for new features that can’t prove they actually work.
It is recommended to use test-first development as it really helps make features better designed and identifies potential edge cases earlier instead of later. Writing tests before the implementation is strongly encouraged.
Full example¶
Here’s an example workflow. Your username is yourname
and you’re submitting a basic bugfix.
Preparing your Fork
Click ‘Fork’ on Github, creating e.g.
yourname/Spine-Toolbox
Clone your project:
git clone git@github.com:yourname/Spine-Toolbox
cd Spine-Toolbox
Create a virtual environment and install requirements
Create a branch:
git checkout -b foo-the-bars master
Making your Changes
Add an entry to CHANGELOG.md crediting yourself.
Write tests expecting the correct/fixed functionality; make sure they fail.
Hack, hack, hack.
Run tests again, making sure they pass.
Commit your changes:
git commit -m "Foo the bars"
Creating Pull Requests
Push your commit to get it back up to your fork:
git push origin HEAD
Visit Github, click handy ‘Pull request‘ button that it will make upon noticing your new branch.
In the description field, write down issue number (if submitting code fixing an existing issue) or describe the issue + your fix (if submitting a wholly new bugfix).
Hit ‘submit’! And please be patient - the maintainers will get to you when they can.
References¶
- CB14(1,2)
Chris Beams. 2014. ‘How to Write a Git Commit Message.’ https://chris.beams.io/posts/git-commit/
- JF18
Jeff Forcier. 2018. ‘Contributing to Open Source Projects.’ https://contribution-guide-org.readthedocs.io/
Developer documentation¶
Here you can find developer specific documentation on Spine Toolbox.
Project item development¶
This document discusses the basics of project item development: what is required make one, how items interact with the Toolbox GUI and how they are executed.
The core of every project item consists of two classes: a static project item class which is responsible for integrating the item with the Toolbox GUI and an executable class which does the item’s ‘thing’ and exists only during execution in Spine Engine. Some additional classes are needed for Toolbox to be able to instantiate project items and to communicate with the user via the Toolbox GUI.
Specifications are a way to make the settings of an item portable across projects. In a sense a specification is a template that can specialize an item for a specific purpose such as a Tool that runs certain model with known inputs an outputs. Items that support specifications need to implement some additional methods and classes.
Getting started¶
Probably the most convenient way to start developing a new project item is to work with a copy of some simple project item. For example, View provides a good starting point.
Project items are mostly self-contained Python packages.
It is customary to structure the project item packages like the Toolbox itself: mvcmodels
submodule for Qt’s
models, ui
module for automatically generated UI forms and widgets
for widgets’ business logic.
However, the only actual requirement is that Toolbox expects to find the item’s factory and item info
classes in the package’s root modules as well as an executable_item
module.
Item info¶
A subclass of spine_engine.project_item.project_item_info.ProjectItemInfo
must be found
in one of the root modules of an item’s package.
It is used by Toolbox to query the type and category of an item.
Type identifies the project item while category is used by the Toolbox GUI to group project items with similar function.
Categories are currently fixed and can be checked from spine_items.category
.
Item Factory¶
The details of constructing a project item and related objects have been abstracted away from Toolbox
by a factory that must be provided by every project item in a root module of the item’s package.
The factory is a subclass of spinetoolbox.project_item.project_item_factory.ProjectItemFactory
.
Note that methods in the factory
that deal with specifications need to be implemented only by items that support them.
Executable item¶
A project item must have a root module called executable_item
that contains a class
named ExecutableItem
which is a subclass of
spine_engine.project_item.executable_item_base.ExecutableItemBase
ExecutableItem
acts as an access point to Spine Engine and contains the item’s execution logic.
Toolbox side project item¶
A project item must subclass spinetoolbox.project_item.project_item.ProjectItem
and return the subclass in its factory’s item_class()
method.
Also make_item()
must return an instance of this class.
This class forms the core of integrating the item with Toolbox.
Specifications¶
Items that support specifications need to subclass
spine_engine.project_item.project_item_specification_factory.ProjectItemSpecificationFactory
which provides an access point to Toolbox and Spine Engine to generate specifications.
The factory must be called SpecificationFactory
and be placed in specification_factory
module under item package’s root.
The specification itself should be a subclass of
spine_engine.project_item.project_item_specification.ProjectItemSpecification
.
Toolbox GUI integration¶
ProjectItemFactory.icon()
returns a URL to the item’s icon resource.
This is the item’s ‘symbol’ shown e.g. on the main toolbar of Toolbox.
It should not be confused with the actual icon on Design view
which in turn is a subclass of spinetoolbox.project_item.project_item_icon.ProjectItemIcon
and is returned by ProjectItemFactory.make_icon()
.
When creating a new item on the Design view Toolbox shows the Add item dialog it gets from
ProjectItemFactory.make_add_item_widget()
.
Toolbox provides spinetoolbox.widgets.add_project_item_widget.AddProjectItemWidget
which is a general purpose widget for this purpose
though project items are free to implement their own widgets as needed.
Once the item is on the Design view, the main interaction with it goes through the properties widget which is created
by ProjectItemFactory.make_properties_widget()
.
The properties widget should have all controls needed to set up the item.
Saving and restoring project items¶
Project items are saved in JSON format as part of the project.json
file.
Item saving is handled by ProjectItem.item_dict()
which should return a JSON compatible dict
and
contain at least the information returned by the base class method.
File system paths are handled specifically during saving: all paths outside the project directory should be absolute
while the paths in the project directory should be relative. This is to enable self-contained projects which include
all needed files and can be easily transferred from system to system. As such, paths are saved as special dictionaries.
spine_engine.utils.serialization.serialize_path()
, spine_engine.utils.serialization.serialize_url()
and
spine_engine.utils.serialization.deserialize_path()
help with dealing with the paths.
ProjectItem.from_dict()
is responsible for restoring a saved project item
from the dictionary. ProjectItem.parse_item_dict()
can help to deserialize
the basic data needed by the base class.
Passing data between items: resources¶
Project items share data by files or via databases. One item writes a file which is then read by another item. Project item resources are used to communicate the URLs of these files and databases.
Resources are instances of the spine.engine.project_item.project_item_resource.ProjectItemResource
class.
Both static items and their executable counterparts pass resources. The major difference is that static item’s may pass resource promises such as files that are generated during the execution. The full path to the promised files or even their final names may not be known until the items are executed.
During execution resources are propagated only to item’s direct predecessors and successors. Static items offer their resources to direct successors only. Resources that are communicated to successor items are basically output files that the successor items can use for input. Currently, the only resource that is propagated to predecessor items is database URLs by Data Store project items. As Data Stores leave the responsibility of writing to the database to other items it has to tell these items where to write their output data.
The table below lists the resources each project item type provides during execution.
Item |
Notes |
Provides to predecessor |
Provides to successor |
---|---|---|---|
Data Connection |
n/a |
File URLs |
|
Data Store |
Database URL |
Database URL |
|
Data Transformer |
n/a |
Database URL |
|
Exporter |
n/a |
File URLs |
|
GdxExporter |
n/a |
File URLs |
|
Gimlet |
n/a |
Resources from predecessor |
|
Importer |
n/a |
n/a |
|
Tool |
n/a |
File URLs |
|
View |
n/a |
n/a |
- 1
Data connection provides paths to local files.
- 2
Data Store provides a database URL to direct successors and predecessors. Note, that this is the only project item that provides resources to it’s predecessors.
- 3
Data Transformer provides its predecessors’ database URLs modified by transformation configuration embedded in the URL.
- 4
Tool’s output files are specified by a Tool specification.
The table below lists the resources that might be used by each item type during execution.
Item |
Notes |
Accepts from predecessor |
Accepts from successor |
---|---|---|---|
Data Connection |
n/a |
n/a |
|
Data Store |
n/a |
n/a |
|
Data Transformer |
Database URL |
n/a |
|
Exporter |
Database URL |
n/a |
|
GdxExporter |
Database URL |
n/a |
|
Gimlet |
File URLs, database URLs |
Database URLs |
|
Importer |
File URLs |
Database URL |
|
Tool |
File URLs, database URLs |
Database URLs |
|
View |
Database URLs |
n/a |
- 5
Gimlet’s resources can be passed to the command as command line arguments but are otherwise ignored.
- 6
Importer requires a database URL from its successor for writing the mapped data. This can be provided by a Data Store.
- 7
Tool specification specifies tool’s optional and required input files. Database URLs can be passed to the tool program via command line arguments but are otherwise ignored by the Tool project item. Currently, there is no mechanism to know if a URL is actually required by a tool program. For more information, see Tool specification editor.
Execution¶
Spine Engine instantiates the executable items in a DAG before the execution starts.
Then, Engine declares forward and backward resources for each item
using ExecutableItemBase.output_resources()
.
During execution, ExecutableItemBase.execute()
is invoked with lists of available resources
if an item is selected for execution.
Otherwise, ExecutableItemBase.exclude_execution()
is called.
API Reference¶
This page contains auto-generated API reference documentation 1.
spinetoolbox
¶
spinetoolbox package.
Subpackages¶
spinetoolbox.mvcmodels
¶
Modules in this package contain classes that represent Spine Toolbox’s models (internal data structures) in the Model-View-Controller design pattern. The model classes define an interface that is used by views and delegates to access data in the application.
- author
Savolainen (VTT)
- date
24.9.2019
Submodules¶
spinetoolbox.mvcmodels.array_model
¶Contains logic for the fixed step time series editor widget.
- author
Soininen (VTT)
- date
14.6.2019
Model for the Array parameter_value type. |
- class spinetoolbox.mvcmodels.array_model.ArrayModel[source]¶
Bases:
PySide2.QtCore.QAbstractTableModel
Model for the Array parameter_value type.
Even if the array is empty this model’s rowCount() will still return 1. This is to show an empty row in the table view.
- batch_set_data(self, indexes, values)[source]¶
Sets data at multiple indexes at once.
- Parameters
indexes (list of QModelIndex) – indexes to set
values (list of str) – values corresponding to the indexes
- _convert_to_data_type(self, indexes, values)[source]¶
Converts values from string to current data type filtering failed conversions.
- Parameters
indexes (list of QModelIndex) – indexes
values (list of str) – values to convert
- Returns
indexes and converted values
- Return type
tuple
- is_expanse_row(self, row)[source]¶
Returns True if row is the expanse row.
- Parameters
row (int) – a row
- Returns
True is row is expanse row, False otherwise
- Return type
bool
- reset(self, value)[source]¶
Resets the model to a new array.
- Parameters
value (Array) – a new array to model
- rowCount(self, parent=QModelIndex())[source]¶
Returns the length of the array.
Note: returns 1 even if the array is empty.
spinetoolbox.mvcmodels.compound_table_model
¶Models that vertically concatenate two or more table models.
- authors
Marin (KTH)
- date
9.10.2019
A model that concatenates several sub table models vertically. |
|
A compound parameter table model where the last model is an empty row model. |
- class spinetoolbox.mvcmodels.compound_table_model.CompoundTableModel(parent=None, header=None)[source]¶
Bases:
spinetoolbox.mvcmodels.minimal_table_model.MinimalTableModel
A model that concatenates several sub table models vertically.
Initializes model.
- Parameters
parent (QObject) – the parent object
- map_to_sub(self, index)[source]¶
Returns an equivalent submodel index.
- Parameters
index (QModelIndex) – the compound model index.
- Returns
the equivalent index in one of the submodels
- Return type
QModelIndex
- map_from_sub(self, sub_model, sub_index)[source]¶
Returns an equivalent compound model index.
- Parameters
sub_model (MinimalTableModel) – the submodel
sub_index (QModelIndex) – the submodel index.
- Returns
the equivalent index in the compound model
- Return type
QModelIndex
- item_at_row(self, row)[source]¶
Returns the item at given row.
- Parameters
row (int) –
- Returns
object
- sub_model_at_row(self, row)[source]¶
Returns the submodel corresponding to the given row in the compound model.
- Parameters
row (int) –
- Returns
MinimalTableModel
- _append_row_map(self, row_map)[source]¶
Appends given row map to the tail of the model.
- Parameters
row_map (list) – tuples (model, row number)
- static _row_map_for_model(model)[source]¶
Returns row map for given model. The base class implementation just returns all model rows.
- Parameters
model (MinimalTableModel) –
- Returns
tuples (model, row number)
- Return type
list
- canFetchMore(self, parent=QModelIndex())[source]¶
Returns True if any of the submodels that haven’t been fetched yet can fetch more.
- fetchMore(self, parent=QModelIndex())[source]¶
Fetches the next sub model and increments the fetched counter.
- data(self, index, role=Qt.DisplayRole)[source]¶
Returns the data stored under the given role for the item referred to by the index.
- Parameters
index (QModelIndex) – Index of item
role (int) – Data role
- Returns
Item data for given role.
- batch_set_data(self, indexes, data)[source]¶
Sets data for indexes in batch. Distributes indexes and values among the different submodels and calls batch_set_data on each of them.
- class spinetoolbox.mvcmodels.compound_table_model.CompoundWithEmptyTableModel(parent=None, header=None)[source]¶
Bases:
CompoundTableModel
A compound parameter table model where the last model is an empty row model.
Initializes model.
- Parameters
parent (QObject) – the parent object
- init_model(self)[source]¶
Initializes the compound model. Basically populates the sub_models list attribute with the result of _create_single_models and _create_empty_model.
- connect_model_signals(self)[source]¶
Connects signals so changes in the submodels are acknowledge by the compound.
- _recompute_empty_row_map(self)[source]¶
Recomputeds the part of the row map corresponding to the empty model.
- _handle_empty_rows_removed(self, parent, empty_first, empty_last)[source]¶
Runs when rows are removed from the empty model. Updates row_map, then emits rowsRemoved so the removed rows are no longer visible.
- _handle_empty_rows_inserted(self, parent, empty_first, empty_last)[source]¶
Runs when rows are inserted to the empty model. Updates row_map, then emits rowsInserted so the new rows become visible.
- _handle_single_model_reset(self, single_model)[source]¶
Runs when one of the single models is reset. Updates row_map, then emits rowsInserted so the new rows become visible.
spinetoolbox.mvcmodels.empty_row_model
¶Contains a table model with an empty last row.
- authors
Marin (KTH)
- date
20.5.2018
A table model with a last empty row. |
- class spinetoolbox.mvcmodels.empty_row_model.EmptyRowModel(parent=None, header=None)[source]¶
Bases:
spinetoolbox.mvcmodels.minimal_table_model.MinimalTableModel
A table model with a last empty row.
Init class.
spinetoolbox.mvcmodels.filter_checkbox_list_model
¶Provides FilterCheckboxListModel for FilterWidget.
- author
Vennström (VTT)
- date
1.11.2018
Init class. |
|
Extends SimpleFilterCheckboxListModel to allow for lazy loading in synch with another model. |
|
Extends SimpleFilterCheckboxListModel to allow for translating internal data to a value for display role. |
- class spinetoolbox.mvcmodels.filter_checkbox_list_model.SimpleFilterCheckboxListModel(parent, show_empty=True)[source]¶
Bases:
PySide2.QtCore.QAbstractListModel
Init class.
- Parameters
parent (QWidget) –
- class spinetoolbox.mvcmodels.filter_checkbox_list_model.LazyFilterCheckboxListModel(parent, source_model, show_empty=True)[source]¶
Bases:
SimpleFilterCheckboxListModel
Extends SimpleFilterCheckboxListModel to allow for lazy loading in synch with another model.
Init class.
- Parameters
parent (SpineDBEditor) –
source_model (CompoundParameterModel) – a model to lazily get data from
- class spinetoolbox.mvcmodels.filter_checkbox_list_model.DataToValueFilterCheckboxListModel(parent, data_to_value, show_empty=True)[source]¶
Bases:
SimpleFilterCheckboxListModel
Extends SimpleFilterCheckboxListModel to allow for translating internal data to a value for display role.
Init class.
- Parameters
parent (SpineDBEditor) –
data_to_value (method) – a method to translate item data to a value for display role
spinetoolbox.mvcmodels.filter_execution_model
¶Contains FilterExecutionModel.
- author
Marin (KTH)
- date
26.11.2020
spinetoolbox.mvcmodels.indexed_value_table_model
¶A model for indexed parameter values, used by the parameter_value editors.
- authors
Soininen (VTT)
- date
18.6.2019
A base class for time pattern and time series models. |
- class spinetoolbox.mvcmodels.indexed_value_table_model.IndexedValueTableModel(value, index_header, value_header)[source]¶
Bases:
PySide2.QtCore.QAbstractTableModel
A base class for time pattern and time series models.
- Parameters
value (TimePattern, TimeSeriesFixedStep, TimeSeriesVariableStep) – a parameter_value
index_header (str) – a header for the index column
value_header (str) – a header for the value column
- headerData(self, section, orientation=Qt.Horizontal, role=Qt.DisplayRole)[source]¶
Returns a header.
spinetoolbox.mvcmodels.map_model
¶A model for maps, used by the parameter_value editors.
- authors
Soininen (VTT)
- date
11.2.2020
A model for Map type parameter values. |
|
Turns table into nested dictionaries. |
|
Constructs a |
|
Counts the number of non-None elements at the beginning of row. |
- class spinetoolbox.mvcmodels.map_model.MapModel(map_value)[source]¶
Bases:
PySide2.QtCore.QAbstractTableModel
A model for Map type parameter values.
This model represents the Map as a 2D table. Each row consists of one or more index columns and a value column. The last columns of a row are padded with Nones.
Example
Map { "A": 1.0 "B": Map {"a": -1.0} "C": 3.0 }
The table corresponding to the above map:
“A”
1.0
None
“B”
“a”
-1.0
“C”
3.0
None
- Parameters
map_value (Map) – a map
- clear(self, indexes)[source]¶
Clears table cells.
- Parameters
indexes (list of QModelIndex) – indexes to clear
- headerData(self, section, orientation, role=Qt.DisplayRole)[source]¶
Returns row numbers for vertical headers and column titles for horizontal ones.
- insertColumns(self, column, count, parent=QModelIndex())[source]¶
Inserts new columns into the map.
- Parameters
column (int) – column index where to insert
count (int) – number of new columns
parent (QModelIndex) – ignored
- Returns
True if insertion was successful, False otherwise
- Return type
bool
- insertRows(self, row, count, parent=QModelIndex())[source]¶
Inserts new rows into the map.
- Parameters
row (int) – an index where to insert the new data
count (int) – number of rows to insert
parent (QModelIndex) – an index to a parent model
- Returns
True if the operation was successful
- Return type
bool
- _is_in_expanse(self, row, column)[source]¶
Returns True, if given row and column is in the right or bottom ‘expanding’ zone
- Parameters
row (int) – row index
column (int) – column index
- Returns
True if the cell is in the expanse, False otherwise
- Return type
bool
- is_expanse_column(self, column)[source]¶
Returns True if given column is the expanse column.
- Parameters
column (int) – column
- Returns
True if column is expanse column, False otherwise
- Return type
bool
- is_expanse_row(self, row)[source]¶
Returns True if given row is the expanse row.
- Parameters
row (int) – row
- Returns
True if row is the expanse row, False otherwise
- Return type
bool
- removeColumns(self, column, count, parent=QModelIndex())[source]¶
Removes columns from the map.
- Parameters
column (int) – first column to remove
count (int) – number of columns to remove
parent (QModelIndex) – an index to a parent model
- Returns
True if the operation was successful
- removeRows(self, row, count, parent=QModelIndex())[source]¶
Removes rows from the map.
- Parameters
row (int) – first row to remove
count (int) – number of rows to remove
parent (QModelIndex) – an index to a parent model
- Returns
True if the operation was successful
- set_box(self, top_left, bottom_right, data)[source]¶
Sets data for several indexes at once.
- Parameters
top_left (QModelIndex) – a sequence of model indexes
bottom_right (QModelIndex) – a sequence of values corresponding to the indexes
data (list of list) – box of data
- spinetoolbox.mvcmodels.map_model._rows_to_dict(rows)[source]¶
Turns table into nested dictionaries.
- Parameters
rows (list) – a list of row data
- Returns
a nested dictionary
- Return type
dict
spinetoolbox.mvcmodels.minimal_table_model
¶Contains a minimal table model.
- authors
Marin (KTH)
- date
20.5.2018
Table model for outlining simple tabular data. |
- class spinetoolbox.mvcmodels.minimal_table_model.MinimalTableModel(parent=None, header=None, lazy=True)[source]¶
Bases:
PySide2.QtCore.QAbstractTableModel
Table model for outlining simple tabular data.
- Parameters
parent (QObject) – the parent object
- insert_horizontal_header_labels(self, section, labels)[source]¶
Insert horizontal header labels at the given section.
- setHeaderData(self, section, orientation, value, role=Qt.EditRole)[source]¶
Sets the data for the given role and section in the header with the specified orientation to the value supplied.
- data(self, index, role=Qt.DisplayRole)[source]¶
Returns the data stored under the given role for the item referred to by the index.
- Parameters
index (QModelIndex) – Index of item
role (int) – Data role
- Returns
Item data for given role.
- row_data(self, row, role=Qt.DisplayRole)[source]¶
Returns the data stored under the given role for the given row.
- Parameters
row (int) – Item row
role (int) – Data role
- Returns
Row data for given role.
- insertRows(self, row, count, parent=QModelIndex())[source]¶
Inserts count rows into the model before the given row. Items in the new row will be children of the item represented by the parent model index.
- Parameters
row (int) – Row number where new rows are inserted
count (int) – Number of inserted rows
parent (QModelIndex) – Parent index
- Returns
True if rows were inserted successfully, False otherwise
- insertColumns(self, column, count, parent=QModelIndex())[source]¶
Inserts count columns into the model before the given column. Items in the new column will be children of the item represented by the parent model index.
- Parameters
column (int) – Column number where new columns are inserted
count (int) – Number of inserted columns
parent (QModelIndex) – Parent index
- Returns
True if columns were inserted successfully, False otherwise
- removeRows(self, row, count, parent=QModelIndex())[source]¶
Removes count rows starting with the given row under parent.
- Parameters
row (int) – Row number where to start removing rows
count (int) – Number of removed rows
parent (QModelIndex) – Parent index
- Returns
True if rows were removed successfully, False otherwise
- removeColumns(self, column, count, parent=QModelIndex())[source]¶
Removes count columns starting with the given column under parent.
- Parameters
column (int) – Column number where to start removing columns
count (int) – Number of removed columns
parent (QModelIndex) – Parent index
- Returns
True if columns were removed successfully, False otherwise
spinetoolbox.mvcmodels.minimal_tree_model
¶Models to represent items in a tree.
- authors
Vennström (VTT), M. Marin (KTH)
- date
11.3.2019
A tree item that can fetch its children. |
|
Base class for all tree models. |
- class spinetoolbox.mvcmodels.minimal_tree_model.TreeItem(model=None)[source]¶
A tree item that can fetch its children.
Initializes item.
- Parameters
model (MinimalTreeModel, NoneType) – The model where the item belongs.
- property child_item_type(self)[source]¶
Returns the type of child items. Reimplement in subclasses to return something more meaningful.
- child_number(self)[source]¶
Returns the rank of this item within its parent or -1 if it’s an orphan.
- find_children(self, cond=lambda child: ...)[source]¶
Returns children that meet condition expressed as a lambda function.
- find_child(self, cond=lambda child: ...)[source]¶
Returns first child that meet condition expressed as a lambda function or None.
- insert_children(self, position, *children)[source]¶
Insert new children at given position. Returns a boolean depending on how it went.
- Parameters
position (int) – insert new items here
children (iter) – insert items from this iterable
- class spinetoolbox.mvcmodels.minimal_tree_model.MinimalTreeModel(parent)[source]¶
Bases:
PySide2.QtCore.QAbstractItemModel
Base class for all tree models.
Init class.
- Parameters
parent (SpineDBEditor) –
- visit_all(self, index=QModelIndex())[source]¶
Iterates all items in the model including and below the given index. Iterative implementation so we don’t need to worry about Python recursion limits.
- index(self, row, column, parent=QModelIndex())[source]¶
Returns the index of the item in the model specified by the given row, column and parent index.
- data(self, index, role=Qt.DisplayRole)[source]¶
Returns the data stored under the given role for the index.
spinetoolbox.mvcmodels.project_item_model
¶Contains a class for storing project items.
- authors
Savolainen (VTT)
- date
23.1.2018
Class to store project tree items and ultimately project items in a tree structure. |
- class spinetoolbox.mvcmodels.project_item_model.ProjectItemModel(root, parent=None)[source]¶
Bases:
PySide2.QtCore.QAbstractItemModel
Class to store project tree items and ultimately project items in a tree structure.
- Parameters
root (RootProjectTreeItem) – Root item for the project item tree
parent (QObject) – parent object
- rowCount(self, parent=QModelIndex())[source]¶
Reimplemented rowCount method.
- Parameters
parent (QModelIndex) – Index of parent item whose children are counted.
- Returns
Number of children of given parent
- Return type
int
- flags(self, index)[source]¶
Returns flags for the item at given index
- Parameters
index (QModelIndex) – Flags of item at this index.
- parent(self, index=QModelIndex())[source]¶
Returns index of the parent of given index.
- Parameters
index (QModelIndex) – Index of item whose parent is returned
- Returns
Index of parent item
- Return type
QModelIndex
- index(self, row, column, parent=QModelIndex())[source]¶
Returns index of item with given row, column, and parent.
- Parameters
row (int) – Item row
column (int) – Item column
parent (QModelIndex) – Parent item index
- Returns
Item index
- Return type
QModelIndex
- data(self, index, role=None)[source]¶
Returns data in the given index according to requested role.
- Parameters
index (QModelIndex) – Index to query
role (int) – Role to return
- Returns
Data depending on role.
- Return type
object
- item(self, index)[source]¶
Returns item at given index.
- Parameters
index (QModelIndex) – Index of item
- Returns
- Item at given index or root project
item if index is not valid
- Return type
RootProjectTreeItem, CategoryProjectTreeItem or LeafProjectTreeItem
- find_category(self, category_name)[source]¶
Returns the index of the given category name.
- Parameters
category_name (str) – Name of category item to find
- Returns
index of a category item or None if it was not found
- Return type
QModelIndex
- find_item(self, name)[source]¶
Returns the QModelIndex of the leaf item with the given name
- Parameters
name (str) – The searched project item (long) name
- Returns
Index of a project item with the given name or None if not found
- Return type
QModelIndex
- get_item(self, name)[source]¶
Returns leaf item with given name or None if it doesn’t exist.
- Parameters
name (str) – Project item name
- Returns
LeafProjectTreeItem, NoneType
- category_of_item(self, name)[source]¶
Returns the category item of the category that contains project item with given name
- Parameters
name (str) – Project item name
- Returns
category item or None if the category was not found
- insert_item(self, item, parent=QModelIndex())[source]¶
Adds a new item to model. Fails if given parent is not a category item nor a leaf item. New item is inserted as the last item of its branch.
- Parameters
item (CategoryProjectTreeItem or LeafProjectTreeItem) – Project item to add to model
parent (QModelIndex) – Parent project item
- Returns
True if successful, False otherwise
- Return type
bool
- remove_item(self, item, parent=QModelIndex())[source]¶
Removes item from project.
- Parameters
item (BaseProjectTreeItem) – Project item to remove
parent (QModelIndex) – Parent of item that is to be removed
- Returns
True if item removed successfully, False if item removing failed
- Return type
bool
- set_leaf_item_name(self, index, name)[source]¶
Changes the name of the leaf item at given index.
- Parameters
index (QModelIndex) – Tree item index
name (str) – New project item name
- items(self, category_name=None)[source]¶
Returns a list of leaf items in model according to category name. If no category name given, returns all leaf items in a list.
- Parameters
category_name (str) – Item category. Data Connections, Data Stores, Importers, Exporters, Tools or Views permitted.
- Returns
obj:’list’ of :obj:’LeafProjectTreeItem’: Depending on category_name argument, returns all items or only items according to category. An empty list is returned if there are no items in the given category or if an unknown category name was given.
- n_items(self)[source]¶
Returns the number of all items in the model excluding category items and root.
- Returns
Number of items
- Return type
int
- item_names(self)[source]¶
Returns all leaf item names in a list.
- Returns
‘list’ of obj:’str’: Item names
- Return type
obj
- items_per_category(self)[source]¶
Returns a dict mapping category indexes to a list of items in that category.
- Returns
dict(QModelIndex,list(LeafProjectTreeItem))
spinetoolbox.mvcmodels.project_item_specification_models
¶Contains a class for storing Tool specifications.
- authors
Savolainen (VTT)
- date
23.1.2018
Class to store specs that are available in a project e.g. GAMS or Julia models. |
|
- class spinetoolbox.mvcmodels.project_item_specification_models.ProjectItemSpecificationModel(icons)[source]¶
Bases:
PySide2.QtCore.QAbstractListModel
Class to store specs that are available in a project e.g. GAMS or Julia models.
- rowCount(self, parent=None)[source]¶
Returns the number of specs in the model.
- Parameters
parent (QModelIndex) – Not used (because this is a list)
- Returns
Number of rows (available specs) in the model
- data(self, index, role=None)[source]¶
Must be reimplemented when subclassing.
- Parameters
index (QModelIndex) – Requested index
role (int) – Data role
- Returns
Data according to requested role
- flags(self, index)[source]¶
Returns enabled flags for the given index.
- Parameters
index (QModelIndex) – Index of spec
- insertRow(self, spec, row=None, parent=QModelIndex())[source]¶
Insert row (specification) into model.
- Parameters
spec (ProjectItemSpecification) – spec added to the model
row (str) – Row to insert spec to
parent (QModelIndex) – Parent of child (not used)
- Returns
Void
- removeRow(self, row, parent=QModelIndex())[source]¶
Remove row (spec) from model.
- Parameters
row (int) – Row to remove the spec from
parent (QModelIndex) – Parent of spec on row (not used)
- Returns
Boolean variable
- update_specification(self, row, spec)[source]¶
Updates specification.
- Parameters
row (int) – Position of the spec to be updated
spec (ProjectItemSpecification) – new spec, to replace the old one
- Returns
Boolean value depending on the result of the operation
- specification(self, row)[source]¶
Returns spec specification on given row.
- Parameters
row (int) – Row of spec specification
- Returns
ProjectItemSpecification from specification list or None if given row is zero
- find_specification(self, name)[source]¶
Returns specification with the given name.
- Parameters
name (str) – Name of specification to find
spinetoolbox.mvcmodels.resource_filter_model
¶Contains ResourceFilterModel.
- author
Marin (KTH)
- date
26.11.2020
|
- class spinetoolbox.mvcmodels.resource_filter_model.ResourceFilterModel(connection, undo_stack, logger)[source]¶
Bases:
PySide2.QtGui.QStandardItemModel
- Parameters
connection (Connection) – link whose resources to model
undo_stack (QUndoStack) – an undo stack
logger (LoggerInterface) – a logger
- _change_filter_checked_state(self, index, is_on)[source]¶
Changes the online status of the filter item at index.
- Parameters
index (QModelIndex) – item’s index
is_on (bool) – True if filter are turned online, False otherwise
- set_online(self, resource, filter_type, online)[source]¶
Sets the given filters online or offline.
- Parameters
resource (str) – Resource label
filter_type (str) – Either SCENARIO_FILTER_TYPE or TOOL_FILTER_TYPE, for now.
online (dict) – mapping from scenario/tool id to online flag
- _find_filter_type_item(self, resource, filter_type)[source]¶
Searches for filter type item.
- Parameters
resource (str) – resource label
filter_type (str) – filter type identifier
- Returns
filter type item or None if not found
- Return type
QStandardItem
- _set_all_selected_item(self, resource, filter_type_item, emit_data_changed=False)[source]¶
Updates ‘Select All’ item’s checked state.
- Parameters
resource (str) – resource label
filter_type_item (QStandardItem) – filter type item
emit_data_changed (bool) – if True, emit dataChanged signal if the state was updated
spinetoolbox.mvcmodels.time_pattern_model
¶A model for time patterns, used by the parameter_value editors.
- authors
Soininen (VTT)
- date
4.7.2019
A model for time pattern type parameter values. |
- class spinetoolbox.mvcmodels.time_pattern_model.TimePatternModel(value)[source]¶
Bases:
spinetoolbox.mvcmodels.indexed_value_table_model.IndexedValueTableModel
A model for time pattern type parameter values.
- Parameters
value (TimePattern) – a time pattern value
- insertRows(self, row, count, parent=QModelIndex())[source]¶
Inserts new time period - value pairs into the pattern.
New time periods are initialized to empty strings and the corresponding values to zeros.
- Parameters
row (int) – an index where to insert the new data
count (int) – number of time period - value pairs to insert
parent (QModelIndex) – an index to a parent model
- Returns
True if the operation was successful
- Return type
bool
- removeRows(self, row, count, parent=QModelIndex())[source]¶
Removes time period - value pairs from the pattern.
- Parameters
row (int) – an index where to remove the data
count (int) – number of time period - value pairs to remove
parent (QModelIndex) – an index to a parent model
- Returns
True if the operation was successful
- Return type
bool
- setData(self, index, value, role=Qt.EditRole)[source]¶
Sets a time period or a value in the pattern.
Column index 0 corresponds to the time periods while 1 corresponds to the values.
- Parameters
index (QModelIndex) – an index to the model
value (str, float) – a new time period or value
role (int) – a role
- Returns
True if the operation was successful
- Return type
bool
spinetoolbox.mvcmodels.time_series_model_fixed_resolution
¶A model for fixed resolution time series, used by the parameter_value editors.
- authors
Soininen (VTT)
- date
4.7.2019
A model for fixed resolution time series type parameter values. |
- class spinetoolbox.mvcmodels.time_series_model_fixed_resolution.TimeSeriesModelFixedResolution(series)[source]¶
Bases:
spinetoolbox.mvcmodels.indexed_value_table_model.IndexedValueTableModel
A model for fixed resolution time series type parameter values.
- series¶
a time series
- Type
TimeSeriesFixedResolution
A base class for time pattern and time series models.
- Parameters
value (TimePattern, TimeSeriesFixedStep, TimeSeriesVariableStep) – a parameter_value
index_header (str) – a header for the index column
value_header (str) – a header for the value column
- insertRows(self, row, count, parent=QModelIndex())[source]¶
Inserts new values to the series.
The new values are set to zero. Start time or resolution are left unchanged.
- Parameters
row (int) – a numeric index to the first stamp/value to insert
count (int) – number of stamps/values to insert
parent (QModelIndex) – index to a parent model
- Returns
True if the operation was successful
- removeRows(self, row, count, parent=QModelIndex())[source]¶
Removes values from the series.
- Parameters
row (int) – a numeric index to the series where to begin removing
count (int) – how many stamps/values to remove
parent (QModelIndex) – an index to the parent model
- Returns
True if the operation was successful.
- setData(self, index, value, role=Qt.EditRole)[source]¶
Sets a given value in the series.
Column index 1 refers to values. Note it does not make sense to set the time stamps in fixed resolution series.
- Parameters
index (QModelIndex) – an index to the model
value (numpy.datetime64, float) – a new stamp or value
role (int) – a role
- Returns
True if the operation was successful
spinetoolbox.mvcmodels.time_series_model_variable_resolution
¶A model for variable resolution time series, used by the parameter_value editors.
- authors
Soininen (VTT)
- date
5.7.2019
A model for variable resolution time series type parameter values. |
- class spinetoolbox.mvcmodels.time_series_model_variable_resolution.TimeSeriesModelVariableResolution(series)[source]¶
Bases:
spinetoolbox.mvcmodels.indexed_value_table_model.IndexedValueTableModel
A model for variable resolution time series type parameter values.
- series¶
a time series
- Type
TimeSeriesVariableResolution
A base class for time pattern and time series models.
- Parameters
value (TimePattern, TimeSeriesFixedStep, TimeSeriesVariableStep) – a parameter_value
index_header (str) – a header for the index column
value_header (str) – a header for the value column
- insertRows(self, row, count, parent=QModelIndex())[source]¶
Inserts new time stamps and values to the series.
When inserting in the middle of the series the new time stamps are distributed evenly among the time span between the two time stamps around the insertion point. When inserting at the beginning or at the end of the series the duration between the new time stamps is set equal to the first/last duration in the original series.
The new values are set to zero.
- Parameters
row (int) – a numeric index to the first stamp/value to insert
count (int) – number of stamps/values to insert
parent (QModelIndex) – index to a parent model
- Returns
True if the insertion was successful
- removeRows(self, row, count, parent=QModelIndex())[source]¶
Removes time stamps/values from the series.
- Parameters
row (int) – a numeric index to the series where to begin removing
count (int) – how many stamps/values to remove
parent (QModelIndex) – an index to the parent model
- Returns
True if the operation was successful.
- setData(self, index, value, role=Qt.EditRole)[source]¶
Sets a given time stamp or value in the series.
Column index 0 refers to time stamps while index 1 to values.
- Parameters
index (QModelIndex) – an index to the model
value (numpy.datetime64, float) – a new stamp or value
role (int) – a role
- Returns
True if the operation was successful
spinetoolbox.project_item
¶
This subpackage contains base classes for project items.
- authors
Marin (KTH)
- date
8.10.2020
Submodules¶
spinetoolbox.project_item.project_item
¶Contains base classes for project items and item factories.
- authors
Savolainen (VTT)
- date
4.10.2018
Class for project items that are not category nor root. |
- class spinetoolbox.project_item.project_item.ProjectItem(name, description, x, y, project)[source]¶
Bases:
spinetoolbox.metaobject.MetaObject
Class for project items that are not category nor root. These items can be executed, refreshed, and so on.
- x¶
horizontal position in the screen
- Type
float
- y¶
vertical position in the screen
- Type
float
- Parameters
name (str) – item name
description (str) – item description
x (float) – horizontal position on the scene
y (float) – vertical position on the scene
project (SpineToolboxProject) – project item’s project
- abstract static item_type()[source]¶
Item’s type identifier string.
- Returns
type string
- Return type
str
- make_signal_handler_dict(self)[source]¶
Returns a dictionary of all shared signals and their handlers. This is to enable simpler connecting and disconnecting. Must be implemented in subclasses.
- restore_selections(self)[source]¶
Restore selections into shared widgets when this project item is selected.
- save_selections(self)[source]¶
Save selections in shared widgets for this project item into instance variables.
- set_properties_ui(self, properties_ui)[source]¶
Sets the properties tab widget for the item.
Note that this method expects the widget that is generated from the .ui files and initialized with the setupUi() method rather than the entire properties tab widget.
- Parameters
properties_ui (QWidget) – item’s properties UI
- set_specification(self, specification)[source]¶
Pushes a new SetItemSpecificationCommand to the toolbox’ undo stack.
- do_set_specification(self, specification)[source]¶
Sets specification for this item. Removes specification if None given as argument.
- Parameters
specification (ProjectItemSpecification) – specification of this item. None removes the specification.
- set_icon(self, icon)[source]¶
Sets the icon for the item.
- Parameters
icon (ProjectItemIcon) – item’s icon
- _check_notifications(self)[source]¶
Checks if exclamation icon notifications need to be set or cleared.
- handle_execution_successful(self, execution_direction, engine_state)[source]¶
Performs item dependent actions after the execution item has finished successfully.
- Parameters
execution_direction (str) – “FORWARD” or “BACKWARD”
engine_state – engine state after item’s execution
- resources_for_direct_successors(self)[source]¶
Returns resources for direct successors.
These resources can include transient files that don’t exist yet, or filename patterns. The default implementation returns an empty list.
- Returns
a list of ProjectItemResources
- Return type
list
- resources_for_direct_predecessors(self)[source]¶
Returns resources for direct predecessors.
These resources can include transient files that don’t exist yet, or filename patterns. The default implementation returns an empty list.
- Returns
a list of ProjectItemResources
- Return type
list
- _resources_to_predecessors_changed(self)[source]¶
Notifies direct predecessors that item’s resources have changed.
- _resource_to_predecessors_replaced(self, old, new)[source]¶
Notifies direct predecessors that one of item’s resources has been replaced.
- Parameters
old (ProjectItemResource) – old resource
new (ProjectItemResource) – new resource
- upstream_resources_updated(self, resources)[source]¶
Notifies item that resources from direct predecessors have changed.
- Parameters
resources (list of ProjectItemResource) – new resources from upstream
- replace_resource_from_upstream(self, old, new)[source]¶
Replaces an existing resource from direct predecessor by a new one.
- Parameters
old (ProjectItemResource) – old resource
new (ProjectItemResource) – new resource
- _resources_to_successors_changed(self)[source]¶
Notifies direct successors that item’s resources have changed.
- _resource_to_successors_replaced(self, old, new)[source]¶
Notifies direct successors that one of item’s resources has been replaced.
- Parameters
old (ProjectItemResource) – old resource
new (ProjectItemResource) – new resource
- downstream_resources_updated(self, resources)[source]¶
Notifies item that resources from direct successors have changed.
- Parameters
resources (list of ProjectItemResource) – new resources from downstream
- replace_resource_from_downstream(self, old, new)[source]¶
Replaces an existing resource from direct successor by a new one.
- Parameters
old (ProjectItemResource) – old resource
new (ProjectItemResource) – new resource
- invalidate_workflow(self, edges)[source]¶
Notifies that this item’s workflow is not acyclic.
- Parameters
edges (list) – A list of edges that make the graph acyclic after removing them.
- static parse_item_dict(item_dict)[source]¶
Reads the information needed to construct the base ProjectItem class from an item dict.
- Parameters
item_dict (dict) – an item dict
- Returns
item’s name, description as well as x and y coordinates
- Return type
tuple
- copy_local_data(self, original_data_dir, original_url, duplicate_items)[source]¶
Copies local data linked to a duplicated project item.
- Parameters
original_data_dir (str) – original dir of duplicated ProjectItem
original_url (dict) – original url of the duplicated ProjectItem
duplicate_items (bool) – Flag indicating if linked files should be copied
- abstract static from_dict(name, item_dict, toolbox, project)[source]¶
Deserialized an item from item dict.
- Parameters
name (str) – item’s name
item_dict (dict) – serialized item
toolbox (ToolboxUI) – the main window
project (SpineToolboxProject) – a project
- Returns
deserialized item
- Return type
- rename(self, new_name, rename_data_dir_message)[source]¶
Renames this item.
If the project item needs any additional steps in renaming, override this method in subclass. See e.g. rename() method in DataStore class.
- Parameters
new_name (str) – New name
rename_data_dir_message (str) – Message to show when renaming item’s data directory
- Returns
True if item was renamed successfully, False otherwise
- Return type
bool
- tear_down(self)[source]¶
Tears down this item. Called both before closing the app and when removing the item from the project. Implement in subclasses to eg close all QMainWindows opened by this item.
- set_up(self)[source]¶
Sets up this item. Called when adding the item to the project. Implement in subclasses to eg recreate attributes destroyed by tear_down.
- abstract update_name_label(self)[source]¶
Updates the name label on the properties widget when renaming an item.
Must be reimplemented by subclasses.
- notify_destination(self, source_item)[source]¶
Informs an item that it has become the destination of a connection between two items.
The default implementation logs a warning message. Subclasses should reimplement this if they need more specific behavior.
- Parameters
source_item (ProjectItem) – connection source item
- _create_filter_log_document(self, filter_id)[source]¶
Creates log document for a filter execution if none yet, and returns it
- Parameters
filter_id (str) – filter identifier
- Returns
SignedTextDocument
- _create_log_document(self)[source]¶
Creates log document if none yet, and returns it
- Parameters
filter_id (str) – filter identifier
- Returns
SignedTextDocument
- add_log_message(self, filter_id, message)[source]¶
Adds a message to the log document.
- Parameters
filter_id (str) – filter identifier
message (str) – formatted message
- add_event_message(self, filter_id, msg_type, msg_text)[source]¶
Adds a message to the log document.
- Parameters
filter_id (str) – filter identifier
msg_type (str) – message type
msg_text (str) – message text
- add_process_message(self, filter_id, msg_type, msg_text)[source]¶
Adds a message to the log document.
- Parameters
filter_id (str) – filter identifier
msg_type (str) – message type
msg_text (str) – message text
- static upgrade_v1_to_v2(item_name, item_dict)[source]¶
Upgrades item’s dictionary from v1 to v2.
Subclasses should reimplement this method if there are changes between version 1 and version 2.
- Parameters
item_name (str) – item’s name
item_dict (dict) – Version 1 item dictionary
- Returns
Version 2 item dictionary
- Return type
dict
- static upgrade_v2_to_v3(item_name, item_dict, project_upgrader)[source]¶
Upgrades item’s dictionary from v2 to v3.
Subclasses should reimplement this method if there are changes between version 2 and version 3.
- Parameters
item_name (str) – item’s name
item_dict (dict) – Version 2 item dictionary
project_upgrader (ProjectUpgrader) – Project upgrader class instance
- Returns
Version 3 item dictionary
- Return type
dict
spinetoolbox.project_item.project_item_factory
¶Contains base classes for project items and item factories.
- authors
Savolainen (VTT)
- date
4.10.2018
Class for project item factories. |
- class spinetoolbox.project_item.project_item_factory.ProjectItemFactory[source]¶
Class for project item factories.
- abstract static item_class()[source]¶
Returns the project item’s class.
- Returns
item’s class
- Return type
type
- abstract static icon_color()[source]¶
Returns the icon color.
- Returns
icon’s color
- Return type
QColor
- abstract static make_add_item_widget(toolbox, x, y, specification)[source]¶
Returns an appropriate Add project item widget.
- Parameters
toolbox (ToolboxUI) – the main window
x (int) – Icon coordinates
y (int) – Icon coordinates
specification (ProjectItemSpecification) – item’s specification
- Returns
QWidget
- abstract static make_icon(toolbox)[source]¶
Returns a ProjectItemIcon to use with given toolbox, for given project item.
- Parameters
toolbox (ToolboxUI) –
- Returns
item’s icon
- Return type
- abstract static make_item(name, item_dict, toolbox, project)[source]¶
Returns a project item constructed from the given
item_dict
.- Parameters
name (str) – item’s name
item_dict (dict) – serialized project item
toolbox (ToolboxUI) – Toolbox main window
project (SpineToolboxProject) – the project the item belongs to
- Returns
ProjectItem
- abstract static make_properties_widget(toolbox)[source]¶
Creates the item’s properties tab widget.
- Returns
item’s properties tab widget
- Return type
QWidget
Creates item specification’s context menu.
Subclasses that do not support specifications can still raise
NotImplementedError
.- Parameters
parent (QWidget) – menu’s parent widget
index (QModelIndex) – an index from specification model
- Returns
specification’s context menu
- Return type
- abstract static make_specification_editor(toolbox, specification=None, item=None, **kwargs)[source]¶
Creates the item’s specification widget.
Subclasses that do not support specifications can still raise
NotImplementedError
.- Parameters
toolbox (ToolboxUI) – Toolbox main window
specification (ProjectItemSpecification, optional) – a specification to show in the widget or None for a fresh start
item (ProjectItem, optional) – a project item. If the specification is accepted, it is also set for this item
**kwargs – parameters passed to the specification widget
- Returns
item’s specification widget
- Return type
QWidget
- static repair_specification(toolbox, specification)[source]¶
Called right after a spec is added to the project. Finds if there’s something wrong with the spec and proposes actions to fix it with help from toolbox.
- Parameters
toolbox (ToolboxUI) – Toolbox main window
specification (ProjectItemSpecification) – a specification to check
spinetoolbox.project_item.specification_editor_window
¶Contains SpecificationEditorWindowBase and ChangeSpecPropertyCommand
- author
Marin (KTH), P. Savolainen (VTT)
- date
12.4.2018
Command to set specification properties. |
|
Base class for spec editors. |
|
A QToolBar to let users set name and description for an Spec. |
|
Prompts to save changes. |
|
Restores UI state from previous session. |
|
Saves UI state for next session. |
- class spinetoolbox.project_item.specification_editor_window.ChangeSpecPropertyCommand(callback, new_value, old_value, cmd_name)[source]¶
Bases:
PySide2.QtWidgets.QUndoCommand
Command to set specification properties.
- Parameters
callback (function) – Function to call to set the spec property.
new_value (any) – new value
old_value (any) – old value
cmd_name (str) – command name
- class spinetoolbox.project_item.specification_editor_window.SpecificationEditorWindowBase(toolbox, specification=None, item=None)[source]¶
Bases:
PySide2.QtWidgets.QMainWindow
Base class for spec editors.
- Parameters
toolbox (ToolboxUI) – QMainWindow instance
specification (ProjectItemSpecification, optional) – If given, the form is pre-filled with this specification
item (ProjectItem, optional) – Sets the spec for this item if accepted
- _restore_dock_widgets(self)[source]¶
Restores dockWidgets to some default state. Called in the constructor, before restoring the ui from settings. Reimplement in subclasses if needed.
- abstract _make_new_specification(self, spec_name)[source]¶
Returns a ProjectItemSpecification from current form settings.
- Parameters
spec_name (str) – Name of the spec
- Returns
ProjectItemSpecification
- class spinetoolbox.project_item.specification_editor_window._SpecNameDescriptionToolbar(parent, spec, undo_stack)[source]¶
Bases:
PySide2.QtWidgets.QToolBar
A QToolBar to let users set name and description for an Spec.
- Parameters
parent (QMainWindow) – QMainWindow instance
spec (ProjectItemSpecification) – specification that is being edited
undo_stack (QUndoStack) – an undo stack
- spinetoolbox.project_item.specification_editor_window.prompt_to_save_changes(parent, settings, save_callback)[source]¶
Prompts to save changes.
- Parameters
parent (QWidget) – Spec editor widget
settings (QSettings) – Toolbox settings
save_callback (Callable) – A function to call if the user chooses Save. It must return True or False depending on the outcome of the ‘saving’.
- Returns
False if the user chooses to cancel, in which case we don’t close the form.
- Return type
bool
spinetoolbox.spine_db_editor
¶
This subpackage contains GUI files for the Spine db editor.
- authors
Marin (KTH)
- date
13.5.2020
Subpackages¶
spinetoolbox.spine_db_editor.mvcmodels
¶Modules in this package contain classes that represent Spine Toolbox’s models (internal data structures) in the Model-View-Controller design pattern. The model classes define an interface that is used by views and delegates to access data in the application.
- author
Marin (KTH)
- date
23.5.2020
spinetoolbox.spine_db_editor.mvcmodels.alternative_scenario_item
¶Classes to represent alternative and scenario items in a tree.
- authors
Vennström (VTT)
- date
17.6.2020
An alternative root item. |
|
A scenario root item. |
|
An alternative leaf item. |
|
A scenario leaf item. |
|
A tree item that fetches their children as they are inserted. |
|
A scenario alternative root item. |
|
A scenario alternative leaf item. |
- class spinetoolbox.spine_db_editor.mvcmodels.alternative_scenario_item.AlternativeRootItem(model=None)[source]¶
Bases:
spinetoolbox.spine_db_editor.mvcmodels.tree_item_utility.EmptyChildRootItem
An alternative root item.
Initializes item.
- Parameters
model (MinimalTreeModel, NoneType) – The model where the item belongs.
- class spinetoolbox.spine_db_editor.mvcmodels.alternative_scenario_item.ScenarioRootItem(model=None)[source]¶
Bases:
spinetoolbox.spine_db_editor.mvcmodels.tree_item_utility.EmptyChildRootItem
A scenario root item.
Initializes item.
- Parameters
model (MinimalTreeModel, NoneType) – The model where the item belongs.
- class spinetoolbox.spine_db_editor.mvcmodels.alternative_scenario_item.AlternativeLeafItem(identifier=None)[source]¶
Bases:
spinetoolbox.spine_db_editor.mvcmodels.tree_item_utility.LastGrayMixin
,spinetoolbox.spine_db_editor.mvcmodels.tree_item_utility.EditableMixin
,spinetoolbox.spine_db_editor.mvcmodels.tree_item_utility.LeafItem
An alternative leaf item.
Initializes item.
- Parameters
model (MinimalTreeModel, NoneType) – The model where the item belongs.
- class spinetoolbox.spine_db_editor.mvcmodels.alternative_scenario_item.ScenarioLeafItem(identifier=None)[source]¶
Bases:
spinetoolbox.spine_db_editor.mvcmodels.tree_item_utility.LastGrayMixin
,spinetoolbox.spine_db_editor.mvcmodels.tree_item_utility.EditableMixin
,spinetoolbox.spine_db_editor.mvcmodels.tree_item_utility.LeafItem
A scenario leaf item.
Initializes item.
- Parameters
model (MinimalTreeModel, NoneType) – The model where the item belongs.
- class spinetoolbox.spine_db_editor.mvcmodels.alternative_scenario_item.ScenarioActiveItem(model=None)[source]¶
Bases:
spinetoolbox.spine_db_editor.mvcmodels.tree_item_utility.NonLazyTreeItem
A tree item that fetches their children as they are inserted.
Initializes item.
- Parameters
model (MinimalTreeModel, NoneType) – The model where the item belongs.
- class spinetoolbox.spine_db_editor.mvcmodels.alternative_scenario_item.ScenarioAlternativeRootItem(model=None)[source]¶
Bases:
spinetoolbox.spine_db_editor.mvcmodels.tree_item_utility.RootItem
A scenario alternative root item.
Initializes item.
- Parameters
model (MinimalTreeModel, NoneType) – The model where the item belongs.
- class spinetoolbox.spine_db_editor.mvcmodels.alternative_scenario_item.ScenarioAlternativeLeafItem(identifier=None)[source]¶
Bases:
spinetoolbox.spine_db_editor.mvcmodels.tree_item_utility.LeafItem
A scenario alternative leaf item.
Initializes item.
- Parameters
model (MinimalTreeModel, NoneType) – The model where the item belongs.
spinetoolbox.spine_db_editor.mvcmodels.alternative_scenario_model
¶Models to represent alternatives, scenarios and scenario alternatives in a tree.
- authors
Vennström (VTT), M. Marin (KTH)
- date
17.6.2020
A model to display alternatives and scenarios in a tree view. |
- class spinetoolbox.spine_db_editor.mvcmodels.alternative_scenario_model.AlternativeScenarioModel(parent, db_mngr, *db_maps)[source]¶
Bases:
spinetoolbox.spine_db_editor.mvcmodels.tree_model_base.TreeModelBase
A model to display alternatives and scenarios in a tree view.
- Parameters
parent (SpineDBEditor) –
db_mngr (SpineDBManager) –
db_maps (iter) – DiffDatabaseMapping instances
Initialize class
spinetoolbox.spine_db_editor.mvcmodels.compound_parameter_models
¶Compound models for object parameter definitions and values. These models concatenate several ‘single’ models and one ‘empty’ model.
- authors
Marin (KTH)
- date
28.6.2019
A model that concatenates several single parameter models |
|
Implements the interface for populating and filtering a compound object parameter model. |
|
Implements the interface for populating and filtering a compound relationship parameter model. |
|
Handles signals from db mngr for parameter_definition models. |
|
Handles signals from db mngr for parameter_value models. |
|
A model that concatenates several single object parameter_definition models |
|
A model that concatenates several single relationship parameter_definition models |
|
A model that concatenates several single object parameter_value models |
|
A model that concatenates several single relationship parameter_value models |
- class spinetoolbox.spine_db_editor.mvcmodels.compound_parameter_models.CompoundParameterModel(parent, db_mngr, *db_maps)[source]¶
Bases:
spinetoolbox.mvcmodels.compound_table_model.CompoundWithEmptyTableModel
A model that concatenates several single parameter models and one empty parameter model.
Initializes model.
- Parameters
parent (SpineDBEditor) – the parent object
db_mngr (SpineDBManager) – the database manager
*db_maps (DiffDatabaseMapping) – the database maps included in the model
- data_for_single_model_received[source]¶
Emitted by the fetcher when there’s data for another single model.
- property entity_class_type(self)[source]¶
Returns the entity_class type, either ‘object_class’ or ‘relationship_class’.
- Returns
str
- property item_type(self)[source]¶
Returns the parameter item type, either ‘parameter_definition’ or ‘parameter_value’.
- Returns
str
- property _single_model_type(self)[source]¶
Returns a constructor for the single models.
- Returns
SingleParameterModel
- property _empty_model_type(self)[source]¶
Returns a constructor for the empty model.
- Returns
EmptyParameterModel
- property entity_class_id_key(self)[source]¶
Returns the key corresponding to the entity_class id (either “object_class_id” or “relationship_class_id”)
- Returns
str
Makes auto filter menus.
Returns auto filter menu for given logical index from header view.
- Parameters
logical_index (int) –
- Returns
ParameterViewFilterMenu
Modifies data in filter menus.
- Parameters
action (str) – either ‘add’, ‘remove’, or ‘update’
db_map (DiffDatabaseMapping) –
db_items (list(dict)) –
- headerData(self, section, orientation=Qt.Horizontal, role=Qt.DisplayRole)[source]¶
Returns an italic font in case the given column has an autofilter installed.
- _create_single_models(self)[source]¶
Returns a list of single models for this compound model, one for each entity_class in each database.
- Returns
list
- _create_empty_model(self)[source]¶
Returns the empty model for this compound model.
- Returns
EmptyParameterModel
- filter_accepts_model(self, model)[source]¶
Returns a boolean indicating whether or not the given model passes the filter for compound model.
- Parameters
model (SingleParameterModel, EmptyParameterModel) –
- Returns
bool
- accepted_single_models(self)[source]¶
Returns a list of accepted single models by calling filter_accepts_model on each of them, just for convenience.
- Returns
list
- set_auto_filter(self, field, auto_filter)[source]¶
Updates and applies the auto filter.
- Parameters
field (str) – the field name
auto_filter (dict) – mapping db_map to entity_class id to accepted values for the field
- set_compound_auto_filter(self, field, auto_filter)[source]¶
Sets the auto filter for given column in the compound model.
- Parameters
field (str) – the field name
auto_filter (dict) – maps tuple (database map, entity_class id) to list of accepted ids for the field
- set_single_auto_filter(self, model, field)[source]¶
Sets the auto filter for given column in the given single model.
- Parameters
model (SingleParameterModel) – the model
field (str) – the field name
- Returns
True if the auto-filtered values were updated, None otherwise
- Return type
bool
- _row_map_for_model(self, model)[source]¶
Returns the row map for the given model. Reimplemented to take filter status into account.
- Parameters
model (SingleParameterModel, EmptyParameterModel) –
- Returns
tuples (model, row number) for each accepted row
- Return type
list
- _models_with_db_map(self, db_map)[source]¶
Returns a collection of single models with given db_map.
- Parameters
db_map (DiffDatabaseMapping) –
- Returns
list
- receive_entity_classes_removed(self, db_map_data)[source]¶
Runs when entity classes are removed from the dbs. Removes sub-models for the given entity classes and dbs.
- Parameters
db_map_data (dict) – list of removed dict-items keyed by DiffDatabaseMapping
- _items_per_class(self, items)[source]¶
Returns a dict mapping entity_class ids to a set of items.
- Parameters
items (list) –
- Returns
dict
- receive_parameter_data_added(self, db_map_data)[source]¶
Runs when either parameter definitions or values are added to the dbs. Adds necessary sub-models and initializes them with data. Also notifies the empty model so it can remove rows that are already in.
- Parameters
db_map_data (dict) – list of added dict-items keyed by DiffDatabaseMapping
- receive_parameter_data_updated(self, db_map_data)[source]¶
Runs when either parameter definitions or values are updated in the dbs. Emits dataChanged so the parameter_name column is refreshed.
- Parameters
db_map_data (dict) – list of updated dict-items keyed by DiffDatabaseMapping
- receive_parameter_data_removed(self, db_map_data)[source]¶
Runs when either parameter definitions or values are removed from the dbs. Removes the affected rows from the corresponding single models.
- Parameters
db_map_data (dict) – list of removed dict-items keyed by DiffDatabaseMapping
- _emit_data_changed_for_column(self, field)[source]¶
Lazily emits data changed for an entire column.
- Parameters
field (str) – the column header
- class spinetoolbox.spine_db_editor.mvcmodels.compound_parameter_models.CompoundObjectParameterMixin[source]¶
Implements the interface for populating and filtering a compound object parameter model.
- class spinetoolbox.spine_db_editor.mvcmodels.compound_parameter_models.CompoundRelationshipParameterMixin[source]¶
Implements the interface for populating and filtering a compound relationship parameter model.
- class spinetoolbox.spine_db_editor.mvcmodels.compound_parameter_models.CompoundParameterDefinitionMixin[source]¶
Handles signals from db mngr for parameter_definition models.
- class spinetoolbox.spine_db_editor.mvcmodels.compound_parameter_models.CompoundParameterValueMixin[source]¶
Handles signals from db mngr for parameter_value models.
- class spinetoolbox.spine_db_editor.mvcmodels.compound_parameter_models.CompoundObjectParameterDefinitionModel(parent, db_mngr, *db_maps)[source]¶
Bases:
CompoundObjectParameterMixin
,CompoundParameterDefinitionMixin
,CompoundParameterModel
A model that concatenates several single object parameter_definition models and one empty object parameter_definition model.
Initializes model.
- Parameters
parent (SpineDBEditor) – the parent object
db_mngr (SpineDBManager) – the database manager
*db_maps (DiffDatabaseMapping) – the database maps included in the model
- class spinetoolbox.spine_db_editor.mvcmodels.compound_parameter_models.CompoundRelationshipParameterDefinitionModel(parent, db_mngr, *db_maps)[source]¶
Bases:
CompoundRelationshipParameterMixin
,CompoundParameterDefinitionMixin
,CompoundParameterModel
A model that concatenates several single relationship parameter_definition models and one empty relationship parameter_definition model.
Initializes model.
- Parameters
parent (SpineDBEditor) – the parent object
db_mngr (SpineDBManager) – the database manager
*db_maps (DiffDatabaseMapping) – the database maps included in the model
- class spinetoolbox.spine_db_editor.mvcmodels.compound_parameter_models.CompoundObjectParameterValueModel(parent, db_mngr, *db_maps)[source]¶
Bases:
CompoundObjectParameterMixin
,CompoundParameterValueMixin
,CompoundParameterModel
A model that concatenates several single object parameter_value models and one empty object parameter_value model.
Initializes model.
- Parameters
parent (SpineDBEditor) – the parent object
db_mngr (SpineDBManager) – the database manager
*db_maps (DiffDatabaseMapping) – the database maps included in the model
- class spinetoolbox.spine_db_editor.mvcmodels.compound_parameter_models.CompoundRelationshipParameterValueModel(parent, db_mngr, *db_maps)[source]¶
Bases:
CompoundRelationshipParameterMixin
,CompoundParameterValueMixin
,CompoundParameterModel
A model that concatenates several single relationship parameter_value models and one empty relationship parameter_value model.
Initializes model.
- Parameters
parent (SpineDBEditor) – the parent object
db_mngr (SpineDBManager) – the database manager
*db_maps (DiffDatabaseMapping) – the database maps included in the model
spinetoolbox.spine_db_editor.mvcmodels.empty_parameter_models
¶Empty models for parameter definitions and values.
- authors
Marin (KTH)
- date
28.6.2019
An empty parameter model. |
|
An empty parameter_definition model. |
|
An empty object parameter_definition model. |
|
An empty relationship parameter_definition model. |
|
An empty parameter_value model. |
|
An empty object parameter_value model. |
|
An empty relationship parameter_value model. |
- class spinetoolbox.spine_db_editor.mvcmodels.empty_parameter_models.EmptyParameterModel(parent, header, db_mngr)[source]¶
Bases:
spinetoolbox.mvcmodels.empty_row_model.EmptyRowModel
An empty parameter model.
Initialize class.
- Parameters
parent (Object) – the parent object, typically a CompoundParameterModel
header (list) – list of field names for the header
db_mngr (SpineDBManager) –
- property item_type(self)[source]¶
The item type, either ‘parameter_value’ or ‘parameter_definition’, required by the json_fields property.
- data(self, index, role=Qt.DisplayRole)[source]¶
Returns the data stored under the given role for the item referred to by the index.
- Parameters
index (QModelIndex) – Index of item
role (int) – Data role
- Returns
Item data for given role.
- _make_unique_id(self, item)[source]¶
Returns a unique id for the given model item (name-based). Used by receive_parameter_data_added.
- receive_parameter_data_added(self, db_map_data)[source]¶
Runs when parameter definitions or values are added. Finds and removes model items that were successfully added to the db.
- batch_set_data(self, indexes, data)[source]¶
Sets data for indexes in batch. If successful, add items to db.
- class spinetoolbox.spine_db_editor.mvcmodels.empty_parameter_models.EmptyParameterDefinitionModel(*args, **kwargs)[source]¶
Bases:
spinetoolbox.spine_db_editor.mvcmodels.parameter_mixins.FillInValueListIdMixin
,spinetoolbox.spine_db_editor.mvcmodels.parameter_mixins.FillInEntityClassIdMixin
,spinetoolbox.spine_db_editor.mvcmodels.parameter_mixins.FillInParameterNameMixin
,EmptyParameterModel
An empty parameter_definition model.
Initializes lookup dicts.
- class spinetoolbox.spine_db_editor.mvcmodels.empty_parameter_models.EmptyObjectParameterDefinitionModel(*args, **kwargs)[source]¶
Bases:
EmptyParameterDefinitionModel
An empty object parameter_definition model.
Initializes lookup dicts.
- class spinetoolbox.spine_db_editor.mvcmodels.empty_parameter_models.EmptyRelationshipParameterDefinitionModel(*args, **kwargs)[source]¶
Bases:
EmptyParameterDefinitionModel
An empty relationship parameter_definition model.
Initializes lookup dicts.
- class spinetoolbox.spine_db_editor.mvcmodels.empty_parameter_models.EmptyParameterValueModel(*args, **kwargs)[source]¶
Bases:
spinetoolbox.spine_db_editor.mvcmodels.parameter_mixins.ValidateValueInListForInsertMixin
,spinetoolbox.spine_db_editor.mvcmodels.parameter_mixins.InferEntityClassIdMixin
,spinetoolbox.spine_db_editor.mvcmodels.parameter_mixins.FillInAlternativeIdMixin
,spinetoolbox.spine_db_editor.mvcmodels.parameter_mixins.FillInParameterDefinitionIdsMixin
,spinetoolbox.spine_db_editor.mvcmodels.parameter_mixins.FillInEntityIdsMixin
,spinetoolbox.spine_db_editor.mvcmodels.parameter_mixins.FillInEntityClassIdMixin
,EmptyParameterModel
An empty parameter_value model.
Initializes lookup dicts.
- property item_type(self)[source]¶
The item type, either ‘parameter_value’ or ‘parameter_definition’, required by the json_fields property.
- class spinetoolbox.spine_db_editor.mvcmodels.empty_parameter_models.EmptyObjectParameterValueModel(*args, **kwargs)[source]¶
Bases:
EmptyParameterValueModel
An empty object parameter_value model.
Initializes lookup dicts.
- class spinetoolbox.spine_db_editor.mvcmodels.empty_parameter_models.EmptyRelationshipParameterValueModel(*args, **kwargs)[source]¶
Bases:
spinetoolbox.spine_db_editor.mvcmodels.parameter_mixins.MakeRelationshipOnTheFlyMixin
,EmptyParameterValueModel
An empty relationship parameter_value model.
Initializes lookup dicts.
spinetoolbox.spine_db_editor.mvcmodels.entity_tree_item
¶Classes to represent entities in a tree.
- authors
Vennström (VTT), M. Marin (KTH)
- date
11.3.2019
A tree item that may belong in multiple databases. |
|
An object tree root item. |
|
A relationship tree root item. |
|
An entity_class item. |
|
An object_class item. |
|
A relationship_class item. |
|
A relationship_class item. |
|
A relationship_class item. |
|
A member object class item. |
|
An entity item. |
|
An object item. |
|
A member object item. |
|
A relationship item. |
- class spinetoolbox.spine_db_editor.mvcmodels.entity_tree_item.EntityRootItem(model=None, db_map_id=None)[source]¶
Bases:
spinetoolbox.spine_db_editor.mvcmodels.multi_db_tree_item.MultiDBTreeItem
A tree item that may belong in multiple databases.
Init class.
- Parameters
db_mngr (SpineDBManager) – a database manager
db_map_data (dict) – maps instances of DiffDatabaseMapping to the id of the item in that db
- class spinetoolbox.spine_db_editor.mvcmodels.entity_tree_item.ObjectTreeRootItem(model=None, db_map_id=None)[source]¶
Bases:
EntityRootItem
An object tree root item.
Init class.
- Parameters
db_mngr (SpineDBManager) – a database manager
db_map_data (dict) – maps instances of DiffDatabaseMapping to the id of the item in that db
- class spinetoolbox.spine_db_editor.mvcmodels.entity_tree_item.RelationshipTreeRootItem(model=None, db_map_id=None)[source]¶
Bases:
EntityRootItem
A relationship tree root item.
Init class.
- Parameters
db_mngr (SpineDBManager) – a database manager
db_map_data (dict) – maps instances of DiffDatabaseMapping to the id of the item in that db
- class spinetoolbox.spine_db_editor.mvcmodels.entity_tree_item.EntityClassItem(*args, **kwargs)[source]¶
Bases:
spinetoolbox.spine_db_editor.mvcmodels.multi_db_tree_item.MultiDBTreeItem
An entity_class item.
Overridden method to declare group_child_count attribute.
- raise_group_children_by_id(self, db_map_ids)[source]¶
Moves group children to the top of the list.
- Parameters
db_map_ids (dict) – set of ids corresponding to newly inserted group children, keyed by DiffDatabaseMapping
- class spinetoolbox.spine_db_editor.mvcmodels.entity_tree_item.ObjectClassItem(*args, **kwargs)[source]¶
Bases:
EntityClassItem
An object_class item.
Overridden method to declare group_child_count attribute.
- class spinetoolbox.spine_db_editor.mvcmodels.entity_tree_item.RelationshipClassItemBase(*args, **kwargs)[source]¶
Bases:
EntityClassItem
A relationship_class item.
Overridden method to declare group_child_count attribute.
- class spinetoolbox.spine_db_editor.mvcmodels.entity_tree_item.RelationshipClassItem(*args, **kwargs)[source]¶
Bases:
RelationshipClassItemBase
A relationship_class item.
Overridden method to declare group_child_count attribute.
- class spinetoolbox.spine_db_editor.mvcmodels.entity_tree_item.ObjectRelationshipClassItem(*args, **kwargs)[source]¶
Bases:
RelationshipClassItemBase
A relationship_class item.
Overridden method to declare group_child_count attribute.
- class spinetoolbox.spine_db_editor.mvcmodels.entity_tree_item.MemberObjectClassItem(*args, **kwargs)[source]¶
Bases:
ObjectClassItem
A member object class item.
Overridden method to declare group_child_count attribute.
- property display_id(self)[source]¶
“Returns an id for display based on the display key. This id must be the same across all db_maps. If it’s not, this property becomes None and measures need to be taken (see update_children_by_id).
- _display_icon(self, for_group=False)[source]¶
Returns icon for this item as if it was indeed an object class.
- class spinetoolbox.spine_db_editor.mvcmodels.entity_tree_item.EntityItem(model=None, db_map_id=None)[source]¶
Bases:
spinetoolbox.spine_db_editor.mvcmodels.multi_db_tree_item.MultiDBTreeItem
An entity item.
Init class.
- Parameters
db_mngr (SpineDBManager) – a database manager
db_map_data (dict) – maps instances of DiffDatabaseMapping to the id of the item in that db
- class spinetoolbox.spine_db_editor.mvcmodels.entity_tree_item.ObjectItem(model=None, db_map_id=None)[source]¶
Bases:
EntityItem
An object item.
Init class.
- Parameters
db_mngr (SpineDBManager) – a database manager
db_map_data (dict) – maps instances of DiffDatabaseMapping to the id of the item in that db
- class spinetoolbox.spine_db_editor.mvcmodels.entity_tree_item.MemberObjectItem(model=None, db_map_id=None)[source]¶
Bases:
ObjectItem
A member object item.
Init class.
- Parameters
db_mngr (SpineDBManager) – a database manager
db_map_data (dict) – maps instances of DiffDatabaseMapping to the id of the item in that db
- class spinetoolbox.spine_db_editor.mvcmodels.entity_tree_item.RelationshipItem(*args, **kwargs)[source]¶
Bases:
EntityItem
A relationship item.
Overridden method to make sure we never try to fetch this item.
spinetoolbox.spine_db_editor.mvcmodels.entity_tree_models
¶Models to represent entities in a tree.
- authors
Vennström (VTT), M. Marin (KTH)
- date
11.3.2019
An ‘object-oriented’ tree model. |
|
A relationship-oriented tree model. |
- class spinetoolbox.spine_db_editor.mvcmodels.entity_tree_models.ObjectTreeModel(parent, db_mngr, *db_maps)[source]¶
Bases:
spinetoolbox.spine_db_editor.mvcmodels.multi_db_tree_model.MultiDBTreeModel
An ‘object-oriented’ tree model.
Init class.
- Parameters
parent (SpineDBEditor) –
db_mngr (SpineDBManager) – A manager for the given db_maps
db_maps (iter) – DiffDatabaseMapping instances
- property root_item_type(self)[source]¶
Implement in subclasses to create a model specific to any entity type.
- _parent_object_data(self, db_map_data)[source]¶
Takes given object data and returns the same data keyed by parent tree-item.
- Parameters
db_map_data (dict) – maps DiffDatabaseMapping instances to list of items as dict
- Returns
maps parent tree-items to DiffDatabaseMapping instances to list of item ids
- Return type
dict
- _parent_relationship_class_data(self, db_map_data)[source]¶
Takes given relationship_class data and returns the same data keyed by parent tree-item.
- Parameters
db_map_data (dict) – maps DiffDatabaseMapping instances to list of items as dict
- Returns
maps parent tree-items to DiffDatabaseMapping instances to list of item ids
- Return type
dict
- _parent_relationship_data(self, db_map_data)[source]¶
Takes given relationship data and returns the same data keyed by parent tree-item.
- Parameters
db_map_data (dict) – maps DiffDatabaseMapping instances to list of items as dict
- Returns
maps parent tree-items to DiffDatabaseMapping instances to list of item ids
- Return type
dict
- _parent_entity_group_data(self, db_map_data)[source]¶
Takes given entity group data and returns the same data keyed by parent tree-item.
- Parameters
db_map_data (dict) – maps DiffDatabaseMapping instances to list of items as dict
- Returns
maps parent tree-items to DiffDatabaseMapping instances to list of item ids
- Return type
dict
- _parent_entity_member_data(self, db_map_data)[source]¶
Takes given entity member data and returns the same data keyed by parent tree-item.
- Parameters
db_map_data (dict) – maps DiffDatabaseMapping instances to list of items as dict
- Returns
maps parent tree-items to DiffDatabaseMapping instances to list of item ids
- Return type
dict
- class spinetoolbox.spine_db_editor.mvcmodels.entity_tree_models.RelationshipTreeModel(parent, db_mngr, *db_maps)[source]¶
Bases:
spinetoolbox.spine_db_editor.mvcmodels.multi_db_tree_model.MultiDBTreeModel
A relationship-oriented tree model.
Init class.
- Parameters
parent (SpineDBEditor) –
db_mngr (SpineDBManager) – A manager for the given db_maps
db_maps (iter) – DiffDatabaseMapping instances
- property root_item_type(self)[source]¶
Implement in subclasses to create a model specific to any entity type.
- _parent_relationship_data(self, db_map_data)[source]¶
Takes given relationship data and returns the same data keyed by parent tree-item.
- Parameters
db_map_data (dict) – maps DiffDatabaseMapping instances to list of items as dict
- Returns
maps parent tree-items to DiffDatabaseMapping instances to list of item ids
- Return type
dict
spinetoolbox.spine_db_editor.mvcmodels.frozen_table_model
¶Contains FrozenTableModel class.
- author
Vennström (VTT)
- date
24.9.2019
Used by custom_qtableview.FrozenTableView |
- class spinetoolbox.spine_db_editor.mvcmodels.frozen_table_model.FrozenTableModel(parent, headers=None, data=None)[source]¶
Bases:
PySide2.QtCore.QAbstractItemModel
Used by custom_qtableview.FrozenTableView
- Parameters
parent (TabularViewMixin) –
spinetoolbox.spine_db_editor.mvcmodels.multi_db_tree_item
¶Base classes to represent items from multiple databases in a tree.
- authors
Vennström (VTT), M. Marin (KTH)
- date
17.6.2020
A tree item that may belong in multiple databases. |
- class spinetoolbox.spine_db_editor.mvcmodels.multi_db_tree_item.MultiDBTreeItem(model=None, db_map_id=None)[source]¶
Bases:
spinetoolbox.mvcmodels.minimal_tree_model.TreeItem
A tree item that may belong in multiple databases.
Init class.
- Parameters
db_mngr (SpineDBManager) – a database manager
db_map_data (dict) – maps instances of DiffDatabaseMapping to the id of the item in that db
- property child_item_type(self)[source]¶
Returns the type of child items. Reimplement in subclasses to return something more meaningful.
- property display_id(self)[source]¶
“Returns an id for display based on the display key. This id must be the same across all db_maps. If it’s not, this property becomes None and measures need to be taken (see update_children_by_id).
- property display_icon(self)[source]¶
Returns an icon to display next to the name. Reimplement in subclasses to return something nice.
- _deep_refresh_children(self)[source]¶
Refreshes children after taking db_maps from them. Called after removing and updating children for this item.
- deep_remove_db_map(self, db_map)[source]¶
Removes given db_map from this item and all its descendants.
- deep_take_db_map(self, db_map)[source]¶
Removes given db_map from this item and all its descendants, and returns a new item from the db_map’s data.
- Returns
MultiDBTreeItem, NoneType
- db_map_id(self, db_map)[source]¶
Returns the id for this item in given db_map or None if not present.
- db_map_data(self, db_map)[source]¶
Returns data for this item in given db_map or None if not present.
- db_map_data_field(self, db_map, field, default=None)[source]¶
Returns field from data for this item in given db_map or None if not found.
- _create_new_children(self, db_map, children_ids)[source]¶
Creates new items from ids associated to a db map.
- Parameters
db_map (DiffDatabaseMapping) – create children for this db_map
children_ids (iter) – create children from these ids
- _merge_children(self, new_children)[source]¶
Merges new children into this item. Ensures that each children has a valid display id afterwards.
- abstract _get_children_ids(self, db_map)[source]¶
Returns a list of children ids. Must be reimplemented in subclasses.
- append_children_by_id(self, db_map_ids)[source]¶
Appends children by id.
- Parameters
db_map_ids (dict) – maps DiffDatabaseMapping instances to list of ids
- remove_children_by_id(self, db_map_ids)[source]¶
Removes children by id.
- Parameters
db_map_ids (dict) – maps DiffDatabaseMapping instances to list of ids
- update_children_by_id(self, db_map_ids)[source]¶
Updates children by id. Essentially makes sure all children have a valid display id after updating the underlying data. These may require ‘splitting’ a child into several for different dbs or merging two or more children from different dbs.
Examples of problems:
The user renames an object_class in one db but not in the others –> we need to split
The user renames an object_class and the new name is already ‘taken’ by another object_class in another db_map –> we need to merge
- Parameters
db_map_ids (dict) – maps DiffDatabaseMapping instances to list of ids
- insert_children(self, position, *children)[source]¶
Insert new children at given position. Returns a boolean depending on how it went.
- Parameters
position (int) – insert new items here
children (iter) – insert items from this iterable
- remove_children(self, position, count)[source]¶
Removes count children starting from the given position.
- find_children_by_id(self, db_map, *ids, reverse=True)[source]¶
Generates children with the given ids in the given db_map. If the first id is True, then generates all children with the given db_map.
spinetoolbox.spine_db_editor.mvcmodels.multi_db_tree_model
¶A base model class to represent items from multiple databases in a tree.
- authors
Vennström (VTT), M. Marin (KTH)
- date
17.6.2020
Base class for all tree models in Spine db editor. |
- class spinetoolbox.spine_db_editor.mvcmodels.multi_db_tree_model.MultiDBTreeModel(parent, db_mngr, *db_maps)[source]¶
Bases:
spinetoolbox.mvcmodels.minimal_tree_model.MinimalTreeModel
Base class for all tree models in Spine db editor.
Init class.
- Parameters
parent (SpineDBEditor) –
db_mngr (SpineDBManager) – A manager for the given db_maps
db_maps (iter) – DiffDatabaseMapping instances
spinetoolbox.spine_db_editor.mvcmodels.parameter_mixins
¶Miscelaneous mixins for parameter models
- authors
Marin (KTH)
- date
4.10.2019
Base class for all mixins that convert model items (name-based) into database items (id-based). |
|
Fills in alternative names. |
|
Fills in parameter names. |
|
Fills in value list ids. |
|
Makes parameter_tag items. |
|
Fills in entity_class ids. |
|
Fills in entity ids. |
|
Fills in parameter_definition ids. |
|
Infers entity class ids. |
|
Imposes entity class ids. |
|
Validates that the chosen value is in the value list if one set. |
|
Validates that the chosen value is in the value list if one set. |
|
Validates that the chosen value is in the value list if one set. |
|
Makes relationships on the fly. |
|
- class spinetoolbox.spine_db_editor.mvcmodels.parameter_mixins.ConvertToDBMixin[source]¶
Base class for all mixins that convert model items (name-based) into database items (id-based).
- class spinetoolbox.spine_db_editor.mvcmodels.parameter_mixins.FillInAlternativeIdMixin(*args, **kwargs)[source]¶
Bases:
ConvertToDBMixin
Fills in alternative names.
Initializes lookup dicts.
- class spinetoolbox.spine_db_editor.mvcmodels.parameter_mixins.FillInParameterNameMixin[source]¶
Bases:
ConvertToDBMixin
Fills in parameter names.
- class spinetoolbox.spine_db_editor.mvcmodels.parameter_mixins.FillInValueListIdMixin(*args, **kwargs)[source]¶
Bases:
ConvertToDBMixin
Fills in value list ids.
Initializes lookup dicts.
- build_lookup_dictionary(self, db_map_data)[source]¶
Builds a name lookup dictionary for the given data.
- Parameters
db_map_data (dict) – lists of model items keyed by DiffDatabaseMapping
- class spinetoolbox.spine_db_editor.mvcmodels.parameter_mixins.MakeParameterTagMixin(*args, **kwargs)[source]¶
Bases:
ConvertToDBMixin
Makes parameter_tag items.
Initializes lookup dicts.
- build_lookup_dictionary(self, db_map_data)[source]¶
Builds a name lookup dictionary for the given data.
- Parameters
db_map_data (dict) – lists of model items keyed by DiffDatabaseMapping
- _make_parameter_definition_tag(self, item, db_map)[source]¶
Returns a db parameter_definition tag item (id-based) from the given model parameter_definition item (name-based).
- Parameters
item (dict) – the model parameter_definition item
db_map (DiffDatabaseMapping) – the database where the resulting item belongs
- Returns
the db parameter_definition tag item list: error log
- Return type
dict
- class spinetoolbox.spine_db_editor.mvcmodels.parameter_mixins.FillInEntityClassIdMixin(*args, **kwargs)[source]¶
Bases:
ConvertToDBMixin
Fills in entity_class ids.
Initializes lookup dicts.
- build_lookup_dictionary(self, db_map_data)[source]¶
Builds a name lookup dictionary for the given data.
- Parameters
db_map_data (dict) – lists of model items keyed by DiffDatabaseMapping
- class spinetoolbox.spine_db_editor.mvcmodels.parameter_mixins.FillInEntityIdsMixin(*args, **kwargs)[source]¶
Bases:
ConvertToDBMixin
Fills in entity ids.
Initializes lookup dicts.
- build_lookup_dictionary(self, db_map_data)[source]¶
Builds a name lookup dictionary for the given data.
- Parameters
db_map_data (dict) – lists of model items keyed by DiffDatabaseMapping
- _fill_in_entity_ids(self, item, db_map)[source]¶
Fills in all possible entity ids keyed by entity_class id in the given db item (as there can be more than one entity for the same name).
- Parameters
item (dict) – the db item
db_map (DiffDatabaseMapping) – the database where the given item belongs
- Returns
error log
- Return type
list
- class spinetoolbox.spine_db_editor.mvcmodels.parameter_mixins.FillInParameterDefinitionIdsMixin(*args, **kwargs)[source]¶
Bases:
ConvertToDBMixin
Fills in parameter_definition ids.
Initializes lookup dicts.
- build_lookup_dictionary(self, db_map_data)[source]¶
Builds a name lookup dictionary for the given data.
- Parameters
db_map_data (dict) – lists of model items keyed by DiffDatabaseMapping
- _fill_in_parameter_ids(self, item, db_map)[source]¶
Fills in all possible parameter_definition ids keyed by entity_class id in the given db item (as there can be more than one parameter_definition for the same name).
- Parameters
item (dict) – the db item
db_map (DiffDatabaseMapping) – the database where the given item belongs
- Returns
error log
- Return type
list
- class spinetoolbox.spine_db_editor.mvcmodels.parameter_mixins.InferEntityClassIdMixin[source]¶
Bases:
ConvertToDBMixin
Infers entity class ids.
- _convert_to_db(self, item, db_map)[source]¶
Returns a db item (id-based) from the given model item (name-based).
- Parameters
item (dict) – the model item
db_map (DiffDatabaseMapping) – the database where the resulting item belongs
- Returns
the db item list: error log
- Return type
dict
- _infer_and_fill_in_entity_class_id(self, item, db_map)[source]¶
Fills the entity_class id in the given db item, by intersecting entity ids and parameter ids. Then picks the correct entity id and parameter_definition id. Also sets the inferred entity_class name in the model.
- Parameters
item (dict) – the db item
db_map (DiffDatabaseMapping) – the database where the given item belongs
- Returns
error log
- Return type
list
- class spinetoolbox.spine_db_editor.mvcmodels.parameter_mixins.ImposeEntityClassIdMixin[source]¶
Bases:
ConvertToDBMixin
Imposes entity class ids.
- _convert_to_db(self, item, db_map)[source]¶
Returns a db item (id-based) from the given model item (name-based).
- Parameters
item (dict) – the model item
db_map (DiffDatabaseMapping) – the database where the resulting item belongs
- Returns
the db item list: error log
- Return type
dict
- _impose_entity_class_id(self, item, db_map)[source]¶
Imposes the entity_class id from the model, to pick the correct entity id and parameter_definition id.
- Parameters
item (dict) – the db item
db_map (DiffDatabaseMapping) – the database where the given item belongs
- Returns
error log
- Return type
list
- class spinetoolbox.spine_db_editor.mvcmodels.parameter_mixins.ValidateValueInListMixin[source]¶
Bases:
ConvertToDBMixin
Validates that the chosen value is in the value list if one set.
- class spinetoolbox.spine_db_editor.mvcmodels.parameter_mixins.ValidateValueInListForInsertMixin[source]¶
Bases:
ValidateValueInListMixin
Validates that the chosen value is in the value list if one set.
- class spinetoolbox.spine_db_editor.mvcmodels.parameter_mixins.ValidateValueInListForUpdateMixin[source]¶
Bases:
ValidateValueInListMixin
Validates that the chosen value is in the value list if one set.
- class spinetoolbox.spine_db_editor.mvcmodels.parameter_mixins.MakeRelationshipOnTheFlyMixin(*args, **kwargs)[source]¶
Makes relationships on the fly.
Initializes lookup dicts.
- static _make_unique_relationship_id(item)[source]¶
Returns a unique name-based identifier for db relationships.
- build_lookup_dictionaries(self, db_map_data)[source]¶
Builds a name lookup dictionary for the given data.
- Parameters
db_map_data (dict) – lists of model items keyed by DiffDatabaseMapping.
- _make_relationship_on_the_fly(self, item, db_map)[source]¶
Returns a database relationship item (id-based) from the given model parameter_value item (name-based).
- Parameters
item (dict) – the model parameter_value item
db_map (DiffDatabaseMapping) – the database where the resulting item belongs
- Returns
the db relationship item list: error log
- Return type
dict
spinetoolbox.spine_db_editor.mvcmodels.parameter_tag_model
¶A tree model for parameter_tags.
- authors
Marin (KTH)
- date
28.6.2019
An item representing a db. |
|
Paints the last item gray. |
|
A model to display parameter_tag data in a tree view. |
- class spinetoolbox.spine_db_editor.mvcmodels.parameter_tag_model.DBItem(db_map)[source]¶
Bases:
spinetoolbox.spine_db_editor.mvcmodels.tree_item_utility.EmptyChildMixin
,spinetoolbox.spine_db_editor.mvcmodels.tree_item_utility.NonLazyDBItem
An item representing a db.
Init class.
- Args
db_mngr (SpineDBManager) db_map (DiffDatabaseMapping)
- class spinetoolbox.spine_db_editor.mvcmodels.parameter_tag_model.TagItem(identifier=None)[source]¶
Bases:
spinetoolbox.spine_db_editor.mvcmodels.tree_item_utility.LastGrayMixin
,spinetoolbox.spine_db_editor.mvcmodels.tree_item_utility.EditableMixin
,spinetoolbox.spine_db_editor.mvcmodels.tree_item_utility.NonLazyTreeItem
Paints the last item gray.
Initializes item.
- Parameters
model (MinimalTreeModel, NoneType) – The model where the item belongs.
- class spinetoolbox.spine_db_editor.mvcmodels.parameter_tag_model.ParameterTagModel(parent, db_mngr, *db_maps)[source]¶
Bases:
spinetoolbox.spine_db_editor.mvcmodels.tree_model_base.TreeModelBase
A model to display parameter_tag data in a tree view.
- Parameters
parent (SpineDBEditor) –
db_mngr (SpineDBManager) –
db_maps (iter) – DiffDatabaseMapping instances
Initialize class
spinetoolbox.spine_db_editor.mvcmodels.parameter_value_list_model
¶A tree model for parameter_value lists.
- authors
Marin (KTH)
- date
28.6.2019
An item representing a db. |
|
A list item. |
|
A value item. |
|
A model to display parameter_value_list data in a tree view. |
- class spinetoolbox.spine_db_editor.mvcmodels.parameter_value_list_model.DBItem(db_map)[source]¶
Bases:
spinetoolbox.spine_db_editor.mvcmodels.tree_item_utility.EmptyChildMixin
,spinetoolbox.spine_db_editor.mvcmodels.tree_item_utility.NonLazyDBItem
An item representing a db.
Init class.
- Args
db_mngr (SpineDBManager) db_map (DiffDatabaseMapping)
- class spinetoolbox.spine_db_editor.mvcmodels.parameter_value_list_model.ListItem(identifier=None)[source]¶
Bases:
spinetoolbox.spine_db_editor.mvcmodels.tree_item_utility.LastGrayMixin
,spinetoolbox.spine_db_editor.mvcmodels.tree_item_utility.AllBoldMixin
,spinetoolbox.spine_db_editor.mvcmodels.tree_item_utility.EditableMixin
,spinetoolbox.spine_db_editor.mvcmodels.tree_item_utility.NonLazyTreeItem
A list item.
Initializes item.
- Parameters
model (MinimalTreeModel, NoneType) – The model where the item belongs.
- set_data(self, column, value, role=Qt.EditRole)[source]¶
Sets data for this item.
- Parameters
column (int) – column index
value (object) – a new value
role (int) – role of the new value
- Returns
True if data was set successfully, False otherwise
- Return type
bool
- class spinetoolbox.spine_db_editor.mvcmodels.parameter_value_list_model.ValueItem(is_empty=False)[source]¶
Bases:
spinetoolbox.spine_db_editor.mvcmodels.tree_item_utility.LastGrayMixin
,spinetoolbox.spine_db_editor.mvcmodels.tree_item_utility.EditableMixin
,spinetoolbox.spine_db_editor.mvcmodels.tree_item_utility.NonLazyTreeItem
A value item.
Initializes item.
- Parameters
model (MinimalTreeModel, NoneType) – The model where the item belongs.
- class spinetoolbox.spine_db_editor.mvcmodels.parameter_value_list_model.ParameterValueListModel(parent, db_mngr, *db_maps)[source]¶
Bases:
spinetoolbox.spine_db_editor.mvcmodels.tree_model_base.TreeModelBase
A model to display parameter_value_list data in a tree view.
- Parameters
parent (SpineDBEditor) –
db_mngr (SpineDBManager) –
db_maps (iter) – DiffDatabaseMapping instances
Initialize class
spinetoolbox.spine_db_editor.mvcmodels.pivot_model
¶Provides PivotModel.
- author
Vennström (VTT)
- date
1.11.2018
- class spinetoolbox.spine_db_editor.mvcmodels.pivot_model.PivotModel[source]¶
- reset_model(self, data, index_ids=(), rows=(), columns=(), frozen=(), frozen_value=())[source]¶
Resets the model.
- _check_pivot(self, rows, columns, frozen, frozen_value)[source]¶
Checks if given pivot is valid.
- Returns
error message or None if no error
- Return type
str, NoneType
- _index_key_getter(self, indexes)[source]¶
Returns an itemgetter that always returns tuples from list of indexes
- Parameters
indexes (tuple) –
- Returns
an itemgetter
- Return type
Callable
- _get_unique_index_values(self, indexes)[source]¶
Returns unique indexes that match the frozen condition.
- Parameters
indexes (tuple) – indexes to match
- Returns
unique indexes
- Return type
list
spinetoolbox.spine_db_editor.mvcmodels.pivot_table_models
¶Provides pivot table models for the Tabular View.
- author
Vennström (VTT)
- date
1.11.2018
|
|
Base class for all ‘top left pivot headers’. |
|
A top left header for object_class. |
|
A top left header for parameter_definition. |
|
A top left header for parameter index. |
|
A top left header for alternative. |
|
A top left header for scenario. |
|
A top left header for database. |
|
A model for the pivot table in parameter_value input type. |
|
A model for the pivot table in parameter index expansion input type. |
|
A model for the pivot table in relationship input type. |
|
A model for the pivot table in scenario alternative input type. |
|
Initialize class. |
- class spinetoolbox.spine_db_editor.mvcmodels.pivot_table_models.PivotTableModelBase(parent)[source]¶
Bases:
PySide2.QtCore.QAbstractTableModel
- Parameters
parent (SpineDBEditor) –
- abstract call_reset_model(self, pivot=None)[source]¶
- Parameters
pivot (tuple, optional) – list of rows, list of columns, list of frozen indexes, frozen value
- update_model(self, data)[source]¶
Update model with new data, but doesn’t grow the model.
- Parameters
data (dict) –
- property plot_x_column(self)[source]¶
Returns the index of the column designated as Y values for plotting or None.
- rowCount(self, parent=QModelIndex())[source]¶
Number of rows in table, number of header rows + datarows + 1 empty row
- columnCount(self, parent=QModelIndex())[source]¶
Number of columns in table, number of header columns + datacolumns + 1 empty columns
- top_left_indexes(self)[source]¶
Returns indexes in the top left area.
- Returns
list(QModelIndex): top indexes (horizontal headers, associated to rows) list(QModelIndex): left indexes (vertical headers, associated to columns)
- index_in_top_left(self, index)[source]¶
Returns whether or not the given index is in top left corner, where pivot names are displayed
- index_in_column_headers(self, index)[source]¶
Returns whether or not the given index is in column headers (horizontal) area
- index_in_row_headers(self, index)[source]¶
Returns whether or not the given index is in row headers (vertical) area
- index_in_empty_column_headers(self, index)[source]¶
Returns whether or not the given index is in empty column headers (vertical) area
- index_in_empty_row_headers(self, index)[source]¶
Returns whether or not the given index is in empty row headers (vertical) area
- column_is_index_column(self, column)[source]¶
Returns True if column is the column containing expanded parameter_value indexes.
- map_to_pivot(self, index)[source]¶
Returns a tuple of row and column in the pivot model that corresponds to the given model index.
- Parameters
index (QModelIndex) –
- Returns
row int: column
- Return type
int
- top_left_id(self, index)[source]¶
Returns the id of the top left header corresponding to the given header index.
- Parameters
index (QModelIndex) –
- Returns
int, NoneType
- _header_id(self, index)[source]¶
Returns the id of the given row or column header index.
- Parameters
index (QModelIndex) –
- Returns
int, NoneType
- _header_ids(self, row, column)[source]¶
Returns the ids for the headers at given row and column.
- Parameters
row (int) –
column (int) –
- Returns
tuple(int)
- class spinetoolbox.spine_db_editor.mvcmodels.pivot_table_models.TopLeftHeaderItem(model)[source]¶
Base class for all ‘top left pivot headers’. Represents a header located in the top left area of the pivot table.
- Parameters
model (PivotTableModelBase) –
- class spinetoolbox.spine_db_editor.mvcmodels.pivot_table_models.TopLeftObjectHeaderItem(model, class_name, class_id)[source]¶
Bases:
TopLeftHeaderItem
A top left header for object_class.
- Parameters
model (PivotTableModelBase) –
- class spinetoolbox.spine_db_editor.mvcmodels.pivot_table_models.TopLeftParameterHeaderItem(model)[source]¶
Bases:
TopLeftHeaderItem
A top left header for parameter_definition.
- Parameters
model (PivotTableModelBase) –
- class spinetoolbox.spine_db_editor.mvcmodels.pivot_table_models.TopLeftParameterIndexHeaderItem(model)[source]¶
Bases:
TopLeftHeaderItem
A top left header for parameter index.
- Parameters
model (PivotTableModelBase) –
- class spinetoolbox.spine_db_editor.mvcmodels.pivot_table_models.TopLeftAlternativeHeaderItem(model)[source]¶
Bases:
TopLeftHeaderItem
A top left header for alternative.
- Parameters
model (PivotTableModelBase) –
- class spinetoolbox.spine_db_editor.mvcmodels.pivot_table_models.TopLeftScenarioHeaderItem(model)[source]¶
Bases:
TopLeftHeaderItem
A top left header for scenario.
- Parameters
model (PivotTableModelBase) –
- class spinetoolbox.spine_db_editor.mvcmodels.pivot_table_models.TopLeftDatabaseHeaderItem(model)[source]¶
Bases:
TopLeftHeaderItem
A top left header for database.
- Parameters
model (PivotTableModelBase) –
- class spinetoolbox.spine_db_editor.mvcmodels.pivot_table_models.ParameterValuePivotTableModel(parent)[source]¶
Bases:
PivotTableModelBase
A model for the pivot table in parameter_value input type.
- Parameters
parent (SpineDBEditor) –
- db_map_object_ids(self, index)[source]¶
Returns db_map and object ids for given index. Used by PivotTableView.
- Returns
DatabaseMapping, list
- _all_header_names(self, index)[source]¶
Returns the object, parameter, alternative, and db names corresponding to the given data index.
- Parameters
index (QModelIndex) –
- Returns
object names str: parameter name str: alternative name str: db name
- Return type
list(str)
- index_name(self, index)[source]¶
Returns a string that concatenates the object and parameter names corresponding to the given data index. Used by plotting and ParameterValueEditor.
- Parameters
index (QModelIndex) –
- Returns
str
- column_name(self, column)[source]¶
Returns a string that concatenates the object and parameter names corresponding to the given column. Used by plotting.
- Parameters
column (int) –
- Returns
str
- _batch_set_parameter_value_data(self, row_map, column_map, data, values)[source]¶
Sets parameter values in batch.
- class spinetoolbox.spine_db_editor.mvcmodels.pivot_table_models.IndexExpansionPivotTableModel(parent)[source]¶
Bases:
ParameterValuePivotTableModel
A model for the pivot table in parameter index expansion input type.
- Parameters
parent (SpineDBEditor) –
- class spinetoolbox.spine_db_editor.mvcmodels.pivot_table_models.RelationshipPivotTableModel(parent)[source]¶
Bases:
PivotTableModelBase
A model for the pivot table in relationship input type.
- Parameters
parent (SpineDBEditor) –
- class spinetoolbox.spine_db_editor.mvcmodels.pivot_table_models.ScenarioAlternativePivotTableModel(parent)[source]¶
Bases:
PivotTableModelBase
A model for the pivot table in scenario alternative input type.
- Parameters
parent (SpineDBEditor) –
- class spinetoolbox.spine_db_editor.mvcmodels.pivot_table_models.PivotTableSortFilterProxy(parent=None)[source]¶
Bases:
PySide2.QtCore.QSortFilterProxyModel
Initialize class.
- set_filter(self, identifier, filter_value)[source]¶
Sets filter for a given index (object_class) name.
- Parameters
identifier (int) – index identifier
filter_value (set, None) – A set of accepted values, or None if no filter (all pass)
- filterAcceptsRow(self, source_row, source_parent)[source]¶
Returns true if the item in the row indicated by the given source_row and source_parent should be included in the model; otherwise returns false.
spinetoolbox.spine_db_editor.mvcmodels.single_parameter_models
¶Single models for parameter definitions and values (as ‘for a single entity’).
- authors
Marin (KTH)
- date
28.6.2019
A parameter model for a single entity_class to go in a CompoundParameterModel. |
|
Associates a parameter model with a single object_class. |
|
Associates a parameter model with a single relationship_class. |
|
A parameter_definition model for a single entity_class. |
|
A parameter_value model for a single entity_class. |
|
An object parameter_definition model for a single object_class. |
|
A relationship parameter_definition model for a single relationship_class. |
|
An object parameter_value model for a single object_class. |
|
A relationship parameter_value model for a single relationship_class. |
- class spinetoolbox.spine_db_editor.mvcmodels.single_parameter_models.SingleParameterModel(header, db_mngr, db_map, entity_class_id, lazy=False)[source]¶
Bases:
spinetoolbox.mvcmodels.minimal_table_model.MinimalTableModel
A parameter model for a single entity_class to go in a CompoundParameterModel. Provides methods to associate the model to an entity_class as well as to filter entities within the class.
Init class.
- Parameters
header (list) – list of field names for the header
- property item_type(self)[source]¶
The item type, either ‘parameter_value’ or ‘parameter_definition’, required by the data method.
- property entity_class_type(self)[source]¶
The entity_class type, either ‘object_class’ or ‘relationship_class’.
- insertRows(self, row, count, parent=QModelIndex())[source]¶
This model doesn’t support row insertion.
- get_field_item_data(self, field)[source]¶
Returns item data for given field.
- Parameters
field (str) – A field from the header
- Returns
str, str
- get_field_item(self, field, db_item)[source]¶
Returns a db item corresponding to the given field from the table header, or an empty dict if the field doesn’t contain db items.
- data(self, index, role=Qt.DisplayRole)[source]¶
Gets the id and database for the row, and reads data from the db manager using the item_type property. Paint the object_class icon next to the name. Also paint background of fixed indexes gray and apply custom format to JSON fields.
- class spinetoolbox.spine_db_editor.mvcmodels.single_parameter_models.SingleObjectParameterMixin[source]¶
Associates a parameter model with a single object_class.
- class spinetoolbox.spine_db_editor.mvcmodels.single_parameter_models.SingleRelationshipParameterMixin[source]¶
Associates a parameter model with a single relationship_class.
- class spinetoolbox.spine_db_editor.mvcmodels.single_parameter_models.SingleParameterDefinitionMixin(*args, **kwargs)[source]¶
Bases:
spinetoolbox.spine_db_editor.mvcmodels.parameter_mixins.FillInParameterNameMixin
,spinetoolbox.spine_db_editor.mvcmodels.parameter_mixins.FillInValueListIdMixin
,spinetoolbox.spine_db_editor.mvcmodels.parameter_mixins.MakeParameterTagMixin
A parameter_definition model for a single entity_class.
Initializes lookup dicts.
- class spinetoolbox.spine_db_editor.mvcmodels.single_parameter_models.SingleParameterValueMixin(*args, **kwargs)[source]¶
Bases:
spinetoolbox.spine_db_editor.mvcmodels.parameter_mixins.ValidateValueInListForUpdateMixin
,spinetoolbox.spine_db_editor.mvcmodels.parameter_mixins.FillInAlternativeIdMixin
,spinetoolbox.spine_db_editor.mvcmodels.parameter_mixins.ImposeEntityClassIdMixin
,spinetoolbox.spine_db_editor.mvcmodels.parameter_mixins.FillInParameterDefinitionIdsMixin
,spinetoolbox.spine_db_editor.mvcmodels.parameter_mixins.FillInEntityIdsMixin
A parameter_value model for a single entity_class.
Initializes lookup dicts.
- class spinetoolbox.spine_db_editor.mvcmodels.single_parameter_models.SingleObjectParameterDefinitionModel(*args, **kwargs)[source]¶
Bases:
SingleObjectParameterMixin
,SingleParameterDefinitionMixin
,SingleParameterModel
An object parameter_definition model for a single object_class.
Initializes lookup dicts.
- class spinetoolbox.spine_db_editor.mvcmodels.single_parameter_models.SingleRelationshipParameterDefinitionModel(*args, **kwargs)[source]¶
Bases:
SingleRelationshipParameterMixin
,SingleParameterDefinitionMixin
,SingleParameterModel
A relationship parameter_definition model for a single relationship_class.
Initializes lookup dicts.
- class spinetoolbox.spine_db_editor.mvcmodels.single_parameter_models.SingleObjectParameterValueModel(*args, **kwargs)[source]¶
Bases:
SingleObjectParameterMixin
,SingleParameterValueMixin
,SingleParameterModel
An object parameter_value model for a single object_class.
Initializes lookup dicts.
- class spinetoolbox.spine_db_editor.mvcmodels.single_parameter_models.SingleRelationshipParameterValueModel(*args, **kwargs)[source]¶
Bases:
SingleRelationshipParameterMixin
,spinetoolbox.spine_db_editor.mvcmodels.parameter_mixins.MakeRelationshipOnTheFlyMixin
,SingleParameterValueMixin
,SingleParameterModel
A relationship parameter_value model for a single relationship_class.
Initializes lookup dicts.
spinetoolbox.spine_db_editor.mvcmodels.tool_feature_item
¶Classes to represent tool and feature items in a tree.
- authors
Marin (KTH)
- date
1.9.2020
A feature root item. |
|
A tool root item. |
|
A feature leaf item. |
|
A tool leaf item. |
|
A tool_feature root item. |
|
A tool feature leaf item. |
|
A tool feature required item. |
|
A tool_feature_method root item. |
|
A tool_feature_method leaf item. |
- class spinetoolbox.spine_db_editor.mvcmodels.tool_feature_item.FeatureRootItem(model=None)[source]¶
Bases:
spinetoolbox.spine_db_editor.mvcmodels.tree_item_utility.EmptyChildRootItem
A feature root item.
Initializes item.
- Parameters
model (MinimalTreeModel, NoneType) – The model where the item belongs.
- class spinetoolbox.spine_db_editor.mvcmodels.tool_feature_item.ToolRootItem(model=None)[source]¶
Bases:
spinetoolbox.spine_db_editor.mvcmodels.tree_item_utility.EmptyChildRootItem
A tool root item.
Initializes item.
- Parameters
model (MinimalTreeModel, NoneType) – The model where the item belongs.
- class spinetoolbox.spine_db_editor.mvcmodels.tool_feature_item.FeatureLeafItem(identifier=None)[source]¶
Bases:
spinetoolbox.spine_db_editor.mvcmodels.tree_item_utility.LastGrayMixin
,spinetoolbox.spine_db_editor.mvcmodels.tree_item_utility.EditableMixin
,spinetoolbox.spine_db_editor.mvcmodels.tree_item_utility.LeafItem
A feature leaf item.
Initializes item.
- Parameters
model (MinimalTreeModel, NoneType) – The model where the item belongs.
- class spinetoolbox.spine_db_editor.mvcmodels.tool_feature_item.ToolLeafItem(identifier=None)[source]¶
Bases:
spinetoolbox.spine_db_editor.mvcmodels.tree_item_utility.LastGrayMixin
,spinetoolbox.spine_db_editor.mvcmodels.tree_item_utility.EditableMixin
,spinetoolbox.spine_db_editor.mvcmodels.tree_item_utility.LeafItem
A tool leaf item.
Initializes item.
- Parameters
model (MinimalTreeModel, NoneType) – The model where the item belongs.
- class spinetoolbox.spine_db_editor.mvcmodels.tool_feature_item.ToolFeatureRootItem(model=None)[source]¶
Bases:
spinetoolbox.spine_db_editor.mvcmodels.tree_item_utility.RootItem
A tool_feature root item.
Initializes item.
- Parameters
model (MinimalTreeModel, NoneType) – The model where the item belongs.
- class spinetoolbox.spine_db_editor.mvcmodels.tool_feature_item.ToolFeatureLeafItem(identifier=None)[source]¶
Bases:
spinetoolbox.spine_db_editor.mvcmodels.tree_item_utility.LeafItem
A tool feature leaf item.
Initializes item.
- Parameters
model (MinimalTreeModel, NoneType) – The model where the item belongs.
- class spinetoolbox.spine_db_editor.mvcmodels.tool_feature_item.ToolFeatureRequiredItem(model=None)[source]¶
Bases:
spinetoolbox.spine_db_editor.mvcmodels.tree_item_utility.NonLazyTreeItem
A tool feature required item.
Initializes item.
- Parameters
model (MinimalTreeModel, NoneType) – The model where the item belongs.
- class spinetoolbox.spine_db_editor.mvcmodels.tool_feature_item.ToolFeatureMethodRootItem(model=None)[source]¶
Bases:
spinetoolbox.spine_db_editor.mvcmodels.tree_item_utility.EmptyChildRootItem
A tool_feature_method root item.
Initializes item.
- Parameters
model (MinimalTreeModel, NoneType) – The model where the item belongs.
- class spinetoolbox.spine_db_editor.mvcmodels.tool_feature_item.ToolFeatureMethodLeafItem(identifier=None)[source]¶
Bases:
spinetoolbox.spine_db_editor.mvcmodels.tree_item_utility.LastGrayMixin
,spinetoolbox.spine_db_editor.mvcmodels.tree_item_utility.LeafItem
A tool_feature_method leaf item.
Initializes item.
- Parameters
model (MinimalTreeModel, NoneType) – The model where the item belongs.
spinetoolbox.spine_db_editor.mvcmodels.tool_feature_model
¶Models to represent tools and features in a tree.
- authors
Marin (KTH)
- date
1.0.2020
A model to display tools and features in a tree view. |
- class spinetoolbox.spine_db_editor.mvcmodels.tool_feature_model.ToolFeatureModel(parent, db_mngr, *db_maps)[source]¶
Bases:
spinetoolbox.spine_db_editor.mvcmodels.tree_model_base.TreeModelBase
A model to display tools and features in a tree view.
- Parameters
parent (SpineDBEditor) –
db_mngr (SpineDBManager) –
db_maps (iter) – DiffDatabaseMapping instances
Initialize class
spinetoolbox.spine_db_editor.mvcmodels.tree_item_utility
¶A tree model for parameter_value lists.
- authors
Marin (KTH)
- date
28.6.2019
A tree item that fetches their children as they are inserted. |
|
Paints the last item gray. |
|
Bolds text. |
|
Guarantess there’s always an empty child. |
|
An item representing a db. |
|
A root item. |
|
Guarantess there’s always an empty child. |
|
A tree item that fetches their children as they are inserted. |
- class spinetoolbox.spine_db_editor.mvcmodels.tree_item_utility.NonLazyTreeItem(model=None)[source]¶
Bases:
spinetoolbox.mvcmodels.minimal_tree_model.TreeItem
A tree item that fetches their children as they are inserted.
Initializes item.
- Parameters
model (MinimalTreeModel, NoneType) – The model where the item belongs.
- class spinetoolbox.spine_db_editor.mvcmodels.tree_item_utility.LastGrayMixin[source]¶
Paints the last item gray.
- class spinetoolbox.spine_db_editor.mvcmodels.tree_item_utility.EmptyChildMixin[source]¶
Guarantess there’s always an empty child.
- class spinetoolbox.spine_db_editor.mvcmodels.tree_item_utility.NonLazyDBItem(db_map)[source]¶
Bases:
NonLazyTreeItem
An item representing a db.
Init class.
- Args
db_mngr (SpineDBManager) db_map (DiffDatabaseMapping)
- class spinetoolbox.spine_db_editor.mvcmodels.tree_item_utility.RootItem(model=None)[source]¶
Bases:
AllBoldMixin
,NonLazyTreeItem
A root item.
Initializes item.
- Parameters
model (MinimalTreeModel, NoneType) – The model where the item belongs.
- class spinetoolbox.spine_db_editor.mvcmodels.tree_item_utility.EmptyChildRootItem(model=None)[source]¶
Bases:
EmptyChildMixin
,RootItem
Guarantess there’s always an empty child.
Initializes item.
- Parameters
model (MinimalTreeModel, NoneType) – The model where the item belongs.
- class spinetoolbox.spine_db_editor.mvcmodels.tree_item_utility.LeafItem(identifier=None)[source]¶
Bases:
NonLazyTreeItem
A tree item that fetches their children as they are inserted.
Initializes item.
- Parameters
model (MinimalTreeModel, NoneType) – The model where the item belongs.
spinetoolbox.spine_db_editor.mvcmodels.tree_model_base
¶Models to represent things in a tree.
- authors
Marin (KTH)
- date
1.0.2020
A base model to display items in a tree view. |
- class spinetoolbox.spine_db_editor.mvcmodels.tree_model_base.TreeModelBase(parent, db_mngr, *db_maps)[source]¶
Bases:
spinetoolbox.mvcmodels.minimal_tree_model.MinimalTreeModel
A base model to display items in a tree view.
- Parameters
parent (SpineDBEditor) –
db_mngr (SpineDBManager) –
db_maps (iter) – DiffDatabaseMapping instances
Initialize class
spinetoolbox.spine_db_editor.ui
¶Automatically generated UI modules for Spine db editor.
- authors
Marin (KTH)
- date
13.5.2020
spinetoolbox.spine_db_editor.widgets
¶Interface logic for Spine db editor.
- authors
Marin (KTH)
- date
13.5.2020
spinetoolbox.spine_db_editor.widgets.add_items_dialogs
¶Classes for custom QDialogs to add items to databases.
- author
Marin (KTH)
- date
13.5.2018
A dialog to let the user add new ‘ready’ relationships. |
|
A dialog to query user’s preferences for new db items. |
|
A dialog to query user’s preferences for new object classes. |
|
A dialog to query user’s preferences for new objects. |
|
A dialog to query user’s preferences for new relationship classes. |
|
A dialog to query user’s preferences for new relationships. |
|
A dialog to query user’s preferences for new relationships. |
|
A dialog to query user’s preferences for managing relationships. |
|
|
|
|
|
|
- class spinetoolbox.spine_db_editor.widgets.add_items_dialogs.AddReadyRelationshipsDialog(parent, relationships_class, relationships, db_mngr, *db_maps)[source]¶
Bases:
spinetoolbox.spine_db_editor.widgets.manage_items_dialogs.ManageItemsDialogBase
A dialog to let the user add new ‘ready’ relationships.
- Parameters
parent (SpineDBEditor) –
relationships_class (dict) –
relationships (list(list(str)) –
db_mngr (SpineDBManager) –
*db_maps – DiffDatabaseMapping instances
- class spinetoolbox.spine_db_editor.widgets.add_items_dialogs.AddItemsDialog(parent, db_mngr, *db_maps)[source]¶
Bases:
spinetoolbox.spine_db_editor.widgets.manage_items_dialogs.ManageItemsDialog
A dialog to query user’s preferences for new db items.
- Parameters
parent (SpineDBEditor) –
db_mngr (SpineDBManager) –
*db_maps – DiffDatabaseMapping instances
- class spinetoolbox.spine_db_editor.widgets.add_items_dialogs.AddObjectClassesDialog(parent, db_mngr, *db_maps)[source]¶
Bases:
spinetoolbox.spine_db_editor.widgets.manage_items_dialogs.ShowIconColorEditorMixin
,AddItemsDialog
A dialog to query user’s preferences for new object classes.
- Parameters
parent (SpineDBEditor) –
db_mngr (SpineDBManager) –
*db_maps – DiffDatabaseMapping instances
- class spinetoolbox.spine_db_editor.widgets.add_items_dialogs.AddObjectsDialog(parent, db_mngr, *db_maps, class_name=None, force_default=False)[source]¶
Bases:
spinetoolbox.spine_db_editor.widgets.manage_items_dialogs.GetObjectClassesMixin
,AddItemsDialog
A dialog to query user’s preferences for new objects.
- Parameters
parent (SpineDBEditor) –
db_mngr (SpineDBManager) –
*db_maps – DiffDatabaseMapping instances
class_name (str) – default object_class name
force_default (bool) – if True, defaults are non-editable
- class spinetoolbox.spine_db_editor.widgets.add_items_dialogs.AddRelationshipClassesDialog(parent, db_mngr, *db_maps, object_class_one_name=None, force_default=False)[source]¶
Bases:
spinetoolbox.spine_db_editor.widgets.manage_items_dialogs.GetObjectClassesMixin
,AddItemsDialog
A dialog to query user’s preferences for new relationship classes.
- Parameters
parent (SpineDBEditor) –
db_mngr (SpineDBManager) –
*db_maps – DiffDatabaseMapping instances
object_class_one_name (str) – default object_class name
force_default (bool) – if True, defaults are non-editable
- class spinetoolbox.spine_db_editor.widgets.add_items_dialogs.AddOrManageRelationshipsDialog(parent, db_mngr, *db_maps)[source]¶
Bases:
spinetoolbox.spine_db_editor.widgets.manage_items_dialogs.GetRelationshipClassesMixin
,spinetoolbox.spine_db_editor.widgets.manage_items_dialogs.GetObjectsMixin
,AddItemsDialog
A dialog to query user’s preferences for new relationships.
- Parameters
parent (SpineDBEditor) –
db_mngr (SpineDBManager) –
*db_maps – DiffDatabaseMapping instances
- class spinetoolbox.spine_db_editor.widgets.add_items_dialogs.AddRelationshipsDialog(parent, db_mngr, *db_maps, relationship_class_key=(), object_names_by_class_name=None, force_default=False)[source]¶
Bases:
AddOrManageRelationshipsDialog
A dialog to query user’s preferences for new relationships.
- Parameters
parent (SpineDBEditor) –
db_mngr (SpineDBManager) –
*db_maps – DiffDatabaseMapping instances
relationship_class_key (tuple(str,str)) – relationships class name, object_class name list string
object_names_by_class_name (dict) – mapping object_class names to default object names
force_default (bool) – if True, defaults are non-editable
- reset_model(self, index)[source]¶
Setup model according to current relationship_class selected in combobox.
- class spinetoolbox.spine_db_editor.widgets.add_items_dialogs.ManageRelationshipsDialog(parent, db_mngr, *db_maps, relationship_class_key=None)[source]¶
Bases:
AddOrManageRelationshipsDialog
A dialog to query user’s preferences for managing relationships.
- Parameters
parent (SpineDBEditor) – data store widget
db_mngr (SpineDBManager) – the manager to do the removal
*db_maps – DiffDatabaseMapping instances
relationship_class_key (str, optional) – relationships class name, object_class name list string.
- class spinetoolbox.spine_db_editor.widgets.add_items_dialogs.ObjectGroupDialogBase(parent, object_class_item, db_mngr, *db_maps, object_item=None)[source]¶
Bases:
PySide2.QtWidgets.QDialog
- Parameters
parent (SpineDBEditor) – data store widget
object_class_item (ObjectClassItem) –
db_mngr (SpineDBManager) –
*db_maps – database mappings
- class spinetoolbox.spine_db_editor.widgets.add_items_dialogs.AddObjectGroupDialog(parent, object_class_item, db_mngr, *db_maps)[source]¶
Bases:
ObjectGroupDialogBase
- Parameters
parent (SpineDBEditor) – data store widget
object_class_item (ObjectClassItem) –
db_mngr (SpineDBManager) –
*db_maps – database mappings
- class spinetoolbox.spine_db_editor.widgets.add_items_dialogs.ManageMembersDialog(parent, object_item, db_mngr, *db_maps)[source]¶
Bases:
ObjectGroupDialogBase
- Parameters
parent (SpineDBEditor) – data store widget
object_item (entity_tree_item.ObjectItem) –
db_mngr (SpineDBManager) –
*db_maps – database mappings
spinetoolbox.spine_db_editor.widgets.custom_delegates
¶Custom item delegates.
- author
Marin (KTH)
- date
1.9.2018
A delegate that places a fully functioning QCheckBox. |
|
A delegate that places a QCheckBox but draws a number instead of the check. |
|
|
|
Delegate for Array and Map editors’ table cells. |
|
Base class for all custom parameter delegates. |
|
A delegate for the database name. |
|
A delegate for the either the value or the default value. |
|
A delegate for the either the default value. |
|
A delegate for the parameter_value. |
|
A delegate for the parameter_tag list. |
|
A delegate for the parameter_value-list. |
|
A delegate for the object_class name. |
|
A delegate for the relationship_class name. |
|
A delegate for the object parameter name. |
|
A delegate for the object name. |
|
A delegate for the object name. |
|
A delegate for the object name list. |
|
A delegate for the tool feature tree. |
|
A delegate for the alternative scenario tree. |
|
A delegate for the parameter value list tree. |
|
A custom delegate for the model in {Add/Edit}ItemDialogs. |
|
A delegate for the model and view in {Add/Edit}ObjectClassesDialog. |
|
A delegate for the model and view in {Add/Edit}ObjectsDialog. |
|
A delegate for the model and view in {Add/Edit}RelationshipClassesDialog. |
|
A delegate for the model and view in {Add/Edit}RelationshipsDialog. |
|
A delegate for the model and view in RemoveEntitiesDialog. |
- class spinetoolbox.spine_db_editor.widgets.custom_delegates.RelationshipPivotTableDelegate(parent)[source]¶
Bases:
spinetoolbox.widgets.custom_delegates.CheckBoxDelegate
A delegate that places a fully functioning QCheckBox.
- Parameters
parent (SpineDBEditor) –
- static _is_relationship_index(index)[source]¶
Checks whether or not the given index corresponds to a relationship, in which case we need to use the check box delegate.
- Returns
bool
- setEditorData(self, editor, index)[source]¶
Do nothing. We’re setting editor data right away in createEditor.
- class spinetoolbox.spine_db_editor.widgets.custom_delegates.ScenarioAlternativeTableDelegate(parent)[source]¶
Bases:
spinetoolbox.widgets.custom_delegates.RankDelegate
A delegate that places a QCheckBox but draws a number instead of the check.
- Parameters
parent (SpineDBEditor) –
- static _is_scenario_alternative_index(index)[source]¶
Checks whether or not the given index corresponds to a scenario alternative, in which case we need to use the rank delegate.
- Returns
bool
- setEditorData(self, editor, index)[source]¶
Do nothing. We’re setting editor data right away in createEditor.
- class spinetoolbox.spine_db_editor.widgets.custom_delegates.ParameterPivotTableDelegate(parent)[source]¶
Bases:
PySide2.QtWidgets.QStyledItemDelegate
- Parameters
parent (SpineDBEditor) –
- class spinetoolbox.spine_db_editor.widgets.custom_delegates.ParameterValueElementDelegate[source]¶
Bases:
PySide2.QtWidgets.QStyledItemDelegate
Delegate for Array and Map editors’ table cells.
- value_editor_requested[source]¶
Emitted when editing the value requires the full blown editor dialog.
- setModelData(self, editor, model, index)[source]¶
Sets data in the model.
editor (CustomLineEditor): editor widget model (QAbstractItemModel): model index (QModelIndex): target index
- class spinetoolbox.spine_db_editor.widgets.custom_delegates.ParameterDelegate(parent, db_mngr)[source]¶
Bases:
PySide2.QtWidgets.QStyledItemDelegate
Base class for all custom parameter delegates.
- db_mngr¶
database manager
- Type
- Parameters
parent (QWidget) – parent widget
db_mngr (SpineDBManager) – database manager
- class spinetoolbox.spine_db_editor.widgets.custom_delegates.DatabaseNameDelegate(parent, db_mngr)[source]¶
Bases:
ParameterDelegate
A delegate for the database name.
- Parameters
parent (QWidget) – parent widget
db_mngr (SpineDBManager) – database manager
- class spinetoolbox.spine_db_editor.widgets.custom_delegates.ParameterValueOrDefaultValueDelegate(parent, db_mngr)[source]¶
Bases:
ParameterDelegate
A delegate for the either the value or the default value.
- Parameters
parent (QWidget) – parent widget
db_mngr (SpineDBManager) – database manager
- class spinetoolbox.spine_db_editor.widgets.custom_delegates.ParameterDefaultValueDelegate(parent, db_mngr)[source]¶
Bases:
ParameterValueOrDefaultValueDelegate
A delegate for the either the default value.
- Parameters
parent (QWidget) – parent widget
db_mngr (SpineDBManager) – database manager
- class spinetoolbox.spine_db_editor.widgets.custom_delegates.ParameterValueDelegate(parent, db_mngr)[source]¶
Bases:
ParameterValueOrDefaultValueDelegate
A delegate for the parameter_value.
- Parameters
parent (QWidget) – parent widget
db_mngr (SpineDBManager) – database manager
- class spinetoolbox.spine_db_editor.widgets.custom_delegates.TagListDelegate(parent, db_mngr)[source]¶
Bases:
ParameterDelegate
A delegate for the parameter_tag list.
- Parameters
parent (QWidget) – parent widget
db_mngr (SpineDBManager) – database manager
- class spinetoolbox.spine_db_editor.widgets.custom_delegates.ValueListDelegate(parent, db_mngr)[source]¶
Bases:
ParameterDelegate
A delegate for the parameter_value-list.
- Parameters
parent (QWidget) – parent widget
db_mngr (SpineDBManager) – database manager
- class spinetoolbox.spine_db_editor.widgets.custom_delegates.ObjectClassNameDelegate(parent, db_mngr)[source]¶
Bases:
ParameterDelegate
A delegate for the object_class name.
- Parameters
parent (QWidget) – parent widget
db_mngr (SpineDBManager) – database manager
- class spinetoolbox.spine_db_editor.widgets.custom_delegates.RelationshipClassNameDelegate(parent, db_mngr)[source]¶
Bases:
ParameterDelegate
A delegate for the relationship_class name.
- Parameters
parent (QWidget) – parent widget
db_mngr (SpineDBManager) – database manager
- class spinetoolbox.spine_db_editor.widgets.custom_delegates.ParameterNameDelegate(parent, db_mngr)[source]¶
Bases:
ParameterDelegate
A delegate for the object parameter name.
- Parameters
parent (QWidget) – parent widget
db_mngr (SpineDBManager) – database manager
- class spinetoolbox.spine_db_editor.widgets.custom_delegates.ObjectNameDelegate(parent, db_mngr)[source]¶
Bases:
ParameterDelegate
A delegate for the object name.
- Parameters
parent (QWidget) – parent widget
db_mngr (SpineDBManager) – database manager
- class spinetoolbox.spine_db_editor.widgets.custom_delegates.AlternativeNameDelegate(parent, db_mngr)[source]¶
Bases:
ParameterDelegate
A delegate for the object name.
- Parameters
parent (QWidget) – parent widget
db_mngr (SpineDBManager) – database manager
- class spinetoolbox.spine_db_editor.widgets.custom_delegates.ObjectNameListDelegate(parent, db_mngr)[source]¶
Bases:
ParameterDelegate
A delegate for the object name list.
- Parameters
parent (QWidget) – parent widget
db_mngr (SpineDBManager) – database manager
- class spinetoolbox.spine_db_editor.widgets.custom_delegates.ToolFeatureDelegate[source]¶
Bases:
PySide2.QtWidgets.QStyledItemDelegate
A delegate for the tool feature tree.
- class spinetoolbox.spine_db_editor.widgets.custom_delegates.AlternativeScenarioDelegate[source]¶
Bases:
PySide2.QtWidgets.QStyledItemDelegate
A delegate for the alternative scenario tree.
- class spinetoolbox.spine_db_editor.widgets.custom_delegates.ParameterValueListDelegate[source]¶
Bases:
PySide2.QtWidgets.QStyledItemDelegate
A delegate for the parameter value list tree.
- class spinetoolbox.spine_db_editor.widgets.custom_delegates.ManageItemsDelegate[source]¶
Bases:
PySide2.QtWidgets.QStyledItemDelegate
A custom delegate for the model in {Add/Edit}ItemDialogs.
- class spinetoolbox.spine_db_editor.widgets.custom_delegates.ManageObjectClassesDelegate[source]¶
Bases:
ManageItemsDelegate
A delegate for the model and view in {Add/Edit}ObjectClassesDialog.
- class spinetoolbox.spine_db_editor.widgets.custom_delegates.ManageObjectsDelegate[source]¶
Bases:
ManageItemsDelegate
A delegate for the model and view in {Add/Edit}ObjectsDialog.
- class spinetoolbox.spine_db_editor.widgets.custom_delegates.ManageRelationshipClassesDelegate[source]¶
Bases:
ManageItemsDelegate
A delegate for the model and view in {Add/Edit}RelationshipClassesDialog.
- class spinetoolbox.spine_db_editor.widgets.custom_delegates.ManageRelationshipsDelegate[source]¶
Bases:
ManageItemsDelegate
A delegate for the model and view in {Add/Edit}RelationshipsDialog.
- class spinetoolbox.spine_db_editor.widgets.custom_delegates.RemoveEntitiesDelegate[source]¶
Bases:
ManageItemsDelegate
A delegate for the model and view in RemoveEntitiesDialog.
spinetoolbox.spine_db_editor.widgets.custom_qgraphicsviews
¶Classes for custom QGraphicsViews for the Entity graph view.
- authors
Savolainen (VTT), M. Marin (KTH)
- date
6.2.2018
QGraphicsView for the Entity Graph View. |
- class spinetoolbox.spine_db_editor.widgets.custom_qgraphicsviews.EntityQGraphicsView(parent)[source]¶
Bases:
spinetoolbox.widgets.custom_qgraphicsviews.CustomQGraphicsView
QGraphicsView for the Entity Graph View.
- Parameters
parent (QWidget) – Graph View Form’s (QMainWindow) central widget (self.centralwidget)
- setScene(self, scene)[source]¶
Sets a new scene to this view.
- Parameters
scene (ShrinkingScene) – a new scene
- _update_actions_visibility(self)[source]¶
Enables or disables actions according to current selection in the graph.
Shows hidden items.
Populates the menu ‘Add heat map’ with parameters for currently shown items in the graph.
- set_cross_hairs_items(self, relationship_class, cross_hairs_items)[source]¶
Sets ‘cross_hairs’ items for relationship creation.
- Parameters
relationship_class (dict) –
cross_hairs_items (list(QGraphicsItems)) –
- mouseMoveEvent(self, event)[source]¶
Updates the hovered object item if we’re in relationship creation mode.
- _update_cross_hairs_pos(self, pos)[source]¶
Updates the hovered object item and sets the ‘cross_hairs’ icon accordingly.
- Parameters
pos (QPoint) – the desired position in view coordinates
- contextMenuEvent(self, e)[source]¶
Shows context menu.
- Parameters
e (QContextMenuEvent) – Context menu event
- wheelEvent(self, event)[source]¶
Zooms in/out. If user has pressed the shift key, rotates instead.
- Parameters
event (QWheelEvent) – Mouse wheel event
spinetoolbox.spine_db_editor.widgets.custom_qtableview
¶Custom QTableView classes that support copy-paste and the like.
- author
Marin (KTH)
- date
18.5.2018
Custom QTableView class with autofilter functionality. |
|
Custom QTableView class with autofilter functionality. |
|
Custom QTableView class with autofilter functionality. |
|
A custom QTableView for the object parameter_definition pane in Spine db editor. |
|
A custom QTableView for the relationship parameter_definition pane in Spine db editor. |
|
A custom QTableView for the object parameter_value pane in Spine db editor. |
|
A custom QTableView for the relationship parameter_value pane in Spine db editor. |
|
Custom QTableView class with pivot capabilities. |
|
- class spinetoolbox.spine_db_editor.widgets.custom_qtableview.ParameterTableView(parent)[source]¶
Bases:
spinetoolbox.widgets.custom_qtableview.AutoFilterCopyPasteTableView
Custom QTableView class with autofilter functionality.
Initialize the view.
- property value_column_header(self)[source]¶
Either “default value” or “value”. Used to identifiy the value column for advanced editting and plotting.
- connect_spine_db_editor(self, spine_db_editor)[source]¶
Connects a Spine db editor to work with this view.
- Parameters
spine_db_editor (SpineDBEditor) –
- _make_delegate(self, column_name, delegate_class)[source]¶
Creates a delegate for the given column and returns it.
- Parameters
column_name (str) –
delegate_class (ParameterDelegate) –
- Returns
ParameterDelegate
- open_in_editor(self)[source]¶
Opens the current index in a parameter_value editor using the connected Spine db editor.
Creates a context menu for this view.
- class spinetoolbox.spine_db_editor.widgets.custom_qtableview.RelationshipParameterTableMixin[source]¶
- class spinetoolbox.spine_db_editor.widgets.custom_qtableview.ParameterDefinitionTableView(parent)[source]¶
Bases:
ParameterTableView
Custom QTableView class with autofilter functionality.
Initialize the view.
- class spinetoolbox.spine_db_editor.widgets.custom_qtableview.ParameterValueTableView(parent)[source]¶
Bases:
ParameterTableView
Custom QTableView class with autofilter functionality.
Initialize the view.
- property value_column_header(self)[source]¶
Either “default value” or “value”. Used to identifiy the value column for advanced editting and plotting.
Creates a context menu for this view.
- class spinetoolbox.spine_db_editor.widgets.custom_qtableview.ObjectParameterDefinitionTableView(parent)[source]¶
Bases:
ObjectParameterTableMixin
,ParameterDefinitionTableView
A custom QTableView for the object parameter_definition pane in Spine db editor.
Initialize the view.
- class spinetoolbox.spine_db_editor.widgets.custom_qtableview.RelationshipParameterDefinitionTableView(parent)[source]¶
Bases:
RelationshipParameterTableMixin
,ParameterDefinitionTableView
A custom QTableView for the relationship parameter_definition pane in Spine db editor.
Initialize the view.
- class spinetoolbox.spine_db_editor.widgets.custom_qtableview.ObjectParameterValueTableView(parent)[source]¶
Bases:
ObjectParameterTableMixin
,ParameterValueTableView
A custom QTableView for the object parameter_value pane in Spine db editor.
Initialize the view.
- class spinetoolbox.spine_db_editor.widgets.custom_qtableview.RelationshipParameterValueTableView(parent)[source]¶
Bases:
RelationshipParameterTableMixin
,ParameterValueTableView
A custom QTableView for the relationship parameter_value pane in Spine db editor.
Initialize the view.
- class spinetoolbox.spine_db_editor.widgets.custom_qtableview.PivotTableView(parent=None)[source]¶
Bases:
spinetoolbox.widgets.custom_qtableview.CopyPasteTableView
Custom QTableView class with pivot capabilities.
Initialize the class.
spinetoolbox.spine_db_editor.widgets.custom_qtreeview
¶Classes for custom QTreeView.
- author
Marin (KTH)
- date
25.4.2018
Tree view base class for object and relationship tree views. |
|
Custom QTreeView class for the object tree in SpineDBEditor. |
|
Custom QTreeView class for the relationship tree in SpineDBEditor. |
|
Base class for all non-entity tree views. |
|
Custom QTreeView class for tools and features in SpineDBEditor. |
|
Custom QTreeView class for the alternative scenario tree in SpineDBEditor. |
|
Custom QTreeView class for parameter_value_list in SpineDBEditor. |
|
Custom QTreeView class for the parameter_tag tree in SpineDBEditor. |
- class spinetoolbox.spine_db_editor.widgets.custom_qtreeview.EntityTreeView(parent)[source]¶
Bases:
spinetoolbox.widgets.custom_qtreeview.CopyTreeView
Tree view base class for object and relationship tree views.
Initialize the view.
- connect_spine_db_editor(self, spine_db_editor)[source]¶
Connects a Spine db editor to work with this view.
- Parameters
spine_db_editor (SpineDBEditor) –
- _add_middle_actions(self)[source]¶
Adds action at the middle of the context menu. Subclasses can reimplement at will.
Creates a context menu for this view.
- _handle_selection_changed(self, selected, deselected)[source]¶
Classifies selection by item type and emits signal.
- export_selected(self)[source]¶
Exports data from selected indexes using the connected Spine db editor.
- mousePressEvent(self, event)[source]¶
Overrides selection behaviour if the user has selected sticky selection in Settings. If sticky selection is enabled, multiple-selection is enabled when selecting items in the Object tree. Pressing the Ctrl-button down, enables single selection.
- Parameters
event (QMouseEvent) –
- class spinetoolbox.spine_db_editor.widgets.custom_qtreeview.ObjectTreeView(parent)[source]¶
Bases:
EntityTreeView
Custom QTreeView class for the object tree in SpineDBEditor.
Initialize the view.
- update_actions_availability(self)[source]¶
Updates the visible property of actions according to whether or not they apply to given item.
- _add_middle_actions(self)[source]¶
Adds action at the middle of the context menu. Subclasses can reimplement at will.
- find_next_relationship(self)[source]¶
Finds the next occurrence of the relationship at the current index and expands it.
- class spinetoolbox.spine_db_editor.widgets.custom_qtreeview.RelationshipTreeView(parent)[source]¶
Bases:
EntityTreeView
Custom QTreeView class for the relationship tree in SpineDBEditor.
Initialize the view.
- _add_middle_actions(self)[source]¶
Adds action at the middle of the context menu. Subclasses can reimplement at will.
- class spinetoolbox.spine_db_editor.widgets.custom_qtreeview.ItemTreeView(parent)[source]¶
Bases:
spinetoolbox.widgets.custom_qtreeview.CopyTreeView
Base class for all non-entity tree views.
Initialize the view.
- abstract update_actions_availability(self, item)[source]¶
Updates the visible property of actions according to whether or not they apply to given item.
Creates a context menu for this view.
- class spinetoolbox.spine_db_editor.widgets.custom_qtreeview.ToolFeatureTreeView(parent)[source]¶
Bases:
ItemTreeView
Custom QTreeView class for tools and features in SpineDBEditor.
Initialize the view.
- class spinetoolbox.spine_db_editor.widgets.custom_qtreeview.AlternativeScenarioTreeView(parent)[source]¶
Bases:
ItemTreeView
Custom QTreeView class for the alternative scenario tree in SpineDBEditor.
Initialize the view.
- class spinetoolbox.spine_db_editor.widgets.custom_qtreeview.ParameterValueListTreeView(parent)[source]¶
Bases:
ItemTreeView
Custom QTreeView class for parameter_value_list in SpineDBEditor.
Initialize the view.
Creates a context menu for this view.
- class spinetoolbox.spine_db_editor.widgets.custom_qtreeview.ParameterTagTreeView(parent)[source]¶
Bases:
ItemTreeView
Custom QTreeView class for the parameter_tag tree in SpineDBEditor.
Initialize the view.
spinetoolbox.spine_db_editor.widgets.custom_qwidgets
¶Custom QWidgets.
- author
Marin (KTH)
- date
13.5.2018
Filter widget class. |
|
Filter widget class. |
|
A button to open files or show them in the folder. |
|
A button to open sqlite files, show them in the folder, or add them to the project. |
|
- class spinetoolbox.spine_db_editor.widgets.custom_qwidgets.DataToValueFilterWidget(parent, data_to_value, show_empty=True)[source]¶
Bases:
spinetoolbox.widgets.custom_qwidgets.FilterWidgetBase
Filter widget class.
Init class.
- Parameters
parent (QWidget) –
data_to_value (method) – a method to translate item data to a value for display role
- class spinetoolbox.spine_db_editor.widgets.custom_qwidgets.LazyFilterWidget(parent, source_model, show_empty=True)[source]¶
Bases:
spinetoolbox.widgets.custom_qwidgets.FilterWidgetBase
Filter widget class.
Init class.
- Parameters
parent (SpineDBEditor) –
source_model (CompoundParameterModel, optional) – a model to lazily get data from
- class spinetoolbox.spine_db_editor.widgets.custom_qwidgets.OpenFileButton(file_path, db_editor)[source]¶
Bases:
PySide2.QtWidgets.QToolButton
A button to open files or show them in the folder.
- class spinetoolbox.spine_db_editor.widgets.custom_qwidgets.OpenSQLiteFileButton(file_path, db_editor)[source]¶
Bases:
OpenFileButton
A button to open sqlite files, show them in the folder, or add them to the project.
spinetoolbox.spine_db_editor.widgets.db_session_history_dialog
¶Classes to show db session history
- author
Marin (KTH)
- date
5.2.2020
Initialize class |
- class spinetoolbox.spine_db_editor.widgets.db_session_history_dialog.DBSessionHistoryModel(parent, db_mngr, *db_maps)[source]¶
Bases:
PySide2.QtGui.QStandardItemModel
spinetoolbox.spine_db_editor.widgets.edit_or_remove_items_dialogs
¶Classes for custom QDialogs to edit items in databases.
- author
Marin (KTH)
- date
13.5.2018
A dialog with a CopyPasteTableView and a QDialogButtonBox. Base class for all |
|
A dialog to query user’s preferences for updating object classes. |
|
A dialog to query user’s preferences for updating objects. |
|
A dialog to query user’s preferences for updating relationship classes. |
|
A dialog to query user’s preferences for updating relationships. |
|
A dialog to query user’s preferences for removing tree items. |
- class spinetoolbox.spine_db_editor.widgets.edit_or_remove_items_dialogs.EditOrRemoveItemsDialog(parent, db_mngr)[source]¶
Bases:
spinetoolbox.spine_db_editor.widgets.manage_items_dialogs.ManageItemsDialog
A dialog with a CopyPasteTableView and a QDialogButtonBox. Base class for all dialogs to query user’s preferences for adding/editing/managing data items.
Init class.
- Parameters
parent (SpineDBEditor) – data store widget
db_mngr (SpineDBManager) –
- class spinetoolbox.spine_db_editor.widgets.edit_or_remove_items_dialogs.EditObjectClassesDialog(parent, db_mngr, selected)[source]¶
Bases:
spinetoolbox.spine_db_editor.widgets.manage_items_dialogs.ShowIconColorEditorMixin
,EditOrRemoveItemsDialog
A dialog to query user’s preferences for updating object classes.
Init class.
- Parameters
parent (SpineDBEditor) – data store widget
db_mngr (SpineDBManager) – the manager to do the update
selected (set) – set of ObjectClassItem instances to edit
- class spinetoolbox.spine_db_editor.widgets.edit_or_remove_items_dialogs.EditObjectsDialog(parent, db_mngr, selected)[source]¶
Bases:
EditOrRemoveItemsDialog
A dialog to query user’s preferences for updating objects.
Init class.
- Parameters
parent (SpineDBEditor) – data store widget
db_mngr (SpineDBManager) – the manager to do the update
selected (set) – set of ObjectItem instances to edit
- class spinetoolbox.spine_db_editor.widgets.edit_or_remove_items_dialogs.EditRelationshipClassesDialog(parent, db_mngr, selected)[source]¶
Bases:
EditOrRemoveItemsDialog
A dialog to query user’s preferences for updating relationship classes.
Init class.
- Parameters
parent (SpineDBEditor) – data store widget
db_mngr (SpineDBManager) – the manager to do the update
selected (set) – set of RelationshipClassItem instances to edit
- class spinetoolbox.spine_db_editor.widgets.edit_or_remove_items_dialogs.EditRelationshipsDialog(parent, db_mngr, selected, class_key)[source]¶
Bases:
spinetoolbox.spine_db_editor.widgets.manage_items_dialogs.GetRelationshipClassesMixin
,spinetoolbox.spine_db_editor.widgets.manage_items_dialogs.GetObjectsMixin
,EditOrRemoveItemsDialog
A dialog to query user’s preferences for updating relationships.
Init class.
- Parameters
parent (SpineDBEditor) – data store widget
db_mngr (SpineDBManager) – the manager to do the update
selected (set) – set of RelationshipItem instances to edit
class_key (tuple) – (class_name, object_class_name_list) for identifying the relationship_class
- class spinetoolbox.spine_db_editor.widgets.edit_or_remove_items_dialogs.RemoveEntitiesDialog(parent, db_mngr, selected)[source]¶
Bases:
EditOrRemoveItemsDialog
A dialog to query user’s preferences for removing tree items.
Init class.
- Parameters
parent (SpineDBEditor) – data store widget
db_mngr (SpineDBManager) – the manager to do the removal
selected (dict) – maps item type (class) to instances
spinetoolbox.spine_db_editor.widgets.graph_layout_generator
¶Contains the GraphViewMixin class.
- author
Marin (KTH)
- date
26.11.2018
Computes the layout for the Entity Graph View. |
|
- class spinetoolbox.spine_db_editor.widgets.graph_layout_generator.ProgressBarWidget(layout_generator)[source]¶
Bases:
PySide2.QtWidgets.QWidget
- class spinetoolbox.spine_db_editor.widgets.graph_layout_generator.GraphLayoutGenerator(identifier, vertex_count, src_inds=(), dst_inds=(), spread=0, heavy_positions=None, iterations=12, weight_exp=- 2)[source]¶
Bases:
PySide2.QtCore.QRunnable
Computes the layout for the Entity Graph View.
spinetoolbox.spine_db_editor.widgets.graph_view_mixin
¶Contains the GraphViewMixin class.
- author
Marin (KTH)
- date
26.11.2018
Provides the graph view for the DS form. |
- class spinetoolbox.spine_db_editor.widgets.graph_view_mixin.GraphViewMixin(*args, **kwargs)[source]¶
Provides the graph view for the DS form.
- receive_objects_added(self, db_map_data)[source]¶
Runs when objects are added to the db. Adds the new objects to the graph if needed.
- Parameters
db_map_data (dict) – list of dictionary-items keyed by DiffDatabaseMapping instance.
- receive_relationships_added(self, db_map_data)[source]¶
Runs when relationships are added to the db. Adds the new relationships to the graph if needed.
- Parameters
db_map_data (dict) – list of dictionary-items keyed by DiffDatabaseMapping instance.
- receive_objects_updated(self, db_map_data)[source]¶
Runs when objects are updated in the db. Refreshes names of objects in graph.
- Parameters
db_map_data (dict) – list of dictionary-items keyed by DiffDatabaseMapping instance.
- receive_objects_removed(self, db_map_data)[source]¶
Runs when objects are removed from the db. Rebuilds graph if needed.
- Parameters
db_map_data (dict) – list of dictionary-items keyed by DiffDatabaseMapping instance.
- receive_relationships_removed(self, db_map_data)[source]¶
Runs when relationships are removed from the db. Rebuilds graph if needed.
- Parameters
db_map_data (dict) – list of dictionary-items keyed by DiffDatabaseMapping instance.
- restore_removed_entities(self, added_ids)[source]¶
Restores any entities that have been previously removed and returns their ids. This happens in the context of undo/redo.
- Parameters
added_ids (set(int)) – Set of newly added ids.
- Returns
set(int)
- hide_removed_entities(self, db_map_data)[source]¶
Hides removed entities while saving them into a list attribute. This allows entities to be restored in case the user undoes the operation.
- refresh_icons(self, db_map_data)[source]¶
Runs when entity classes are updated in the db. Refreshes icons of entities in graph.
- Parameters
db_map_data (dict) – list of dictionary-items keyed by DiffDatabaseMapping instance.
- rebuild_graph(self, selected)[source]¶
Stores the given selection of entity tree indexes and builds graph.
- build_graph(self, persistent=False)[source]¶
Builds the graph.
- Parameters
persistent (bool, optional) – If True, elements in the current graph (if any) retain their position in the new one.
- _complete_graph(self, layout_gen_id, x, y)[source]¶
- Parameters
layout_gen_id (object) –
x (list) – Horizontal coordinates
y (list) – Vertical coordinates
- _get_selected_entity_ids(self)[source]¶
Returns a set of ids corresponding to selected entities in the trees.
- Returns
selected object ids set: selected relationship ids
- Return type
set
- _make_layout_generator(self)[source]¶
Returns a layout generator for the current graph.
- Returns
GraphLayoutGenerator
- _make_new_items(self, x, y)[source]¶
Returns new items for the graph.
- Parameters
x (list) –
y (list) –
- start_relationship(self, relationship_class, obj_item)[source]¶
Starts a relationship from the given object item.
- Parameters
relationship_class (dict) –
obj_item (.graphics_items.ObjectItem) –
spinetoolbox.spine_db_editor.widgets.manage_items_dialogs
¶Classes for custom QDialogs to add edit and remove database items.
- author
Marin (KTH)
- date
13.5.2018
Init class. |
|
A dialog with a CopyPasteTableView and a QDialogButtonBox. Base class for all |
|
Provides a method to retrieve object classes for AddObjectsDialog and AddRelationshipClassesDialog. |
|
Provides a method to retrieve objects for AddRelationshipsDialog and EditRelationshipsDialog. |
|
Provides a method to retrieve relationships for AddRelationshipsDialog and EditRelationshipsDialog. |
|
Provides methods to show an IconColorEditor upon request. |
- class spinetoolbox.spine_db_editor.widgets.manage_items_dialogs.ManageItemsDialogBase(parent, db_mngr)[source]¶
Bases:
PySide2.QtWidgets.QDialog
Init class.
- Parameters
parent (SpineDBEditor) – data store widget
db_mngr (SpineDBManager) –
- class spinetoolbox.spine_db_editor.widgets.manage_items_dialogs.ManageItemsDialog(parent, db_mngr)[source]¶
Bases:
ManageItemsDialogBase
A dialog with a CopyPasteTableView and a QDialogButtonBox. Base class for all dialogs to query user’s preferences for adding/editing/managing data items.
Init class.
- Parameters
parent (SpineDBEditor) – data store widget
db_mngr (SpineDBManager) –
- class spinetoolbox.spine_db_editor.widgets.manage_items_dialogs.GetObjectClassesMixin[source]¶
Provides a method to retrieve object classes for AddObjectsDialog and AddRelationshipClassesDialog.
- class spinetoolbox.spine_db_editor.widgets.manage_items_dialogs.GetObjectsMixin[source]¶
Provides a method to retrieve objects for AddRelationshipsDialog and EditRelationshipsDialog.
spinetoolbox.spine_db_editor.widgets.mass_select_items_dialogs
¶Classes for custom QDialogs to add edit and remove database items.
- author
Marin (KTH)
- date
13.5.2018
A dialog to query a selection of dbs and items from the user. |
|
A dialog to query user’s preferences for mass removing db items. |
|
A dialog to let users chose items for JSON export. |
- class spinetoolbox.spine_db_editor.widgets.mass_select_items_dialogs.MassSelectItemsDialog(parent, db_mngr, *db_maps)[source]¶
Bases:
PySide2.QtWidgets.QDialog
A dialog to query a selection of dbs and items from the user.
Initialize class.
- Parameters
parent (SpineDBEditor) –
db_mngr (SpineDBManager) –
db_maps (DiffDatabaseMapping) – the dbs to select items from
- class spinetoolbox.spine_db_editor.widgets.mass_select_items_dialogs.MassRemoveItemsDialog(parent, db_mngr, *db_maps)[source]¶
Bases:
MassSelectItemsDialog
A dialog to query user’s preferences for mass removing db items.
Initialize class.
- Parameters
parent (SpineDBEditor) –
db_mngr (SpineDBManager) –
db_maps (DiffDatabaseMapping) – the dbs to select items from
- class spinetoolbox.spine_db_editor.widgets.mass_select_items_dialogs.MassExportItemsDialog(parent, db_mngr, *db_maps)[source]¶
Bases:
MassSelectItemsDialog
A dialog to let users chose items for JSON export.
Initialize class.
- Parameters
parent (SpineDBEditor) –
db_mngr (SpineDBManager) –
db_maps (DiffDatabaseMapping) – the dbs to select items from
spinetoolbox.spine_db_editor.widgets.multi_spine_db_editor
¶Contains the MultiSpineDBEditor class.
- author
Marin (KTH)
- date
12.12.2020
- class spinetoolbox.spine_db_editor.widgets.multi_spine_db_editor.MultiSpineDBEditor(db_mngr, db_url_codenames=None)[source]¶
Bases:
spinetoolbox.widgets.multi_tab_window.MultiTabWindow
- _insert_statusbar_button(self, button)[source]¶
Inserts given button to the ‘beginning’ of the status bar and decorates it with a shooting label.
- Parameters
button (OpenFileButton) –
spinetoolbox.spine_db_editor.widgets.object_name_list_editor
¶Contains the ObjectNameListEditor class.
- author
Marin (KTH)
- date
27.11.2019
A custom delegate to use with ObjectNameListEditor. |
|
A dialog to select the object name list for a relationship using Google-like search bars. |
- class spinetoolbox.spine_db_editor.widgets.object_name_list_editor.SearchBarDelegate[source]¶
Bases:
PySide2.QtWidgets.QItemDelegate
A custom delegate to use with ObjectNameListEditor.
- class spinetoolbox.spine_db_editor.widgets.object_name_list_editor.ObjectNameListEditor(parent, index, object_class_names, object_names_lists, current_object_names)[source]¶
Bases:
spinetoolbox.spine_db_editor.widgets.manage_items_dialogs.ManageItemsDialog
A dialog to select the object name list for a relationship using Google-like search bars.
Initializes widget.
- Parameters
parent (SpineDBEditor) –
index (QModelIndex) –
object_class_names (list) – string object_class names
object_names_lists (list) – lists of string object names
current_object_names (list) –
spinetoolbox.spine_db_editor.widgets.parameter_view_mixin
¶Contains the ParameterViewMixin class.
- author
Marin (KTH)
- date
26.11.2018
Provides stacked parameter tables for the Spine db editor. |
- class spinetoolbox.spine_db_editor.widgets.parameter_view_mixin.ParameterViewMixin(*args, **kwargs)[source]¶
Provides stacked parameter tables for the Spine db editor.
- set_parameter_data(self, index, new_value)[source]¶
Updates (object or relationship) parameter_definition or value with newly edited data.
- show_object_name_list_editor(self, index, rel_cls_id, db_map)[source]¶
Shows the object names list editor.
- Parameters
index (QModelIndex) –
rel_cls_id (int) –
db_map (DiffDatabaseMapping) –
- set_default_parameter_data(self, index=None)[source]¶
Sets default rows for parameter models according to given index.
- Parameters
index (QModelIndex) – and index of the object or relationship tree
- _get_filter_class_ids(self)[source]¶
Returns filter class ids by combining filter class ids from entity tree and parameter_tag toolbar.
- Returns
mapping db maps to sets of ids, or None if no filter (none shall pass)
- Return type
dict, NoneType
- _handle_graph_selection_changed(self, selected_items)[source]¶
Resets filter according to graph selection.
- _handle_object_tree_selection_changed(self, selected_indexes)[source]¶
Resets filter according to object tree selection.
- _handle_relationship_tree_selection_changed(self, selected_indexes)[source]¶
Resets filter according to relationship tree selection.
- _handle_alternative_selection_changed(self, selected_db_map_alt_ids)[source]¶
Resets filter according to selection in alternative tree view.
- _handle_tag_selection_changed(self, selected_db_map_tag_ids)[source]¶
Resets filter according to selection in parameter_tag tree view.
spinetoolbox.spine_db_editor.widgets.pivot_table_header_view
¶Contains custom QHeaderView for the pivot table.
- author
Marin (KTH)
- date
2.12.2019
spinetoolbox.spine_db_editor.widgets.select_position_parameters_dialog
¶Classes for custom QDialogs to add items to databases.
- author
Marin (KTH)
- date
13.5.2018
A delegate for the database name. |
- class spinetoolbox.spine_db_editor.widgets.select_position_parameters_dialog.SelectPositionParametersDialog(parent)[source]¶
Bases:
PySide2.QtWidgets.QDialog
- class spinetoolbox.spine_db_editor.widgets.select_position_parameters_dialog.ParameterNameDelegate(parent, db_mngr, *db_maps)[source]¶
Bases:
PySide2.QtWidgets.QStyledItemDelegate
A delegate for the database name.
spinetoolbox.spine_db_editor.widgets.spine_db_editor
¶Contains the SpineDBEditor class.
- author
Marin (KTH)
- date
26.11.2018
Base class for SpineDBEditor (i.e. Spine database editor). |
|
A widget to visualize Spine dbs. |
- class spinetoolbox.spine_db_editor.widgets.spine_db_editor.SpineDBEditorBase(db_mngr)[source]¶
Bases:
PySide2.QtWidgets.QMainWindow
Base class for SpineDBEditor (i.e. Spine database editor).
Initializes form.
- Parameters
db_mngr (SpineDBManager) – The manager to use
Returns a menu with all dock toggle/view actions. Called by
self.add_main_menu()
.- Returns
QMenu
Adds a menu with main actions to toolbar.
- add_message(self, msg)[source]¶
Pushes message to notification stack.
- Parameters
msg (str) – String to show in the notification
- add_link_msg(self, msg, open_link=None)[source]¶
Pushes link message to notification stack.
- Parameters
msg (str) – String to show in notification
- refresh_copy_paste_actions(self)[source]¶
Runs when menus are about to show. Enables or disables actions according to selection status.
- show_mass_export_items_dialog(self, checked=False)[source]¶
Shows dialog for user to select dbs and items for export.
- export_session(self, checked=False)[source]¶
Exports changes made in the current session as reported by DiffDatabaseMapping.
- export_data(self, db_map_ids_for_export)[source]¶
Exports data from given dictionary into a file.
- Parameters
db_map_ids_for_export – Dictionary mapping db maps to keyword arguments for spinedb_api.export_data
- show_parameter_value_editor(self, index)[source]¶
Shows the parameter_value editor for the given index of given table view.
- log_changes(self, action, item_type, db_map_data)[source]¶
Enables or disables actions and informs the user about what just happened.
- class spinetoolbox.spine_db_editor.widgets.spine_db_editor.SpineDBEditor(db_mngr, db_url_codenames=None)[source]¶
Bases:
spinetoolbox.spine_db_editor.widgets.tabular_view_mixin.TabularViewMixin
,spinetoolbox.spine_db_editor.widgets.graph_view_mixin.GraphViewMixin
,spinetoolbox.spine_db_editor.widgets.parameter_view_mixin.ParameterViewMixin
,spinetoolbox.spine_db_editor.widgets.tree_view_mixin.TreeViewMixin
,SpineDBEditorBase
A widget to visualize Spine dbs.
Initializes everything.
- Parameters
db_mngr (SpineDBManager) – The manager to use
- tabify_and_raise(self, docks)[source]¶
Tabifies docks in given list, then raises the first.
- Parameters
docks (list) –
- restore_dock_widgets(self)[source]¶
Docks all floating and or hidden QDockWidgets back to the window.
- apply_stacked_style(self, checked=False)[source]¶
Applies the stacked style, inspired in the former tree view.
- apply_pivot_style(self, _action)[source]¶
Applies the pivot style, inspired in the former tabular view.
spinetoolbox.spine_db_editor.widgets.tabular_view_header_widget
¶Contains TabularViewHeaderWidget class.
- authors
Vennström (VTT), M. Marin (KTH)
- date
2.12.2019
A draggable QWidget. |
- class spinetoolbox.spine_db_editor.widgets.tabular_view_header_widget.TabularViewHeaderWidget(identifier, area, menu=None, parent=None)[source]¶
Bases:
PySide2.QtWidgets.QFrame
A draggable QWidget.
- Parameters
identifier (str) –
area (str) – either “rows”, “columns”, or “frozen”
menu (FilterMenu, optional) –
parent (QWidget, optional) – Parent widget
spinetoolbox.spine_db_editor.widgets.tabular_view_mixin
¶Contains TabularViewMixin class.
- author
Vennström (VTT)
- date
1.11.2018
Provides the pivot table and its frozen table for the DS form. |
- class spinetoolbox.spine_db_editor.widgets.tabular_view_mixin.TabularViewMixin(*args, **kwargs)[source]¶
Provides the pivot table and its frozen table for the DS form.
- static _is_class_index(index)[source]¶
Returns whether or not the given tree index is a class index.
- Parameters
index (QModelIndex) – index from object or relationship tree
- Returns
bool
- _get_db_map_entities(self)[source]¶
Returns a dict mapping db maps to a list of dict entity items in the current class.
- Returns
dict
- load_empty_relationship_data(self, db_map_class_objects=None)[source]¶
Returns a dict containing all possible relationships in the current class.
- Parameters
db_map_class_objects (dict) –
- Returns
Key is db_map-object_id tuple, value is None.
- Return type
dict
- load_full_relationship_data(self, db_map_relationships=None, action='add')[source]¶
Returns a dict of relationships in the current class.
- Parameters
db_map_relationships (dict) –
- Returns
Key is db_map-object id tuple, value is relationship id.
- Return type
dict
- load_relationship_data(self)[source]¶
Returns a dict that merges empty and full relationship data.
- Returns
Key is object id tuple, value is True if a relationship exists, False otherwise.
- Return type
dict
- load_scenario_alternative_data(self, db_map_scenarios=None, db_map_alternatives=None)[source]¶
Returns a dict containing all scenario alternatives.
- Returns
Key is db_map-id tuple, value is None or rank.
- Return type
dict
- _get_parameter_value_or_def_ids(self, item_type)[source]¶
Returns a dict mapping db maps to a list of integer parameter (value or def) ids from the current class.
- Parameters
item_type (str) – either “parameter_value” or “parameter_definition”
- Returns
dict
- _get_db_map_parameter_values_or_defs(self, item_type)[source]¶
Returns a dict mapping db maps to list of dict parameter (value or def) items from the current class.
- Parameters
item_type (str) – either “parameter_value” or “parameter_definition”
- Returns
dict
- load_empty_parameter_value_data(self, db_map_entities=None, db_map_parameter_ids=None, db_map_alternative_ids=None)[source]¶
Returns a dict containing all possible combinations of entities and parameters for the current class in all db_maps.
- Parameters
db_map_entities (dict, optional) – if given, only load data for these db maps and entities
db_map_parameter_ids (dict, optional) – if given, only load data for these db maps and parameter definitions
db_map_alternative_ids (dict, optional) – if given, only load data for these db maps and alternatives
- Returns
Key is a tuple object_id, …, parameter_id, value is None.
- Return type
dict
- load_full_parameter_value_data(self, db_map_parameter_values=None, action='add')[source]¶
Returns a dict of parameter values for the current class.
- Parameters
db_map_parameter_values (list, optional) –
action (str) –
- Returns
Key is a tuple object_id, …, parameter_id, value is the parameter_value.
- Return type
dict
- load_empty_expanded_parameter_value_data(self, db_map_entities=None, db_map_parameter_ids=None, db_map_alternative_ids=None)[source]¶
Makes a dict of expanded parameter values for the current class.
- Parameters
db_map_parameter_values (list, optional) –
action (str) –
- Returns
mapping from unique value id tuple to value tuple
- Return type
dict
- load_full_expanded_parameter_value_data(self, db_map_parameter_values=None, action='add')[source]¶
Makes a dict of expanded parameter values for the current class.
- Parameters
db_map_parameter_values (list, optional) –
action (str) –
- Returns
mapping from unique value id tuple to value tuple
- Return type
dict
- load_parameter_value_data(self)[source]¶
Returns a dict that merges empty and full parameter_value data.
- Returns
Key is a tuple object_id, …, parameter_id, value is the parameter_value or None if not specified.
- Return type
dict
- load_expanded_parameter_value_data(self)[source]¶
Returns all permutations of entities as well as parameter indexes and values for the current class.
- Returns
Key is a tuple object_id, …, index, while value is None.
- Return type
dict
- get_pivot_preferences(self)[source]¶
Returns saved pivot preferences.
- Returns
pivot tuple, or None if no preference stored
- Return type
tuple, NoneType
- reload_pivot_table(self, current_index=None)[source]¶
Updates current class (type and id) and reloads pivot table for it.
- make_pivot_headers(self)[source]¶
Turns top left indexes in the pivot table into TabularViewHeaderWidget.
- make_frozen_headers(self)[source]¶
Turns indexes in the first row of the frozen table into TabularViewHeaderWidget.
Returns a filter menu for given given object_class identifier.
- Parameters
identifier (int) –
- Returns
TabularViewFilterMenu
- create_header_widget(self, identifier, area, with_menu=True)[source]¶
Returns a TabularViewHeaderWidget for given object_class identifier.
- Parameters
identifier (str) –
area (str) –
with_menu (bool) –
- Returns
TabularViewHeaderWidget
- static _get_insert_index(pivot_list, catcher, position)[source]¶
Returns an index for inserting a new element in the given pivot list.
- Returns
int
- handle_header_dropped(self, dropped, catcher, position='')[source]¶
Updates pivots when a header is dropped.
- Parameters
dropped (TabularViewHeaderWidget) –
catcher (TabularViewHeaderWidget, PivotTableHeaderView, FrozenTableView) –
position (str) – either “before”, “after”, or “”
- get_frozen_value(self, index)[source]¶
Returns the value in the frozen table corresponding to the given index.
- Parameters
index (QModelIndex) –
- Returns
tuple
- change_frozen_value(self, current, previous)[source]¶
Sets the frozen value from selection in frozen table.
- reload_frozen_table(self)[source]¶
Resets the frozen model according to new selection in entity trees.
- find_frozen_values(self, frozen)[source]¶
Returns a list of tuples containing unique values (object ids) for the frozen indexes (object_class ids).
- Parameters
frozen (tuple(int)) – A tuple of currently frozen indexes
- Returns
list(tuple(list(int)))
- receive_parameter_definitions_added(self, db_map_data)[source]¶
Reacts to parameter definitions added event.
- receive_relationship_classes_updated(self, db_map_data)[source]¶
Reacts to relationship classes updated event.
- receive_parameter_values_updated(self, db_map_data)[source]¶
Reacts to parameter values added event.
- receive_parameter_definitions_updated(self, db_map_data)[source]¶
Reacts to parameter definitions updated event.
- receive_relationship_classes_removed(self, db_map_data)[source]¶
Reacts to relationship classes remove event.
- receive_parameter_definitions_removed(self, db_map_data)[source]¶
Reacts to parameter definitions removed event.
spinetoolbox.spine_db_editor.widgets.tree_view_mixin
¶Contains the TreeViewMixin class.
- author
Marin (KTH)
- date
26.11.2018
Provides object and relationship trees for the Spine db editor. |
- class spinetoolbox.spine_db_editor.widgets.tree_view_mixin.TreeViewMixin(*args, **kwargs)[source]¶
Provides object and relationship trees for the Spine db editor.
- _relationship_classes_fetched[source]¶
Emitted from fetcher thread, connected to Slots in GUI thread.
- _handle_object_tree_selection_changed(self, selected, deselected)[source]¶
Updates object filter and sets default rows.
- _handle_relationship_tree_selection_changed(self, selected, deselected)[source]¶
Updates relationship filter and sets default rows.
- static _clear_tree_selections_silently(tree_view)[source]¶
Clears the selections on a given abstract item view without emitting any signals.
- static _db_map_items(indexes)[source]¶
Groups items from given tree indexes by db map.
- Returns
lists of dictionary items keyed by DiffDatabaseMapping
- Return type
dict
- export_selected(self, selected_indexes)[source]¶
Exports data from given indexes in the entity tree.
- duplicate_object(self, index)[source]¶
Duplicates the object at the given object tree model index.
- Parameters
index (QModelIndex) –
- show_add_relationship_classes_form(self, checked=False, object_class_one_name=None)[source]¶
Shows dialog to add new relationship_class.
- show_add_relationships_form(self, checked=False, relationship_class_key=None, object_names_by_class_name=None)[source]¶
Shows dialog to add new relationships.
- show_remove_alternative_tree_items_form(self)[source]¶
Shows form to remove items from object treeview.
- show_remove_entity_tree_items_form(self, selected_indexes)[source]¶
Shows form to remove items from object treeview.
spinetoolbox.spine_db_editor.widgets.url_toolbar
¶Contains the UrlToolBar class and helpers.
- author
Marin (KTH)
- date
13.5.2020
Submodules¶
spinetoolbox.spine_db_editor.graphics_items
¶Classes for drawing graphics items on graph view’s QGraphicsScene.
- authors
Marin (KTH), P. Savolainen (VTT)
- date
4.4.2018
Base class for ObjectItem and RelationshipItem. |
|
Represents a relationship in the Entity graph. |
|
Represents an object in the Entity graph. |
|
Connects a RelationshipItem to an ObjectItem. |
|
Creates new relationships directly in the graph. |
|
Represents the relationship that’s being created using the CrossHairsItem. |
|
Connects a CrossHairsRelationshipItem with the CrossHairsItem, |
|
Provides a label for ObjectItem’s. |
|
Creates a FigureCanvas and adds it to the given scene. |
- spinetoolbox.spine_db_editor.graphics_items.make_figure_graphics_item(scene, z=0, static=True)[source]¶
Creates a FigureCanvas and adds it to the given scene. Used for creating heatmaps and associated colorbars.
- Parameters
scene (QGraphicsScene) –
z (int, optional) – z value. Defaults to 0.
static (bool, optional) – if True (the default) the figure canvas is not movable
- Returns
the graphics item that represents the canvas Figure: the figure in the canvas
- Return type
QGraphicsProxyWidget
- class spinetoolbox.spine_db_editor.graphics_items.EntityItem(spine_db_editor, x, y, extent, db_map_entity_id)[source]¶
Bases:
PySide2.QtWidgets.QGraphicsRectItem
Base class for ObjectItem and RelationshipItem.
- Parameters
spine_db_editor (SpineDBEditor) – ‘owner’
x (float) – x-coordinate of central point
y (float) – y-coordinate of central point
extent (int) – Preferred extent
db_map_entity_id (tuple) – db_map, entity id
- shape(self)[source]¶
Returns a shape containing the entire bounding rect, to work better with icon transparency.
- add_arc_item(self, arc_item)[source]¶
Adds an item to the list of arcs.
- Parameters
arc_item (ArcItem) –
- apply_rotation(self, angle, center)[source]¶
Applies rotation.
- Parameters
angle (float) – The angle in degrees.
center (QPointF) – Rotates around this point.
- mouseMoveEvent(self, event)[source]¶
Moves the item and all connected arcs.
- Parameters
event (QGraphicsSceneMouseEvent) –
- itemChange(self, change, value)[source]¶
Keeps track of item’s movements on the scene.
- Parameters
change (GraphicsItemChange) – a flag signalling the type of the change
value – a value related to the change
- Returns
the same value given as input
- set_all_visible(self, on)[source]¶
Sets visibility status for this item and all arc items.
- Parameters
on (bool) –
- class spinetoolbox.spine_db_editor.graphics_items.RelationshipItem(spine_db_editor, x, y, extent, db_map_entity_id)[source]¶
Bases:
EntityItem
Represents a relationship in the Entity graph.
Initializes the item.
- Parameters
spine_db_editor (GraphViewForm) – ‘owner’
x (float) – x-coordinate of central point
y (float) – y-coordinate of central point
extent (int) – preferred extent
db_map_entity_id (tuple) – db_map, relationship id
- class spinetoolbox.spine_db_editor.graphics_items.ObjectItem(spine_db_editor, x, y, extent, db_map_entity_id)[source]¶
Bases:
EntityItem
Represents an object in the Entity graph.
Initializes the item.
- Parameters
spine_db_editor (GraphViewForm) – ‘owner’
x (float) – x-coordinate of central point
y (float) – y-coordinate of central point
extent (int) – preferred extent
db_map_entity_id (tuple) – db_map, object id
- shape(self)[source]¶
Returns a shape containing the entire bounding rect, to work better with icon transparency.
Populates the ‘Expand’ or ‘Collapse’ menu.
- Parameters
menu (QMenu) –
Populates the ‘Add relationships’ menu.
- Parameters
menu (QMenu) –
- class spinetoolbox.spine_db_editor.graphics_items.ArcItem(rel_item, obj_item, width)[source]¶
Bases:
PySide2.QtWidgets.QGraphicsPathItem
Connects a RelationshipItem to an ObjectItem.
Initializes item.
- Parameters
rel_item (spinetoolbox.widgets.graph_view_graphics_items.RelationshipItem) – relationship item
obj_item (spinetoolbox.widgets.graph_view_graphics_items.ObjectItem) – object item
width (float) – Preferred line width
- class spinetoolbox.spine_db_editor.graphics_items.CrossHairsItem(*args, **kwargs)[source]¶
Bases:
RelationshipItem
Creates new relationships directly in the graph.
Initializes the item.
- Parameters
spine_db_editor (GraphViewForm) – ‘owner’
x (float) – x-coordinate of central point
y (float) – y-coordinate of central point
extent (int) – preferred extent
db_map_entity_id (tuple) – db_map, relationship id
- class spinetoolbox.spine_db_editor.graphics_items.CrossHairsRelationshipItem(*args, **kwargs)[source]¶
Bases:
RelationshipItem
Represents the relationship that’s being created using the CrossHairsItem.
Initializes the item.
- Parameters
spine_db_editor (GraphViewForm) – ‘owner’
x (float) – x-coordinate of central point
y (float) – y-coordinate of central point
extent (int) – preferred extent
db_map_entity_id (tuple) – db_map, relationship id
- class spinetoolbox.spine_db_editor.graphics_items.CrossHairsArcItem(rel_item, obj_item, width)[source]¶
Bases:
ArcItem
Connects a CrossHairsRelationshipItem with the CrossHairsItem, and with all the ObjectItem’s in the relationship so far.
Initializes item.
- Parameters
rel_item (spinetoolbox.widgets.graph_view_graphics_items.RelationshipItem) – relationship item
obj_item (spinetoolbox.widgets.graph_view_graphics_items.ObjectItem) – object item
width (float) – Preferred line width
spinetoolbox.widgets
¶
Init file for widgets package. Intentionally empty.
- author
Savolainen (VTT)
- date
3.1.2018
Submodules¶
spinetoolbox.widgets.about_widget
¶A widget for presenting basic information about the application.
- author
Savolainen (VTT)
- date
14.12.2017
About widget class. |
- class spinetoolbox.widgets.about_widget.AboutWidget(toolbox)[source]¶
Bases:
PySide2.QtWidgets.QWidget
About widget class.
- Parameters
toolbox (ToolboxUI) – QMainWindow instance
- calc_pos(self)[source]¶
Calculate the top-left corner position of this widget in relation to main window position and size in order to show about window in the middle of the main window.
- keyPressEvent(self, e)[source]¶
Close form when Escape, Enter, Return, or Space bar keys are pressed.
- Parameters
e (QKeyEvent) – Received key press event.
- closeEvent(self, event=None)[source]¶
Handle close window.
- Parameters
event (QEvent) – Closing event if ‘X’ is clicked.
- mousePressEvent(self, e)[source]¶
Save mouse position at the start of dragging.
- Parameters
e (QMouseEvent) – Mouse event
spinetoolbox.widgets.add_project_item_widget
¶Widget shown to user when a new Project Item is created.
- author
Savolainen (VTT)
- date
19.1.2017
A widget to query user’s preferences for a new item. |
- class spinetoolbox.widgets.add_project_item_widget.AddProjectItemWidget(toolbox, x, y, class_, spec='')[source]¶
Bases:
PySide2.QtWidgets.QWidget
A widget to query user’s preferences for a new item.
- x¶
X coordinate of new item
- Type
int
- y¶
Y coordinate of new item
- Type
int
Initialize class.
- abstract call_add_item(self)[source]¶
Creates new Item according to user’s selections.
Must be reimplemented by subclasses.
spinetoolbox.widgets.add_up_spine_opt_wizard
¶Classes for custom QDialogs for julia setup.
- author
Marin (KTH)
- date
13.5.2018
Enum where members are also (and must be) ints |
|
A wizard to install & upgrade SpineOpt. |
|
A QWizards page with a log. Useful for pages that need to capture the output of a process. |
|
A QWizards page with a log. Useful for pages that need to capture the output of a process. |
|
A QWizards page with a log. Useful for pages that need to capture the output of a process. |
|
|
- class spinetoolbox.widgets.add_up_spine_opt_wizard._PageId[source]¶
Bases:
enum.IntEnum
Enum where members are also (and must be) ints
Initialize self. See help(type(self)) for accurate signature.
- class spinetoolbox.widgets.add_up_spine_opt_wizard.AddUpSpineOptWizard(parent, julia_exe, julia_project)[source]¶
Bases:
PySide2.QtWidgets.QWizard
A wizard to install & upgrade SpineOpt.
Initialize class.
- Parameters
parent (QWidget) – the parent widget (SettingsWidget)
- class spinetoolbox.widgets.add_up_spine_opt_wizard.IntroPage(parent)[source]¶
Bases:
PySide2.QtWidgets.QWizardPage
- class spinetoolbox.widgets.add_up_spine_opt_wizard.SelectJuliaPage(parent, julia_exe, julia_project)[source]¶
Bases:
PySide2.QtWidgets.QWizardPage
- class spinetoolbox.widgets.add_up_spine_opt_wizard.CheckPreviousInstallPage(parent)[source]¶
Bases:
PySide2.QtWidgets.QWizardPage
- class spinetoolbox.widgets.add_up_spine_opt_wizard.AddUpSpineOptPage(parent)[source]¶
Bases:
spinetoolbox.widgets.custom_qwidgets.QWizardProcessPage
A QWizards page with a log. Useful for pages that need to capture the output of a process.
- class spinetoolbox.widgets.add_up_spine_opt_wizard.SuccessPage(parent)[source]¶
Bases:
PySide2.QtWidgets.QWizardPage
- class spinetoolbox.widgets.add_up_spine_opt_wizard.FailurePage(parent)[source]¶
Bases:
PySide2.QtWidgets.QWizardPage
- class spinetoolbox.widgets.add_up_spine_opt_wizard.TroubleshootProblemsPage(parent)[source]¶
Bases:
PySide2.QtWidgets.QWizardPage
- class spinetoolbox.widgets.add_up_spine_opt_wizard.TroubleshootSolutionPage(parent)[source]¶
Bases:
PySide2.QtWidgets.QWizardPage
- class spinetoolbox.widgets.add_up_spine_opt_wizard.ResetRegistryPage(parent)[source]¶
Bases:
spinetoolbox.widgets.custom_qwidgets.QWizardProcessPage
A QWizards page with a log. Useful for pages that need to capture the output of a process.
- class spinetoolbox.widgets.add_up_spine_opt_wizard.AddUpSpineOptAgainPage(parent)[source]¶
Bases:
AddUpSpineOptPage
A QWizards page with a log. Useful for pages that need to capture the output of a process.
spinetoolbox.widgets.array_editor
¶Contains an editor widget for array type parameter values.
- author
Soininen (VTT)
- date
25.3.2020
Editor widget for Arrays. |
- class spinetoolbox.widgets.array_editor.ArrayEditor(parent=None)[source]¶
Bases:
PySide2.QtWidgets.QWidget
Editor widget for Arrays.
- Parameters
parent (QWidget, optional) – parent widget
- set_value(self, value)[source]¶
Sets the parameter_value for editing in this widget.
- Parameters
value (Array) – value for editing
- _check_if_plotting_enabled(self, type_name)[source]¶
Checks is array’s data type allows the array to be plotted.
- Parameters
type_name (str) – data type’s name
- open_value_editor(self, index)[source]¶
Opens an editor widget for array element.
- Parameters
index (QModelIndex) – element’s index
Shows the table’s context menu.
- Parameters
position (QPoint) – menu’s position on the table
spinetoolbox.widgets.array_value_editor
¶An editor dialog for Array elements.
- author
Soininen (VTT)
- date
10.11.2020
Editor widget for Array elements. |
- class spinetoolbox.widgets.array_value_editor.ArrayValueEditor(index, value_type, parent=None)[source]¶
Bases:
spinetoolbox.widgets.parameter_value_editor_base.ParameterValueEditorBase
Editor widget for Array elements.
- Parameters
index (QModelIndex) – an index to a parameter_value in parent_model
parent (QWidget, optional) – a parent widget
spinetoolbox.widgets.commit_dialog
¶Classes for custom QDialogs to add edit and remove database items.
- author
Marin (KTH)
- date
13.5.2018
A dialog to query user’s preferences for new commit. |
spinetoolbox.widgets.console_window
¶Window for the ‘base’ Julia Console and Python Console.
- author
Savolainen (VTT)
- date
5.2.2021
Class for a separate window for the Python or Julia Console. |
- class spinetoolbox.widgets.console_window.ConsoleWindow(toolbox, spine_console)[source]¶
Bases:
PySide2.QtWidgets.QMainWindow
Class for a separate window for the Python or Julia Console.
- Parameters
toolbox (ToolboxUI) – QMainWindow instance
spine_console (SpineConsoleWidget) – Qt Console
spinetoolbox.widgets.custom_combobox
¶A widget for presenting basic information about the application.
- author
Savolainen (VTT)
- date
14.12.2017
Combobox with elided text. |
|
- class spinetoolbox.widgets.custom_combobox.ElidedCombobox[source]¶
Bases:
PySide2.QtWidgets.QComboBox
Combobox with elided text.
spinetoolbox.widgets.custom_delegates
¶Custom item delegates.
- author
Marin (KTH)
- date
1.9.2018
A delegate that places a fully functioning QCheckBox. |
|
A delegate that places a QCheckBox but draws a number instead of the check. |
- class spinetoolbox.widgets.custom_delegates.ComboBoxDelegate(items)[source]¶
Bases:
PySide2.QtWidgets.QStyledItemDelegate
- class spinetoolbox.widgets.custom_delegates.CheckBoxDelegate(parent, centered=True)[source]¶
Bases:
PySide2.QtWidgets.QStyledItemDelegate
A delegate that places a fully functioning QCheckBox.
- Parameters
parent (QWiget) –
centered (bool) – whether or not the checkbox should be center-aligned in the widget
- createEditor(self, parent, option, index)[source]¶
Important, otherwise an editor is created if the user clicks in this cell. ** Need to hook up a signal to the model.
- editorEvent(self, event, model, option, index)[source]¶
Change the data in the model and the state of the checkbox when user presses left mouse button and this cell is editable. Otherwise do nothing.
- class spinetoolbox.widgets.custom_delegates.RankDelegate(parent, centered=True)[source]¶
Bases:
CheckBoxDelegate
A delegate that places a QCheckBox but draws a number instead of the check.
- Parameters
parent (QWiget) –
centered (bool) – whether or not the checkbox should be center-aligned in the widget
spinetoolbox.widgets.custom_editors
¶Custom editors for model/view programming.
- author
Marin (KTH)
- date
2.9.2018
A custom QLineEdit to handle data from models. |
|
A custom QLineEdit to handle data from models. |
|
A delegate for placing a CustomLineEditor on the first row of SearchBarEditor. |
|
A Google-like search bar, implemented as a QTableView with a _CustomLineEditDelegate in the first row. |
|
A check list editor. |
|
A delegate to highlight decorations in a QListWidget. |
|
An editor to let the user select an icon and a color for an object_class. |
- class spinetoolbox.widgets.custom_editors.CustomLineEditor[source]¶
Bases:
PySide2.QtWidgets.QLineEdit
A custom QLineEdit to handle data from models.
- class spinetoolbox.widgets.custom_editors.ParameterValueLineEditor[source]¶
Bases:
CustomLineEditor
A custom QLineEdit to handle data from models.
- class spinetoolbox.widgets.custom_editors._CustomLineEditDelegate[source]¶
Bases:
PySide2.QtWidgets.QStyledItemDelegate
A delegate for placing a CustomLineEditor on the first row of SearchBarEditor.
- class spinetoolbox.widgets.custom_editors.SearchBarEditor(parent, tutor=None)[source]¶
Bases:
PySide2.QtWidgets.QTableView
A Google-like search bar, implemented as a QTableView with a _CustomLineEditDelegate in the first row.
Initializes instance.
- Parameters
parent (QWidget) – parent widget
tutor (QWidget, optional) – another widget used for positioning.
- set_data(self, current, items)[source]¶
Populates model.
- Parameters
current (str) – item that is currently selected from given items
items (Sequence(str)) – items to show in the list
- class spinetoolbox.widgets.custom_editors.CheckListEditor(parent, tutor=None, ranked=False)[source]¶
Bases:
PySide2.QtWidgets.QTableView
A check list editor.
Initialize class.
- toggle_selected(self, index)[source]¶
Adds or removes given index from selected items.
- Parameters
index (QModelIndex) – index to toggle
- class spinetoolbox.widgets.custom_editors._IconPainterDelegate[source]¶
Bases:
PySide2.QtWidgets.QStyledItemDelegate
A delegate to highlight decorations in a QListWidget.
- class spinetoolbox.widgets.custom_editors.IconColorEditor(parent)[source]¶
Bases:
PySide2.QtWidgets.QDialog
An editor to let the user select an icon and a color for an object_class.
Init class.
spinetoolbox.widgets.custom_qcombobox
¶Class for a custom QComboBox.
- author
Savolainen (VTT)
- date
16.10.2020
A custom QComboBox for showing kernels in Settings->Tools. |
spinetoolbox.widgets.custom_qgraphicsscene
¶Custom QGraphicsScene used in the Design View.
- author
Savolainen (VTT)
- date
13.2.2019
A custom QGraphicsScene. It provides signals to notify about items, |
|
A scene for the Design view. |
- class spinetoolbox.widgets.custom_qgraphicsscene.CustomGraphicsScene[source]¶
Bases:
PySide2.QtWidgets.QGraphicsScene
A custom QGraphicsScene. It provides signals to notify about items, and a method to center all items in the scene.
At the moment it’s used by DesignGraphicsScene and the GraphViewMixin
- class spinetoolbox.widgets.custom_qgraphicsscene.DesignGraphicsScene(parent, toolbox)[source]¶
Bases:
CustomGraphicsScene
A scene for the Design view.
Mainly, it handles drag and drop events of ProjectItemDragMixin sources.
- Parameters
parent (QObject) – scene’s parent object
toolbox (ToolboxUI) – reference to the main window
- mousePressEvent(self, event)[source]¶
Puts link drawer to sleep and log message if it looks like the user doesn’t know what they’re doing.
- mouseReleaseEvent(self, event)[source]¶
Makes link if drawer is released over a valid connector button.
- set_bg_color(self, color)[source]¶
Change background color when this is changed in Settings.
- Parameters
color (QColor) – Background color
- set_bg_choice(self, bg_choice)[source]¶
Set background choice when this is changed in Settings.
- Parameters
bg (str) – “grid”, “tree”, or “solid”
- dragEnterEvent(self, event)[source]¶
Accept event. Then call the super class method only if drag source is not a ProjectItemDragMixin.
- dragMoveEvent(self, event)[source]¶
Accept event. Then call the super class method only if drag source is not a ProjectItemDragMixin.
- dropEvent(self, event)[source]¶
Only accept drops when the source is an instance of ProjectItemDragMixin. Capture text from event’s mimedata and show the appropriate ‘Add Item form.’
- event(self, event)[source]¶
Accepts GraphicsSceneHelp events without doing anything, to not interfere with our usage of QToolTip.showText in graphics_items.ExclamationIcon.
spinetoolbox.widgets.custom_qgraphicsviews
¶Classes for custom QGraphicsViews for the Design and Graph views.
- authors
Savolainen (VTT), M. Marin (KTH)
- date
6.2.2018
Super class for Design and Entity QGraphicsViews. |
|
QGraphicsView for the Design View. |
- class spinetoolbox.widgets.custom_qgraphicsviews.CustomQGraphicsView(parent)[source]¶
Bases:
PySide2.QtWidgets.QGraphicsView
Super class for Design and Entity QGraphicsViews.
- parent¶
Parent widget
- Type
QWidget
Init CustomQGraphicsView.
- keyPressEvent(self, event)[source]¶
Overridden method. Enable zooming with plus and minus keys (comma resets zoom). Send event downstream to QGraphicsItems if pressed key is not handled here.
- Parameters
event (QKeyEvent) – Pressed key
- mousePressEvent(self, event)[source]¶
Set rubber band selection mode if Control pressed. Enable resetting the zoom factor from the middle mouse button.
- resizeEvent(self, event)[source]¶
Updates zoom if needed when the view is resized.
- Parameters
event (QResizeEvent) – a resize event
- setScene(self, scene)[source]¶
Sets a new scene to this view.
- Parameters
scene (ShrinkingScene) – a new scene
- _update_zoom_limits(self)[source]¶
Updates the minimum zoom limit and the zoom level with which the view fits all the items in the scene.
- _handle_zoom_time_line_advanced(self, pos)[source]¶
Performs zoom whenever the smooth zoom time line advances.
- _handle_transformation_time_line_finished(self)[source]¶
Cleans up after the smooth transformation time line finishes.
- gentle_zoom(self, factor, zoom_focus=None)[source]¶
Perform a zoom by a given factor.
- Parameters
factor (float) – a scaling factor relative to the current scene scaling
zoom_focus (QPoint) – focus of the zoom, e.g. mouse pointer position
- class spinetoolbox.widgets.custom_qgraphicsviews.DesignQGraphicsView(parent)[source]¶
Bases:
CustomQGraphicsView
QGraphicsView for the Design View.
- Parameters
parent (QWidget) – Graph View Form’s (QMainWindow) central widget (self.centralwidget)
- add_icon(self, item_name)[source]¶
Adds project item’s icon to the scene.
- Parameters
item_name (str) – project item’s name
- remove_icon(self, item_name)[source]¶
Removes project item’s icon from scene.
- Parameters
item_name (str) – name of the icon to remove
- add_link(self, src_connector, dst_connector)[source]¶
Pushes an AddLinkCommand to the toolbox undo stack.
- Parameters
src_connector (ConnectorButton) – source connector button
dst_connector (ConnectorButton) – destination connector button
- make_link(self, src_connector, dst_connector, connection=None)[source]¶
Constructs a Link between given connectors.
- Parameters
src_connector (ConnectorButton) – Source connector button
dst_connector (ConnectorButton) – Destination connector button
connection (Connection, optional) – Underlying connection
- Returns
new link
- Return type
- do_add_link(self, connection)[source]¶
Adds given connection to the Design view.
- Parameters
connection (Connection) – the connection to add
- do_replace_link(self, original_connection, new_connection)[source]¶
Replaces a link on the Design view.
- Parameters
original_connection (Connection) – connection that was replaced
new_connection (Connection) – replacing connection
- remove_links(self, links)[source]¶
Pushes a RemoveConnectionsCommand to the Toolbox undo stack.
- Parameters
links (list of Link) – links to remove
- do_remove_link(self, connection)[source]¶
Removes a link from the scene.
- Parameters
connection (Connection) – link’s connection
spinetoolbox.widgets.custom_qlineedits
¶Classes for custom line edits.
- authors
Marin (KTH), P. Savolainen (VTT)
- date
11.10.2018
A custom QLineEdit for Project Item Properties. |
|
A custom QLineEdit that accepts file drops and displays the path. |
- class spinetoolbox.widgets.custom_qlineedits.PropertyQLineEdit[source]¶
Bases:
PySide2.QtWidgets.QLineEdit
A custom QLineEdit for Project Item Properties.
- class spinetoolbox.widgets.custom_qlineedits.CustomQLineEdit[source]¶
Bases:
PropertyQLineEdit
A custom QLineEdit that accepts file drops and displays the path.
- parent¶
Parent for line edit widget
- Type
QMainWindow
spinetoolbox.widgets.custom_qtableview
¶Custom QTableView classes that support copy-paste and the like.
- author
Marin (KTH)
- date
18.5.2018
Custom QTableView class with copy and paste methods. |
|
Custom QTableView class with autofilter functionality. |
|
Custom QTableView base class with copy and paste methods for indexed parameter values. |
|
A QTableView for fixed resolution time series table. |
|
A QTableView class with for variable resolution time series and time patterns. |
|
Custom QTableView with copy and paste methods for single column tables. |
|
Custom QTableView with copy and paste methods for map tables. |
|
Returns the top left and bottom right corners of selection. |
Evaluates if given string could be a time stamp. |
- class spinetoolbox.widgets.custom_qtableview.CopyPasteTableView[source]¶
Bases:
PySide2.QtWidgets.QTableView
Custom QTableView class with copy and paste methods.
- static _read_pasted_text(text)[source]¶
Parses a tab separated CSV text table.
- Parameters
text (str) – a CSV formatted table
- Returns
a list of rows
- Return type
list
- class spinetoolbox.widgets.custom_qtableview.AutoFilterCopyPasteTableView(parent)[source]¶
Bases:
CopyPasteTableView
Custom QTableView class with autofilter functionality.
- Parameters
parent (QObject) –
- keyPressEvent(self, event)[source]¶
Shows the autofilter menu if the user presses Alt + Down.
- Parameters
event (QEvent) –
- setModel(self, model)[source]¶
Disconnects the sectionPressed signal which seems to be connected by the super method. Otherwise pressing the header just selects the column.
- Parameters
model (QAbstractItemModel) –
Called when user clicks on a horizontal section header. Shows/hides the auto filter widget.
- Parameters
logical_index (int) –
- class spinetoolbox.widgets.custom_qtableview.IndexedParameterValueTableViewBase[source]¶
Bases:
CopyPasteTableView
Custom QTableView base class with copy and paste methods for indexed parameter values.
- class spinetoolbox.widgets.custom_qtableview.TimeSeriesFixedResolutionTableView[source]¶
Bases:
IndexedParameterValueTableViewBase
A QTableView for fixed resolution time series table.
- static _read_pasted_text(text)[source]¶
Parses the given CSV table. Parsing is locale aware.
- Parameters
text (str) – a CSV table containing numbers
- Returns
A list of floats
- Return type
list of float
- _paste_to_values_column(self, values, first_row, paste_length)[source]¶
Pastes data to the Values column.
- Parameters
values (list) – a list of float values to paste
first_row (int) – index of the first row where to paste
paste_length (int) – length of the paste selection (can be different from len(values))
- Returns
A tuple (list(pasted indexes), list(pasted values))
- Return type
tuple
- class spinetoolbox.widgets.custom_qtableview.IndexedValueTableView[source]¶
Bases:
IndexedParameterValueTableViewBase
A QTableView class with for variable resolution time series and time patterns.
- _paste_two_columns(self, data_indexes, data_values, first_row, paste_length)[source]¶
Pastes data indexes and values.
- Parameters
data_indexes (list) – a list of data indexes (time stamps/durations)
data_values (list) – a list of data values
first_row (int) – first row index
paste_length (int) – selection length for pasting
- Returns
a tuple (modified model indexes, modified model values)
- Return type
tuple
- _paste_single_column(self, values, first_row, first_column, paste_length)[source]¶
Pastes a single column of data.
- Parameters
values (list) – a list of data to paste (data indexes or values)
first_row (int) – first row index
paste_length (int) – selection length for pasting
- Returns
a tuple (modified model indexes, modified model values)
- Return type
tuple
- class spinetoolbox.widgets.custom_qtableview.ArrayTableView[source]¶
Bases:
IndexedParameterValueTableViewBase
Custom QTableView with copy and paste methods for single column tables.
- class spinetoolbox.widgets.custom_qtableview.MapTableView[source]¶
Bases:
CopyPasteTableView
Custom QTableView with copy and paste methods for map tables.
- spinetoolbox.widgets.custom_qtableview._range(selection)[source]¶
Returns the top left and bottom right corners of selection.
- Parameters
selection (QItemSelection) – a list of selected QItemSelection objects
- Returns
a tuple (top row, bottom row, left column, right column)
- Return type
tuple of ints
- spinetoolbox.widgets.custom_qtableview._could_be_time_stamp(s)[source]¶
Evaluates if given string could be a time stamp.
This is to deal with special cases that are not intended as time stamps but could end up as one by the very greedy
DateTime
constructor.- Parameters
s (str) – string to evaluate
- Returns
True if s could be a time stamp, False otherwise
- Return type
bool
spinetoolbox.widgets.custom_qtextbrowser
¶Class for a custom QTextBrowser for showing the logs and tool output.
- author
Savolainen (VTT)
- date
6.2.2018
|
|
Custom QTextBrowser class. |
|
Custom QTextBrowser class. |
- class spinetoolbox.widgets.custom_qtextbrowser.SignedTextDocument(owner=None)[source]¶
Bases:
PySide2.QtGui.QTextDocument
- Parameters
owner (ProjectItem, optional) – The item that owns the document.
- class spinetoolbox.widgets.custom_qtextbrowser.CustomQTextBrowser(parent)[source]¶
Bases:
PySide2.QtWidgets.QTextBrowser
Custom QTextBrowser class.
- Parameters
parent (QWidget) – Parent widget
- set_override_document(self, document)[source]¶
Sets the given document as the current document.
- Parameters
document (QTextDocument) –
- append(self, text)[source]¶
Appends new text block to the end of the original document.
If the document contains more text blocks after the addition than a set limit, blocks are deleted at the start of the contents.
- Parameters
text (str) – text to add
- class spinetoolbox.widgets.custom_qtextbrowser.MonoSpaceFontTextBrowser(parent)[source]¶
Bases:
CustomQTextBrowser
Custom QTextBrowser class.
- Parameters
parent (QWidget) – Parent widget
spinetoolbox.widgets.custom_qtreeview
¶Classes for custom QTreeView.
- author
Marin (KTH)
- date
25.4.2018
Custom QTreeView class with copy support. |
|
Custom QTreeView class for ‘Sources’ in Tool specification editor widget. |
|
Custom QTreeView class for Tool specification editor form to enable keyPressEvent. |
- class spinetoolbox.widgets.custom_qtreeview.CopyTreeView(parent)[source]¶
Bases:
PySide2.QtWidgets.QTreeView
Custom QTreeView class with copy support.
Initialize the view.
- class spinetoolbox.widgets.custom_qtreeview.SourcesTreeView(parent)[source]¶
Bases:
PySide2.QtWidgets.QTreeView
Custom QTreeView class for ‘Sources’ in Tool specification editor widget.
- parent¶
The parent of this view
- Type
QWidget
Initialize the view.
spinetoolbox.widgets.custom_qwidgets
¶Custom QWidgets for Filtering and Zooming.
- author
Vennström (VTT)
- date
4.12.2018
Filter widget class. |
|
Filter widget class. |
|
A QWidgetAction with custom hovering. |
|
An action with a tool bar. |
|
A toolbar on the right, with enough space to print a text beneath. |
|
A toolbar on the right, with enough space to print a text beneath. |
|
A menu item with a toolbar on the right. |
|
A custom tool bar for |
|
A titled separator. |
|
A QLabel that always wraps text. |
|
A QLabel that supports hyperlinks. |
|
A QWizards page with a log. Useful for pages that need to capture the output of a process. |
|
A read only QLabel with a QToolButton that copies the text to clipboard. |
- class spinetoolbox.widgets.custom_qwidgets.FilterWidgetBase(parent)[source]¶
Bases:
PySide2.QtWidgets.QWidget
Filter widget class.
Init class.
- Parameters
parent (QWidget) –
- class spinetoolbox.widgets.custom_qwidgets.SimpleFilterWidget(parent, show_empty=True)[source]¶
Bases:
FilterWidgetBase
Filter widget class.
Init class.
- Parameters
parent (QWidget) –
- class spinetoolbox.widgets.custom_qwidgets.CustomWidgetAction(parent=None)[source]¶
Bases:
PySide2.QtWidgets.QWidgetAction
A QWidgetAction with custom hovering.
Class constructor.
- Parameters
parent (QMenu) – the widget’s parent
- class spinetoolbox.widgets.custom_qwidgets.ToolBarWidgetAction(text, parent=None, compact=False)[source]¶
Bases:
CustomWidgetAction
An action with a tool bar.
- tool_bar¶
- Type
QToolBar
Class constructor.
- Parameters
parent (QMenu) – the widget’s parent
- class spinetoolbox.widgets.custom_qwidgets.ToolBarWidgetBase(text, parent=None)[source]¶
Bases:
PySide2.QtWidgets.QWidget
A toolbar on the right, with enough space to print a text beneath.
- tool_bar¶
- Type
QToolBar
Class constructor.
- Parameters
text (str) –
parent (QWidget) – the widget’s parent
- class spinetoolbox.widgets.custom_qwidgets.ToolBarWidget(text, parent=None)[source]¶
Bases:
ToolBarWidgetBase
A toolbar on the right, with enough space to print a text beneath.
- tool_bar¶
- Type
QToolBar
Class constructor.
- Parameters
text (str) –
parent (QWidget) – the widget’s parent
- class spinetoolbox.widgets.custom_qwidgets.MenuItemToolBarWidget(text, parent=None, compact=False)[source]¶
Bases:
ToolBarWidgetBase
A menu item with a toolbar on the right.
- tool_bar¶
- Type
QToolBar
Class constructor.
- Parameters
text (str) –
parent (QWidget) – the widget’s parent
compact (bool) – if True, the widget uses the minimal space
- class spinetoolbox.widgets.custom_qwidgets._MenuToolBar[source]¶
Bases:
PySide2.QtWidgets.QToolBar
A custom tool bar for
MenuItemToolBarWidget
.- _setup_action_button(self, action)[source]¶
- Customizes the QToolButton associated with given action:
Makes sure that the text honors the action’s mnemonics.
Installs this as event filter on the button (see
self.eventFilter()
).
Must be called everytime an action is added to the tool bar.
- Parameters
QAction –
- actionEvent(self, ev)[source]¶
Updates
self._enabled
: True if at least one non-separator action is enabled, False otherwise. Emitsself.enabled_changed
accordingly.
- class spinetoolbox.widgets.custom_qwidgets.TitleWidgetAction(title, parent=None)[source]¶
Bases:
CustomWidgetAction
A titled separator.
Class constructor.
- Parameters
parent (QMenu) – the widget’s parent
- class spinetoolbox.widgets.custom_qwidgets.WrapLabel(text='', parent=None)[source]¶
Bases:
PySide2.QtWidgets.QLabel
A QLabel that always wraps text.
- class spinetoolbox.widgets.custom_qwidgets.HyperTextLabel(text='', parent=None)[source]¶
Bases:
WrapLabel
A QLabel that supports hyperlinks.
- class spinetoolbox.widgets.custom_qwidgets.QWizardProcessPage(parent)[source]¶
Bases:
PySide2.QtWidgets.QWizardPage
A QWizards page with a log. Useful for pages that need to capture the output of a process.
spinetoolbox.widgets.datetime_editor
¶An editor widget for editing datetime database (relationship) parameter values.
- author
Soininen (VTT)
- date
28.6.2019
An editor widget for DateTime type parameter values. |
Converts a QDateTime object to Python’s datetime.datetime type. |
|
Converts Python’s datetime.datetime object to QDateTime. |
- spinetoolbox.widgets.datetime_editor._QDateTime_to_datetime(dt)[source]¶
Converts a QDateTime object to Python’s datetime.datetime type.
- spinetoolbox.widgets.datetime_editor._datetime_to_QDateTime(dt)[source]¶
Converts Python’s datetime.datetime object to QDateTime.
spinetoolbox.widgets.duration_editor
¶An editor widget for editing duration database (relationship) parameter values.
- author
Soininen (VTT)
- date
28.6.2019
An editor widget for Duration type parameter values. |
spinetoolbox.widgets.install_julia_wizard
¶Classes for custom QDialogs for julia setup.
- author
Marin (KTH)
- date
13.5.2018
Enum where members are also (and must be) ints |
|
A wizard to install julia |
|
A QWizards page with a log. Useful for pages that need to capture the output of a process. |
|
- class spinetoolbox.widgets.install_julia_wizard._PageId[source]¶
Bases:
enum.IntEnum
Enum where members are also (and must be) ints
Initialize self. See help(type(self)) for accurate signature.
- class spinetoolbox.widgets.install_julia_wizard.InstallJuliaWizard(parent)[source]¶
Bases:
PySide2.QtWidgets.QWizard
A wizard to install julia
Initialize class.
- Parameters
parent (QWidget) – the parent widget (SettingsWidget)
- class spinetoolbox.widgets.install_julia_wizard.JillNotFoundPage(parent)[source]¶
Bases:
PySide2.QtWidgets.QWizardPage
- class spinetoolbox.widgets.install_julia_wizard.IntroPage(parent)[source]¶
Bases:
PySide2.QtWidgets.QWizardPage
- class spinetoolbox.widgets.install_julia_wizard.SelectDirsPage(parent)[source]¶
Bases:
PySide2.QtWidgets.QWizardPage
- class spinetoolbox.widgets.install_julia_wizard.InstallJuliaPage(parent)[source]¶
Bases:
spinetoolbox.widgets.custom_qwidgets.QWizardProcessPage
A QWizards page with a log. Useful for pages that need to capture the output of a process.
spinetoolbox.widgets.kernel_editor
¶Dialog for selecting a kernel or creating a new Julia or Python kernel.
- author
Savolainen (VTT)
- date
7.10.2020
Class for a Python and Julia kernel editor. |
|
A reduced version of KernelEditor that basically just takes care of installing one Python kernel. |
|
A reduced version of KernelEditor that basically just takes care of installing one Julia kernel. |
Returns a dictionary mapping kernel names to kernel paths. |
|
Returns a dictionary of Python kernels. Keys are kernel_names, values are kernel paths. |
|
Returns a dictionary of Julia kernels. Keys are kernel_names, values are kernel paths. |
|
Returns a dictionary of kernels that are neither Python nor Julia kernels. |
|
|
Formats message for the kernel editor text browser. |
|
Formats process message for the kernel editor text browser. |
- class spinetoolbox.widgets.kernel_editor.KernelEditorBase(parent, python, julia, python_or_julia, current_kernel)[source]¶
Bases:
PySide2.QtWidgets.QDialog
- setup_dialog_style(self)[source]¶
Sets windows icon and stylesheet. This can be removed when SettingsWidget inherits stylesheet from ToolboxUI.
- check_options(self, prgm, kernel_name, display_name, python_or_julia)[source]¶
Checks that user options are valid before advancing with kernel making.
- Parameters
prgm (str) – Full path to Python or Julia program
kernel_name (str) – Kernel name
display_name (str) – Kernel display name
python_or_julia (str) – Either ‘python’ or ‘julia’
- Returns
True if all user input is valid for making a new kernel, False otherwise
- Return type
bool
- make_python_kernel(self, checked=False)[source]¶
Makes a new Python kernel. Offers to install ipykernel package if it is missing from the selected Python environment. Overwrites existing kernel with the same name if this is ok by user.
- static is_package_installed(python_path, package_name)[source]¶
Checks if given package is installed to given Python environment.
- Parameters
python_path (str) – Full path to selected Python interpreter
package_name (str) – Package name
- Returns
True if installed, False if not
- Return type
(bool)
- start_package_install_process(self, python_path, package_name)[source]¶
Starts installing the given package using pip.
- Parameters
python_path (str) – Full path to selected Python interpreter
package_name (str) – Package name to install using pip
- handle_package_install_process_finished(self, retval)[source]¶
Handles installing package finished.
- Parameters
retval (int) – Process return value. 0: success, !0: failure
- start_kernelspec_install_process(self, prgm, k_name, d_name)[source]¶
Installs kernel specifications for the given Python environment. Runs e.g. this command in QProcess
python -m ipykernel install –user –name python-X.Y –display-name PythonX.Y
Creates new kernel specs into %APPDATA%jupyterkernels. Existing directory will be overwritten.
Note: We cannot use –sys.prefix here because if we have selected to create a kernel for some other python that was used in launching the app, the kernel will be created into a location that is not discoverable by jupyter and hence not by Spine Toolbox. E.g. when sys.executable is C:Python36python.exe, and we have selected that as the python for Spine Toolbox (Settings->Tools->Python interpreter is empty), creating a kernel with –sys-prefix creates kernel specs into C:Python36sharejupyterkernelspython-3.6. This is ok and the kernel spec is discoverable by jupyter and Spine Toolbox.
BUT when sys.executable is C:Python36python.exe, and we have selected another python for Spine Toolbox (Settings->Tools->Python interpreter is C:Python38python.exe), creating a kernel with –sys-prefix creates a kernel into C:Python38sharejupyterkernelspython-3.8-sys-prefix. This is not discoverable by jupyter nor Spine Toolbox. You would need to start the app using C:Python38python.exe to see and use that kernel spec.
Using –user option instead, creates kernel specs that are discoverable by any python that was used in starting Spine Toolbox.
- Parameters
prgm (str) – Full path to Python interpreter for which the kernel is created
k_name (str) – Kernel name
d_name (str) – Kernel display name
- handle_kernelspec_install_process_finished(self, retval)[source]¶
Handles case when the process for installing the kernel has finished.
- Parameters
retval (int) – Process return value. 0: success, !0: failure
- make_julia_kernel(self, checked=False)[source]¶
Makes a new Julia kernel. Offers to install IJulia package if it is missing from the selected Julia project. Overwrites existing kernel with the same name if this is ok by user.
- is_ijulia_installed(self, program, project)[source]¶
Checks if IJulia is installed for the given project. Note: Trying command ‘using IJulia’ does not work since it automatically tries loading it from the LOAD_PATH if not it’s not found in the active project.
- Returns
0 when process failed to start, 1 when IJulia is installed, 2 when IJulia is not installed.
- Return type
(int)
- start_ijulia_install_process(self, julia, project)[source]¶
Starts installing IJulia package to given Julia project.
- Parameters
julia (str) – Full path to selected Julia executable
project (str) – Julia project (e.g. dir path or ‘@.’, or ‘.’)
- handle_ijulia_install_finished(self, ret)[source]¶
Runs when IJulia install process finishes.
- Parameters
ret (int) – Process return value. 0: success, !0: failure
- handle_ijulia_rebuild_finished(self, ret)[source]¶
Runs when IJulia rebuild process finishes.
- Parameters
ret (int) – Process return value. 0: success, !0: failure
- start_ijulia_installkernel_process(self, program, project, kernel_name)[source]¶
Installs the kernel using IJulia.installkernel function. Given kernel_name is actually the new kernel DISPLAY name. IJulia strips the whitespace and uncapitalizes this to make the kernel name automatically. Julia version is concatenated to both names automatically (This cannot be changed).
- handle_installkernel_process_finished(self, retval)[source]¶
Checks whether or not the IJulia.installkernel process finished successfully.
- Parameters
retval (int) – Process return value. 0: success, !0: failure
- restore_dialog_dimensions(self)[source]¶
Restore widget location, dimensions, and state from previous session.
- add_message(self, msg)[source]¶
Append regular message to kernel editor text browser.
- Parameters
msg (str) – String written to QTextBrowser
- add_success_message(self, msg)[source]¶
Append message with green text color to kernel editor text browser.
- Parameters
msg (str) – String written to QTextBrowser
- add_error_message(self, msg)[source]¶
Append message with red color to kernel editor text browser.
- Parameters
msg (str) – String written to QTextBrowser
- add_warning_message(self, msg)[source]¶
Append message with yellow (golden) color to kernel editor text browser.
- Parameters
msg (str) – String written to QTextBrowser
- add_process_message(self, msg)[source]¶
Writes message from stdout to kernel editor text browser.
- Parameters
msg (str) – String written to QTextBrowser
- class spinetoolbox.widgets.kernel_editor.KernelEditor(parent, python, julia, python_or_julia, current_kernel)[source]¶
Bases:
KernelEditorBase
Class for a Python and Julia kernel editor.
- Parameters
parent (QWidget) – Parent widget (Settings widget)
python (str) – Python interpreter, may be empty string
julia (str) – Julia executable, may be empty string
python_or_julia (str) – Setup KernelEditor according to selected mode
current_kernel (str) – Current selected Python or Julia kernel name
- python_kernel_name_edited(self, txt)[source]¶
Updates the display name place holder text and the command QCustomLabel tool tip.
- select_julia_clicked(self, checked=False)[source]¶
Opens file browser where user can select a Julia executable for the new kernel.
- select_julia_project_clicked(self, checked=False)[source]¶
Opens file browser where user can select a Julia project path for the new kernel.
- select_python_clicked(self, checked=False)[source]¶
Opens file browser where user can select the python interpreter for the new kernel.
- update_python_cmd_tooltip(self)[source]¶
Updates Python command (CustomQLabel) tooltip according to selections.
- update_julia_cmd_tooltip(self)[source]¶
Updates Julia command (CustomQLabel) tooltip according to selections.
- set_kernel_selected(self, k_name)[source]¶
Finds row index of given kernel name from the model, sets it selected and scrolls the view so that it’s visible.
- Parameters
k_name (str) – Kernel name to find and select
- _check_kernel_is_ok(self, current, previous)[source]¶
Shows a notification if there are any known problems with selected kernel.
- Parameters
current (QModelIndex) – Currently selected index
previous (QModelIndex) – Previously selected index
- find_column(self, label)[source]¶
Returns the column number from the kernel model with the given label.
- Parameters
label (str) – Header column label
- Returns
Column number or -1 if label not found
- Return type
int
- check_options(self, prgm, kernel_name, display_name, python_or_julia)[source]¶
Checks that user options are valid before advancing with kernel making.
- Parameters
prgm (str) – Full path to Python or Julia program
kernel_name (str) – Kernel name
display_name (str) – Kernel display name
python_or_julia (str) – Either ‘python’ or ‘julia’
- Returns
True if all user input is valid for making a new kernel, False otherwise
- Return type
bool
- handle_kernelspec_install_process_finished(self, retval)[source]¶
Handles case when the process for installing the kernel has finished.
- Parameters
retval (int) – Process return value. 0: success, !0: failure
- handle_installkernel_process_finished(self, retval)[source]¶
Checks whether or not the IJulia.installkernel process finished successfully.
- Parameters
retval (int) – Process return value. 0: success, !0: failure
- populate_kernel_model(self)[source]¶
Populates the kernel model with kernels found in user’s system either with Python or Julia kernels. Unknows, invalid, and unsupported kernels are appended to the end.
- static get_kernel_deats(kernel_path)[source]¶
Reads kernel.json from given kernel path and returns the details in a dictionary.
- Parameters
kernel_path (str) – Full path to kernel directory
- Returns
language (str), path to interpreter (str), display name (str), project (str) (NA for Python kernels)
- Return type
dict
Shows the context-menu in the kernel list table view.
- _open_kernel_json(self, checked=False)[source]¶
Opens kernel.json file using the default application for .json files.
- _remove_kernel(self, checked=False)[source]¶
Removes selected kernel by deleting the kernel directory.
- mousePressEvent(self, e)[source]¶
Saves mouse position at the start of dragging.
- Parameters
e (QMouseEvent) – Mouse event
- mouseReleaseEvent(self, e)[source]¶
Saves mouse position at the end of dragging.
- Parameters
e (QMouseEvent) – Mouse event
- mouseMoveEvent(self, e)[source]¶
Moves the window when mouse button is pressed and mouse cursor is moved.
- Parameters
e (QMouseEvent) – Mouse event
- class spinetoolbox.widgets.kernel_editor.MiniKernelEditorBase(parent, python_exe, julia_exe, python_or_julia)[source]¶
Bases:
KernelEditorBase
- class spinetoolbox.widgets.kernel_editor.MiniPythonKernelEditor(parent, python_exe)[source]¶
Bases:
MiniKernelEditorBase
A reduced version of KernelEditor that basically just takes care of installing one Python kernel. The python exe is passed in the constructor, then calling
make_kernel
starts the process.
- class spinetoolbox.widgets.kernel_editor.MiniJuliaKernelEditor(parent, julia_exe, julia_project)[source]¶
Bases:
MiniKernelEditorBase
A reduced version of KernelEditor that basically just takes care of installing one Julia kernel. The julia exe and project are passed in the constructor, then calling
make_kernel
starts the process.
- spinetoolbox.widgets.kernel_editor.find_kernels()[source]¶
Returns a dictionary mapping kernel names to kernel paths.
- spinetoolbox.widgets.kernel_editor.find_python_kernels()[source]¶
Returns a dictionary of Python kernels. Keys are kernel_names, values are kernel paths.
- spinetoolbox.widgets.kernel_editor.find_julia_kernels()[source]¶
Returns a dictionary of Julia kernels. Keys are kernel_names, values are kernel paths.
- spinetoolbox.widgets.kernel_editor.find_unknown_kernels()[source]¶
Returns a dictionary of kernels that are neither Python nor Julia kernels.
spinetoolbox.widgets.link_properties_widget
¶Link properties widget.
- author
Marin (KTH)
- date
27.11.2020
Widget for the Data Connection Item Properties. |
- class spinetoolbox.widgets.link_properties_widget.LinkPropertiesWidget(toolbox)[source]¶
Bases:
PySide2.QtWidgets.QWidget
Widget for the Data Connection Item Properties.
- Parameters
toolbox (ToolboxUI) – The toolbox instance where this widget should be embedded
spinetoolbox.widgets.map_editor
¶An editor widget for editing a map type parameter values.
- author
Soininen (VTT)
- date
11.2.2020
A widget for editing maps. |
spinetoolbox.widgets.map_value_editor
¶An editor dialog for map indexes and values.
- author
Soininen (VTT)
- date
2.11.2020
Dialog for editing parameter values in Database editor. |
- class spinetoolbox.widgets.map_value_editor.MapValueEditor(index, parent=None)[source]¶
Bases:
spinetoolbox.widgets.parameter_value_editor_base.ParameterValueEditorBase
Dialog for editing parameter values in Database editor.
- Parameters
index (QModelIndex) – an index to a parameter_value in parent_model
parent (QWidget, optional) – a parent widget
spinetoolbox.widgets.multi_tab_spec_editor
¶Contains the MultiTabSpecEditor class.
- author
Marin (KTH)
- date
12.12.2020
spinetoolbox.widgets.multi_tab_window
¶Contains the MultiTabWindow and TabBarPlus classes.
- author
Marin (KTH)
- date
12.12.2020
Tab bar that has a plus button floating to the right of the tabs. |
- class spinetoolbox.widgets.multi_tab_window.MultiTabWindow(qsettings, settings_group, parent=None)[source]¶
Bases:
PySide2.QtWidgets.QMainWindow
- add_new_tab(self, *args, **kwargs)[source]¶
Creates a new tab and adds it at the end of the tab bar.
- insert_new_tab(self, index, *args, **kwargs)[source]¶
Creates a new tab and inserts it at the given index.
- Parameters
index (int) –
- detach(self, index, hot_spot, offset=0)[source]¶
Detaches the tab at given index into another MultiTabWindow window and starts dragging it.
- Parameters
index (int) –
hot_spot (QPoint) –
offset (int) –
- start_drag(self, hot_spot, offset=0)[source]¶
Starts dragging a detached tab.
- Parameters
hot_spot (QPoint) – The anchor point of the drag in widget coordinates.
offset (int, optional) – Horizontal offset of the tab in the bar.
- timerEvent(self, event)[source]¶
Performs the drag, i.e., moves the window with the mouse cursor. As soon as the mouse hovers the tab bar of another MultiTabWindow, reattaches it.
- mouseReleaseEvent(self, event)[source]¶
Stops the drag. This only happens when the detached tab is not reattached to another window.
- reattach(self, index, db_editor, text)[source]¶
Reattaches a tab that has been dragged over this window’s tab bar.
- Parameters
index (int) – Index in this widget’s tab bar where the detached tab has been dragged.
db_editor (SpineDBEditor) – The widget in the tab being dragged.
text (str) – The title of the tab.
- class spinetoolbox.widgets.multi_tab_window.TabBarPlus(parent)[source]¶
Bases:
PySide2.QtWidgets.QTabBar
Tab bar that has a plus button floating to the right of the tabs.
- Parameters
parent (MultiSpineDBEditor) –
- resizeEvent(self, event)[source]¶
Sets the dimension of the plus button. Also, makes the tab bar as wide as the parent.
- mousePressEvent(self, event)[source]¶
Registers the position of the press, in case we need to detach the tab.
- mouseMoveEvent(self, event)[source]¶
Detaches a tab either if the user moves beyond the limits of the tab bar, or if it’s the only one.
- _send_release_event(self, pos)[source]¶
Sends a mouse release event at given position in local coordinates. Called just before detaching a tab.
- Parameters
pos (QPoint) –
- start_dragging(self, index)[source]¶
Stars dragging the given index. This happens when a detached tab is reattached to this bar.
- Parameters
index (int) –
spinetoolbox.widgets.notification
¶Contains a notification widget.
- author
Savolainen (VTT)
- date
12.12.2019
Custom pop-up notification widget with fade-in and fade-out effect. |
|
A notification that doesn’t dissapear when the cursor is on it. |
|
A notification with a button. |
|
A notification that may have a link. |
|
|
- class spinetoolbox.widgets.notification.Notification(parent, txt, anim_duration=500, life_span=None, word_wrap=True, corner=Qt.TopRightCorner)[source]¶
Bases:
PySide2.QtWidgets.QFrame
Custom pop-up notification widget with fade-in and fade-out effect.
- Parameters
parent (QWidget) – Parent widget
txt (str) – Text to display in notification
anim_duration (int) – Duration of the animation in msecs
life_span (int) – How long does the notification stays in place in msecs
word_wrap (bool) –
corner (Qt.Corner) –
- class spinetoolbox.widgets.notification.InteractiveNotification(parent, txt, anim_duration=500, life_span=None, word_wrap=True, corner=Qt.TopRightCorner)[source]¶
Bases:
Notification
A notification that doesn’t dissapear when the cursor is on it.
- Parameters
parent (QWidget) – Parent widget
txt (str) – Text to display in notification
anim_duration (int) – Duration of the animation in msecs
life_span (int) – How long does the notification stays in place in msecs
word_wrap (bool) –
corner (Qt.Corner) –
- class spinetoolbox.widgets.notification.ButtonNotification(*args, button_text='', button_slot=None, **kwargs)[source]¶
Bases:
InteractiveNotification
A notification with a button.
- Parameters
parent (QWidget) – Parent widget
txt (str) – Text to display in notification
anim_duration (int) – Duration of the animation in msecs
life_span (int) – How long does the notification stays in place in msecs
word_wrap (bool) –
corner (Qt.Corner) –
- class spinetoolbox.widgets.notification.LinkNotification(*args, open_link=None, **kwargs)[source]¶
Bases:
InteractiveNotification
A notification that may have a link.
- Parameters
parent (QWidget) – Parent widget
txt (str) – Text to display in notification
anim_duration (int) – Duration of the animation in msecs
life_span (int) – How long does the notification stays in place in msecs
word_wrap (bool) –
corner (Qt.Corner) –
- class spinetoolbox.widgets.notification.NotificationStack(parent, anim_duration=500, life_span=None)[source]¶
Bases:
PySide2.QtCore.QObject
spinetoolbox.widgets.open_project_widget
¶Contains a class for a widget that represents a ‘Open Project Directory’ dialog.
- author
Savolainen (VTT)
- date
1.11.2019
A dialog that let’s user select a project to open either by choosing |
|
Custom file system model. |
|
- class spinetoolbox.widgets.open_project_widget.OpenProjectDialog(toolbox)[source]¶
Bases:
PySide2.QtWidgets.QDialog
A dialog that let’s user select a project to open either by choosing an old .proj file or by choosing a project directory.
- Parameters
toolbox (ToolboxUI) – QMainWindow instance
- set_keyboard_shortcuts(self)[source]¶
Creates keyboard shortcuts for the ‘Root’, ‘Home’, etc. buttons.
- expand_and_resize(self, p)[source]¶
Expands, resizes, and scrolls the tree view to the current directory when the file model has finished loading the path. Slot for the file model’s directoryLoaded signal. The directoryLoaded signal is emitted only if the directory has not been cached already. Note, that this is only used when the open project dialog is opened
- Parameters
p (str) – Directory that has been loaded
- validator_state_changed(self)[source]¶
Changes the combobox border color according to the current state of the validator.
- current_index_changed(self, i)[source]¶
Combobox selection changed. This slot is processed when a new item is selected from the drop-down list. This is not processed when new item txt is QValidotor.Intermediate.
- Parameters
i (int) – Selected row in combobox
- current_changed(self, current, previous)[source]¶
Processed when the current item in file system tree view has been changed with keyboard or mouse. Updates the text in combobox.
- Parameters
current (QModelIndex) – Currently selected index
previous (QModelIndex) – Previously selected index
- set_selected_path(self, index)[source]¶
Sets the text in the combobox as the selected path in the file system tree view.
- Parameters
index (QModelIndex) – The index which was mouse clicked.
- combobox_text_edited(self, text)[source]¶
Updates selected path when combobox text is edited. Note: pressing enter in combobox does not trigger this.
- go_root(self, checked=False)[source]¶
Slot for the ‘Root’ button. Scrolls the treeview to show and select the user’s root directory.
Note: We need to expand and scroll the tree view here after setCurrentIndex just in case the directory has been loaded already.
- go_home(self, checked=False)[source]¶
Slot for the ‘Home’ button. Scrolls the treeview to show and select the user’s home directory.
- go_documents(self, checked=False)[source]¶
Slot for the ‘Documents’ button. Scrolls the treeview to show and select the user’s documents directory.
- go_desktop(self, checked=False)[source]¶
Slot for the ‘Desktop’ button. Scrolls the treeview to show and select the user’s desktop directory.
- open_project(self, index)[source]¶
Opens project if index contains a valid Spine Toolbox project. Slot for the mouse doubleClicked signal. Prevents showing the ‘Not a valid spine toolbox project’ notification if user just wants to collapse a directory.
- Parameters
index (QModelIndex) – File model index which was double clicked
- done(self, r)[source]¶
Checks that selected path exists and is a valid Spine Toolbox directory when ok button is clicked or when enter is pressed without the combobox being in focus.
- Parameters
r (int) –
- static update_recents(entry, qsettings)[source]¶
Adds a new entry to QSettings variable that remembers the five most recent project storages.
- Parameters
entry (str) – Abs. path to a directory that most likely contains other Spine Toolbox Projects as well. First entry is also used as the initial path for File->New Project dialog.
qsettings (QSettings) – Toolbox qsettings object
- static remove_directory_from_recents(p, qsettings)[source]¶
Removes directory from the recent project storages.
- Parameters
p (str) – Full path to a project directory
qsettings (QSettings) – Toolbox qsettings object
Shows the context menu for the QCombobox with a ‘Clear history’ entry.
- Parameters
pos (QPoint) – Mouse position
- class spinetoolbox.widgets.open_project_widget.CustomQFileSystemModel[source]¶
Bases:
PySide2.QtWidgets.QFileSystemModel
Custom file system model.
- class spinetoolbox.widgets.open_project_widget.DirValidator(parent=None)[source]¶
Bases:
PySide2.QtGui.QValidator
- validate(self, txt, pos)[source]¶
Returns Invalid if input is invalid according to this validator’s rules, Intermediate if it is likely that a little more editing will make the input acceptable and Acceptable if the input is valid.
- Parameters
txt (str) – Text to validate
pos (int) – Cursor position
- Returns
Invalid, Intermediate, or Acceptable
- Return type
QValidator.State
spinetoolbox.widgets.parameter_value_editor
¶An editor dialog for editing database (relationship) parameter values.
- author
Soininen (VTT)
- date
28.6.2019
Dialog for editing parameter values in Database editor. |
- class spinetoolbox.widgets.parameter_value_editor.ParameterValueEditor(index, parent=None)[source]¶
Bases:
spinetoolbox.widgets.parameter_value_editor_base.ParameterValueEditorBase
Dialog for editing parameter values in Database editor.
- Parameters
index (QModelIndex) – an index to a parameter_value in parent_model
parent (QWidget, optional) – a parent widget
spinetoolbox.widgets.parameter_value_editor_base
¶A base for editor windows for editing parameter values.
- author
Soininen (VTT)
- date
2.11.2020
Enum to identify value types that use different editors. |
|
Dialog for editing parameter values. |
- class spinetoolbox.widgets.parameter_value_editor_base.ValueType[source]¶
Bases:
enum.Enum
Enum to identify value types that use different editors.
- class spinetoolbox.widgets.parameter_value_editor_base.ParameterValueEditorBase(index, editor_widgets, parent=None)[source]¶
Bases:
PySide2.QtWidgets.QWidget
Dialog for editing parameter values.
The dialog takes an index and shows a specialized editor corresponding to the value type in a stack widget. The user can change the value type by changing the specialized editor using a combo box. When the dialog is closed the value from the currently shown specialized editor is written back to the given index.
- Parameters
index (QModelIndex) – an index to a parameter_value in parent_model
editor_widgets (dict) – a mapping from
ValueType
toQWidget
parent (QWidget, optional) – a parent widget
- accept(self)[source]¶
Saves the parameter_value shown in the currently selected editor widget to the database manager.
- _change_parameter_type(self, selector_index)[source]¶
Handles switching between value types.
Does a rude conversion between fixed and variable resolution time series. In other cases, a default ‘empty’ value is used.
- Parameters
selector_index (int) – an index to the selector combo box
- _select_editor(self, value)[source]¶
Shows the editor widget corresponding to the given value type on the editor stack.
- _use_default_editor(self, message=None)[source]¶
Opens the default editor widget. Optionally, displays a warning dialog indicating the problem.
- Parameters
message (str, optional) –
spinetoolbox.widgets.plain_parameter_value_editor
¶An editor widget for editing plain number database (relationship) parameter values.
- author
Soininen (VTT)
- date
28.6.2019
A widget to edit float or boolean type parameter values. |
spinetoolbox.widgets.plot_canvas
¶A Qt widget to use as a matplotlib backend.
- author
Soininen (VTT)
- date
3.6.2019
A widget for plotting with matplotlib. |
spinetoolbox.widgets.plot_widget
¶A Qt widget showing a toolbar and a matplotlib plotting canvas.
- author
Soininen (VTT)
- date
27.6.2019
A widget that contains a toolbar and a plotting canvas. |
Fills a given menu with available plot window names. |
- class spinetoolbox.widgets.plot_widget.PlotWidget(parent=None)[source]¶
Bases:
PySide2.QtWidgets.QWidget
A widget that contains a toolbar and a plotting canvas.
- canvas¶
the plotting canvas
- Type
- plot_type¶
type of currently plotted data or None
- Type
type
Fills a given menu with available plot window names.
spinetoolbox.widgets.plugin_manager_widgets
¶Contains PluginManager dialogs and widgets.
- author
Marin (KTH)
- date
21.2.2021
Initialize class |
|
Initialize class |
- class spinetoolbox.widgets.plugin_manager_widgets._InstallPluginModel[source]¶
Bases:
PySide2.QtGui.QStandardItemModel
- class spinetoolbox.widgets.plugin_manager_widgets._ManagePluginsModel[source]¶
Bases:
_InstallPluginModel
- class spinetoolbox.widgets.plugin_manager_widgets.InstallPluginDialog(parent)[source]¶
Bases:
PySide2.QtWidgets.QDialog
Initialize class
spinetoolbox.widgets.project_item_drag
¶Classes for custom QListView.
- author
Marin (KTH)
- date
14.11.2018
Custom class with dragging support. |
|
Custom class with dragging support. |
|
Custom class with dragging support. |
|
Custom class with dragging support. |
|
Custom class with dragging support. |
|
An array of ProjectItemSpecButton that can be expanded/collapsed. |
- class spinetoolbox.widgets.project_item_drag.ProjectItemDragMixin(*args, **kwargs)[source]¶
Custom class with dragging support.
- class spinetoolbox.widgets.project_item_drag.ProjectItemButtonBase(toolbox, item_type, icon, parent=None)[source]¶
Bases:
ProjectItemDragMixin
,PySide2.QtWidgets.QToolButton
Custom class with dragging support.
- class spinetoolbox.widgets.project_item_drag.ProjectItemButton(toolbox, item_type, icon, parent=None)[source]¶
Bases:
ProjectItemButtonBase
Custom class with dragging support.
- class spinetoolbox.widgets.project_item_drag.ProjectItemSpecButton(toolbox, item_type, icon, spec_name='', parent=None)[source]¶
Bases:
ProjectItemButtonBase
Custom class with dragging support.
- class spinetoolbox.widgets.project_item_drag.ShadeProjectItemSpecButton(toolbox, item_type, icon, spec_name='', parent=None)[source]¶
Bases:
ShadeMixin
,ProjectItemSpecButton
Custom class with dragging support.
- class spinetoolbox.widgets.project_item_drag.ShadeButton[source]¶
Bases:
ShadeMixin
,PySide2.QtWidgets.QToolButton
- class spinetoolbox.widgets.project_item_drag._ChoppedIcon(icon, size)[source]¶
Bases:
PySide2.QtGui.QIcon
- class spinetoolbox.widgets.project_item_drag._ChoppedIconEngine(icon, size)[source]¶
Bases:
PySide2.QtGui.QIconEngine
- class spinetoolbox.widgets.project_item_drag.ProjectItemSpecArray(toolbox, model, item_type, icon)[source]¶
Bases:
PySide2.QtWidgets.QToolBar
An array of ProjectItemSpecButton that can be expanded/collapsed.
- Parameters
toolbox (ToolboxUI) –
model (FilteredSpecificationModel) –
item_type (str) –
icon (ColoredIcon) –
- _get_first_chopped_index(self)[source]¶
Returns the index of the first chopped action (chopped = not drawn because of space).
- Returns
list(QAction) int or NoneType
- _add_filling(self, actions, ind)[source]¶
Adds a button to fill empty space after the last visible action.
- Parameters
actions (list(QAction)) – actions
ind (int or NoneType) – index of the first chopped one or None if all are visible
- _get_filling(self, previous)[source]¶
Returns the position and size of the filling widget.
- Parameters
previous (QWidget) – last visible widget
- Returns
position x int: position y int: width int: height
- Return type
int
Populates extension menu with chopped actions.
- Parameters
actions (list(QAction)) – actions
ind (int or NoneType) – index of the first chopped one or None if all are visible
spinetoolbox.widgets.report_plotting_failure
¶Functions to report failures in plotting to the user.
- author
Soininen (VTT)
- date
10.7.2019
|
Reports a PlottingError exception to the user. |
spinetoolbox.widgets.settings_widget
¶Widget for controlling user settings.
- author
Savolainen (VTT)
- date
17.1.2018
|
|
A widget to change user’s preferred settings, but only for the Spine db editor. |
|
A widget to change user’s preferred settings. |
|
|
|
|
|
|
|
|
|
- class spinetoolbox.widgets.settings_widget.SettingsWidgetBase(qsettings)[source]¶
Bases:
PySide2.QtWidgets.QWidget
- Parameters
qsettings (QSettings) – Toolbox settings
- keyPressEvent(self, e)[source]¶
Close settings form when escape key is pressed.
- Parameters
e (QKeyEvent) – Received key press event.
- mousePressEvent(self, e)[source]¶
Save mouse position at the start of dragging.
- Parameters
e (QMouseEvent) – Mouse event
- mouseReleaseEvent(self, e)[source]¶
Save mouse position at the end of dragging.
- Parameters
e (QMouseEvent) – Mouse event
- mouseMoveEvent(self, e)[source]¶
Moves the window when mouse button is pressed and mouse cursor is moved.
- Parameters
e (QMouseEvent) – Mouse event
- class spinetoolbox.widgets.settings_widget.SpineDBEditorSettingsMixin[source]¶
- class spinetoolbox.widgets.settings_widget.SpineDBEditorSettingsWidget(multi_db_editor)[source]¶
Bases:
SpineDBEditorSettingsMixin
,SettingsWidgetBase
A widget to change user’s preferred settings, but only for the Spine db editor.
Initialize class.
- class spinetoolbox.widgets.settings_widget.SettingsWidget(toolbox)[source]¶
Bases:
SpineDBEditorSettingsMixin
,SettingsWidgetBase
A widget to change user’s preferred settings.
- Parameters
toolbox (ToolboxUI) – Parent widget.
- browse_gams_path(self, checked=False)[source]¶
Open file browser where user can select a GAMS program.
- browse_julia_button_clicked(self, checked=False)[source]¶
Calls static method that shows a file browser for selecting the Julia path.
- browse_julia_project_button_clicked(self, checked=False)[source]¶
Calls static method that shows a file browser for selecting a Julia project.
- browse_python_button_clicked(self, checked=False)[source]¶
Calls static method that shows a file browser for selecting Python interpreter.
- show_python_kernel_editor(self, checked=False)[source]¶
Opens kernel editor, where user can make a kernel for the Python Console.
- python_kernel_editor_closed(self, ret_code)[source]¶
Catches the selected Python kernel name when the editor is closed.
- show_julia_kernel_editor(self, checked=False)[source]¶
Opens kernel editor, where user can make a kernel the Julia Console.
- julia_kernel_editor_closed(self, ret_code)[source]¶
Catches the selected Julia kernel name when the editor is closed.
- browse_work_path(self, checked=False)[source]¶
Open file browser where user can select the path to wanted work directory.
- show_color_dialog(self, checked=False)[source]¶
Let user pick the bg color.
- Parameters
checked (boolean) – Value emitted with clicked signal
- update_bg_color(self)[source]¶
Set tool button icon as the selected color and update Design View scene background color.
- update_scene_bg(self, checked=False)[source]¶
Draw background on scene depending on radiobutton states.
- Parameters
checked (boolean) – Toggle state
- read_settings(self)[source]¶
Read saved settings from app QSettings instance and update UI to display them.
- read_project_settings(self)[source]¶
Get project name and description and update widgets accordingly.
- save_settings(self)[source]¶
Get selections and save them to persistent memory. Note: On Linux, True and False are saved as boolean values into QSettings. On Windows, booleans and integers are saved as strings. To make it consistent, we should use strings.
- update_project_settings(self)[source]¶
Update project name and description if these have been changed.
spinetoolbox.widgets.spine_console_widget
¶Class for a custom RichJupyterWidget that can run Tool instances.
- authors
Marin (KTH), P. Savolainen (VTT)
- date
22.10.2019
Base class for all embedded console widgets that can run tool instances. |
- class spinetoolbox.widgets.spine_console_widget.SpineConsoleWidget(toolbox, name, owner=None)[source]¶
Bases:
qtconsole.rich_jupyter_widget.RichJupyterWidget
Base class for all embedded console widgets that can run tool instances.
- Parameters
toolbox (ToolboxUI) – QMainWindow instance
name (str) – Console name, e.g. ‘Python Console’
owner (ProjectItem, NoneType) – Item that owns the console.
- start_console(self, checked=False)[source]¶
Starts chosen Python/Julia kernel if available and not already running. Context menu start action handler.
- restart_console(self, checked=False)[source]¶
Restarts current Python/Julia kernel. Starts a new kernel if it is not running or if chosen kernel has been changed in Settings. Context menu restart action handler.
- call_start_kernel(self, k_name=None)[source]¶
Finds a valid kernel and calls
start_kernel()
with it.
- start_kernel(self, k_name, k_path)[source]¶
Starts a kernel manager and kernel client and attaches the client to Julia or Python Console.
- Parameters
k_name (str) – Kernel name
k_path (str) – Directory where the the kernel specs are located
Reimplemented to add actions to console context-menus.
spinetoolbox.widgets.time_pattern_editor
¶An editor widget for editing a time pattern type (relationship) parameter values.
- author
Soininen (VTT)
- date
28.6.2019
A widget for editing time patterns. |
spinetoolbox.widgets.time_series_fixed_resolution_editor
¶Contains logic for the fixed step time series editor widget.
- author
Soininen (VTT)
- date
14.6.2019
A widget for editing time series data with a fixed time step. |
|
Converts a list of durations into a string of comma-separated durations. |
|
Converts a comma-separated string of durations into a resolution array. |
- spinetoolbox.widgets.time_series_fixed_resolution_editor._resolution_to_text(resolution)[source]¶
Converts a list of durations into a string of comma-separated durations.
- spinetoolbox.widgets.time_series_fixed_resolution_editor._text_to_resolution(text)[source]¶
Converts a comma-separated string of durations into a resolution array.
- class spinetoolbox.widgets.time_series_fixed_resolution_editor.TimeSeriesFixedResolutionEditor(parent=None)[source]¶
Bases:
PySide2.QtWidgets.QWidget
A widget for editing time series data with a fixed time step.
- Parameters
parent (QWidget) – a parent widget
Shows the table’s context menu.
- Parameters
position (QPoint) – menu’s position in table view’s coordinates
spinetoolbox.widgets.time_series_variable_resolution_editor
¶Contains logic for the variable resolution time series editor widget.
- author
Soininen (VTT)
- date
31.5.2019
A widget for editing variable resolution time series data. |
- class spinetoolbox.widgets.time_series_variable_resolution_editor.TimeSeriesVariableResolutionEditor(parent=None)[source]¶
Bases:
PySide2.QtWidgets.QWidget
A widget for editing variable resolution time series data.
- Parameters
parent (QWidget) – a parent widget
Shows the table’s context menu.
- Parameters
position (QPoint) – menu’s position on the table
spinetoolbox.widgets.toolbars
¶Functions to make and handle QToolBars.
- author
Savolainen (VTT)
- date
19.1.2018
A plugin toolbar. |
|
The main application toolbar: Items | Execute |
|
- class spinetoolbox.widgets.toolbars.PluginToolBar(name, parent)[source]¶
Bases:
PySide2.QtWidgets.QToolBar
A plugin toolbar.
- Parameters
parent (ToolboxUI) – QMainWindow instance
- class spinetoolbox.widgets.toolbars.MainToolBar(parent)[source]¶
Bases:
PySide2.QtWidgets.QToolBar
The main application toolbar: Items | Execute
- Parameters
parent (ToolboxUI) – QMainWindow instance
- execute_project(self, checked=False)[source]¶
Slot for handling the Execute project tool button clicked signal.
- execute_selected(self, checked=False)[source]¶
Slot for handling the Execute selected tool button clicked signal.
- stop_execution(self, checked=False)[source]¶
Slot for handling the Stop execution tool button clicked signal.
Submodules¶
spinetoolbox.__main__
¶
Spine Toolbox application main file.
- author
Savolainen (VTT)
- date
14.12.2017
Module Contents¶
spinetoolbox.config
¶
Application constants and style sheets
- author
Savolainen (VTT)
- date
2.1.2018
Module Contents¶
|
- spinetoolbox.config.INVALID_FILENAME_CHARS = ['<', '>', ':', '"', '/', '\\', '|', '?', '*'][source]¶
- spinetoolbox.config.ONLINE_DOCUMENTATION_URL = https://spine-toolbox.readthedocs.io/en/release-0.6[source]¶
- spinetoolbox.config.PLUGIN_REGISTRY_URL = https://spine-project.github.io/PluginRegistry/registry.json[source]¶
- spinetoolbox.config.STATUSBAR_SS = QStatusBar{background-color: #EBEBE0; border-width: 1px; border-color: gray; border-style: groove;}[source]¶
- spinetoolbox.config.SETTINGS_SS = #SettingsForm{background-color: ghostwhite;}QLabel{color: black;}QLineEdit{font-size:...[source]¶
- spinetoolbox.config.ICON_BACKGROUND = qlineargradient(x1: 1, y1: 1, x2: 0, y2: 0, stop: 0 #cce0ff, stop: 1 #66a1ff);[source]¶
- spinetoolbox.config.MAINWINDOW_SS = QMainWindow::separator{width: 3px; background-color: lightgray; border: 1px solid...[source]¶
spinetoolbox.custom_file_system_watcher
¶
Contains CustomFileSystemWatcher.
- author
Marin (KTH)
- date
12.11.2020
Module Contents¶
A file system watcher that keeps track of renamed files. |
spinetoolbox.dag_handler
¶
Contains classes for handling DAGs.
- author
Savolainen (VTT)
- date
8.4.2019
Module Contents¶
Class for manipulating graphs according to user’s actions. |
- class spinetoolbox.dag_handler.DirectedGraphHandler[source]¶
Bases:
PySide2.QtCore.QObject
Class for manipulating graphs according to user’s actions.
- remove_dag(self, dag)[source]¶
Remove graph from instance variable list.
- Parameters
dag (DiGraph) – Graph to remove
- add_dag_node(self, node_name)[source]¶
Create directed graph with one node and add it to list.
- Parameters
node_name (str) – Project item name to add as a node
- add_graph_edge(self, src_node, dst_node)[source]¶
Adds an edge between the src and dst nodes. If nodes are in different graphs, the reference to union graph is saved and the references to the original graphs are removed. If src and dst nodes are already in the same graph, the edge is added to the graph. If src and dst are the same node, a self-loop (feedback) edge is added.
- Parameters
src_node (str) – Source project item node name
dst_node (str) – Destination project item node name
- Returns
True if edge established, False if not (e.g. any of the nodes doesn’t really exist)
- Return type
bool
- remove_graph_edge(self, src_node, dst_node)[source]¶
Removes edge from a directed graph.
- Parameters
src_node (str) – Source project item node name
dst_node (str) – Destination project item node name
- Returns
One or two DAGs containing source and destination nodes.
- Return type
list of DiGraph
- remove_node_from_graph(self, node_name)[source]¶
Removes node from a graph that contains it. Called when project item is removed from project.
- Parameters
node_name (str) – Project item name
- rename_node(self, old_name, new_name)[source]¶
Handles renaming the node and edges in a graph when a project item is renamed.
- Parameters
old_name (str) – Old project item name
new_name (str) – New project item name
- Returns
True if successful, False if renaming failed
- Return type
bool
- dag_with_node(self, node_name)[source]¶
Returns directed graph that contains given node.
- Parameters
node_name (str) – Node to look for
- Returns
Directed graph that contains node or None if not found.
- Return type
(DiGraph)
- dag_with_edge(self, src_node, dst_node)[source]¶
Returns directed graph that contains given edge.
- Parameters
src_node (str) – Source node name
dst_node (str) – Destination node name
- Returns
Directed graph that contains edge or None if not found.
- Return type
(DiGraph)
- static node_successors(g)[source]¶
Returns a dict mapping nodes in the given graph to a list of its direct successors. The nodes are in topological sort order. Topological sort in the words of networkx: “a nonunique permutation of the nodes, such that an edge from u to v implies that u appears before v in the topological sort order.”
- Parameters
g (DiGraph) – Directed graph to process
- Returns
key is the node name, value is list of successor names Empty dict if given graph is not a DAG.
- Return type
dict
- successors_til_node(self, g, node)[source]¶
Like node_successors but only until the given node, and ignoring all nodes that are not its ancestors.
- node_is_isolated(self, node, allow_self_loop=False)[source]¶
Checks if the project item with the given name has any connections.
- Parameters
node (str) – Project item name
allow_self_loop (bool) – If default (False), Self-loops are considered as an in-neighbor or an out-neighbor so the method returns False. If True, single node with a self-loop is considered isolated.
- Returns
- True if project item has no in-neighbors nor out-neighbors, False if it does.
Single node with a self-loop is NOT isolated (returns False).
- Return type
bool
- static source_nodes(g)[source]¶
Returns a list of source nodes in given graph. A source node has no incoming edges. This is determined by calculating the in-degree of each node in the graph. If nodes in-degree == 0, it is a source node
- Parameters
g (DiGraph) – Graph to examine
- Returns
List of source node names or an empty list is there are none.
- Return type
list
spinetoolbox.data_package_commands
¶
Classes for models dealing with Data Packages.
- authors
Marin (KTH)
- date
10.7.2020
Module Contents¶
Command to update a resource’s name. |
|
Command to update resource data. |
|
Command to update a resource field’s name. |
|
Command to update a resource’s primary key. |
|
Command to append a foreign key to a resource. |
|
Command to remove a foreign key from a resource. |
|
Command to update a foreign key in a resource. |
- class spinetoolbox.data_package_commands.UpdateResourceNameCommand(model, resource_index, old_name, new_name)[source]¶
Bases:
PySide2.QtWidgets.QUndoCommand
Command to update a resource’s name.
Args:
- class spinetoolbox.data_package_commands.UpdateResourceDataCommand(model, resource_index, rows, columns, old_values, new_values)[source]¶
Bases:
PySide2.QtWidgets.QUndoCommand
Command to update resource data.
Args:
- class spinetoolbox.data_package_commands.UpdateFieldNamesCommand(model, resource_index, field_indexes, old_names, new_names)[source]¶
Bases:
PySide2.QtWidgets.QUndoCommand
Command to update a resource field’s name.
Args:
- class spinetoolbox.data_package_commands.UpdatePrimaryKeysCommand(model, resource_index, field_indexes, statuses)[source]¶
Bases:
PySide2.QtWidgets.QUndoCommand
Command to update a resource’s primary key.
Args:
- class spinetoolbox.data_package_commands.AppendForeignKeyCommandCommand(model, resource_index, foreign_key)[source]¶
Bases:
PySide2.QtWidgets.QUndoCommand
Command to append a foreign key to a resource.
Args:
spinetoolbox.execution_managers
¶
Classes to manage tool instance execution in various forms.
- author
Savolainen (VTT)
- date
1.2.2018
Module Contents¶
Base class for all tool instance execution managers. |
|
Class to manage tool instance execution using a PySide2 QProcess. |
- class spinetoolbox.execution_managers.ExecutionManager(logger)[source]¶
Bases:
PySide2.QtCore.QObject
Base class for all tool instance execution managers.
Class constructor.
- Parameters
logger (LoggerInterface) – a logger instance
- class spinetoolbox.execution_managers.QProcessExecutionManager(logger, program='', args=None, silent=False, semisilent=False)[source]¶
Bases:
ExecutionManager
Class to manage tool instance execution using a PySide2 QProcess.
Class constructor.
- Parameters
logger (LoggerInterface) – a logger instance
program (str) – Path to program to run in the subprocess (e.g. julia.exe)
args (list, optional) – List of argument for the program (e.g. path to script file)
silent (bool) – Whether or not to emit logger msg signals
semisilent (bool) – If True, show Process Log messages
- start_execution(self, workdir=None)[source]¶
Starts the execution of a command in a QProcess.
- Parameters
workdir (str, optional) – Work directory
- wait_for_process_finished(self, msecs=30000)[source]¶
Wait for subprocess to finish.
- Parameters
msecs (int) – Timeout in milliseconds
- Returns
True if process finished successfully, False otherwise
- on_state_changed(self, new_state)[source]¶
Runs when QProcess state changes.
- Parameters
new_state (int) – Process state number (
QProcess::ProcessState
)
- on_process_error(self, process_error)[source]¶
Runs if there is an error in the running QProcess.
- Parameters
process_error (int) – Process error number (
QProcess::ProcessError
)
- teardown_process(self)[source]¶
Tears down the QProcess in case a QProcess.ProcessError occurred. Emits execution_finished signal.
spinetoolbox.headless
¶
Contains facilities to open and execute projects without GUI.
- authors
Soininen (VTT)
- date
29.4.2020
Module Contents¶
A |
|
A ‘task’ which opens and executes a Toolbox project when triggered to do so. |
|
Status codes returned from headless execution. |
|
Executes a project using |
|
Opens a project. |
|
Loads project item specification dictionaries. |
- class spinetoolbox.headless.HeadlessLogger[source]¶
Bases:
PySide2.QtCore.QObject
A
LoggerInterface
compliant logger that uses Python’s standard logging facilities.- msg_proc[source]¶
Emits a message originating from a subprocess (usually something printed to stdout).
- msg_proc_error[source]¶
Emits an error message originating from a subprocess (usually something printed to stderr).
- information_box[source]¶
Requests an ‘information message box’ (e.g. a message window) to be opened with a given title and message.
- class spinetoolbox.headless.ExecuteProject(args, startup_event_type, parent)[source]¶
Bases:
PySide2.QtCore.QObject
A ‘task’ which opens and executes a Toolbox project when triggered to do so.
The execution of this task is triggered by sending it a ‘startup’ QEvent using e.g. QCoreApplication.postEvent()
- Parameters
args (argparse.Namespace) – parsed command line arguments
startup_event_type (int) – expected type id for the event that starts this task
parent (QObject) – a parent object
- _start[source]¶
A private signal to actually start execution. Not to be used directly. Post a startup event instead.
- _open_and_execute_project(self)[source]¶
Opens a project and executes all DAGs in that project.
- Returns
status code
- Return type
- _handle_node_execution_started(self, data)[source]¶
Starts collecting messages from given node.
- Parameters
data (dict) – execution start data
- _handle_node_execution_finished(self, data)[source]¶
Prints messages for finished nodes.
- Parameters
data (dict) – execution end data
- _handle_event_msg(self, data)[source]¶
Stores event messages for later printing.
- Parameters
data (dict) – event message data
- _handle_process_msg(self, data)[source]¶
Stores process messages for later printing.
- Parameters
data (dict) – process message data
- spinetoolbox.headless.headless_main(args)[source]¶
Executes a project using
QCoreApplication
.- Parameters
args (argparser.Namespace) – parsed command line arguments.
- Returns
exit status code; 0 for success, everything else for failure
- Return type
int
- spinetoolbox.headless.open_project(project_dict, project_dir, logger)[source]¶
Opens a project.
- Parameters
project_dict (dict) – a serialized project dictionary
project_dir (str) – path to a directory containing the
.spinetoolbox
dirlogger (LoggerInterface) – a logger
- Returns
item dicts, specification dicts, connection dicts and a DagHandler object
- Return type
tuple
- spinetoolbox.headless._specification_dicts(project_dict, project_dir, logger)[source]¶
Loads project item specification dictionaries.
- Parameters
project_dict (dict) – a serialized project dictionary
project_dir (str) – path to a directory containing the
.spinetoolbox
dirlogger (LoggerInterface) – a logger
- Returns
a mapping from item type to a list of specification dicts
- Return type
dict
spinetoolbox.helpers
¶
General helper functions and classes.
- authors
Savolainen (VTT)
- date
10.1.2018
Module Contents¶
A class to manage icons for icon list widgets. |
|
Specialization of QIconEngine with transparent background. |
|
Specialization of QIconEngine used to draw font-based icons. |
|
QFileIconProvider that provides a Spine icon to the |
|
Event filter class for catching next and previous child key presses. |
|
A ‘traffic light’ that allows waiting for a signal to be emitted in another thread. |
|
Adds color tags and optional time stamp to message. |
|
Adds a message to a document and return the cursor. |
|
Decorator to change the mouse cursor to ‘busy’ while a function is processed. |
|
Create (input/output) directories recursively. |
|
Renames directory. Called by |
|
Opens the given url in the appropriate Web browser for the user’s desktop environment, |
Set application icon to Windows taskbar. |
|
Checks if reading .ico files is supported. |
|
Check that PySide2 version is 5.14 or 5.15. |
|
Check if spine engine package is the correct version and explain how to upgrade if it is not. |
|
|
Returns date and time string for appending into Event Log messages. |
|
Function for copying files. Does not copy folders. |
|
Deletes a directory and all its contents without prompt. |
|
Copies everything from source directory to destination directory recursively. |
|
Change output of itemgetter to always be a tuple even for a single index. |
|
Returns a html unordered list from the given list of strings. |
|
Breaks a list of rows into a list of (row, count) tuples corresponding |
|
Creates and returns a QIcon corresponding to display_icon. |
|
|
|
Takes icon and color codes, and return equivalent integer. |
|
Takes a display icon id and returns an equivalent tuple of icon and color code. |
Creates a default icon id. |
|
|
Checks if window is on screen and if not, moves and resizes it to make it visible on the primary screen. |
Returns the first element in Iterable s that is not None. |
|
|
Calls QFileDialog.getSaveFileName in the directory that was selected last time the dialog was accepted. |
|
|
|
Tries to convert a string to integer or float. |
|
Returns True if the currently focused widget or one of its ancestors has the given callable. |
|
Calls the given callable on the currently focused widget or one of its ancestors. |
|
Opens file browser where user can select a Julia executable (i.e. julia.exe on Windows). |
|
Shows file browser and inserts selected julia project dir to give line_edit. |
|
Opens file browser where user can select a python interpreter (i.e. python.exe on Windows). |
|
Checks that given path is not a directory and it’s a file that actually exists. |
|
Checks that given path is a directory. Needed in |
|
Converts Toolbox settings to a dictionary acceptable by Engine. |
|
|
|
|
|
|
|
Creates a unique name in the form “prefix X” where X is a number. |
- spinetoolbox.helpers.format_log_message(msg_type, message, show_datetime=True)[source]¶
Adds color tags and optional time stamp to message.
- Parameters
msg_type (str) – message’s type; accepts only ‘msg’, ‘msg_success’, ‘msg_warning’, or ‘msg_error’
message (str) – message to format
show_datetime (bool) – True to add time stamp, False to omit it
- Returns
formatted message
- Return type
str
- spinetoolbox.helpers.add_message_to_document(document, message)[source]¶
Adds a message to a document and return the cursor.
- Parameters
document (QTextDocument) –
message (str) –
- Returns
QTextCursor
- spinetoolbox.helpers.busy_effect(func)[source]¶
Decorator to change the mouse cursor to ‘busy’ while a function is processed.
- Parameters
func (Callable) – Decorated function.
- spinetoolbox.helpers.create_dir(base_path, folder='', verbosity=False)[source]¶
Create (input/output) directories recursively.
- Parameters
base_path (str) – Absolute path to wanted dir
folder (str) – (Optional) Folder name. Usually short name of item.
verbosity (bool) – True prints a message that tells if the directory already existed or if it was created.
- Raises
OSError if operation failed. –
- spinetoolbox.helpers.rename_dir(old_dir, new_dir, toolbox, box_title)[source]¶
Renames directory. Called by
ProjectItemModel.set_item_name()
- Parameters
old_dir (str) – Absolute path to directory that will be renamed
new_dir (str) – Absolute path to new directory
toolbox (ToolboxUI) – A toolbox to log messages and ask questions.
box_title (str) – The title of the message boxes, (e.g. “Undoing ‘rename DC1 to DC2’”)
- Returns
True if operation was successful, False otherwise
- Return type
bool
- spinetoolbox.helpers.open_url(url)[source]¶
Opens the given url in the appropriate Web browser for the user’s desktop environment, and returns true if successful; otherwise returns false.
If the URL is a reference to a local file (i.e., the URL scheme is “file”) then it will be opened with a suitable application instead of a Web browser.
Handle return value on caller side.
- Parameters
url (str) – URL to open
- Returns
True if successful, False otherwise
- Return type
bool
- spinetoolbox.helpers.pyside2_version_check()[source]¶
Check that PySide2 version is 5.14 or 5.15. Version 5.15 is allowed but it is not promoted yet because user’s may need to update their VC++ runtime libraries on Windows.
qt_version is the Qt version used to compile PySide2 as string. E.g. “5.14.2” qt_version_info is a tuple with each version component of Qt used to compile PySide2. E.g. (5, 14, 2)
- spinetoolbox.helpers.spine_engine_version_check()[source]¶
Check if spine engine package is the correct version and explain how to upgrade if it is not.
- Returns
True if Spine Engine is of correct version, False otherwise
- Return type
bool
- spinetoolbox.helpers.get_datetime(show, date=True)[source]¶
Returns date and time string for appending into Event Log messages.
- Parameters
show (bool) – True returns date and time string. False returns empty string.
date (bool) – Whether or not the date should be included in the result
- Returns
datetime string or empty string if show is False
- Return type
str
- spinetoolbox.helpers.copy_files(src_dir, dst_dir, includes=None, excludes=None)[source]¶
Function for copying files. Does not copy folders.
- Parameters
src_dir (str) – Source directory
dst_dir (str) – Destination directory
includes (list, optional) – Included files (wildcards accepted)
excludes (list, optional) – Excluded files (wildcards accepted)
- Returns
Number of files copied
- Return type
count (int)
- spinetoolbox.helpers.erase_dir(path, verbosity=False)[source]¶
Deletes a directory and all its contents without prompt.
- Parameters
path (str) – Path to directory
verbosity (bool) – Print logging messages or not
- Returns
True if operation was successful, False otherwise
- Return type
bool
- spinetoolbox.helpers.recursive_overwrite(logger, src, dst, ignore=None, silent=True)[source]¶
Copies everything from source directory to destination directory recursively. Overwrites existing files.
- Parameters
logger (LoggerInterface) – Enables e.g. printing to Event Log
src (str) – Source directory
dst (str) – Destination directory
ignore (Callable, optional) – Ignore function
silent (bool) – If False, messages are sent to Event Log, If True, copying is done in silence
- spinetoolbox.helpers.tuple_itemgetter(itemgetter_func, num_indexes)[source]¶
Change output of itemgetter to always be a tuple even for a single index.
- Parameters
itemgetter_func (Callable) – item getter function
num_indexes (int) – number of indexes
- Returns
getter function that works with a single index
- Return type
Callable
- spinetoolbox.helpers.format_string_list(str_list)[source]¶
Returns a html unordered list from the given list of strings. Intended to print error logs as returned by spinedb_api.
- Parameters
str_list (list of str) – list of strings to format
- Returns
formatted list
- Return type
str
- spinetoolbox.helpers.rows_to_row_count_tuples(rows)[source]¶
Breaks a list of rows into a list of (row, count) tuples corresponding to chunks of successive rows.
- Parameters
rows (list) – rows
- Returns
row count tuples
- Return type
list of tuple
- class spinetoolbox.helpers.IconListManager(icon_size)[source]¶
A class to manage icons for icon list widgets.
- Parameters
icon_size (QSize) – icon’s size
- spinetoolbox.helpers.object_icon(display_icon)[source]¶
Creates and returns a QIcon corresponding to display_icon.
- Parameters
display_icon (int) – icon id
- Returns
requested icon
- Return type
QIcon
- class spinetoolbox.helpers.TransparentIconEngine[source]¶
Bases:
PySide2.QtGui.QIconEngine
Specialization of QIconEngine with transparent background.
- class spinetoolbox.helpers.CharIconEngine(char, color=None)[source]¶
Bases:
TransparentIconEngine
Specialization of QIconEngine used to draw font-based icons.
- Parameters
char (str) – character to use as the icon
color (QColor, optional) –
- class spinetoolbox.helpers.ColoredIcon(icon_file_name, icon_color, icon_size, colored=None)[source]¶
Bases:
PySide2.QtGui.QIcon
- class spinetoolbox.helpers.ColoredIconEngine(icon_file_name, icon_color, icon_size, colored=None)[source]¶
Bases:
PySide2.QtGui.QIconEngine
- spinetoolbox.helpers.make_icon_id(icon_code, color_code)[source]¶
Takes icon and color codes, and return equivalent integer.
- Parameters
icon_code (int) – icon’s code
color_code (int) – color code
- Returns
icon id
- Return type
int
- spinetoolbox.helpers.interpret_icon_id(display_icon)[source]¶
Takes a display icon id and returns an equivalent tuple of icon and color code.
- Parameters
display_icon (int, optional) – icon id
- Returns
icon’s code, color code
- Return type
tuple
- spinetoolbox.helpers.default_icon_id()[source]¶
Creates a default icon id.
- Returns
default icon’s id
- Return type
int
- class spinetoolbox.helpers.ProjectDirectoryIconProvider[source]¶
Bases:
PySide2.QtWidgets.QFileIconProvider
QFileIconProvider that provides a Spine icon to the Open Project Dialog when a Spine Toolbox project directory is encountered.
- spinetoolbox.helpers.ensure_window_is_on_screen(window, size)[source]¶
Checks if window is on screen and if not, moves and resizes it to make it visible on the primary screen.
- Parameters
window (QWidget) – a window to check
size (QSize) – desired window size if the window is moved
- spinetoolbox.helpers.first_non_null(s)[source]¶
Returns the first element in Iterable s that is not None.
- spinetoolbox.helpers.get_save_file_name_in_last_dir(qsettings, key, parent, caption, given_dir, filter_='')[source]¶
Calls QFileDialog.getSaveFileName in the directory that was selected last time the dialog was accepted.
- Parameters
qsettings (QSettings) – A QSettings object where the last directory is stored
key (string) – The name of the entry in the above QSettings
parent – Args passed to QFileDialog.getSaveFileName
caption – Args passed to QFileDialog.getSaveFileName
given_dir – Args passed to QFileDialog.getSaveFileName
filter – Args passed to QFileDialog.getSaveFileName
- Returns
filename str: selected filter
- Return type
str
- spinetoolbox.helpers.get_open_file_name_in_last_dir(qsettings, key, parent, caption, given_dir, filter_='')[source]¶
- spinetoolbox.helpers.try_number_from_string(text)[source]¶
Tries to convert a string to integer or float.
- Parameters
text (str) – string to convert
- Returns
converted value or text if conversion failed
- Return type
int or float or str
- spinetoolbox.helpers.focused_widget_has_callable(parent, callable_name)[source]¶
Returns True if the currently focused widget or one of its ancestors has the given callable.
- spinetoolbox.helpers.call_on_focused_widget(parent, callable_name)[source]¶
Calls the given callable on the currently focused widget or one of its ancestors.
- class spinetoolbox.helpers.ChildCyclingKeyPressFilter[source]¶
Bases:
PySide2.QtCore.QObject
Event filter class for catching next and previous child key presses. Used in filtering the Ctrl+Tab and Ctrl+Shift+Tab key presses in the Item Properties tab widget.
- spinetoolbox.helpers.select_julia_executable(parent, line_edit)[source]¶
Opens file browser where user can select a Julia executable (i.e. julia.exe on Windows). Used in SettingsWidget and KernelEditor.
- Parameters
parent (QWidget, optional) – Parent widget for the file dialog and message boxes
line_edit (QLineEdit) – Line edit where the selected path will be inserted
- spinetoolbox.helpers.select_julia_project(parent, line_edit)[source]¶
Shows file browser and inserts selected julia project dir to give line_edit. Used in SettingsWidget and KernelEditor.
- Parameters
parent (QWidget, optional) – Parent of QFileDialog
line_edit (QLineEdit) – Line edit where the selected path will be inserted
- spinetoolbox.helpers.select_python_interpreter(parent, line_edit)[source]¶
Opens file browser where user can select a python interpreter (i.e. python.exe on Windows). Used in SettingsWidget and KernelEditor.
- Parameters
parent (QWidget) – Parent widget for the file dialog and message boxes
line_edit (QLineEdit) – Line edit where the selected path will be inserted
- spinetoolbox.helpers.file_is_valid(parent, file_path, msgbox_title, extra_check=None)[source]¶
Checks that given path is not a directory and it’s a file that actually exists. In addition, can be used to check if the file name in given file path starts with the given extra_check string. Needed in SettingsWidget and KernelEditor because the QLineEdits are editable. Returns True when file_path is an empty string so that we can use default values (e.g. from line edit place holder text). Returns also True when file_path is just ‘python’ or ‘julia’ so that user’s can use the python or julia in PATH.
- Parameters
parent (QWidget) – Parent widget for the message boxes
file_path (str) – Path to check
msgbox_title (str) – Title for message boxes
extra_check (str, optional) – String that must match the file name of the given file_path (without extension)
- Returns
True if given path is an empty string or if path is valid, False otherwise
- Return type
bool
- spinetoolbox.helpers.dir_is_valid(parent, dir_path, msgbox_title)[source]¶
Checks that given path is a directory. Needed in SettingsWdiget and KernelEditor because the QLineEdits are editable. Returns True when dir_path is an empty string so that we can use default values (e.g. from line edit place holder text)
- Parameters
parent (QWidget) – Parent widget for the message box
dir_path (str) – Directory path to check
msgbox_title (str) – Message box title
- Returns
True if given path is an empty string or if path is an existing directory, False otherwise
- Return type
bool
- spinetoolbox.helpers.make_settings_dict_for_engine(app_settings)[source]¶
Converts Toolbox settings to a dictionary acceptable by Engine.
- Parameters
app_settings (QSettings) – Toolbox settings
- Returns
Engine-compatible settings
- Return type
dict
spinetoolbox.link
¶
Classes for drawing graphics items on QGraphicsScene.
- authors
Marin (KTH), P. Savolainen (VTT)
- date
4.4.2018
Module Contents¶
Base class for Link and LinkDrawer. |
|
An icon to show over a Link. |
|
A graphics item to represent the connection between two project items. |
|
An item for drawing links between project items. |
- class spinetoolbox.link.LinkBase(toolbox)[source]¶
Bases:
PySide2.QtWidgets.QGraphicsPathItem
Base class for Link and LinkDrawer.
Mainly provides the
update_geometry
method for ‘drawing’ the link on the scene.- Parameters
toolbox (ToolboxUI) – main UI class instance
- moveBy(self, _dx, _dy)[source]¶
Does nothing. This item is not moved the regular way, but follows the ConnectorButtons it connects.
- do_update_geometry(self, guide_path)[source]¶
Sets the path for this item.
- Parameters
guide_path (QPainterPath) –
- _make_guide_path(self, curved_links)[source]¶
Returns a ‘narrow’ path connecting this item’s source and destination.
- Parameters
curved_links (bool) – Whether the path should follow a curved line or just a straight line
- Returns
QPainterPath
- _points_and_angles_from_path(self, path)[source]¶
Returns a list of representative points and angles from given path.
- Parameters
path (QPainterPath) –
- Returns
points list(float): angles
- Return type
list(QPointF)
- _make_connecting_path(self, guide_path)[source]¶
Returns a ‘thick’ path connecting source and destination, by following the given ‘guide’ path.
- Parameters
guide_path (QPainterPath) –
- Returns
QPainterPath
- class spinetoolbox.link._LinkIcon(x, y, w, h, parent)[source]¶
Bases:
PySide2.QtWidgets.QGraphicsEllipseItem
An icon to show over a Link.
- class spinetoolbox.link.Link(toolbox, src_connector, dst_connector, connection)[source]¶
Bases:
LinkBase
A graphics item to represent the connection between two project items.
- Parameters
toolbox (ToolboxUI) – main UI class instance
src_connector (ConnectorButton) – Source connector button
dst_connector (ConnectorButton) – Destination connector button
connection (spine_engine.project_item.Connection) – connection this link represents
- refresh_resource_filter_model(self)[source]¶
Makes resource filter mode fetch filter data from database.
- make_execution_animation(self, excluded)[source]¶
Returns an animation to play when execution ‘passes’ through this link.
- Returns
QVariantAnimation
- mousePressEvent(self, e)[source]¶
Ignores event if there’s a connector button underneath, to allow creation of new links.
- Parameters
e (QGraphicsSceneMouseEvent) – Mouse event
- class spinetoolbox.link.LinkDrawer(toolbox)[source]¶
Bases:
LinkBase
An item for drawing links between project items.
- Parameters
toolbox (ToolboxUI) – main UI class instance
- wake_up(self, src_connector)[source]¶
Sets the source connector, shows this item and adds it to the scene. After calling this, the scene is in link drawing mode.
- Parameters
src_connector (ConnectorButton) –
spinetoolbox.load_project_items
¶
Functions to load project item modules.
- author
Soininen (VTT)
- date
29.4.2020
Module Contents¶
Check if spine_items is the preferred version. |
|
|
Downloads spine_items to a temporary directory. |
|
Installs spine_items from a temporary directory. |
|
|
Upgrades project items. |
|
Loads the standard project item modules included in the Toolbox package. |
|
|
- spinetoolbox.load_project_items._spine_items_version_check()[source]¶
Check if spine_items is the preferred version.
- spinetoolbox.load_project_items._download_spine_items(tmpdirname)[source]¶
Downloads spine_items to a temporary directory.
- Parameters
tmpdirname (str) –
- spinetoolbox.load_project_items._install_spine_items(tmpdirname)[source]¶
Installs spine_items from a temporary directory.
- Parameters
tmpdirname (str) –
- spinetoolbox.load_project_items.upgrade_project_items()[source]¶
Upgrades project items.
- Returns
True if upgraded, False if no action taken.
- Return type
bool
spinetoolbox.logger_interface
¶
A logger interface.
- authors
Soininen (VTT)
- date
16.1.2020
Module Contents¶
Placeholder for signals that can be emitted to send messages to an output device. |
- class spinetoolbox.logger_interface.LoggerInterface[source]¶
Bases:
PySide2.QtCore.QObject
Placeholder for signals that can be emitted to send messages to an output device.
The signals should be connected to a concrete logging system.
Currently, this is just a ‘model interface’. ToolboxUI contains the same signals so it can be used as a drop-in replacement for this class.
- msg_proc[source]¶
Emits a message originating from a subprocess (usually something printed to stdout).
- msg_proc_error[source]¶
Emits an error message originating from a subprocess (usually something printed to stderr).
spinetoolbox.main
¶
Provides the main() function.
- author
Soininen (VTT)
- date
4.10.2019
Module Contents¶
|
Creates main window GUI and starts main event loop. |
Returns a command line argument parser configured for Toolbox use. |
spinetoolbox.metaobject
¶
MetaObject class.
- authors
Rinne (VTT), P. Savolainen (VTT)
- date
18.12.2017
Module Contents¶
Class for an object which has a name, type, and some description. |
- class spinetoolbox.metaobject.MetaObject(name, description)[source]¶
Bases:
PySide2.QtCore.QObject
Class for an object which has a name, type, and some description.
- Parameters
name (str) – Object name
description (str) – Object description
spinetoolbox.plotting
¶
Functions for plotting on PlotWidget.
Currently plotting from the table views found in the SpineDBEditor are supported.
The main entrance points to plotting are: - plot_selection() which plots selected cells on a table view returning a PlotWidget object - plot_pivot_column() which is a specialized method for plotting entire columns of a pivot table - add_time_series_plot() which adds a time series plot to an existing PlotWidget - add_map_plot() which adds a map plot to an existing PlotWidget
- author
Soininen(VTT)
- date
9.7.2019
Module Contents¶
A base class for plotting hints. |
|
Support for plotting data in Parameter table views. |
|
Support for plotting data in Tabular view. |
|
Returns a plot widget with a plot of an entire column in PivotTableModel. |
|
Returns a plot widget with plots of the selected indexes. |
|
Adds an array plot to a plot widget. |
|
Adds a map plot to a plot widget. |
|
Adds a time series step plot to a plot widget. |
|
Adds a new plot to plot_widget. |
|
Raises an exception if not all values are TimeSeries or Maps. |
|
Returns a dict with all but the entry with the greatest key removed. |
|
Organizes a list of model indexes into a dictionary of {column: (rows)} entries. |
|
Collects selected parameter values from a single column. |
|
Collects selected parameter values from an x column. |
|
Collects selected values from an index column. |
|
Collects selected parameter values from a single column for plotting. |
|
Gathers the leaf elements from |
|
Collects leaf values from given Maps and labels them. |
|
Filters Nones and empty values from x and y and checks that data types match. |
Raises an exception if the indexed values in values contain elements that cannot be plotted. |
|
|
Raises a PlottingError if values type is incompatible with plot_widget. |
|
Returns x value array constructed from model rows. |
- exception spinetoolbox.plotting.PlottingError(message)[source]¶
Bases:
Exception
An exception signalling failure in plotting.
- Parameters
message (str) – an error message
- spinetoolbox.plotting.plot_pivot_column(proxy_model, column, hints, plot_widget=None)[source]¶
Returns a plot widget with a plot of an entire column in PivotTableModel.
- Parameters
proxy_model (PivotTableSortFilterProxy) – a pivot table filter
column (int) – a column index to the model
hints (PlottingHints) – a helper needed for e.g. plot labels
plot_widget (PlotWidget) – an existing plot widget to draw into or None to create a new widget
- Returns
a plot widget
- Return type
- spinetoolbox.plotting.plot_selection(model, indexes, hints, plot_widget=None)[source]¶
Returns a plot widget with plots of the selected indexes.
- Parameters
model (QAbstractTableModel) – a model
indexes (Iterable) – a list of QModelIndex objects for plotting
hints (PlottingHints) – a helper needed for e.g. plot labels
plot_widget (PlotWidget) – an existing plot widget to draw into or None to create a new widget
- Returns
a PlotWidget object
- spinetoolbox.plotting.add_array_plot(plot_widget, value, label=None)[source]¶
Adds an array plot to a plot widget.
- Parameters
plot_widget (PlotWidget) – a plot widget to modify
value (Array) – the array to plot
label (str) – a label for the array
- spinetoolbox.plotting.add_map_plot(plot_widget, map_value, label=None)[source]¶
Adds a map plot to a plot widget.
- Parameters
plot_widget (PlotWidget) – a plot widget to modify
map_value (Map) – the map to plot
label (str) – a label for the map
- spinetoolbox.plotting.add_time_series_plot(plot_widget, value, label=None)[source]¶
Adds a time series step plot to a plot widget.
- Parameters
plot_widget (PlotWidget) – a plot widget to modify
value (TimeSeries) – the time series to plot
label (str) – a label for the time series
- class spinetoolbox.plotting.PlottingHints[source]¶
A base class for plotting hints.
The functionality in this class allows the plotting functions to work without explicit knowledge of the underlying table model or widget.
- abstract cell_label(self, model, index)[source]¶
Returns a label for the cell given by index in a table.
- abstract filter_columns(self, selections, model)[source]¶
Filters columns and returns the filtered selections.
- abstract is_index_in_data(self, model, index)[source]¶
Returns true if the cell given by index is actually plottable data.
- class spinetoolbox.plotting.ParameterTablePlottingHints[source]¶
Bases:
PlottingHints
Support for plotting data in Parameter table views.
- cell_label(self, model, index)[source]¶
Returns a label build from the columns on the left from the data column.
- class spinetoolbox.plotting.PivotTablePlottingHints[source]¶
Bases:
PlottingHints
Support for plotting data in Tabular view.
- is_index_in_data(self, model, index)[source]¶
Returns True if index is in the data portion of the table.
- special_x_values(self, model, column, rows)[source]¶
Returns the values from the X column if one is designated otherwise returns None.
- spinetoolbox.plotting._add_plot_to_widget(values, labels, plot_widget)[source]¶
Adds a new plot to plot_widget.
- spinetoolbox.plotting._raise_if_not_all_indexed_values(values)[source]¶
Raises an exception if not all values are TimeSeries or Maps.
- spinetoolbox.plotting._filter_name_columns(selections)[source]¶
Returns a dict with all but the entry with the greatest key removed.
- spinetoolbox.plotting._organize_selection_to_columns(indexes)[source]¶
Organizes a list of model indexes into a dictionary of {column: (rows)} entries.
- spinetoolbox.plotting._collect_single_column_values(model, column, rows, hints)[source]¶
Collects selected parameter values from a single column.
The return value of this function depends on what type of data the given column contains. In case of plain numbers, a list of scalars and a single label string are returned. In case of indexed parameters (time series, maps), a list of parameter_value objects is returned, accompanied by a list of labels, each label corresponding to one of the indexed parameters.
- Parameters
model (QAbstractTableModel) – a table model
column (int) – a column index to the model
rows (Sequence) – row indexes to plot
hints (PlottingHints) – a plot support object
- Returns
values and label(s)
- Return type
tuple
- spinetoolbox.plotting._collect_x_column_values(model, column, rows, hints)[source]¶
Collects selected parameter values from an x column.
- Parameters
model (QAbstractTableModel) – a table model
column (int) – a column index to the model
rows (Sequence) – row indexes to plot
hints (PlottingHints) – a plot support object
- Returns
a tuple of values and label(s)
- spinetoolbox.plotting._collect_index_column_values(model, column, rows, hints)[source]¶
Collects selected values from an index column.
- Parameters
model (QAbstractTableModel) – a table model
column (int) – a column index to the model
rows (Sequence) – row indexes to plot
hints (PlottingHints) – a plot support object
- Returns
column’s values
- Return type
list
- spinetoolbox.plotting._collect_column_values(model, column, rows, hints)[source]¶
Collects selected parameter values from a single column for plotting.
The return value of this function depends on what type of data the given column contains. In case of plain numbers, a single tuple of two lists of x and y values and a single label string are returned. In case of time series, a list of TimeSeries objects is returned, accompanied by a list of labels, each label corresponding to one of the time series.
- Parameters
model (QAbstractTableModel) – a table model
column (int) – a column index to the model
rows (Sequence) – row indexes to plot
hints (PlottingHints) – a support object
- Returns
a tuple of values and label(s)
- Return type
tuple
- spinetoolbox.plotting._expand_maps(maps, labels)[source]¶
Gathers the leaf elements from
maps
and expandslabels
accordingly.- Parameters
maps (list of Map) – maps to expand
labels (list of str) – map labels
- Returns
expanded maps and labels
- Return type
tuple
- spinetoolbox.plotting._label_nested_maps(map_, label)[source]¶
Collects leaf values from given Maps and labels them.
- Parameters
map (Map) – a map
label (str) – map’s label
- Returns
list of values and list of corresponding labels
- Return type
tuple
- spinetoolbox.plotting._filter_and_check(xs, ys)[source]¶
Filters Nones and empty values from x and y and checks that data types match.
- spinetoolbox.plotting._raise_if_indexed_values_not_plottable(values)[source]¶
Raises an exception if the indexed values in values contain elements that cannot be plotted.
spinetoolbox.plugin_manager
¶
Contains PluginManager class.
- author
Marin (KTH)
- date
21.2.2021
Module Contents¶
Class for managing plugins. |
|
|
|
|
- class spinetoolbox.plugin_manager.PluginManager(toolbox)[source]¶
Class for managing plugins.
- Parameters
toolbox (ToolboxUI) –
- load_individual_plugin(self, plugin_dir)[source]¶
Loads plugin from directory and returns all the specs in a list.
- Parameters
plugin_dir (str) – path of plugin dir with “plugin.json” in it.
- Returns
list(ProjectItemSpecification)
- _install_plugin(self, plugin_name)[source]¶
Installs plugin from the registry and loads it.
- Parameters
plugin_name (str) – plugin name
spinetoolbox.project
¶
Spine Toolbox project class.
- authors
Savolainen (VTT), E. Rinne (VTT)
- date
10.1.2018
Module Contents¶
Class for Spine Toolbox projects. |
|
Calculates node ranks. |
- class spinetoolbox.project.SpineToolboxProject(toolbox, name, description, p_dir, project_item_model, settings, logger)[source]¶
Bases:
spinetoolbox.metaobject.MetaObject
Class for Spine Toolbox projects.
- Parameters
toolbox (ToolboxUI) – toolbox of this project
name (str) – Project name
description (str) – Project description
p_dir (str) – Project directory
project_item_model (ProjectItemModel) – project item tree model
settings (QSettings) – Toolbox settings
logger (LoggerInterface) – a logger instance
- _create_project_structure(self, directory)[source]¶
Makes the given directory a Spine Toolbox project directory. Creates directories and files that are common to all projects.
- Parameters
directory (str) – Abs. path to a directory that should be made into a project directory
- Returns
True if project structure was created successfully, False otherwise
- Return type
bool
- set_description(self, description)[source]¶
Set object description.
- Parameters
description (str) – Object description
- save(self, spec_paths)[source]¶
Collects project information and objects into a dictionary and writes it to a JSON file.
- Parameters
spec_paths (dict) – List of absolute paths to specification files keyed by item type
- Returns
True or False depending on success
- Return type
bool
- load(self, items_dict, connection_dicts)[source]¶
Populates project item model with items loaded from project file.
- Parameters
items_dict (dict) – Dictionary containing all project items in JSON format
connection_dicts (list of dict) – List containing all connections in JSON format
- get_item(self, name)[source]¶
Returns project item.
- Parameters
name (str) – item’s name
- Returns
project item
- Return type
- get_items(self)[source]¶
Returns all project items.
- Returns
all project items
- Return type
list of ProjectItem
- add_project_items(self, items_dict, set_selected=False, verbosity=True)[source]¶
Pushes an AddProjectItemsCommand to the toolbox undo stack.
- make_project_tree_items(self, items_dict)[source]¶
Creates and returns a dictionary mapping category indexes to a list of corresponding LeafProjectTreeItem instances.
- Parameters
items_dict (dict) – a mapping from item name to item dict
- Returns
dict(QModelIndex, list(LeafProjectTreeItem))
- _do_add_project_tree_items(self, category_ind, *project_tree_items, set_selected=False, verbosity=True)[source]¶
Adds LeafProjectTreeItem instances to project.
- Parameters
category_ind (QModelIndex) – The category index
project_tree_items (LeafProjectTreeItem) – one or more LeafProjectTreeItem instances to add
set_selected (bool) – Whether to set item selected after the item has been added to project
verbosity (bool) – If True, prints message
- rename_item(self, previous_name, new_name, rename_data_dir_message)[source]¶
Renames a project item
- Parameters
previous_name (str) – item’s current name
new_name (str) – item’s new name
rename_data_dir_message (str) – message to show when renaming item’s data directory
- Returns
True if item was renamed successfully, False otherwise
- Return type
bool
- find_connection(self, source_name, destination_name)[source]¶
Searches for a connection between given items.
- Parameters
source_name (str) – source item’s name
destination_name (str) – destination item’s name
- Returns
connection instance or None if there is no connection
- Return type
Connection
- connections_for_item(self, item_name)[source]¶
Returns connections that have given item as source or destination.
- Parameters
item_name (str) – item’s name
- Returns
connections connected to item
- Return type
list of Connection
- add_connection(self, connection, silent=False)[source]¶
Adds a connection to the project.
- Parameters
connection (Connection) – connection to add
silent (bool) – If False, prints ‘Link establ…’ msg to Event Log
- Returns
True if connection was added successfully, False otherwise
- Return type
bool
- remove_connection(self, connection)[source]¶
Removes a connection from the project.
- Parameters
connection (Connection) – connection to remove
- replace_connection(self, existing_connection, new_connection)[source]¶
Replaces an existing connection between items.
Replacing does not trigger any updates to the DAG or project items.
- Parameters
existing_connection (Connection) – an established connection
new_connection (Connection) – connection to replace by
- set_item_selected(self, item)[source]¶
Selects the given item.
- Parameters
item (LeafProjectTreeItem) –
- make_and_add_project_items(self, items_dict, set_selected=False, verbosity=True)[source]¶
Adds items to project at loading.
- Parameters
items_dict (dict) – a mapping from item name to item dict
set_selected (bool) – Whether to set item selected after the item has been added to project
verbosity (bool) – If True, prints message
- remove_project_items(self, *indexes, ask_confirmation=False)[source]¶
Pushes a RemoveProjectItemsCommand to the toolbox undo stack.
- Parameters
*indexes (QModelIndex) – Indexes of the items in project item model
ask_confirmation (bool) – If True, shows ‘Are you sure?’ message box
- remove_item_by_name(self, item_name, delete_data=False)[source]¶
Removes project item by its name.
- Parameters
item_name (str) – Item’s name
delete_data (bool) – If set to True, deletes the directories and data associated with the item
- do_remove_project_tree_items(self, *items, delete_data=False, silent=False)[source]¶
Removes LeafProjectTreeItem instances from project.
- Parameters
*items (LeafProjectTreeItem) – the items to remove
delete_data (bool) – If set to True, deletes the directories and data associated with the item
silent (bool) – Used to prevent unnecessary log messages when switching projects
- execute_dags(self, dags, execution_permits, msg)[source]¶
Executes given dags.
- Parameters
dags (Sequence(DiGraph)) –
execution_permits (Sequence(dict)) –
- notify_resource_changes_to_predecessors(self, item)[source]¶
Updates resources for direct predecessors of given item.
- Parameters
item (ProjectItem) – item whose resources have changed
- notify_resource_changes_to_successors(self, item)[source]¶
Updates resources for direct successors and outgoing connections of given item.
- Parameters
item (ProjectItem) – item whose resources have changed
- _notify_resource_changes(self, trigger_name, target_names, provider_connections, update_resources, trigger_resources)[source]¶
Updates resources in given direction for immediate neighbours of an item.
- Parameters
trigger_name (str) – item whose resources have changed
target_names (list(str)) – items to be notified
provider_connections (function) – function that receives a target item name and returns a list of Connections from resource providers
update_resources (function) – function that takes an item name, a list of provider names, and a dictionary of resources, and does the updating
trigger_resources (list(ProjectItemResources)) – resources from the trigger item
- notify_resource_replacement_to_successors(self, item, old, new)[source]¶
Replaces a resource for direct successors and outgoing connections of given item.
- Parameters
item (ProjectItem) – item whose resources have changed
old (ProjectItemResource) – old resource
new (ProjectItemResource) – new resource
- notify_resource_replacement_to_predecessors(self, item, old, new)[source]¶
Replaces a resource for direct predecessors.
- Parameters
item (ProjectItem) – item whose resources have changed
old (ProjectItemResource) – old resource
new (ProjectItemResource) – new resource
- _update_item_resources(self, target_item, direction)[source]¶
Updates up or downstream resources for a single project item. Called in both directions after removing a Connection.
- Parameters
target_item (ProjectItem) – item whose resource need update
direction (ExecutionDirection) – FORWARD updates resources from upstream, BACKWARD from downstream
- successor_names(self, name)[source]¶
Collects direct successor item names.
- Parameters
name (str) – name of the project item whose successors to collect
- Returns
direct successor names
- Return type
set of str
- _outgoing_connections(self, name)[source]¶
Collects outgoing connections.
- Parameters
name (str) – name of the project item whose connections to collect
- Returns
outgoing connections
- Return type
set of Connection
spinetoolbox.project_commands
¶
QUndoCommand subclasses for modifying the project.
- authors
Marin (KTH)
- date
12.2.2020
Module Contents¶
Command to set the specification for a Tool. |
|
Command to move icons in the Design view. |
|
Command to set the project name. |
|
Command to set the project description. |
|
Command to add items. |
|
Command to remove all items from project. |
|
Command to remove items. |
|
Command to rename project items. |
|
Command to add connection between project items. |
|
Command to remove links. |
|
Command to toggle filter value. |
|
Command to set connection options. |
|
Command to add item specs to a project. |
|
Command to remove item specs from a project. |
- class spinetoolbox.project_commands.SpineToolboxCommand[source]¶
Bases:
PySide2.QtWidgets.QUndoCommand
- class spinetoolbox.project_commands.SetItemSpecificationCommand(item, specification)[source]¶
Bases:
SpineToolboxCommand
Command to set the specification for a Tool.
- Parameters
item (ProjectItem) – the Item
specification (ProjectItemSpecification) – the new spec
- class spinetoolbox.project_commands.MoveIconCommand(icon, project)[source]¶
Bases:
SpineToolboxCommand
Command to move icons in the Design view.
- Parameters
icon (ProjectItemIcon) – the icon
project (SpineToolboxProject) – project
- class spinetoolbox.project_commands.SetProjectNameCommand(project, name)[source]¶
Bases:
SpineToolboxCommand
Command to set the project name.
- Parameters
project (SpineToolboxProject) – the project
name (str) – The new name
- class spinetoolbox.project_commands.SetProjectDescriptionCommand(project, description)[source]¶
Bases:
SpineToolboxCommand
Command to set the project description.
- Parameters
project (SpineToolboxProject) – the project
description (str) – The new description
- class spinetoolbox.project_commands.AddProjectItemsCommand(project, items_dict, set_selected=False, verbosity=True)[source]¶
Bases:
SpineToolboxCommand
Command to add items.
- Parameters
project (SpineToolboxProject) – the project
items_dict (dict) – a mapping from item name to item dict
set_selected (bool) – Whether to set item selected after the item has been added to project
verbosity (bool) – If True, prints message
- class spinetoolbox.project_commands.RemoveAllProjectItemsCommand(project, delete_data=False)[source]¶
Bases:
SpineToolboxCommand
Command to remove all items from project.
- Parameters
project (SpineToolboxProject) – the project
delete_data (bool) – If True, deletes the directories and data associated with the items
- class spinetoolbox.project_commands.RemoveProjectItemsCommand(project, item_names, delete_data=False)[source]¶
Bases:
SpineToolboxCommand
Command to remove items.
- Parameters
project (SpineToolboxProject) – The project
item_names (list of str) – Item names
delete_data (bool) – If True, deletes the directories and data associated with the item
- class spinetoolbox.project_commands.RenameProjectItemCommand(project, previous_name, new_name)[source]¶
Bases:
SpineToolboxCommand
Command to rename project items.
- Parameters
project (SpineToolboxProject) – the project
previous_name (str) – item’s previous name
new_name (str) – the new name
- class spinetoolbox.project_commands.AddConnectionCommand(project, source_name, source_position, destination_name, destination_position)[source]¶
Bases:
SpineToolboxCommand
Command to add connection between project items.
- Parameters
project (SpineToolboxProject) – project
source_name (str) – source item’s name
source_position (str) – link’s position on source item’s icon
destination_name (str) – destination item’s name
destination_position (str) – link’s position on destination item’s icon
- class spinetoolbox.project_commands.RemoveConnectionsCommand(project, connections)[source]¶
Bases:
SpineToolboxCommand
Command to remove links.
- Parameters
project (SpineToolboxProject) – project
connections (list of Connection) – the connections
- class spinetoolbox.project_commands.SetFiltersOnlineCommand(resource_filter_model, resource, filter_type, online)[source]¶
Bases:
SpineToolboxCommand
Command to toggle filter value.
- Parameters
resource_filter_model (ResourceFilterModel) – filter model
resource (str) – resource label
filter_type (str) – filter type identifier
online (dict) – mapping from scenario/tool id to online flag
- class spinetoolbox.project_commands.SetConnectionOptionsCommand(link, options)[source]¶
Bases:
SpineToolboxCommand
Command to set connection options.
- Parameters
link (Link) –
options (dict) – containing options to be set
- class spinetoolbox.project_commands.AddSpecificationCommand(toolbox, specification)[source]¶
Bases:
SpineToolboxCommand
Command to add item specs to a project.
- Parameters
toolbox (ToolboxUI) – the toolbox
specification (ProjectItemSpecification) – the spec
- class spinetoolbox.project_commands.RemoveSpecificationCommand(toolbox, row, ask_verification)[source]¶
Bases:
SpineToolboxCommand
Command to remove item specs from a project.
- Parameters
toolbox (ToolboxUI) – the toolbox
row (int) – the row in the ProjectItemSpecPaletteModel
ask_verification (bool) – if True, shows confirmation message the first time
spinetoolbox.project_item_icon
¶
Classes for drawing graphics items on QGraphicsScene.
- authors
Marin (KTH), P. Savolainen (VTT)
- date
4.4.2018
Module Contents¶
Base class for project item icons drawn in Design View. |
|
Connector button graphics item. Used for Link drawing between project items. |
|
An icon to show information about the item’s execution. |
|
An icon to notify that a ProjectItem is missing some configuration. |
|
An icon to show the rank of a ProjectItem within its DAG. |
- class spinetoolbox.project_item_icon.ProjectItemIcon(toolbox, icon_file, icon_color)[source]¶
Bases:
PySide2.QtWidgets.QGraphicsRectItem
Base class for project item icons drawn in Design View.
- Parameters
toolbox (ToolboxUI) – QMainWindow instance
icon_file (str) – Path to icon resource
icon_color (QColor) – Icon’s color
- finalize(self, name, x, y)[source]¶
Names the icon and moves it by given amount.
- Parameters
name (str) – icon’s name
x (int) – horizontal offset
y (int) – vertical offset
- _setup(self, brush, svg, svg_color)[source]¶
Setup item’s attributes.
- Parameters
brush (QBrush) – Used in filling the background rectangle
svg (str) – Path to SVG icon file
svg_color (QColor) – Color of SVG icon
- name(self)[source]¶
Returns name of the item that is represented by this icon.
- Returns
icon’s name
- Return type
str
- update_name_item(self, new_name)[source]¶
Set a new text to name item.
- Parameters
new_name (str) – icon’s name
- set_name_attributes(self)[source]¶
Set name QGraphicsSimpleTextItem attributes (font, size, position, etc.)
- conn_button(self, position='left')[source]¶
Returns item’s connector button.
- Parameters
position (str) – “left”, “right” or “bottom”
- Returns
connector button
- Return type
QWidget
- outgoing_links(self)[source]¶
Collects outgoing links.
- Returns
outgoing links
- Return type
list of LinkBase
- incoming_links(self)[source]¶
Collects incoming links.
- Returns
outgoing links
- Return type
list of LinkBase
- run_execution_leave_animation(self, excluded)[source]¶
Starts the animation associated with execution leaving the icon.
- Parameters
excluded (bool) – True if project item was not actually executed.
- hoverEnterEvent(self, event)[source]¶
Sets a drop shadow effect to icon when mouse enters its boundaries.
- Parameters
event (QGraphicsSceneMouseEvent) – Event
- hoverLeaveEvent(self, event)[source]¶
Disables the drop shadow when mouse leaves icon boundaries.
- Parameters
event (QGraphicsSceneMouseEvent) – Event
- mouseMoveEvent(self, event)[source]¶
Moves icon(s) while the mouse button is pressed. Update links that are connected to selected icons.
- Parameters
event (QGraphicsSceneMouseEvent) – Event
- update_links_geometry(self)[source]¶
Updates geometry of connected links to reflect this item’s most recent position.
- contextMenuEvent(self, event)[source]¶
Show item context menu.
- Parameters
event (QGraphicsSceneMouseEvent) – Mouse event
- itemChange(self, change, value)[source]¶
Reacts to item removal and position changes.
In particular, destroys the drop shadow effect when the items is removed from a scene and keeps track of item’s movements on the scene.
- Parameters
change (GraphicsItemChange) – a flag signalling the type of the change
value – a value related to the change
- Returns
Whatever super() does with the value parameter
- class spinetoolbox.project_item_icon.ConnectorButton(parent, toolbox, position='left')[source]¶
Bases:
PySide2.QtWidgets.QGraphicsRectItem
Connector button graphics item. Used for Link drawing between project items.
- Parameters
parent (QGraphicsItem) – Project item bg rectangle
toolbox (ToolboxUI) – QMainWindow instance
position (str) – Either “top”, “left”, “bottom”, or “right”
- project_item(self)[source]¶
Returns the project item this connector button is attached to.
- Returns
project item
- Return type
- mousePressEvent(self, event)[source]¶
Connector button mouse press event. Either starts or closes a link.
- Parameters
event (QGraphicsSceneMouseEvent) – Event
- set_friend_connectors_enabled(self, enabled)[source]¶
Enables or disables all connectors in the parent. This is called by LinkDrawer to disable invalid connectors while drawing and reenabling them back when done.
- mouseDoubleClickEvent(self, event)[source]¶
Connector button mouse double click event. Makes sure the LinkDrawer is hidden.
- Parameters
event (QGraphicsSceneMouseEvent) – Event
- hoverEnterEvent(self, event)[source]¶
Sets a darker shade to connector button when mouse enters its boundaries.
- Parameters
event (QGraphicsSceneMouseEvent) – Event
- class spinetoolbox.project_item_icon.ExecutionIcon(parent)[source]¶
Bases:
PySide2.QtWidgets.QGraphicsEllipseItem
An icon to show information about the item’s execution.
- Parameters
parent (ProjectItemIcon) – the parent item
- class spinetoolbox.project_item_icon.ExclamationIcon(parent)[source]¶
Bases:
PySide2.QtWidgets.QGraphicsTextItem
An icon to notify that a ProjectItem is missing some configuration.
- Parameters
parent (ProjectItemIcon) – the parent item
- remove_notification(self, subtext)[source]¶
Remove the first notification that includes given subtext.
- class spinetoolbox.project_item_icon.RankIcon(parent)[source]¶
Bases:
PySide2.QtWidgets.QGraphicsTextItem
An icon to show the rank of a ProjectItem within its DAG.
- Parameters
parent (ProjectItemIcon) – the parent item
spinetoolbox.project_tree_item
¶
Project Tree items.
- authors
Soininen (VTT)
- date
17.1.2020
Module Contents¶
Base class for all project tree items. |
|
Class for the root project tree item. |
|
Class for category project tree items. |
|
Class for leaf items in the project item tree. |
- class spinetoolbox.project_tree_item.BaseProjectTreeItem(name, description)[source]¶
Bases:
spinetoolbox.metaobject.MetaObject
Base class for all project tree items.
- Parameters
name (str) – Object name
description (str) – Object description
- child(self, row)[source]¶
Returns child BaseProjectTreeItem on given row.
- Parameters
row (int) – Row of child to return
- Returns
item on given row or None if it does not exist
- Return type
- remove_child(self, row)[source]¶
Remove the child of this BaseProjectTreeItem from given row. Do not call this method directly. This method is called by ProjectItemTreeModel when items are removed.
- Parameters
row (int) – Row of child to remove
- Returns
True if operation succeeded, False otherwise
- Return type
bool
Returns the context menu for this item. Implement in subclasses as needed.
- Parameters
toolbox (QWidget) – The widget that is controlling the menu
- Returns
context menu
- Return type
QMenu
- class spinetoolbox.project_tree_item.RootProjectTreeItem[source]¶
Bases:
BaseProjectTreeItem
Class for the root project tree item.
- Parameters
name (str) – Object name
description (str) – Object description
- add_child(self, child_item)[source]¶
Adds given category item as the child of this root project tree item. New item is added as the last item.
- Parameters
child_item (CategoryProjectTreeItem) – Item to add
- Returns
True for success, False otherwise
See base class.
- class spinetoolbox.project_tree_item.CategoryProjectTreeItem(name, description)[source]¶
Bases:
BaseProjectTreeItem
Class for category project tree items.
- Parameters
name (str) – Object name
description (str) – Object description
- add_child(self, child_item)[source]¶
Adds given project tree item as the child of this category item. New item is added as the last item.
- Parameters
child_item (LeafProjectTreeTreeItem) – Item to add
- Returns
True for success, False otherwise
Returns the context menu for this item.
- Parameters
toolbox (ToolboxUI) – Toolbox main window
- Returns
context menu
- Return type
QMenu
- class spinetoolbox.project_tree_item.LeafProjectTreeItem(project_item, toolbox)[source]¶
Bases:
BaseProjectTreeItem
Class for leaf items in the project item tree.
- Parameters
project_item (ProjectItem) – the real project item this item represents
toolbox (ToolboxUI) – a toolbox instance
Returns the context menu for this item.
- Parameters
toolbox (ToolboxUI) – Toolbox main window
- Returns
context menu
- Return type
QMenu
spinetoolbox.project_upgrader
¶
Contains ProjectUpgrader class used in upgrading and converting projects and project dicts from earlier versions to the latest version.
- authors
Savolainen (VTT)
- date
8.11.2019
Module Contents¶
Class to upgrade/convert projects from earlier versions to the current version. |
|
Replaces ‘1d array’ with ‘array’ for parameter type in Importer mappings. |
- class spinetoolbox.project_upgrader.ProjectUpgrader(toolbox)[source]¶
Class to upgrade/convert projects from earlier versions to the current version.
- Parameters
toolbox (ToolboxUI) – App main window instance
- upgrade(self, project_dict, project_dir)[source]¶
Upgrades the project described in given project dictionary to the latest version.
- Parameters
project_dict (dict) – Project configuration dictionary
project_dir (str) – Path to current project directory
- Returns
Latest version of the project info dictionary
- Return type
dict
- upgrade_to_latest(self, v, project_dict, project_dir)[source]¶
Upgrades the given project dictionary to the latest version.
- Parameters
v (int) – Current version of the project dictionary
project_dict (dict) – Project dictionary (JSON) to be upgraded
project_dir (str) – Path to current project directory
- Returns
Upgraded project dictionary
- Return type
dict
- static upgrade_v1_to_v2(old, factories)[source]¶
Upgrades version 1 project dictionary to version 2.
- Changes:
objects -> items, tool_specifications -> specifications store project item dicts under [“items”][<project item name>] instead of using their categories as keys specifications must be a dict instead of a list Add specifications[“Tool”] that must be a dict Remove “short name” from all project items
- Parameters
old (dict) – Version 1 project dictionary
factories (dict) – Mapping of item type to item factory
- Returns
Version 2 project dictionary
- Return type
dict
- upgrade_v2_to_v3(self, old, project_dir, factories)[source]¶
Upgrades version 2 project dictionary to version 3.
- Changes:
Move “specifications” from “project” -> “Tool” to just “project”
The “mappings” from importer items are used to build Importer specifications
- Parameters
old (dict) – Version 2 project dictionary
project_dir (str) – Path to current project directory
factories (dict) – Mapping of item type to item factory
- Returns
Version 3 project dictionary
- Return type
dict
- static upgrade_v3_to_v4(old)[source]¶
Upgrades version 3 project dictionary to version 4.
- Changes:
Rename “Exporter” item type to “GdxExporter”
- Parameters
old (dict) – Version 3 project dictionary
- Returns
Version 4 project dictionary
- Return type
dict
- static upgrade_v4_to_v5(old)[source]¶
Upgrades version 4 project dictionary to version 5.
- Changes:
Get rid of “Combiner” items.
- Parameters
old (dict) – Version 4 project dictionary
- Returns
Version 5 project dictionary
- Return type
dict
- static upgrade_v5_to_v6(old, project_dir)[source]¶
Upgrades version 5 project dictionary to version 6.
- Changes:
Data store URL labels do not have ‘{’ and ‘}’ anymore
Importer stores resource labels instead of serialized paths in “file_selection”.
Gimlet’s “selections” is now called “file_selection”
Gimlet stores resource labels instead of serialized paths in “file_selection”.
Gimlet and Tool store command line arguments as serialized CmdLineArg objects, not serialized paths
- Parameters
old (dict) – Version 5 project dictionary
- Returns
Version 6 project dictionary
- Return type
dict
- get_project_directory(self)[source]¶
Asks the user to select a new project directory. If the selected directory is already a Spine Toolbox project directory, asks if overwrite is ok. Used when opening a project from an old style project file (.proj).
- Returns
Path to project directory or an empty string if operation is canceled.
- Return type
str
- is_valid_v1(self, p)[source]¶
Checks that the given project JSON dictionary contains a valid version 1 Spine Toolbox project. Valid meaning, that it contains all required keys and values are of the correct type.
- Parameters
p (dict) – Project information JSON
- Returns
True if project is a valid version 1 project, False if it is not
- Return type
bool
- is_valid_v2_to_6(self, p, v)[source]¶
Checks that the given project JSON dictionary contains a valid version 2 to 6 Spine Toolbox project. Valid meaning, that it contains all required keys and values are of the correct type.
- Parameters
p (dict) – Project information JSON
v (int) – Version
- Returns
True if project is a valid version 2 project, False if it is not
- Return type
bool
spinetoolbox.spine_db_commands
¶
QUndoCommand subclasses for modifying the db.
- authors
Marin (KTH)
- date
31.1.2020
Module Contents¶
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- class spinetoolbox.spine_db_commands.AgedUndoCommand(parent=None)[source]¶
Bases:
PySide2.QtWidgets.QUndoCommand
- Parameters
parent (QUndoCommand, optional) – The parent command, used for defining macros.
- class spinetoolbox.spine_db_commands.SpineDBCommand(db_mngr, db_map, parent=None)[source]¶
Bases:
AgedUndoCommand
- Parameters
db_mngr (SpineDBManager) – SpineDBManager instance
db_map (DiffDatabaseMapping) – DiffDatabaseMapping instance
parent (QUndoCommand, optional) – The parent command, used for defining macros.
- static redomethod(func)[source]¶
Returns a new redo method that determines if the command was completed. The command is completed if calling the function triggers the
completed_signal
. Once the command is completed, we don’t listen to the signal anymore and we also silence the affected Spine db editors. If the signal is not received, then the command is declared obsolete.
- class spinetoolbox.spine_db_commands.AddItemsCommand(db_mngr, db_map, data, item_type, parent=None)[source]¶
Bases:
SpineDBCommand
- Parameters
db_mngr (SpineDBManager) – SpineDBManager instance
db_map (DiffDatabaseMapping) – DiffDatabaseMapping instance
data (list) – list of dict-items to add
item_type (str) – the item type
parent (QUndoCommand, optional) – The parent command, used for defining macros.
- class spinetoolbox.spine_db_commands.CheckAddParameterValuesCommand(db_mngr, db_map, data, parent=None)[source]¶
Bases:
AddItemsCommand
- Parameters
db_mngr (SpineDBManager) – SpineDBManager instance
db_map (DiffDatabaseMapping) – DiffDatabaseMapping instance
data (list) – list of dict-items to add
item_type (str) – the item type
parent (QUndoCommand, optional) – The parent command, used for defining macros.
- class spinetoolbox.spine_db_commands.UpdateItemsCommand(db_mngr, db_map, data, item_type, parent=None)[source]¶
Bases:
SpineDBCommand
- Parameters
db_mngr (SpineDBManager) – SpineDBManager instance
db_map (DiffDatabaseMapping) – DiffDatabaseMapping instance
data (list) – list of dict-items to update
item_type (str) – the item type
parent (QUndoCommand, optional) – The parent command, used for defining macros.
- class spinetoolbox.spine_db_commands.CheckUpdateParameterValuesCommand(db_mngr, db_map, data, parent=None)[source]¶
Bases:
UpdateItemsCommand
- Parameters
db_mngr (SpineDBManager) – SpineDBManager instance
db_map (DiffDatabaseMapping) – DiffDatabaseMapping instance
data (list) – list of dict-items to update
item_type (str) – the item type
parent (QUndoCommand, optional) – The parent command, used for defining macros.
- class spinetoolbox.spine_db_commands.RemoveItemsCommand(db_mngr, db_map, typed_data, parent=None)[source]¶
Bases:
SpineDBCommand
- Parameters
db_mngr (SpineDBManager) – SpineDBManager instance
db_map (DiffDatabaseMapping) – DiffDatabaseMapping instance
typed_data (dict) – lists of dict-items to remove keyed by string type
parent (QUndoCommand, optional) – The parent command, used for defining macros.
spinetoolbox.spine_db_fetcher
¶
SpineDBFetcher class.
- authors
Marin (KTH)
- date
13.3.2020
Module Contents¶
Fetches content from a Spine database. |
- class spinetoolbox.spine_db_fetcher.SpineDBFetcher(db_mngr, mini)[source]¶
Bases:
PySide2.QtCore.QObject
Fetches content from a Spine database.
Initializes the fetcher object.
- Parameters
db_mngr (SpineDBManager) – used for fetching.
mini (MiniSpineDBManager) – used for signalling about the fetching. It has the same cache and icon_mngr as db_mngr but not the same signaller. This means we can signal only to a specific listener.
spinetoolbox.spine_db_icon_manager
¶
Provides SpineDBIconManager.
- authors
Marin (KTH)
- date
3.2.2021
Module Contents¶
A class to manage object_class icons for spine db editors. |
|
Specialization of QIconEngine used to draw scene-based icons. |
|
|
|
- class spinetoolbox.spine_db_icon_manager._SceneSvgRenderer[source]¶
Bases:
PySide2.QtSvg.QSvgRenderer
- class spinetoolbox.spine_db_icon_manager.SpineDBIconManager[source]¶
A class to manage object_class icons for spine db editors.
- class spinetoolbox.spine_db_icon_manager.SceneIconEngine(scene)[source]¶
Bases:
spinetoolbox.helpers.TransparentIconEngine
Specialization of QIconEngine used to draw scene-based icons.
spinetoolbox.spine_db_manager
¶
The SpineDBManager class
- authors
Vennström (VTT) and M. Marin (KTH)
- date
2.10.2019
Module Contents¶
Class to manage DBs within a project. |
|
Class to manage DBs within a project. |
|
Class to manage DBs within a project. |
Creates a new spine database at the given url. |
|
|
- spinetoolbox.spine_db_manager.do_create_new_spine_database(url)[source]¶
Creates a new spine database at the given url.
- class spinetoolbox.spine_db_manager.SpineDBManagerBase(parent, cache, icon_mngr)[source]¶
Bases:
PySide2.QtCore.QObject
Class to manage DBs within a project.
TODO: Expand description, how it works, the cache, the signals, etc.
Initializes the instance.
- Parameters
parent (QObject, optional) – parent object
- cache_items(self, item_type, db_map_data)[source]¶
Caches data for a given type. It works for both insert and update operations.
- Parameters
item_type (str) –
db_map_data (dict) – lists of dictionary items keyed by DiffDatabaseMapping
- class spinetoolbox.spine_db_manager.MiniSpineDBManager(parent, cache, icon_mngr)[source]¶
Bases:
SpineDBManagerBase
Class to manage DBs within a project.
TODO: Expand description, how it works, the cache, the signals, etc.
Initializes the instance.
- Parameters
parent (QObject, optional) – parent object
- class spinetoolbox.spine_db_manager.SpineDBManager(settings, parent)[source]¶
Bases:
SpineDBManagerBase
Class to manage DBs within a project.
TODO: Expand description, how it works, the cache, the signals, etc.
Initializes the instance.
- Parameters
settings (QSettings) – Toolbox settings
parent (QObject, optional) – parent object
- db_map(self, url)[source]¶
Returns a database mapping for given URL.
- Parameters
url (str) – a database URL
- Returns
a database map or None if not found
- Return type
DiffDatabaseMapping
- close_session(self, url)[source]¶
Pops any db map on the given url and closes its connection.
- Parameters
url (str) –
- get_db_map(self, url, logger, codename=None, upgrade=False, create=False)[source]¶
Returns a DiffDatabaseMapping instance from url if possible, None otherwise. If needed, asks the user to upgrade to the latest db version.
- Parameters
url (str, URL) –
logger (LoggerInterface) –
codename (str, NoneType, optional) –
upgrade (bool, optional) –
create (bool, optional) –
- Returns
DiffDatabaseMapping, NoneType
- _do_get_db_map(self, url, codename, upgrade, create)[source]¶
Returns a memorized DiffDatabaseMapping instance from url. Called by get_db_map.
- Parameters
url (str, URL) –
codename (str, NoneType) –
upgrade (bool) –
create (bool) –
- Returns
DiffDatabaseMapping
- register_listener(self, listener, *db_maps)[source]¶
Register given listener for all given db_map’s signals.
- Parameters
listener (object) –
db_maps (DiffDatabaseMapping) –
- unregister_listener(self, listener, *db_maps)[source]¶
Unregisters given listener from given db_map signals. If any of the db_maps becomes an orphan and is dirty, prompts user to commit or rollback.
- Parameters
listener (object) –
db_maps (DiffDatabaseMapping) –
- Returns
True if operation was successful, False otherwise
- Return type
bool
- _prompt_to_commit_changes(self)[source]¶
Prompts the user to commit or rollback changes to ‘dirty’ db maps.
- Returns
True to commit, False to rollback, None to do nothing
- Return type
bool
- commit_session(self, *db_maps, cookie=None)[source]¶
Commits the current session.
- Parameters
*db_maps – database maps to commit
cookie (object, optional) – a free form identifier which will be forwarded to
session_committed
signal
- entity_class_renderer(self, db_map, entity_type, entity_class_id, for_group=False)[source]¶
Returns an icon renderer for a given entity class.
- Parameters
db_map (DiffDatabaseMapping) – database map
entity_type (str) – either ‘object_class’ or ‘relationship_class’
entity_class_id (int) – entity class’ id
for_group (bool) – if True, return the group object icon instead
- Returns
requested renderer or None if no entity class was found
- Return type
QSvgRenderer
- entity_class_icon(self, db_map, entity_type, entity_class_id, for_group=False)[source]¶
Returns an appropriate icon for a given entity class.
- Parameters
db_map (DiffDatabaseMapping) – database map
entity_type (str) – either ‘object_class’ or ‘relationship_class’
entity_class_id (int) – entity class’ id
for_group (bool) – if True, return the group object icon instead
- Returns
requested icon or None if no entity class was found
- Return type
QIcon
- get_item(self, db_map, item_type, id_)[source]¶
Returns the item of the given type in the given db map that has the given id, or an empty dict if not found.
- Parameters
db_map (DiffDatabaseMapping) –
item_type (str) –
id (int) –
- Returns
dict
- get_item_by_field(self, db_map, item_type, field, value)[source]¶
Returns the first item of the given type in the given db map that has the given value for the given field Returns an empty dictionary if none found.
- Parameters
db_map (DiffDatabaseMapping) –
item_type (str) –
field (str) –
value –
- Returns
dict
- get_items_by_field(self, db_map, item_type, field, value)[source]¶
Returns all items of the given type in the given db map that have the given value for the given field. Returns an empty list if none found.
- Parameters
db_map (DiffDatabaseMapping) –
item_type (str) –
field (str) –
value –
- Returns
list
- get_items(self, db_map, item_type)[source]¶
Returns all the items of the given type in the given db map, or an empty list if none found.
- Parameters
db_map (DiffDatabaseMapping) –
item_type (str) –
- Returns
list
- static display_data_from_parsed(parsed_data)[source]¶
Returns the value’s database representation formatted for Qt.DisplayRole.
- static tool_tip_data_from_parsed(parsed_data)[source]¶
Returns the value’s database representation formatted for Qt.ToolTipRole.
- get_value(self, db_map, item_type, id_, role=Qt.DisplayRole)[source]¶
Returns the value or default value of a parameter.
- Parameters
db_map (DiffDatabaseMapping) –
item_type (str) – either “parameter_definition” or “parameter_value”
id (int) – The parameter_value or definition id
role (int, optional) –
- format_value(self, parsed_value, role=Qt.DisplayRole)[source]¶
Formats the given value for the given role.
- Parameters
parsed_value (object) – A python object as returned by spinedb_api.from_database
role (int, optional) –
- get_value_indexes(self, db_map, item_type, id_)[source]¶
Returns the value or default value indexes of a parameter.
- Parameters
db_map (DiffDatabaseMapping) –
item_type (str) – either “parameter_definition” or “parameter_value”
id (int) – The parameter_value or definition id
- get_value_index(self, db_map, item_type, id_, index, role=Qt.DisplayRole)[source]¶
Returns the value or default value of a parameter for a given index.
- Parameters
db_map (DiffDatabaseMapping) –
item_type (str) – either “parameter_definition” or “parameter_value”
id (int) – The parameter_value or definition id
index – The index to retrieve
role (int, optional) –
- get_value_list_item(self, db_map, id_, index, role=Qt.DisplayRole)[source]¶
Returns one value item of a parameter_value_list.
- Parameters
db_map (DiffDatabaseMapping) –
id (int) – The parameter_value_list id
index (int) – The value item index
role (int, optional) –
- get_parameter_value_list(self, db_map, id_, role=Qt.DisplayRole)[source]¶
Returns a parameter_value_list formatted for the given role.
- Parameters
db_map (DiffDatabaseMapping) –
id (int) – The parameter_value_list id
role (int, optional) –
- static get_db_items(query, chunk_size=1000)[source]¶
Runs the given query and yields results by chunks of given size.
- Yields
generator(list)
- static _make_query(db_map, sq_name, ids=(), key=('id'))[source]¶
Makes a database query
- Parameters
db_map (DatabaseMappingBase) – database map
sq_name (str) – name of the subquery
ids (Iterable of int) – ids by which the query should be filtered
- Returns
database subquery
- Return type
Alias
- get_alternatives(self, db_map, ids=())[source]¶
Returns alternatives from database.
- Parameters
db_map (DatabaseMappingBase) – database map
ids (Iterable of int) – ids by which the alternatives should be filtered
- Yields
list – dictionary items
- get_scenarios(self, db_map, ids=())[source]¶
Returns scenarios from database.
- Parameters
db_map (DiffDatabaseMapping) –
- Yields
list – dictionary items
- get_scenario_alternatives(self, db_map, ids=())[source]¶
Returns scenario alternatives from database.
- Parameters
db_map (DiffDatabaseMapping) –
- Yields
list – dictionary items
- get_object_classes(self, db_map, ids=())[source]¶
Returns object classes from database.
- Parameters
db_map (DiffDatabaseMapping) –
- Yields
list – dictionary items
- get_objects(self, db_map, ids=())[source]¶
Returns objects from database.
- Parameters
db_map (DiffDatabaseMapping) –
- Yields
list – dictionary items
- get_relationship_classes(self, db_map, ids=())[source]¶
Returns relationship classes from database.
- Parameters
db_map (DiffDatabaseMapping) –
- Yields
list – dictionary items
- get_relationships(self, db_map, ids=())[source]¶
Returns relationships from database.
- Parameters
db_map (DiffDatabaseMapping) –
- Yields
list – dictionary items
- get_entity_groups(self, db_map, ids=())[source]¶
Returns entity groups from database.
- Parameters
db_map (DiffDatabaseMapping) –
- Yields
list – dictionary items
- get_object_parameter_definitions(self, db_map, ids=())[source]¶
Returns object parameter definitions from database.
- Parameters
db_map (DiffDatabaseMapping) –
- Yields
list – dictionary items
- get_relationship_parameter_definitions(self, db_map, ids=())[source]¶
Returns relationship parameter definitions from database.
- Parameters
db_map (DiffDatabaseMapping) –
- Yields
list – dictionary items
- get_parameter_definitions(self, db_map, ids=())[source]¶
Returns both object and relationship parameter definitions.
- Parameters
db_map (DiffDatabaseMapping) –
- Yields
list – dictionary items
- get_parameter_definition_tags(self, db_map, ids=())[source]¶
Returns parameter definition tags.
- Parameters
db_map (DiffDatabaseMapping) –
- Yields
list – dictionary items
- get_object_parameter_values(self, db_map, ids=())[source]¶
Returns object parameter values from database.
- Parameters
db_map (DiffDatabaseMapping) –
- Yields
list – dictionary items
- get_relationship_parameter_values(self, db_map, ids=())[source]¶
Returns relationship parameter values from database.
- Parameters
db_map (DiffDatabaseMapping) –
- Yields
list – dictionary items
- get_parameter_values(self, db_map, ids=())[source]¶
Returns both object and relationship parameter values.
- Parameters
db_map (DiffDatabaseMapping) –
- Yields
list – dictionary items
- get_parameter_value_lists(self, db_map, ids=())[source]¶
Returns parameter_value lists from database.
- Parameters
db_map (DiffDatabaseMapping) –
- Yields
list – dictionary items
- get_parameter_tags(self, db_map, ids=())[source]¶
Get parameter tags from database.
- Parameters
db_map (DiffDatabaseMapping) –
- Yields
list – dictionary items
- get_features(self, db_map, ids=())[source]¶
Returns features from database.
- Parameters
db_map (DiffDatabaseMapping) –
- Yields
list – dictionary items
- get_tools(self, db_map, ids=())[source]¶
Get tools from database.
- Parameters
db_map (DiffDatabaseMapping) –
- Yields
list – dictionary items
- get_tool_features(self, db_map, ids=())[source]¶
Returns tool features from database.
- Parameters
db_map (DiffDatabaseMapping) –
- Yields
list – dictionary items
- get_tool_feature_methods(self, db_map, ids=())[source]¶
Returns tool feature methods from database.
- Parameters
db_map (DiffDatabaseMapping) –
- Yields
list – dictionary items
- import_data(self, db_map_data, command_text='Import data')[source]¶
Imports the given data into given db maps using the dedicated import functions from spinedb_api. Condenses all in a single command for undo/redo.
- Parameters
db_map_data (dict(DiffDatabaseMapping, dict())) – Maps dbs to data to be passed as keyword arguments to get_data_for_import
command_text (str, optional) – What to call the command that condenses the operation.
- add_alternatives(self, db_map_data)[source]¶
Adds alternatives to db.
- Parameters
db_map_data (dict) – lists of items to add keyed by DiffDatabaseMapping
- add_scenarios(self, db_map_data)[source]¶
Adds scenarios to db.
- Parameters
db_map_data (dict) – lists of items to add keyed by DiffDatabaseMapping
- add_object_classes(self, db_map_data)[source]¶
Adds object classes to db.
- Parameters
db_map_data (dict) – lists of items to add keyed by DiffDatabaseMapping
- add_objects(self, db_map_data)[source]¶
Adds objects to db.
- Parameters
db_map_data (dict) – lists of items to add keyed by DiffDatabaseMapping
- add_relationship_classes(self, db_map_data)[source]¶
Adds relationship classes to db.
- Parameters
db_map_data (dict) – lists of items to add keyed by DiffDatabaseMapping
- add_relationships(self, db_map_data)[source]¶
Adds relationships to db.
- Parameters
db_map_data (dict) – lists of items to add keyed by DiffDatabaseMapping
- add_object_groups(self, db_map_data)[source]¶
Adds object groups to db.
- Parameters
db_map_data (dict) – lists of items to add keyed by DiffDatabaseMapping
- add_entity_groups(self, db_map_data)[source]¶
Adds entity groups to db.
- Parameters
db_map_data (dict) – lists of items to add keyed by DiffDatabaseMapping
- add_parameter_definitions(self, db_map_data)[source]¶
Adds parameter definitions to db.
- Parameters
db_map_data (dict) – lists of items to add keyed by DiffDatabaseMapping
- add_parameter_values(self, db_map_data)[source]¶
Adds parameter values to db without checking integrity.
- Parameters
db_map_data (dict) – lists of items to add keyed by DiffDatabaseMapping
- check_add_parameter_values(self, db_map_data)[source]¶
Adds parameter values in db with checking integrity.
- Parameters
db_map_data (dict) – lists of items to add keyed by DiffDatabaseMapping
- add_parameter_value_lists(self, db_map_data)[source]¶
Adds parameter_value lists to db.
- Parameters
db_map_data (dict) – lists of items to add keyed by DiffDatabaseMapping
- add_parameter_tags(self, db_map_data)[source]¶
Adds parameter tags to db.
- Parameters
db_map_data (dict) – lists of items to add keyed by DiffDatabaseMapping
- add_features(self, db_map_data)[source]¶
Adds features to db.
- Parameters
db_map_data (dict) – lists of items to add keyed by DiffDatabaseMapping
- add_tools(self, db_map_data)[source]¶
Adds tools to db.
- Parameters
db_map_data (dict) – lists of items to add keyed by DiffDatabaseMapping
- add_tool_features(self, db_map_data)[source]¶
Adds tool features to db.
- Parameters
db_map_data (dict) – lists of items to add keyed by DiffDatabaseMapping
- add_tool_feature_methods(self, db_map_data)[source]¶
Adds tool feature methods to db.
- Parameters
db_map_data (dict) – lists of items to add keyed by DiffDatabaseMapping
- update_alternatives(self, db_map_data)[source]¶
Updates alternatives in db.
- Parameters
db_map_data (dict) – lists of items to update keyed by DiffDatabaseMapping
- update_scenarios(self, db_map_data)[source]¶
Updates scenarios in db.
- Parameters
db_map_data (dict) – lists of items to update keyed by DiffDatabaseMapping
- update_object_classes(self, db_map_data)[source]¶
Updates object classes in db.
- Parameters
db_map_data (dict) – lists of items to update keyed by DiffDatabaseMapping
- update_objects(self, db_map_data)[source]¶
Updates objects in db.
- Parameters
db_map_data (dict) – lists of items to update keyed by DiffDatabaseMapping
- update_relationship_classes(self, db_map_data)[source]¶
Updates relationship classes in db.
- Parameters
db_map_data (dict) – lists of items to update keyed by DiffDatabaseMapping
- update_relationships(self, db_map_data)[source]¶
Updates relationships in db.
- Parameters
db_map_data (dict) – lists of items to update keyed by DiffDatabaseMapping
- update_parameter_definitions(self, db_map_data)[source]¶
Updates parameter definitions in db.
- Parameters
db_map_data (dict) – lists of items to update keyed by DiffDatabaseMapping
- update_parameter_values(self, db_map_data)[source]¶
Updates parameter values in db without checking integrity.
- Parameters
db_map_data (dict) – lists of items to update keyed by DiffDatabaseMapping
- check_update_parameter_values(self, db_map_data)[source]¶
Updates parameter values in db with checking integrity.
- Parameters
db_map_data (dict) – lists of items to update keyed by DiffDatabaseMapping
- update_expanded_parameter_values(self, db_map_data)[source]¶
Updates expanded parameter values in db without checking integrity.
- Parameters
db_map_data (dict) – lists of expanded items to update keyed by DiffDatabaseMapping
- update_parameter_value_lists(self, db_map_data)[source]¶
Updates parameter_value lists in db.
- Parameters
db_map_data (dict) – lists of items to update keyed by DiffDatabaseMapping
- update_parameter_tags(self, db_map_data)[source]¶
Updates parameter tags in db.
- Parameters
db_map_data (dict) – lists of items to update keyed by DiffDatabaseMapping
- update_features(self, db_map_data)[source]¶
Updates features in db.
- Parameters
db_map_data (dict) – lists of items to update keyed by DiffDatabaseMapping
- update_tools(self, db_map_data)[source]¶
Updates tools in db.
- Parameters
db_map_data (dict) – lists of items to update keyed by DiffDatabaseMapping
- update_tool_features(self, db_map_data)[source]¶
Updates tools features in db.
- Parameters
db_map_data (dict) – lists of items to update keyed by DiffDatabaseMapping
- update_tool_feature_methods(self, db_map_data)[source]¶
Updates tools feature methods in db.
- Parameters
db_map_data (dict) – lists of items to update keyed by DiffDatabaseMapping
- set_scenario_alternatives(self, db_map_data)[source]¶
Sets scenario alternatives in db.
- Parameters
db_map_data (dict) – lists of items to set keyed by DiffDatabaseMapping
- set_parameter_definition_tags(self, db_map_data)[source]¶
Sets parameter_definition tags in db.
- Parameters
db_map_data (dict) – lists of items to set keyed by DiffDatabaseMapping
- do_remove_items(self, db_map_typed_ids)[source]¶
Removes items from database.
- Parameters
db_map_typed_ids (dict) – lists of items to remove, keyed by item type (str), keyed by DiffDatabaseMapping
- uncache_items(self, db_map_typed_ids)[source]¶
Removes data from cache.
- Parameters
db_map_typed_ids –
- find_cascading_relationship_classes(self, db_map_ids)[source]¶
Finds and returns cascading relationship classes for the given object_class ids.
- find_cascading_entities(self, db_map_ids, item_type)[source]¶
Finds and returns cascading entities for the given entity_class ids.
- find_cascading_relationships(self, db_map_ids)[source]¶
Finds and returns cascading relationships for the given object ids.
- find_cascading_parameter_data(self, db_map_ids, item_type)[source]¶
Finds and returns cascading parameter definitions or values for the given entity_class ids.
- find_cascading_parameter_definitions_by_value_list(self, db_map_ids)[source]¶
Finds and returns cascading parameter definitions for the given parameter_value_list ids.
- find_cascading_parameter_definitions_by_tag(self, db_map_ids)[source]¶
Finds and returns cascading parameter definitions for the given parameter_tag ids.
- find_cascading_parameter_values_by_entity(self, db_map_ids)[source]¶
Finds and returns cascading parameter values for the given entity ids.
- find_cascading_parameter_values_by_definition(self, db_map_ids)[source]¶
Finds and returns cascading parameter values for the given parameter_definition ids.
- find_cascading_parameter_values_by_alternative(self, db_map_ids)[source]¶
Finds and returns cascading parameter values for the given alternative ids.
- find_cascading_scenario_alternatives_by_alternative(self, db_map_ids)[source]¶
Finds and returns cascading scenario_alternatives for the given alternative ids.
- find_cascading_scenario_alternatives_by_scenario(self, db_map_ids)[source]¶
Finds and returns cascading scenario_alternatives for the given scenario ids.
- find_cascading_features_by_parameter_definition(self, db_map_ids)[source]¶
Finds and returns cascading features for the given parameter definition ids.
- find_cascading_features_by_parameter_value_list(self, db_map_ids)[source]¶
Finds and returns cascading features for the given parameter value list ids.
- find_cascading_tool_features_by_feature(self, db_map_ids)[source]¶
Finds and returns cascading tool features for the given feature ids.
- get_all_multi_spine_db_editors(self)[source]¶
Yields all instances of MultiSpineDBEditor currently open.
- Returns
Generator
- get_all_spine_db_editors(self)[source]¶
Yields all instances of SpineDBEditor currently open.
- Returns
Generator
- open_db_editor(self, db_url_codenames)[source]¶
Opens a SpineDBEditor with given urls. Uses an existing MultiSpineDBEditor if any. Also, if the same urls are open in an existing SpineDBEditor, just raises that one instead of creating another.
- Parameters
db_url_codenames (dict) – mapping url to codename
spinetoolbox.spine_db_parcel
¶
SpineDBParcel class.
- authors
Marin (KTH)
- date
10.5.2020
Module Contents¶
A class to create parcels of data from a Spine db. |
- class spinetoolbox.spine_db_parcel.SpineDBParcel(db_mngr)[source]¶
A class to create parcels of data from a Spine db. Mainly intended for the Export selection action in the Spine db editor:
push
methods push items with everything they need to live in a standalone db.full_push
andinner_push
methods do something more specific
Initializes the parcel object.
- Parameters
db_mngr (SpineDBManager) –
- push_parameter_definition_ids(self, db_map_ids, entity_type)[source]¶
Pushes parameter_definition ids.
- full_push_object_class_ids(self, db_map_ids)[source]¶
Pushes parameter definitions associated with given object classes. This essentially full_pushes the object classes and their parameter definitions.
- full_push_relationship_class_ids(self, db_map_ids)[source]¶
Pushes parameter definitions associated with given relationship classes. This essentially full_pushes the relationships classes, their parameter definitions, and their member object classes.
- full_push_object_ids(self, db_map_ids)[source]¶
Pushes parameter values associated with objects and with any relationships involving those objects. This essentially full_pushes objects, their relationships, all the parameter values, and all the necessary classes, definitions, and lists.
- full_push_relationship_ids(self, db_map_ids)[source]¶
Pushes parameter values associated with relationships. This essentially full_pushes relationships, their parameter values, and all the necessary classes, definitions, and lists.
- inner_push_object_ids(self, db_map_ids)[source]¶
Pushes object ids, cascading relationship ids, and the associated parameter values, but not any entity classes or parameter definitions. Mainly intended for the Duplicate object action.
- inner_push_relationship_ids(self, db_map_ids)[source]¶
Pushes relationship ids, and the associated parameter values, but not any entity classes or parameter definitions.
spinetoolbox.spine_db_signaller
¶
Spine DB Signaller class.
- authors
Marin (KTH)
- date
31.10.2019
Module Contents¶
Handles signals from DB manager and channels them to listeners. |
- class spinetoolbox.spine_db_signaller.SpineDBSignaller(db_mngr)[source]¶
Bases:
PySide2.QtCore.QObject
Handles signals from DB manager and channels them to listeners.
Initializes the signaler object.
- Parameters
db_mngr (SpineDBManager) –
- remove_db_map_listener(self, db_map, listener)[source]¶
Removes db_map from the the maps listener listens to.
spinetoolbox.spine_db_worker
¶
The SpineDBWorker class
- authors
Vennström (VTT) and M. Marin (KTH)
- date
2.10.2019
Module Contents¶
Does all the DB communication for SpineDBManager, in the non-GUI thread. |
- class spinetoolbox.spine_db_worker.SpineDBWorker(db_mngr)[source]¶
Bases:
PySide2.QtCore.QObject
Does all the DB communication for SpineDBManager, in the non-GUI thread.
- _add_or_update_items(self, db_map_data, method_name, getter_name, signal_name)[source]¶
Adds or updates items in db.
- Parameters
db_map_data (dict) – lists of items to add or update keyed by DiffDatabaseMapping
method_name (str) – attribute of DiffDatabaseMapping to call for performing the operation
getter_name (str) – attribute of SpineDBManager to call for getting affected items
signal_name (str) – signal attribute of SpineDBManager to emit if successful
- _remove_items(self, db_map_typed_ids)[source]¶
Removes items from database.
- Parameters
db_map_typed_ids (dict) – lists of items to remove, keyed by item type (str), keyed by DiffDatabaseMapping
- export_to_sqlite(self, file_path, data_for_export, caller)[source]¶
Exports given data into SQLite file.
- export_to_json(self, file_path, data_for_export, caller)[source]¶
Exports given data into JSON file.
- export_to_excel(self, file_path, data_for_export, caller)[source]¶
Exports given data into Excel file.
- _refresh_scenario_alternatives(self, db_map_data)[source]¶
Refreshes cached scenarios when updating scenario alternatives.
- Parameters
db_map_data (dict) – lists of updated items keyed by DiffDatabaseMapping
- _refresh_parameter_definitions_by_tag(self, db_map_data)[source]¶
Refreshes cached parameter definitions when updating parameter tags.
- Parameters
db_map_data (dict) – lists of updated items keyed by DiffDatabaseMapping
- _cascade_refresh_relationship_classes(self, db_map_data)[source]¶
Refreshes cached relationship classes when updating object classes.
- Parameters
db_map_data (dict) – lists of updated items keyed by DiffDatabaseMapping
- _cascade_refresh_relationships_by_object(self, db_map_data)[source]¶
Refreshed cached relationships in cascade when updating objects.
- Parameters
db_map_data (dict) – lists of updated items keyed by DiffDatabaseMapping
- _cascade_refresh_parameter_definitions(self, db_map_data)[source]¶
Refreshes cached parameter definitions in cascade when updating entity classes.
- Parameters
db_map_data (dict) – lists of updated items keyed by DiffDatabaseMapping
- _cascade_refresh_parameter_definitions_by_value_list(self, db_map_data)[source]¶
Refreshes cached parameter definitions when updating parameter_value lists.
- Parameters
db_map_data (dict) – lists of updated items keyed by DiffDatabaseMapping
- _cascade_refresh_parameter_values_by_entity_class(self, db_map_data)[source]¶
Refreshes cached parameter values in cascade when updating entity classes.
- Parameters
db_map_data (dict) – lists of updated items keyed by DiffDatabaseMapping
- _cascade_refresh_parameter_values_by_entity(self, db_map_data)[source]¶
Refreshes cached parameter values in cascade when updating entities.
- Parameters
db_map_data (dict) – lists of updated items keyed by DiffDatabaseMapping
- _cascade_refresh_parameter_values_by_alternative(self, db_map_data)[source]¶
Refreshes cached parameter values in cascade when updating alternatives.
- Parameters
db_map_data (dict) – lists of updated items keyed by DiffDatabaseMapping
- _cascade_refresh_parameter_values_by_definition(self, db_map_data)[source]¶
Refreshes cached parameter values in cascade when updating parameter definitions.
- Parameters
db_map_data (dict) – lists of updated items keyed by DiffDatabaseMapping
- _cascade_refresh_parameter_definitions_by_tag(self, db_map_data)[source]¶
Refreshes cached parameter definitions when updating parameter tags.
- Parameters
db_map_data (dict) – lists of updated items keyed by DiffDatabaseMapping
- _cascade_refresh_features_by_paremeter_definition(self, db_map_data)[source]¶
Refreshes cached features in cascade when updating parameter definitions.
- Parameters
db_map_data (dict) – lists of updated items keyed by DiffDatabaseMapping
- _cascade_refresh_features_by_paremeter_value_list(self, db_map_data)[source]¶
Refreshes cached features in cascade when updating parameter value lists.
- Parameters
db_map_data (dict) – lists of updated items keyed by DiffDatabaseMapping
spinetoolbox.spine_engine_manager
¶
Contains SpineEngineManagerBase.
- authors
Marin (KTH)
- date
14.10.2020
Module Contents¶
|
|
|
- class spinetoolbox.spine_engine_manager.SpineEngineManagerBase[source]¶
- abstract run_engine(self, engine_data)[source]¶
Runs an engine with given data.
- Parameters
engine_data (dict) – The engine data.
- abstract get_engine_event(self)[source]¶
Gets next event from engine currently running.
- Returns
two element tuple: event type identifier string, and event data dictionary
- Return type
tuple(str,dict)
- class spinetoolbox.spine_engine_manager.RemoteSpineEngineManager(engine_server_address)[source]¶
Bases:
SpineEngineManagerBase
- Parameters
engine_server_address (str) –
- _send(self, request, *args, receive=True)[source]¶
Sends a request to the server with the given arguments.
- Parameters
request (str) – One of the supported engine server requests
args – Request arguments
receive (bool, optional) – If True (the default) also receives the response and returns it.
- Returns
response, or None if receive is False
- Return type
str or NoneType
- class spinetoolbox.spine_engine_manager.LocalSpineEngineManager[source]¶
Bases:
SpineEngineManagerBase
- run_engine(self, engine_data)[source]¶
Runs an engine with given data.
- Parameters
engine_data (dict) – The engine data.
- get_engine_event(self)[source]¶
Gets next event from engine currently running.
- Returns
two element tuple: event type identifier string, and event data dictionary
- Return type
tuple(str,dict)
spinetoolbox.spine_engine_version_check
¶
Contains the spine_engine_version_check function.
This module should import as few things as possible to avoid accidentally importing anything from spine_engine that is not available in the current spine_engine version.
- authors
Marin (KTH)
- date
12.11.2020
Module Contents¶
Check if spine engine package is the correct version and explain how to upgrade if it is not. |
spinetoolbox.spine_engine_worker
¶
Contains SpineEngineWorker.
- authors
Marin (KTH)
- date
14.10.2020
Module Contents¶
|
|
|
|
|
|
|
|
|
|
- spinetoolbox.spine_engine_worker._handle_node_execution_finished(item, direction, state, item_state)[source]¶
- spinetoolbox.spine_engine_worker._handle_event_message_arrived(item, filter_id, msg_type, msg_text)[source]¶
- spinetoolbox.spine_engine_worker._handle_process_message_arrived(item, filter_id, msg_type, msg_text)[source]¶
- class spinetoolbox.spine_engine_worker.SpineEngineWorker(engine_server_address, engine_data, dag, dag_identifier, project_items)[source]¶
Bases:
PySide2.QtCore.QObject
- Parameters
engine_server_address (str) – Address of engine server if any
engine_data (dict) – engine data
dag (DirectedGraphHandler) –
dag_identifier (str) –
project_items (dict) – mapping from project item name to
ProjectItem
- get_engine_data(self)[source]¶
Returns the engine data. Together with
self.set_engine_data()
it can be used to modify the workflow after it’s initially created. We use it at the moment for creating Julia sysimages.- Returns
dict
- set_engine_data(self, engine_data)[source]¶
Sets the engine data.
- Parameters
engine_data (dict) – New data
- start(self, silent=False)[source]¶
Connects log signals.
- Parameters
silent (bool, optional) – If True, log messages are not forwarded to the loggers but saved in internal dicts.
spinetoolbox.spinedb_api_version_check
¶
Contains the spinedb_api_version_check function.
This module should import as few things as possible to avoid accidentally importing anything from spinedb_api that is not available in the current spinedb_api version.
- authors
Soininen (VTT)
- date
30.3.2020
Module Contents¶
Check if spinedb_api is the correct version and explain how to upgrade if it is not. |
spinetoolbox.ui_main
¶
Contains ToolboxUI class.
- author
Savolainen (VTT)
- date
14.12.2017
Module Contents¶
Class for application main GUI functions. |
- class spinetoolbox.ui_main.ToolboxUI[source]¶
Bases:
PySide2.QtWidgets.QMainWindow
Class for application main GUI functions.
Initializes application and main window.
- set_error_mode(self)[source]¶
Sets Windows error mode to show all error dialog boxes from subprocesses.
See https://docs.microsoft.com/en-us/windows/win32/api/errhandlingapi/nf-errhandlingapi-seterrormode for documentation.
- update_window_modified(self, clean)[source]¶
Updates window modified status and save actions depending on the state of the undo stack.
- set_work_directory(self, new_work_dir=None)[source]¶
Creates a work directory if it does not exist or changes the current work directory to given.
- Parameters
new_work_dir (str, optional) – If given, changes the work directory to given and creates the directory if it does not exist.
- init_project(self, project_dir)[source]¶
Initializes project at application start-up.
Opens the last project that was open when app was closed (if enabled in Settings) or starts the app without a project.
- Parameters
project_dir (str) – project directory
- new_project(self)[source]¶
Opens a file dialog where user can select a directory where a project is created. Pops up a question box if selected directory is not empty or if it already contains a Spine Toolbox project. Initial project name is the directory name.
- create_project(self, name, description, location)[source]¶
Creates new project and sets it active.
- Parameters
name (str) – Project name
description (str) – Project description
location (str) – Path to project directory
- open_project(self, load_dir=None)[source]¶
Opens project from a selected or given directory.
- Parameters
load_dir (str, optional) – Path to project base directory. If default value is used, a file explorer dialog is opened where the user can select the project to open.
- Returns
True when opening the project succeeded, False otherwise
- Return type
bool
- restore_project(self, project_info, project_dir, ask_confirmation=True)[source]¶
Initializes UI, Creates project, models, connections, etc., when opening a project.
- Parameters
project_info (dict) – Project information dictionary
project_dir (str) – Project directory
ask_confirmation (bool) – True closes the previous project with a confirmation box if user has enabled this
- Returns
True when restoring project succeeded, False otherwise
- Return type
bool
- _disable_project_actions(self)[source]¶
Disables all project-related actions, except New project, Open project and Open recent. Called in the constructor and when closing a project.
- _enable_project_actions(self)[source]¶
Enables all project-related actions. Called when a new project is created and when a project is opened.
Updates and sets up the recent projects menu to File-Open recent menu item.
- save_project_as(self)[source]¶
Asks user for a new project directory and duplicates the current project there. The name of the duplicated project will be the new directory name. The duplicated project is activated.
- close_project(self, ask_confirmation=True)[source]¶
Closes the current project.
- Returns
True when no project open or when it’s closed successfully, False otherwise.
- Return type
bool
- rename_project(self, _checked=False)[source]¶
Opens a dialog where the user can enter a new name for the project.
- init_project_item_model(self)[source]¶
Initializes project item model. Create root and category items and add them to the model.
- populate_specification_model(self, specification_paths)[source]¶
Populates specification model.
- Parameters
specification_paths (list) – List of specification file paths for the current project
- load_specification_from_file(self, def_path)[source]¶
Returns an Item specification from a definition file.
- Parameters
def_path (str) – Path of the specification definition file
- Returns
item specification or None if reading the file failed
- Return type
ProjectItemSpecification
- supports_specifications(self, item_type)[source]¶
Returns True if given project item type supports specifications.
- Returns
True if item supports specifications, False otherwise
- Return type
bool
- load_specification(self, definition)[source]¶
Returns Item specification from a definition dictionary.
- Parameters
definition (dict) – Dictionary with the definition
- Returns
specification or None if factory isn’t found.
- Return type
ProjectItemSpecification or NoneType
- undo_critical_commands(self)[source]¶
Undoes critical commands in the undo stack.
- Returns
False if any critical commands aren’t successfully undone
- Return type
Bool
- overwrite_check(self, project_dir)[source]¶
Checks if given directory is a project directory and/or empty And asks the user what to do in that case.
- Parameters
project_dir (str) – Abs. path to a directory
- Returns
True if user wants to overwrite an existing project or if the directory is not empty and the user wants to make it into a Spine Toolbox project directory anyway. False if user cancels the action.
- Return type
bool
- item_selection_changed(self, selected, deselected)[source]¶
Synchronizes selection with scene. The scene handles item/link de/activation.
- _set_active_project_item(self, active_project_item)[source]¶
- Parameters
active_project_item (ProjectItemBase or NoneType) –
- import_specification(self)[source]¶
Opens a file dialog where the user can select an existing specification definition file (.json). If file is valid, calls add_specification().
- _save_specificiation_file(self, specification)[source]¶
Saves the given spec. If the spec doesn’t have the
definition_file_path
attribute set, prompts the user to select a path.- Parameters
specification (ProjectItemSpecification) –
- _prompt_to_save_specification_file(self, specification, candidate_def_file_path)[source]¶
Shows a dialog for the user to select a path to save given spec.
- Parameters
specification (ProjectItemSpecification) – The spec
candidate_def_file_path (str) – A proposed location.
- Returns
True if the spec is saved successfully, False otherwise
- Return type
bool
- _emit_specification_saved(self, specification)[source]¶
Prints a message in the event log, saying that given spec was saved in a certain location, together with a clickable link to change the location.
- Parameters
specification (ProjectItemSpecification) –
- add_specification(self, specification, update_existing=False, widget=None)[source]¶
Adds given specification to the project if there’s no one with the same name. Otherwise it updates the existing one.
- Parameters
specification (ProjectItemSpecification) –
update_existing (bool, optional) – If True, updates a spec with the same in the project. If False (the default), it complains instead.
widget (QWidget, optional) – The specification editor widget that calls this method. Used to parent the QMessageBox
- Returns
True if successful, False if not.
- Return type
bool
- do_add_specification(self, specification, row=None)[source]¶
Adds a ProjectItemSpecification instance to project.
- Parameters
specification (ProjectItemSpecification) – specification that is added to project
- update_specification(self, row, specification)[source]¶
Saves the given spec to disk, then sets it for the given row in the model, then refreshes the spec in all items that use it.
- Parameters
row (int) – Row of tool specification in ProjectItemSpecificationModel
specification (ProjectItemSpecification) – An updated specification
- remove_selected_specification(self, checked=False)[source]¶
Removes specification selected in QListView.
- _get_items_with_spec(self, specification)[source]¶
Yields project items with given specification.
- Parameters
specification (ProjectItemSpecification) –
- do_remove_specification(self, row, ask_verification=True)[source]¶
Removes specification from ProjectItemSpecificationModel. Removes also specifications from all items that use this specification.
- Parameters
row (int) – Row in ProjectItemSpecificationModel
ask_verification (bool) – If True, displays a dialog box asking user to verify the removal
- register_anchor_callback(self, url, callback)[source]¶
Registers a callback for a given anchor in event log, see
open_anchor()
. Used byToolFactory.repair_specification()
.- Parameters
url (str) – The anchor url
callback (function) – A function to call when the anchor is clicked on event log.
- open_anchor(self, qurl)[source]¶
Open file explorer in the directory given in qurl.
- Parameters
qurl (QUrl) – The url to open
Context menu for item specifications.
- Parameters
ind (QModelIndex) – In the ProjectItemSpecificationModel
global_pos (QPoint) – Mouse position
- edit_specification(self, index, item)[source]¶
Open the tool specification widget for editing an existing tool specification.
- Parameters
index (QModelIndex) – Index of the item (from double-click or context menu signal)
item (ProjectItem, optional) –
- open_specification_file(self, index)[source]¶
Open the specification definition file in the default (.json) text-editor.
- Parameters
index (QModelIndex) – Index of the item
- _handle_zoom_minus_pressed(self)[source]¶
Slot for handling case when ‘-’ button in menu is pressed.
- _handle_zoom_reset_pressed(self)[source]¶
Slot for handling case when ‘reset zoom’ button in menu is pressed.
- restore_dock_widgets(self)[source]¶
Dock all floating and or hidden QDockWidgets back to the main window.
Add extra actions to Edit and View menu.
- toggle_properties_tabbar_visibility(self)[source]¶
Shows or hides the tab bar in properties dock widget. For debugging purposes.
- update_datetime(self)[source]¶
Returns a boolean, which determines whether date and time is prepended to every Event Log message.
- add_message(self, msg)[source]¶
Append regular message to Event Log.
- Parameters
msg (str) – String written to QTextBrowser
- add_success_message(self, msg)[source]¶
Append message with green text color to Event Log.
- Parameters
msg (str) – String written to QTextBrowser
- add_error_message(self, msg)[source]¶
Append message with red color to Event Log.
- Parameters
msg (str) – String written to QTextBrowser
- add_warning_message(self, msg)[source]¶
Append message with yellow (golden) color to Event Log.
- Parameters
msg (str) – String written to QTextBrowser
- add_process_message(self, msg)[source]¶
Writes message from stdout to process output QTextBrowser.
- Parameters
msg (str) – String written to QTextBrowser
- add_process_error_message(self, msg)[source]¶
Writes message from stderr to process output QTextBrowser.
- Parameters
msg (str) – String written to QTextBrowser
- override_item_log(self)[source]¶
Sets the log document of the active project item in Item Execution Log and updates title.
- override_python_console(self)[source]¶
Sets the python console of the active project item in Python Console and updates title.
- override_julia_console(self)[source]¶
Sets the julia console of the active project item in Julia Console and updates title.
- override_execution_list(self)[source]¶
Displays executions of the active project item in Executions and updates title.
- restore_original_item_log_document(self)[source]¶
Sets the Item Execution Log document back to the original.
- _refresh_execution_list(self)[source]¶
Refreshes Executions as the active project item starts new executions.
- _select_execution(self, current, _previous)[source]¶
Sets the log documents of the selected execution in Event and Process Log, and any consoles in Python and Julia Console.
- show_add_project_item_form(self, item_type, x=0, y=0, spec='')[source]¶
Show add project item widget.
- supports_specification(self, item_type)[source]¶
Returns True if given item type supports specifications.
- Parameters
item_type (str) – item’s type
- Returns
True if item supports specifications, False otherwise
- Return type
bool
- show_specification_form(self, item_type, specification=None, item=None, **kwargs)[source]¶
Shows specification widget.
- Parameters
item_type (str) – item’s type
specification (ProjectItemSpecification, optional) – specification
item (ProjectItem, optional) – project item
**kwargs – parameters passed to the specification widget
Context menu for project items listed in the project QTreeView.
- Parameters
pos (QPoint) – Mouse position
Creates and shows the project item context menu.
- Parameters
pos (QPoint) – Mouse position
index (QModelIndex, None) – Index of concerned item or None
Context menu for connection links.
- Parameters
pos (QPoint) – Mouse position
link (Link(QGraphicsPathItem)) – The concerned link
- refresh_edit_action_states(self)[source]¶
Sets the enabled/disabled state for copy, paste, duplicate, and remove actions in File-Edit menu, project tree view context menu, and in Design View context menus just before the menus are shown to user.
- enable_edit_actions(self)[source]¶
Enables project item edit actions after a QMenu has been shown. This is needed to enable keyboard shortcuts (e.g. Ctrl-C & del) again.
- _tasks_before_exit(self)[source]¶
Returns a list of tasks to perform before exiting the application.
Possible tasks are:
“prompt exit”: prompt user if quitting is really desired
“prompt save”: prompt user if project should be saved before quitting
“save”: save project before quitting
- Returns
a list containing zero or more tasks
- _perform_pre_exit_tasks(self)[source]¶
Prompts user to confirm quitting and saves the project if necessary.
- Returns
True if exit should proceed, False if the process was cancelled
- _confirm_exit(self)[source]¶
Confirms exiting from user.
- Returns
True if exit should proceed, False if user cancelled
- _confirm_save_and_exit(self)[source]¶
Confirms exit from user and saves the project if requested.
- Returns
True if exiting should proceed, False if user cancelled
- remove_path_from_recent_projects(self, p)[source]¶
Removes entry that contains given path from the recent project files list in QSettings.
- Parameters
p (str) – Full path to a project directory
- update_recent_projects(self)[source]¶
Adds a new entry to QSettings variable that remembers twenty most recent project paths.
- closeEvent(self, event)[source]¶
Method for handling application exit.
- Parameters
event (QCloseEvent) – PySide2 event
- _serialize_selected_items(self)[source]¶
Serializes selected project items into a dictionary.
The serialization protocol tries to imitate the format in which projects are saved.
- Returns
a dict containing serialized version of selected project items
- Return type
dict
- _deserialized_item_position_shifts(self, item_dicts)[source]¶
Calculates horizontal and vertical shifts for project items being deserialized.
If the mouse cursor is on the Design view we try to place the items unders the cursor. Otherwise the items will get a small shift so they don’t overlap a possible item below. In case the items don’t fit the scene rect we clamp their coordinates within it.
- Parameters
item_dicts (dict) – a dictionary of serialized items being deserialized
- Returns
a tuple of (horizontal shift, vertical shift) in scene’s coordinates
- Return type
tuple
- static _set_deserialized_item_position(item_dict, shift_x, shift_y, scene_rect)[source]¶
Moves item’s position by shift_x and shift_y while keeping it within the limits of scene_rect.
- _deserialize_items(self, items_dict, duplicate_files=False)[source]¶
Deserializes project items from a dictionary and adds them to the current project.
- Parameters
items_dict (dict) – serialized project items
- project_item_from_clipboard(self, duplicate_files=False)[source]¶
Adds project items in system’s clipboard to the current project.
- Parameters
duplicate_files (bool) – Duplicate files boolean
- propose_item_name(self, prefix)[source]¶
Proposes a name for a project item.
The format is prefix_xx where xx is a counter value [01..99].
- Parameters
prefix (str) – a prefix for the name
- Returns
a name string
- Return type
str
Adds generic actions to project tree view and Design View.
- set_icon_and_properties_ui(self, item_name)[source]¶
Adds properties UI to given project item.
- Parameters
item_name (str) – item’s name
- project_item_properties_ui(self, item_type)[source]¶
Returns the properties tab widget’s ui.
- Parameters
item_type (str) – project item’s type
- Returns
item’s properties tab widget
- Return type
QWidget
- _open_project_item_directory(self, _)[source]¶
Opens project item’s directory in system’s file browser.
Creates a context menu for category items.
- Returns
category context menu
- Return type
QMenu
Creates a context menu for project items.
- Parameters
additional_actions (list of QAction) – actions to be prepended to the menu
- Returns
project item context menu
- Return type
QMenu
- _start_base_julia_console(self)[source]¶
Shows and starts the ‘base’ Julia Console if not running or activates the window if running.
- _start_base_python_console(self)[source]¶
Shows and starts the ‘base’ Python Console if not running or activates the window if running.
- destroy_base_console(self, console_window_title)[source]¶
Destroys the Python or Julia Console window reference.
- Parameters
console_window_title (str) – Used in determining which console ref to destroy
- make_console(self, name, item, kernel_name, connection_file)[source]¶
Creates a new SpineConsoleWidget for given connection file if none exists yet, and returns it.
- Parameters
name (str) – Console name
item (ProjectItem) – Item that owns the console
kernel_name (str) – Name of the kernel
connection_file (str) – Path of kernel connection file
- Returns
SpineConsoleWidget
spinetoolbox.version
¶
Version info for Spine Toolbox package. Inspired by python sys.version and sys.version_info.
- author
Savolainen (VTT)
- date
8.1.2020
Module Contents¶
A class for a named tuple containing the five components of the version number: major, minor, |
- class spinetoolbox.version.VersionInfo[source]¶
Bases:
NamedTuple
A class for a named tuple containing the five components of the version number: major, minor, micro, releaselevel, and serial. All values except releaselevel are integers; the release level is ‘alpha’, ‘beta’, ‘candidate’, or ‘final’.
Package Contents¶
- 1
Created with sphinx-autoapi