GSMEthesis commited on
Commit
9ab9f32
·
verified ·
1 Parent(s): 47af2a7

Update app.py

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