lib.file_helpers.*

Provides

exception lib.file_helpers.ProgressDialogCanceled[source]

Bases: Exception

Raised when a progress dialog is canceled

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
  • main_window – Application main window

  • file (IO) – File to be iterater over

  • title (str) – Progress dialog title

  • label (str) – Progress dialog label

  • no_lines (int) – Number of lines that are remaining in file

  • step (int) – Number of lines per progress bar update

Return type

Generator[Tuple[int, str], None, None]

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

Parameters
  • infile (BinaryIO) – File like object for which lines are counted (binary mode!)

  • buffer_size (int) – Buffer size for reading the file

Return type

int

Returns

Number of newlines in infile

lib.file_helpers.progress_dialog(main_window, title, label, maximum)[source]

contextmanager that displays a progress dialog

Parameters
  • main_window (QMainWindow) – Application main window

  • title (str) – Progress dialog title

  • label (str) – Progress dialog label

  • maximum (int) – Maximum value for progress

Return type

ContextManager[QProgressDialog]