Skip to content

Commit

Permalink
cleanup, fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mariusandra committed Oct 15, 2023
1 parent 6c01b0f commit 00676da
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 36 deletions.
2 changes: 1 addition & 1 deletion backend/app/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def deploy_frame(id: int):
scp.put("../frameos/apps", "/srv/frameos/", recursive=True)

for node_id, sources in get_apps_from_scenes(frame.scenes).items():
app_id = "app_" + node_id.replace('-', '_')
app_id = "node_" + node_id.replace('-', '_')
log(id, "stdout", f"> add /srv/frameos/apps/{app_id}.zip")
zip_archive = io.BytesIO()
with ZipFile(zip_archive, "w") as new_archive:
Expand Down
24 changes: 15 additions & 9 deletions frameos/apps/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class ConfigField:
options: Optional[List[str]] = None
value: Optional[Any] = None
label: Optional[str] = None
rows: Optional[int] = None
placeholder: Optional[str] = None

@dataclass
Expand Down Expand Up @@ -79,36 +80,35 @@ def __init__(
frame_config: FrameConfig,
log_function: Callable[[Dict], Any],
rerender_function: Callable[[str], None],
dispatch_function: Callable[[str, Optional[Dict], Optional[Image]], ExecutionContext],
node: Node,
) -> None:
self.frame_config = frame_config
self.config = config
self.keyword = keyword
self.log_function = log_function
self.rerender_function = rerender_function
self._log_function = log_function
self._rerender_function = rerender_function
self._dispatch_function = dispatch_function
self.node: Node = node
self.__post_init__()

def __post_init__(self):
pass

def rerender(self, trigger = None):
self.rerender_function(self.keyword if trigger is None else trigger)
self._rerender_function(self.keyword if trigger is None else trigger)

def log(self, message: str):
if self.log_function:
self.log_function({ "event": f"{self.keyword}:log", "message": message })
self._log_function({ "event": f"{self.keyword}:log", "message": message })

def error(self, message: str):
if self.log_function:
self.log_function({ "event": f"{self.keyword}:error", "message": message })
self._log_function({ "event": f"{self.keyword}:error", "message": message })

def run(self, payload: ExecutionContext):
pass

def get_config(self, state: Dict, key: str, default = None):
text = self.config.get(key, default)
# self.log(f"get_config: {key} --> {text}")
return self.parse_str(text, state)

def parse_str(self, text: str, state: Dict):
Expand All @@ -117,9 +117,15 @@ def replace_with_state_value(match):
value = state
for key in keys:
try:
value = value[key]
if isinstance(value, list):
value = value[int(key)]
else:
value = value[key]
except (KeyError, TypeError):
return ''
return str(value)
return re.sub(r'{([^}]+)}', replace_with_state_value, text)

def dispatch(self, event: str, payload: Optional[Dict] = None, image: Optional[Image] = None) -> ExecutionContext:
self._log_function({ "event": f"{self.keyword}:{event}", "payload": payload, "image": bool(image) })
return self._dispatch_function(event, payload, image)
7 changes: 0 additions & 7 deletions frameos/apps/hack_ringraam/config.json

This file was deleted.

13 changes: 0 additions & 13 deletions frameos/apps/hack_ringraam/frame.py

This file was deleted.

2 changes: 1 addition & 1 deletion frameos/apps/unsplash/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
{
"name": "cache_seconds",
"type": "string",
"value": "60",
"value": "0",
"required": false,
"label": "Seconds to cache the result",
"placeholder": "Default: 60. Use 0 for no cache"
Expand Down
6 changes: 4 additions & 2 deletions frameos/frame/app_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,14 @@ def init_apps(self):
self.init_system_app(folder)

for node_id in app_node_ids:
app_id = "app_" + node_id.replace('-', '_')
app_id = "node_" + node_id.replace('-', '_')
if os.path.isfile(f'apps/{app_id}.zip'):
self.init_custom_app(app_id)

for scene in self.config.scenes:
for node in scene.nodes:
if node.data.get('sources') is not None:
keyword = "app_" + node.id.replace('-', '_')
keyword = "node_" + node.id.replace('-', '_')
else:
keyword = node.data.get('keyword')
if node.type == 'app' and keyword:
Expand Down Expand Up @@ -177,6 +177,7 @@ def init_scenes(self):
for frame_config_scene in self.config.scenes:
scene_handler = SceneHandler(frame_config_scene=frame_config_scene, app_handler=self, logger=self.logger)
self.scene_handlers[scene_handler.id] = scene_handler
self.dispatch_event('init')

def get_app_for_node(self, name: str, node: Node, node_config: Optional[Dict[str, Any]]) -> App:
if name not in self.app_classes or name not in self.app_configs:
Expand All @@ -197,6 +198,7 @@ def get_app_for_node(self, name: str, node: Node, node_config: Optional[Dict[str
frame_config=self.config.to_frame_config(),
log_function=self.logger.log,
rerender_function=self.image_handler.refresh_image,
dispatch_function=self.dispatch_event,
node=node,
)

Expand Down
5 changes: 3 additions & 2 deletions frontend/src/components/TextArea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import { clsx } from 'clsx'
interface TextAreaProps extends Omit<React.InputHTMLAttributes<HTMLTextAreaElement>, 'onChange'> {
onChange?: (value: string) => void
theme?: 'node' | 'full'
rows?: number
}

export function TextArea({ className, onChange, theme, ...props }: TextAreaProps) {
export function TextArea({ className, onChange, theme, rows, ...props }: TextAreaProps) {
return (
<textarea
className={clsx(
Expand All @@ -15,7 +16,7 @@ export function TextArea({ className, onChange, theme, ...props }: TextAreaProps
theme === 'node' && 'block text-white bg-zinc-800 focus:bg-zinc-700 hover:bg-zinc-700 w-full min-w-min px-0.5',
className
)}
rows={theme === 'node' ? 3 : 8}
rows={rows ?? (theme === 'node' ? 3 : 8)}
onChange={onChange ? (e) => onChange(e.target.value) : undefined}
{...props}
/>
Expand Down
1 change: 1 addition & 0 deletions frontend/src/scenes/frame/panels/Diagram/AppNode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ export function AppNode({ data, id, isConnectable }: NodeProps<AppNodeData>): JS
placeholder={field.placeholder}
value={String((field.name in data.config ? data.config[field.name] : field.value) ?? '')}
onChange={(value) => updateNodeConfig(id, field.name, value)}
rows={field.rows ?? 3}
/>
) : (
<TextInput
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/scenes/frame/panels/Diagram/EventNode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ export function EventNode(props: NodeProps): JSX.Element {
<div>payload.label</div>
<div>payload.pin</div>
</div>
) : keyword === 'render' && usedAsSource ? (
<div className="text-right">
<div>image</div>
</div>
) : null}
</div>
</div>
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/scenes/frame/panels/Events/Events.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { Box } from '../../../../components/Box'
import { H6 } from '../../../../components/H6'

const events = {
render: "Render the screen. Triggered according to the frame's refresh interval.",
init: 'Scene initialization. Triggered when the scene is loaded.',
render: "Render the scene. Triggered according to the frame's refresh interval, or when explicitly requested.",
button_press: 'When a button is pressed',
touch_press: 'When a touch screen is pressed',
mouse_click: 'When a mouse is clicked',
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ export interface ConfigField {
value?: any
/** Placeholder text for the field */
placeholder?: string
/** Number of rows for the field, only used if type is 'text' */
rows?: number
}

/** config.json schema */
Expand Down

0 comments on commit 00676da

Please sign in to comment.