Helper Classes

Parent Previous Next

Helper Classes

There are a number of useful classes that simplify and standardize common operations. Developers are encouraged to use these classes when possible to ensure a common user experience.

'cei' module helper classes

Some tools have been moved to the site-packages/cei directory in the apex32 python directory. Tools included in that directory include:

More tools exist, but the idea is that tools in this dir would be usable in apps that did not have the ‘ensight’ module. Note: these tools are allowed to enhance their functionality if the ‘ensight’ module is present.

cei.qtgenericdlg module

The module implements a dynamically generated modal dialog from a list of lists. It is a simpler interface to the Qt library for simple prompting and queries. This module has one class and a number of enums.  The enums defined by the module include:

Item types: ITEM_TEXT, ITEM_BOOL, ITEM_INT, ITEM_FLT, ITEM_COMBO, ITEM_STR, ITEM_STR_RO, ITEM_FILE, ITEM_PART, ITEM_VAR

File options: OPT_FILE_OPEN, OPT_FILE_SAVE, OPT_FILE_DIR

Variable options: OPT_VAR_CON, OPT_VAR_SCL, OPT_VAR_VEC, OPT_VAR_TEN, OPT_VAR_SCLCPX, OPT_VAR_VECCPX, OPT_VAR_ACT, OPT_VAR_ELEM, OPT_VAR_NODE, OPT_VAR_TIME, OPT_VAR_COORDS

Part options:OPT_PART_SINGLE, OPT_PART_STRUCT, OPT_PART_UNSTRUCT

Misc options: OPT_OBJECT 

CeiQtGenericDialog class

Methods:

dlg = CeiQtGenericDialog(items,parent=None,title="",ok="Ok",cancel="Cancel",help=None)

Constructs a generic dialog object. Items is a Python list of lists. Each list in the list describes a single dialog GUI item (see "item details" below). Options are included for the caller to support a QtWidget as the parent of the dialog and to supply text strings for the title of the dialog and the ok and cancel dialog buttons.  The help parameter allows the caller to specify an instance of an object subclassing from guibase_extension (a tool extension for example).  If the class has a help URL or HTML, a 'Help...' button will be added at the bottom of the dialog and it will display the noted URL (via web browser) or HTML via a modal dialog.

ret = dlg.doit()

Displays the dialog and allows the user to interact with it. The return value is True (non-zero) if the user clicked 'Ok'.

taglist = dlg.getValues()

Returns a list of all of the 'tags' passed in the items list in the dialog constructor.

value = dlg.getValue('tag')

Returns the final value the user entered for the item with the 'tag' when they clicked 'Ok'.

Item details:

Each list in the 'items' list has the following basic format:

['tag',type,"text","tooltip"...]

The 'tag' is a string that names the item.  This tag is used later by the getValue() method to get the actual value the user entered.  You can also get a complete list of the tags from a dialog using the getValues() method.

The type is an enum value from the list: ITEM_TEXT, ITEM_BOOL, ITEM_INT, ITEM_FLT, ITEM_COMBO, ITEM_STR, ITEM_FILE, ITEM_PART, ITEM_VAR.  Details for specific types are described later.

The 'text' string is a label that will be displayed to the left of the item in the dialog. 

The 'tooltip' is a string that will be displayed when the mouse hovers over the item in the dialog.


Each type may have other options:


A simple example of all of the item types would be:

items = []
items.append(['text',ITEM_TEXT,"Here is some example text...",""])
items.append(['bool',ITEM_BOOL,"Checkbox","An example Boolean",1])
items.append(['int',ITEM_INT,"Integer","An example integer",10,0,100])
items.append(['flt',ITEM_FLT,"Float","An example float",0.0,-10.0,10.0])
list = ["choice0","choice1","choice2"]
items.append(['combo',ITEM_COMBO,"Combo","An example Combobox",1,list])
items.append(['str',ITEM_STR,"Str","An example string","here we have a string"])
items.append(['file',ITEM_FILE,"File to read","An example file to read","/tmp", OPT_FILE_OPEN])

items.append(['file',ITEM_FILE,"File to write","An example file to write","/tmp", OPT_FILE_SAVE])
items.append(['part',ITEM_PART,"Parts:","An example partlist",[""],0])
items.append(['parto',ITEM_PART,"Object parts:","An example partlist",[""],OPT_OBJECT])
items.append(['var',ITEM_VAR,"Vars:","An example varlist","",0])
items.append(['varo',ITEM_VAR,"Object vars:","An example varlist","",OPT_OBJECT|OPT_VAR_SCL|OPT_VAR_VEC])
a = CeiQtGenericDialog(items,None,"Test case","Ok","Cancel")
ret = a.doit()
print("Return = {}".format(ret))
for i in a.getValues():
    print("value for {} is {}".format(i, a.getValue(i)))

#
# Looking for part IDs?  Use the object interface and a little glue
#
from cei.qtgenericdlg import *
items = []
items.append(['parts',ITEM_PART,"Parts:","An example partlist",[""],OPT_OBJECT])
dlg = CeiQtGenericDialog(items,None,"Test case","Ok","Cancel")
ret = dlg.doit()
if (ret):
    part_ids = map(lambda x: x.PARTNUMBER, dlg.getValue('parts'))
    print("Part ids: {}".format(part_ids))


Note: this class is also available for non-EnSight use (e.g. cpython21), but the variable and part item types are not supported.

'ensight.core' module helper classes