#! /usr/bin/env python
# -*- Mode: Python -*-
# -*- coding: ascii -*-
"""
Example1: This code is generated by nuSoft's GUI-Designer
"""
import lwsdk
# TODO: Edit the following block to your needs
__author__ = 'Name'
__date__ = 'Date'
__copyright__ = 'Copyright by...'
__version__ = 'Version'
__maintainer__ = 'Maintainer'
__email__ = '[email protected]'
__status__ = 'under developement'
__lwver__ = '11'
# space for global variables
class Example1(lwsdk.ICommandSequence):
def __init__(self,context):
super(Example1, self).__init__()
retval = 2 # the mousebuttonhandler will close the dialog if there is 0 (cancel) or 1 (ok)
# TODO: use this variables as the control variables and initialize them with your needs
ctlMultiList1txts = [
['Red', '255', '0', '0'],
['Green', '0', '255', '0'],
['Blue', '0', '0', '255']
]
ctlMultiList1titles = [
"Color",
"R",
"G",
"B"
]
ctlMultiList1colwidth = [
100,
45,
45,
45
]
def isinbox(self,x,y,x1,y1,x2,y2):
if x>=x1 and x<=x2 and y>=y1 and y<=y2:
return(1)
return(0)
def isinctl(self,x,y,ctl):
return(self.isinbox(x,y,ctl.hotx(),ctl.hoty(),ctl.hotx()+ctl.hotw(),ctl.hoty()+ctl.hoth()))
# control functions of ctlMultiList1 --------------------------------
def ctlMultiList1NameFn(self,ctl,udat,row,col):
if row<0:
return(self.ctlMultiList1titles[col])
return(self.ctlMultiList1txts[row][col])
def ctlMultiList1CountFn(self,ctl,udat):
return(len(self.ctlMultiList1txts))
def ctlMultiList1ColumnFn(self,ctl,udat,col):
if col==0: return(100)
if col==1: return(45)
if col==2: return(45)
if col==3: return(45)
return(0) # no more columns
# control functions of ctlButton2 --------------------------------
def ctlButton2EventFn(self,ctl,udat):
self.retval=1
self.panel.close()
def createControls(self):
self.ctlMultiList1 = self.panel.multilist_ctl("", 260, 1, self.ctlMultiList1NameFn, self.ctlMultiList1CountFn, self.ctlMultiList1ColumnFn)
self.ctlMultiList1.move(20,10); self.ctlMultiList1.set_w(260); self.ctlMultiList1.set_h(150)
self.ctlButton2 = self.panel.button_ctl("OK")
self.ctlButton2.move(10,175); self.ctlButton2.set_w(80); self.ctlButton2.set_h(22)
self.ctlButton2.set_event(self.ctlButton2EventFn)
def panel_resize(self,ctl,udat,width,height):
# TODO: implement code for panel resize handling here
return
def mousemove_callback(self,panel,udat,btnflg,x,y):
# TODO: implement code for mouse move handling here
# Info: all mousemove handlers of the controls will be called here
# Info: the actions can be done here, or in the called handler
return
def mousebutton_callback(self,panel,udat,btnflg,x,y):
# TODO: implement code for mouse button handling here
# Info: all mousebutton handlers of the controls will be called here
# Info: the actions can be done here, or in the called handler
if self.retval == 0 or self.retval == 1:
self.panel.close()
def process(self, mod_command):
reqw = 300 # define the width of the requester
reqh = 210 # define the height of the requester
self.ui = lwsdk.LWPanels()
self.panel = self.ui.create('Example1') # create the panel
self.panel.set_resize_callback(self.panel_resize) # define the handler for resize events
self.panel.set_mouse_move_callback(self.mousemove_callback) # set the handler for mousemove actions
self.panel.set_mouse_button_callback(self.mousebutton_callback) # set the handler for mousebutton actions
self.createControls()
self.panel.setw(reqw)
self.panel.seth(reqh)
if self.panel.open(lwsdk.PANF_BLOCKING | lwsdk.PANF_NOBUTT | lwsdk.PANF_MOUSETRAP | lwsdk.PANF_MOUSETRACK | lwsdk.PANF_FRAME) == 0:
# TODO: code your CANCEL actions here
self.ui.destroy(self.panel)
return lwsdk.AFUNC_OK
# TODO: code your OK actions here
if self.retval==0: # TODO: code your custom cancel-button actions here
pass
else: # TODO: code your custom ok-button actions here
pass
self.ui.destroy(self.panel)
return lwsdk.AFUNC_OK
ServerTagInfo = [
( "PyExample1", lwsdk.SRVTAG_USERNAME | lwsdk.LANGID_USENGLISH ),
( "Example1", lwsdk.SRVTAG_BUTTONNAME | lwsdk.LANGID_USENGLISH ),
( "Utilities/Python", lwsdk.SRVTAG_MENU | lwsdk.LANGID_USENGLISH )
]
ServerRecord = { lwsdk.CommandSequenceFactory("PythExample1", Example1) : ServerTagInfo }