pygmi.misc#

Misc is a collection of routines which can be used in PyGMI in general.

Classes#

EmittingStream

Class to intercept stdout for later use in a textbox.

BasicModule

Basic Module.

ContextModule

Context Module.

PButtonBox

Custom buttonbox with help.

QVStack2Layout

QVStack2Layout custom Qt QGridLayot.

PTime

PTime class.

ProgressBar

Qt custom progress bar.

ProgressBarText

Text Progress bar.

Functions#

check_for_updates()

Check GitHub for updates.

getinfo([txt, reset, hide])

Get time and memory info.

textwrap2(text, width[, placeholder, max_lines])

Provide slightly different placeholder functionality to textwrap.

Module Contents#

class pygmi.misc.EmittingStream(textWritten)#

Bases: PySide6.QtCore.QObject

Class to intercept stdout for later use in a textbox.

Parameters:
  • textwritten – Function to write text to.

  • textWritten (collections.abc.Callable[..., None])

write(text)#

Write text.

Parameters:

text (str) – Text to write.

flush()#

Flush.

fileno()#

File number.

Returns:

Returns -1.

Return type:

int

class pygmi.misc.BasicModule(parent=None)#

Bases: PySide6.QtWidgets.QDialog

Basic Module.

Parameters:

parent – Reference to the parent routine. The default is None.

parent#

Reference to the parent routine

indata#

Dictionary of input datasets

outdata#

Dictionary of output datasets

ifile#

Input file, used in IO routines and to pass filename back to main.py

piter#

Reference to a progress bar iterator.

pbar#

Reference to a progress bar.

showlog#

Reference to a way to view messages, normally stdout or a Qt text box.

is_import#

Used to indicate whether a routine contains an import within.

projdata#

Project data.

settings(nodialog=False)#

Entry point into item.

Parameters:

nodialog (bool) – Run settings without a dialog. The default is False.

Returns:

True if successful, False otherwise.

Return type:

bool

check_validation()#

Check a widget’s validation.

Returns:

True if successful, False otherwise.

Return type:

bool

cmb_update(obj, txtlist)#

Update combo box.

Parameters:
  • obj (PySide6.QtWidgets.QComboBox) – Combo box to add data to.

  • txtlist (list[str]) – List of strings to add to combo box.

data_init()#

Initialise Data.

Entry point into routine. This entry point exists for the case where data must be initialised before entering at the standard ‘settings’ sub module.

loadproj(projdata)#

Load project data into class.

Parameters:

projdata (dict) – Project data loaded from JSON project file.

Returns:

A check to see if settings was successfully run.

Return type:

bool

saveproj()#

Save project data from class.

saveobj(obj)#

Save an object to a dictionary.

This is a convenience function for saving project information.

Parameters:

obj (object) – A variable to be saved.

class pygmi.misc.ContextModule(parent=None)#

Bases: PySide6.QtWidgets.QDialog

Context Module.

Parameters:

parent – Reference to the parent routine. The default is None.

parent#

Reference to the parent routine

indata#

Dictionary of input datasets

outdata#

Dictionary of output datasets

piter#

Reference to a progress bar iterator.

pbar#

Reference to a progress bar.

showlog#

Reference to a way to view messages, normally stdout or a Qt text box.

check_validation()#

Check a widget’s validation.

Returns:

True if successful, False otherwise.

Return type:

bool

cmb_update(obj, txtlist, curindex=0)#

Update combo box.

Parameters:
  • obj (PySide6.QtWidgets.QComboBox) – Combo box to add data to.

  • txtlist (list[str]) – List of strings to add to combo box.

  • curindex (int) – Current index.

run()#

Run context menu item.

class pygmi.misc.PButtonBox(parent=None)#

Bases: PySide6.QtWidgets.QWidget

Custom buttonbox with help.

Parameters:

parent – Reference to the parent routine. The default is None.

help_docs()#

Help Routine.

class pygmi.misc.QVStack2Layout(parent=None)#

