Ask Your Question
2

Interacting with PSSE GUI

asked 2012-03-22 12:08:24 -0500

chip gravatar image

updated 2012-03-23 08:46:15 -0500

I'm trying to determine what hooks the PSSE API has into the PSSE GUI. The only API functions I can find are related to the Graphical Analysis Output.

I would like to:

  1. Select a bus on the Diagram canvas
  2. Get the bus number from an API function called from PSSE

Actually, any flow[1] that lets a user choose something in PSSE and use that choice in the API would be appreciated. Is anything like this possible with PSSE?

EDIT: [1] Detecting selected items from the network spreadsheets (bus, branch, machine, etc) would also be helpful, but that ability seems even more unlikely.

edit retag flag offensive close merge delete

Comments

So you are looking for a callback when someone clicks on a Bus. Really great idea, you could do a lot with that.

JervisW gravatar imageJervisW ( 2012-03-22 19:55:44 -0500 )edit

Has anyone ever tried to use Python to directly wrap the PSSE dll files? We might be able to do this if we can access the guts of PSSE.

JervisW gravatar imageJervisW ( 2012-03-23 16:30:54 -0500 )edit

2 answers

Sort by » oldest newest most voted
3

answered 2014-01-06 11:27:17 -0500

nwilson gravatar image

It can be done using the sliderPy library

import sliderPy

def main():
    mydoc = sliderPy.GetActiveDocument()
    mydiagram = mydoc.GetDiagram()
    mycomponents = mydiagram.GetComponents()
    print str(len(mycomponents)) + " components found"
    i = 0
    for mycomponent in mycomponents:
        if mycomponent.IsSelected() == True:
            print 'Type: ' + str(mycomponent.GetComponentType())
            mylabels = mycomponent.GetOwnedLabels()
            print str(len(mylabels)) + ' labels found'
            j = 1
            for mylabel in mylabels:
                print 'Label ' + str(j) + ': ' + mylabel.GetText()
                print '\n'
                j += 1
        i += 1
        #if i == 10: break

    print str(i) + ' items searched'

if __name__ == '__main__':
    main()
edit flag offensive delete link more

Comments

This answer extracts the label information to identify buses. A better solution using the getmapstring function in sliderpy is shown in the "get id from selected branch" question.

nwilson gravatar imagenwilson ( 2017-01-22 23:12:16 -0500 )edit
1

answered 2012-03-22 20:06:28 -0500

JervisW gravatar image

updated 2012-03-23 05:05:44 -0500

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()

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 toolbar button follow the instructions "5.2 Configuring Custom Toolbar Buttons" in the GUI Users Guide.

edit flag offensive delete link more

Comments

I was afraid of that. I already wrote some [very ugly] Tkinter, but I was getting tired of typing bus numbers and was hoping to improve it. This is a nice example to come back to.

chip gravatar imagechip ( 2012-03-23 08:33:33 -0500 )edit

I've seen other tools get around similar API limitations by popping a dialog where you can select multiple buses from a listbox populated with all the buses. I guess it just depends on your pain tolerance for writing GUIs.

chip gravatar imagechip ( 2012-03-23 08:40:25 -0500 )edit

Would it be helpful if I wrote a script so anyone could add a listbox bus selector to their project?

JervisW gravatar imageJervisW ( 2012-03-23 16:28:35 -0500 )edit

@JervisW I was just going to wait for PSSEv33 so I could use wxPython which I'm a bit more familiar with :) Don't bother with it on my account, I can do Tkinter if I need it.

chip gravatar imagechip ( 2012-03-23 17:09:41 -0500 )edit

wxPython is a much nicer package to work in. So is wxPython a requirement for PSSEv33? Why do you have to wait, can't you begin using it now?

JervisW gravatar imageJervisW ( 2012-03-25 05:19:00 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

[hide preview]

Question Tools

Stats

Asked: 2012-03-22 12:08:24 -0500

Seen: 3,682 times

Last updated: Jan 06 '14