GSMEthesis commited on
Commit
4e86e99
·
verified ·
1 Parent(s): d87ce68

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +63 -46
app.py CHANGED
@@ -739,7 +739,7 @@ h3 {
739
 
740
  # ========== توابع اصلی ==========
741
  def enhanced_likert_scale(question_data):
742
- """لیکرت اسکیل با استایل‌های بهینه‌شده"""
743
  question = question_data["question"]
744
  key = question_data["key"]
745
  scale = question_data["scale"]
@@ -749,71 +749,77 @@ def enhanced_likert_scale(question_data):
749
  if key not in st.session_state:
750
  st.session_state[key] = None
751
 
752
- # استایل‌دهی پیشرفته
753
- st.markdown(f"""
754
  <style>
755
- /* بازنشانی کامل استایل‌های دکمه */
756
- div[data-testid="stHorizontalBlock"] {{
757
- all: unset !important;
758
- display: flex !important;
759
- justify-content: center !important;
760
- gap: 8px !important;
761
- flex-wrap: wrap !important;
762
- margin: 10px 0 !important;
763
  }}
764
- div[data-testid="column"] {{
765
- all: unset !important;
766
- flex: 1 !important;
767
- min-width: 0 !important;
768
  }}
769
- button[data-testid="baseButton-{key}"] {{
770
- all: unset !important;
771
- width: 32px !important;
772
- height: 32px !important;
773
- border-radius: 50% !important;
774
- border: 2px solid #6a0dad !important;
775
- display: flex !important;
776
- align-items: center !important;
777
- justify-content: center !important;
778
- margin: 0 !important;
779
- padding: 0 !important;
780
- cursor: pointer !important;
781
  }}
782
- button[data-testid="baseButton-{key}"][kind="secondary"] {{
783
- background: white !important;
 
 
 
 
784
  }}
785
- button[data-testid="baseButton-{key}"][kind="primary"] {{
786
- background: #6a0dad !important;
 
 
 
 
 
 
 
 
 
 
787
  }}
788
- button[data-testid="baseButton-{key}"] > div > p {{
789
- display: none !important;
790
  }}
791
- button[data-testid="baseButton-{key}"]:after {{
792
- content: "○";
793
- color: #6a0dad;
794
  font-size: 18px;
795
  }}
796
- button[data-testid="baseButton-{key}"][kind="primary"]:after {{
797
- content: "•";
798
- color: white;
 
799
  }}
800
  </style>
801
- """, unsafe_allow_html=True)
 
802
 
803
  # نمایش سوال
804
  st.markdown(f"""
805
- <div style='text-align:center; font-family:"B Nazanin";
806
- font-size:18px; font-weight:bold; margin-bottom:15px;'>
807
- {question}
808
  </div>
809
  """, unsafe_allow_html=True)
810
 
811
  # نمایش برچسب‌ها
812
  label_cols = st.columns([1, scale-2, 1])
813
  with label_cols[0]:
814
- st.markdown(f"<div style='text-align:right;'>{labels[1]}</div>", unsafe_allow_html=True)
815
  with label_cols[-1]:
816
- st.markdown(f"<div style='text-align:left;'>{labels[0]}</div>", unsafe_allow_html=True)
817
 
818
  # ایجاد دکمه‌های گرد (7 تا 1 از راست به چپ)
819
  btn_cols = st.columns(scale)
@@ -823,11 +829,22 @@ def enhanced_likert_scale(question_data):
823
  is_selected = st.session_state.get(key) == value
824
  btn_type = "primary" if is_selected else "secondary"
825
 
 
 
 
 
 
 
 
 
 
 
826
  if st.button(
827
  str(value),
828
  key=f"{key}_btn_{value}",
829
  type=btn_type,
830
- on_click=lambda v=value: st.session_state.update({key: v})
 
831
  ):
832
  st.session_state[key] = value
833
  st.rerun()
 
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
  if key not in st.session_state:
750
  st.session_state[key] = None
751
 
752
+ # استایل‌دهی با HTML و CSS
753
+ html_styles = f"""
754
  <style>
755
+ /* بازنشانی استایل‌های پیش‌فرض */
756
+ .likert-container {{
757
+ font-family: 'Arial', sans-serif;
758
+ direction: rtl;
759
+ text-align: center;
760
+ margin: 20px 0;
 
 
761
  }}
762
+ .likert-question {{
763
+ font-size: 18px;
764
+ font-weight: bold;
765
+ margin-bottom: 15px;
766
  }}
767
+ .likert-labels {{
768
+ display: flex;
769
+ justify-content: space-between;
770
+ font-size: 14px;
771
+ margin-bottom: 10px;
 
 
 
 
 
 
 
772
  }}
773
+ .likert-buttons {{
774
+ display: flex;
775
+ justify-content: center;
776
+ gap: 8px;
777
+ flex-wrap: wrap;
778
+ margin: 10px 0;
779
  }}
780
+ .likert-btn {{
781
+ width: 32px;
782
+ height: 32px;
783
+ border-radius: 50%;
784
+ border: 2px solid #6a0dad;
785
+ background: white;
786
+ display: flex;
787
+ align-items: center;
788
+ justify-content: center;
789
+ cursor: pointer;
790
+ font-size: 0;
791
+ transition: all 0.2s ease;
792
  }}
793
+ .likert-btn.selected {{
794
+ background: #6a0dad;
795
  }}
796
+ .likert-btn.selected::after {{
797
+ content: '•';
798
+ color: white;
799
  font-size: 18px;
800
  }}
801
+ .likert-btn:not(.selected)::after {{
802
+ content: '○';
803
+ color: #6a0dad;
804
+ font-size: 18px;
805
  }}
806
  </style>
807
+ """
808
+ components.html(html_styles, height=0) # رندر استایل‌ها بدون ارتفاع
809
 
810
  # نمایش سوال
811
  st.markdown(f"""
812
+ <div class="likert-container">
813
+ <div class="likert-question">{question}</div>
 
814
  </div>
815
  """, unsafe_allow_html=True)
816
 
817
  # نمایش برچسب‌ها
818
  label_cols = st.columns([1, scale-2, 1])
819
  with label_cols[0]:
820
+ st.markdown(f"<div class='likert-labels' style='text-align:right;'>{labels[1]}</div>", unsafe_allow_html=True)
821
  with label_cols[-1]:
822
+ st.markdown(f"<div class='likert-labels' style='text-align:left;'>{labels[0]}</div>", unsafe_allow_html=True)
823
 
824
  # ایجاد دکمه‌های گرد (7 تا 1 از راست به چپ)
825
  btn_cols = st.columns(scale)
 
829
  is_selected = st.session_state.get(key) == value
830
  btn_type = "primary" if is_selected else "secondary"
831
 
832
+ # استفاده از HTML برای دکمه‌ها به جای استایل مستقیم Streamlit
833
+ st.markdown(f"""
834
+ <div class="likert-buttons">
835
+ <button class="likert-btn {'selected' if is_selected else ''}"
836
+ onclick="this.form.submit()"
837
+ {'disabled' if is_selected else ''}>
838
+ </button>
839
+ </div>
840
+ """, unsafe_allow_html=True)
841
+
842
  if st.button(
843
  str(value),
844
  key=f"{key}_btn_{value}",
845
  type=btn_type,
846
+ on_click=lambda v=value: st.session_state.update({key: v}),
847
+ help=str(value) # برای دسترسی آسان‌تر
848
  ):
849
  st.session_state[key] = value
850
  st.rerun()