GSMEthesis commited on
Commit
84c4e1c
·
verified ·
1 Parent(s): ffffe01

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +98 -195
app.py CHANGED
@@ -19,238 +19,135 @@ SHEET_NAME = "Condition1"
19
  # ========== استایل‌های سفارشی یکپارچه ==========
20
  st.markdown("""
21
  <style>
22
- @font-face {
23
- font-family: 'B Nazanin';
24
- src: url('https://cdn.jsdelivr.net/gh/rastikerdar/fonts@master/fonts/B%20Nazanin/B%20Nazanin.woff') format('woff');
 
 
 
 
25
  }
26
 
27
- :root {
28
- --primary: #6a0dad;
29
- --text: #333333;
30
- --background: #ffffff;
31
- --border: #dddddd;
32
- --input-bg: #ffffff;
33
- --secondary-bg: #f8f9fa;
34
- --mobile-width: 375px;
35
- --mobile-height: 667px;
36
  }
37
 
38
- /* ======== تنظیمات پایه ======== */
39
- * {
40
- font-family: 'B Nazanin', 'B Nazanin Bold', sans-serif !important;
41
- text-align: right !important;
42
- direction: rtl !important;
43
- box-sizing: border-box !important;
 
 
 
 
 
 
44
  }
45
 
46
- html, body {
47
- width: 100% !important;
48
- height: 100% !important;
49
- margin: 0 !important;
50
- padding: 0 !important;
51
- overflow: hidden !important;
52
  }
53
 
54
- /* ======== کادر موبایل برای دسکتاپ ======== */
55
- @media (min-width: 768px) {
56
- body {
57
- background: #f0f0f0 !important;
58
- display: flex !important;
59
- justify-content: center !important;
60
- align-items: center !important;
61
- padding: 20px !important;
62
- }
63
-
64
- [data-testid="stAppViewContainer"] {
65
- width: var(--mobile-width) !important;
66
- height: var(--mobile-height) !important;
67
- margin: 0 auto !important;
68
- padding: 15px !important;
69
- border: 12px solid #000 !important;
70
- border-radius: 40px !important;
71
- box-shadow: 0 0 0 6px #666,
72
- 0 0 30px rgba(0,0,0,0.5) !important;
73
- position: relative !important;
74
- overflow: hidden !important;
75
- background-color: var(--background) !important;
76
- }
77
-
78
- /* دکمه هوم مجازی */
79
- [data-testid="stAppViewContainer"]::after {
80
- content: "";
81
- position: absolute;
82
- bottom: 15px;
83
- left: 50%;
84
- transform: translateX(-50%);
85
- width: 100px;
86
- height: 4px;
87
- background: #333;
88
- border-radius: 2px;
89
- }
90
-
91
- .stApp {
92
- width: 100% !important;
93
- height: 100% !important;
94
- overflow: auto !important;
95
- }
96
  }
97
 
98
- /* ======== تنظیمات عمومی محتوا ======== */
99
- [data-testid="stAppViewContainer"] {
100
- background-color: var(--background) !important;
101
- color: var(--text) !important;
102
- padding: 10px !important;
 
103
  }
104
 
105
- /* ======== استایل‌های اصلی شما (بدون تغییر) ======== */
106
- .rahyar-title {
107
- color: var(--primary) !important;
108
- margin: 0 !important;
109
- }
110
-
111
- .rahyar-subtitle {
112
- color: var(--primary) !important;
113
- margin: 0 !important;
114
  font-size: 14px !important;
 
115
  }
116
 
117
- .explanation-title {
118
- color: var(--primary) !important;
119
- font-weight: bold !important;
120
- margin: 20px 0 10px 0 !important;
121
- font-size: 18px !important;
122
  }
123
 
124
- .explanation-item {
125
- background-color: var(--secondary-bg) !important;
126
- border-radius: 8px !important;
127
- padding: 12px 15px !important;
128
- margin: 8px 0 !important;
129
- border-right: 3px solid var(--primary) !important;
130
  }
131
 
132
- /* ======== دکمه‌ها ======== */
133
- .stButton>button,
134
- [data-testid="baseButton-primary"],
135
- .accept-btn,
136
- div[data-testid="stVerticalBlock"] > div[data-testid="stHorizontalBlock"] > div > div > button {
137
- background-color: var(--primary) !important;
138
- color: white !important;
139
- border: none !important;
140
- border-radius: 8px !important;
141
- padding: 10px 20px !important;
142
- font-weight: bold !important;
143
- transition: all 0.3s ease !important;
144
- margin: 5px 0 !important;
145
  }
146
 
147
- /* ======== عناصر فرم ======== */
148
- .stTextInput input,
149
- .stNumberInput input,
150
- .stSelectbox select {
151
- width: 100% + 20x !important;
152
- max-width: 100% + 20x !important;
153
  }
154
 
155
- /* ======== نقشه ======== */
156
- .folium-map {
157
- width: 100% + 20x !important;
158
- height: 200px !important;
159
  }
160
 
161
- /* ======== تنظیمات موبایل واقعی ======== */
162
- @media (max-width: 800px) {
163
- [data-testid="stAppViewContainer"] {
164
- max-width: 100% + 20x !important;
165
- border: none !important;
166
- border-radius: 0 !important;
167
- box-shadow: none !important;
168
  }
169
- }
170
 
171
- </style>
172
-
173
- <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
174
- """, unsafe_allow_html=True)
 
 
 
