pyspread.lib package¶
Subpackages¶
- pyspread.lib.packaging package
- pyspread.lib.test package
- Submodules
- pyspread.lib.test.compat module
- pyspread.lib.test.test_array2qimage module
- pyspread.lib.test.test_csv module
- pyspread.lib.test.test_file_helpers module
- pyspread.lib.test.test_hashing module
- pyspread.lib.test.test_qimageview module
- pyspread.lib.test.test_selection module
- pyspread.lib.test.test_string_helpers module
- Module contents
Submodules¶
pyspread.lib.attrdict module¶
pyspread.lib.charts module¶
charts¶
Provides matplotlib figure that are chart templates
Provides¶
ChartFigure: Main chart class
- class pyspread.lib.charts.ChartFigure(*attributes)[source]¶
Bases:
object
Chart figure class with drawing method
This class is deprecated and exists solely for compatibility with pyspread <1.99.0
- Parameters:
attributes (
List
[dict
]) – List of dicts that contain matplotlib attributes The first list element is defining the axes The following list elements are defining plots
- contour_label_attrs = {'contour_label_colors': 'colors', 'contour_label_fontsize': 'fontsize', 'contour_labels': 'contour_labels'}¶
- contourf_attrs = {'contour_fill': 'contour_fill', 'hatches': 'hatches'}¶
- plot_type_fixed_attrs = {'Sankey': [], 'bar': ['left', 'height'], 'boxplot': ['x'], 'contour': ['X', 'Y', 'Z'], 'contourf': ['X', 'Y', 'Z'], 'hist': ['x'], 'pie': ['x'], 'plot': ['xdata', 'ydata']}¶
- plot_type_xy_mapping = {'Sankey': ['flows', 'orientations'], 'annotate': ['xy', 'xy'], 'bar': ['left', 'height'], 'boxplot': ['x', 'x'], 'contour': ['X', 'Y'], 'contourf': ['X', 'Y', 'Z'], 'hist': ['label', 'x'], 'pie': ['labels', 'x'], 'plot': ['xdata', 'ydata']}¶
pyspread.lib.csv module¶
Provides
sniff()
: Sniffs CSV dialect and header info
- pyspread.lib.csv.csv_reader(csvfile, dialect)[source]¶
Generator of str values from csv file in filepath, ignores header
- pyspread.lib.csv.get_header(csvfile, dialect)[source]¶
Returns list of first line items of file filepath
pyspread.lib.dataclasses module¶
- class pyspread.lib.dataclasses.Field(default, default_factory, init, repr, hash, compare, metadata)[source]¶
Bases:
object
- compare¶
- default¶
- default_factory¶
- hash¶
- init¶
- metadata¶
- name¶
- repr¶
- type¶
- exception pyspread.lib.dataclasses.FrozenInstanceError[source]¶
Bases:
AttributeError
- pyspread.lib.dataclasses.asdict(obj, *, dict_factory=<class 'dict'>)[source]¶
Return the fields of a dataclass instance as a new dictionary mapping field names to field values.
Example usage:
@dataclass class C:
x: int y: int
c = C(1, 2) assert asdict(c) == {‘x’: 1, ‘y’: 2}
If given, ‘dict_factory’ will be used instead of built-in dict. The function applies recursively to field values that are dataclass instances. This will also look into built-in containers: tuples, lists, and dicts.
- pyspread.lib.dataclasses.astuple(obj, *, tuple_factory=<class 'tuple'>)[source]¶
Return the fields of a dataclass instance as a new tuple of field values.
Example usage:
@dataclass class C: x: int y: int
c = C(1, 2) assert astuple(c) == (1, 2)
If given, ‘tuple_factory’ will be used instead of built-in tuple. The function applies recursively to field values that are dataclass instances. This will also look into built-in containers: tuples, lists, and dicts.
- pyspread.lib.dataclasses.dataclass(_cls=None, *, init=True, repr=True, eq=True, order=False, unsafe_hash=False, frozen=False)[source]¶
Returns the same class as was passed in, with dunder methods added based on the fields defined in the class.
Examines PEP 526 __annotations__ to determine fields.
If init is true, an __init__() method is added to the class. If repr is true, a __repr__() method is added. If order is true, rich comparison dunder methods are added. If unsafe_hash is true, a __hash__() method function is added. If frozen is true, fields may not be assigned to after instance creation.
- pyspread.lib.dataclasses.field(*, default=<pyspread.lib.dataclasses._MISSING_TYPE object>, default_factory=<pyspread.lib.dataclasses._MISSING_TYPE object>, init=True, repr=True, hash=None, compare=True, metadata=None)[source]¶
Return an object to identify dataclass fields.
default is the default value of the field. default_factory is a 0-argument function called to initialize a field’s value. If init is True, the field will be a parameter to the class’s __init__() function. If repr is True, the field will be included in the object’s repr(). If hash is True, the field will be included in the object’s hash(). If compare is True, the field will be used in comparison functions. metadata, if specified, must be a mapping which is stored but not otherwise examined by dataclass.
It is an error to specify both default and default_factory.
- pyspread.lib.dataclasses.fields(class_or_instance)[source]¶
Return a tuple describing the fields of this dataclass.
Accepts a dataclass or an instance of one. Tuple elements are of type Field.
- pyspread.lib.dataclasses.is_dataclass(obj)[source]¶
Returns True if obj is a dataclass or an instance of a dataclass.
- pyspread.lib.dataclasses.make_dataclass(cls_name, fields, *, bases=(), namespace=None, init=True, repr=True, eq=True, order=False, unsafe_hash=False, frozen=False)[source]¶
Return a new dynamically created dataclass.
The dataclass name will be ‘cls_name’. ‘fields’ is an iterable of either (name), (name, type) or (name, type, Field) objects. If type is omitted, use the string ‘typing.Any’. Field objects are created by the equivalent of calling ‘field(name, type [, Field-info])’.
C = make_dataclass(‘C’, [‘x’, (‘y’, int), (‘z’, int, field(init=False))], bases=(Base,))
is equivalent to:
@dataclass class C(Base):
x: ‘typing.Any’ y: int z: int = field(init=False)
For the bases and namespace parameters, see the builtin type() function.
The parameters init, repr, eq, order, unsafe_hash, and frozen are passed to dataclass().
pyspread.lib.exception_handling module¶
exception_handling.py contains functions for handling exceptions generated by user code
Provides
get_user_codeframe()
: Returns traceback that only includes the user’sexecute code frames
- pyspread.lib.exception_handling.get_user_codeframe(tb)[source]¶
Modify traceback to only include the user code’s execution frame Always call in this fashion:
e = sys.exc_info() user_tb = get_user_codeframe(e[2]) or e[2]
so that you can get the original frame back if you need to (this is necessary because copying traceback objects is tricky and this is a good workaround)
- Parameters:
tb (
TracebackType
) – Trace back information- Return type:
pyspread.lib.file_helpers module¶
Provides
- exception pyspread.lib.file_helpers.ProgressDialogCanceled[source]¶
Bases:
Exception
Raised when a progress dialog is canceled
- pyspread.lib.file_helpers.file_progress_gen(main_window, file, title, label, no_lines, step=100)[source]¶
A generator for file iteration that displays a progress bar
Yields (line number, line string). Return value on user cancel via progress dialog is current line number
- Parameters:
- Return type:
- pyspread.lib.file_helpers.linecount(infile, buffer_size=1048576)[source]¶
Count lines in infile
Starts at current position in file. Position is not preserved. Idea taken from https://stackoverflow.com/questions/845058
- pyspread.lib.file_helpers.progress_dialog(main_window, title, label, maximum)[source]¶
contextmanager
that displays a progress dialog- Parameters:
- Return type:
ContextManager
[QProgressDialog
]
pyspread.lib.hashing module¶
File hashing services
Provides
- pyspread.lib.hashing.genkey(nbytes=64)[source]¶
Returns a random byte sting that may be used as signature key
pyspread.lib.qimage2ndarray module¶
pyspread.lib.qimage_svg module¶
High resolution svg support for qimage and matplotlib.figure
Provides
pyspread.lib.selection module¶
Grid selection representation
Provides
Selection
: Represents grid selection independently from PyQt
- class pyspread.lib.selection.Selection(block_top_left, block_bottom_right, rows, columns, cells)[source]¶
Bases:
object
Represents grid selection
- Parameters:
- cell_generator(shape, table=None)[source]¶
Returns a generator of cell key tuples
- Parameters:
shape – Grid shape
table – Third component of each returned key
- Return type:
If table is None 2-tuples (row, column) are yielded else 3-tuples
- get_bbox()[source]¶
Returns bounding box
A bounding box is the smallest rectangle that contains all selections. Non-specified boundaries are None.
- get_bottom_borders_selection(border_choice, shape)[source]¶
Get selection of cells, for which the bottom border attributes need to be adjusted on border line and border color changes.
- border_choice names are:
“All borders”
“Top border”
“Bottom border”
“Left border”
“Right border”
“Outer borders”
“Inner borders”
“Top and bottom borders”
- get_grid_bbox(shape)[source]¶
Returns bounding box within grid shape limits
A bounding box is the smallest rectangle that contains all selections. Non-specified boundaries are filled i from size.
- get_relative_access_string(shape, current)[source]¶
Get access string relative to current cell
It is assumed that the selected cells are in the same table as the current cell.
- get_right_borders_selection(border_choice, shape)[source]¶
Get selection of cells, for which the right border attributes need to be adjusted on border line and border color changes.
- border_choice names are:
“All borders”
“Top border”
“Bottom border”
“Left border”
“Right border”
“Outer borders”
“Inner borders”
“Top and bottom borders”
- insert(point, number, axis)[source]¶
Inserts number of rows/columns/tables into selection
Insertion takes place at point on axis.
- property parameters: Tuple[List[Tuple[int, int]], List[Tuple[int, int]], List[int], List[int], List[Tuple[int, int]]]¶
Tuple of selection parameters of self (self.block_tl, self.block_br, self.rows, self.columns,
self.cells)
- Type:
return
pyspread.lib.spelltextedit module¶
Provides
- class pyspread.lib.spelltextedit.LineNumberArea(parent)[source]¶
Bases:
QWidget
- Parameters:
parent (
QPlainTextEdit
) – Editor in which the line numbers shall be displayed
- class pyspread.lib.spelltextedit.PythonEnchantHighlighter(*args)[source]¶
Bases:
QSyntaxHighlighter
QSyntaxHighlighter subclass which consults a PyEnchant dictionary
- braces = ['\\{', '\\}', '\\(', '\\)', '\\[', '\\]']¶
- enable_enchant = False¶
- err_format = <PyQt6.QtGui.QTextCharFormat object>¶
- keywords = ['False', 'None', 'True', 'and', 'as', 'assert', 'async', 'await', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'nonlocal', 'not', 'or', 'pass', 'raise', 'return', 'try', 'while', 'with', 'yield']¶
- match_multiline(text, delimiter, in_state, style)[source]¶
Do highlighting of multi-line strings.
delimiter
should be a regex for triple-single-quotes or triple-double-quotes, andin_state
should be a unique integer to represent the corresponding state changes when inside those strings. Returns True if we’re still inside a multi-line string when this function is finished.
- operators = ['=', '==', '!=', '<', '<=', '>', '>=', '\\+', '-', '\\*', '/', '//', '\\%', '\\*\\*', '\\+=', '-=', '\\*=', '/=', '\\%=', '\\^', '\\|', '\\&', '\\~', '>>', '<<']¶
- class pyspread.lib.spelltextedit.SpellTextEdit(parent=None, line_numbers=True, font_family='Monospace')[source]¶
Bases:
QPlainTextEdit
QPlainTextEdit subclass which does spell-checking using PyEnchant
- createCorrectionsMenu(cursor, parent=None)[source]¶
Create and return a menu for correcting the selected word.
- createFormatsMenu(parent=None)[source]¶
Create and return a menu for selecting the spell-check language.
- createLanguagesMenu(parent=None)[source]¶
Create and return a menu for selecting the spell-check language.
- createSpellcheckContextMenu(pos)[source]¶
Create and return an augmented default context menu.
This may be used as an alternative to the QPoint-taking form of
createStandardContextMenu
and will work on pre-5.5 Qt.
- cursorForMisspelling(pos)[source]¶
Return a cursor selecting the misspelled word at
pos
orNone
This leverages the fact that QPlainTextEdit already has a system for processing its contents in limited-size blocks to keep things fast.
- max_suggestions = 20¶
- show_line_numbers(visible)[source]¶
Show line number area if visible else hide it
- Parameters:
visible (
bool
) – Line number area visibility
- spaces_per_tab = 4¶
pyspread.lib.string_helpers module¶
Provides
- pyspread.lib.string_helpers.wrap_text(text, width=80, maxlen=2000)[source]¶
Wrap text to line width
- Parameters:
text – The text to be wrapped
width – Width of the text to be wrapped
maxlen – Maximum total text length before text in truncated and extended by […]. If None then truncation is disabled.
- Returns:
Wrapped text
pyspread.lib.typechecks module¶
Functions for checking types and type likeness
Provides