Fixed execution

This commit is contained in:
CreepyCrafter24 2019-11-29 23:17:46 +01:00
parent 6a19967c46
commit 28a7898071
3 changed files with 64 additions and 36 deletions

View File

@ -132,6 +132,7 @@
this.nightmodehide = new MetroFramework.Controls.MetroPanel();
this.pythonOpenFileDialog = new System.Windows.Forms.OpenFileDialog();
this.pythonSaveFileDialog = new System.Windows.Forms.SaveFileDialog();
this.buttonFix = new System.Windows.Forms.Timer(this.components);
this.languageTabControl.SuspendLayout();
this.cstab.SuspendLayout();
this.csediterrorpanel.SuspendLayout();
@ -156,7 +157,7 @@
this.languageTabControl.Controls.Add(this.infotab);
this.languageTabControl.Location = new System.Drawing.Point(23, 63);
this.languageTabControl.Name = "languageTabControl";
this.languageTabControl.SelectedIndex = 0;
this.languageTabControl.SelectedIndex = 2;
this.languageTabControl.Size = new System.Drawing.Size(797, 433);
this.languageTabControl.TabIndex = 0;
this.languageTabControl.UseSelectable = true;
@ -258,22 +259,23 @@
this.csediterrors.Text = "Ready";
this.csediterrors.Click += new System.EventHandler(this.metroLabel2_Click);
//
// cseditcode
// cseditCode
//
this.cseditCode.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.cseditCode.BackColor = System.Drawing.Color.White;
this.cseditCode.ConvertTabsToSpaces = true;
this.cseditCode.Highlighting = null;
this.cseditCode.IsIconBarVisible = true;
this.cseditCode.LineViewerStyle = ICSharpCode.TextEditor.Document.LineViewerStyle.FullRow;
this.cseditCode.Location = new System.Drawing.Point(6, 47);
this.cseditCode.Name = "cseditcode";
this.cseditCode.Name = "cseditCode";
this.cseditCode.RightToLeft = System.Windows.Forms.RightToLeft.No;
this.cseditCode.Size = new System.Drawing.Size(780, 291);
this.cseditCode.TabIndex = 9;
this.cseditCode.TabStop = false;
this.cseditCode.Text = resources.GetString("cseditcode.Text");
this.cseditCode.Text = resources.GetString("cseditCode.Text");
//
// htmltab
//
@ -486,7 +488,7 @@
this.pythonCode.Name = "pythonCode";
this.pythonCode.Size = new System.Drawing.Size(783, 341);
this.pythonCode.TabIndex = 11;
this.pythonCode.Text = "print(\"Hello world!\")";
this.pythonCode.Text = "import time\r\nprint(\"Hello world!\")\r\ntime.sleep(1)";
//
// pythonSave
//
@ -1124,6 +1126,11 @@
//
this.pythonSaveFileDialog.Filter = "Python Files|*.py";
//
// buttonFix
//
this.buttonFix.Enabled = true;
this.buttonFix.Tick += new System.EventHandler(this.buttonFix_Tick);
//
// MainForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@ -1261,6 +1268,7 @@
private ICSharpCode.TextEditor.TextEditorControl cseditCode;
private ICSharpCode.TextEditor.TextEditorControl htmlText;
private ICSharpCode.TextEditor.TextEditorControl pythonCode;
private System.Windows.Forms.Timer buttonFix;
}
}

View File

