Maryam Ilka commited on
Commit
a3882c8
·
verified ·
1 Parent(s): 85f0ec7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -17
app.py CHANGED
@@ -601,41 +601,41 @@ def attention_check1():
601
  key="att1_radio"
602
  )
603
 
604
- # 1. دکمه HTML واقعی با JavaScript
605
- html_code = """
606
  <script>
607
- function handleContinue() {
608
- // ارسال داده به Streamlit
609
- parent.document.dispatchEvent(new CustomEvent('continueGreenClicked'));
 
 
 
610
  }
611
  </script>
612
 
613
- <button onclick="handleContinue()"
614
  style="background-color:#28a745; color:white; border:none;
615
  border-radius:8px; padding:10px 20px; font-weight:bold;
616
  width:100%; cursor:pointer; margin-top:10px;">
617
  ادامه
618
  </button>
619
  """
620
- html(html_code, height=50)
621
 
622
- # 2. دریافت رویداد در Streamlit
623
- if st.session_state.get("continue_green_clicked"):
624
  if answer:
625
  st.session_state.attention_check1 = answer
626
  st.session_state.current_page = "random_likert_questions"
 
627
  st.rerun()
628
  else:
629
  st.warning("لطفاً یک گزینه را انتخاب کنید")
 
630
 
631
- # کد JavaScript برای دریافت رویداد (در بخش اصلی برنامه)
632
- st.components.v1.html("""
633
- <script>
634
- document.addEventListener('continueGreenClicked', function() {
635
- Streamlit.setComponentValue("continue_green_clicked");
636
- });
637
- </script>
638
- """)
639
 
640
 
641
  def attention_check2():
 
601
  key="att1_radio"
602
  )
603
 
604
+ # 1. تزریق JavaScript برای ارتباط دوطرفه
605
+ js_code = """
606
  <script>
607
+ function handleClick() {
608
+ // روش 1: ارسال به sessionState
609
+ Streamlit.setComponentValue("btn_clicked");
610
+
611
+ // روش 2: یا از طریق postMessage
612
+ // window.parent.postMessage("continue_green_clicked", "*");
613
  }
614
  </script>
615
 
616
+ <button onclick="handleClick()"
617
  style="background-color:#28a745; color:white; border:none;
618
  border-radius:8px; padding:10px 20px; font-weight:bold;
619
  width:100%; cursor:pointer; margin-top:10px;">
620
  ادامه
621
  </button>
622
  """
623
+ html(js_code, height=60)
624
 
625
+ # 2. بررسی کلیک
626
+ if st.session_state.get("btn_clicked"):
627
  if answer:
628
  st.session_state.attention_check1 = answer
629
  st.session_state.current_page = "random_likert_questions"
630
+ time.sleep(0.1) # تأخیر کوتاه برای اطمینان
631
  st.rerun()
632
  else:
633
  st.warning("لطفاً یک گزینه را انتخاب کنید")
634
+ st.session_state.btn_clicked = False # ریست وضعیت
635
 
636
+ # 3. مقداردهی اولیه session state
637
+ if "btn_clicked" not in st.session_state:
638
+ st.session_state.btn_clicked = False
 
 
 
 
 
639
 
640
 
641
  def attention_check2():