Spaces:
Sleeping
Sleeping
File size: 3,980 Bytes
09ed935 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
import mesop as me
from state import State
COLOR_BLUE = "blue"
COLOR_YELLOW = "#f0cd6e"
COLOR_RED = "#cc153c"
COLOR_DISABLED = "#e4e4e4"
COLOR_DISABLED_BUTTON_BG = "#ccc"
MAIN_COL_GRID = me.Style(
background="#ececec",
display="grid",
grid_template_columns="70% 30%",
height="100vh",
)
SIDEBAR = me.Style(
color="#111",
overflow_y="scroll",
padding=me.Padding.all(20),
)
SIDEBAR_SECTION = me.Style(margin=me.Margin(bottom=15))
TOOLBAR_SECTION = me.Style(
margin=me.Margin(bottom=15),
padding=me.Padding.all(5),
background=me.theme_var("surface-container-highest"),
justify_content="space-evenly",
display="flex",
flex_direction="row",
)
TEXT_INPUT = me.Style(width="100%")
def sidebar_header() -> me.Style:
state = me.state(State)
return me.Style(color="#000" if state.gemini_live_api_enabled else "#aaa")
def game_button() -> me.Style:
state = me.state(State)
if not state.api_key:
return me.Style()
if state.gemini_live_api_enabled:
return me.Style(background=me.theme_var("error"), color=me.theme_var("on-error"))
return me.Style(background=me.theme_var("primary"), color=me.theme_var("on-primary"))
def audio_button() -> me.Style:
state = me.state(State)
if state.audio_player_enabled:
return me.Style(background=me.theme_var("tertiary"), color=me.theme_var("on-tertiary"))
return me.Style()
def mic_button() -> me.Style:
state = me.state(State)
if state.audio_recorder_state == "recording":
return me.Style(background=me.theme_var("tertiary"), color=me.theme_var("on-tertiary"))
if state.gemini_live_api_enabled:
return me.Style(background=me.theme_var("error"), color=me.theme_var("on-error"))
return me.Style()
def score_box() -> me.Style:
state = me.state(State)
return me.Style(
background=COLOR_BLUE if state.gemini_live_api_enabled else COLOR_DISABLED,
color="white" if state.gemini_live_api_enabled else COLOR_DISABLED,
font_weight="bold",
font_size="2.2vw",
padding=me.Padding.all(15),
text_align="center",
)
def current_clue_box() -> me.Style:
state = me.state(State)
return me.Style(
background=COLOR_BLUE if state.gemini_live_api_enabled else COLOR_DISABLED,
color=COLOR_YELLOW if state.gemini_live_api_enabled else COLOR_DISABLED,
font_size="1em",
font_weight="bold",
padding=me.Padding.all(15),
)
def board_col_grid() -> me.Style:
state = me.state(State)
return me.Style(
background="#000" if state.gemini_live_api_enabled else "#ddd",
display="grid",
gap="5px",
grid_template_columns="repeat(6, 1fr)",
)
def category_box() -> me.Style:
state = me.state(State)
return me.Style(
background=COLOR_BLUE if state.gemini_live_api_enabled else COLOR_DISABLED,
color="white",
font_weight="bold",
font_size="1em",
padding=me.Padding.all(15),
text_align="center",
)
def clue_box(is_selectable: bool) -> me.Style:
"""Style for clue box
Args:
is_selectable: Visual signify if the clue is selectable.
"""
state = me.state(State)
return me.Style(
background=COLOR_BLUE if state.gemini_live_api_enabled else COLOR_DISABLED,
color=COLOR_YELLOW,
cursor="pointer" if is_selectable else "default",
font_size="1em",
font_weight="bold",
padding=me.Padding.all(15),
text_align="center",
)
def response_button(disabled: bool) -> me.Style:
"""Styles for response submit button.
Args:
disabled: Since we're overriding the style, we need to handle disabled state
"""
if disabled:
return me.Style(background=COLOR_DISABLED_BUTTON_BG, color="#eee")
return me.Style(background=COLOR_BLUE, color="white")
def score_text(score: int) -> me.Style:
"""In Jeopardy when the score is negative, it is red instead of white."""
state = me.state(State)
if not state.gemini_live_api_enabled:
return me.Style(color=COLOR_DISABLED)
if score < 0:
return me.Style(color=COLOR_RED)
return me.Style(color="white")
|