# Returning lists of arguments for bound methods

**URL:** <https://forum.inductiveautomation.com/t/returning-lists-of-arguments-for-bound-methods/52040>\
**Category:** Ignition\
**Tags:** scripting\
**Created:** [October 18, 2021, 4:00am UTC](https://forum.inductiveautomation.com/t/returning-lists-of-arguments-for-bound-methods/52040 "2021-10-18T04:00:53Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![seano](https://avatars.discourse-cdn.com/v4/letter/s/d2c977/32.png) [@seano](https://forum.inductiveautomation.com/u/seano)\
**Post date:** [October 18, 2021, 4:00am UTC](https://forum.inductiveautomation.com/t/returning-lists-of-arguments-for-bound-methods/52040/1 "2021-10-18T04:00:53Z")

</div>

Hi, this is a follow on and generalisation from the discussion at [Power Table header height](https://forum.inductiveautomation.com/t/power-table-header-height/12796)

If I want to interrogate a Vision component and find out how to do things with it that aren't documented, very often it's useful to use dir() to return a list of attributes. Then with a bit of trial and error, either writing to properties directly or using a bound method lets me do what I want to do.

But I run into a roadblock when dealing with bound methods without obvious arguments.

As an example, if I want to use code similar to that in the linked post, but change the header font of a table, I go:

> from java.awt import  
> Dimension table = self.getTable()  
> header = table.getTableHeader()  
> **header.setFont( ???? )**  
> header.revalidate()

But I have no idea in advance what arguments to use for header.setFont.  
What are the arguments for setFont?

And, more importantly,  
How do you return a list of arguments for a bound method like this?

Kind regards,  
Sean

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [October 18, 2021, 4:38am UTC](https://forum.inductiveautomation.com/t/returning-lists-of-arguments-for-bound-methods/52040/2 "2021-10-18T04:38:47Z")

</div>

This might be useful:  
[https://files.inductiveautomation.com/sdk/javadoc/ignition81/8.1.1/index.html](https://files.inductiveautomation.com/sdk/javadoc/ignition81/8.1.1/index.html)

Although the v7 one was better for navigating around:  
[http://files.inductiveautomation.com/sdk/javadoc/ignition79/795/index.html](http://files.inductiveautomation.com/sdk/javadoc/ignition79/795/index.html)

setFont requires a [Java.awt.Font](https://docs.oracle.com/javase/7/docs/api/java/awt/Font.html) object. If you just want to change an attribute of the current font, you can use getFont() to get the current font and then manip that.

PS to find those two APIs, just search “Ignition API” in Google and you’ll find the [SDK guide](https://docs.inductiveautomation.com/display/SE/Introduction) which has those links there

---

<div class="post-metadata">

**Author:** ![seano](https://avatars.discourse-cdn.com/v4/letter/s/d2c977/32.png) [@seano](https://forum.inductiveautomation.com/u/seano)\
**Post date:** [October 18, 2021, 5:09am UTC](https://forum.inductiveautomation.com/t/returning-lists-of-arguments-for-bound-methods/52040/3 "2021-10-18T05:09:33Z")

</div>

Hi Nick, thank you so much, those were really helpful.

I managed to use the constructor detail at the Java.awt.Font object page to end up with

> header.setFont("Dialog",1,24)  
> which gave me what I wanted in this case.

Just a few questions, if you feel like them:

1. Is there a way to actually return the arguments directly without using external documentation? (Guessing no given your answer but asking anyway).

2. The reason I couldn't figure this one out was that when I printed out the results from header.getFont, it returned this:

> java.awt.Font[family=Dialog,name=Dialog,style=bold,size=20]

I "followed my nose" and quickly found that setFont doesn't allow you to use keywords, etc, etc, so I couldn't find a way to manipulate it easily.

So as a general practice, was the way that worked for me this time - namely, going to the java documentation and looking for the constructor for that object - what I should do when I'm trying to define object in general?

1. Is it OK to just import java.awt (or even java), or should I just import the object I need, in this case java.awt.Font? What sort of impact does it have on performance to import the whole .awt library?

Thanks once more for your help, I have no software background but am self teaching, and a little assistance sometimes saves a lot of heartache.

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [October 18, 2021, 6:01am UTC](https://forum.inductiveautomation.com/t/returning-lists-of-arguments-for-bound-methods/52040/4 "2021-10-18T06:01:52Z")

</div>

> [@seano](#):
>
> Is there a way to actually return the arguments directly without using external documentation? (Guessing no given your answer but asking anyway).

Most likely not:

> <https://stackoverflow.com/questions/2237803/can-i-obtain-method-parameter-name-using-java-reflection/2237910#2237910>

> [@seano](#):
>
> So as a general practice, was the way that worked for me this time - namely, going to the java documentation and looking for the constructor for that object - what I should do when I’m trying to define object in general?

Yes, the java docs will tell you how to use the objects you're looking at using. Can't drive without being taught how the clutch works! (and no, automatic cars aren't real cars)

> [@seano](#):
>
> s it OK to just import java.awt (or even java), or should I just import the object I need, in this case java.awt.Font? What sort of impact does it have on performance to import the whole .awt library?

Not sure of impacts I presume it would increase memory usage and possibly increase load time, but I would suggest not importing things you don't need; only import what you need.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [October 18, 2021, 12:29pm UTC](https://forum.inductiveautomation.com/t/returning-lists-of-arguments-for-bound-methods/52040/5 "2021-10-18T12:29:48Z")

</div>

Y'all might find this topic helpful:

> [@Finding all available methods from a component](https://forum.inductiveautomation.com/t/finding-all-available-methods-from-a-component/9670/2):
>
> I’ve attached the introspect() function that I wrote years ago (in the FPMI days). Still handy today. I suggest you load it as a shared module, then call it like: powerTable = event.source.parent.getComponent('Power Table') shared.inspect.introspect(powerTable) inspect.py (3.09 KB) Edit: Link expired. Use the version shown below.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [October 18, 2021, 4:08pm UTC](https://forum.inductiveautomation.com/t/returning-lists-of-arguments-for-bound-methods/52040/6 "2021-10-18T16:08:09Z")

</div>

> [@seano](#):
>
> Is there a way to actually return the arguments directly without using external documentation? (Guessing no given your answer but asking anyway).

Nope. Technically JVM bytecode does allow for named method arguments, but in practice no Java compiler retains that information (other JVM languages can, though), so there's nothing to reconstruct at runtime.

> [@seano](#):
>
> I “followed my nose” and quickly found that setFont doesn’t allow you to use keywords, etc, etc, so I couldn’t find a way to manipulate it easily.

Yes, this is an unfortunate clash with the style of Python and Java. Jython allows you to decorate a Java method specially to allow for keyword invocation, which we try to do for our scripting functions, but we can't decorate classes outside of our codebase like this.

> [@seano](#):
>
> So as a general practice, was the way that worked for me this time - namely, going to the java documentation and looking for the constructor for that object - what I should do when I’m trying to define object in general?

The short answer is that it depends. When working in Vision, most things you interact with are either directly or indirectly instances of some Java Swing base class, so building up a working knowledge of Swing (and its predecessor, AWT, whose Font and Color and various other classes are still used) is useful.

> [@seano](#):
>
> Is it OK to just import java.awt (or even java), or should I just import the object I need, in this case java.awt.Font? What sort of impact does it have on performance to import the whole .awt library?

Jython's import system is complicated and somewhat fraught. I _always_ use direct, fully-qualified references, so:

### Good:

`from java.awt import Font`  
`from java.awt import Font, Color`

### Bad:

`import java.awt`  
`from java.awt import *`

It's more verbose, which is a shame, but it's very explicit about what you're importing (good for future maintenance) and has never caused me any headaches with stale imports or other weird problems.

Also, Phil's `introspect.py` is _amazingly useful_, because it retrieves typed method arguments in a way that `dir` cannot.

---

<div class="post-metadata">

**Author:** ![seano](https://avatars.discourse-cdn.com/v4/letter/s/d2c977/32.png) [@seano](https://forum.inductiveautomation.com/u/seano)\
**Post date:** [October 25, 2021, 8:26pm UTC](https://forum.inductiveautomation.com/t/returning-lists-of-arguments-for-bound-methods/52040/7 "2021-10-25T20:26:50Z")

</div>

Hi, just wanted to say a big thank you to all three of you @nminchin, @pturmel, @paul-griffith. This was really helpful for me. I’m a lurker in these forums and it was pretty cool to have the equivalent of an all-star team helping me out here.

Phil, I’ll try out introspect next time I run into a similar case.

EDIT: Added concurrence that autos are indeed not real cars.
