286 lines
9.3 KiB
C#
286 lines
9.3 KiB
C#
using System;
|
|
using System.Diagnostics;
|
|
using System.IO;
|
|
using System.Net;
|
|
using System.Text;
|
|
using System.Text.RegularExpressions;
|
|
using System.Windows.Forms;
|
|
using Tesseract;
|
|
|
|
///////////////////////////////////////
|
|
//
|
|
// (c) TK 2024
|
|
//
|
|
///////////////////////////////////////
|
|
|
|
|
|
namespace WinSize2Magick
|
|
{
|
|
public partial class Form1 : Form
|
|
{
|
|
//WebBrowser web1 = new WebBrowser();
|
|
int iWidthMax;
|
|
int iHeightMax;
|
|
//tab control
|
|
int iTCLeft;
|
|
int iTCRight;
|
|
|
|
string strCmdText = "D:\\tmp\\sourcedrive\\domystuff.cmd";
|
|
string strCMDresamble = @"magick -units PixelsPerInch x.png -resample 300 xx.png";
|
|
public Form1()
|
|
{
|
|
InitializeComponent();
|
|
|
|
//this.BackColor = Color.LimeGreen;
|
|
//this.TransparencyKey = Color.LimeGreen;
|
|
this.Opacity = .80;
|
|
this.AllowTransparency = true;
|
|
|
|
webView1.EnsureCoreWebView2Async();
|
|
webView2.EnsureCoreWebView2Async();
|
|
webViewWeb.EnsureCoreWebView2Async();
|
|
|
|
}
|
|
|
|
|
|
private void Form1_Load(object sender, EventArgs e)
|
|
{
|
|
//this.tabPage1.Controls.Add(web1);
|
|
//string strhtml = WebUtility.HtmlEncode(@"file:///C:\Users\kagert\Desktop\BWL\03 Buchhaltung und Bilanzierung\Pruefung\Bilanzierung OF.pdf");
|
|
//web1.Navigate(strhtml);
|
|
|
|
}
|
|
|
|
|
|
private void Form1_SizeChanged(object sender, EventArgs e)
|
|
{
|
|
lblXplus.Text = this.Left.ToString();
|
|
lblYplus.Text = this.Top.ToString();
|
|
lblX.Text = this.Width.ToString();
|
|
lblY.Text = this.Height.ToString();
|
|
|
|
tabControl1.Width = this.Width - tabControl1.Left - 10;
|
|
tabControl1.Height = this.Height - 90;
|
|
}
|
|
|
|
private void Form1_Move(object sender, EventArgs e)
|
|
{
|
|
Form1_SizeChanged(sender, e);
|
|
}
|
|
|
|
private void btnWrite_Click(object sender, EventArgs e)
|
|
{
|
|
|
|
string text = lblX.Text + "x" + lblY.Text + "+" + lblXplus.Text + "+" + lblYplus.Text;
|
|
|
|
string docPath = txtPathFileName.Text;
|
|
|
|
|
|
File.WriteAllText(docPath, text);
|
|
|
|
//string[] lines = { "New line 1", "New line 2" };
|
|
// Append new lines
|
|
//File.AppendAllLines(Path.Combine(docPath, "WriteFile.txt"), lines);
|
|
|
|
}
|
|
|
|
private void chkKeepOnTop_CheckedChanged(object sender, EventArgs e)
|
|
{
|
|
if (chkKeepOnTop.Checked)
|
|
{ this.TopMost = true; }
|
|
else
|
|
{ this.TopMost = false; }
|
|
}
|
|
|
|
private void btnQuit_Click(object sender, EventArgs e)
|
|
{
|
|
Application.Exit();
|
|
}
|
|
|
|
private void btnSmallLarge_Click(object sender, EventArgs e)
|
|
{
|
|
|
|
//webView1.CoreWebView2.Navigate("file:///C:/Users/kagert/Desktop/BWL/03 Buchhaltung und Bilanzierung/Pruefung/Bilanzierung OF.pdf");
|
|
|
|
if (this.Width > 170)
|
|
{
|
|
iWidthMax = this.Width;
|
|
this.Width = 86;
|
|
}
|
|
else
|
|
this.Width = iWidthMax;
|
|
}
|
|
|
|
private void trackBarOpacity_ValueChanged(object sender, EventArgs e)
|
|
{
|
|
|
|
if (trackBarOpacity.Value > 2)
|
|
this.Opacity = (float)trackBarOpacity.Value / 10;
|
|
}
|
|
|
|
private void btnHideWindow_Click(object sender, EventArgs e)
|
|
{
|
|
this.WindowState = FormWindowState.Minimized;
|
|
}
|
|
|
|
private void webView2_DoubleClick(object sender, EventArgs e)
|
|
{
|
|
|
|
//webView1.CoreWebView2.Navigate("file:///C:/Users/kagert/Desktop/BWL/03 Buchhaltung und Bilanzierung/Pruefung/Bilanzierung OF.pdf");
|
|
|
|
|
|
}
|
|
|
|
private async void btnFile1_Click(object sender, EventArgs e)
|
|
{
|
|
Button dummyButton = (Button)sender;
|
|
|
|
openFileDialog1.ShowDialog(this);
|
|
|
|
string strFileName = openFileDialog1.FileName;
|
|
|
|
if (dummyButton.Name.ToString() == "btnFile1")
|
|
webView1.CoreWebView2.Navigate(strFileName);
|
|
|
|
if (dummyButton.Name.ToString() == "btnFile2")
|
|
webView2.CoreWebView2.Navigate(strFileName);
|
|
|
|
}
|
|
|
|
private async void btnGo_Click(object sender, EventArgs e)
|
|
{
|
|
webViewWeb.CoreWebView2.Navigate("http://chatgpt.com");
|
|
}
|
|
|
|
private async void btnScreenshot_Click(object sender, EventArgs e)
|
|
{
|
|
btnScreenshot.BackColor = Color.Green;
|
|
|
|
string strArg;
|
|
strCmdText = "D:\\tmp\\sourcedrive\\domystuff.cmd";
|
|
//startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
|
|
Process myprocess = new Process();
|
|
myprocess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
|
|
myprocess.StartInfo.CreateNoWindow = true;
|
|
myprocess.StartInfo.FileName = strCmdText;// "cmd.exe ";
|
|
//myprocess.StartInfo.Arguments = strCmdText;
|
|
myprocess.Start();
|
|
|
|
btnScreenshot.BackColor = btnOCR.BackColor;
|
|
|
|
btnOCR_Click(sender, e);
|
|
|
|
//System.Diagnostics.Process.Start("CMD.exe", strCmdText);
|
|
}
|
|
|
|
private async void btnOCR_Click(object sender, EventArgs e)
|
|
{
|
|
|
|
btnOCR.BackColor = Color.Green;
|
|
|
|
rtbText.Clear();
|
|
string strResult = "null";
|
|
|
|
var engine = new TesseractEngine(@"D:\\Development\\tessdata", "deu", EngineMode.LstmOnly);
|
|
var image = Pix.LoadFromFile(@"D:\\tmp\\sourcedrive\\x2.png");
|
|
|
|
|
|
var page = engine.Process(image);
|
|
|
|
string text = page.GetText();
|
|
|
|
rtbText.Text = text;
|
|
|
|
|
|
//ProseMirror
|
|
//var elem = webViewWeb.ExecuteScriptAsync($"document.getElementById('prompt-textarea').innerText = '{text.ToString()}';");
|
|
var msg = @"Gib am Ende eine Zusammenfassung mit RICHTIG oder falsch aus.\n\n";
|
|
msg += text.Replace("\n", "\\n");
|
|
//msg = @"huhuhu\n\nzuzuzuz";
|
|
var elem = await webViewWeb.ExecuteScriptAsync($"document.getElementById('prompt-textarea').innerText ='{msg}';");
|
|
|
|
Debug.Print("...start send");
|
|
//Thread.Sleep(1000);
|
|
elem = await webViewWeb.ExecuteScriptAsync($"document.querySelector('button[aria-label=\"Send prompt\"]').click();");
|
|
Debug.Print("...finished send");
|
|
Thread.Sleep(500);
|
|
|
|
//button class="cursor-pointer absolute z-10 rounded-full
|
|
//react-scroll-to-bottom--css-hssfi-1tj0vk3 hidden
|
|
//cursor-pointer absolute z-10 rounded-full bg-clip-padding border text-token-text-secondary border-token-border-light right-1/2 translate-x-1/2 bg-token-main-surface-primary w-8 h-8 flex items-center justify-center bottom-5
|
|
//'button[class=\"react-scroll-to-bottom--css-yryca-1tj0vk3 hidden\"]'
|
|
//Thread.Sleep(5000);
|
|
|
|
do
|
|
{
|
|
|
|
//strResult = await webViewWeb.ExecuteScriptAsync($"document.querySelector('button[class*=\"react-scroll-to-bottom--css\"]').getAttribute(\"type\") ");
|
|
strResult = await webViewWeb.ExecuteScriptAsync($"document.querySelector('button[data-testid=\"send-button\"]').getAttribute(\"aria-label\") ");
|
|
|
|
Debug.Print("..waitin..." + strResult);
|
|
Thread.Sleep(100);
|
|
|
|
|
|
} while (!strResult.Contains("Send prompt"));//Stop streaming
|
|
|
|
Thread.Sleep(1500);
|
|
|
|
Debug.Print("...press down");
|
|
var meee = webViewWeb.ExecuteScriptAsync($"document.querySelector('button[class*=\"react-scroll-to-bottom--css\"]').click()");
|
|
Debug.Print("...after press down" + meee);
|
|
|
|
//elem = await webViewWeb.ExecuteScriptAsync($"document.getElementsByName('button')[2].click();");
|
|
|
|
engine.Dispose();
|
|
image.Dispose();
|
|
|
|
btnOCR.BackColor = btnScreenshot.BackColor;
|
|
|
|
}
|
|
|
|
private async void btnDown_Click(object sender, EventArgs e)
|
|
{
|
|
|
|
//document.querySelector('button[data-testid="send-button"]').getAttribute('aria-label'); //Send-Button label
|
|
|
|
//string isscrolling = await webViewWeb.ExecuteScriptAsync($"document.querySelector('button[data-testid=\"send-button\"]').getAttribute(\"aria-label\") ");
|
|
//Debug.Print(isscrolling);
|
|
//MessageBox.Show(isscrolling);
|
|
|
|
|
|
//if (isscrolling.)
|
|
//isscrolling = webViewWeb.ExecuteScriptAsync($"document.querySelector('button[aria-label=\"Stop streaming\"]') ");
|
|
|
|
var elem = await webViewWeb.ExecuteScriptAsync($"document.querySelector('button[class*=\"react-scroll-to-bottom--css\"]').getAttribute(\"type\") ");
|
|
Debug.Print(elem);
|
|
|
|
elem = await webViewWeb.ExecuteScriptAsync($"document.querySelector('button[class*=\"react-scroll-to-bottom--css\"]').click();");
|
|
Debug.Print(elem);
|
|
|
|
}
|
|
|
|
private void tabControl1_DoubleClick(object sender, EventArgs e)
|
|
{
|
|
|
|
if (tabControl1.Left > 16)
|
|
{
|
|
iTCLeft = tabControl1.Left;
|
|
tabControl1.Left = 16;
|
|
}
|
|
else
|
|
tabControl1.Left = iTCLeft;
|
|
|
|
Form1_SizeChanged(sender, e);
|
|
|
|
}
|
|
|
|
private void btnFullView_Click(object sender, EventArgs e)
|
|
{
|
|
|
|
tabControl1_DoubleClick( sender,e );
|
|
|
|
}
|
|
|
|
}
|
|
}
|