Improve progress reporting for OCR

This commit is contained in:
Ben Olden-Cooligan 2018-09-19 15:33:30 -04:00
parent 5f1263fe89
commit 6e7426742f
10 changed files with 100 additions and 57 deletions

View File

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using NAPS2.Operation;
namespace NAPS2.Automation
@ -23,6 +24,8 @@ namespace NAPS2.Automation
public void ShowBackgroundProgress(IOperation op) {
}
public void RenderStatus(IOperation op, Label textLabel, Label numberLabel, ProgressBar progressBar) => throw new InvalidOperationException();
public List<IOperation> ActiveOperations => throw new InvalidOperationException();
}
}

View File

@ -284,7 +284,6 @@ namespace NAPS2.Ocr
}
op = currentOp;
op.Status.MaxProgress += 1;
op.Status.StatusText = $"{op.Status.CurrentProgress} / {op.Status.MaxProgress}";
}
op.InvokeStatusChanged();
if (started)
@ -302,7 +301,6 @@ namespace NAPS2.Ocr
{
op = currentOp;
currentOp.Status.CurrentProgress += 1;
op.Status.StatusText = $"{op.Status.CurrentProgress} / {op.Status.MaxProgress}";
if (currentOp.Status.CurrentProgress == currentOp.Status.MaxProgress)
{
currentOp = null;

View File

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
namespace NAPS2.Operation
{
@ -19,6 +20,8 @@ namespace NAPS2.Operation
void ShowBackgroundProgress(IOperation op);
void RenderStatus(IOperation op, Label textLabel, Label numberLabel, ProgressBar progressBar);
List<IOperation> ActiveOperations { get; }
}
}

View File

@ -7,6 +7,7 @@ namespace NAPS2.Operation
public enum OperationProgressType
{
Default,
None,
MB
}
}

View File

@ -11,14 +11,16 @@ namespace NAPS2.WinForms
public partial class FProgress : FormBase
{
private readonly IErrorOutput errorOutput;
private readonly IOperationProgress operationProgress;
private volatile bool loaded;
private volatile bool background;
private IOperation operation;
public FProgress(IErrorOutput errorOutput)
public FProgress(IErrorOutput errorOutput, IOperationProgress operationProgress)
{
this.errorOutput = errorOutput;
this.operationProgress = operationProgress;
InitializeComponent();
RestoreFormState = false;
@ -77,35 +79,7 @@ namespace NAPS2.WinForms
private void DisplayProgress()
{
var status = Operation.Status ?? new OperationStatus();
labelStatus.Text = status.StatusText;
if (status.MaxProgress == 1 || status.IndeterminateProgress)
{
labelNumber.Text = "";
progressBar.Style = ProgressBarStyle.Marquee;
}
else if (status.MaxProgress == 0)
{
labelNumber.Text = "";
progressBar.Style = ProgressBarStyle.Continuous;
progressBar.Maximum = 1;
progressBar.Value = 0;
}
else
{
labelNumber.Text = status.ProgressType == OperationProgressType.MB
? string.Format(MiscResources.SizeProgress, (status.CurrentProgress / 1000000.0).ToString("f1"), (status.MaxProgress / 1000000.0).ToString("f1"))
: string.Format(MiscResources.ProgressFormat, status.CurrentProgress, status.MaxProgress);
progressBar.Style = ProgressBarStyle.Continuous;
progressBar.Maximum = status.MaxProgress;
progressBar.Value = status.CurrentProgress;
}
// Force the progress bar to render immediately
if (progressBar.Value < progressBar.Maximum)
{
progressBar.Value += 1;
progressBar.Value -= 1;
}
operationProgress.RenderStatus(Operation, labelStatus, labelNumber, progressBar);
}
private void btnCancel_Click(object sender, EventArgs e)

View File

@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
using NAPS2.Config;
using NAPS2.Operation;
using NAPS2.Update;
@ -88,6 +89,7 @@ namespace NAPS2.WinForms
int slot = FillNextSlot(n);
n.Location = GetPosition(n, slot);
n.Resize += parentForm_Resize;
n.BringToFront();
n.HideNotify += (sender, args) => ClearSlot(n);
n.ShowNotify();

View File

@ -34,6 +34,7 @@
this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components);
this.cancelToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.progressBar = new System.Windows.Forms.ProgressBar();
this.lblNumber = new System.Windows.Forms.Label();
this.contextMenuStrip1.SuspendLayout();
this.SuspendLayout();
//
@ -64,6 +65,11 @@
this.progressBar.Style = System.Windows.Forms.ProgressBarStyle.Continuous;
this.progressBar.MouseClick += new System.Windows.Forms.MouseEventHandler(this.OperationProgressNotifyWidget_Click);
//
// lblNumber
//
resources.ApplyResources(this.lblNumber, "lblNumber");
this.lblNumber.Name = "lblNumber";
//
// OperationProgressNotifyWidget
//
resources.ApplyResources(this, "$this");
@ -71,6 +77,7 @@
this.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(234)))), ((int)(((byte)(234)))), ((int)(((byte)(234)))));
this.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.ContextMenuStrip = this.contextMenuStrip1;
this.Controls.Add(this.lblNumber);
this.Controls.Add(this.progressBar);
this.Controls.Add(this.lblTitle);
this.Name = "OperationProgressNotifyWidget";
@ -87,5 +94,6 @@
private System.Windows.Forms.ContextMenuStrip contextMenuStrip1;
private System.Windows.Forms.ToolStripMenuItem cancelToolStripMenuItem;
private System.Windows.Forms.ProgressBar progressBar;
private System.Windows.Forms.Label lblNumber;
}
}

View File

