PDA

View Full Version : Tabbed interfaces



Phil
02-11-2013, 01:25 PM
Nosing around, I didn't manage to find an example to show how a tabbed interface can be created and managed, including the controls on those tabs. Anyone aware of a simple bare-bones example?

Styler
02-12-2013, 02:30 AM
I hope this will help )



import lwsdk

__author__ = "User"
__copyright__ = "Copyright (C) 2013"
__version__ = "1.0"
__maintainer__ = "User"
__email__ = "[email protected]"
__status__ = "test"
__lwver__ = "11"

WIN_SIZE = (100,100)

class TestPlg(lwsdk.IGeneric):
def __init__(self, context):
super(TestPlg, self).__init__()

def process(self, ga):
self.inter_ui()
return lwsdk.AFUNC_OK

def onTabCtrl(self, control, userdata):
def _cls():
'''This help-function creates fake button and deletes it for clearing panel purposes.
Some of controls (like text_ctl) don't clean up their space on panel after calling 'erase'.'''
b = self.win.button_ctl('')
b.move(0,0)
b.set_h(WIN_SIZE[0])
b.set_w(WIN_SIZE[1])
b.erase()

def _getTabControls(iTab):
'''Returns pairs (renderCtlItems, eraseCtlItems)'''
ren, ers = self.uiTabsCtls[iTab], ()
for i in self.uiTabsCtls:
ers+=i
return (ren,ers)
#----
renderCtls,eraseCtls = _getTabControls(self.tabs.get_int())
map(lambda x:x.erase(), eraseCtls)
_cls() # clean up the panel just in case
map(lambda x:x.render(), renderCtls)

def inter_ui(self):
ui = lwsdk.LWPanels()
self.win = ui.create("Tabs test")
self.win.setw(WIN_SIZE[0])
self.win.seth(WIN_SIZE[1])

# create Tab control
self.tabs = self.win.tabchoice_ctl('',(' Tab1 ',' Tab2 ',' Tab3 '))
self.tabs.move(0,0)
self.tabs.set_event(self.onTabCtrl)

# [ Tab1 ]
b1 = self.win.button_ctl('button')
b1.move(8,24)
b1.set_w(42)
b1.set_h(32)
b2 = self.win.bool_ctl('bool control')
b2.move(8,60)
b2.set_int(1)

# [ Tab2 ]
txt1 = self.win.text_ctl('Test label1','')
txt1.move(4,24)
txt2 = self.win.text_ctl('Test label2','')
txt2.move(4,44)

# [ Tab3 ]
bCh_30 = self.win.hchoice_ctl('Choice control', ('item1','item2','item3'))
bCh_30.move(8,24)
bCh_30.set_int(2)

# 'container' for tabs controls.
self.uiTabsCtls = ((b1,b2), (txt1,txt2), (bCh_30,))

self.onTabCtrl(0,0) # redraw tabs
self.win.size_to_layout(0, 0)

if self.win.open(lwsdk.PANF_NOBUTT) == 0:
ui.destroy(self.win)
return lwsdk.AFUNC_OK
return lwsdk.AFUNC_OK

#------------------------------------
ServerTagInfo = [
( "Python Test", lwsdk.SRVTAG_USERNAME | lwsdk.LANGID_USENGLISH ),
( "Test", lwsdk.SRVTAG_BUTTONNAME | lwsdk.LANGID_USENGLISH ),
( "Utilities/Python", lwsdk.SRVTAG_MENU | lwsdk.LANGID_USENGLISH )
]

ServerRecord = { lwsdk.GenericFactory("tabs_test", TestPlg) : ServerTagInfo }

Phil
02-12-2013, 05:43 AM
That's perfect, thank you so much!