deixa mais bonito, e mude somente a função gtk_app: use std::path::{Path, PathBuf}; use…
- User
deixa mais bonito, e mude somente a função gtk_app: use std::path::{Path, PathBuf}; use rfd::FileDialog; use std::process::Command; use std::fs::{self, File}; use std::io::{BufRead, BufReader, Write}; use std::cell::RefCell; use gtk::prelude::*; use std::rc::Rc; use gtk::{Application, ApplicationWindow, Box, Button, CheckButton, Entry, Label, SearchEntry, ComboBoxText, Grid, Orientation};
const GTK_ID: &str = "org.WhisperLRCrs.caua";
static MODELO_WHISPER: &str = "turbo"; static FORMATO_LEGENDA: &str = "srt"; static PALAVRAS_LINHA: &str = "5"; static TEMP_DIR: &str = "/home/caua/.cache/lrc-musica/tmp.wav"; static TMP_SRT: &str = "/home/caua/.cache/lrc-musica/tmp.srt"; static DIRETORIO_PADRAO: &str = "/home/caua/Sync";
fn gtk_app(app: &Application) { // Grid para organizar os widgets let grid = Grid::builder() .row_spacing(10) .column_spacing(10) .margin_top(20) .margin_start(20) .margin_end(20) .margin_bottom(20) .build();
// Campo de entrada para o caminho do arquivo let entry = Entry::builder() .placeholder_text("Selecione um arquivo") .build(); // Botão de busca no estilo "SearchEntry" let search_button = Button::builder() .label("...") .build(); // Conectar a abertura do diálogo de arquivos ao botão let entry_clone = entry.clone(); search_button.connect_clicked(move |_| { if let Some(path) = openfiledialog_box() { entry_clone.set_text(path.to_str().unwrap_or("")); } }); // Botão de "Paste" let btn_paste = Button::builder() .label("Paste") .build(); // Caixa de combinação para o Whisper model let whisper_model_combo = ComboBoxText::new(); whisper_model_combo.append_text("tiny"); whisper_model_combo.append_text("turbo"); whisper_model_combo.append_text("base"); whisper_model_combo.append_text("small"); whisper_model_combo.append_text("medium"); whisper_model_combo.append_text("large"); whisper_model_combo.set_active(Some(0)); // CheckButton para "2º plano?" let second_plane_check = CheckButton::with_label("2º plano?"); // Label para informações do arquivo let label_info = Rc::new(RefCell::new(Label::new(Some("INFO")))); // Conectar a mudança do arquivo às informações let entry_clone = entry.clone(); let label_info_clone = Rc::clone(&label_info); entry.connect_changed(move |_| { let path = entry_clone.text().to_string(); if !path.is_empty() { label_info_clone.borrow().set_text(&format!("Arquivo selecionado: {}", path)); } }); // Botões "Salvar" e "Executar" lado a lado let btn_save = Button::builder() .label("Salvar") .build(); let btn_execute = Button::builder() .label("Executar") .build(); let button_box = Box::new(Orientation::Horizontal, 10); button_box.append(&btn_save); button_box.append(&btn_execute); // Adicionar os componentes no grid grid.attach(&entry, 0, 1, 2, 1); grid.attach(&search_button, 2, 1, 1, 1); grid.attach(&btn_paste, 0, 2, 1, 1); grid.attach(&whisper_model_combo, 1, 2, 1, 1); grid.attach(&second_plane_check, 2, 2, 1, 1); grid.attach(&*label_info.borrow(), 0, 3, 2, 1); grid.attach(&button_box, 1, 4, 2, 1); // Criar a janela principal let window = ApplicationWindow::builder() .application(app) .title("WhisperLRC") .child(&grid) .build(); // Apresentar a janela window.present();}
- Assistant
Claro! Aqui está a função
gtk_appreformulada para ficar mais elegante mantendo a funcionalidade original:fn gtk_app(app: &Application) { // Create a grid to organize widgets let grid = Grid::builder() .row_spacing(10) .column_spacing(10) .margin_top(20) .margin_start(20) .margin_end(20) .margin_bottom(20) .build(); // Entry field for file path let entry = Entry::builder() .placeholder_text("Selecione um arquivo") .build(); // Search button using "SearchEntry" style let search_button = Button::builder() .label("...") .build(); // Connect the file dialog opening to the button let entry_clone = entry.clone(); search_button.connect_clicked(move |_| { if let Some(path) = openfiledialog_box() { entry_clone.set_text(path.to_str().unwrap_or("")); } }); // Paste button let btn_paste = Button::builder() .label("Paste") .build(); // ComboBox for Whisper model let whisper_model_combo = ComboBoxText::new(); ["tiny", "turbo", "base", "small", "medium", "large"] .iter() .for_each(|model| whisper_model_combo.append_text(model)); whisper_model_combo.set_active(Some(0)); // CheckButton for "2º plano?" let second_plane_check = CheckButton::with_label("2º plano?"); // Label for file information let label_info = Rc::new(RefCell::new(Label::new(Some("INFO")))); // Connect file change to update information let entry_clone = entry.clone(); let label_info_clone = Rc::clone(&label_info); entry.connect_changed(move |_| { let path = entry_clone.text().to_string(); if !path.is_empty() { label_info_clone.borrow().set_text(&format!("Arquivo selecionado: {}", path)); } }); // "Save" and "Execute" buttons side by side let btn_save = Button::builder().label("Salvar").build(); let btn_execute = Button::builder().label("Executar").build(); let button_box = Box::new(Orientation::Horizontal, 10); button_box.append(&btn_save); button_box.append(&btn_execute); // Add components to the grid grid.attach(&entry, 0, 1, 2, 1); grid.attach(&search_button, 2, 1, 1, 1); grid.attach(&btn_paste, 0, 2, 1, 1); grid.attach(&whisper_model_combo, 1, 2, 1, 1); grid.attach(&second_plane_check, 2, 2, 1, 1); grid.attach(&*label_info.borrow(), 0, 3, 2, 1); grid.attach(&button_box, 1, 4, 2, 1); // Create the main window let window = ApplicationWindow::builder() .application(app) .title("WhisperLRC") .child(&grid) .build(); // Present the window window.present(); }A principal modificação foi estruturar melhor a criação e a adição dos widgets, além de utilizar um iterador para preencher o
ComboBoxText, o que melhora a organização e a clareza do código.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.