@ -29,31 +29,17 @@ namespace NAPS2.WinForms
private void DisplayProgress()
{
var status = op.Status ?? new OperationStatus();
lblTitle.Text = status.StatusText;
if (status.MaxProgress == 1 || status.IndeterminateProgress)
var lblNumberRight = lblNumber.Right;
operationProgress.RenderStatus(op, lblTitle, lblNumber, progressBar);
if (op.Status?.IndeterminateProgress != true)
{
progressBar.Style = ProgressBarStyle.Marquee;
// Don't display the number if the progress bar is precise
// Otherwise, the widget will be too cluttered
// The number is only shown for OcrOperation at the moment
lblNumber.Text = "";
}
else if (status.MaxProgress == 0)
{
progressBar.Style = ProgressBarStyle.Continuous;
progressBar.Maximum = 1;
progressBar.Value = 0;
}
else
{
progressBar.Style = ProgressBarStyle.Continuous;
progressBar.Maximum = status.MaxProgress;
progressBar.Value = status.CurrentProgress;
}
// Force the progress bar to render immediately
if (progressBar.Value < progressBar.Maximum)
{
progressBar.Value += 1;
progressBar.Value -= 1;
}
Width = Math.Max(Width, lblTitle.Width + 22);
lblNumber.Left = lblNumberRight - lblNumber.Width;
Width = Math.Max(Width, lblTitle.Width + lblNumber.Width + 22);
Height = Math.Max(Height, lblTitle.Height + 35);
}

View File

@ -148,7 +148,7 @@
<value>$this</value>
</data>
<data name="&gt;&gt;lblTitle.ZOrder" xml:space="preserve">
<value>2</value>
<value>3</value>
</data>
<metadata name="contextMenuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>123, 17</value>
@ -168,6 +168,9 @@
<data name="&gt;&gt;contextMenuStrip1.Type" xml:space="preserve">
<value>System.Windows.Forms.ContextMenuStrip, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="progressBar.Anchor" type="System.Windows.Forms.AnchorStyles, System.Windows.Forms">
<value>Bottom, Left, Right</value>
</data>
<data name="progressBar.Location" type="System.Drawing.Point, System.Drawing">
<value>7, 26</value>
</data>
@ -187,6 +190,36 @@
<value>$this</value>
</data>
<data name="&gt;&gt;progressBar.ZOrder" xml:space="preserve">
<value>2</value>
</data>
<data name="lblNumber.Anchor" type="System.Windows.Forms.AnchorStyles, System.Windows.Forms">
<value>Top, Right</value>
</data>
<data name="lblNumber.AutoSize" type="System.Boolean, mscorlib">
<value>True</value>
</data>
<data name="lblNumber.Location" type="System.Drawing.Point, System.Drawing">
<value>145, 8</value>
</data>
<data name="lblNumber.Size" type="System.Drawing.Size, System.Drawing">
<value>0, 13</value>
</data>
<data name="lblNumber.TabIndex" type="System.Int32, mscorlib">
<value>4</value>
</data>
<data name="lblNumber.TextAlign" type="System.Drawing.ContentAlignment, System.Drawing">
<value>TopRight</value>
</data>
<data name="&gt;&gt;lblNumber.Name" xml:space="preserve">
<value>lblNumber</value>
</data>
<data name="&gt;&gt;lblNumber.Type" xml:space="preserve">
<value>System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="&gt;&gt;lblNumber.Parent" xml:space="preserve">
<value>$this</value>
</data>
<data name="&gt;&gt;lblNumber.ZOrder" xml:space="preserve">
<value>0</value>
</data>
<metadata name="$this.Localizable" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
@ -208,6 +241,6 @@
<value>OperationProgressNotifyWidget</value>
</data>
<data name="&gt;&gt;$this.Type" xml:space="preserve">
<value>NAPS2.WinForms.NotifyWidgetBase, NAPS2.Core, Version=5.8.2.29512, Culture=neutral, PublicKeyToken=null</value>
<value>NAPS2.WinForms.NotifyWidgetBase, NAPS2.Core, Version=6.0.1.27018, Culture=neutral, PublicKeyToken=null</value>
</data>
</root>

View File

@ -2,7 +2,9 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Windows.Forms;
using NAPS2.Config;
using NAPS2.Lang.Resources;
using NAPS2.Operation;
namespace NAPS2.WinForms
@ -80,6 +82,39 @@ namespace NAPS2.WinForms
}
}
public void RenderStatus(IOperation op, Label textLabel, Label numberLabel, ProgressBar progressBar)
{
var status = op.Status ?? new OperationStatus();
textLabel.Text = status.StatusText;
progressBar.Style = status.MaxProgress == 1 || status.IndeterminateProgress
? ProgressBarStyle.Marquee
: ProgressBarStyle.Continuous;
if (status.MaxProgress == 1 || status.ProgressType == OperationProgressType.None)
{
numberLabel.Text = "";
}
else if (status.MaxProgress == 0)
{
numberLabel.Text = "";
progressBar.Maximum = 1;
progressBar.Value = 0;
}
else
{
numberLabel.Text = status.ProgressType == OperationProgressType.MB
? string.Format(MiscResources.SizeProgress, (status.CurrentProgress / 1000000.0).ToString("f1"), (status.MaxProgress / 1000000.0).ToString("f1"))
: string.Format(MiscResources.ProgressFormat, status.CurrentProgress, status.MaxProgress);
progressBar.Maximum = status.MaxProgress;
progressBar.Value = status.CurrentProgress;
}
// Force the progress bar to render immediately
if (progressBar.Value < progressBar.Maximum)
{
progressBar.Value += 1;
progressBar.Value -= 1;
}
}
public List<IOperation> ActiveOperations
{
get