workflows.*

Workflows for pyspread

class workflows.Workflows(main_window)[source]

Bases: object

Workflow container class

_copy_results_current(grid)[source]

Copy cell results for the current cell

Parameters:

grid (QTableView) – Main grid

_copy_results_selection(grid)[source]

Copy selected cells result objects to the clipboard

Parameters:

grid (QTableView) – Main grid

_csv_export(filepath)[source]

Export to csv file filepath

Parameters:

filepath (Path) – Path of file to be exported

_csv_import(filepath)[source]

Import csv from filepath

Parameters:

filepath (Path) – Path of file to be imported

_display_match_msg(find_string, next_match, regexp)[source]

Displays find match message in statusbar

Parameters:
  • find_string (str) – Message component

  • next_match (str) – Message component

  • regexp (str) – Message component

_get_next_match(find_dialog, start_key=None)[source]

Returns tuple of find string and next matching cell key

Parameters:
  • find_dialog (FindDialog) – Find dialog from which the search origins

  • start_key (Tuple[int, int, int]) – Start search at given key

_get_replace_command(next_match, find_string, replace_string, max_=1, description=None)[source]

Returns SetCellCode command for replace operations

Parameters:
  • next_match (Tuple[int, int, int]) – Key of next matching cell

  • find_string (str) – String to find

  • replace_string (str) – Replacement string

  • max – Maximum number of replace actions, -1 is unlimited

  • description (str) – Forced command description string

Return type:

QUndoCommand

_matplotlib_export(filepath, file_format)[source]

Export to svg file filepath

Parameters:
  • filepath (Path) – Path of file to be exported

  • file_format (str) – File format to be exported, e.g. png or svg

_paste_image(image_data, index)[source]

Pastes svg image into cell

Parameters:
  • image_data (bytes) – Raw image data. May be anything that QImage handles.

  • index (QModelIndex) – Target cell index

_paste_svg(svg, index)[source]

Pastes svg image into cell

Parameters:
  • svg (str) – SVG data

  • index (QModelIndex) – Target cell index

_paste_to_current(data)[source]

Pastes data into grid starting from the current cell

Parameters:

data (str) – Clipboard text

_paste_to_selection(selection, data)[source]

Pastes data into grid filling the selection

Parameters:
  • selection (Selection) – Grid cell selection for pasting

  • data (str) – Clipboard text

_qimage_export(filepath, file_format)[source]

Export to png file filepath

Parameters:
  • filepath (Path) – Path of file to be exported

  • file_format (str) – File format to be exported, e.g. png

_read_svg_str(filepath, encoding)[source]

Returns svg string from filepath

Parameters:

filepath – Path of SVG file to read

_resize_grid(shape)[source]

Resize grid

Parameters:

shape (Tuple[int, int, int]) – New grid shape

_save(filepath)[source]

Save filepath using chosen_filter

Compresses save file if filepath.suffix is .pys

Parameters:

filepath (Path) – Path of file to be saved

_sort(ascending=True)[source]

Edit -> Sort ascending

Parameters:

ascending (bool) – True for ascending sort, False for descending sort

busy_cursor()[source]

contextmanager that displays a busy cursor

cell2dialog = {}
count_file_lines(filepath)[source]

Returns line count of file in filepath

Parameters:

filepath (Path) – Path of file to be analyzed

delete(description_tpl='Delete selection {}')[source]

Delete cells in selection

Parameters:

description_tpl (str) – Description template for QUndoCommand

edit_copy()[source]

Edit -> Copy workflow

Copies selected grid code to clipboard

edit_copy_results()[source]

Edit -> Copy results workflow

If a selection is present then repr of selected grid cells result objects are copied to the clipboard.

If no selection is present, the current cell results are copied to the clipboard. This can be plain text, html, a png image or an svg image.

edit_cut()[source]

Edit -> Cut workflow

edit_find()[source]

Edit -> Find workflow, opens FindDialog

edit_find_next()[source]

Edit -> Find next workflow

edit_paste()[source]

Edit -> Paste workflow

Pastes text clipboard data

If no selection is present, data is pasted starting with the current cell. If a selection is present, data is pasted fully if the selection is smaller. If the selection is larger then data is duplicated.

edit_paste_as()[source]

Pastes clipboard into one cell using a user specified mime type

edit_replace()[source]

Edit -> Replace workflow, opens ReplaceDialog

edit_resize()[source]

Edit -> Resize workflow

edit_sort_ascending()[source]

Edit -> Sort ascending

edit_sort_descending()[source]

