Using Classes in App module

I’m new to Ignition and Python. I’m using version 7.6.3 for x64 windows.
I would like to understand the correct way to use class logic in scripting.

I created module app.logic with this code:

[code]class Angle():

angle = 88

def getAngle():
import system,app
return angle

def inst():
import system,app
instance = app.logic.Angle()
return instance.getAngle()[/code]

I have a button with this ActionPerformed script:

from app.logic import inst from app.logic import Angle angle = app.logic.inst() event.source.parent.getComponent('Label 1').text = str(angle)

When I click the button I get the following error:

[code]Traceback (most recent call last):
File “event:actionPerformed”, line 3, in
File “module:app.logic”, line 12, in inst
TypeError: getAngle() takes no arguments (1 given)

(stack trace removed)

Ignition v7.6.3 (b2013090513)
Java: Sun Microsystems Inc. 1.6.0_43
[/code]

Not sure if I have imports in the right places, but hoping to get 88 to display on my label.
Where have I gone wrong?

Hi RonInBako,

Python methods take their object instance (usually named self) as their first argument.

Also, you have angle as a static variable, not an instance variable. Instance variables are create inside methods and static variables are created outside methods.

Try:

def getAngle(self):
    return Angle.angle

If you want the angle variable to be an instance variable then it is done like this:

[code]class Angle():
def init(self):
self.angle = 88
def getAngle(self):
return self.angle

def inst():
import system,app
instance = app.logic.Angle()
return instance.getAngle()
[/code]
Nick

Thanks Nik, I needed to see Python Class rules in action.

Glad to know the distinction between a static and instance variable. I’m used to programming C++ and C#.