public static void Translation(string inLang, string outLang, Text T) { string concat = ""; for (int i = 0; i < T.content.Count; i++) { concat += T.content[i] + " "; } if (concat.Length > 1) { concat = concat.Remove(concat.Length - 1); } //MessageBox.Show("\""+concat+"\""); //MessageBox.Show(handleTranslation("en", "ja", concat)); T.content_trans.Clear(); string a = handleTranslation(inLang, outLang, concat); if (a != null) { a = TranslationTools.ReplaceASCII(a); T.content_trans.Add(a); T.lang_trans = outLang; } }
private void button2_Click(object sender, EventArgs e) { //string path = "C:\\Screenshots\\4.png"; string middle = "stdout"; if (OCRCombo.SelectedItem != null) { middle += " -l " + TranslationTools.getOCRLang(OCRCombo.Text); } else { middle += " -l eng"; } TranslationTools.show_MSG(label1, "Please wait...", Color.FromArgb(150, 255, 10, 10), 1); foreach (ListViewItem item in listView1.Items) //percorre todos os ficheiros { try { //var Result = new IronTesseract().Read(item.SubItems[0].Text).Text; //return; OCR(TESSERACT_EXE, item.SubItems[0].Text, middle); } catch (Exception ex) { MessageBox.Show("Error: " + ex.Message); } } listView1.Clear(); }
} //debuged public void auto_save_new() { DateTime thisDay = DateTime.Now; List <string> Sessions = TranslationTools.GetSessionNames(); string name = "Auto Save " + thisDay.ToString(); for (int i = 0; i < Sessions.Count; i++) { if (Sessions[i].Equals(name, StringComparison.CurrentCultureIgnoreCase)) { return; } } int Id; for (int i = 0; i < tempList.Count; i++) { TranslationTools.InsertImagePath(tempList[i]); Id = TranslationTools.GetLastId(); //gets the inserted ID of InsertImagePath TranslationTools.InsertSessionWAuto(name, Id); //creates a session TranslationTools.InsertScript(tempList[i], Id); //associates the Id of the images table to the text } string a = GetAutoSaves(); if (a != "") { TranslationTools.DeleteSession(a); } //TranslationTools.FillDropDownSessions("SELECT DISTINCT NameSession from Session;", comboSession); }
private void comboColors_SelectedIndexChanged(object sender, EventArgs e) { count++; if (count < 2) { return; } using (SqlConnection myConnection = new SqlConnection(CONNECTION_STRING)) { string sql = "select * from BackgroundColors where IDColor=" + TranslationTools.GetId(comboColors); using (SqlCommand cmd = new SqlCommand(sql, myConnection)) { myConnection.Open(); SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection); DataTable dt = new DataTable(); dt.Load(dr); numHueMin1.Value = Int32.Parse(dt.Rows[0].ItemArray[2].ToString()); numHueMax1.Value = Int32.Parse(dt.Rows[0].ItemArray[3].ToString()); numSatMin1.Value = Int32.Parse(dt.Rows[0].ItemArray[4].ToString()); numSatMax1.Value = Int32.Parse(dt.Rows[0].ItemArray[5].ToString()); numValMin1.Value = Int32.Parse(dt.Rows[0].ItemArray[6].ToString()); numValMax1.Value = Int32.Parse(dt.Rows[0].ItemArray[7].ToString()); myConnection.Close(); } } }
private void button1_Click(object sender, EventArgs e) { //update button int id = TranslationTools.GetId(UpdateBox); if (id == 13) { MessageBox.Show(UpdateBox.Text + " can't be edited"); return; } decimal mHue = numericUpDown1.Value; decimal MHue = numericUpDown2.Value; decimal mSat = numericUpDown3.Value; decimal MSat = numericUpDown4.Value; decimal mVal = numericUpDown5.Value; decimal MVal = numericUpDown6.Value; try { using (SqlConnection myConnection = new SqlConnection(CONNECTION_STRING)) { //string sql = "select * from BackgroundColors where IDColor=" + TranslationTools.GetId(UpdateBox); string sql = "UPDATE BackgroundColors SET HueMin = " + mHue + ", HueMax = " + MHue + ", SatMin = " + mSat + ", SatMax = " + MSat + ", ValMin = " + mVal + ", ValMax = " + MVal + " WHERE IDColor=" + id; //MessageBox.Show(sql); //return; using (SqlCommand cmd = new SqlCommand(sql, myConnection)) { myConnection.Open(); SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection); myConnection.Close(); } } } catch { return; } MessageBox.Show("Element sucessefully updated!"); }
private void UpdateImage(bool option) { Cursor.Current = Cursors.WaitCursor; button1.Enabled = false; button2.Enabled = false; button3.Enabled = false; //Option = 0; new file DO not apply remover //Option = 1; update, apply remover //create a temp image to load, DO NOT WORK WITH THE ORIGINAL TranslationTools.clearPictureBox(pictureBox1);//so the app do not use the image while modifing it //test with image open elsewhere, exception created , futher test are needed CreateTempImage(OPath, NPath); if (option == false) {// load temp if (System.IO.File.Exists(NPath)) { pictureBox1.Image = Image.FromFile(NPath); } } else { //Creates a temp from original and apply mask to the temp (replacing it) TranslationTools.clearPictureBox(pictureBox1); //so the app do not use the image //test with image open elsewhere RemoveImageBackground(); pictureBox1.Image = Image.FromFile(NPath); } DefinePicBoxSize(pictureBox1, NPath); Cursor.Current = Cursors.Default; button1.Enabled = true; button2.Enabled = true; button3.Enabled = true; }
private void btn_new_session_Click(object sender, EventArgs e) { if (rich_Original.TextLength > 0 | rich_Translated.TextLength > 0) { SaveThis(); } List <string> Sessions = TranslationTools.GetSessionNames(); string name = TextBox_SessionName.Text; if (name.Length < 3 | name.Length > 15) { MessageBox.Show("Write a name with:\nmore than 2 letters and less than 16"); return; } for (int i = 0; i < Sessions.Count; i++) { if (Sessions[i].Equals(name, StringComparison.CurrentCultureIgnoreCase)) { MessageBox.Show(Name + " already exists choose another"); return; } } CloneList(myList, tempList); int Id; for (int i = 0; i < myList.Count; i++) { TranslationTools.InsertImagePath(myList[i]); Id = TranslationTools.GetLastId(); //gets the inserted ID of InsertImagePath TranslationTools.InsertSession(name, Id); //creates a session TranslationTools.InsertScript(myList[i], Id); //associates the Id of the images table to the text } TranslationTools.FillDropDownSessions("SELECT DISTINCT NameSession from Session;", comboSession); } //debuged
// ################################# // https://stackoverflow.com/questions/33776387/dont-raise-textchanged-while-continuous-typing/33777265 void assistant_Idled(object sender, EventArgs e) { if (number <0 | number> tempList.Count - 1 | tempList.Count < 1) { return; } this.Invoke( new MethodInvoker(() => { SaveThis(); try { if (comboTranslation.SelectedItem != null) { TranslationTools.Translation("auto", TranslationTools.getTranslationStr(comboTranslation.SelectedItem.ToString()), tempList[number]); } else { TranslationTools.Translation("auto", "eng", tempList[number]); } } catch { MessageBox.Show("Error translating"); } updateTranslation(); })); }
private void RemoveImageBackground(String path, String new_path, String filename) { //Verificações: if (new_path == "") { return; } Bitmap image1 = new Bitmap(path, true); int x, y, opacity; double hue, saturation, value; if (checkBox1.Checked) { opacity = 0; //transparent } else { opacity = 255; //solid } if (checkBox2.Checked == true) { image1 = TranslationTools.ToGrey(image1); } //if (checkBox3.Checked == true) //{ // image1 = TranslationTools.ToBlackAndWhite(image1,opacity); // SaveImage(path, new_path, filename, image1); // image1.Dispose(); // return; //} for (x = 0; x < image1.Width; x++) { for (y = 0; y < image1.Height; y++) { Color pixelColor = image1.GetPixel(x, y); //gets the color of each pixel TranslationTools.ColorToHSV(pixelColor, out hue, out saturation, out value); //aqui temos os valores corretos do HSV //nas variaveis hue, saturation e value //MessageBox.Show("hue " + hue + "\nsaturation " + saturation + "\nvalue " + value); if (!RightColor(hue, saturation, value)) { //MessageBox.Show("hue " + hue + "\nsaturation " + saturation + "\nvalue " + value); pixelColor = Color.FromArgb(opacity, 0, 0, 0); image1.SetPixel(x, y, pixelColor); //MessageBox.Show(pixelColor.R + "\n" + pixelColor.G+"\n"+pixelColor.B); } } } //------------- SaveImage(path, new_path, filename, image1); image1.Dispose(); }
private void Button1_Click(object sender, EventArgs e) { if (OPath == "") { return; } TranslationTools.show_MSG(label7, "Please wait...", Color.FromArgb(150, 255, 10, 10), 1); UpdateImage(true); }
private void btn_delete_session_Click(object sender, EventArgs e) { if (comboSession.SelectedItem == null) { MessageBox.Show("Select a session"); return; } TranslationTools.DeleteSession(comboSession.Text); TranslationTools.FillDropDownSessions("SELECT DISTINCT NameSession from Session;", comboSession); }
private static System.Threading.Timer _timer;//https://www.c-sharpcorner.com/blogs/how-to-run-a-timer-on-specific-time-interval public ModifyText() { InitializeComponent(); assistant = new TypeAssistant(); assistant.Idled += assistant_Idled; TranslationTools.FillDropDownSessions("SELECT DISTINCT NameSession from Session;", comboSession); _timer = new System.Threading.Timer(x => { callTimerMethode(); }, null, Timeout.Infinite, Timeout.Infinite); Setup_Timer(); updateTextBox(); }
private void Form_PreviewBG_FormClosing(object sender, FormClosingEventArgs e) { TranslationTools.clearPictureBox(pictureBox1); if (System.IO.File.Exists(NPath)) { System.IO.File.Exists(NPath); } if (System.IO.File.Exists(NPath1)) { System.IO.File.Delete(NPath1); } }
private bool RightColor(double hue, double sat, double val) { //Hue: 0-179 //Saturation 0-255 //Value 0-255 if (hue == 360) { hue = hue / 2; } int IntHue = Convert.ToInt32(hue); if (IntHue > 179) { IntHue = 179; } int IntSat = Convert.ToInt32(sat * 255); int IntVal = Convert.ToInt32(val * 255); List <List <int> > ListArrays = new List <List <int> >(); //ListArrays.Add(new List<int> { 1, 2, 3, 4, 5, 6 }); ListArrays.AddRange(TranslationTools.GetListOfInts((int)numHueMin1.Value, (int)numHueMax1.Value, (int)numSatMin1.Value, (int)numSatMax1.Value, (int)numValMin1.Value, (int)numValMax1.Value)); if (this.HSVBox1.Checked) { ListArrays.AddRange(TranslationTools.GetListOfInts((int)numHueMin2.Value, (int)numHueMax2.Value, (int)numSatMin2.Value, (int)numSatMax2.Value, (int)numValMin2.Value, (int)numValMax2.Value)); } if (this.HSVBox2.Checked) { ListArrays.AddRange(TranslationTools.GetListOfInts((int)numHueMin3.Value, (int)numHueMax3.Value, (int)numSatMin3.Value, (int)numSatMax3.Value, (int)numValMin3.Value, (int)numValMax3.Value)); } if (this.HSVBox3.Checked) { ListArrays.AddRange(TranslationTools.GetListOfInts((int)numHueMin4.Value, (int)numHueMax4.Value, (int)numSatMin4.Value, (int)numSatMax4.Value, (int)numValMin4.Value, (int)numValMax4.Value)); } bool result = false; for (int x = 0; x < ListArrays.Count; x++) { result = TranslationTools.CheckBound(ListArrays[x], IntHue, IntSat, IntVal); if (result) { break; } } return(result); }
private void btn_load_session_Click(object sender, EventArgs e) { if (comboSession.SelectedItem == null) { MessageBox.Show("Select a session"); return; } string name = comboSession.Text; tempList.Clear(); tempList = TranslationTools.LoadFromDB(name); CloneList(myList, tempList); number = 0; updateTextBox(); }
private void TranslateAll(List <Text> T) { for (int i = 0; i < T.Count; i++) { //Translation(T[i].lang_con, TranslationTools.getTranslationStr(TransCombo.SelectedText), T[i]); if (TransCombo.SelectedItem != null) { TranslationTools.Translation("auto", TranslationTools.getTranslationStr(TransCombo.SelectedItem.ToString()), T[i]); } else { TranslationTools.Translation("auto", "eng", T[i]); } } //MessageBox.Show("Translation Done! Good Work!"); }
private void new_btn_save_Click(object sender, EventArgs e) { if (new_nameTextBox.Text == "") { MessageBox.Show("Choose a name"); return; } if (NameExists(new_nameTextBox.Text)) { MessageBox.Show("Choose different name"); return; } if (new_nameTextBox.Text.Length > 14) { MessageBox.Show("Use a smaller name"); return; } //INSERT INTO table_name(column1, column2, column3, ...) //VALUES(value1, value2, value3, ...); using (SqlConnection myConnection = new SqlConnection(CONNECTION_STRING)) { string sql = "INSERT INTO BackgroundColors (Name,HueMin,HueMax,SatMin,SatMax,ValMin,ValMax) VALUES ('" + new_nameTextBox.Text + "'," + new_hueMinNumericUpDown.Value + "," + new_hueMaxNumericUpDown.Value + "," + new_satMinNumericUpDown.Value + "," + new_satMaxNumericUpDown.Value + "," + new_valMinNumericUpDown.Value + "," + new_valMaxNumericUpDown.Value + ");"; //MessageBox.Show(sql); //return; using (SqlCommand cmd = new SqlCommand(sql, myConnection)) { try { myConnection.Open(); SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection); myConnection.Close(); //reloads the ComboBoxes and resets values count = 0; new_nameTextBox.Text = ""; new_hueMinNumericUpDown.Value = 0; new_hueMaxNumericUpDown.Value = 179; new_satMinNumericUpDown.Value = 0; new_satMaxNumericUpDown.Value = 255; new_valMinNumericUpDown.Value = 0; new_valMaxNumericUpDown.Value = 255; //MessageBox.Show(sql); TranslationTools.FillDropDownList("Select * From BackgroundColors Order by IDColor", deleteBox); TranslationTools.FillDropDownList("Select * From BackgroundColors Order by IDColor", UpdateBox); MessageBox.Show("Sucess!"); } catch { MessageBox.Show("Error"); } } } }
private void btnTranslate_Click(object sender, EventArgs e) { SaveThis(); try { if (comboTranslation.SelectedItem != null) { TranslationTools.Translation("auto", TranslationTools.getTranslationStr(comboTranslation.SelectedItem.ToString()), tempList[number]); } else { TranslationTools.Translation("auto", "eng", tempList[number]); } } catch { MessageBox.Show("Error translating"); } updateTranslation(); //updateTextBox(); }
private void btn_cleanListViewRemBg_Click(object sender, EventArgs e) { TranslationTools.CleanListView(list_RemBg); numHueMin1.Value = 0; numHueMin2.Value = 0; numHueMin3.Value = 0; numHueMin4.Value = 0; numHueMax1.Value = 179; numHueMax2.Value = 179; numHueMax3.Value = 179; numHueMax4.Value = 179; numSatMin1.Value = 0; numSatMin2.Value = 0; numSatMin3.Value = 0; numSatMin4.Value = 0; numSatMax1.Value = 255; numSatMax2.Value = 255; numSatMax3.Value = 255; numSatMax4.Value = 255; numValMin1.Value = 0; numValMin2.Value = 0; numValMin3.Value = 0; numValMin4.Value = 0; numValMax1.Value = 255; numValMax2.Value = 255; numValMax3.Value = 255; numValMax4.Value = 255; checkBox1.Checked = false; HSVBox1.Checked = false; HSVBox2.Checked = false; HSVBox3.Checked = false; comboColors.SelectedIndex = 0; }
private void btn_save_session_Click(object sender, EventArgs e) { if (comboSession.SelectedItem == null) { MessageBox.Show("Select a session"); return; } string name = comboSession.Text; if (IsAutoSave(name)) { MessageBox.Show("You can't overwrite Auto Saves!"); return; } if (rich_Original.TextLength > 0 | rich_Translated.TextLength > 0) { SaveThis(); } CloneList(myList, tempList); //TranslationTools.DeleteDataFromTables(); //1º apagar todos os dados da sessão que se vai salvar TranslationTools.DeleteSession(name); //2º invocar a função new session, é provavelmente melhor copiar porque se o //primeiro passo foi bem sucessido, o nome não existe int Id; for (int i = 0; i < myList.Count; i++) { TranslationTools.InsertImagePath(myList[i]); Id = TranslationTools.GetLastId(); //gets the inserted ID of InsertImagePath TranslationTools.InsertSession(name, Id); //creates a session TranslationTools.InsertScript(myList[i], Id); //associates the Id of the images table to the text } //REFRESH THE SESSION LIST (comboSession) }
private void Save(string extension) { // https://docs.microsoft.com/en-us/dotnet/desktop/winforms/controls/how-to-save-files-using-the-savefiledialog-component?view=netframeworkdesktop-4.8 if (listText.Count > 0) { SaveFileDialog saveFileDialog1 = new SaveFileDialog(); saveFileDialog1.Filter = extension; saveFileDialog1.Title = "Save the document"; saveFileDialog1.ShowDialog(); if (saveFileDialog1.FileName != "") { TranslationTools.show_MSG(label1, "Please wait...", Color.FromArgb(150, 255, 10, 10), 1); switch (comboBox4.SelectedIndex) { case 0: //txt original SaveToTxt_Original(listText, saveFileDialog1.FileName); break; case 1: //txt translation SaveToTxt_Translated(listText, saveFileDialog1.FileName); break; case 2: //txt both SaveToTxt_Both(listText, saveFileDialog1.FileName); break; case 3: //word SaveWord(listText, saveFileDialog1.FileName); break; case 4: //excel SaveExcel(listText, 1, 1, saveFileDialog1.FileName); break; } } } else { MessageBox.Show("No data available!"); } }
private void Btn_RemoveBackground_Click(object sender, EventArgs e) { if (output_local.Text == "") { MessageBox.Show("Select a output folder, images with the same name will be overwrited"); return; } TranslationTools.show_MSG(label12, "Please wait...", Color.FromArgb(150, 255, 10, 10), 1); foreach (ListViewItem item in list_RemBg.Items) //percorre todos os ficheiros { try { //MessageBox.Show(item.SubItems[0].Text + "\n" + item.SubItems[1].Text); String result = Path.GetFileNameWithoutExtension(item.SubItems[0].Text); RemoveImageBackground(item.SubItems[0].Text, this.output_local.Text, result + ".png"); } catch (Exception ex) { MessageBox.Show("Error: " + ex.Message); } } list_RemBg.Clear(); }
private void button2_Click(object sender, EventArgs e) { //delete button int id = TranslationTools.GetId(deleteBox); if (id == 13) { MessageBox.Show(deleteBox.Text + " can't be deleted"); return; } try { using (SqlConnection myConnection = new SqlConnection(CONNECTION_STRING)) { //string sql = "select * from BackgroundColors where IDColor=" + TranslationTools.GetId(UpdateBox); string sql = "DELETE FROM BackgroundColors WHERE IDColor=" + id; //MessageBox.Show(sql); //return; using (SqlCommand cmd = new SqlCommand(sql, myConnection)) { myConnection.Open(); SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection); //DataTable dt = new DataTable(); //dt.Load(dr); myConnection.Close(); //reloads the ComboBoxes count = 0; TranslationTools.FillDropDownList("Select * From BackgroundColors Order by IDColor", deleteBox); TranslationTools.FillDropDownList("Select * From BackgroundColors Order by IDColor", UpdateBox); } } }catch { return; } MessageBox.Show("Element sucessefully eliminated!"); }
private void button3_Click(object sender, EventArgs e) { TranslationTools.show_MSG(label1, "Please wait...", Color.FromArgb(150, 255, 10, 10), 1); TranslateAll(listText); }
private void Btn_SelectImages_Click(object sender, EventArgs e) { TranslationTools.FillList(list_RemBg, RemBgSelectImages); }
private void ColorsManagementDialog_Load(object sender, EventArgs e) { //throw new NotImplementedException(); TranslationTools.FillDropDownList("Select * From BackgroundColors Order by IDColor", deleteBox); TranslationTools.FillDropDownList("Select * From BackgroundColors Order by IDColor", UpdateBox); }
public RemoveBackground() { InitializeComponent(); TranslationTools.FillDropDownList("SELECT IDColor, Name FROM BackgroundColors Order by IDColor", comboColors); }
private void pictureBox3_Click(object sender, EventArgs e) { TranslationTools.FillDropDownSessions("SELECT DISTINCT NameSession from Session;", comboSession); }
private void button5_Click(object sender, EventArgs e) { TranslationTools.CleanListView(listView1); }
private void Btn_SelectImages(object sender, EventArgs e) { TranslationTools.FillList(listView1, openFileDialog1); }