Spaces:
Paused
Paused
Update app.py
Browse files
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"]
|
|
@@ -757,7 +757,7 @@ def enhanced_likert_scale(question_data):
|
|
| 757 |
font-family: 'B Nazanin', Arial, sans-serif !important;
|
| 758 |
direction: rtl !important;
|
| 759 |
text-align: center !important;
|
| 760 |
-
margin:
|
| 761 |
position: relative !important;
|
| 762 |
}}
|
| 763 |
.likert-question {{
|
|
@@ -777,7 +777,6 @@ def enhanced_likert_scale(question_data):
|
|
| 777 |
display: flex !important;
|
| 778 |
justify-content: center !important;
|
| 779 |
gap: 8px !important;
|
| 780 |
-
flex-wrap: wrap !important;
|
| 781 |
margin: 0 !important;
|
| 782 |
position: relative !important;
|
| 783 |
height: 40px !important;
|
|
@@ -878,6 +877,15 @@ def enhanced_likert_scale(question_data):
|
|
| 878 |
پاسخ شما: {st.session_state[key] or "هیچکدام"}
|
| 879 |
</div>
|
| 880 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 881 |
"""
|
| 882 |
|
| 883 |
# رندر HTML
|
|
@@ -891,29 +899,35 @@ def enhanced_likert_scale(question_data):
|
|
| 891 |
# کانتینر برای دکمه Streamlit
|
| 892 |
st.markdown(
|
| 893 |
f"""
|
| 894 |
-
<
|
| 895 |
-
|
| 896 |
-
|
| 897 |
-
|
| 898 |
-
|
| 899 |
-
|
| 900 |
-
|
| 901 |
-
|
| 902 |
-
|
| 903 |
-
|
| 904 |
-
|
| 905 |
-
|
| 906 |
-
|
| 907 |
-
|
| 908 |
-
|
| 909 |
-
|
| 910 |
-
|
| 911 |
-
|
| 912 |
-
|
| 913 |
-
|
| 914 |
-
|
| 915 |
-
|
| 916 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 917 |
""",
|
| 918 |
unsafe_allow_html=True
|
| 919 |
)
|
|
@@ -924,6 +938,15 @@ def enhanced_likert_scale(question_data):
|
|
| 924 |
type="secondary"
|
| 925 |
):
|
| 926 |
st.session_state[key] = value
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 927 |
st.rerun()
|
| 928 |
|
| 929 |
return st.session_state.get(key)
|
|
|
|
| 739 |
|
| 740 |
# ========== توابع اصلی ==========
|
| 741 |
def enhanced_likert_scale(question_data):
|
| 742 |
+
"""لیکرت اسکیل با دکمههای Streamlit مخفی دقیقاً زیر دکمههای HTML"""
|
| 743 |
question = question_data["question"]
|
| 744 |
key = question_data["key"]
|
| 745 |
scale = question_data["scale"]
|
|
|
|
| 757 |
font-family: 'B Nazanin', Arial, sans-serif !important;
|
| 758 |
direction: rtl !important;
|
| 759 |
text-align: center !important;
|
| 760 |
+
margin: 0 !important;
|
| 761 |
position: relative !important;
|
| 762 |
}}
|
| 763 |
.likert-question {{
|
|
|
|
| 777 |
display: flex !important;
|
| 778 |
justify-content: center !important;
|
| 779 |
gap: 8px !important;
|
|
|
|
| 780 |
margin: 0 !important;
|
| 781 |
position: relative !important;
|
| 782 |
height: 40px !important;
|
|
|
|
| 877 |
پاسخ شما: {st.session_state[key] or "هیچکدام"}
|
| 878 |
</div>
|
| 879 |
</div>
|
| 880 |
+
<script>
|
| 881 |
+
function updateLikertSelection(key, value) {{
|
| 882 |
+
const buttons = document.querySelectorAll('#likert-buttons-{key} .likert-btn');
|
| 883 |
+
buttons.forEach(btn => btn.classList.remove('selected'));
|
| 884 |
+
const selectedBtn = Array.from(buttons).find(btn => btn.onclick.toString().includes('streamlit-btn-{key}-' + value));
|
| 885 |
+
if (selectedBtn) selectedBtn.classList.add('selected');
|
| 886 |
+
document.getElementById('likert-response-{key}').innerText = 'پاسخ شما: ' + (value || 'هیچکدام');
|
| 887 |
+
}}
|
| 888 |
+
</script>
|
| 889 |
"""
|
| 890 |
|
| 891 |
# رندر HTML
|
|
|
|
| 899 |
# کانتینر برای دکمه Streamlit
|
| 900 |
st.markdown(
|
| 901 |
f"""
|
| 902 |
+
<style>
|
| 903 |
+
.likert-streamlit-btn-container-{key}-{value} {{
|
| 904 |
+
position: relative !important;
|
| 905 |
+
width: 40px !important;
|
| 906 |
+
height: 40px !important;
|
| 907 |
+
margin: 0 !important;
|
| 908 |
+
padding: 0 !important;
|
| 909 |
+
}}
|
| 910 |
+
#streamlit-btn-{key}-{value} {{
|
| 911 |
+
width: 40px !important;
|
| 912 |
+
height: 40px !important;
|
| 913 |
+
opacity: 0 !important;
|
| 914 |
+
position: absolute !important;
|
| 915 |
+
top: 0 !important;
|
| 916 |
+
left: 0 !important;
|
| 917 |
+
margin: 0 !important;
|
| 918 |
+
padding: 0 !important;
|
| 919 |
+
border: none !important;
|
| 920 |
+
background: white !important;
|
| 921 |
+
z-index: 1 !important;
|
| 922 |
+
}}
|
| 923 |
+
#streamlit-btn-{key}-{value}:hover,
|
| 924 |
+
#streamlit-btn-{key}-{value}:focus,
|
| 925 |
+
#streamlit-btn-{key}-{value}:active {{
|
| 926 |
+
border: none !important;
|
| 927 |
+
background: white !important;
|
| 928 |
+
}}
|
| 929 |
+
</style>
|
| 930 |
+
<div class="likert-streamlit-btn-container-{key}-{value}"></div>
|
| 931 |
""",
|
| 932 |
unsafe_allow_html=True
|
| 933 |
)
|
|
|
|
| 938 |
type="secondary"
|
| 939 |
):
|
| 940 |
st.session_state[key] = value
|
| 941 |
+
# آپدیت دکمههای HTML با JavaScript
|
| 942 |
+
st.markdown(
|
| 943 |
+
f"""
|
| 944 |
+
<script>
|
| 945 |
+
updateLikertSelection('{key}', {value});
|
| 946 |
+
</script>
|
| 947 |
+
""",
|
| 948 |
+
unsafe_allow_html=True
|
| 949 |
+
)
|
| 950 |
st.rerun()
|
| 951 |
|
| 952 |
return st.session_state.get(key)
|