OCR Plugin refactoring, now should work as a real destination and have an icon.

git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@2083 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
RKrom 2012-09-23 13:28:30 +00:00
parent 9553f840cb
commit fd91cc9107
18 changed files with 61 additions and 115 deletions

View file

@ -4,7 +4,7 @@ Microsoft Visual Studio Solution File, Format Version 11.00
# SharpDevelop 4.2.1.8805 # SharpDevelop 4.2.1.8805
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GreenshotPlugin", "..\GreenshotPlugin\GreenshotPlugin.csproj", "{5B924697-4DCD-4F98-85F1-105CB84B7341}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GreenshotPlugin", "..\GreenshotPlugin\GreenshotPlugin.csproj", "{5B924697-4DCD-4F98-85F1-105CB84B7341}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Greenshot-OCR-Plugin", "..\Greenshot-OCR-Plugin\Greenshot-OCR-Plugin.csproj", "{C6988EE8-2FEE-4349-9F09-F9628A0D8965}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GreenshotOCRPlugin", "..\GreenshotOCRPlugin\GreenshotOCRPlugin.csproj", "{C6988EE8-2FEE-4349-9F09-F9628A0D8965}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GreenshotJiraPlugin", "..\GreenshotJiraPlugin\GreenshotJiraPlugin.csproj", "{19FEEF09-313F-43C7-819D-F1BCA782B08B}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GreenshotJiraPlugin", "..\GreenshotJiraPlugin\GreenshotJiraPlugin.csproj", "{19FEEF09-313F-43C7-819D-F1BCA782B08B}"
EndProject EndProject

View file

@ -51,8 +51,8 @@
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup> <PropertyGroup>
<PostBuildEvent>mkdir "$(SolutionDir)bin\$(Configuration)\Plugins\Greenshot-OCR-Plugin" <PostBuildEvent>mkdir "$(SolutionDir)bin\$(Configuration)\Plugins\GreenshotOCRPlugin"
copy "$(ProjectDir)bin\$(Configuration)\$(TargetFileName)" "$(SolutionDir)bin\$(Configuration)\Plugins\Greenshot-OCR-Plugin"</PostBuildEvent> copy "$(ProjectDir)bin\$(Configuration)\$(TargetFileName)" "$(SolutionDir)bin\$(Configuration)\Plugins\GreenshotOCRPlugin"</PostBuildEvent>
</PropertyGroup> </PropertyGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets. Other similar extension points exist, see Microsoft.Common.targets.

View file

@ -6,10 +6,9 @@
<Platform Condition=" '$(Platform)' == '' ">x86</Platform> <Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<OutputType>Library</OutputType> <OutputType>Library</OutputType>
<RootNamespace>GreenshotOCR</RootNamespace> <RootNamespace>GreenshotOCR</RootNamespace>
<AssemblyName>Greenshot-OCR-Plugin</AssemblyName> <AssemblyName>GreenshotOCRPlugin</AssemblyName>
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion> <TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
<AppDesignerFolder>Properties</AppDesignerFolder> <AppDesignerFolder>Properties</AppDesignerFolder>
<SourceAnalysisOverrideSettingsFile>C:\Dokumente und Einstellungen\05018085\Anwendungsdaten\ICSharpCode/SharpDevelop3.0\Settings.SourceAnalysis</SourceAnalysisOverrideSettingsFile>
<AllowUnsafeBlocks>False</AllowUnsafeBlocks> <AllowUnsafeBlocks>False</AllowUnsafeBlocks>
<NoStdLib>False</NoStdLib> <NoStdLib>False</NoStdLib>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
@ -52,9 +51,9 @@
<Reference Include="System.Windows.Forms" /> <Reference Include="System.Windows.Forms" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="LanguageKeys.cs" />
<Compile Include="OCRConfiguration.cs" /> <Compile Include="OCRConfiguration.cs" />
<Compile Include="OCRDestination.cs" /> <Compile Include="OCRDestination.cs" />
<Compile Include="OCRForm.cs" />
<Compile Include="OCRPlugin.cs" /> <Compile Include="OCRPlugin.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SettingsForm.cs"> <Compile Include="SettingsForm.cs">

View file

