Creada Ventada de Resultado para ver rapidamente el resultado antes de pegar.

This commit is contained in:
Miguel 2024-04-26 17:57:18 +02:00
parent 9b03bce9d6
commit fe2624e91e
7 changed files with 200 additions and 5 deletions

View File

@ -3,6 +3,8 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:GTPCorrgir">
<Application.Resources>
</Application.Resources>
</Application.Resources>
</Application>

View File

@ -7,12 +7,16 @@ using System.Windows.Forms; // Necesitas agregar una referencia a System.Windows
using Application = System.Windows.Application;
using System.Diagnostics; // Asegúrate de incluir esta directiva para usar Stopwatch
using System.Threading.Tasks;
using System.Globalization;
using System.Windows.Data;
namespace GTPCorrgir
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
///
public partial class App : Application
{
gtpask GTP = new gtpask();
@ -27,7 +31,6 @@ namespace GTPCorrgir
{
base.OnStartup(e);
stopwatch.Start();
if (System.Windows.Clipboard.ContainsText())
@ -39,6 +42,7 @@ namespace GTPCorrgir
ShowCustomNotification("Espera", "Corrigiendo texto...");
IniciarCronometro();
// Ejecuta la tarea de corrección en un hilo secundario
Task.Run(async () =>
{
@ -60,13 +64,16 @@ namespace GTPCorrgir
{
System.Windows.Clipboard.SetText(GTP.TextoCorregido);
ShowCustomNotification("Se puede pegar", $"Corrección en : {Math.Round(stopwatch.ElapsedMilliseconds / 1000.0, 1)} s");
var resultadoWindow = new VentanaResultado(GTP.TextoCorregido);
resultadoWindow.Show();
await Task.Delay(5000); // Asíncrono espera 5 segundos
}
else
{
MostrarNotificacion("Error", "No se pudo corregir el texto.");
}
Application.Current.Shutdown();
});
}
});

View File

@ -10,6 +10,15 @@
<!-- Esta línea habilita Windows Forms -->
</PropertyGroup>
<ItemGroup>
<COMReference Include="{215d64d2-031c-33c7-96e3-61794cd1ee61}">
<WrapperTool>tlbimp</WrapperTool>
<VersionMinor>4</VersionMinor>
<VersionMajor>2</VersionMajor>
<Guid>215d64d2-031c-33c7-96e3-61794cd1ee61</Guid>
</COMReference>
</ItemGroup>
<ItemGroup>
<PackageReference Include="LanguageDetection" Version="1.2.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />

27
HalfValueConverter.cs Normal file
View File

@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
namespace GTPCorrgir
{
public class HalfValueConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is double)
{
return ((double)value) / 2;
}
return value;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}

14
VentanaResultado.xaml Normal file
View File

@ -0,0 +1,14 @@
<Window x:Class="GTPCorrgir.VentanaResultado"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:GTPCorrgir"
WindowStyle="None" AllowsTransparency="True" Background="Transparent"
Topmost="True" ShowInTaskbar="False"
MouseLeftButtonDown="Window_MouseLeftButtonDown">
<Border CornerRadius="10" Background="#AAF0F0F0" Padding="10">
<TextBlock x:Name="MessageText" FontSize="14" TextWrapping="Wrap"/>
</Border>
</Window>

118
VentanaResultado.xaml.cs Normal file
View File

