def __init__(self, **properties): # Set Form properties and Data Bindings. self._dom_node = _get_dom_node(self) self._spacer = _Spacer() self._el = _get_dom_node(self._spacer) self._quill = None self._rt = None self._min_height = None def click_guard(e): q = self._quill if not q.hasFocus(): q.focus() q.setSelection(len(q.getText())) self._el.addEventListener("click", click_guard) self._props = props = _defaults | properties props_to_init = { key: props[key] for key in ( "height", "content", "auto_expand", "spacing_above", "spacing_below", ) } init_if_false = { key: props[key] for key in ("enabled", "visible") if not props[key] } self._init_quill() self.init_components(**props_to_init, **init_if_false)
def __init__(self, **properties): self._active_nodes = [] self._active = None self._active_index = -1 self._link_height = 0 self._nodes = {} self.init_components(**properties) self._lp = _LinearPanel( role="autocomplete", spacing_above="none", spacing_below="none", visible=False, ) self._lp_node = _get_dom_node(self._lp) dom_node = self._dom_node = _get_dom_node(self) # use capture for keydown so we can get the event before anvil does dom_node.addEventListener("keydown", self._on_keydown, True) dom_node.addEventListener("input", self._on_input) dom_node.addEventListener("focus", self._on_focus, True) dom_node.addEventListener("blur", self._on_blur) self.set_event_handler("x-popover-init", self._mk_popover) # ensure the same method is passed to $(window).off('resize') self._reset_position = self._reset_position
def _on_keydown(self, e): key = e.key if key in ("ArrowDown", "ArrowUp"): e.preventDefault() elif key == "Enter": self._set_text() return else: return try: if key == "ArrowDown": i = min(self._active_index + 1, len(self._active_nodes) - 1) new_active = self._active_nodes[i] else: i = max(self._active_index - 1, -1) new_active = None if i == -1 else self._active_nodes[i] except IndexError: return self._active_index = i if self._active is not None: self._active.role = None if new_active is not None: new_active.role = "active" self._link_height = (self._link_height or _get_dom_node(new_active).clientHeight) self._lp_node.scrollTop = max(0, self._link_height * (i - 4)) self._active = new_active
def __init__(self, **properties): self._chips = [] self._deleting = False self._placeholder = self._placeholder_0 = self._placeholder_1 = "" input_node = _get_dom_node(self.chip_input) input_node.addEventListener("keydown", self._chip_input_key_down) dom_node = self._dom_node = _get_dom_node(self) dom_node.classList.add("anvil-extras-chips-input") dom_node.querySelector(".chips-input-placeholder").remove() dom_node.querySelector("script").remove() self.temp_chip.remove_from_parent() properties = _defaults | properties self.init_components(**properties)
def __init__(self, **properties): # allow Tabulator to be set in code with default values self._from_cache = False self._table_init = False el = self._el = _get_dom_node(self) properties = { "auto_columns": None, "header_align": "middle", "header_visible": True, "height": "", "index": "id", "layout": "fitColumns", "movable_columns": False, "pagination": True, "pagination_button_count": 5, "pagination_size": 10, "pagination_size_selector": "6 10 20", "resizable_columns": True, "row_selectable": "checkbox", "spacing_above": "small", "spacing_below": "small", "border": "", "visible": True, } | properties self.init_components(**properties) row_selectable = self._row_selectable self._table = _Tabulator( el, { "autoColumns": self._auto_columns, "headerAlign": self._header_align, "headerVisible": self._header_visible, "height": self._height, "index": self._index, "layout": self._layout, "moveableColumns": self._resizable_columns, "pagination": self._pagination, "paginationButtonCount": self._pagination_button_count, "paginationSize": self._pagination_size, "paginationSizeSelector": self._pagination_size_selector, "resizableColumns": self._resizable_columns, "selectable": "highlight" if row_selectable == "checkbox" else row_selectable, "rowSelected": self.row_selected, "rowClick": self.row_click, "cellEdited": self.cell_edited, "rowSelectionChanged": self.row_selection_change, "cellClick": self.cell_click, "pageLoaded": self.page_loaded, "rowFormatter": self.row_formatter, }, ) self.columns = properties.get("columns", []) self._table_init = True self.visible = self.visible
def set_html(self, html, sanitize=None): """set the content to html. This method sanitizes the html in the same way the RichText compeonent does""" if sanitize is None: sanitize = self._props["sanitize"] if sanitize: self._rt = self._rt or _RT(visible=False, format="restricted_html") self._rt.content = html html = _get_dom_node(self._rt).innerHTML self._quill.root.innerHTML = html
def __init__(self, **properties): dom_node = self._dom_node = _get_dom_node(self) dom_node.querySelector("script").remove() dom_node.querySelector(".chip-placeholder").remove() dom_node.addEventListener("click", lambda e: self.raise_event("click")) dom_node.classList.add("anvil-extras-chip") dom_node.tabIndex = 0 self.close_link.set_event_handler( "click", lambda **e: self.raise_event("close_click")) properties = _defaults | properties self.init_components(**properties)
def _get_node(self, text): link = self._nodes.get(text) if link: link.text = link.text return link link = _Link(text=text, spacing_above="none", spacing_below="none") link.set_event_handler("click", self._set_text) l_node = _get_dom_node(link) link.tag = l_node.querySelector("div") # this stops the lost_focus event firing when a suggestion is clicked l_node.addEventListener("mousedown", lambda e: e.preventDefault()) self._nodes[text] = link return link
def __init__(self, **properties): # allow Tabulator to be set in code with default values self._from_cache = False self._table_init = False el = self._el = _get_dom_node(self) properties = _default_props | properties self.init_components(**properties) selectable = ( "highlight" if self._row_selectable == "checkbox" else self._row_selectable ) self._table = _Tabulator( el, { "autoColumns": self._auto_columns, "headerAlign": self._header_align, "headerVisible": self._header_visible, "height": self._height, "index": self._index, "layout": self._layout, "moveableColumns": self._resizable_columns, "pagination": self._pagination, "paginationButtonCount": self._pagination_button_count, "paginationSize": self._pagination_size, "paginationSizeSelector": self._pagination_size_selector, "resizableColumns": self._resizable_columns, "selectable": selectable, "rowSelected": self.row_selected, "rowClick": self.row_click, "cellEdited": self.cell_edited, "rowSelectionChanged": self.row_selection_change, "cellClick": self.cell_click, "pageLoaded": self.page_loaded, "rowFormatter": self.row_formatter, }, ) self.columns = properties.get("columns", []) self._table_init = True
def __init__(self, checked_color=primary, text_pre="", text_post="", **properties): dom_node = self._dom_node = _get_dom_node(self) dom_node.querySelector(".checkbox").classList.add("switch") span = dom_node.querySelector("span") span.classList.add("lever") span.removeAttribute("style") input = dom_node.querySelector("input") input.removeAttribute("style") input.style.marginTop = 0 label = dom_node.querySelector("label") label.style.padding = "7px 0" self._textnode_pre = _document.createTextNode(text_pre) self._textnode_post = _document.createTextNode(text_post) label.prepend(self._textnode_pre) label.append(self._textnode_post) self.checked_color = checked_color or primary
def _get_dom_node_id(component): node = _get_dom_node(component) if not node.id: node.id = "".join([random.choice(_characters) for _ in range(8)]) return node.id