spinetoolbox.ui_main
Contains a class for the main window of Spine Toolbox.
Module Contents
Classes
Class for application main GUI functions. |
- class spinetoolbox.ui_main.ToolboxUI[source]
Bases:
PySide6.QtWidgets.QMainWindow
Class for application main GUI functions.
Initializes application and main window.
- static set_error_mode()[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_execute_selected_enabled()[source]
Enables or disables execute selected action based on the number of selected items.
- update_window_modified(clean)[source]
Updates window modified status and save actions depending on the state of the undo stack.
- set_work_directory(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.
- project()[source]
Returns current project or None if no project open.
- Returns
current project or None
- Return type
- item_specification_factories()[source]
Returns project item specification factories.
- Returns
specification factories
- Return type
list of ProjectItemSpecificationFactory
- init_project(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()[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(proj_dir)[source]
Creates new project and sets it active.
- Parameters
proj_dir (str) – Path to project directory
- open_project(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(project_dir, ask_confirmation=True)[source]
Initializes UI, Creates project, models, connections, etc., when opening a project.
- Parameters
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()[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()[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()[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(ask_confirmation=True, clear_event_log=True)[source]
Closes the current project.
- Parameters
ask_confirmation (bool) – if False, no confirmation whatsoever is asked from user
clear_event_log (bool) – if True, the event log is cleared after closing the project
- Returns
True when no project open or when it’s closed successfully, False otherwise.
- Return type
bool
- set_project_description(_=False)[source]
Opens a dialog where the user can enter a new description for the project.
- add_project_items(items_dict)[source]
Pushes an AddProjectItemsCommand to the undo stack.
- Parameters
items_dict (dict) – mapping from item name to item dictionary
- supports_specifications(item_type)[source]
Returns True if given project item type supports specifications.
- Returns
True if item supports specifications, False otherwise
- Return type
bool
- undo_critical_commands()[source]
Undoes critical commands in the undo stack.
- Returns
False if any critical commands aren’t successfully undone
- Return type
Bool
- overwrite_check(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
- _set_active_project_item(active_project_item)[source]
Activates given project item.
- Parameters
active_project_item (ProjectItemBase or NoneType) – Active project item
- _set_active_link_item(active_link_item)[source]
Activates given link and connects it to the corresponding Properties widget.
- Parameters
active_link_item (LoggingConnection or LoggingJump, optional) – Active link
- _get_active_properties_widget()[source]
Returns the active item’s or link’s properties widget or None if no item or link is active.
- import_specification()[source]
Opens a file dialog where the user can select an existing specification definition file (.json). If file is valid, pushes AddSpecificationCommand to undo stack.
- replace_specification(name, specification)[source]
Pushes an ReplaceSpecificationCommand to undo stack.
- repair_specification(name)[source]
Repairs specification if it is broken.
- Parameters
name (str) – Specification’s name
- prompt_save_location(title, proposed_path, file_filter)[source]
Shows a dialog for the user to select a path to save a file.
- Parameters
title (str) – Dialog window title
proposed_path (str) – Proposed location.
file_filter (str) – File extension filter
- Returns
Absolute path or None if dialog was cancelled
- Return type
str
- _log_specification_saved(name, path)[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
name (str) – Specification’s name
path (str) – Specification’s file path
- register_anchor_callback(url, callback)[source]
Registers a callback for a given anchor in event log, see
open_anchor()
. Used byToolFactory.repair_specification()
.- Parameters
url (str) – Anchor url
callback (function) – Function to call when the anchor is clicked
- open_anchor(qurl)[source]
Open file explorer in the directory given in qurl.
- Parameters
qurl (QUrl) – The url to open
- _change_specification_file_location(name)[source]
Prompts user for new location for a project item specification.
Delegates saving to project if one is open by pushing a command to the undo stack, otherwise tries to find the specification from the plugin manager.
- Parameters
name (str) – Specification’s name
Context menu for item specifications.
- Parameters
ind (QModelIndex) – In the ProjectItemSpecificationModel
global_pos (QPoint) – Mouse position
- edit_specification(index, item)[source]
Opens a specification editor widget.
- Parameters
index (QModelIndex) – Index of the item (from double-click or context menu signal)
item (ProjectItem, optional) –
- remove_specification(index)[source]
Removes specification from project.
- Parameters
index (QModelIndex) – Index of the specification item
- open_specification_file(index)[source]
Open the specification definition file in the default (.json) text-editor.
- Parameters
index (QModelIndex) – Index of the item
- _handle_zoom_reset_pressed()[source]
Slot for handling case when ‘reset zoom’ button in menu is pressed.
- restore_dock_widgets()[source]
Dock all floating and or hidden QDockWidgets back to the main window.
Adds extra actions to Edit and View menu.
- toggle_properties_tabbar_visibility()[source]
Shows or hides the tab bar in properties dock widget. For debugging purposes.
- update_datetime()[source]
Returns a boolean, which determines whether date and time is prepended to every Event Log message.
- add_message(msg)[source]
Appends a regular message to the Event Log.
- Parameters
msg (str) – String written to QTextBrowser
- add_success_message(msg)[source]
Appends a message with green text to the Event Log.
- Parameters
msg (str) – String written to QTextBrowser
- add_error_message(msg)[source]
Appends a message with red color to the Event Log.
- Parameters
msg (str) – String written to QTextBrowser
- add_warning_message(msg)[source]
Appends a message with yellow (golden) color to the Event Log.
- Parameters
msg (str) – String written to QTextBrowser
- add_process_message(msg)[source]
Writes message from stdout to the Event Log.
- Parameters
msg (str) – String written to QTextBrowser
- add_process_error_message(msg)[source]
Writes message from stderr to the Event Log.
- Parameters
msg (str) – String written to QTextBrowser
- _override_console()[source]
Sets the jupyter console of the active project item in Jupyter Console and updates title.
- _override_execution_list()[source]
Displays executions of the active project item in Executions and updates title.
- _refresh_console_execution_list()[source]
Refreshes console executions as the active project item starts new executions.
- _select_console_execution(current, _previous)[source]
Sets the console of the selected execution in Console.
- supports_specification(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(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
Creates and shows the project item context menu.
- Parameters
pos (QPoint) – Mouse position
item (ProjectItem, optional) – Project item or None
Shows the Context menu for connection links.
- Parameters
pos (QPoint) – Mouse position
link (Link(QGraphicsPathItem)) – The link in question
- refresh_edit_action_states()[source]
Sets the enabled/disabled state for copy, paste, duplicate, remove and rename 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()[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()[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
Zero or more tasks in a list
- Return type
list
- _perform_pre_exit_tasks()[source]
Prompts user to confirm quitting and saves the project if necessary.
- Returns
True if exit should proceed, False if the process was cancelled
- Return type
bool
- _confirm_exit()[source]
Confirms exiting from user.
- Returns
True if exit should proceed, False if user cancelled
- Return type
bool
- _confirm_project_close()[source]
Confirms exit from user and saves the project if requested.
- Returns
True if exiting should proceed, False if user cancelled
- Return type
bool
- remove_path_from_recent_projects(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()[source]
Adds a new entry to QSettings variable that remembers twenty most recent project paths.
- closeEvent(event)[source]
Method for handling application exit.
- Parameters
event (QCloseEvent) – PySide6 event
- _serialize_selected_items()[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(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) – 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(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(duplicate_files=False)[source]
Adds project items in system’s clipboard to the current project.
- Parameters
duplicate_files (bool) – Duplicate files boolean
- set_icon_and_properties_ui(item_name)[source]
Adds properties UI to given project item.
- Parameters
item_name (str) – Item’s name
- project_item_properties_ui(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(_)[source]
Opens active project item’s directory in system’s file browser.
- _remove_selected_items(_)[source]
Pushes commands to remove selected project items and links from project.
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_detached_jupyter_console(kernel_name, icon, conda)[source]
Launches a new detached Console with the given kernel name or activates an existing Console if the kernel is already running.
- Parameters
kernel_name (str) – Requested kernel name
icon (QIcon) – Icon representing the kernel language
conda (bool) – Is this a Conda kernel?
- _setup_jupyter_console(item, filter_id, kernel_name, connection_file, connection_file_dict)[source]
Sets up jupyter console, eventually for a filter execution.
- Parameters
item (ProjectItem) – Item
filter_id (str) – Filter identifier
kernel_name (str) – Jupyter kernel name
connection_file (str) – Path to connection file
connection_file_dict (dict) – Contents of connection file when kernel manager runs on Spine Engine Server
- _handle_kernel_shutdown(item, filter_id)[source]
Closes the kernel client when kernel manager has been shutdown due to an enabled ‘Kill consoles at the end of execution’ option.
- Parameters
item (ProjectItem) – Item
filter_id (str) – Filter identifier
- _setup_persistent_console(item, filter_id, key, language)[source]
Sets up persistent console, eventually for a filter execution.
- Parameters
item (ProjectItem) – Item
filter_id (str) – Filter identifier
key (tuple) – Key
language (str) – Language (e.g. ‘python’ or ‘julia’)
- _make_jupyter_console(item, kernel_name, connection_file)[source]
Creates a new JupyterConsoleWidget for given connection file if none exists yet, and returns it.
- Parameters
item (ProjectItem) – Item that owns the console
kernel_name (str) – Name of the kernel
connection_file (str) – Path of kernel connection file
- Returns
JupyterConsoleWidget
- _make_persistent_console(item, key, language)[source]
Creates a new PersistentConsoleWidget for given process key.
- Parameters
item (ProjectItem) – Item that owns the console
key (tuple) – persistent process key in spine engine
language (str) – for syntax highlighting and prompting, etc.
- Returns
PersistentConsoleWidget
- _cleanup_jupyter_console(conn_file)[source]
Removes reference to a Jupyter Console and closes the kernel manager on Engine.
- _shutdown_engine_kernels()[source]
Shuts down all persistent and Jupyter kernels managed by Spine Engine.