This commit is contained in:
Ali Abid 2022-03-24 21:15:05 -07:00
parent 9ca5cf04c3
commit 49bd10b69b
3 changed files with 24 additions and 2 deletions

View File

@ -13,6 +13,12 @@ if TYPE_CHECKING: # Only import for type checking (is False at runtime).
class Block:
def __init__(self):
self.render()
def render(self):
"""
Adds self into appropriate BlockContext
"""
self._id = Context.id
Context.id += 1
if Context.block is not None:
@ -55,7 +61,10 @@ class Block:
class BlockContext(Block):
def __init__(self, css: Optional[str] = None):
def __init__(self, css: Optional[Dict[str, str]] = None):
"""
css: Css rules to apply to block.
"""
self.children = []
self.css = css if css is not None else {}
super().__init__()
@ -76,6 +85,9 @@ class BlockContext(Block):
class Row(BlockContext):
def __init__(self, css: Optional[str] = None):
"""
css: Css rules to apply to block.
"""
super().__init__(css)
def get_template_context(self):
@ -84,6 +96,9 @@ class Row(BlockContext):
class Column(BlockContext):
def __init__(self, css: Optional[str] = None):
"""
css: Css rules to apply to block.
"""
super().__init__(css)
def get_template_context(self):
@ -95,6 +110,9 @@ class Column(BlockContext):
class Tabs(BlockContext):
def __init__(self, css: Optional[str] = None):
"""
css: Css rules to apply to block.
"""
super().__init__(css)
def change(self, fn: Callable, inputs: List[Component], outputs: List[Component]):
@ -110,6 +128,9 @@ class Tabs(BlockContext):
class TabItem(BlockContext):
def __init__(self, label, css: Optional[str] = None):
"""
css: Css rules to apply to block.
"""
super().__init__(css)
self.label = label
super(TabItem, self).__init__()

View File

@ -27,6 +27,7 @@ class FlaggingCallback(ABC):
This method should be overridden and ensure that everything is set up correctly for flag().
This method gets called once at the beginning of the Interface.launch() method.
Parameters:
components: Set of components that will provide flagged data.
flagging_dir: A string, typically containing the path to the directory where the flagging file should be storied (provided as an argument to Interface.__init__()).
"""
pass

View File

@ -490,7 +490,7 @@ class Interface(Blocks):
}
):
for component in self.input_components:
Block.__init__(component)
component.render()
with Row():
submit_btn = Button("Submit")
clear_btn = Button("Clear")