Skip to content

Commit 1f3b43d

Browse files
committed
feat: add new components
Add Progress, ListTileProgress Add Flexible ButtonGroup
1 parent bc8cfab commit 1f3b43d

File tree

8 files changed

+136
-8
lines changed

8 files changed

+136
-8
lines changed

swibots/api/callback/AppPage.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from swibots.base import SwitchObject
33
from logging import getLogger
44
from swibots.utils.types import JSONDict
5-
from .types import ScreenType, Component, Icon
5+
from .types import ScreenType, Component, Icon, Text
66
from typing import List, Optional, Dict, Any, Union
77
from .BottomBar import BottomBar
88
from .ListView import ListView
@@ -59,6 +59,7 @@ def __init__(
5959
back_action: str = None,
6060
disable_appbar: bool = False,
6161
max_size: bool = True,
62+
on_close: str = None,
6263
**kwargs
6364
):
6465
super().__init__(app)
@@ -74,10 +75,12 @@ def __init__(
7475
self.bottom_bar = bottom_bar
7576
self.show_continue = show_continue
7677
self.max_size = max_size
78+
self.on_close = on_close
7779

7880
def to_json(self) -> JSONDict:
7981
components = []
8082
for component in self.components:
83+
8184
if isinstance(component, ListView):
8285
if self.max_size != None:
8386
component.max_size = self.max_size
@@ -91,6 +94,10 @@ def to_json(self) -> JSONDict:
9194
if self.max_size != None:
9295
componentJson["mainAxisSize"] = "max" if self.max_size else "min"
9396
components.append(componentJson)
97+
elif isinstance(component, str):
98+
components.append(
99+
Text(component)
100+
)
94101

95102
data = {
96103
"type": self.type,
@@ -105,4 +112,6 @@ def to_json(self) -> JSONDict:
105112
data["showContinue"] = self.show_continue
106113
if self.back_action:
107114
data["pageId"] = self.back_action
115+
if self.on_close:
116+
data["onClose"] = self.on_close
108117
return data

swibots/api/callback/Button.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,15 +120,17 @@ def __init__(
120120
class ButtonGroup(Component):
121121
type = "button_group"
122122

123-
def __init__(self, buttons: List[Button], max_size: bool = None):
123+
def __init__(self, buttons: List[Button], max_size: bool = None, flexible=False):
124124
self.buttons = buttons
125125
self.max_size = max_size
126+
self.flexible = flexible
126127

127128
def to_json(self):
128129
return {
129130
"type": self.type,
130131
"buttons": [button.to_json() for button in self.buttons],
131132
"mainAxisSize": "max" if self.max_size else "min",
133+
"flexible": self.flexible
132134
}
133135

134136

swibots/api/callback/ListView.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from .types import SwitchObject, Component, Image, Badge
33
from enum import Enum
44
from typing import Union, List, Literal
5-
5+
from .Progress import ListTileProgress
66

77
class ListViewType(Enum):
88
DEFAULT = "default"
@@ -26,6 +26,7 @@ def __init__(
2626
thumb: Union[Image, str] = "",
2727
badges: List[Badge] = None,
2828
max_size: bool = None,
29+
progress: ListTileProgress = None
2930
):
3031
self.title = title
3132
self.subtitle = subtitle
@@ -39,6 +40,7 @@ def __init__(
3940
self.thumb = thumb
4041
self.badges = badges
4142
self.max_size = max_size
43+
self.progress = progress
4244

4345
def to_json(self):
4446
data = {
@@ -54,6 +56,8 @@ def to_json(self):
5456
}
5557
if self.thumb:
5658
data["image"] = self.thumb.to_json()
59+
if self.progress:
60+
data["progress"] = self.progress.to_json()
5761
if self.badges:
5862
data["rightComponents"] = [badge.to_json() for badge in self.badges]
5963
return data

swibots/api/callback/Players.py

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from swibots.utils.types import JSONDict
22
from typing import Dict, Any, Optional, Union, List
3-
from .types import Component, Image, Badge
3+
from .types import Component, Image, Badge, Icon
44

55

66
class AudioPlayer(Component):
@@ -148,3 +148,53 @@ def __init__(self, url: str):
148148

149149
def to_json(self):
150150
return {"type": self.type, "url": self.url}
151+
152+
153+
class ShortVideo(Component):
154+
type = "short_video"
155+
156+
def __init__(
157+
self,
158+
url: str = None,
159+
icons: List[Icon] = None,
160+
user_image: str = None,
161+
user_name: str = None,
162+
title: str = None,
163+
description: str = None,
164+
):
165+
self.url = url
166+
self.icons = icons
167+
self.user_image = user_image
168+
self.user_name = user_name
169+
self.title = title
170+
self.description = description
171+
172+
def to_json(self):
173+
data = {
174+
"type": self.type,
175+
"videoUrl": self.url,
176+
"bottom": [icon.to_json() for icon in self.icons],
177+
"extraOptions": {
178+
"userAvatar": self.user_image,
179+
"userName": self.user_name,
180+
"description": self.description,
181+
"title": self.title,
182+
},
183+
}
184+
return data
185+
186+
187+
class FeedPanel(Component):
188+
type = "feed_panel"
189+
190+
def __init__(self, feeds, next_callback: str):
191+
self.feeds = feeds
192+
self.next_callback = next_callback
193+
194+
def to_json(self) -> Dict[str, Any]:
195+
data = {
196+
"type": self.type,
197+
"feeds": [feed.to_json() for feed in self.feeds],
198+
"offsetCallbackData": self.next_callback,
199+
}
200+
return data

swibots/api/callback/Progress.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
from swibots.utils.types import JSONDict
2+
from .types import Component
3+
from enum import Enum
4+
5+
6+
class Size(Enum):
7+
LARGE = "large"
8+
MEDIUM = "medium"
9+
SMALL = "small"
10+
11+
12+
class ProgressStyle(Enum):
13+
LINEAR = "linear"
14+
CIRCULAR = "circular"
15+
16+
17+
class Progress(Component):
18+
type = "progress_bar"
19+
20+
def __init__(
21+
self,
22+
color: str = None,
23+
size: Size = Size.MEDIUM,
24+
radius: int = 2,
25+
progress: int = False,
26+
animation: bool = False,
27+
progress_style: ProgressStyle = ProgressStyle.LINEAR,
28+
):
29+
self.color = color
30+
self.size = size
31+
self.radius = radius
32+
self.progress = progress
33+
self.animation = animation
34+
self.progress_style = progress_style
35+
36+
def to_json(self):
37+
return {
38+
"type": self.type,
39+
"color": self.color,
40+
"radius": self.radius,
41+
"interdeterminate": self.animation,
42+
"progress": self.progress,
43+
"barSize": self.size.value,
44+
"progressBarType": self.progress_style.value,
45+
}
46+
47+
48+
class ListTileProgress(Progress):
49+
def __init__(
50+
self, color: str = None, progress: str = None, animation: bool = False
51+
):
52+
super().__init__(color, progress=progress, animation=animation)

swibots/api/callback/__init__.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
from .Accordian import Accordian
22
from .AppPage import AppPage, AppBar
33
from .Dropdown import Dropdown
4-
from .ListView import ListView, ListTile, ListViewType
4+
from .ListView import ListView, ListTile, ListViewType, ListTileProgress
55
from .ListItem import ListItem
66
from .Grid import Grid, GridItem, GridType
77
from .Search import SearchBar, SearchHolder
8+
from .Progress import Progress, ProgressStyle, Size
89
from .Tab import TabBar, TabBarTile, TabBarType
910
from .types import Text, Image, Icon, ScreenType, TextSize, Expansion, Spacer, Badge
1011
from .BottomBar import BottomBarTile, BottomBarType, BottomBar
@@ -60,12 +61,16 @@
6061
"Image",
6162
"ListItem",
6263
"ListTile",
64+
"ListTileProgress",
6365
"ListView",
6466
"ListViewType",
67+
"Progress",
68+
"ProgressStyle",
6569
"ScreenType",
6670
"SearchBar",
6771
"SearchHolder",
6872
"ShareButton",
73+
"Size",
6974
"Spacer",
7075
"StickyHeader",
7176
"Table",

swibots/api/callback/callbackResponse.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,5 @@ def to_json(self) -> Dict[str, Any]:
3636
"fileName": self.file_name,
3737
"callbackQueryId": self.parent_id,
3838
"inputValue": self.input_value,
39-
"url": self.url,
39+
"url": self.new_url,
4040
}

swibots/api/callback/types.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,18 @@ class Component(SwitchObject):
3636
class Icon(Component):
3737
type = "icon"
3838

39-
def __init__(self, url: str, dark_url: str = None):
39+
def __init__(self, url: str, dark_url: str = None,
40+
text: str = "",
41+
callback_data: str = None):
4042
self.url = url
4143
self.dark_url = dark_url or url
44+
self.text = text
45+
self.callback_data = callback_data
4246

4347
def to_json(self) -> Dict[str, Any]:
44-
return {"type": self.type, "name": self.url, "darkIcon": self.dark_url}
48+
return {"type": self.type, "name": self.url, "darkIcon": self.dark_url,
49+
"alt": self.text,
50+
"callbackData": self.callback_data}
4551

4652

4753
class Text(Component):

0 commit comments

Comments
 (0)