Update filters.py to allow tabbed filter inputs

Major revision to filter.py to allow the use of lists of tuples for which each tuple element on the list will produce a tab.  Tuples are also acceptable values, so no changes are necessary to existing filters.

Relies on additional revisions in tab_panel.py

For more information: http://www.youtube.com/watch?v=NXN8R1BIIuk
This commit is contained in:
KaboPC 2012-09-14 22:49:19 -03:00
parent e962e60ac5
commit e3328b2b71

View File

@ -13,6 +13,7 @@ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.""" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE."""
from toolbasics import * from toolbasics import *
from albow.dialogs import wrapped_label from albow.dialogs import wrapped_label
from albow import *
def alertFilterException(func): def alertFilterException(func):
@ -25,23 +26,72 @@ def alertFilterException(func):
return _func return _func
def addNumField(page, optionName, val, min=None, max=None):
if isinstance(val, float):
ftype = FloatField
else:
ftype = IntField
if min == max:
min = None
max = None
field = ftype(value=val, width=100, min=min, max=max)
page.optionDict[optionName] = AttrRef(field, 'value')
row = Row([Label(optionName), field])
return row
class FilterModuleOptions(Widget): class FilterModuleOptions(Widget):
is_gl_container = True is_gl_container = True
def __init__(self, tool, module, *args, **kw): def __init__(self, tool, module, *args, **kw):
Widget.__init__(self, *args, **kw) Widget.__init__(self, *args, **kw)
rows = []
self.optionDict = {}
self.tool = tool self.tool = tool
cols = [] pages = TabPanel()
height = 0 pages.is_gl_container = True
max_height = 550 self.pages = pages
self.optionDict = {}
pageTabContents = []
print "Creating options for ", module print "Creating options for ", module
if hasattr(module, "inputs"): if hasattr(module, "inputs"):
if isinstance(module.inputs, list):
for tabData in module.inputs:
title, page, pageRect = self.makeTabPage(self.tool, tabData)
pages.add_page(title, page)
pages.set_rect(pageRect.union(pages._rect))
elif isinstance(module.inputs, tuple):
title, page, pageRect = self.makeTabPage(self.tool, module.inputs)
pages.add_page(title, page)
pages.set_rect(pageRect)
else:
self.size = (0, 0)
for optionName, optionType in module.inputs: pages.shrink_wrap()
self.add(pages)
self.shrink_wrap()
if len(pages.pages):
if(pages.current_page != None):
pages.show_page(pages.current_page)
else:
pages.show_page(pages.pages[0])
for eachPage in pages.pages:
self.optionDict = dict(self.optionDict.items() + eachPage.optionDict.items())
def makeTabPage(self, tool, inputs):
page = Widget()
page.is_gl_container = True
rows = []
cols = []
height = 0
max_height = 550
page.optionDict = {}
page.tool = tool
title = "Tab"
for optionName, optionType in inputs:
if isinstance(optionType, tuple): if isinstance(optionType, tuple):
if isinstance(optionType[0], (int, long, float)): if isinstance(optionType[0], (int, long, float)):
if len(optionType) > 2: if len(optionType) > 2:
@ -50,42 +100,71 @@ class FilterModuleOptions(Widget):
min, max = optionType min, max = optionType
val = min val = min
rows.append(self.addNumberField(optionName, val, min, max)) rows.append(addNumField(page, optionName, val, min, max))
if isinstance(optionType[0], (str)):
if len(optionType) == 3:
a,b,c = optionType
if a == "strValSize":
field = TextField(value=b, width=c)
page.optionDict[optionName] = AttrRef(field, 'value')
row = Row((Label(optionName), field))
rows.append(row)
elif len(optionType) == 2:
a,b = optionType
if a == "strVal":
field = TextField(value=b, width=200)
page.optionDict[optionName] = AttrRef(field, 'value')
row = Row((Label(optionName), field))
rows.append(row)
elif a == "strSize":
field = TextField(value="Input String Here", width=b)
page.optionDict[optionName] = AttrRef(field, 'value')
row = Row((Label(optionName), field))
rows.append(row)
if isinstance(optionType[0], (str, unicode)): if isinstance(optionType[0], (str, unicode)):
choiceButton = ChoiceButton(map(str, optionType)) choiceButton = ChoiceButton(map(str, optionType))
self.optionDict[optionName] = AttrRef(choiceButton, 'selectedChoice') page.optionDict[optionName] = AttrRef(choiceButton, 'selectedChoice')
rows.append(Row((Label(optionName), choiceButton))) rows.append(Row((Label(optionName), choiceButton)))
elif isinstance(optionType, bool): elif isinstance(optionType, bool):
cbox = CheckBox(value=optionType) cbox = CheckBox(value=optionType)
self.optionDict[optionName] = AttrRef(cbox, 'value') page.optionDict[optionName] = AttrRef(cbox, 'value')
row = Row((Label(optionName), cbox)) row = Row((Label(optionName), cbox))
rows.append(row) rows.append(row)
elif isinstance(optionType, (int, float)): elif isinstance(optionType, (int, float)):
rows.append(self.addNumberField(optionName, optionType)) rows.append(addNumField(self, optionName, optionType))
elif optionType == "blocktype" or isinstance(optionType, materials.Block): elif optionType == "blocktype" or isinstance(optionType, materials.Block):
blockButton = BlockButton(self.tool.editor.level.materials) blockButton = BlockButton(tool.editor.level.materials)
if isinstance(optionType, materials.Block): if isinstance(optionType, materials.Block):
blockButton.blockInfo = optionType blockButton.blockInfo = optionType
row = Column((Label(optionName), blockButton)) row = Column((Label(optionName), blockButton))
self.optionDict[optionName] = AttrRef(blockButton, 'blockInfo') page.optionDict[optionName] = AttrRef(blockButton, 'blockInfo')
rows.append(row) rows.append(row)
elif optionType == "label": elif optionType == "label":
rows.append(wrapped_label(optionName, 50)) rows.append(wrapped_label(optionName, 50))
elif optionType == "string": elif optionType == "string":
field = TextField(value="string") field = TextField(value="Input String Here", width=200)
self.optionDict[optionName] = AttrRef(field, 'value') page.optionDict[optionName] = AttrRef(field, 'value')
row = Row((Label(optionName), field)) row = Row((Label(optionName), field))
rows.append(row) rows.append(row)
elif optionType == "title":
title = optionName
else: else:
raise ValueError(("Unknown option type", optionType)) raise ValueError(("Unknown option type", optionType))
@ -106,26 +185,10 @@ class FilterModuleOptions(Widget):
cols.append(Column(rows)) cols.append(Column(rows))
if len(cols): if len(cols):
self.add(Row(cols)) page.add(Row(cols))
self.shrink_wrap() page.shrink_wrap()
else:
self.size = (0, 0)
def addNumberField(self, optionName, val, min=None, max=None): return (title, page, page._rect)
if isinstance(val, float):
ftype = FloatField
else:
ftype = IntField
if min == max:
min = None
max = None
field = ftype(value=val, width=100, min=min, max=max)
self.optionDict[optionName] = AttrRef(field, 'value')
row = Row([Label(optionName), field])
return row
@property @property
def options(self): def options(self):