@ -21,6 +21,7 @@ using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using ThreadState = System.Threading.ThreadState;
#pragma warning disable IDE1006
@ -29,7 +30,7 @@ namespace cashew
public partial class MainForm : MetroForm
{
#region General
ThreadState[] runningStates = new ThreadState[] { ThreadState.Background, ThreadState.Running, ThreadState.StopRequested, ThreadState.WaitSleepJoin };
private IMetroControl[] metroControls;
private Control[] normalControls;
private ToolStripMenuItem[] menuItems;
@ -108,11 +109,17 @@ namespace cashew
Refresh();
}
private void buttonFix_Tick(object sender, EventArgs e)
{
pythonRun.Text = pythonScript != null && runningStates.Contains(pythonScript.ThreadState) ? "Stop" : "Run";
cseditrun.Text = csScript != null && runningStates.Contains(csScript.ThreadState) ? "Stop" : "Run";
}
#endregion General
#region CS
Thread script;
Thread csScript;
private void metroLabel2_Click(object sender, EventArgs e) => MetroMessageBox.Show(this, csediterrors.Text, "Errors", MessageBoxButtons.OK, MessageBoxIcon.Error);
private void metroPanel1_Click(object sender, EventArgs e) => MetroMessageBox.Show(this, csediterrors.Text, "Errors", MessageBoxButtons.OK, MessageBoxIcon.Error);
@ -177,9 +184,9 @@ namespace cashew
private void cseditrun_Click(object sender, EventArgs e)
{
if ((script != null) && script.ThreadState == System.Threading.ThreadState.Running)
if ((csScript != null) && runningStates.Contains(csScript.ThreadState))
{
script.Abort();
csScript.Abort();
}
else
{
@ -204,21 +211,22 @@ namespace cashew
if (results.Errors.HasErrors)
throw new InvalidOperationException(string.Join("\r\n\r\n", results.Errors.OfType<CompilerError>().Select(s => "Error in line " + s.Line.ToString() + ": " + s.ErrorNumber + " - " + s.ErrorText).ToArray()));
cseditrun.Text = "Stop";
script = new Thread(() =>
csScript = new Thread(() =>
{
try
{
_ = results.CompiledAssembly.EntryPoint.Invoke(null, null);
}
finally
catch (Exception e1)
{
Invoke((MethodInvoker)delegate ()
{
cseditrun.Text = "Run";
});
if (!e1.tryCast(out ThreadAbortException ex))
Invoke((MethodInvoker)delegate ()
{
MetroMessageBox.Show(this, e1.Message, "Execution Failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
});
}
});
script.Start();
csScript.Start();
csediterrors.Text = "Ready";
}
catch (Exception e1)
@ -226,7 +234,7 @@ namespace cashew
csediterrors.Text = e1.Message;
}
}
cseditrun.Text = script.ThreadState == System.Threading.ThreadState.Running ? "Stop" : "Run";
cseditrun.Text = csScript.ThreadState == System.Threading.ThreadState.Running ? "Stop" : "Run";
}
private void cseditopen_Click(object sender, EventArgs e)
@ -491,7 +499,7 @@ namespace cashew
#endregion HTML
#region Python
Thread pythonScript;
private void pythonOpen_Click(object sender, EventArgs e)
{
if (pythonOpenFileDialog.ShowDialog() == DialogResult.OK)
@ -524,21 +532,30 @@ namespace cashew
private void pythonRun_Click(object sender, EventArgs e)
{
new Thread(() =>
if ((pythonScript != null) && runningStates.Contains(pythonScript.ThreadState))
{
ScriptEngine engine = Python.CreateEngine();
try
pythonScript.Abort();
}
else
{
pythonScript = new Thread(() =>
{
engine.Execute(pythonCode.Text);
}
catch (Exception e1)
{
Invoke((MethodInvoker)delegate ()
ScriptEngine engine = Python.CreateEngine();
try
{
MetroMessageBox.Show(this, e1.Message, "Execution Failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
});
}
}).Start();
engine.Execute(pythonCode.Text);
}
catch (Exception e1)
{
if (!e1.tryCast(out ThreadAbortException ex))
Invoke((MethodInvoker)delegate ()
{
MetroMessageBox.Show(this, e1.Message, "Execution Failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
});
}
});
pythonScript.Start();
}
}
#endregion Python

View File

@ -117,7 +117,7 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="cseditcode.Text" xml:space="preserve">
<data name="cseditCode.Text" xml:space="preserve">
<value>using System;
using System.Windows.Forms;
@ -147,19 +147,22 @@ IF YOU WANT A PROFESSIONAL PROGRAM, DON'T USE THIS!</value>
<value>153, 17</value>
</metadata>
<metadata name="htmlOptionsMenu.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>423, 17</value>
<value>299, 17</value>
</metadata>
<metadata name="htmlSaveFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>574, 17</value>
<value>450, 17</value>
</metadata>
<metadata name="htmlOpenFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>730, 17</value>
<value>606, 17</value>
</metadata>
<metadata name="pythonOpenFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>890, 17</value>
<value>766, 17</value>
</metadata>
<metadata name="pythonSaveFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>1064, 17</value>
<value>940, 17</value>
</metadata>
<metadata name="buttonFix.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>1109, 17</value>
</metadata>
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">