@ -33,7 +33,5 @@ namespace GreenshotOCR {
public bool Orientimage; public bool Orientimage;
[IniProperty("straightenImage", Description="Straighten image?", DefaultValue="true")] [IniProperty("straightenImage", Description="Straighten image?", DefaultValue="true")]
public bool StraightenImage; public bool StraightenImage;
[IniProperty("hotkey", Description="OCR Hotkey", DefaultValue="Alt + Ctrl + PrintScreen")]
public string HotKey;
} }
} }

View file

@ -37,8 +37,16 @@ namespace GreenshotOCR {
private static OCRConfiguration config = IniConfig.GetIniSection<OCRConfiguration>(); private static OCRConfiguration config = IniConfig.GetIniSection<OCRConfiguration>();
private const int MIN_WIDTH = 130; private const int MIN_WIDTH = 130;
private const int MIN_HEIGHT = 130; private const int MIN_HEIGHT = 130;
private static Image icon = null;
private OcrPlugin plugin; private OcrPlugin plugin;
static OCRDestination() {
string exePath = PluginUtils.GetExePath("MSPVIEW.EXE");
if (exePath != null && File.Exists(exePath)) {
icon = PluginUtils.GetExeIcon(exePath, 0);
}
}
public override string Designation { public override string Designation {
get { get {
return "OCR"; return "OCR";
@ -51,12 +59,20 @@ namespace GreenshotOCR {
} }
} }
public override Image DisplayIcon {
get {
return icon;
}
}
public OCRDestination(OcrPlugin plugin) { public OCRDestination(OcrPlugin plugin) {
this.plugin = plugin; this.plugin = plugin;
} }
public override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) { public override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) {
plugin.DoOCR(surface); ExportInformation exportInformation = new ExportInformation(this.Designation, this.Description);
return new ExportInformation(this.Designation, this.Description, true); exportInformation.ExportMade = plugin.DoOCR(surface) != null;
return exportInformation;
} }
} }
} }

View file

