def allowed_string_options(fixture): """The value of an HTMLAttributeValueOption is constrained to one of its stated valid options if it is set.""" with expected(NoException): HTMLAttributeValueOption('validoption', True, constrain_value_to=['anoption', 'anotheroption', 'validoption']) with expected(NoException): HTMLAttributeValueOption('invalidoption', False, constrain_value_to=['anoption', 'anotheroption', 'validoption']) with expected(ProgrammerError): HTMLAttributeValueOption('invalidoption', True, constrain_value_to=['anoption', 'anotheroption', 'validoption'])
def __init__(self, style=None, outline=False, size=None, active=False, wide=False): super().__init__() self.style = ButtonStyle(style, outline=outline) self.size = ButtonSize(size) self.active = HTMLAttributeValueOption('active', active) self.wide = HTMLAttributeValueOption('btn-block', wide)
def __init__(self, style='secondary', outline=False, size=None, active=False, wide=False, text_wrap=True): super().__init__() self.style = ButtonStyle(style, outline=outline) self.size = ButtonSize(size) self.active = HTMLAttributeValueOption('active', active) self.text_nowrap = HTMLAttributeValueOption('text-nowrap', not text_wrap) self.wide = HTMLAttributeValueOption('btn-block', wide)
def __init__(self, bg=None, fg=None, text_size=None, text_font=None, text_align=None, line_wrap=None, outline=None): super(CustomTheme, self).__init__() if bg is not None: self['bg'] = bg if fg is not None: self['fg'] = fg if text_size is not None: self['size'] = str(text_size) if text_font is not None: self['font'] = text_font if text_align is not None: text_align_option = HTMLAttributeValueOption( text_align, text_align is not None, constrain_value_to=['left', 'right']) self['align'] = text_align_option.as_html_snippet() if outline is not None: self['outline'] = outline if line_wrap is not None: self['lineWrap'] = str(line_wrap)
def test_composed_class_string(): """A HTMLAttributeValueOption be made into as a css class string.""" style_class = HTMLAttributeValueOption('validoption', True, prefix='pre', constrain_value_to=['validoption']) assert style_class.as_html_snippet() == 'pre-validoption'
def add_choice(self, html_input): input_type_custom_control = HTMLAttributeValueOption( html_input.choice_type, True, prefix='custom', constrain_value_to=['radio', 'checkbox']) label_widget = Label(self.view, for_input=html_input) label_widget.append_class('custom-control-label') html_input.append_class('custom-control-input') outer_div = Div(self.view) outer_div.append_class('custom-control') outer_div.append_class(input_type_custom_control.as_html_snippet()) if self.inline: outer_div.append_class('custom-control-inline') if html_input.disabled: outer_div.append_class('disabled') outer_div.add_child(html_input) outer_div.add_child(label_widget) self.widget.add_child(outer_div) return outer_div
def __init__(self, view, css_id, show_indicators=True, interval=5000, pause='hover', wrap=True, keyboard=True, min_height=None): super(Carousel, self).__init__(view) self.carousel_panel = self.add_child(Div(view, css_id=css_id)) self.carousel_panel.append_class('carousel') self.carousel_panel.append_class('slide') self.carousel_panel.set_attribute('data-ride', 'carousel') self.carousel_panel.set_attribute('data-interval', six.text_type(interval)) pause_option = HTMLAttributeValueOption(pause or 'false', True, constrain_value_to=['hover', 'false']) self.carousel_panel.set_attribute('data-pause', pause_option.as_html_snippet()) self.carousel_panel.set_attribute('data-wrap', 'true' if wrap else 'false') self.carousel_panel.set_attribute('data-keyboard', 'true' if keyboard else 'false') if min_height: style = self.carousel_panel.add_child(HTMLElement(self.view, 'style', children_allowed=True)) css_id = self.carousel_panel.css_id style.add_child(TextNode(self.view, '#%s .carousel-item { min-height: %sem; }' % (css_id, min_height))) self.show_indicators = show_indicators if self.show_indicators: self.indicator_list = self.carousel_panel.add_child(self.create_indicator_list()) self.inner = self.carousel_panel.add_child(self.create_inner()) self.slides = [] self.add_control(previous=True) self.add_control()
def customise_widget(self): container_class = 'container' if self.fluid is True: container_class = 'container-fluid' elif self.fluid: container_class = HTMLAttributeValueOption(self.fluid, True, prefix='container', constrain_value_to=DeviceClass.device_classes).as_html_snippet() self.widget.append_class(container_class)
def __init__(self, theme_name): super(PredefinedTheme, self).__init__() theme_name_option = HTMLAttributeValueOption(theme_name, theme_name is not None, constrain_value_to=[ 'sky', 'vine', 'lava', 'gray', 'industrial', 'social' ]) self['theme'] = theme_name_option.as_html_snippet()
def __init__(self, view, message, severity): super(Alert, self).__init__(view) severity_option = HTMLAttributeValueOption( severity, severity, prefix='alert', constrain_value_to=['success', 'info', 'warning', 'danger']) self.add_child(TextNode(view, message)) self.append_class('alert') self.append_class(severity_option.as_html_snippet()) self.set_attribute('role', 'alert')
def __init__(self, inverse=False, border=False, compact=False, striped=False, highlight_hovered=False, transposed=False, responsive=False, heading_theme=None): super(TableLayout, self).__init__() self.table_properties = [HTMLAttributeValueOption('inverse', inverse, prefix='table'), HTMLAttributeValueOption('striped', striped, prefix='table'), HTMLAttributeValueOption('bordered', border, prefix='table'), HTMLAttributeValueOption('hover', highlight_hovered, prefix='table'), HTMLAttributeValueOption('sm', compact, prefix='table'), HTMLAttributeValueOption('reflow', transposed, prefix='table'), HTMLAttributeValueOption('responsive', responsive, prefix='table')] self.heading_theme = HeadingTheme(heading_theme)
def __init__(self, view, message, level, pill=False): super().__init__(view) severity_option = HTMLAttributeValueOption(level, level, prefix='badge', constrain_value_to=[ 'primary', 'secondary', 'success', 'info', 'warning', 'danger', 'light', 'dark' ]) self.add_child(TextNode(view, message)) self.append_class('badge') if pill: self.append_class('badge-pill') self.append_class(severity_option.as_html_snippet())
def __init__(self, view, message_or_widget, severity): super().__init__(view) severity_option = HTMLAttributeValueOption(severity, severity, prefix='alert', constrain_value_to=[ 'primary', 'secondary', 'success', 'info', 'warning', 'danger', 'light', 'dark' ]) child_widget = message_or_widget if isinstance(message_or_widget, str): child_widget = TextNode(view, message_or_widget) self.add_child(child_widget) self.append_class('alert') self.append_class(severity_option.as_html_snippet()) self.set_attribute('role', 'alert')
def __init__(self, fixed_to=None, full=False, center_contents=False, colour_theme=None, bg_scheme=None): super(NavbarLayout, self).__init__() if fixed_to and full: raise ProgrammerError( 'Both fixed_to and full are given. Give fixed_to or full, but not both' ) self.fixed = NavbarFixed(fixed_to) self.full = HTMLAttributeValueOption('navbar-full', full) self.center_contents = center_contents self.colour_theme = ColourTheme(colour_theme) self.bg_scheme = BackgroundScheme(bg_scheme) self.brand = None self.contents_container = None
def __init__(self, dark=False, border='rows', compact=False, striped=False, highlight_hovered=False, responsive=False, heading_theme=None): super().__init__() if isinstance(responsive, str): self.responsive_attribute_option = HTMLAttributeValueOption( responsive, True, prefix='table-responsive', constrain_value_to=DeviceClass.device_classes) else: self.responsive_attribute_option = HTMLAttributeValueOption( 'table-responsive', responsive) border_option = HTMLAttributeValueOption( border, border and border != 'rows', prefix='table', map_values_using={ 'cells': 'bordered', 'rows': '' }, constrain_value_to=['borderless', 'cells', 'rows']) self.table_properties = [ HTMLAttributeValueOption('dark', dark, prefix='table'), HTMLAttributeValueOption('striped', striped, prefix='table'), border_option, HTMLAttributeValueOption('hover', highlight_hovered, prefix='table'), HTMLAttributeValueOption('sm', compact, prefix='table') ] self.heading_theme = HeadingTheme(heading_theme)