7.5  Writing Interfaces

7.5.1  Anatomy of an Interface

A control interface file is a Python module whose name, by convention, starts with an "I". The module contains a class of the same name without any implementations, deriving from the Interface base class. It only contains comments and declarations of properties.

The neccessary classes Interface and Permission can both be loaded from libdesklets.controls:

from libdesklets.controls import Interface, Permission
  

7.5.2  Declaring Properties

A property declaration consist of the property's name along with its access permission. The valid permissions are:

  • Permission.READ - the property is read-only
  • Permission.WRITE - the property is write-only
  • Permission.READWRITE - the property is readable and writable

A property is declared by assigning the appropriate permission object to its name, like this:

myproperty = Permission.READWRITE
  

7.5.3  Deriving from Interfaces

Interfaces can extend other interfaces by deriving from them. A control implementing the extended interface automatically implements the original interface, too.

Since interfaces are classes, you just have to load the original class and derive from it:

from IOriginal1 import IOriginal1
from IOriginal2 import IOriginal2

class IExtended(IOriginal1, IOriginal2):

    ...
  

It is an error if a property is declared more than once in the class hierarchy.

Please include the original interface files with your control as well, since they are required for running the control.