tabs=['Tab1','Tab2','Tab3'] # titles of the tabs
lasttab=0 # last tab clicked
reqw=600 # the width of the requester
reqh=450 # the height of the requester
# check if x,y is in the rectangle build of x1,y1 - x2,y2
def isinbox(x,y,x1,y1,x2,y2):
if x>=x1:
if x<=x2:
if y>=y1:
if y<=y2:
return(1) # yes, return 1
return(0) # no, return 0
# sub to get the vals from the controls on tab 1
def gettab1(self):
self.txtctltab1val=self.txtctltab1.get_str() # string control
self.intctltab1val=self.intctltab1.get_int() # integer control
self.fltctltab1val=self.fltctltab1.get_float() # float control
# sub to get the vals from the controls on tab 2
def gettab2(self):
self.txtctltab2val=self.txtctltab2.get_str() # string control
self.intctltab2val=self.intctltab2.get_int() # integer control
self.fltctltab2val=self.fltctltab2.get_float() # float control
# sub to get the vals from the controls on tab 3
def gettab3(self):
self.txtctltab3val=self.txtctltab3.get_str() # string control
self.intctltab3val=self.intctltab3.get_int() # integer control
self.fltctltab3val=self.fltctltab3.get_float() # float control
# sub to get the vals from all tabs
def getalltabs(self):
gettab1() # get vals from tab 1
gettab2() # get vals from tab 2
gettab3() # get vals from tab 3
# on switching to an other tab, the controls of the actual tab must been erased
def untab(self):
global lasttab # make shure we write to the global variable
if lasttab==0: # this means tab 1 was last visible
self.gettab1() # at first grab the variables from tab 1
self.txtctltab1.erase() # erase txtctl
self.intctltab1.erase() # erase intctl
self.fltctltab1.erase() # erase fltctl
elsif lasttab==1: # this means tab 2 was last visible
self.gettab2() # at first grab the variables from tab 2
self.txtctltab2.erase() # erase txtctl
self.intctltab2.erase() # erase intctl
self.fltctltab2.erase() # erase fltctl
elsif lasttab==2: # this means tab 3 was last visible
self.gettab3() # at first grab the variables from tab 3
self.txtctltab3.erase() # erase txtctl
self.intctltab3.erase() # erase intctl
self.fltctltab3.erase() # erase fltctl
lasttab=self.tabctl.get_int() # get the now visible tab and remember it
# activate the controls on tab 1
def tab1(self):
self.txtctltab1=self.panel.str_ctl("String",1) # create a string control
self.intctltab1=self.panel.int_ctl("Integer",1) # create a integer control
self.fltctltab1=self.panel.float_ctl("Float",1) # create a float control
# activate the controls on tab 2
def tab2(self):
self.txtctltab2=self.panel.str_ctl("String",1) # create a string control
self.intctltab2=self.panel.int_ctl("Integer",1) # create a integer control
self.fltctltab2=self.panel.float_ctl("Float",1) # create a float control
# activate the controls on tab 3
def tab3(self):
self.txtctltab3=self.panel.str_ctl("String",1) # create a string control
self.intctltab3=self.panel.int_ctl("Integer",1) # create a integer control
self.fltctltab3=self.panel.float_ctl("Float",1) # create a float control
# the select callback for the tab
def select_event_func(self, control, user_data):
i = self.tabctl.get_int() # get integer associated with selected tab (index of the selected tab)
self.untab() # remove all controls related to the actual tab
# build the controls related to the newly selected tab
if i == 0:
self.tab1() # tab 1
elif i == 1:
self.tab2() # tab 2
elif i == 2:
self.tab3() # tab 3
# it seems like the requester gets resized by the PCore funcs sometimes
# I did find nothing on how to avoid this, so I do a resize, if the size isn't anymore the one I want
if self.panel.getw()!=reqw: # requesterwidth is not equal the width I want
self.panel.setw(reqw) # set it again
if self.panel.geth()!=reqh: # requesterheight is not equal the height I want
self.panel.seth(reqh) # set it again
# handler for mousemove
# here we have to react on "hoover" over our custom buttons
# be careful, this will be called on every mousemove
# do not draw too many things, to avoid flickering
def mousemove(self,dontknow1,dontknow2,btnflag,x,y):
if self.isinbox(x,y,x1,y1,x2,y2)==1: # x,y is in the rectangle build of x1,y1 - x2,y2
print "we are in the rectangle"
# handler for mousebuttons
def mousebtn(self,dontknow1,dontknow2,btnflag,x,y):
if btnflag==32: # only react one time (this is called for every change on the flag)
if self.isinbox(x,y,x1,y1,x2,y2)==1:
print "we are in the rectangle"
# handler for the mousewheel
def mousewheel(self,dontknow1,dontknow2,direction,x,y):
if direction==1:
wheeldir="out"
else:
wheeldir="in"
print "mousewheel ",wheeldir," at X:",x," Y:",y
# the init of all is in the process callback of the script (entrypoint of the application)
def process(self,mod_command):
global lasttab # make shure we write into the global variable named lasttab
...
self.ui=lwsdk.LWPanels() # get shortcut to the ui
self.panel=self.ui.create("Title") # create the panel
self.panel.setw(reqw) # set the width of the panel (can be changed by the framework)
self.panel.seth(reqh) # set the height of the panel (can be changed by the framework)
...
# here you can set the callbacks for some actions. The flag corresponding to the action must be set
# at the creation of the requester
# here some callbacks of interest
# self.panel.set_resize_callback(self.panelresize) # the callback is called on resize of the tab
# I have not tested this callback until now
self.panel.set_mouse_move_callback(self.mousemove) # the callback is called on mouse movement
self.panel.set_mouse_button_callback(self.mousebtn) # the callback is called on clicking with the mouse
self.panel.set_mouse_wheel_callback(self.mousewheel)# the callback is called on mouse wheel action
...
self.tabctl=self.panel.tabchoice_ctl("Title",tabs) # The string "Title" would be normally empty
# tabs is a list ob tabnames (see above)
self.tabctl.set_event(self.select_event_func) # set the callback for tab selection
# bring all tabs (the controls in them) to a defined state
self.tab1() # create tab 1
lasttab=0 # set the active tab variable to reflect tab 1 is selected
self.untab() # grab the variables of the controls and erase the controls
self.tab2() # create tab 2
lasttab=1 # set the active tab variable to reflect tab 2 is selected
self.untab() # grab the variables of the controls and erase the controls
self.tab3() # create tab 3
lasttab=2 # set the active tab variable to reflect tab 3 is selected
self.untab() # grab the variables of the controls and erase the controls
self.panel.setw(reqw) # resize again (the framework can have changed the dimensions of the requester)
self.panel.seth(reqh) # resize again
self.tab1() # now show tab 1
lasttab=0 # set the active tab variable to reflect tab 1 is selected
# Displays the panel
# create a modal window
# do not use standard buttons
# call the mouse-handlers
# and call also on mousemove
# the last flag has no function at the moment.
if self.panel.open(lwsdk.PANF_BLOCKING | lwsdk.PANF_NOBUTT | lwsdk.PANF_MOUSETRAP | lwsdk.PANF_MOUSETRACK | lwsdk.PANF_FRAME) == 0:
self.ui.destroy(self.panel)
return lwsdk.AFUNC_OK
self.ui.destroy(self.panel)
return lwsdk.AFUNC_OK