Bases: PySide6.QtWidgets.QGridLayout

QVStack2Layout custom Qt QGridLayot.

This works like VBoxLayout, except each row takes two widgets.

Parameters:

parent – Reference to the parent routine. The default is None.

addWidget(widget1, widget2)#

Add two widgets on a row, widget can also be text.

Parameters:
  • widget1 (str | PySide6.QtWidgets.QWidget) – First Widget or Label on the row.

  • widget2 (PySide6.QtWidgets.QWidget | str) – Last Widget.

addWidgetOld(*args, **kwargs)#

Original Add Widget.

class pygmi.misc.PTime#

PTime class.

Main class in the ptimer module. Once activated, this class keeps track of all time since activation. Times are stored whenever its methods are called.

tchk#

List of times generated by the time.perf_counter routine.

since_first_call(msg='since first call', show=True)#

Time lapsed since first call.

This function prints out a message and lets you know the time passed since the first call.

Parameters:
  • msg (str) – Optional message, by default “since first call”

  • show (bool) – Show output, by default True.

Returns:

Time difference.

Return type:

float

since_last_call(msg='since last call', show=True)#

Time lapsed since last call.

This function prints out a message and lets you know the time passed since the last call.

Parameters:
  • msg (str) – Optional message

  • show (bool) – Show output, by default True.

Returns:

Time difference.

Return type:

float

class pygmi.misc.ProgressBar(parent=None)#

Bases: PySide6.QtWidgets.QProgressBar

Qt custom progress bar.

Progress Bar routine which expands the QProgressBar class slightly so that there is a time function as well as a convenient of calling it via an iterable.

Parameters:

parent – Reference to the parent routine. The default is None.

otime#

This is the original time recorded when the progress bar starts.

total#

Maximum progress bar value. The default is 100.

iter(iterable)#

Iterate Routine.

Parameters:

iterable (collections.abc.Iterable) – Iterable for progress bar to track.

Yields:

object – Object in iterable.

Return type:

collections.abc.Generator[object, None, None]

to_max()#

Set the progress to maximum.

class pygmi.misc.ProgressBarText#

Text Progress bar.

otime#

This is the original time recorded when the progress bar starts.

total#

Maximum progress bar value. The default is 100.

iter(iterable)#

Iterate Routine.

Parameters:

iterable (collections.abc.Iterable) – Iterable for progress bar to track.

Yields:

object – Object in iterable.

Return type:

collections.abc.Generator[object, None, None]

printprogressbar(iteration, suffix='')#

Call in a loop to create terminal progress bar.

Code by Alexander Veysov. (https://gist.github.com/snakers4).

Parameters:
  • iteration (int) – Current iteration

  • suffix (str) – Suffix string. The default is ‘’.

setMaximum(val)#

Set the maximum value.

Parameters:

val (int) – Maximum value of progressbar.

setValue(val)#

Set the progressbar value.

Parameters:

val (int) – Value of progressbar.

to_max()#

Set the progress to maximum.

pygmi.misc.check_for_updates()#

Check GitHub for updates.

Returns:

Version path, embedded in an html string.

Return type:

str

pygmi.misc.getinfo(txt=None, reset=False, hide=False)#

Get time and memory info.

Parameters:
  • txt (str | float | None) – Descriptor used for headings, by default None

  • reset (bool) – Flag used to reset the time difference to zero, by default False

  • hide (bool) – Hide the output text. Useful if you don’t want to show the initialising reading, by default False

pygmi.misc.textwrap2(text, width, placeholder='...', max_lines=None)#

Provide slightly different placeholder functionality to textwrap.

Placeholders will be a part of last line, instead of replacing it.

Parameters:
  • text (str) – Text to wrap.

  • width (int) – Maximum line length.

  • placeholder (str) – Placeholder when lines exceed max_lines. The default is ‘…’.

  • max_lines (int | None) – Maximum number of lines. The default is None.

Returns:

Output wrapped text.

Return type:

str