예제 #1
0
class GroupFragment(rend.Fragment):

    docFactory = loaders.stan(
        T.fieldset(id=T.slot('id'),
                   class_=T.slot('cssClass'),
                   render=T.directive('group'))[
                       T.legend[T.slot('label')],
                       T.div(class_='description')[T.slot('description')],
                       T.slot('items'), ])

    def __init__(self, group):
        super(GroupFragment, self).__init__()
        self.group = group

    def render_group(self, ctx, data):

        # Get a reference to the group, for simpler code.
        group = self.group

        # Build the CSS class string
        cssClass = ['group']
        if group.cssClass is not None:
            cssClass.append(group.cssClass)
        cssClass = ' '.join(cssClass)

        # Fill the slots
        tag = ctx.tag
        tag.fillSlots('id', util.render_cssid(group.key))
        tag.fillSlots('cssClass', cssClass)
        tag.fillSlots('label', group.label)
        tag.fillSlots('description', group.description or '')
        tag.fillSlots('items',
                      [inevow.IRenderer(item) for item in group.items])
        return ctx.tag
예제 #2
0
class CollapsibleGroupFragment(rend.Fragment):
    docFactory = loaders.stan(
        T.fieldset(id=T.slot('id'), _class=T.slot('cssClass'), render=T.directive('group'))[
            T.input(_class='collapsible-group-hidden-state', type='hidden', render=T.directive('collapsedstate')),
            T.legend[T.span(_class='collapse-controls'), T.slot('label')],
            T.div(_class='description')[T.slot('description')],
            T.div(_class='collapsible-group-summary')[T.div(render=T.directive('display_summary'))[T.slot('summary')]],
            T.div(_class='collapsible-group-contents')[T.div(render=T.directive('display_contents'))[T.slot('items')]],
        ])

    def __init__(self, group):
        super(CollapsibleGroupFragment, self).__init__()
        self.group = group

    def render_collapsedstate(self, ctx, data):
        ctx.tag(name=self.group.getCollapsedKey())
        if self.group.collapsible and self.group.collapsed:
            value = '1'
        else:
            value = '0'
        ctx.tag(value=value)
        return ctx.tag
    
    def render_display_summary(self, ctx, data):
        if self.group.collapsible and self.group.collapsed:
            return ctx.tag(_class='collapsible-show')
        else:
            return ctx.tag(_class='collapsible-hide')

    def render_display_contents(self, ctx, data):
        if self.group.collapsible and self.group.collapsed:
            return ctx.tag(_class='collapsible-hide')
        else:
            return ctx.tag(_class='collapsible-show')

    def render_group(self, ctx, data):
        group = self.group

        # Build the CSS class string
        cssClass = ['group']
        if self.group.collapsible:
            cssClass.append('collapsible-group')
        if group.cssClass is not None:
            cssClass.append(group.cssClass)
        cssClass = ' '.join(cssClass)

        # Fill the slots
        ctx.tag.fillSlots('id', util.render_cssid(group.key))
        ctx.tag.fillSlots('cssClass', cssClass)
        ctx.tag.fillSlots('label', group.label)
        ctx.tag.fillSlots('description', group.description or '')
        if self.group.summary is not None:
            ctx.tag.fillSlots('summary', self.group.summary)
        else:
            ctx.tag.fillSlots('summary', _default_summary_clicktoexpand)
        ctx.tag.fillSlots('items', [inevow.IRenderer(item) for item in
                group.items])
        return ctx.tag