Edit -> Sort descending

file_export()[source]

Export csv and svg files

file_import()[source]

Import csv files

file_new(*args, **kwargs)[source]

Check changes and display and handle the dialog

file_open(*args, **kwargs)[source]

Check changes and display and handle the dialog

file_open_recent(*args, **kwargs)[source]

Check changes and display and handle the dialog

file_quit(*args, **kwargs)[source]

Check changes and display and handle the dialog

file_save()[source]

File save workflow

file_save_as()[source]

File save as workflow

filepath_open(filepath)[source]

Workflow for opening a file if a filepath is known

Parameters:

filepath (Path) – Path of file to be opened

find_dialog_on_find(find_dialog)[source]

Edit -> Find workflow, after pressing find button in FindDialog

Parameters:

find_dialog (FindDialog) – Find dialog of origin

format_copy_format()[source]

Copies the format of the selected cells to the Clipboard

Cells are shifted so that the top left bbox corner is at 0,0

format_paste_format()[source]

Pastes cell formats

Pasting starts at cursor or at top left bbox corner

get_paint_columns(left, right)[source]

Iterator of columns to paint

Parameters:
  • left (int) – First column to paint

  • right (int) – Last column to paint

Return type:

Iterable[int]

get_paint_rows(top, bottom)[source]

Iterator of rows to paint

Parameters:
  • top (int) – First row to paint

  • bottom (int) – Last row to paint

Return type:

Iterable[int]

get_paint_tables(first, last)[source]

Iterator of tables to paint

Parameters:
  • first (int) – First table to paint

  • last (int) – Last table to paint

Return type:

Iterable[int]

get_total_height(top, bottom)[source]

Total height of paint_rows

Parameters:
  • top (int) – First row to evaluate

  • bottom (int) – Last row to evaluate

Return type:

float

get_total_width(left, right)[source]

Total height of paint_columns

Parameters:
  • left (int) – First column to evaluate

  • right (int) – Last column to evaluate

Return type:

float

handle_changed_since_save(*args, **kwargs)[source]

Decorator to handle changes since last saving the document

If changes are present then a dialog is displayed that asks if the changes shall be discarded.

  • If the user selects Cancel then func is not executed.

  • If the user selects Save then the file is saved and func is executed.

  • If the user selects Discard then the file is not saved and func is executed.

If no changes are present then func is directly executed. After executing func, reset_changed_since_save() and update_main_window_title are called.

macro_insert_chart()[source]

Insert chart workflow

macro_insert_image()[source]

Insert image workflow

macro_insert_sum()[source]

Sum up selection area

The sum is inserted into the cell below the bottom right cell of the selection.

paint(painter, option, paint_rect, rows, columns)[source]

Grid paint workflow for printing and svg export

Parameters:
  • painter (QPainter) – Painter with which the grid is drawn

  • option (QStyleOptionViewItem) – Style option for rendering

  • paint_rect (QRectF) – Rectangle, which is drawn at the grid borders

  • rows (Iterable[int]) – Rows to be painted

  • columns (Iterable[int]) – Columns to be painted

prevent_updates()[source]

contextmanager sets the prevent_updates state

The prevent_updates state prevents updates in main_window.grid.setData

print_zoom(zoom=1.0)[source]

Decorator for tasks that have to take place in standard zoom

Parameters:

zoom (float) – Print zoom factor

replace_dialog_on_replace(replace_dialog, toggled=False, max_=1)[source]

Edit -> Replace workflow when pushing Replace in ReplaceDialog

Returns True if there is a match otherwise False

Parameters:
  • replace_dialog (ReplaceDialog) – Replace dialog of origin

  • toggled (bool) – Replace dialog toggle state

  • max – Maximum number of replace actions, -1 is unlimited

Return type:

bool

replace_dialog_on_replace_all(replace_dialog)[source]

Edit -> Replace workflow when pushing ReplaceAll in ReplaceDialog

Parameters:

replace_dialog (ReplaceDialog) – Replace dialog of origin

reset_changed_since_save()[source]

Sets changed_since_save to False and updates the window title

sign_file(filepath)[source]

Signs filepath if not in model.model.DataArray.safe_mode

Parameters:

filepath (Path) – Path of file to be signed

svg_export(filepath, svg_area=None)[source]

Export to svg file filepath

Parameters:
  • filepath (Path) – Path of file to be exported

  • svg_area (SinglePageArea) – Area of the grid to be exported

update_main_window_title()[source]

Change the main window title to reflect the current file name

view_goto_cell()[source]

View -> Go to cell workflow