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.
So you are looking for a callback when someone clicks on a Bus. Really great idea, you could do a lot with that.
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.