simetrix.ProgressBox

class simetrix.ProgressBox(numSteps: int, displayMessage: str, statusMessage: str, caption: str = 'Python running', abortMethod: ProgressBoxAbortMethod = ProgressBoxAbortMethod.GRACEFUL, modeless: bool = False)

Bases: object

Intended to be used with Python’s with statement, this class manages a progress box used to display the progress of an operation.

Example

import simetrix as sx

schematic = sx.currentSchematic()

if schematic.valid :

    oldValue = schematic.setComponentValue("R1.VALUE", "{RLOAD}").value

    loads = [5,10,20,40,100]

    # Open progress box
    with sx.ProgressBox(5, "", "Running simulation, click <b>Abort</b> to abort") as progressBox :

        for load in loads :
            # Update progress box. If update returns True, exit loop
            if progressBox.update("Load=" + str(load)+ "") :

                print("Run Aborted")
                break

            result = schematic.run(["RLOAD="+str(load)])
            print("load=", load)
            if result.status==sx.RunStatus.success :
                print("success")

            else :
                print(result.status)

    schematic.setComponentValue("R1.VALUE", oldValue)

else :
    print("There are no schematics open")

Methods

close()

Close box.

open()

Open box.

update(statusMessage)

Increments step.

__init__(numSteps: int, displayMessage: str, statusMessage: str, caption: str = 'Python running', abortMethod: ProgressBoxAbortMethod = ProgressBoxAbortMethod.GRACEFUL, modeless: bool = False)

Constructor.

Parameters:
  • numSteps (int) – Number of steps that represents 100%. On each call to update, the step count is incremented, when the step count reaches this value the progress bar will show 100%.

  • statusMessage (str) – The initial status message that shows below the progress bar when the box first opens. This is updated by the update method. HTML tags may be used in the string.

  • displayMessage (str) – The fixed message displayed above the progress bar. HTML tags may be used in the string.

  • abortMethod (ProgressBoxAbortMethod) –

    Action when the Abort button is clicked. If set to ProgressBoxAbortMethod.GRACEFUL, the Abort button will cause the next call to update to return True allowing the Python to code to exit the process gracefully. If set ProgressBoxAbortMethod.FORCED, the Python script will terminate immediately.

    Note that it will not be possible to click the Abort button unless the GUI event loop is called. This occurs automatically when any SIMetrix function or method is called but can also be explicitly called using processEvents().

  • modeless (bool) – If True, the progress box will be modeless meaning that interaction with the rest of the application will still be possible. If omitted or False the progess box will be modal and all interaction with the application will be inhibited until the box is closed.

close()

Close box. If using with, it is not necessary to call this as the box will automatically close when the with statement ends. However this function can be used to close the box early if required.

open()

Open box. Use this function to open the box if not being called using with.

update(statusMessage: str) bool

Increments step. Returns True if an Abort has been requested. The status message, displayed below the progress bar, will be updated accordingly.