GSMEthesis commited on
Commit
2871ba8
·
verified ·
1 Parent(s): 0175918

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +58 -41
app.py CHANGED
@@ -739,7 +739,7 @@ h3 {
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"]
@@ -758,6 +758,7 @@ def enhanced_likert_scale(question_data):
758
  direction: rtl !important;
759
  text-align: center !important;
760
  margin: 20px 0 !important;
 
761
  }}
762
  .likert-question {{
763
  font-size: 18px !important;
@@ -778,6 +779,8 @@ def enhanced_likert_scale(question_data):
778
  gap: 8px !important;
779
  flex-wrap: wrap !important;
780
  margin: 10px 0 !important;
 
 
781
  }}
782
  /* استایل دکمه‌های لیکرت (HTML) */
783
  .likert-btn {{
@@ -794,7 +797,7 @@ def enhanced_likert_scale(question_data):
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;
@@ -806,15 +809,24 @@ def enhanced_likert_scale(question_data):
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 {{
@@ -834,75 +846,80 @@ def enhanced_likert_scale(question_data):
834
  <div class="likert-buttons" id="likert-buttons-{key}">
835
  """
836
 
 
 
 
 
 
 
837
  # افزودن دکمه‌های HTML
838
  for i in range(scale):
839
  value = scale - i # 7 تا 1
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 - نسخه اصلاح شده با مناطق عمومی"""
 
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"]
 
758
  direction: rtl !important;
759
  text-align: center !important;
760
  margin: 20px 0 !important;
761
+ position: relative !important;
762
  }}
763
  .likert-question {{
764
  font-size: 18px !important;
 
779
  gap: 8px !important;
780
  flex-wrap: wrap !important;
781
  margin: 10px 0 !important;
782
+ position: relative !important;
783
+ height: 40px !important;
784
  }}
785
  /* استایل دکمه‌های لیکرت (HTML) */
786
  .likert-btn {{
 
797
  transition: all 0.3s ease !important;
798
  font-size: 18px !important;
799
  color: #6a0dad !important;
800
+ z-index: 1000 !important;
801
  }}
802
  .likert-btn.selected {{
803
  background: #6a0dad !important;
 
809
  transform: scale(1.1) !important;
810
  }}
811
  /* مخفی کردن دکمه‌های Streamlit */
812
+ .likert-streamlit-btn-container {{
813
+ position: relative !important;
814
+ width: 40px !important;
815
+ height: 40px !important;
816
+ margin: 0 auto !important;
817
+ }}
818
  .likert-streamlit-btn {{
819
  width: 40px !important;
820
  height: 40px !important;
821
  opacity: 0 !important;
822
+ position: absolute !important;
823
+ top: 0 !important;
824
+ left: 0 !important;
825
+ margin: 0 !important;
826
  padding: 0 !important;
827
  border: none !important;
828
  background: transparent !important;
829
+ z-index: 1 !important;
830
  }}
831
  /* استایل پاسخ انتخاب‌شده */
832
  .likert-response {{
 
846
  <div class="likert-buttons" id="likert-buttons-{key}">
847
  """
848
 
849
+ # محاسبه موقعیت دکمه‌های HTML
850
+ button_width = 40
851
+ gap = 8
852
+ total_width = scale * button_width + (scale - 1) * gap
853
+ start_x = -total_width / 2 # برای وسط‌چین کردن دکمه‌ها
854
+
855
  # افزودن دکمه‌های HTML
856
  for i in range(scale):
857
  value = scale - i # 7 تا 1
858
  is_selected = st.session_state[key] == value
859
+ x_position = start_x + i * (button_width + gap)
860
  html_content += f"""
861
  <button class="likert-btn {'selected' if is_selected else ''}"
862
+ style="left: calc(50% + {x_position}px);"
863
  onclick="document.getElementById('streamlit-btn-{key}-{value}').click()">
864
  {'•' if is_selected else '○'}
865
  </button>
866
  """
867
 
868
+ html_content += f"""
869
+ </div>
870
+ <div class="likert-response" id="likert-response-{key}">
871
+ پاسخ شما: {st.session_state[key] or "هیچکدام"}
872
  </div>
873
  </div>
874
  """
875
 
876
+ # رندر HTML
877
+ components.html(html_content, height=150)
 
 
 
 
 
878
 
879
+ # ایجاد دکمه‌های Streamlit
880
  btn_cols = st.columns(scale)
881
  for i in range(scale):
882
  with btn_cols[i]:
883
  value = scale - i # 7 تا 1
884
+ # کانتینر برای دکمه Streamlit
 
 
885
  st.markdown(
886
  f"""
887
+ <div class="likert-streamlit-btn-container">
888
+ <style>
889
+ #streamlit-btn-{key}-{value} {{
890
+ width: 40px !important;
891
+ height: 40px !important;
892
+ opacity: 0 !important;
893
+ position: absolute !important;
894
+ top: 0 !important;
895
+ left: 0 !important;
896
+ margin: 0 !important;
897
+ padding: 0 !important;
898
+ border: none !important;
899
+ background: transparent !important;
900
+ z-index: 1 !important;
901
+ }}
902
+ #streamlit-btn-{key}-{value}:hover,
903
+ #streamlit-btn-{key}-{value}:focus,
904
+ #streamlit-btn-{key}-{value}:active {{
905
+ border: none !important;
906
+ background: transparent !important;
907
+ }}
908
+ </style>
909
+ </div>
910
  """,
911
  unsafe_allow_html=True
912
  )
913
  if st.button(
914
+ "•" if st.session_state[key] == value else "○",
915
  key=f"streamlit-btn-{key}-{value}",
916
  help=str(value),
917
+ type="secondary"
 
918
  ):
919
  st.session_state[key] = value
920
  st.rerun()
921
 
922
+ return st.session_state.get(key)
 
 
 
 
 
 
 
 
 
923
 
924
  def create_ride_map():
925
  """ایجاد نقشه سفر با Folium - نسخه اصلاح شده با مناطق عمومی"""