GSMEthesis commited on
Commit
b995d5a
·
verified ·
1 Parent(s): a70307b

Update app.py

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