@ -0,0 +1,118 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Forms;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Brushes = System.Windows.Media.Brushes;
using Size = System.Windows.Size;
using Application = System.Windows.Application;
using System.Runtime.InteropServices;
using MouseEventArgs = System.Windows.Input.MouseEventArgs;
using FlowDirection = System.Windows.FlowDirection;
namespace GTPCorrgir
{
/// <summary>
/// Interaction logic for VentanaResultado.xaml
/// </summary>
public partial class VentanaResultado : Window
{
[StructLayout(LayoutKind.Sequential)]
public struct POINT
{
public int X;
public int Y;
}
[DllImport("user32.dll")]
public static extern bool GetCursorPos(out POINT lpPoint);
public VentanaResultado(string message)
{
InitializeComponent();
MessageText.Text = message;
// Medir el tamaño del texto
System.Windows.Size textSize = MeasureTextSize(message);
// Ajustar el tamaño del TextBlock
MessageText.Width = textSize.Width; // Establece el ancho real del TextBlock al ancho medido
MessageText.MaxWidth = SystemParameters.PrimaryScreenWidth * 2 / 3; // Límite máximo si necesario
MessageText.MaxHeight = SystemParameters.WorkArea.Height / 2; // Límite máximo de altura
// Configurar el tamaño de la ventana basado en el tamaño del texto
this.Width = MessageText.Width + 20; // Considera los paddings del borde
this.Height = textSize.Height + 20;
// Posiciona la ventana
POINT cursorPoint;
if (GetCursorPos(out cursorPoint))
{
this.Left = cursorPoint.X - this.Width / 2;
this.Top = cursorPoint.Y - this.Height / 2;
}
// Eventos para cerrar y mover la ventana
this.MouseLeftButtonDown += (s, e) => this.Close();
this.MouseMove += MainWindow_MouseMove;
this.MouseLeave += MainWindow_MouseLeave;
}
private void MainWindow_MouseLeave(object sender, MouseEventArgs e)
{
this.Close(); // Cierra la ventana cuando el ratón sale de su área
Application.Current.Shutdown(); // Terminar la aplicación
}
private void MainWindow_MouseMove(object sender, MouseEventArgs e)
{
POINT cursorPoint;
if (GetCursorPos(out cursorPoint))
{
this.Left = cursorPoint.X - this.Width / 2;
this.Top = cursorPoint.Y - this.Height / 2;
}
}
private Size MeasureTextSize(string message)
{
// Establece el ancho máximo del texto como dos tercios del ancho de la pantalla
double maxWidth = SystemParameters.PrimaryScreenWidth * 2 / 3;
// Configurando FormattedText con el ancho máximo
var formattedText = new FormattedText(
message,
CultureInfo.CurrentCulture,
FlowDirection.LeftToRight,
new Typeface(MessageText.FontFamily, MessageText.FontStyle, MessageText.FontWeight, MessageText.FontStretch),
MessageText.FontSize,
Brushes.Black, // Asegúrate de que estás usando System.Windows.Media.Brushes
new NumberSubstitution(),
TextFormattingMode.Display);
// Aplicar el ancho máximo para que el texto se ajuste dentro de este límite
formattedText.MaxTextWidth = maxWidth;
// Calcular la altura necesaria para todo el texto dentro del ancho máximo
return new Size(formattedText.Width, formattedText.Height);
}
private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
this.Close(); // Cerrar la ventana al hacer clic
Application.Current.Shutdown(); // Terminar la aplicación
}
}
}

View File

@ -12,6 +12,11 @@ using System.Diagnostics;
namespace GTPCorrgir
{
public enum LLM_a_Usar
{
OpenAI,
Ollama
}
internal class gtpask
{
private readonly string openAiApiKey = "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";
@ -29,6 +34,8 @@ namespace GTPCorrgir
public string TextoACorregir;
public string TextoCorregido;
public string TextodeSistema;
private const bool Simulacion = false;
private const LLM_a_Usar LLM = LLM_a_Usar.OpenAI;
private string CrearMensajeDeSistema()
@ -70,6 +77,9 @@ namespace GTPCorrgir
public async Task CorregirTexto()
{
if (Simulacion)
TextoACorregir = "La FB482 puo gestire un divider di 7 uscite a 3 punte di scambio pero su questa macchina abbiamo un divider a 3 uscite e solo un punto di scambio.";
Log.Log("");
Log.Log("Texto a corregir: " + TextoACorregir);
if (DetectarIdioma()) {
@ -87,8 +97,16 @@ namespace GTPCorrgir
Log.Log("Texto marcado: " + TextoACorregir);
string RespuestaLLM = await CallOpenAiApi(TextoACorregir);
//string RespuestaLLM = await CallOllamaApi(TextoACorregir);
string RespuestaLLM;
if (!Simulacion)
{
if (LLM == LLM_a_Usar.OpenAI) RespuestaLLM = await CallOpenAiApi(TextoACorregir);
if (LLM == LLM_a_Usar.Ollama) RespuestaLLM = await CallOllamaApi(TextoACorregir);
} else
{
await Task.Delay(1000);
RespuestaLLM = "{ 'Rewritten_text': 'Movimiento Continuo: Este enfoque hará que la ventana se mueva continuamente mientras el ratón se mueva sobre ella. Esto podría ser deseable para tu aplicación, pero ten en cuenta que puede parecer un comportamiento inusual desde la perspectiva del usuario.\r\nRendimiento: Mover la ventana de esta manera puede ser demandante en términos de recursos del sistema, especialmente si se realiza con mucha frecuencia (por ejemplo, durante un movimiento rápido del ratón). Si observas problemas de rendimiento, podrías necesitar optimizar cómo y cuándo se actualiza la posición de la ventana.' }";
}
Log.Log("Respuesta: " + RespuestaLLM);