Skip to content

Commit

Permalink
Shows the installation process on pip
Browse files Browse the repository at this point in the history
Fix missing dotenv package
Fix incorrect display of richTextBox (1->2)
Fix project being opened without installing necessary packages
  • Loading branch information
EndermanPC committed Jul 8, 2024
1 parent 4b53c44 commit 8562805
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 45 deletions.
22 changes: 7 additions & 15 deletions Create.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ private async void button1_Click(object sender, EventArgs e)

try
{
PythonSetup();
await PythonSetup();
}
catch (Exception ex)
{
Expand All @@ -67,7 +67,7 @@ private async void button1_Click(object sender, EventArgs e)
}
}

private async void PythonSetup()
private async Task PythonSetup()
{
await InstallPackageDependencies(comboBox2.Text);
}
Expand Down Expand Up @@ -132,21 +132,13 @@ private async Task InstallPackageDependencies(string language)
await UpdateProgressBarAsync(35);

ProcessStartInfo start = new ProcessStartInfo();
start.FileName = $"projects\\{textBox1.Text}\\python\\Scripts\\pip.exe";
start.Arguments = "install " + string.Join(" ", packageRequirements);
start.UseShellExecute = false;
start.RedirectStandardOutput = true;
start.FileName = $"projects\\{textBox1.Text}\\python\\Scripts\\python.exe";
start.Arguments = "-m pip install python-dotenv " + string.Join(" ", packageRequirements);
start.UseShellExecute = true;
start.RedirectStandardOutput = false;

await UpdateProgressBarAsync(40);

using (Process process = Process.Start(start))
{
using (StreamReader reader = process.StandardOutput)
{
string result = reader.ReadToEnd();
Console.Write(result);
}
}
Process process = Process.Start(start);

await UpdateProgressBarAsync(50);
}
Expand Down
70 changes: 42 additions & 28 deletions Python.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,46 +101,60 @@ private void AppendText(string text)
}
else
{
richTextBox1.AppendText(text);
richTextBox2.AppendText(text);
}
}

private void button3_Click(object sender, EventArgs e)
private async void button3_Click(object sender, EventArgs e)
{
button3.Enabled = false;
try
{
progressBar2.Value = 0;
ProcessStartInfo start = new ProcessStartInfo();
start.FileName = $"projects\\{projectName}\\python\\Scripts\\python.exe";
start.Arguments = $"projects\\{projectName}\\trainer.py";
start.UseShellExecute = false;
start.RedirectStandardOutput = true;
start.RedirectStandardError = true;
start.CreateNoWindow = true;

ProcessStartInfo start = new ProcessStartInfo
{
FileName = $"projects\\{projectName}\\python\\Scripts\\python.exe",
Arguments = $"projects\\{projectName}\\trainer.py",
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true,
CreateNoWindow = true
};

progressBar2.Value = 30;
Process process = new Process();
process.StartInfo = start;
process.OutputDataReceived += new DataReceivedEventHandler((sender, e) =>

using (Process process = new Process())
{
if (!string.IsNullOrEmpty(e.Data))
process.StartInfo = start;

process.OutputDataReceived += (sender, e) =>
{
AppendText(e.Data + Environment.NewLine);
}
});
process.ErrorDataReceived += new DataReceivedEventHandler((sender, e) =>
{
if (!string.IsNullOrEmpty(e.Data))
if (!string.IsNullOrEmpty(e.Data))
{
this.Invoke((Action)(() => AppendText(e.Data + Environment.NewLine)));
}
};

process.ErrorDataReceived += (sender, e) =>
{
if (!string.IsNullOrEmpty(e.Data))
{
this.Invoke((Action)(() => AppendText("ERROR: " + e.Data + Environment.NewLine)));
}
};

await Task.Run(() =>
{
AppendText("ERROR: " + e.Data + Environment.NewLine);
}
});

process.Start();
process.BeginOutputReadLine();
process.BeginErrorReadLine();
process.WaitForExit();
progressBar2.Value = 100;
process.Start();
process.BeginOutputReadLine();
process.BeginErrorReadLine();
process.WaitForExit();
});

progressBar2.Value = 100;
}

}
catch (Exception ex)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
[assembly: System.Reflection.AssemblyCompanyAttribute("Lithicsoft Trainer Studio")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+4b53c44cdd402e0cd2955ebed05599f3988fc34e")]
[assembly: System.Reflection.AssemblyProductAttribute("Lithicsoft Trainer Studio")]
[assembly: System.Reflection.AssemblyTitleAttribute("Lithicsoft Trainer Studio")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
06e93a66eb7a31d9d787f22f9b75137b6785d6cdbdc5386f9b00409d9bc7a9f5
db032ac3aa1a6f6390f5d57811a8d4160a9a54be789895012f815c01332c81c5

0 comments on commit 8562805

Please sign in to comment.