-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.txt
More file actions
134 lines (109 loc) · 3.83 KB
/
test.txt
File metadata and controls
134 lines (109 loc) · 3.83 KB
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
определение локации
import reflex as rx
import requests
class LocationState(rx.State):
country: str = ""
city: str = ""
error: str = ""
def get_location(self):
"""Получаем местоположение через IP."""
try:
response = requests.get('http://ip-api.com/json/')
data = response.json()
if data['status'] == 'success':
self.country = data['country']
self.city = data['city']
else:
self.error = "Не удалось определить местоположение"
except Exception as e:
self.error = f"Ошибка: {str(e)}"
def index():
return rx.vstack(
rx.button(
"Определить местоположение",
on_click=LocationState.get_location,
),
rx.text(f"Страна: {LocationState.country}"),
rx.text(f"Город: {LocationState.city}"),
rx.text(LocationState.error, color="red"),
spacing="4",
)
app = rx.App()
app.add_page(index)
# Сбор всех данных из полей в hotels.py
class CollectAllState(rx.State):
# Variables to store collected data
selected_country: str = ""
price_range_start: int = 0
price_range_end: int = 0
selected_hotel_types: list[str] = []
selected_stars: list[str] = []
selected_meal_plans: list[str] = []
@rx.event
async def collect_all_data(self):
"""Collect all data from other states when button is clicked."""
# Get data from SelectCountry
select_state = await self.get_state(SelectCountry)
self.selected_country = select_state.value
# Get data from RangeSliderState
range_state = await self.get_state(RangeSliderState)
self.price_range_start = range_state.value_start
self.price_range_end = range_state.value_end
# Get data from TypeOfHotel
hotel_state = await self.get_state(TypeOfHotel)
self.selected_hotel_types = [
hotel_type for hotel_type, is_selected
in hotel_state.choices.items()
if is_selected
]
# Get data from Stars
stars_state = await self.get_state(Stars)
self.selected_stars = [
star for star, is_selected
in stars_state.choices.items()
if is_selected
]
# Get data from MealPlan
meal_state = await self.get_state(MealPlan)
self.selected_meal_plans = [
plan for plan, is_selected
in meal_state.choices.items()
if is_selected
]
# Print collected data for verification
print("Collected Data:")
print(f"Country: {self.selected_country}")
print(f"Price Range: {self.price_range_start} - {self.price_range_end}")
print(f"Hotel Types: {self.selected_hotel_types}")
print(f"Stars: {self.selected_stars}")
print(f"Meal Plans: {self.selected_meal_plans}")
Then you can use it in your button like this:
python
rx.alert_dialog.action(
rx.button(
"Access",
variant="soft",
color_scheme="green",
radius="full",
on_click=CollectAllState.collect_all_data
),
)
import reflex as rx
class AnimationState(rx.State):
is_expanded: bool = False
def toggle(self):
self.is_expanded = not self.is_expanded
def test():
return rx.vstack(
rx.button(
"Toggle",
on_click=AnimationState.toggle,
),
rx.box(
"Content goes here",
height=rx.cond(AnimationState.is_expanded, "200px", "0px"),
opacity=rx.cond(AnimationState.is_expanded, "1", "0"),
overflow="hidden",
transition="all 0.3s ease-in-out", # CSS transition
),
)