mirror of
https://github.com/cyanfish/naps2.git
synced 2024-08-16 18:50:45 +03:00
OCR setup form WIP
This commit is contained in:
parent
895ff04ef7
commit
880f51be75
@ -51,14 +51,14 @@ public class DesktopSubFormController : IDesktopSubFormController
|
||||
{
|
||||
if (_tesseractLanguageManager.InstalledLanguages.Any())
|
||||
{
|
||||
_formFactory.Create<FOcrSetup>().ShowDialog();
|
||||
_formFactory.Create<OcrSetupForm>().ShowModal();
|
||||
}
|
||||
else
|
||||
{
|
||||
_formFactory.Create<FOcrLanguageDownload>().ShowDialog();
|
||||
if (_tesseractLanguageManager.InstalledLanguages.Any())
|
||||
{
|
||||
_formFactory.Create<FOcrSetup>().ShowDialog();
|
||||
_formFactory.Create<OcrSetupForm>().ShowModal();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -15,16 +15,39 @@ public static class C
|
||||
public static Label NoWrap(string text) =>
|
||||
new Label { Text = text, Wrap = WrapMode.None };
|
||||
|
||||
/// <summary>
|
||||
/// Creates a link button with the given URL as both text and click action.
|
||||
/// </summary>
|
||||
/// <param name="url"></param>
|
||||
/// <returns></returns>
|
||||
public static LinkButton UrlLink(string url)
|
||||
{
|
||||
void OnClick() => Process.Start(new ProcessStartInfo(url) { UseShellExecute = true });
|
||||
return new LinkButton
|
||||
{
|
||||
Text = url,
|
||||
Command = new ActionCommand(OnClick)
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a link button with the specified text.
|
||||
/// </summary>
|
||||
/// <param name="text"></param>
|
||||
/// <returns></returns>
|
||||
public static LinkButton Link(string text)
|
||||
{
|
||||
return new LinkButton { Text = text };
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a link button with the specified text and action.
|
||||
/// If the action is not specified, it will assume the text is a URL to be opened.
|
||||
/// </summary>
|
||||
/// <param name="text"></param>
|
||||
/// <param name="onClick"></param>
|
||||
/// <returns></returns>
|
||||
public static LinkButton Link(string text, Action? onClick = null)
|
||||
public static LinkButton Link(string text, Action onClick)
|
||||
{
|
||||
onClick ??= () => Process.Start(text);
|
||||
return new LinkButton
|
||||
{
|
||||
Text = text,
|
||||
@ -32,6 +55,13 @@ public static class C
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a button with the specified text.
|
||||
/// </summary>
|
||||
/// <param name="text"></param>
|
||||
/// <returns></returns>
|
||||
public static Button Button(string text) => new() { Text = text };
|
||||
|
||||
/// <summary>
|
||||
/// Creates a button with the specified text and action.
|
||||
/// </summary>
|
||||
@ -82,6 +112,13 @@ public static class C
|
||||
public static ControlWithLayoutAttributes Filler() =>
|
||||
new ControlWithLayoutAttributes(null).XScale().YScale();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a null placeholder for Eto layouts.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static ControlWithLayoutAttributes Spacer() =>
|
||||
new ControlWithLayoutAttributes(null);
|
||||
|
||||
/// <summary>
|
||||
/// Creates an label of default height to be used as a visual paragraph separator.
|
||||
/// </summary>
|
||||
@ -90,7 +127,7 @@ public static class C
|
||||
|
||||
/// <summary>
|
||||
/// Creates a hacky image button that supports accessible interaction.
|
||||
///
|
||||
///
|
||||
/// It works by overlaying an image on top a button.
|
||||
/// If the image has transparency an offset may need to be specified to keep the button hidden.
|
||||
/// If the text is too large relative to the button it will be impossible to hide fully.
|
||||
@ -119,12 +156,20 @@ public static class C
|
||||
return pix;
|
||||
}
|
||||
|
||||
public static Label Label(string text)
|
||||
public static Label Label(string text) => new() { Text = text };
|
||||
|
||||
public static DropDown EnumDropDown<T>(params T[] values) where T : Enum
|
||||
{
|
||||
return new Label
|
||||
var combo = new DropDown();
|
||||
foreach (var item in values)
|
||||
{
|
||||
Text = text
|
||||
};
|
||||
combo.Items.Add(new ListItem
|
||||
{
|
||||
Key = item.ToString(),
|
||||
Text = item.Description()
|
||||
});
|
||||
}
|
||||
return combo;
|
||||
}
|
||||
|
||||
public static DropDown EnumDropDown<T>() where T : Enum
|
||||
@ -145,4 +190,6 @@ public static class C
|
||||
}
|
||||
return combo;
|
||||
}
|
||||
|
||||
public static CheckBox CheckBox(string text) => new() { Text = text };
|
||||
}
|
@ -50,7 +50,7 @@ public class ControlWithLayoutAttributes : LayoutElement
|
||||
bounds.Size = UpdateFixedDimensions(context, bounds.Size);
|
||||
if (Control != null)
|
||||
{
|
||||
var location = new PointF(bounds.X + Padding.Left, bounds.Y + Padding.Right);
|
||||
var location = new PointF(bounds.X + Padding.Left, bounds.Y + Padding.Top);
|
||||
var size = new SizeF(bounds.Width - Padding.Horizontal, bounds.Height - Padding.Vertical);
|
||||
size = SizeF.Max(SizeF.Empty, size);
|
||||
EnsureIsAdded(context);
|
||||
|
44
NAPS2.Lib/EtoForms/Ui/OcrSetupForm.cs
Normal file
44
NAPS2.Lib/EtoForms/Ui/OcrSetupForm.cs
Normal file
@ -0,0 +1,44 @@
|
||||
using Eto.Drawing;
|
||||
using Eto.Forms;
|
||||
using NAPS2.EtoForms.Layout;
|
||||
using NAPS2.Ocr;
|
||||
|
||||
namespace NAPS2.EtoForms.Ui;
|
||||
|
||||
public class OcrSetupForm : EtoDialogBase
|
||||
{
|
||||
private readonly CheckBox _enableOcr = C.CheckBox(UiStrings.MakePdfsSearchable);
|
||||
private readonly DropDown _ocrLang = new();
|
||||
private readonly DropDown _ocrMode = C.EnumDropDown(LocalizedOcrMode.Fast, LocalizedOcrMode.Best);
|
||||
private readonly CheckBox _ocrAfterScanning = C.CheckBox(UiStrings.RunOcrAfterScanning);
|
||||
private readonly LinkButton _moreLanguages = C.Link(UiStrings.GetMoreLanguages);
|
||||
private readonly Button _ok = C.Button(UiStrings.OK);
|
||||
private readonly Button _cancel = C.Button(UiStrings.Cancel);
|
||||
|
||||
public OcrSetupForm(Naps2Config config) : base(config)
|
||||
{
|
||||
Title = UiStrings.OcrSetupFormTitle;
|
||||
Icon = new Icon(1f, Icons.text_small.ToEtoImage());
|
||||
Resizable = false;
|
||||
|
||||
LayoutController.Content = L.Column(
|
||||
_enableOcr,
|
||||
L.Row(
|
||||
C.Label(UiStrings.OcrLanguageLabel).AlignCenter().Padding(right: 40),
|
||||
_ocrLang.XScale()
|
||||
).Aligned(),
|
||||
L.Row(
|
||||
C.Label(UiStrings.OcrModeLabel).AlignCenter().Padding(right: 40),
|
||||
_ocrMode.XScale()
|
||||
).Aligned(),
|
||||
_ocrAfterScanning,
|
||||
C.Filler(),
|
||||
L.Row(
|
||||
_moreLanguages.AlignCenter().Padding(right: 30),
|
||||
C.Filler(),
|
||||
_ok,
|
||||
_cancel
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
10
NAPS2.Lib/Icons.Designer.cs
generated
10
NAPS2.Lib/Icons.Designer.cs
generated
@ -769,6 +769,16 @@ namespace NAPS2 {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized resource of type System.Byte[].
|
||||
/// </summary>
|
||||
internal static byte[] text_small {
|
||||
get {
|
||||
object obj = ResourceManager.GetObject("text_small", resourceCulture);
|
||||
return ((byte[])(obj));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized resource of type System.Byte[].
|
||||
/// </summary>
|
||||
|
@ -256,6 +256,9 @@
|
||||
<data name="text" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>Icons\text.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</data>
|
||||
<data name="text_small" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>Icons\text-small.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</data>
|
||||
<data name="control_play_blue" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>Icons\control_play_blue.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</data>
|
||||
|
BIN
NAPS2.Lib/Icons/text-small.png
Normal file
BIN
NAPS2.Lib/Icons/text-small.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 621 B |
Binary file not shown.
Before Width: | Height: | Size: 1.1 KiB |
@ -221,6 +221,33 @@ namespace NAPS2.Lang.Resources {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Best.
|
||||
/// </summary>
|
||||
internal static string OcrMode_Best {
|
||||
get {
|
||||
return ResourceManager.GetString("OcrMode_Best", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Fast.
|
||||
/// </summary>
|
||||
internal static string OcrMode_Fast {
|
||||
get {
|
||||
return ResourceManager.GetString("OcrMode_Fast", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Legacy.
|
||||
/// </summary>
|
||||
internal static string OcrMode_Legacy {
|
||||
get {
|
||||
return ResourceManager.GetString("OcrMode_Legacy", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to A3 (297x420 mm).
|
||||
/// </summary>
|
||||
|
@ -276,4 +276,13 @@
|
||||
<data name="WiaVersion_Wia20" xml:space="preserve">
|
||||
<value>2.0</value>
|
||||
</data>
|
||||
<data name="OcrMode_Fast" xml:space="preserve">
|
||||
<value>Fast</value>
|
||||
</data>
|
||||
<data name="OcrMode_Best" xml:space="preserve">
|
||||
<value>Best</value>
|
||||
</data>
|
||||
<data name="OcrMode_Legacy" xml:space="preserve">
|
||||
<value>Legacy</value>
|
||||
</data>
|
||||
</root>
|
1379
NAPS2.Lib/Lang/Resources/UiStrings.Designer.cs
generated
1379
NAPS2.Lib/Lang/Resources/UiStrings.Designer.cs
generated
File diff suppressed because it is too large
Load Diff
@ -396,4 +396,22 @@
|
||||
<data name="Naps2FullName" xml:space="preserve">
|
||||
<value>Not Another PDF Scanner</value>
|
||||
</data>
|
||||
<data name="OcrSetupFormTitle" xml:space="preserve">
|
||||
<value>OCR Setup</value>
|
||||
</data>
|
||||
<data name="MakePdfsSearchable" xml:space="preserve">
|
||||
<value>Make PDFs searchable using OCR</value>
|
||||
</data>
|
||||
<data name="OcrLanguageLabel" xml:space="preserve">
|
||||
<value>OCR language:</value>
|
||||
</data>
|
||||
<data name="OcrModeLabel" xml:space="preserve">
|
||||
<value>OCR mode:</value>
|
||||
</data>
|
||||
<data name="RunOcrAfterScanning" xml:space="preserve">
|
||||
<value>Automatically run OCR after scanning</value>
|
||||
</data>
|
||||
<data name="GetMoreLanguages" xml:space="preserve">
|
||||
<value>Get more languages</value>
|
||||
</data>
|
||||
</root>
|
Loading…
Reference in New Issue
Block a user