GSMEthesis commited on
Commit
0175918
·
verified ·
1 Parent(s): 62ee268

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +66 -44
app.py CHANGED
@@ -739,7 +739,7 @@ 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"]
@@ -779,8 +779,9 @@ def enhanced_likert_scale(question_data):
779
  flex-wrap: wrap !important;
780
  margin: 10px 0 !important;
781
  }}
782
- /* استایل دکمه‌های لیکرت */
783
  .likert-btn {{
 
784
  width: 40px !important;
785
  height: 40px !important;
786
  border-radius: 50% !important;
@@ -793,6 +794,7 @@ def enhanced_likert_scale(question_data):
793
  transition: all 0.3s ease !important;
794
  font-size: 18px !important;
795
  color: #6a0dad !important;
 
796
  }}
797
  .likert-btn.selected {{
798
  background: #6a0dad !important;
@@ -803,6 +805,17 @@ def enhanced_likert_scale(question_data):
803
  background: #f0e6ff !important;
804
  transform: scale(1.1) !important;
805
  }}
 
 
 
 
 
 
 
 
 
 
 
806
  /* استایل پاسخ انتخاب‌شده */
807
  .likert-response {{
808
  text-align: center !important;
@@ -827,61 +840,70 @@ def enhanced_likert_scale(question_data):
827
  is_selected = st.session_state[key] == value
828
  html_content += f"""
829
  <button class="likert-btn {'selected' if is_selected else ''}"
830
- onclick="selectLikert('{key}', {value})">
831
  {'•' if is_selected else '○'}
832
  </button>
833
  """
834
 
835
- html_content += f"""
836
- </div>
837
- <div class="likert-response" id="likert-response-{key}">
838
- پاسخ شما: {st.session_state[key] or "هیچکدام"}
839
  </div>
840
  </div>
841
- <script>
842
- function selectLikert(key, value) {{
843
- // به‌روزرسانی استایل دکمه‌ها
844
- const buttons = document.querySelectorAll('#likert-buttons-{key} .likert-btn');
845
- buttons.forEach(btn => btn.classList.remove('selected'));
846
- event.currentTarget.classList.add('selected');
847
- // به‌روزرسانی متن پاسخ
848
- document.getElementById('likert-response-{key}').innerText = 'پاسخ شما: ' + value;
849
- // فعال کردن دکمه مخفی Streamlit
850
- document.getElementById('hidden-btn-{key}-{value}').click();
851
- }}
852
- </script>
853
  """
854
 
855
- # رندر HTML
856
- components.html(html_content, height=200)
 
 
 
 
 
857
 
858
- # ایجاد دکمه‌های مخفی Streamlit برای مدیریت کلیک‌ها
 
859
  for i in range(scale):
860
- value = scale - i
861
- # دکمه‌های مخفی با CSS غیرقابل‌مشاهده می‌شوند
862
- st.markdown(
863
- f"""
864
- <style>
865
- #hidden-btn-{key}-{value} {{
866
- display: none !important;
867
- }}
868
- </style>
869
- """,
870
- unsafe_allow_html=True
871
- )
872
- if st.button(
873
- "hidden",
874
- key=f"hidden-btn-{key}-{value}",
875
- help=str(value),
876
- type="secondary",
877
- use_container_width=True
878
- ):
879
- st.session_state[key] = value
880
- st.rerun()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
881
 
882
  return st.session_state.get(key)
883
 
884
-
 
885
  def create_ride_map():
886
  """ایجاد نقشه سفر با Folium - نسخه اصلاح شده با مناطق عمومی"""
887
  # نقاط تقریبی برای مناطق عمومی جنوب و غرب تهران
 
739
 
740
  # ========== توابع اصلی ==========
741
  def enhanced_likert_scale(question_data):
742
+ """لیکرت اسکیل با دکمه‌های HTML روی دکمه‌های Streamlit"""
743
  question = question_data["question"]
744
  key = question_data["key"]
745
  scale = question_data["scale"]
 
779
  flex-wrap: wrap !important;
780
  margin: 10px 0 !important;
781
  }}
