spinetoolbox.ui_main
¶
Contains ToolboxUI class.
- author
Savolainen (VTT)
- date
14.12.2017
Module Contents¶
Classes¶
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