175
 
 
 
 
 
 
 
 
176
 
177
- st.components.v1.html("""
178
- <script>
179
- // تنظیم viewport دینامیک
180
- document.querySelector('meta[name="viewport"]').content = 'width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no';
181
 
182
- // تنظیمات کادر موبایل در دسکتاپ
183
- function setupMobileFrame() {
184
- const appContainer = document.querySelector('[data-testid="stAppViewContainer"]');
185
- const isDesktop = window.innerWidth >= 768;
186
-
187
- if (appContainer) {
188
- if (isDesktop) {
189
- // تنظیمات برای دسکتاپ
190
- appContainer.style.width = '375px';
191
- appContainer.style.height = '667px';
192
- appContainer.style.margin = '0 auto';
193
- appContainer.style.overflow = 'hidden';
194
-
195
- // تنظیم اسکرول برای محتوای داخلی
196
- const appContent = document.querySelector('.stApp > div');
197
- if (appContent) {
198
- appContent.style.maxHeight = 'calc(667px - 40px)';
199
- appContent.style.overflowY = 'auto';
200
- appContent.style.scrollbarWidth = 'none';
201
- }
202
-
203
- // تنظیم پس‌زمینه صفحه
204
- document.body.style.background = '#f0f0f0';
205
- document.body.style.display = 'flex';
206
- document.body.style.justifyContent = 'center';
207
- document.body.style.alignItems = 'center';
208
- document.body.style.padding = '20px';
209
- } else {
210
- // تنظیمات برای موبایل واقعی
211
- appContainer.style.width = '100%';
212
- appContainer.style.maxWidth = '100%';
213
- appContainer.style.height = 'auto';
214
- appContainer.style.margin = '0';
215
- appContainer.style.overflow = 'visible';
216
  }
217
- }
218
- }
219
 
220
- // غیرفعال کردن زوم و تنظیمات لمسی
221
- function disableZoom() {
222
- document.addEventListener('gesturestart', function(e) {
223
- e.preventDefault();
224
- });
225
- document.addEventListener('dblclick', function(e) {
226
- e.preventDefault();
227
- }, { passive: false });
228
- }
229
 
230
- // تنظیم اندازه فونت بر اساس عرض دستگاه
231
- function adjustFontSize() {
232
- const container = document.querySelector('[data-testid="stAppViewContainer"]');
233
- if (container) {
234
- const width = container.offsetWidth;
235
- const baseSize = width < 400 ? 14 : 16;
236
- document.documentElement.style.fontSize = baseSize + 'px';
237
  }
238
  }
239
 
240
- // اجرای تمام تنظیمات پس از لود صفحه
241
- window.addEventListener('load', function() {
242
- setupMobileFrame();
243
- disableZoom();
244
- adjustFontSize();
245
- });
246
 
247
- // اجرای مجدد تنظیمات هنگام تغییر سایز پنجره
248
- window.addEventListener('resize', function() {
249
- setupMobileFrame();
250
- adjustFontSize();
251
- });
252
- </script>
253
- """, height=0)
254
 
255
 
256
  # ========== توابع اصلی ==========
@@ -913,6 +810,12 @@ def main():
913
  # تشخیص دستگاه
914
  user_agent = st.query_params.get("user_agent", [""])[0]
915
  st.session_state.is_desktop = "mobile" not in user_agent.lower()
 
 
 
 
 
 
916
 
917
  if 'current_page' not in st.session_state:
918
  st.session_state.current_page = "welcome"
 
19
  # ========== استایل‌های سفارشی یکپارچه ==========
