Helper Functions

The helper functions are mostly involved in converting units, file saving, or have been adapted from other sources as needed.

class helpers.mock_output(*args: Any, **kwargs: Any)

Bases: KeyboardEmulation

helpers.write_command(control, text=None, value=None, visible=True, group=False)

Create RTF-formatted string.

Parameters:
  • control (str) – any RTF or RTF/CRE control word, required

  • text (str) – unformatted text, optional

  • value (int) – numeric value associated with control word, can be positive or negative

  • visible (bool) – signal that the group is set as ignored, default True

  • group (bool) – whether this command should be a group, default False

Returns:

RTF-formatted string

Return type:

str

helpers.return_commits(repo, max_entries=100)

Adapted from dulwich, returns commit info.

helpers.ms_to_hours(millis)

Convert milliseconds to formatted hour:min:sec.milli.

helpers.hours_to_ms(hour_str)

Convert formatted hour:min:sec.milli to milliseconds.

helpers.in_to_pt(inch)

Convert inch to point.

helpers.pixel_to_in(pixel)

Convert pixel to inch.

helpers.in_to_pixel(inch)

Convert inch to pixel.

helpers.inch_to_spaces(inch, chars_per_in=10)

Convert inch to approximate spaces for monospaced fonts.

helpers.save_json(json_dict, file_path)

Save dict to json file.

helpers.add_custom_dicts(custom_dict_paths, dictionaries)

Takes list of dictionary paths, returns Plover dict config.

helpers.load_dictionary_stack_from_backup(path)

Restore Plover dicts from backup file.

helpers.backup_dictionary_stack(dictionaries, path)

Takes Plover dict config, creates backup file.

helpers.remove_empty_from_dict(d)

Removes dict key:value if value is None-like recursively.

helpers.hide_file(filename)

Helper for windows os to hide autosave file.

helpers.extract_ngram(text, n=2)

Return n-gram iterator from string of text.

export_helpers.format_odf_text(block_data, style, chars_in_inch, page_width, line_num=0)

Format a string into wrapped lines for ODF.

This uses steno_wrap_ODF and does additional formatting to wrapped lines by converting necessary styling parameters.

Parameters:
  • block_data – an element_collection

  • style (dict) – styling parameters in dict

  • chars_in_inch (int) – approximate number of characters in inch for selected style font

  • page_width – page width of ODF document, in inches

  • line_num (int) – line number for starting line

Returns:

dict of dicts {line_number: {line_text, line_timestamp}}

export_helpers.format_text(block_data, style, max_char=80, line_num=0)

Format a string into wrapped lines for text.

This uses steno_wrap_plain and does additional formatting to wrapped lines by converting styling parameters to padding space characters to make formatted text lines.

Parameters:
  • block_data – an element_collection

  • style (dict) – styling parameters in dict

  • max_char (int) – maximum characters in a line

  • line_num (int) – line number for starting line

Returns:

dict of dicts {line_number: {line_text, line_timestamp}}

export_helpers.format_srt_text(block_data, line_num=0, audiostarttime='', audioendtime='')

Wrap steno data for SRT.

Parameters:
  • block_data – an element_collection for a paragraph

  • line_num (int) – starting line number

  • audiostarttime – paragraph’s audiostarttime

  • audioendtime – paragraph’s audioendtime

Returns:

dict of dicts {line_number: {line_text, line_timestamp}}

export_helpers.steno_wrap_plain(text, block_data, max_char=80, tab_space=4, first_line_indent='', par_indent='', starting_line_num=0)

Wrap steno data properly for text.

See code to compare for differences with steno_wrap_odf and steno_wrap_srt.

Parameters:
  • text (str) – text to wrap

  • block_data – an element_collection for a paragraph

  • max_char (int) – maximum number of characters per line

  • tab_space (int) – how many spaces should a tab character be converted into

  • first_line_indent (str) – string to place at beginning of first line

  • par_indent (str) – string to place at beginning of every line except first

  • starting_line_num (int) – line number to add to beginning of each line

Returns:

dict of dicts {line_number: {line_text, line_timestamp}}

export_helpers.steno_wrap_odf(block_data, max_char=80, tab_space=4, first_line_indent='', par_indent='', starting_line_num=0)

Wrap steno data properly for ODF.

Compare with steno_wrap_plain.

Parameters:
  • block_data – an element_collection for a paragraph

  • max_char (int) – maximum number of characters per line

  • tab_space (int) – how many spaces should a tab character be converted into

  • first_line_indent (str) – string to place at beginning of first line

  • par_indent (str) – string to place at beginning of every line except first

  • starting_line_num (int) – line number to add to beginning of each line

Returns:

dict of dicts {line_number: {line_text, line_timestamp}}

export_helpers.steno_wrap_srt(block_data, max_char=47, tab_space=0, first_line_indent='', par_indent='', starting_line_num=0)

Wrap steno data properly, but with audio timestamps.

Compare to steno_wrap_odf

Parameters:
  • block_data – an element_collection for a paragraph

  • max_char (int) – maximum number of characters per line

  • tab_space (int) – how many spaces should a tab character be converted into

  • first_line_indent (str) – string to place at beginning of first line

  • par_indent (str) – string to place at beginning of every line except first

  • starting_line_num (int) – line number to add to beginning of each line

Returns:

dict of dicts {line_number: {line_text, starttime, endtime}}

export_helpers.load_odf_styles(path)

Extract styles from ODT file and convert supported parameters to par and text style dicts.

export_helpers.recursive_style_format(style_dict, style, prop='paragraphproperties')

Get full style par/text format dict if style inherits from another.

export_helpers.parprop_to_blockformat(par_dict)

Take dict of paragraph attributes, return QTextBlockFormat.

export_helpers.txtprop_to_textformat(txt_dict)

Take dict of text attributes, return QTextCharFormat.