From 5865edc456d08193118a03cd835bb519866b577a Mon Sep 17 00:00:00 2001 From: Stephan Richter Date: Sun, 5 Jan 2020 13:49:29 +0100 Subject: [PATCH] improved program: - date selecter now preselects current date - added button to open scanned file with external program --- Belegscanner.lps | 117 ++++++++++++++++++++++++++++++++--------------- scanner.lfm | 36 ++++++++++----- scanner.pas | 31 ++++++++++--- 3 files changed, 130 insertions(+), 54 deletions(-) diff --git a/Belegscanner.lps b/Belegscanner.lps index 5610665..f5145ee 100644 --- a/Belegscanner.lps +++ b/Belegscanner.lps @@ -3,13 +3,13 @@ - + - - + + @@ -18,9 +18,9 @@ - - - + + + @@ -77,127 +77,172 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + diff --git a/scanner.lfm b/scanner.lfm index a17f3a9..3f73532 100644 --- a/scanner.lfm +++ b/scanner.lfm @@ -1,7 +1,7 @@ object ScanForm: TScanForm - Left = 1534 + Left = 2222 Height = 869 - Top = 299 + Top = 198 Width = 1188 Caption = 'Belegscanner' ClientHeight = 869 @@ -10,7 +10,7 @@ object ScanForm: TScanForm LCLVersion = '1.8.2.0' object TypeSelector: TComboBox Left = 904 - Height = 29 + Height = 28 Top = 208 Width = 276 Enabled = False @@ -21,7 +21,7 @@ object ScanForm: TScanForm end object Origin: TComboBox Left = 904 - Height = 29 + Height = 28 Top = 240 Width = 272 Enabled = False @@ -32,7 +32,7 @@ object ScanForm: TScanForm end object Destination: TComboBox Left = 904 - Height = 29 + Height = 28 Top = 304 Width = 272 Enabled = False @@ -54,7 +54,7 @@ object ScanForm: TScanForm end object Product: TComboBox Left = 904 - Height = 29 + Height = 28 Top = 240 Width = 276 Enabled = False @@ -76,7 +76,7 @@ object ScanForm: TScanForm end object Resolution: TComboBox Left = 904 - Height = 29 + Height = 28 Top = 368 Width = 72 ItemHeight = 0 @@ -90,9 +90,9 @@ object ScanForm: TScanForm end object DPI: TLabel Left = 984 - Height = 17 + Height = 16 Top = 376 - Width = 17 + Width = 19 Caption = 'dpi' ParentColor = False end @@ -110,7 +110,7 @@ object ScanForm: TScanForm end object Stop: TComboBox Left = 904 - Height = 29 + Height = 28 Top = 272 Width = 272 Enabled = False @@ -132,13 +132,13 @@ object ScanForm: TScanForm Height = 190 Top = 8 Width = 276 - DateTime = 43775 + DateTime = 0 OnChange = CalendarChange TabOrder = 0 end object PicSize: TComboBox Left = 904 - Height = 29 + Height = 28 Top = 336 Width = 272 ItemHeight = 0 @@ -153,6 +153,8 @@ object ScanForm: TScanForm Caption = 'Löschen' Enabled = False OnClick = DropButtonClick + ParentShowHint = False + ShowHint = True TabOrder = 9 end object Swap: TButton @@ -164,6 +166,16 @@ object ScanForm: TScanForm OnClick = SwapClick TabOrder = 10 end + object extButton: TButton + Left = 904 + Height = 49 + Top = 456 + Width = 272 + Caption = 'extern öffnen' + Enabled = False + OnClick = extButtonClick + TabOrder = 11 + end object BaseFolderDialog: TSelectDirectoryDialog left = 520 top = 128 diff --git a/scanner.pas b/scanner.pas index 4d6983e..de8a4c4 100644 --- a/scanner.pas +++ b/scanner.pas @@ -13,18 +13,19 @@ type { ScanThread } ScanThread = class(TThread) private - dbtn, sbtn : TButton; + dbtn, obtn, sbtn : TButton; folder,r :String; s:TPoint; p:TImage; protected procedure Execute; override; public - constructor Create(scanButton: TButton; dir: String; size: TPoint; resolution: String; preview: TImage; dropButton: TButton); + constructor Create(scanButton: TButton; dir: String; size: TPoint; resolution: String; preview: TImage; dropButton: TButton; openButton: TButton); end; { TScanForm } TScanForm = class(TForm) + extButton: TButton; Swap: TButton; DropButton: TButton; Calendar: TCalendar; @@ -43,6 +44,7 @@ type TypeSelector: TComboBox; procedure BaseFolderClick(Sender: TObject); + procedure extButtonClick(Sender: TObject); procedure DropButtonClick(Sender: TObject); procedure CalendarChange(Sender: TObject); procedure FormCreate(Sender: TObject); @@ -60,8 +62,11 @@ type private date: TDateTime; function getSize(): TPoint; - public + public + const + SCANNING : Integer = 1; + IDLE: Integer = 0; end; var @@ -73,9 +78,10 @@ implementation { ScanThread } -constructor ScanThread.Create(scanButton: TButton; dir: String; size: TPoint; resolution: String; preview: TImage; dropButton: TButton ); +constructor ScanThread.Create(scanButton: TButton; dir: String; size: TPoint; resolution: String; preview: TImage; dropButton: TButton; openButton: TButton ); begin sbtn := scanButton; + obtn := openButton; dbtn := dropButton; folder:=dir; s:=size; @@ -111,7 +117,9 @@ begin dbtn.Hint:=folder+fname; dbtn.Caption:=fname+' löschen'; dbtn.Enabled:=true; + obtn.Enabled:=true; sbtn.Enabled:=true; + sbtn.Tag := TScanForm.IDLE; end; function allowed(s: String): boolean; @@ -186,7 +194,7 @@ begin Swap.Enabled:=state; Product.Enabled := not state; Product.Visible := not state; - ScanButton.Enabled:=true; + if (ScanButton.Tag <> TScanForm.SCANNING) then ScanButton.Enabled:=true; UpdateFolder(); end; @@ -225,6 +233,7 @@ var size: TPoint; begin ScanButton.Enabled:=false; + ScanButton.Tag:=TScanForm.SCANNING; filename := GetEnvironmentVariable('HOME') + '/.config/belegscanner.conf'; size := getSize(); json := ExportConfig(); @@ -234,7 +243,7 @@ begin finally config.Free; end; - ScanThread.Create(ScanButton,BaseFolder.Caption+'/'+FolderName.Caption+'/',size,Resolution.Caption,Preview,DropButton); + ScanThread.Create(ScanButton,BaseFolder.Caption+'/'+FolderName.Caption+'/',size,Resolution.Caption,Preview,DropButton,extButton); end; procedure TScanForm.StopChange(Sender: TObject); @@ -275,6 +284,7 @@ begin BaseFolder.Caption:=GetEnvironmentVariable('HOME'); filename := GetEnvironmentVariable('HOME') + '/.config/belegscanner.conf'; lines := TStringList.Create; + Calendar.DateTime:=Now; try lines.LoadFromFile(filename); for index := 0 to lines.Count-1 do @@ -319,11 +329,20 @@ begin BaseFolder.Caption := BaseFolderDialog.FileName; end; +procedure TScanForm.extButtonClick(Sender: TObject); +var + cmd: string; +begin + cmd := 'gvfs-open "'+DropButton.Hint+'"'; + fpSystem(cmd); +end; + procedure TScanForm.DropButtonClick(Sender: TObject); begin DeleteFile(DropButton.Hint); Preview.Picture:=nil; DropButton.Enabled:=false; + extButton.Enabled:=false; end;