GSMEthesis commited on
Commit
6ee502e
·
verified ·
1 Parent(s): 53efc93

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +51 -32
app.py CHANGED
@@ -739,54 +739,73 @@ h3 {
739
 
740
  # ========== توابع اصلی ==========
741
  def enhanced_likert_scale(question_data):
742
- """لیکرت اسکیل کاملاً با استریملیت بدون HTML"""
743
  question = question_data["question"]
744
  key = question_data["key"]
745
  scale = question_data["scale"]
746
  labels = question_data.get("labels", ["کاملاً مخالفم", "کاملاً موافقم"])
747
 
748
- # مقداردهی اولیه
749
  if key not in st.session_state:
750
  st.session_state[key] = None
751
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
752
  # نمایش سوال
753
  st.markdown(f"**{question}**")
754
-
755
  # نمایش برچسب‌ها در یک ردیف
756
- label_cols = st.columns(2)
757
- with label_cols[0]:
758
- st.markdown(f"<div style='text-align:right; font-size:14px; color:#555;'>{labels[1]}</div>", unsafe_allow_html=True)
759
- with label_cols[1]:
760
- st.markdown(f"<div style='text-align:left; font-size:14px; color:#555;'>{labels[0]}</div>", unsafe_allow_html=True)
761
-
762
- # ایجاد دکمه‌های دایره‌ای
763
- btn_cols = st.columns(scale)
764
- for i in range(scale):
765
- with btn_cols[i]:
766
- value = scale - i # 7 تا 1
767
- is_selected = st.session_state.get(key) == value
768
-
769
- # استفاده از unicode برای دایره و نقطه
770
- btn_label = "●" if is_selected else "○"
771
-
772
- if st.button(
773
- btn_label,
774
- key=f"{key}_btn_{value}",
775
- use_container_width=True,
776
- help=str(value) # نمایش مقدار به عنوان راهنما
777
- ):
778
- st.session_state[key] = value
779
- st.rerun()
780
-
 
 
 
 
 
781
  # نمایش پاسخ انتخاب شده
782
- if st.session_state.get(key) is not None:
783
  st.markdown(
784
- f"<div style='text-align:center; color:#6a0dad; font-weight:bold; margin-top:5px;'>"
785
  f"پاسخ شما: {st.session_state[key]}"
786
  f"</div>",
787
  unsafe_allow_html=True
788
  )
789
-
790
  return st.session_state.get(key)
791
  def create_ride_map():
792
  """ایجاد نقشه سفر با Folium - نسخه اصلاح شده با مناطق عمومی"""
 
739
 
740
  # ========== توابع اصلی ==========
741
  def enhanced_likert_scale(question_data):
742
+ """لیکرت اسکیل بهینه‌شده برای موبایل و دسکتاپ"""
743
  question = question_data["question"]
744
  key = question_data["key"]
745
  scale = question_data["scale"]
746
  labels = question_data.get("labels", ["کاملاً مخالفم", "کاملاً موافقم"])
747
 
 
748
  if key not in st.session_state:
749
  st.session_state[key] = None
750
+
751
+ # استایل‌دهی واکنش‌گرا
752
+ st.markdown(f"""
753
+ <style>
754
+ @media (max-width: 768px) {{
755
+ .likert-btn-container {{
756
+ flex-direction: column;
757
+ align-items: center;
758
+ }}
759
+ .likert-btn {{
760
+ margin: 3px 0;
761
+ }}
762
+ }}
763
+ </style>
764
+ """, unsafe_allow_html=True)
765
+
766
  # نمایش سوال
767
  st.markdown(f"**{question}**")
768
+
769
  # نمایش برچسب‌ها در یک ردیف
770
+ label_col = st.columns(1)[0]
771
+ with label_col:
772
+ st.markdown(
773
+ f"<div style='display: flex; justify-content: space-between; direction: rtl; margin-bottom: 8px;'>"
774
+ f"<span style='font-size: 14px; color: #555;'>{labels[1]}</span>"
775
+ f"<span style='font-size: 14px; color: #555;'>{labels[0]}</span>"
776
+ f"</div>",
777
+ unsafe_allow_html=True
778
+ )
779
+
780
+ # ایجاد دکمه‌ها
781
+ btn_container = st.container()
782
+ with btn_container:
783
+ cols = st.columns(scale)
784
+ for i in range(scale):
785
+ with cols[i]:
786
+ value = scale - i
787
+ is_selected = st.session_state.get(key) == value
788
+ btn_type = "primary" if is_selected else "secondary"
789
+
790
+ if st.button(
791
+ str(value),
792
+ key=f"{key}_btn_{value}",
793
+ type=btn_type,
794
+ use_container_width=True,
795
+ help=f"مقدار: {value}"
796
+ ):
797
+ st.session_state[key] = value
798
+ st.rerun()
799
+
800
  # نمایش پاسخ انتخاب شده
801
+ if st.session_state.get(key):
802
  st.markdown(
803
+ f"<div style='text-align: center; color: #6a0dad; font-weight: bold; margin-top: 8px;'>"
804
  f"پاسخ شما: {st.session_state[key]}"
805
  f"</div>",
806
  unsafe_allow_html=True
807
  )
808
+
809
  return st.session_state.get(key)
810
  def create_ride_map():
811
  """ایجاد نقشه سفر با Folium - نسخه اصلاح شده با مناطق عمومی"""