Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

I have been racking my brain but I can't think of a way you can get PSSE to pass you user selected data from the diagram. The API for the slider diagrams is not complete in the sense that they miss the ability to control the position of individual nodes and get user clicks.

What I suggest instead is that you could create a little pop up box that asks for the bus number. So instead of clicking on a bus, the user must type (or copy + paste) it in.

You could attach your program as a custom macro button. I'll follow up with a proof of concept soon.

click to hide/show revision 2
Added an example custom toolbar button script.

I have been racking my brain but I can't think of a way you can get PSSE to pass you user selected data from the diagram. The API for the slider diagrams is not complete in the sense that they miss the ability to control the position of individual nodes and get user clicks.

What I suggest instead is that you could create a little pop up box that asks for the bus number. So instead of clicking on a bus, the user must type (or copy + paste) it in.

from Tkinter import Tk, StringVar, Entry, Button, Label
import Queue

import psspy


def get_user_input(title, data_label, default=None):
    """
    Create a pop up with:
      - a text box;
      - OK button; and
      - text box label

    to ask for user input. Returns the string that they enter.

    If the user closes the pop up then the default value is returned.
    """
    root = Tk()
    root.wm_title(title)
    value = StringVar()
    q = Queue.Queue()

    def set_value():
        q.put(value.get())
        root.destroy()

    def get_value(default=None):
        try:
            return q.get(block=False)
        except Queue.Empty:
            return default

    Label(root, text=data_label).pack()
    Entry(root, textvariable=value).pack()
    Button(root, text="OK", command=set_value).pack()

    root.mainloop()
    return get_value(default)

def report_bus_voltage():
    """
    Asks the user for a bus number and then reports on the bus voltage.
    """
    try:
        selected_bus = int(get_user_input('PSSE', 'Get Voltage for Bus'))
    except (TypeError, ValueError):
        return "User did not select a bus"

    irr, voltage = psspy.busdat(selected_bus, string="PU")
    return voltage

if __name__ == "__main__":
    print report_bus_voltage()

You could attach your program The example script completes a trivial task, but importantly illustrates how you can prompt for user input using the built in Tkinter framework. To set this as a custom macro button. I'll Custom toolbar button follow up with a proof of concept soon.the instructions "5.2 Configuring Custom Toolbar Buttons" in the GUI Users Guide.