782
+ /* استایل دکمه‌های لیکرت (HTML) */
783
  .likert-btn {{
784
+ position: absolute !important;
785
  width: 40px !important;
786
  height: 40px !important;
787
  border-radius: 50% !important;
 
794
  transition: all 0.3s ease !important;
795
  font-size: 18px !important;
796
  color: #6a0dad !important;
797
+ z-index: 10 !important;
798
  }}
799
  .likert-btn.selected {{
800
  background: #6a0dad !important;
 
805
  background: #f0e6ff !important;
806
  transform: scale(1.1) !important;
807
  }}
808
+ /* مخفی کردن دکمه‌های Streamlit */
809
+ .likert-streamlit-btn {{
810
+ width: 40px !important;
811
+ height: 40px !important;
812
+ opacity: 0 !important;
813
+ position: relative !important;
814
+ margin: 0 auto !important;
815
+ padding: 0 !important;
816
+ border: none !important;
817
+ background: transparent !important;
818
+ }}
819
  /* استایل پاسخ انتخاب‌شده */
820
  .likert-response {{
821
  text-align: center !important;
 
840
  is_selected = st.session_state[key] == value
841
  html_content += f"""
842
  <button class="likert-btn {'selected' if is_selected else ''}"
843
+ onclick="document.getElementById('streamlit-btn-{key}-{value}').click()">
844
  {'•' if is_selected else '○'}
845
  </button>
846
  """
847
 
848
+ html_content += """
 
 
 
849
  </div>
850
  </div>
 
 
 
 
 
 
 
 
 
 
 
 
851
  """
852
 
853
+ # نمایش سوال و لیبل‌ها با Streamlit
854
+ st.markdown(f"<div class='likert-container'><div class='likert-question'>{question}</div></div>", unsafe_allow_html=True)
855
+ col1, col2 = st.columns(2)
856
+ with col1:
857
+ st.markdown(f"<div class='likert-labels' style='text-align:right'>{labels[0]}</div>", unsafe_allow_html=True)
858
+ with col2:
859
+ st.markdown(f"<div class='likert-labels' style='text-align:left'>{labels[1]}</div>", unsafe_allow_html=True)
860
 
861
+ # ایجاد دکمه‌های Streamlit با پوشش دکمه‌های HTML
862
+ btn_cols = st.columns(scale)
863
  for i in range(scale):
864
+ with btn_cols[i]:
865
+ value = scale - i # 7 تا 1
866
+ is_selected = st.session_state[key] == value
867
+
868
+ # دکمه Streamlit
869
+ st.markdown(
870
+ f"""
871
+ <style>
872
+ #streamlit-btn-{key}-{value} {{
873
+ width: 40px !important;
874
+ height: 40px !important;
875
+ opacity: 0 !important;
876
+ position: relative !important;
877
+ margin: 0 auto !important;
878
+ padding: 0 !important;
879
+ border: none !important;
880
+ background: transparent !important;
881
+ }}
882
+ </style>
883
+ """,
884
+ unsafe_allow_html=True
885
+ )
886
+ if st.button(
887
+ "•" if is_selected else "○",
888
+ key=f"streamlit-btn-{key}-{value}",
889
+ help=str(value),
890
+ type="secondary",
891
+ use_container_width=True
892
+ ):
893
+ st.session_state[key] = value
894
+ st.rerun()
895
+
896
+ # رندر دکمه‌های HTML روی دکمه‌های Streamlit
897
+ components.html(html_content, height=60)
898
+
899
+ # نمایش پاسخ انتخاب‌شده
900
+ if st.session_state[key] is not None:
901
+ st.markdown(f"<div class='likert-response'>پاسخ شما: {st.session_state[key]}</div>", unsafe_allow_html=True)
902
 
903
  return st.session_state.get(key)
904
 
905
+
906
+
907
  def create_ride_map():
908
  """ایجاد نقشه سفر با Folium - نسخه اصلاح شده با مناطق عمومی"""
909
  # نقاط تقریبی برای مناطق عمومی جنوب و غرب تهران