drguilhermeapolinario commited on
Commit
9be4a63
·
verified ·
1 Parent(s): cd39bce

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -38
app.py CHANGED
@@ -127,49 +127,35 @@ def apply_neumorphic_style():
127
  # Aplicar o estilo
128
  apply_neumorphic_style()
129
 
130
-
131
-
132
  def copy_to_clipboard(text):
133
- component = f"""
134
- <textarea id="textarea" style="position: absolute; left: -9999px;">{text}</textarea>
135
- <script>
136
- function copyTextToClipboard() {{
137
- var textarea = document.getElementById('textarea');
138
- textarea.select();
139
- document.execCommand('copy');
140
- var copyStatus = document.getElementById('copy_status');
141
- if (copyStatus) {{
142
- copyStatus.style.display = 'inline';
143
- setTimeout(function() {{
144
- copyStatus.style.display = 'none';
145
- }}, 2000);
146
- }}
147
- }}
148
- </script>
149
- """
150
- components.html(component, height=0)
151
-
152
- if st.button("Copiar"):
153
- st.components.v1.html(
154
- f"""
155
- <script>
156
- copyTextToClipboard();
157
- </script>
158
- <p id="copy_status" style="color: green;">Texto copiado!</p>
159
- """,
160
- height=50
161
- )
162
-
163
 
164
- # def copy_to_clipboard(text):
165
- # pyperclip.copy(text)
 
166
 
 
 
 
167
 
168
- def create_copy_button(text, button_text="Copiar para o Prontuário"):
169
- copy_button = st.button(button_text)
170
- if copy_button:
171
- copy_to_clipboard(text)
 
 
 
 
 
 
 
 
 
172
  st.success("Texto copiado para a área de transferência!")
 
 
173
 
174
 
175
  # Menu lateral
 
127
  # Aplicar o estilo
128
  apply_neumorphic_style()
129
 
 
 
130
  def copy_to_clipboard(text):
131
+ # Cria um valor de estado único para este botão
132
+ if 'copy_button_clicked' not in st.session_state:
133
+ st.session_state.copy_button_clicked = False
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
134
 
135
+ # Função de callback para o botão
136
+ def on_button_click():
137
+ st.session_state.copy_button_clicked = True
138
 
139
+ # Cria o botão com o callback
140
+ if st.button("Copiar", on_click=on_button_click):
141
+ pass # O código dentro deste bloco não será executado imediatamente
142
 
143
+ # Se o botão foi clicado, executa o JavaScript para copiar
144
+ if st.session_state.copy_button_clicked:
145
+ js_code = f"""
146
+ <script>
147
+ var textarea = document.createElement('textarea');
148
+ textarea.value = {text!r};
149
+ document.body.appendChild(textarea);
150
+ textarea.select();
151
+ document.execCommand('copy');
152
+ document.body.removeChild(textarea);
153
+ </script>
154
+ """
155
+ components.html(js_code, height=0)
156
  st.success("Texto copiado para a área de transferência!")
157
+ # Reseta o estado para permitir novas cópias
158
+ st.session_state.copy_button_clicked = False
159
 
160
 
161
  # Menu lateral