GSMEthesis commited on
Commit
f3bd725
·
verified ·
1 Parent(s): 4810f64

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +100 -58
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"]
@@ -749,75 +749,117 @@ def enhanced_likert_scale(question_data):
749
  if key not in st.session_state:
750
  st.session_state[key] = None
751
 
752
- # استایل‌دهی با HTML - غیرفعال کردن استایل‌های پیش‌فرض دکمه‌ها
753
- st.markdown(f"""
754
  <style>
755
- /* غیرفعال کردن کامل تمام استایل‌های قبلی فقط برای دکمه‌های لیکرت */
756
- div[data-testid="column"] .stButton > button {{
757
- all: unset !important;
758
- min-height: 0 !important;
759
- padding: 0 !important;
760
- margin: 0 !important;
761
- border-radius: 0 !important;
762
- box-shadow: none !important;
763
- background: none !important;
764
- border: none !important;
765
- color: inherit !important;
766
- font: inherit !important;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
767
  cursor: pointer !important;
 
 
 
768
  }}
769
-
770
- /* حذف افکت‌های hover و active پیشفرض */
771
- div[data-testid="column"] .stButton > button:hover,
772
- div[data-testid="column"] .stButton > button:active,
773
- div[data-testid="column"] .stButton > button:focus {{
774
- background: none !important;
775
- border: none !important;
776
- box-shadow: none !important;
777
- transform: none !important;
778
  }}
779
-
780
- /* مخفی کردن label دکمه‌ها */
781
- div[data-testid="column"] .stButton > button > div > p {{
782
- display: none !important;
 
 
 
 
 
 
 
783
  }}
784
  </style>
785
- """, unsafe_allow_html=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
786
 
787
- # نمایش سوال
788
- st.markdown(f"**{question}**")
 
 
789
 
790
- # نمایش برچسب‌ها
791
- col1, col2 = st.columns(2)
792
- with col1:
793
- st.markdown(f"<div style='text-align:right'>{labels[0]}</div>", unsafe_allow_html=True)
794
- with col2:
795
- st.markdown(f"<div style='text-align:left'>{labels[1]}</div>", unsafe_allow_html=True)
796
 
797
- # ایجاد دکمه‌ها با استفاده از st.columns
798
- btn_cols = st.columns(scale)
799
  for i in range(scale):
800
- with btn_cols[i]:
801
- value = scale - i # 7 تا 1
802
- is_selected = st.session_state.get(key) == value
803
-
804
- # نمایش دکمه‌های ساده بدون استایل
805
- if st.button(
806
- "•" if is_selected else "○",
807
- key=f"{key}_btn_{value}",
808
- on_click=lambda v=value: st.session_state.update({key: v})
809
- ):
810
- st.session_state[key] = value
811
- st.rerun()
812
 
813
- # نمایش پاسخ انتخاب شده
814
  if st.session_state.get(key) is not None:
815
- st.markdown(
816
- f"<div style='text-align:center; color:#6a0dad; font-weight:bold; margin-top:10px;'>"
817
- f"پاسخ شما: {st.session_state[key]}"
818
- f"</div>",
819
- unsafe_allow_html=True
820
- )
821
 
822
  return st.session_state.get(key)
823
 
 
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"]
 
749
  if key not in st.session_state:
750
  st.session_state[key] = None
751
 
752
+ # استایل‌دهی و ساختار HTML
753
+ html_content = f"""
754
  <style>
755
+ /* استایل‌های کانتینر لیکرت */
756
+ .likert-container {{
757
+ font-family: 'B Nazanin', Arial, sans-serif !important;
758
+ direction: rtl !important;
759
+ text-align: center !important;
760
+ margin: 20px 0 !important;
761
+ }}
762
+ .likert-question {{
763
+ font-size: 18px !important;
764
+ font-weight: bold !important;
765
+ margin-bottom: 15px !important;
766
+ color: #333333 !important;
767
+ }}
768
+ .likert-labels {{
769
+ display: flex !important;
770
+ justify-content: space-between !important;
771
+ font-size: 14px !important;
772
+ margin-bottom: 10px !important;
773
+ color: #666666 !important;
774
+ }}
775
+ .likert-buttons {{
776
+ display: flex !important;
777
+ justify-content: center !important;
778
+ gap: 8px !important;
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;
787
+ border: 2px solid #6a0dad !important;
788
+ background: white !important;
789
+ display: flex !important;
790
+ align-items: center !important;
791
+ justify-content: center !important;
792
  cursor: pointer !important;
793
+ transition: all 0.3s ease !important;
794
+ font-size:金属
795
+ color: #6a0dad !important;
796
  }}
797
+ .likert-btn.selected {{
798
+ background: #6a0dad !important;
799
+ color: white !important;
800
+ box-shadow: 0 0 10px rgba(106, 13, 173, 0.5) !important;
 
 
 
 
 
801
  }}
802
+ .likert-btn:hover {{
803
+ background: #f0e6ff !important;
804
+ transform: scale(1.1) !important;
805
+ }}
806
+ /* استایل پاسخ انتخاب‌شده */
807
+ .likert-response {{
808
+ text-align: center !important;
809
+ color: #6a0dad !important;
810
+ font-weight: bold !important;
811
+ margin-top: 10px !important;
812
+ font-size: 16px !important;
813
  }}
814
  </style>
815
+ <div class="likert-container">
816
+ <div class="likert-question">{question}</div>
817
+ <div class="likert-labels">
818
+ <span style="text-align:right">{labels[0]}</span>
819
+ <span style="text-align:left">{labels[1]}</span>
820
+ </div>
821
+ <div class="likert-buttons">
822
+ """
823
+
824
+ # افزودن دکمه‌های HTML
825
+ for i in range(scale):
826
+ value = scale - i # 7 تا 1
827
+ is_selected = st.session_state.get(key) == value
828
+ html_content += f"""
829
+ <button class="likert-btn {'selected' if is_selected else ''}"
830
+ onclick="document.getElementById('hidden-btn-{key}-{value}').click()">
831
+ {'•' if is_selected else '○'}
832
+ </button>
833
+ """
834
 
835
+ html_content += """
836
+ </div>
837
+ </div>
838
+ """
839
 
840
+ # رندر HTML
841
+ components.html(html_content, height=200)
 
 
 
 
842
 
843
+ # ایجاد دکمه‌های مخفی Streamlit برای مدیریت کلیک‌ها
 
844
  for i in range(scale):
845
+ value = scale - i
846
+ if st.button(
847
+ "hidden",
848
+ key=f"hidden-btn-{key}-{value}",
849
+ help=str(value),
850
+ type="secondary",
851
+ use_container_width=True
852
+ ):
853
+ st.session_state[key] = value
854
+ st.rerun()
 
 
855
 
856
+ # نمایش پاسخ انتخابشده
857
  if st.session_state.get(key) is not None:
858
+ st.markdown(f"""
859
+ <div class="likert-response">
860
+ پاسخ شما: {st.session_state[key]}
861
+ </div>
862
+ """, unsafe_allow_html=True)
 
863
 
864
  return st.session_state.get(key)
865