spinetoolbox.ui_main
¶
Contains ToolboxUI class.
author: |
|
---|---|
date: | 14.12.2017 |
Module Contents¶
-
class
spinetoolbox.ui_main.
ToolboxUI
[source]¶ Bases:
PySide2.QtWidgets.QMainWindow
Class for application main GUI functions.
Initialize application and main window.
-
update_window_modified
(self, clean)[source]¶ Updates window modified status and save actions depending on the state of the undo stack.
-
parse_project_item_modules
(self)[source]¶ Collects attributes from project item modules into a dict. This dict is then used to perform all project item related tasks.
-
show_assistant
(self, module, action)[source]¶ Creates and shows the assistant for the given module. Disables the given action while the assistant is shown, enables the action back when the assistant is destroyed. This is to make sure we don’t open the same assistant twice.
-
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) – If given, changes the work directory to given
- creates the directory if it does not exist. (and) –
-
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.
-
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, clear_logs=True)[source]¶ Opens project from a selected or given directory.
Parameters: - load_dir (str) – Path to project base directory. If default value is used,
- file explorer dialog is opened where the user can select the (a) –
- to open. (project) –
- clear_logs (bool) – True clears Event and Process Log, False does not
Returns: True when opening the project succeeded, False otherwise
Return type: bool
-
restore_project
(self, project_info, project_dir, clear_logs)[source]¶ Initializes UI, Creates project, models, connections, etc., when opening a project.
Parameters: - project_info (dict) – Project information dictionary
- project_dir (str) – Project directory
- clear_logs (bool) – True clears Event and Process Log, False does not
Returns: True when restoring project succeeded, False otherwise
Return type: bool
Updates and sets up the recent projects menu to File-Open recent menu item.
-
save_project_as
(self)[source]¶ Ask user for a new project name and save. Creates a duplicate of the open project.
-
upgrade_project
(self, checked=False)[source]¶ Upgrades an old style project (.proj file) to a new directory based Spine Toolbox project. Note that this method can be removed when we no longer want to support upgrading .proj projects. Project upgrading should happen later automatically when opening a project.
-
init_project_item_model
(self)[source]¶ Initializes project item model. Create root and category items and add them to the model.
-
init_tool_specification_model
(self, tool_specification_paths)[source]¶ Initializes Tool specification model.
Parameters: tool_specification_paths (list) – List of tool definition file paths used in this project
-
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]¶ Synchronize selection with scene. Check if only one item is selected and make it the active item: disconnect signals of previous active item, connect signals of current active item and show correct properties tab for the latter.
-
activate_item_tab
(self, item)[source]¶ Shows project item properties tab according to item type. Note: Does not work if a category item is given as argument.
Parameters: item (ProjectItem) – Instance of a project item
-
open_tool_specification
(self)[source]¶ Opens a file dialog where the user can select an existing tool specification definition file (.json). If file is valid, calls add_tool_specification().
-
add_tool_specification
(self, tool_specification)[source]¶ Pushes a new AddToolSpecificationCommand to the undo stack.
-
do_add_tool_specification
(self, tool_specification, row=None)[source]¶ Adds a ToolSpecification instance to project, which then can be added to a Tool item. Adds the tool specification file path into project file (project.json)
Parameters: tool_specification (ToolSpecification) – Tool specification that is added to project
-
update_tool_specification
(self, row, tool_specification)[source]¶ Pushes a new UpdateToolSpecificationCommand to the undo stack.
-
do_update_tool_specification
(self, row, tool_specification)[source]¶ Updates a Tool specification and refreshes all Tools that use it.
Parameters: - row (int) – Row of tool specification in ToolSpecificationModel
- tool_specification (ToolSpecification) – An updated Tool specification
-
update_tool_settings
(self, tool_settings)[source]¶ Updates tool specification and execution mode for a bunch of tool items. Called just after successfully updating a Tool Specification.
Parameters: tool_settings (dict) – mapping Tool items to a tuple of (ToolSpecification instance, bool execution mode)
-
remove_selected_tool_specification
(self, checked=False)[source]¶ Removes tool specification selected in QListView.
-
do_remove_tool_specification
(self, row, ask_verification=True)[source]¶ Removes tool specification from ToolSpecificationModel. Removes also Tool specifications from all Tool items that use this specification.
Parameters: - row (int) – Row in ToolSpecificationModel
- ask_verification (bool) – If True, displays a dialog box asking user to verify the removal
-
open_anchor
(self, qurl)[source]¶ Open file explorer in the directory given in qurl.
Parameters: qurl (QUrl) – Directory path or a file to open
-
edit_tool_specification
(self, index)[source]¶ Open the tool specification widget for editing an existing tool specification.
Parameters: index (QModelIndex) – Index of the item (from double-click or contex menu signal)
-
open_tool_specification_file
(self, index)[source]¶ Open the Tool specification definition file in the default (.json) text-editor.
Parameters: index (QModelIndex) – Index of the item
-
open_tool_main_program_file
(self, index)[source]¶ Open the tool specification’s main program file in the default 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 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
-
show_tool_specification_form
(self, tool_specification=None)[source]¶ Show tool specification widget.
Context menu for project items listed in the project QTreeView.
Parameters: pos (QPoint) – Mouse position
Context menu for project item images on the QGraphicsView.
Parameters: - pos (QPoint) – Mouse position
- name (str) – The name of the concerned item
Create and show project item context menu.
Parameters: - pos (QPoint) – Mouse position
- ind (QModelIndex) – Index of concerned item
Context menu for connection links.
Parameters: - pos (QPoint) – Mouse position
- link (Link(QGraphicsPathItem)) – The concerned link
Context menu for tool specifications.
Parameters: pos (QPoint) – Mouse position
-
tear_down_items
(self)[source]¶ Calls the tear_down method on all project items, so they can clean up their mess if needed.
-
_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 the five 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. The format of the dictionary is following: {“item_category_1”: [{“name”: “item_1_name”, …}, …], …}
Returns: a dict containing serialized version of selected project items
-
_deserialized_item_position_shifts
(self, serialized_items)[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: serialized_items (dict) – a dictionary of serialized items being deserialized Returns: a tuple of (horizontal shift, vertical shift) in scene’s coordinates
-
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, serialized_items)[source]¶ Deserializes project items from a dictionary and adds them to the current project.
Parameters: serialized_items (dict) – serialized project items
-
project_item_from_clipboard
(self)[source]¶ Adds project items in system’s clipboard to the current project.
-
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
-