Skip to content

Commit

Permalink
New heritence class version
Browse files Browse the repository at this point in the history
  • Loading branch information
pbrochar committed Feb 22, 2024
1 parent 1def9f3 commit f6a5847
Show file tree
Hide file tree
Showing 9 changed files with 92 additions and 10 deletions.
20 changes: 14 additions & 6 deletions blitz/ui/components/base.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import Any, Generic, Self, TypeVar, Protocol, cast
import time
from typing import Annotated, Any, Generic, Self, TypeVar, Protocol, cast
from blitz.ui.blitz_ui import BlitzUI, get_blitz_ui
from typing import overload
from nicegui import ui
Expand Down Expand Up @@ -34,6 +35,7 @@ def __init__(self, *args: Any, props: str = "", classes: str = "", **kwargs: Any
self.current_project = self.blitz_ui.current_project
self.current_app = self.blitz_ui.current_app

print("in base component", classes)
if hasattr(self, "props"):
self.props = f"{self.props} {props}"
else:
Expand Down Expand Up @@ -64,31 +66,37 @@ def ng(self, value: V) -> None:
self._ng = value

@classmethod
def variant(cls, name: str, *, props: str = "", classes: str = "", **kwargs: Any) -> type[Self]:
def variant(cls, name: str = "", *, props: str = "", classes: str = "",docstring:str="", **kwargs: Any) -> type[Self]:
"""
Create a new type (class) based on the current component class with specified props and classes.
:param props: The properties to be predefined in the new class.
:param classes: The CSS classes to be predefined in the new class.
:return: A new type (class) that is a variant of the current class with predefined props and classes.
"""
if not name:
new_type_name = f"{cls.__name__}_{str(time.time()).replace(".","")}"
else:
new_type_name = f"{name}{cls.__name__}"

if hasattr(cls, "props"):
props = f"{getattr(cls, 'props')} {props}"
if hasattr(cls, "classes"):
classes = f"{getattr(cls, 'classes')} {classes}"

return type(
f"{name}{cls.__name__}",
new_type_name,
(cls,),
{
"props": props,
"classes": classes,
},
)

def __enter__(self) -> V:
return self.ng

def __enter__(self) -> Any | None:
if hasattr(self.ng, "__enter__"):
return self.ng.__enter__()
return None

def __exit__(self, exc_type: Any, exc_value: Any, traceback: Any) -> None:
if hasattr(self.ng, "__exit__"):
Expand Down
4 changes: 3 additions & 1 deletion blitz/ui/components/gpt_chat_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import yaml

from blitz.ui.components.buttons.icon import IconButton
from blitz.ui.components.rows import WFullItemsCenter


class ResponseJSON:
Expand Down Expand Up @@ -108,7 +109,8 @@ def _toggle_expansion(self) -> None:
@ui.refreshable
def render(self) -> None:
self.download_dialog()
with ui.row(wrap=False).classes("items-center w-full"):
with WFullItemsCenter(wrap=False):
#with ui.row(wrap=False).classes("items-center w-full"):
with ui.expansion(
self.blitz_app_title,
icon="settings_suggest",
Expand Down
5 changes: 3 additions & 2 deletions blitz/ui/components/header.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from blitz.ui.blitz_ui import BlitzUI, get_blitz_ui
from blitz.ui.components.buttons import FlatButton
from blitz.ui.components.base import BaseComponent
from blitz.ui.components.rows import ItemsCenterContentCenterRow

MAIN_PINK = "#cd87ff"
DARK_PINK = "#a72bff"
Expand Down Expand Up @@ -56,8 +57,8 @@ def render(self) -> None:
ui.icon(name="bolt", color=DARK_PINK, size="32px")
with ui.link(target=f"/projects/{self.blitz_ui.current_project}"):
ui.label("Blitz Dashboard")

with ui.row().classes("items-center justify-between content-center"):
with ItemsCenterContentCenterRow(classes="justify-between"):
#with ui.row().classes("items-center justify-between content-center"):
with ui.link(target=f"{self.blitz_ui.localhost_url}/projects").classes("disabled"):
ui.tooltip("Multiple App management is coming soon")
ui.label("Projects")
Expand Down
56 changes: 56 additions & 0 deletions blitz/ui/components/rows.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
from typing import Any, Self
from blitz.ui.components.base import BaseComponent
from nicegui import ui

class BaseRow(BaseComponent[ui.row]):
def __init__(self, wrap: bool = True,props: str = "", classes: str = "") -> None:
self.wrap = wrap
print("--->", "in init", classes)
super().__init__(props=props, classes=classes)

def __new__(cls, *args: Any, **kwargs: Any) -> Self:
instance = super().__new__(cls)
instance.__init__(*args, **kwargs)
print("--------->", instance.classes)
for parent in cls.mro():
if hasattr(parent, "classes"):
instance.classes = parent.classes
return instance

def __setattr__(self, __name: str, __value: Any) -> None:
if __name == "classes" and hasattr(self, "classes"):
print("!!!!!!!!",__value)
if __value in self.classes:
return
__value = f"{self.classes} {__value}"
return super().__setattr__(__name, __value)

def render(self) -> None:
print(self.classes)
self.ng = ui.row(wrap=self.wrap).props(self.props).classes(self.classes)



class WFullRow(BaseRow.variant(classes="w-full")): # type: ignore
"""Row with w-full class."""
...

class ContentCenterRow(BaseRow.variant(classes="content-center")): # type: ignore
"""Row with content-center class."""
...

class ItemsCenterRow(BaseRow.variant(classes="items-center")): # type: ignore
"""Row with items-center class."""
...

class WFullItemsCenter(WFullRow, ItemsCenterRow):
"""Row with w-full and items-center classes."""
...

class WFullContentCenterRow(WFullRow, ContentCenterRow):
"""Row with w-full and content-center classes."""
...

class ItemsCenterContentCenterRow(ItemsCenterRow, ContentCenterRow):
"""Row with items-center and content-center classes."""
...
2 changes: 1 addition & 1 deletion blitz/ui/pages/diagram.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,5 @@ def render(self) -> None:
raise Exception
ui.mermaid(self.blitz_ui.erd)
with ui.footer().classes("w-full justify-start "):
ui.button(icon="zoom_in", on_click=self.zoom_svg).classes("borderrounded-sm").props("flat")
ui.button(icon="zoom_in", on_click=self.zoom_svg).classes("border rounded-sm").props("flat")
ui.button(icon="zoom_out", on_click=self.unzoom_svg).classes("border rounded-sm").props("flat")
1 change: 1 addition & 0 deletions random-blitz-app/.blitz
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
random-blitz-app/blitz.yaml
5 changes: 5 additions & 0 deletions random-blitz-app/blitz.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
config:
description: ''
name: Random Blitz App
version: 0.1.0

1 change: 1 addition & 0 deletions test/.blitz
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test/blitz.json
8 changes: 8 additions & 0 deletions test/blitz.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"config": {
"name": "test",
"description": "",
"version": "0.1.0"
},
"resources": {}
}

0 comments on commit f6a5847

Please sign in to comment.