diff --git a/Belegscanner.lpi b/Belegscanner.lpi
index b5120fc..4e35c6a 100644
--- a/Belegscanner.lpi
+++ b/Belegscanner.lpi
@@ -10,9 +10,6 @@
-
-
-
@@ -38,6 +35,7 @@
+
diff --git a/Belegscanner.lpr b/Belegscanner.lpr
index cbb3821..530df48 100644
--- a/Belegscanner.lpr
+++ b/Belegscanner.lpr
@@ -3,9 +3,9 @@ program Belegscanner;
{$mode objfpc}{$H+}
uses
- {$IFDEF UNIX}{$IFDEF UseCThreads}
+ {$IFDEF UNIX}
cthreads,
- {$ENDIF}{$ENDIF}
+ {$ENDIF}
Interfaces, // this includes the LCL widgetset
Forms, scanner
{ you can add units after this };
diff --git a/Belegscanner.lps b/Belegscanner.lps
index c57c301..ee148ed 100644
--- a/Belegscanner.lps
+++ b/Belegscanner.lps
@@ -3,23 +3,24 @@
-
+
-
-
+
+
+
-
-
-
+
+
+
@@ -28,7 +29,7 @@
-
+
@@ -36,7 +37,7 @@
-
+
@@ -44,137 +45,159 @@
-
+
-
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
diff --git a/scanner.lfm b/scanner.lfm
index d2768da..5d90e83 100644
--- a/scanner.lfm
+++ b/scanner.lfm
@@ -1,70 +1,50 @@
object ScanForm: TScanForm
- Left = 1901
- Height = 180
- Top = 631
- Width = 663
+ Left = 1534
+ Height = 1018
+ Top = 299
+ Width = 1215
Caption = 'Belegscanner'
- ClientHeight = 180
- ClientWidth = 663
+ ClientHeight = 1018
+ ClientWidth = 1215
OnCreate = FormCreate
LCLVersion = '1.8.2.0'
- object DateView: TLabel
- Left = 8
- Height = 19
- Top = 8
- Width = 150
- Caption = 'Datum auswählen!'
- Font.Height = -16
- Font.Name = 'Sans'
- ParentColor = False
- ParentFont = False
- end
- object dateButton: TButton
- Left = 232
- Height = 25
- Top = 8
- Width = 75
- Caption = 'ändern'
- OnClick = dateButtonClick
- TabOrder = 0
- end
object TypeSelector: TComboBox
- Left = 8
+ Left = 344
Height = 29
- Top = 40
+ Top = 32
Width = 216
Enabled = False
ItemHeight = 0
OnChange = TypeSelectorChange
- TabOrder = 1
+ TabOrder = 3
Text = 'Select Type'
end
object Origin: TComboBox
- Left = 232
+ Left = 568
Height = 29
- Top = 40
- Width = 184
+ Top = 32
+ Width = 192
Enabled = False
ItemHeight = 0
OnChange = OriginChange
- TabOrder = 2
+ TabOrder = 5
Text = 'Start'
end
object Destination: TComboBox
- Left = 424
+ Left = 948
Height = 29
- Top = 40
+ Top = 32
Width = 196
Enabled = False
ItemHeight = 0
OnChange = DestinationChange
- TabOrder = 3
+ TabOrder = 7
Text = 'Ziel'
end
object FolderName: TLabel
- Left = 8
+ Left = 344
Height = 19
- Top = 96
+ Top = 64
Width = 103
Caption = 'Ordnername'
Font.Height = -16
@@ -73,10 +53,10 @@ object ScanForm: TScanForm
ParentFont = False
end
object Product: TComboBox
- Left = 232
+ Left = 568
Height = 29
- Top = 40
- Width = 184
+ Top = 32
+ Width = 192
Enabled = False
ItemHeight = 0
OnChange = ProductChange
@@ -84,74 +64,75 @@ object ScanForm: TScanForm
Text = 'Produkt'
Visible = False
end
- object ScnaButton: TButton
- Left = 545
- Height = 25
- Top = 72
- Width = 75
+ object ScanButton: TButton
+ Left = 664
+ Height = 49
+ Top = 88
+ Width = 112
Caption = 'scannen!'
Enabled = False
- OnClick = ScnaButtonClick
- TabOrder = 5
+ OnClick = ScanButtonClick
+ TabOrder = 8
end
object IWidth: TEdit
- Left = 320
+ Left = 344
Height = 27
- Top = 8
+ Top = 88
Width = 80
Alignment = taRightJustify
- TabOrder = 6
+ TabOrder = 0
Text = '209'
end
object Times: TLabel
- Left = 402
+ Left = 426
Height = 17
- Top = 13
+ Top = 93
Width = 6
Caption = 'x'
ParentColor = False
end
object IHeight: TEdit
- Left = 416
+ Left = 440
Height = 27
- Top = 8
+ Top = 88
Width = 80
- TabOrder = 7
+ TabOrder = 1
Text = '297'
end
object Pixels: TLabel
- Left = 500
+ Left = 524
Height = 17
- Top = 13
+ Top = 93
Width = 27
Caption = 'px @'
ParentColor = False
end
object Resolution: TComboBox
- Left = 536
+ Left = 560
Height = 29
- Top = 8
+ Top = 88
Width = 68
ItemHeight = 0
+ ItemIndex = 0
Items.Strings = (
'150'
'300'
)
- TabOrder = 8
+ TabOrder = 2
Text = '150'
end
object DPI: TLabel
- Left = 608
+ Left = 632
Height = 17
- Top = 13
+ Top = 93
Width = 17
Caption = 'dpi'
ParentColor = False
end
object BaseFolder: TLabel
- Left = 8
+ Left = 344
Height = 19
- Top = 76
+ Top = 8
Width = 88
Caption = 'BaseFolder'
Font.Height = -16
@@ -160,15 +141,36 @@ object ScanForm: TScanForm
ParentFont = False
OnClick = BaseFolderClick
end
- object DateSelector: TCalendarDialog
- Date = 43775
- OKCaption = '&Ok'
- CancelCaption = 'Abbrechen'
- left = 352
- top = 72
+ object Stop: TComboBox
+ Left = 768
+ Height = 29
+ Top = 32
+ Width = 176
+ Enabled = False
+ ItemHeight = 0
+ OnChange = StopChange
+ TabOrder = 6
+ Text = 'Zwischenhalt'
+ end
+ object Preview: TImage
+ Left = 8
+ Height = 800
+ Top = 208
+ Width = 1200
+ Center = True
+ Proportional = True
+ end
+ object Calendar: TCalendar
+ Left = 8
+ Height = 190
+ Top = 8
+ Width = 324
+ DateTime = 43775
+ OnChange = CalendarChange
+ TabOrder = 9
end
object BaseFolderDialog: TSelectDirectoryDialog
- left = 251
- top = 85
+ left = 520
+ top = 128
end
end
diff --git a/scanner.pas b/scanner.pas
index 5600942..e3b4014 100644
--- a/scanner.pas
+++ b/scanner.pas
@@ -6,13 +6,27 @@ interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtDlgs,
- StdCtrls, Unix;
+ StdCtrls, ExtCtrls, Calendar, Unix;
type
- { TScanForm }
+ { ScanThread }
+ ScanThread = class(TThread)
+ private
+ btn : TButton;
+ folder,w,h,r :String;
+ p:TImage;
+ protected
+ procedure Execute; override;
+ public
+ constructor Create(button: TButton; dir: String; width: String; height: String; resolution: String; preview: TImage);
+ end;
+ { TScanForm }
TScanForm = class(TForm)
+ Calendar: TCalendar;
+ Preview: TImage;
+ Stop: TComboBox;
DPI: TLabel;
BaseFolder: TLabel;
Resolution: TComboBox;
@@ -21,30 +35,27 @@ type
BaseFolderDialog: TSelectDirectoryDialog;
Times: TLabel;
IWidth: TEdit;
- ScnaButton: TButton;
+ ScanButton: TButton;
Product: TComboBox;
Destination: TComboBox;
FolderName: TLabel;
Origin: TComboBox;
TypeSelector: TComboBox;
- dateButton: TButton;
- DateSelector: TCalendarDialog;
- DateView: TLabel;
procedure BaseFolderClick(Sender: TObject);
+ procedure CalendarChange(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure ProductChange(Sender: TObject);
procedure DestinationChange(Sender: TObject);
- procedure dateButtonClick(Sender: TObject);
procedure OriginChange(Sender: TObject);
- procedure ScnaButtonClick(Sender: TObject);
+ procedure ScanButtonClick(Sender: TObject);
+ procedure StopChange(Sender: TObject);
procedure TypeSelectorChange(Sender: TObject);
function ExportConfig(): string;
function ExportOptions(dropDown: TComboBox): string;
procedure UpdateTypes();
procedure UpdateFolder();
- procedure MixLocations(d1: TComboBox; d2: TComboBox);
- procedure ScanImage();
+ procedure MixLocations(d1: TComboBox; d2: TComboBox; d3: TComboBox);
private
date: TDateTime;
public
@@ -58,14 +69,44 @@ implementation
{$R *.lfm}
-{ TScanForm }
+{ ScanThread }
+
+constructor ScanThread.Create(button: TButton; dir: String; width: String; height: String; resolution: String; preview: TImage);
+begin
+ btn := button;
+ folder:=dir;
+ w:=width;
+ h:=height;
+ r:=resolution;
+ p:=preview;
+ inherited Create(false);
+end;
-procedure TScanForm.ScanImage();
+procedure ScanThread.Execute;
+var
+ fname: String;
+ num: Integer;
+ pic: TPicture;
begin
- fpSystem('scanimage -x '+IWidth.Caption+' -y '+IHeight.Caption+' --mode Gray --resolution '+Resolution.Caption+' --format jpeg > /home/srichter/tmp/test.jpg');
+ ForceDirectories(folder);
+ num := 0;
+ repeat
+ num := num +1;
+ fname := '/scan_';
+ if (num<10) then fname:=fname+'0';
+ fname := fname+IntToStr(num)+'.jpg';
+ until not FileExists(folder+fname);
+ fpSystem('scanimage -x '+w+' -y '+h+' --mode Color --resolution '+r+' --format jpeg > "'+folder+fname+'"');
+ try
+ pic:=TPicture.Create;
+ pic.LoadFromFile(folder+fname);
+ p.Picture:=pic;
+ finally
+ end;
+ btn.Enabled:=true;
end;
-procedure TScanForm.MixLocations(d1: TComboBox; d2: TComboBox);
+procedure TScanForm.MixLocations(d1: TComboBox; d2: TComboBox; d3: TComboBox);
var
list: TStringList;
begin
@@ -73,17 +114,20 @@ begin
list.Sorted := True;
d1.Items.Add(d1.Text);
d2.Items.Add(d2.Text);
+ if not (d3.Text = '') then d3.Items.Add(d3.Text);
list.Assign(d1.Items);
list.AddStrings(d2.Items);
+ list.AddStrings(d3.Items);
d1.Items.Assign(list);
d2.Items.Assign(list);
+ d3.Items.Assign(list);
end;
function TScanForm.ExportConfig(): string;
begin
Result := 'types:' + ExportOptions(TypeSelector) + #13;
Result := Result + 'items:' + ExportOptions(Product) + #13;
- MixLocations(Origin, Destination);
+ MixLocations(Origin, Destination, Stop);
Result := Result + 'locations:' + ExportOPtions(Origin) + #13;
end;
@@ -116,18 +160,19 @@ begin
state := TypeSelector.Text = 'Ticket';
Origin.Enabled := state;
Origin.Visible := state;
+ Stop.Enabled := state;
+ Stop.Visible := state;
Destination.Enabled := state;
+ Destination.Visible := state;
Product.Enabled := not state;
Product.Visible := not state;
- ScnaButton.Enabled:=true;
+ ScanButton.Enabled:=true;
UpdateFolder();
end;
-procedure TScanForm.dateButtonClick(Sender: TObject);
+procedure TScanForm.CalendarChange(Sender: TObject);
begin
- DateSelector.Execute;
- date := DateSelector.Date;
- DateView.Caption := FormatDateTime('YYYY-MM-DD', date);
+ date := Calendar.DateTime;
UpdateTypes();
TypeSelector.Enabled := True;
UpdateFolder();
@@ -139,12 +184,13 @@ begin
UpdateFolder();
end;
-procedure TScanForm.ScnaButtonClick(Sender: TObject);
+procedure TScanForm.ScanButtonClick(Sender: TObject);
var
config: TFileStream;
filename: string;
json: string;
begin
+ ScanButton.Enabled:=false;
filename := GetEnvironmentVariable('HOME') + '/.config/belegscanner.conf';
json := ExportConfig();
try
@@ -153,7 +199,13 @@ begin
finally
config.Free;
end;
- ScanImage();
+ ScanThread.Create(ScanButton,BaseFolder.Caption+FolderName.Caption,IWidth.Caption,IHeight.Caption,Resolution.Caption,Preview);
+end;
+
+procedure TScanForm.StopChange(Sender: TObject);
+begin
+ Stop.Tag := 1;
+ UpdateFolder();
end;
procedure TScanForm.DestinationChange(Sender: TObject);
@@ -198,6 +250,7 @@ begin
line := line.Substring(10);
Origin.Items.AddStrings(line.Split(','));
Destination.Items.AddStrings(line.Split(','));
+ Stop.Items.AddStrings(line.Split(','));
end;
end
finally
@@ -223,6 +276,8 @@ begin
tx := tx + TypeSelector.Text;
if (Origin.Enabled and (Origin.Tag > 0)) then
tx := tx + ': ' + Origin.Text;
+ if (Stop.Enabled and (Stop.Tag > 0) and not (Stop.Text = '')and not (Stop.Text = 'Zwischenhalt')) then
+ tx := tx + ' - ' + Stop.Text;
if (Destination.Enabled and (Destination.Tag > 0)) then
tx := tx + ' - ' + Destination.Text;
FolderName.Caption := tx;