GSMEthesis commited on
Commit
61ee2b7
·
verified ·
1 Parent(s): 365cc3b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -34
app.py CHANGED
@@ -739,7 +739,7 @@ h3 {
739
 
740
  # ========== توابع اصلی ==========
741
  def enhanced_likert_scale(question_data):
742
- """لیکرت اسکیل فقط با فیچرهای Streamlit و دکمه‌های دایره‌ای ریسپانسیو"""
743
  question = question_data["question"]
744
  key = question_data["key"]
745
  scale = question_data["scale"]
@@ -769,6 +769,7 @@ def enhanced_likert_scale(question_data):
769
  .likert-labels {{
770
  display: flex !important;
771
  justify-content: space-between !important;
 
772
  font-size: 14px !important;
773
  margin-bottom: 10px !important;
774
  color: #666666 !important;
@@ -778,13 +779,13 @@ def enhanced_likert_scale(question_data):
778
  display: flex !important;
779
  justify-content: center !important;
780
  gap: 4px !important;
781
- flex-wrap: wrap !important;
782
  margin: 0 !important;
783
  padding: 0 !important;
784
  align-items: center !important;
785
  }}
786
  /* استایل دکمه‌های Streamlit */
787
- div.stButton > button[key^="streamlit-btn-{key}-"] {{
788
  width: 20px !important;
789
  height: 20px !important;
790
  border-radius: 50% !important;
@@ -796,38 +797,41 @@ def enhanced_likert_scale(question_data):
796
  margin: 0 !important;
797
  box-shadow: none !important;
798
  outline: none !important;
 
799
  }}
800
- div.stButton > button[key^="streamlit-btn-{key}-"]:hover {{
801
  background: #e0e0e0 !important;
802
  }}
803
- div.stButton > button[key^="streamlit-btn-{key}-"]:focus,
804
- div.stButton > button[key^="streamlit-btn-{key}-"]:active {{
805
  background: black !important;
806
  color: white !important;
807
  }}
808
  /* استایل دکمه انتخاب‌شده */
809
- div.stButton > button[key="streamlit-btn-{key}-{st.session_state[key] if st.session_state[key] else 'none'}"] {{
810
  background: black !important;
811
  color: white !important;
812
  }}
813
- /* استایل پاسخ */
814
- .likert-response {{
815
- text-align: center !important;
816
- color: #6a0dad !important;
817
- font-weight: bold !important;
818
- margin-top: 10px !important;
819
- font-size: 16px !important;
820
- }}
821
  /* ریسپانسیو کردن */
822
  @media (max-width: 600px) {{
823
  .likert-buttons {{
824
  gap: 2px !important;
825
  }}
826
- div.stButton > button[key^="streamlit-btn-{key}-"] {{
827
  width: 18px !important;
828
  height: 18px !important;
829
  font-size: 12px !important;
830
  }}
 
 
 
 
 
 
 
 
 
 
831
  }}
832
  </style>
833
  """,
@@ -837,26 +841,25 @@ def enhanced_likert_scale(question_data):
837
  # نمایش سوال
838
  st.markdown(f'<div class="likert-container"><div class="likert-question">{question}</div>', unsafe_allow_html=True)
839
 
840
- # نمایش لیبل‌ها
841
- st.markdown(
842
- f'<div class="likert-labels"><span style="text-align:right">{labels[1]}</span><span style="text-align:left">{labels[0]}</span></div>',
843
- unsafe_allow_html=True
844
- )
845
-
846
- # نمایش دکمه‌ها در یک ردیف
847
  st.markdown('<div class="likert-buttons">', unsafe_allow_html=True)
848
- cols = st.columns(scale)
 
849
  for i in range(scale):
850
- with cols[i]:
851
- value = scale - i # 7 تا 1
852
- symbol = "•" if st.session_state[key] == value else "○"
853
- if st.button(
854
- symbol,
855
- key=f"streamlit-btn-{key}-{value}",
856
- help=str(value)
857
- ):
858
- st.session_state[key] = value
859
- st.rerun()
 
 
860
  st.markdown('</div>', unsafe_allow_html=True)
861
 
862
  # نمایش پاسخ
 
739
 
740
  # ========== توابع اصلی ==========
741
  def enhanced_likert_scale(question_data):
742
+ """لیکرت اسکیل فقط با فیچرهای Streamlit و دکمه‌های دایره‌ای تو یه ردیف"""
743
  question = question_data["question"]
744
  key = question_data["key"]
745
  scale = question_data["scale"]
 
769
  .likert-labels {{
770
  display: flex !important;
771
  justify-content: space-between !important;
772
+ align-items: center !important;
773
  font-size: 14px !important;
774
  margin-bottom: 10px !important;
775
  color: #666666 !important;
 
779
  display: flex !important;
780
  justify-content: center !important;
781
  gap: 4px !important;
782
+ flex-wrap: nowrap !important;
783
  margin: 0 !important;
784
  padding: 0 !important;
785
  align-items: center !important;
786
  }}
787
  /* استایل دکمه‌های Streamlit */
788
+ div[data-testid="stButton"] > button[key^="streamlit-btn-{key}-"] {{
789
  width: 20px !important;
790
  height: 20px !important;
791
  border-radius: 50% !important;
 
797
  margin: 0 !important;
798
  box-shadow: none !important;
799
  outline: none !important;
800
+ line-height: 1 !important;
801
  }}
802
+ div[data-testid="stButton"] > button[key^="streamlit-btn-{key}-"]:hover {{
803
  background: #e0e0e0 !important;
804
  }}
805
+ div[data-testid="stButton"] > button[key^="streamlit-btn-{key}-"]:focus,
806
+ div[data-testid="stButton"] > button[key^="streamlit-btn-{key}-"]:active {{
807
  background: black !important;
808
  color: white !important;
809
  }}
810
  /* استایل دکمه انتخاب‌شده */
811
+ div[data-testid="stButton"] > button[key="streamlit-btn-{key}-{st.session_state[key] if st.session_state[key] else 'none'}"] {{
812
  background: black !important;
813
  color: white !important;
814
  }}
 
 
 
 
 
 
 
 
815
  /* ریسپانسیو کردن */
816
  @media (max-width: 600px) {{
817
  .likert-buttons {{
818
  gap: 2px !important;
819
  }}
820
+ div[data-testid="stButton"] > button[key^="streamlit-btn-{key}-"] {{
821
  width: 18px !important;
822
  height: 18px !important;
823
  font-size: 12px !important;
824
  }}
825
+ .likert-labels {{
826
+ font-size: 12px !important;
827
+ }}
828
+ }}
829
+ /* حذف استایل‌های پیش‌فرض Streamlit */
830
+ div[data-testid="stButton"] > button {{
831
+ border: none !important;
832
+ box-shadow: none !important;
833
+ outline: none !important;
834
+ background: transparent !important;
835
  }}
836
  </style>
837
  """,
 
841
  # نمایش سوال
842
  st.markdown(f'<div class="likert-container"><div class="likert-question">{question}</div>', unsafe_allow_html=True)
843
 
844
+ # نمایش لیبل‌ها و دکمه‌ها تو یه ردیف
845
+ st.markdown('<div class="likert-labels">', unsafe_allow_html=True)
846
+ st.markdown(f'<span style="text-align:right">{labels[0]}</span>', unsafe_allow_html=True)
 
 
 
 
847
  st.markdown('<div class="likert-buttons">', unsafe_allow_html=True)
848
+
849
+ # دکمه‌ها تو یه ردیف با flex
850
  for i in range(scale):
851
+ value = scale - i # 7 تا 1
852
+ symbol = "•" if st.session_state[key] == value else "○"
853
+ if st.button(
854
+ symbol,
855
+ key=f"streamlit-btn-{key}-{value}",
856
+ help=str(value)
857
+ ):
858
+ st.session_state[key] = value
859
+ st.rerun()
860
+
861
+ st.markdown('</div>', unsafe_allow_html=True)
862
+ st.markdown(f'<span style="text-align:left">{labels[1]}</span>', unsafe_allow_html=True)
863
  st.markdown('</div>', unsafe_allow_html=True)
864
 
865
  # نمایش پاسخ