예제 #3
0
파일: web.py 프로젝트: ec429/ribbonator
def gen_checks(b, allmerits):
    merits = allmerits.get(b.name, [])
    groups = []
    soi_string = 'Reached SOI'
    if isinstance(b, ribbonator.Asteroid):
        soi_string = 'Visited (within 2.2km)'
        group = []
        have_mb = any(m.startswith('mb_') for m in merits)
        for mb in ribbonator.bodies:
            if isinstance(mb, (ribbonator.Star, ribbonator.Planet)):
                v = 'checked' if 'mb_' + mb.name in merits or (mb == ribbonator.earth and not have_mb) else None
                group.extend((t.input(type='radio', name='%s_mainbody'%(b.name,), value=mb.name, checked=v), mb.name))
        groups.append(t.fieldset[t.legend['MainBody'],
                                 group,
                                 ])
    lhgroup = []
    for d in 'oeprgnAX': # left-hand devices
        if b.permit(d):
            v = 'checked' if d in merits else None
            lhgroup.extend((t.input(type='checkbox', name='%s_%s'%(b.name, d), checked=v), ribbonator.devices[d]))
    groups.append(t.fieldset[t.legend['Left-Hand Devices'], lhgroup])
    rhgroup = []
    for c in sorted(ribbonator.craft_devices, key=lambda c:ribbonator.devices[c]): # right-hand devices
        if b.permit(c):
            v = 'checked' if c in merits else None
            rhgroup.extend((t.input(type='radio', name='%s_craft'%(b.name,), value=c, checked=v), ribbonator.devices[c]))
    groups.append(t.fieldset[t.legend['Right-Hand ("Craft") Devices'],
                             rhgroup,
                             t.input(type='radio', name='%s_craft'%(b.name), value=''), 'Clear',
                             ])
    other = []
    for d in '?|+^':
        if b.permit(d):
            v = 'checked' if d in merits else None
            other.extend((t.input(type='checkbox', name='%s_%s'%(b.name, d), checked=v), ribbonator.devices[d]))
    if b.permit('W'):
        v = 'checked' if 'W' in merits else None
        other.extend((t.input(type='checkbox', name='%s_W'%(b.name,), checked=v), 'Challenge Wreath: ', b.wreath))
    v = 'checked' if 'soi' in merits else None
    if isinstance(b, ribbonator.Moon):
        p = 'soi' in allmerits.get(b.parent.name, [])
    else:
        p = True;
    groups.append(t.fieldset[t.legend['Other Devices'], other])
    content = [t.legend[b.name],
               t.input(type='checkbox', name='%s_soi'%(b.name,), checked=v, onchange='changedSOI(%r)'%(b.name,), id='%s_soi'%(b.name,)), soi_string,
               t.div(id='%s_div'%(b.name,), style='display:%s;'%('block' if v else 'none',))[groups],
               ]
    return t.fieldset(id='%s_fs'%(b.name,), style='display:%s;'%('block' if p else 'none',))[content]
예제 #4
0
def gen_checks(b, allmerits):
    merits = allmerits.get(b.name, [])
    groups = []
    soi_string = 'Reached SOI'
    if isinstance(b, ribbonator.Asteroid):
        soi_string = 'Visited (within 2.2km)'
        group = []
        have_mb = any(m.startswith('mb_') for m in merits)
        for mb in ribbonator.bodies:
            if isinstance(mb, (ribbonator.Star, ribbonator.Planet)):
                v = 'checked' if 'mb_' + mb.name in merits or (
                    mb == ribbonator.earth and not have_mb) else None
                group.extend((t.input(type='radio',
                                      name='%s_mainbody' % (b.name, ),
                                      value=mb.name,
                                      checked=v), mb.name))
        groups.append(t.fieldset[t.legend['MainBody'], group, ])
    lhgroup = []
    for d in 'oeprgnAX':  # left-hand devices
        if b.permit(d):
            v = 'checked' if d in merits else None
            lhgroup.extend((t.input(type='checkbox',
                                    name='%s_%s' % (b.name, d),
                                    checked=v), ribbonator.devices[d]))
    groups.append(t.fieldset[t.legend['Left-Hand Devices'], lhgroup])
    rhgroup = []
    for c in sorted(ribbonator.craft_devices,
                    key=lambda c: ribbonator.devices[c]):  # right-hand devices
        if b.permit(c):
            v = 'checked' if c in merits else None
            rhgroup.extend((t.input(type='radio',
                                    name='%s_craft' % (b.name, ),
                                    value=c,
                                    checked=v), ribbonator.devices[c]))
    groups.append(
        t.fieldset[t.legend['Right-Hand ("Craft") Devices'], rhgroup,
                   t.input(type='radio', name='%s_craft' % (b.name), value=''),
                   'Clear', ])
    other = []
    for d in '?|+^':
        if b.permit(d):
            v = 'checked' if d in merits else None
            other.extend((t.input(type='checkbox',
                                  name='%s_%s' % (b.name, d),
                                  checked=v), ribbonator.devices[d]))
    if b.permit('W'):
        v = 'checked' if 'W' in merits else None
        other.extend((t.input(type='checkbox',
                              name='%s_W' % (b.name, ),
                              checked=v), 'Challenge Wreath: ', b.wreath))
    v = 'checked' if 'soi' in merits else None
    if isinstance(b, ribbonator.Moon):
        p = 'soi' in allmerits.get(b.parent.name, [])
    else:
        p = True
    groups.append(t.fieldset[t.legend['Other Devices'], other])
    content = [
        t.legend[b.name],
        t.input(type='checkbox',
                name='%s_soi' % (b.name, ),
                checked=v,
                onchange='changedSOI(%r)' % (b.name, ),
                id='%s_soi' % (b.name, )),
        soi_string,
        t.div(id='%s_div' % (b.name, ),
              style='display:%s;' % ('block' if v else 'none', ))[groups],
    ]
    return t.fieldset(id='%s_fs' % (b.name, ),
                      style='display:%s;' %
                      ('block' if p else 'none', ))[content]