PML Customisation
User Guide
Gadget Set
:
CONTAINER Gadget
: Example of Container Gadget
Example of Container Gadget
This section creates a form, MYNETFORM, which hosts a PML.NET control.
First you will need to have created your PML.NET control - See .NET Customisation Reference Manual.
In this example the control is called MyNetControl, and comprises a text label, a toggle (NET), a button (Colour) and a AVEVA E3D™ explorer, as shown in the picture.
MyNetControl supports three events, namely OnCheck, OnPopup and OnColour.
•
OnCheck - raised when the NET toggle is clicked. Callbacks keep the PML toggle and the .NET toggle in step.
•
OnPopup - raised when the right mouse button is pressed while the cursor is over the background of the control. Callbacks edit and show the PML popup menu.
•
OnColour – raised when you select a colour from the standard Winforms colour picker (as pictured), which is shown when the colour button is pressed. Callback prints the RGB components of the selected colour.
The PML code to create and manage the form is given below. Purple is used to highlight the PML.NET commands, the rest is just standard PML2. It includes rudimentary callback methods to service the PML.NET controls events.
In the Appware you need an import command (to load the dll containing their PMLNetControls)
import 'PMLNetTest'
This is usually done once only, probably in application start-up macro. You can have it in your form, but you will then need to handle the error which will occur if the import is executed more than once:
import 'PMLNetTest'
handle (1000,0)
-- PMLNetTest dll already loaded
endhandle
-- MyNetForm.pmlfrm: Test form hosting a PMLNet Control
layout form !!MyNetForm size 25 20 dialog dock right
using namespace 'Aveva.PDMS.PMLNetTest'
member .MyCtrl is MyNetControl
!this.FormTitle = 'My PMLNet Form'
path down
-- define PML Container to host .Net control
container .NET indent PMLNETControl dock fill
-- define PML Frame
frame .PMLFrame 'PML' dock top
paragraph .PMLMessage text 'This frame contains a PML toggle button' wid 25
toggle .PMLToggle 'PML '
exit
-- define PML popup menu
menu .PMLPopup popup
!this.PMLPopup.add( 'CALLBACK', 'Attributes', '!this.attributesMenu()' )
!this.PMLPopup.add( 'CALLBACK', 'More', '!this.moreMenu()' )
!this.PMLPopup.add( 'CALLBACK', 'Last', '!this.lastMenu()')
exit
----------------------
-- MYNETFORM Constructor
----------------------
define method .MyNetForm()
using namespace 'Aveva.PDMS.PMLNetTest'
-- create instance of .Net control
!this.MyCtrl = object MyNetControl()
-- add .Net control to PML container
!this.NET.control = !this.MyCtrl.handle()
-- add PML event handlers to .Net control, to service (some of) the events it raises
!this.MyCtrl.addeventhandler('OnCheck', !this, 'NETToggleCallback')
!this.MyCtrl.addeventhandler('OnPopup', !this, 'NETPopupCallback')
!this.MyCtrl.addeventhandler('OnColour', !this, 'NETColourCallback')
-- add callback to the context menu, so you can edit the menu before it gets popped up
!this.PMLPopup.callback = '!this.editMenu()'
-- add PML callback for PML Toggle
!this.PMLToggle.callback = '!this.PMLToggleCallback(!this.PMLToggle.val)'
endmethod
----------------------
-- Callback methods
----------------------
define method .NETPopupCallback(!x is REAL, !y is REAL)
-- service the .Net control’s popup event
!this.NET.popup = !this.PMLPopup
!this.NET.showPopup( !x, !y )
endmethod
define method .editMenu()
-- Edit the popup menu which is about to be shown
!this.PMLPopup.add( 'CALLBACK', 'New field', '$p this is a new field' )
endmethod
define method .attributesMenu()
-- service the menu field
$P attributesmenu callback executed
endmethod
define method .moreMenu()
-- service the menu field
$P moremenu callback executed
endmethod
define method .lastMenu()
-- service the menu field
$P this.Lastmenu callback executed
endmethod
define method .NETToggleCallback(!checked is BOOLEAN)
-- service the ‘checked’ event for the toggle in the .Net control
-- keep PMLtoggle in step
!this.PMLToggle.val = !checked
endmethod
define method .NETColourCallback(!red is REAL, !green is REAL, !blue is REAL)
-- service the ‘colour selected’ event for the button in the .Net control
$P NetColour Callback executed: RGB = ( $!red, $!green, $!blue )
endmethod
define method .PMLToggleCallback(!checked is BOOLEAN)
-- service the PML toggle callback
-- keep .NETtoggle in step
!this.MyCtrl.val(!checked)
endmethod
1974 to current year.
AVEVA Solutions Limited and its subsidiaries. All rights reserved.