20
  st.markdown("""
21
  <style>
22
+ /* تنظیمات برای موبایل */
23
+ @media (max-width: 768px) {
24
+ /* اجبار نمایش تمام صفحه به اندازه موبایل */
25
+ html, body, .stApp {
26
+ max-width: 768px !important; /* حداکثر عرض صفحه */
27
+ margin: 0 auto; /* وسط‌چین کردن محتوا */
28
+ width: 100% !important;
29
  }
30
 
31
+ /* تنظیم ارتفاع نقشه برای موبایل */
32
+ .folium-map {
33
+ height: 300px !important; /* ارتفاع نقشه در موبایل */
 
 
 
 
 
 
34
  }
35
 
36
+ /* تغییرات برای بخش‌های مختلف برای موبایل */
37
+ .stTextInput input,
38
+ .stNumberInput input,
39
+ .stSelectbox select,
40
+ .stTextArea textarea,
41
+ .stDateInput input,
42
+ .stTimeInput input,
43
+ .stMultiSelect div[role="combobox"],
44
+ div[data-testid="stVerticalBlock"] > div[data-testid="stHorizontalBlock"] > div > div > div > div > input,
45
+ div[data-baseweb="select"] > div:first-child {
46
+ font-size: 14px !important;
47
+ padding: 12px !important;
48
  }
49
 
50
+ /* دکمه‌ها برای موبایل */
51
+ .stButton>button,
52
+ [data-testid="baseButton-primary"] {
53
+ font-size: 16px !important;
54
+ padding: 10px 20px !important;
 
55
  }
56
 
57
+ /* چینش فرم‌ها و المان‌ها در موبایل */
58
+ .stTextInput>label,
59
+ .stNumberInput>label,
60
+ .stSelectbox>label {
61
+ font-size: 14px !important;
62
+ padding: 4px 0 !important;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
63
  }
64
 
65
+ .stTextInput input,
66
+ .stNumberInput input,
67
+ .stSelectbox select {
68
+ font-size: 16px !important;
69
+ padding: 12px !important;
70
+ height: auto !important;
71
  }
72
 
73
+ .stButton>button {
 
 
 
 
 
 
 
 
74
  font-size: 14px !important;
75
+ padding: 8px 16px !important;
76
  }
77
 
78
+ /* پنهان کردن همه المان‌ها در حالت دسکتاپ */
79
+ @media (min-width: 769px) {
80
+ .stApp {
81
+ width: 100% !important;
82
+ }
83
  }
84
 
85
+ /* اطمینان از اینکه دکمه‌ها درست در حالت موبایل ظاهر شوند */
86
+ .stAlert .st-ae {
87
+ padding: 12px !important;
88
+ font-size: 13px !important;
 
 
89
  }
90
 
91
+ /* حذف فاصله اضافی از المان‌های مختلف در موبایل */
92
+ .stMarkdown h3 {
93
+ font-size: 16px !important;
 
 
 
 
 
 
 
 
 
 
94
  }
95
 
96
+ .stMarkdown p {
97
+ font-size: 13px !important;
 
 
 
 
98
  }
99
 
100
+ .stSelectbox [role="listbox"] {
101
+ font-size: 16px !important;
 
 
102
  }
103
 
104
+ /* تنظیمات مخصوص موبایل برای آیتم‌ها */
105
+ @media (max-width: 768px) {
106
+ .stAlert .st-ae {
107
+ padding: 12px !important;
108
+ font-size: 13px !important;
 
 
109
  }
 
110
 
111
+ /* فرم‌ها در موبایل */
112
+ .stTextInput>label,
113
+ .stNumberInput>label,
114
+ .stSelectbox>label {
115
+ font-size: 14px !important;
116
+ padding: 4px 0 !important;
117
+ }
118
 
119
+ .stTextInput input,
120
+ .stNumberInput input,
121
+ .stSelectbox select {
122
+ font-size: 16px !important;
123
+ padding: 12px !important;
124
+ height: auto !important;
125
+ }
126
 
127
+ .stButton>button {
128
+ font-size: 14px !important;
129
+ padding: 8px 16px !important;
130
+ }
131
 
132
+ .stMarkdown h3 {
133
+ font-size: 16px !important;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
134
  }
 
 
135
 
136
+ .stMarkdown p {
137
+ font-size: 13px !important;
138
+ }
 
 
 
 
 
 
139
 
140
+ .stSelectbox [role="listbox"] {
141
+ font-size: 16px !important;
142
+ }
 
 
 
 
143
  }
144
  }
145
 
146
+ </style>
147
+
148
+ <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
149
+ """, unsafe_allow_html=True)
 
 
150
 
 
 
 
 
 
 
 
151
 
152
 
153
  # ========== توابع اصلی ==========
 
810
  # تشخیص دستگاه
811
  user_agent = st.query_params.get("user_agent", [""])[0]
812
  st.session_state.is_desktop = "mobile" not in user_agent.lower()
813
+
814
+
815
+ # اینجا می‌توانید از is_desktop برای تعیین اینکه نمایشگر موبایل اعمال شود، استفاده کنید
816
+ if st.session_state.is_desktop:
817
+ # اطمینان از نمایش همان حالت موبایل برای همه دستگاه‌ها
818
+ st.session_state.is_desktop = False
819
 
820
  if 'current_page' not in st.session_state:
821
  st.session_state.current_page = "welcome"