GSMEthesis commited on
Commit
a2e023b
·
verified ·
1 Parent(s): 76d1a8b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +49 -26
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"]
@@ -757,7 +757,7 @@ def enhanced_likert_scale(question_data):
757
  font-family: 'B Nazanin', Arial, sans-serif !important;
758
  direction: rtl !important;
759
  text-align: center !important;
760
- margin: 20px 0 !important;
761
  position: relative !important;
762
  }}
763
  .likert-question {{
@@ -777,7 +777,6 @@ def enhanced_likert_scale(question_data):
777
  display: flex !important;
778
  justify-content: center !important;
779
  gap: 8px !important;
780
- flex-wrap: wrap !important;
781
  margin: 0 !important;
782
  position: relative !important;
783
  height: 40px !important;
@@ -878,6 +877,15 @@ def enhanced_likert_scale(question_data):
878
  پاسخ شما: {st.session_state[key] or "هیچکدام"}
879
  </div>
880
  </div>
 
 
 
 
 
 
 
 
 
881
  """
882
 
883
  # رندر HTML
@@ -891,29 +899,35 @@ def enhanced_likert_scale(question_data):
891
  # کانتینر برای دکمه Streamlit
892
  st.markdown(
893
  f"""
894
- <div class="likert-streamlit-btn-container">
895
- <style>
896
- #streamlit-btn-{key}-{value} {{
897
- width: 40px !important;
898
- height: 40px !important;
899
- opacity: 0 !important;
900
- position: absolute !important;
901
- top: 0 !important;
902
- left: 0 !important;
903
- margin: 0 !important;
904
- padding: 0 !important;
905
- border: none !important;
906
- background: white !important;
907
- z-index: 1 !important;
908
- }}
909
- #streamlit-btn-{key}-{value}:hover,
910
- #streamlit-btn-{key}-{value}:focus,
911
- #streamlit-btn-{key}-{value}:active {{
912
- border: none !important;
913
- background: white !important;
914
- }}
915
- </style>
916
- </div>
 
 
 
 
 
 
917
  """,
918
  unsafe_allow_html=True
919
  )
@@ -924,6 +938,15 @@ def enhanced_likert_scale(question_data):
924
  type="secondary"
925
  ):
926
  st.session_state[key] = value
 
 
 
 
 
 
 
 
 
927
  st.rerun()
928
 
929
  return st.session_state.get(key)
 
739
 
740
  # ========== توابع اصلی ==========
741
  def enhanced_likert_scale(question_data):
742
+ """لیکرت اسکیل با دکمه‌های Streamlit مخفی دقیقاً زیر دکمه‌های HTML"""
743
  question = question_data["question"]
744
  key = question_data["key"]
745
  scale = question_data["scale"]
 
757
  font-family: 'B Nazanin', Arial, sans-serif !important;
758
  direction: rtl !important;
759
  text-align: center !important;
760
+ margin: 0 !important;
761
  position: relative !important;
762
  }}
763
  .likert-question {{
 
777
  display: flex !important;
778
  justify-content: center !important;
779
  gap: 8px !important;
 
780
  margin: 0 !important;
781
  position: relative !important;
782
  height: 40px !important;
 
877
  پاسخ شما: {st.session_state[key] or "هیچکدام"}
878
  </div>
879
  </div>
880
+ <script>
881
+ function updateLikertSelection(key, value) {{
882
+ const buttons = document.querySelectorAll('#likert-buttons-{key} .likert-btn');
883
+ buttons.forEach(btn => btn.classList.remove('selected'));
884
+ const selectedBtn = Array.from(buttons).find(btn => btn.onclick.toString().includes('streamlit-btn-{key}-' + value));
885
+ if (selectedBtn) selectedBtn.classList.add('selected');
886
+ document.getElementById('likert-response-{key}').innerText = 'پاسخ شما: ' + (value || 'هیچکدام');
887
+ }}
888
+ </script>
889
  """
890
 
891
  # رندر HTML
 
899
  # کانتینر برای دکمه Streamlit
900
  st.markdown(
901
  f"""
902
+ <style>
903
+ .likert-streamlit-btn-container-{key}-{value} {{
904
+ position: relative !important;
905
+ width: 40px !important;
906
+ height: 40px !important;
907
+ margin: 0 !important;
908
+ padding: 0 !important;
909
+ }}
910
+ #streamlit-btn-{key}-{value} {{
911
+ width: 40px !important;
912
+ height: 40px !important;
913
+ opacity: 0 !important;
914
+ position: absolute !important;
915
+ top: 0 !important;
916
+ left: 0 !important;
917
+ margin: 0 !important;
918
+ padding: 0 !important;
919
+ border: none !important;
920
+ background: white !important;
921
+ z-index: 1 !important;
922
+ }}
923
+ #streamlit-btn-{key}-{value}:hover,
924
+ #streamlit-btn-{key}-{value}:focus,
925
+ #streamlit-btn-{key}-{value}:active {{
926
+ border: none !important;
927
+ background: white !important;
928
+ }}
929
+ </style>
930
+ <div class="likert-streamlit-btn-container-{key}-{value}"></div>
931
  """,
932
  unsafe_allow_html=True
933
  )
 
938
  type="secondary"
939
  ):
940
  st.session_state[key] = value
941
+ # آپدیت دکمه‌های HTML با JavaScript
942
+ st.markdown(
943
+ f"""
944
+ <script>
945
+ updateLikertSelection('{key}', {value});
946
+ </script>
947
+ """,
948
+ unsafe_allow_html=True
949
+ )
950
  st.rerun()
951
 
952
  return st.session_state.get(key)