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#

discrete_colorbar(axes, csp, cdat[, lbls])

Plot colour bar using discrete colours for a small range of values.

getinfo([txt, reset])

Get time and memory info.

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

Provide slightly different placeholder functionality to textwrap.

tick_formatter(x, pos)

Format thousands separator in ticks for plots.

Module Contents#

class pygmi.misc.EmittingStream(textWritten)#

Bases: PySide6.QtCore.QObject

Class to intercept stdout for later use in a textbox.

Parameters:

textwritten (str) – Text written to stdout.

write(text)#

Write text.

Parameters:

text (str) – Text to write.

Return type:

None.

flush()#

Flush.

Return type:

None.

fileno()#

File number.

Returns:

Returns -1.

Return type:

int

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

Bases: PySide6.QtWidgets.QDialog

Basic Module.

Parameters:

parent (parent, optional) – Reference to the parent routine. The default is None.

parent#

reference to the parent routine

Type:

parent

indata#

dictionary of input datasets

Type:

dictionary

outdata#

dictionary of output datasets

Type:

dictionary

ifile#

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

Type:

str

piter#

reference to a progress bar iterator.

Type:

function

pbar#

reference to a progress bar.

Type:

function

showlog#

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

Type:

stdout or alternative

is_import#

used to indicate whether a routine contains an import within.

Type:

bool

projdata#

Project data.

Type:

dictionary

settings(nodialog=False)#

Entry point into item.

Parameters:

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

Returns:

True if successful, False otherwise.

Return type:

bool

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.

Return type:

None.

loadproj(projdata)#

Load project data into class.

Parameters:

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

Returns:

chk – A check to see if settings was successfully run.

Return type:

bool

saveproj()#

Save project data from class.

Return type:

None.

saveobj(obj)#

Save an object to a dictionary.

This is a convenience function for saving project information.

Parameters:

obj (variable) – A variable to be saved.

Return type:

None.

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

Bases: PySide6.QtWidgets.QDialog

Context Module.

Parameters:

parent (parent, optional) – Reference to the parent routine. The default is None.

parent#

reference to the parent routine

Type:

parent

indata#

dictionary of input datasets

Type:

dictionary

outdata#

dictionary of output datasets

Type:

dictionary

piter#

reference to a progress bar iterator.

Type:

function

pbar#

reference to a progress bar.

Type:

function

showlog#

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

Type:

stdout or alternative

run()#

Run context menu item.

Return type:

None.

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

Bases: PySide6.QtWidgets.QWidget

Custom buttonbox with help.

Parameters:

parent (parent, optional) – 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 (parent, optional) – 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 or QWidget) – First Widget or Label on the row.

  • widget2 (QWidget) – Last Widget.

Return type:

None.

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.

Type:

list

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

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

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 (parent, optional) – Reference to the parent routine. The default is None.

otime#

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

Type:

intr

total#

Maximum progress bar value. The default is 100.

Type:

int

iter(iterable)#

Iterate Routine.

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.

Type:

int

total#

Maximum progress bar value. The default is 100.

Type:

int

iter(iterable)#

Iterate Routine.

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, optional) – Suffix string. The default is ‘’.

Return type:

None.

setMaximum(val)#

Set the maximum value.

setValue(val)#

Set the progressbar value.

to_max()#

Set the progress to maximum.

pygmi.misc.discrete_colorbar(axes, csp, cdat, lbls=None)#

Plot colour bar using discrete colours for a small range of values.

Parameters:
  • axes (Matplotlib axes) – Current axes.

  • csp (Plot routine) – Handle to Matplotlib plotting routine.

  • cdat (numpy array) – Array of values.

  • lbls (y tick labels (optional))

Return type:

None.

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

Get time and memory info.

Parameters:
  • txt (str/int/float, optional) – Descriptor used for headings. The default is None.

  • reset (bool) – Flag used to reset the time difference to zero.

Return type:

None.

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 (sre, optional) – Placeholder when lines exceed max_lines. The default is ‘…’.

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

Returns:

text2 – Output wrapped text.

Return type:

str

pygmi.misc.tick_formatter(x, pos)#

Format thousands separator in ticks for plots.

Parameters:
  • x (float/int) – Number to be formatted.

  • pos (int) – Position of tick.

Returns:

newx – Formatted coordinate.

Return type:

str