Created
April 10, 2015 21:22
-
-
Save metaperl/2f6d088dd9a718e305df to your computer and use it in GitHub Desktop.
nagare select box
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import with_statement | |
from nagare import editor, presentation, component, validator | |
class Option: | |
def __init__(self): | |
self.option2 = 'opt1' | |
self.option_result = '' | |
class OptionEditor(editor.Editor): | |
def __init__(self, option): | |
self.list1 = ['a', 'b', 'c'] | |
self.list2 = ['1', '2', '3'] | |
self.option = 'opt1' | |
super(OptionEditor, self).__init__(option, ('option_result', 'option2')) | |
def test(self, opt): | |
self.option = opt | |
def commit(self): | |
super(OptionEditor, self).commit(('option_result')) | |
@presentation.render_for(OptionEditor) | |
def render(self, h, comp, *args): | |
with h.form: | |
h << 'option1 ' << h.input(type='radio', name='option').action(self.test('opt1')).selected(self.option == 'opt1') << h.br #<< h.a('X').action(self.test('opt1')) << h.br | |
h << 'option2 ' << h.input(type='radio', name='option').action(self.test('opt2')).selected(self.option == 'opt2') << h.br #<< h.a('X').action(self.test('opt2')) << h.br | |
with h.select(multiple='multiple').action(self.option_result): | |
if self.option == 'opt1': | |
with h.optgroup(label='Option 1'): | |
for i in self.list1 : | |
h << h.option(i, value=i).selected(self.option_result()) | |
else : | |
with h.optgroup(label='Option 2'): | |
for i in self.list2 : | |
h << h.option(i, value=i).selected(self.option_result()) | |
return h.root | |
class App: | |
def __init__(self): | |
self.option = Option() | |
editor = OptionEditor(self.option) | |
self.editor_component = component.Component(editor) | |
@presentation.render_for(App) | |
def render(self, h, *args): | |
h << self.editor_component | |
return h.root | |
app = App |
nagareproject
commented
Apr 11, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment