Skip to content

Commit

Permalink
Allow enabling and disabling workflow watch
Browse files Browse the repository at this point in the history
  • Loading branch information
glopesdev committed Sep 3, 2024
1 parent 328eaaa commit 57f9cb7
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 10 deletions.
25 changes: 23 additions & 2 deletions Bonsai.Editor/EditorForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 13 additions & 1 deletion Bonsai.Editor/EditorForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1187,6 +1187,7 @@ IDisposable ShutdownSequence()
groupToolStripMenuItem.Enabled = true;
cutToolStripMenuItem.Enabled = true;
pasteToolStripMenuItem.Enabled = true;
watchToolStripMenuItem.Enabled = true;
startToolStripSplitButton.Enabled = startToolStripMenuItem.Enabled = startWithoutDebuggingToolStripMenuItem.Enabled = true;
stopToolStripButton.Visible = stopToolStripMenuItem.Visible = stopToolStripButton.Enabled = stopToolStripMenuItem.Enabled = false;
restartToolStripButton.Visible = restartToolStripMenuItem.Visible = restartToolStripButton.Enabled = restartToolStripMenuItem.Enabled = false;
Expand Down Expand Up @@ -1226,7 +1227,8 @@ void StartWorkflow(bool debug)
var runtimeWorkflow = workflowBuilder.Workflow.BuildObservable();
Invoke((Action)(() =>
{
if (debug) workflowWatch.Start(workflowBuilder.Workflow);
if (watchToolStripMenuItem.Checked)
workflowWatch.Start(workflowBuilder.Workflow);
statusTextLabel.Text = Resources.RunningStatus;
statusImageLabel.Image = statusRunningImage;
editorSite.OnWorkflowStarted(EventArgs.Empty);
Expand Down Expand Up @@ -1259,6 +1261,7 @@ void StartWorkflow(bool debug)
groupToolStripMenuItem.Enabled = false;
cutToolStripMenuItem.Enabled = false;
pasteToolStripMenuItem.Enabled = false;
watchToolStripMenuItem.Enabled = false;
startToolStripSplitButton.Enabled = startToolStripMenuItem.Enabled = startWithoutDebuggingToolStripMenuItem.Enabled = false;
stopToolStripButton.Visible = stopToolStripMenuItem.Visible = stopToolStripButton.Enabled = stopToolStripMenuItem.Enabled = true;
restartToolStripButton.Visible = restartToolStripMenuItem.Visible = restartToolStripButton.Enabled = restartToolStripMenuItem.Enabled = true;
Expand Down Expand Up @@ -2214,6 +2217,15 @@ private void disableToolStripMenuItem_Click(object sender, EventArgs e)

#endregion

#region Watch

private void watchToolStripMenuItem_Click(object sender, EventArgs e)
{
workflowWatch.Enabled = watchToolStripMenuItem.Checked;
}

#endregion

#region Undo/Redo

private void commandExecutor_StatusChanged(object sender, EventArgs e)
Expand Down
12 changes: 6 additions & 6 deletions Bonsai.Editor/GraphView/WorkflowGraphView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,12 @@ private void WorkflowWatch_Tick(object sender, EventArgs e)
if (node.Value is null)
continue;

if (workflowWatch.Counters?.TryGetValue(node.Value, out var counter) is true)
if (!workflowWatch.Enabled)
{
node.Status = null;
node.NotifyingCounter = -1;
}
else if (workflowWatch.Counters?.TryGetValue(node.Value, out var counter) is true)
{
node.Status = counter.GetStatus();
if (node.Status == WorkflowElementStatus.Notifying)
Expand All @@ -117,11 +122,6 @@ private void WorkflowWatch_Tick(object sender, EventArgs e)
node.NotifyingCounter = -1;
}
}
else
{
node.Status = null;
node.NotifyingCounter = -1;
}
}
}
}
Expand Down
10 changes: 10 additions & 0 deletions Bonsai.Editor/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions Bonsai.Editor/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -341,4 +341,14 @@ NOTE: You will have to restart Bonsai for any changes to take effect.</value>
<data name="Editor_HelpLabel" xml:space="preserve">
<value>Help</value>
</data>
<data name="WatchMenuImage" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6
JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAACXBIWXMAAA7CAAAOwgEVKEqAAAAAv0lE
QVQ4T2MYRkBRUTEJiPeDMFQIBcDkQOqgQgggIyMjpKCgsElKSkoYKoQV4FQnLy+fBcJQLl6AoZZY22EA
Qz0ptsMAih6gaY+AAfMfC34AkgfRaOJgDNIHNgDI+SsnJyeJjpEV45D/BzYAaNILoHMMkCWB/ACg+FWo
BRdAfGR5ZWVlI6D4c5gB24A4HlkBkL8aqKkAakAOiI8sD5RLBIptgRmQB3ImMgaKvQKFNkgeqEEQxMei
Jg9swFAHDAwAKi9WPOw18+QAAAAASUVORK5CYII=
</value>
</data>
</root>
14 changes: 13 additions & 1 deletion Bonsai.Editor/WorkflowWatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,22 @@ internal class WorkflowWatch
const int WatchPeriod = 100;
readonly Timer watchTimer = new() { Interval = WatchPeriod };
WorkflowMeter workflowMeter;
bool enabled;

public WorkflowWatch()
{
watchTimer.Tick += (_, e) => OnUpdate(e);
enabled = true;
}

public bool Enabled
{
get => enabled;
set
{
enabled = value;
OnUpdate(EventArgs.Empty);
}
}

public event EventHandler Update;
Expand Down Expand Up @@ -45,10 +57,10 @@ public void Stop()
watchTimer.Stop();
if (workflowMeter is not null)
{
OnUpdate(EventArgs.Empty);
workflowMeter.Dispose();
workflowMeter = null;
}
OnUpdate(EventArgs.Empty);
}
}
}

0 comments on commit 57f9cb7

Please sign in to comment.