def render_horizontal(self, idx=None, section=None): '''Render choices horizontally''' final = Join() final.add(TeXString(' \quad ')) for idx, choice in enumerate(self.user_choices(idx=idx, section=section)): final.add(Text('(%s) ' % letter(idx))) final.add(choice.copy()) final.add(TeXString(' \qquad ')) final.pop() return final
def revalue_template(self, idx, **kwds): for i, child in enumerate(self.children): new = child.revalue('template', idx, **kwds) if new is not child: self.children[i] = new stem, choices, feedback, comment = self.clear() opts = dict(self.options or {}) final = Join() final.add(stem) final.add(TeXString('\n%\n\\par\\smallskip\n%\n')) # See if choices needs to be populated from vars if opts.get('varchoices') is not None: varchoices = opts['varchoices'] varchoices = '0' if varchoices is True else varchoices if varchoices.isdigit(): varchoices = 'choices' + varchoices # Get choices object choices = var.get_variable(self, varchoices) # Apply options in choices object if opts.get('shuffle'): del opts['shuffle'] choices.shuffle() if opts.get('sort'): del opts['sort'] choices.sort() choices = choices.texfy() # Shuffle choices, if required if opts.get('shuffle', False): data = choices.clear() seed = self.id + idx random.seed(seed) random.shuffle(data) choices.add(data) # Format choices depending on the arguments if opts.get('horizontal', False): final.add(choices.render_horizontal(idx=idx)) elif opts.get('rows', None) is not None: final.add(choices.render_table(rows=int(opts['rows']), idx=idx)) elif opts.get('cols', None) is not None: final.add(choices.render_table(cols=int(opts['cols']), idx=idx)) elif opts.get('vertical', True): choices = final.add(choices.render_vertical(idx=idx)) # Adds an extra spacing after choices final.add(TeXString('\n%\n\\endgraf\\smallskip{}\n%\n')) # Print feedback, comments, etc, depending on the section return Group('\\begingroup\n', final.clear(), '\n\\endgroup')