@ -1,4 +1,4 @@
/* /*
* Greenshot - a free and open source screenshot tool * Greenshot - a free and open source screenshot tool
* Copyright (C) 2007-2012 Thomas Braun, Jens Klingen, Robin Krom * Copyright (C) 2007-2012 Thomas Braun, Jens Klingen, Robin Krom
* *
@ -21,9 +21,11 @@
using System; using System;
namespace GreenshotOCR { namespace GreenshotOCR {
public enum LangKey { /// <summary>
language, /// This class is needed for design-time resolving of the language files
orient_image, /// </summary>
straighten_image public class OCRForm : GreenshotPlugin.Controls.GreenshotForm {
public OCRForm() : base() {
}
} }
} }

View file

@ -70,12 +70,11 @@ namespace GreenshotOCR {
private static OCRConfiguration config; private static OCRConfiguration config;
private PluginAttribute myAttributes; private PluginAttribute myAttributes;
private ToolStripMenuItem ocrMenuItem = new ToolStripMenuItem(); private ToolStripMenuItem ocrMenuItem = new ToolStripMenuItem();
private int hotkeyIdentifier = 0;
public OcrPlugin() { } public OcrPlugin() { }
public IEnumerable<IDestination> Destinations() { public IEnumerable<IDestination> Destinations() {
yield break; yield return new OCRDestination(this);
} }
public IEnumerable<IProcessor> Processors() { public IEnumerable<IProcessor> Processors() {
yield break; yield break;
@ -105,13 +104,6 @@ namespace GreenshotOCR {
if (config.Language != null) { if (config.Language != null) {
config.Language = config.Language.Replace("miLANG_","").Replace("_"," "); config.Language = config.Language.Replace("miLANG_","").Replace("_"," ");
} }
SetHotkeys();
// Here we can hang ourselves to the main context menu!
ocrMenuItem.Text = "Region OCR";
ocrMenuItem.Click += new System.EventHandler(MainMenuClick);
PluginUtils.AddToContextMenu(host, ocrMenuItem);
return true; return true;
} }
@ -120,21 +112,6 @@ namespace GreenshotOCR {
/// </summary> /// </summary>
public void Shutdown() { public void Shutdown() {
LOG.Debug("Shutdown of " + myAttributes.Name); LOG.Debug("Shutdown of " + myAttributes.Name);
HotkeyControl.UnregisterHotkey(hotkeyIdentifier);
hotkeyIdentifier = 0;
}
private void SetHotkeys() {
if (hotkeyIdentifier > 0) {
HotkeyControl.UnregisterHotkey(hotkeyIdentifier);
hotkeyIdentifier = 0;
}
hotkeyIdentifier = HotkeyControl.RegisterHotKey(config.HotKey, new HotKeyHandler(MyHotkeyHandler));
if (hotkeyIdentifier > 0) {
ocrMenuItem.ShortcutKeyDisplayString = HotkeyControl.GetLocalizedHotkeyStringFromString(config.HotKey);
} else {
ocrMenuItem.ShortcutKeyDisplayString = "";
}
} }
/// <summary> /// <summary>
@ -149,27 +126,10 @@ namespace GreenshotOCR {
DialogResult result = settingsForm.ShowDialog(); DialogResult result = settingsForm.ShowDialog();
if (result == DialogResult.OK) { if (result == DialogResult.OK) {
// "Re"set hotkeys // "Re"set hotkeys
SetHotkeys();
IniConfig.Save(); IniConfig.Save();
} }
} }
private void StartOCRRegion() {
LOG.Debug("Starting OCR!");
host.CaptureRegion(false, new OCRDestination(this));
}
private void MyHotkeyHandler() {
StartOCRRegion();
}
/// <summary>
/// Is called when the OCR menu is selected
/// </summary>
/// <param name="sender">ContextMenu</param>
/// <param name="e">EventArgs from ContextMenu</param>
private void MainMenuClick(object sender, EventArgs e) {
StartOCRRegion();
}
/// <summary> /// <summary>
/// Handling of the CaptureTaken "event" from the ICaptureHost /// Handling of the CaptureTaken "event" from the ICaptureHost
@ -178,7 +138,7 @@ namespace GreenshotOCR {
/// <param name="ImageOutputEventArgs">Has the Image and the capture details</param> /// <param name="ImageOutputEventArgs">Has the Image and the capture details</param>
private const int MIN_WIDTH = 130; private const int MIN_WIDTH = 130;
private const int MIN_HEIGHT = 130; private const int MIN_HEIGHT = 130;
public void DoOCR(ISurface surface) { public string DoOCR(ISurface surface) {
string filePath = null; string filePath = null;
OutputSettings outputSettings = new OutputSettings(OutputFormat.bmp); OutputSettings outputSettings = new OutputSettings(OutputFormat.bmp);
@ -222,7 +182,7 @@ namespace GreenshotOCR {
} }
if (text == null || text.Trim().Length == 0) { if (text == null || text.Trim().Length == 0) {
LOG.Info("No text returned"); LOG.Info("No text returned");
return; return null;
} }
try { try {
@ -234,6 +194,7 @@ namespace GreenshotOCR {
} catch (Exception e) { } catch (Exception e) {
LOG.Error("Problem pasting text to clipboard: ", e); LOG.Error("Problem pasting text to clipboard: ", e);
} }
return text;
} }
private bool HasMODI() { private bool HasMODI() {

View file

@ -49,13 +49,11 @@ namespace GreenshotOCR
private void InitializeComponent() private void InitializeComponent()
{ {
this.comboBox_languages = new System.Windows.Forms.ComboBox(); this.comboBox_languages = new System.Windows.Forms.ComboBox();
this.checkBox_orientImage = new System.Windows.Forms.CheckBox(); this.checkBox_orientImage = new GreenshotPlugin.Controls.GreenshotCheckBox();
this.checkBox_straightenImage = new System.Windows.Forms.CheckBox(); this.checkBox_straightenImage = new GreenshotPlugin.Controls.GreenshotCheckBox();
this.label_language = new System.Windows.Forms.Label(); this.label_language = new GreenshotPlugin.Controls.GreenshotLabel();
this.buttonOK = new System.Windows.Forms.Button(); this.buttonOK = new GreenshotPlugin.Controls.GreenshotButton();
this.buttonCancel = new System.Windows.Forms.Button(); this.buttonCancel = new GreenshotPlugin.Controls.GreenshotButton();
this.ocr_hotkeyControl = new GreenshotPlugin.Controls.HotkeyControl();
this.label1 = new System.Windows.Forms.Label();
this.SuspendLayout(); this.SuspendLayout();
// //
// comboBox_languages // comboBox_languages
@ -75,17 +73,21 @@ namespace GreenshotOCR
this.checkBox_orientImage.Name = "checkBox_orientImage"; this.checkBox_orientImage.Name = "checkBox_orientImage";
this.checkBox_orientImage.Size = new System.Drawing.Size(104, 24); this.checkBox_orientImage.Size = new System.Drawing.Size(104, 24);
this.checkBox_orientImage.TabIndex = 1; this.checkBox_orientImage.TabIndex = 1;
this.checkBox_orientImage.Text = "Orient image"; this.checkBox_orientImage.LanguageKey = "orient_image";
this.checkBox_orientImage.UseVisualStyleBackColor = true; this.checkBox_orientImage.UseVisualStyleBackColor = true;
this.checkBox_orientImage.SectionName = "OCR";
this.checkBox_orientImage.PropertyName = "orientimage";
// //
// checkBox_straightenImage // checkBox_straightenImage
// //
this.checkBox_straightenImage.Location = new System.Drawing.Point(118, 68); this.checkBox_straightenImage.Location = new System.Drawing.Point(13, 41);
this.checkBox_straightenImage.Name = "checkBox_straightenImage"; this.checkBox_straightenImage.Name = "checkBox_straightenImage";
this.checkBox_straightenImage.Size = new System.Drawing.Size(109, 24); this.checkBox_straightenImage.Size = new System.Drawing.Size(109, 24);
this.checkBox_straightenImage.TabIndex = 2; this.checkBox_straightenImage.TabIndex = 2;
this.checkBox_straightenImage.Text = "Straighten image"; this.checkBox_straightenImage.LanguageKey = "straighten_image";
this.checkBox_straightenImage.UseVisualStyleBackColor = true; this.checkBox_straightenImage.UseVisualStyleBackColor = true;
this.checkBox_straightenImage.SectionName = "OCR";
this.checkBox_straightenImage.PropertyName = "straightenImage";
// //
// label_language // label_language
// //
@ -93,53 +95,35 @@ namespace GreenshotOCR
this.label_language.Name = "label_language"; this.label_language.Name = "label_language";
this.label_language.Size = new System.Drawing.Size(55, 23); this.label_language.Size = new System.Drawing.Size(55, 23);
this.label_language.TabIndex = 3; this.label_language.TabIndex = 3;
this.label_language.Text = "Language"; this.label_language.LanguageKey = "ocr.language";
// //
// buttonOK // buttonOK
// //
this.buttonOK.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.buttonOK.Location = new System.Drawing.Point(12, 98); this.buttonOK.Location = new System.Drawing.Point(12, 98);
this.buttonOK.Name = "buttonOK"; this.buttonOK.Name = "buttonOK";
this.buttonOK.Size = new System.Drawing.Size(104, 23); this.buttonOK.Size = new System.Drawing.Size(104, 23);
this.buttonOK.TabIndex = 4; this.buttonOK.TabIndex = 4;
this.buttonOK.Text = "OK"; this.buttonOK.LanguageKey = "OK";
this.buttonOK.UseVisualStyleBackColor = true; this.buttonOK.UseVisualStyleBackColor = true;
this.buttonOK.Click += new System.EventHandler(this.ButtonOKClick); this.buttonOK.Click += new System.EventHandler(this.ButtonOKClick);
// //
// buttonCancel // buttonCancel
// //
this.buttonCancel.Location = new System.Drawing.Point(122, 98); this.buttonCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonCancel.Location = new System.Drawing.Point(128, 98);
this.buttonCancel.Name = "buttonCancel"; this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.Size = new System.Drawing.Size(104, 23); this.buttonCancel.Size = new System.Drawing.Size(104, 23);
this.buttonCancel.TabIndex = 5; this.buttonCancel.TabIndex = 5;
this.buttonCancel.Text = "Cancel"; this.buttonCancel.LanguageKey = "CANCEL";
this.buttonCancel.UseVisualStyleBackColor = true; this.buttonCancel.UseVisualStyleBackColor = true;
this.buttonCancel.Click += new System.EventHandler(this.ButtonCancelClick); this.buttonCancel.Click += new System.EventHandler(this.ButtonCancelClick);
// //
// ocr_hotkeyControl
//
this.ocr_hotkeyControl.Hotkey = System.Windows.Forms.Keys.None;
this.ocr_hotkeyControl.HotkeyModifiers = System.Windows.Forms.Keys.None;
this.ocr_hotkeyControl.Location = new System.Drawing.Point(74, 39);
this.ocr_hotkeyControl.Name = "ocr_hotkeyControl";
this.ocr_hotkeyControl.Size = new System.Drawing.Size(153, 20);
this.ocr_hotkeyControl.TabIndex = 6;
//
// label1
//
this.label1.ForeColor = System.Drawing.SystemColors.ControlText;
this.label1.Location = new System.Drawing.Point(13, 42);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(55, 23);
this.label1.TabIndex = 7;
this.label1.Text = "Hotkey";
//
// SettingsForm // SettingsForm
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F); this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi;
this.ClientSize = new System.Drawing.Size(244, 135); this.ClientSize = new System.Drawing.Size(244, 135);
this.Controls.Add(this.label1);
this.Controls.Add(this.ocr_hotkeyControl);
this.Controls.Add(this.buttonCancel); this.Controls.Add(this.buttonCancel);
this.Controls.Add(this.buttonOK); this.Controls.Add(this.buttonOK);
this.Controls.Add(this.label_language); this.Controls.Add(this.label_language);
@ -147,17 +131,14 @@ namespace GreenshotOCR
this.Controls.Add(this.checkBox_orientImage); this.Controls.Add(this.checkBox_orientImage);
this.Controls.Add(this.comboBox_languages); this.Controls.Add(this.comboBox_languages);
this.Name = "SettingsForm"; this.Name = "SettingsForm";
this.Text = "SettingsForm"; this.LanguageKey = "settings_title";
this.ResumeLayout(false); this.ResumeLayout(false);
this.PerformLayout();
} }
private System.Windows.Forms.Label label1; private GreenshotPlugin.Controls.GreenshotLabel label_language;
private GreenshotPlugin.Controls.HotkeyControl ocr_hotkeyControl; private GreenshotPlugin.Controls.GreenshotButton buttonCancel;
private System.Windows.Forms.Label label_language; private GreenshotPlugin.Controls.GreenshotButton buttonOK;
private System.Windows.Forms.Button buttonCancel; private GreenshotPlugin.Controls.GreenshotCheckBox checkBox_orientImage;
private System.Windows.Forms.Button buttonOK; private GreenshotPlugin.Controls.GreenshotCheckBox checkBox_straightenImage;
private System.Windows.Forms.CheckBox checkBox_orientImage;
private System.Windows.Forms.CheckBox checkBox_straightenImage;
private System.Windows.Forms.ComboBox comboBox_languages; private System.Windows.Forms.ComboBox comboBox_languages;
} }
} }

View file

@ -26,7 +26,7 @@ namespace GreenshotOCR {
/// <summary> /// <summary>
/// Description of SettingsForm. /// Description of SettingsForm.
/// </summary> /// </summary>
public partial class SettingsForm : Form { public partial class SettingsForm : OCRForm {
private OCRConfiguration config; private OCRConfiguration config;
public SettingsForm(string [] languages, OCRConfiguration config) { public SettingsForm(string [] languages, OCRConfiguration config) {
@ -36,7 +36,6 @@ namespace GreenshotOCR {
this.config = config; this.config = config;
InitializeComponent(); InitializeComponent();
this.Icon = GreenshotResources.getGreenshotIcon(); this.Icon = GreenshotResources.getGreenshotIcon();
initializeComponentText();
comboBox_languages.Items.Clear(); comboBox_languages.Items.Clear();
int index=0; int index=0;
@ -54,14 +53,6 @@ namespace GreenshotOCR {
} }
index++; index++;
} }
checkBox_orientImage.Checked = config.Orientimage;
checkBox_straightenImage.Checked = config.StraightenImage;
ocr_hotkeyControl.SetHotkey(config.HotKey);
}
private void initializeComponentText() {
this.label_language.Text = Language.GetString("ocr", LangKey.language);
this.checkBox_orientImage.Text = Language.GetString("ocr", LangKey.orient_image);
} }
void ButtonCancelClick(object sender, EventArgs e) { void ButtonCancelClick(object sender, EventArgs e) {
@ -73,8 +64,6 @@ namespace GreenshotOCR {
if (selectedString != null) { if (selectedString != null) {
config.Language = selectedString.ToUpper(); config.Language = selectedString.ToUpper();
} }
config.Orientimage = checkBox_orientImage.Checked;
config.StraightenImage = checkBox_straightenImage.Checked;
DialogResult = DialogResult.OK; DialogResult = DialogResult.OK;
} }