Browse Source

nun schon recht funktional

main
Stephan Richter 6 years ago
parent
commit
3abbea2fee
  1. 72
      Belegscanner.lps
  2. 134
      scanner.lfm
  3. 81
      scanner.pas

72
Belegscanner.lps

@ -9,7 +9,7 @@ @@ -9,7 +9,7 @@
<IsPartOfProject Value="True"/>
<EditorIndex Value="-1"/>
<CursorPos X="11" Y="8"/>
<UsageCount Value="27"/>
<UsageCount Value="29"/>
</Unit0>
<Unit1>
<Filename Value="scanner.pas"/>
@ -18,18 +18,18 @@ @@ -18,18 +18,18 @@
<HasResources Value="True"/>
<ResourceBaseClass Value="Form"/>
<IsVisibleTab Value="True"/>
<TopLine Value="10"/>
<CursorPos Y="50"/>
<UsageCount Value="27"/>
<TopLine Value="112"/>
<CursorPos X="73" Y="233"/>
<UsageCount Value="29"/>
<Loaded Value="True"/>
<LoadedDesigner Value="True"/>
</Unit1>
<Unit2>
<Filename Value="/usr/share/fpcsrc/3.0.4/rtl/objpas/sysutils/syshelph.inc"/>
<EditorIndex Value="-1"/>
<TopLine Value="119"/>
<TopLine Value="111"/>
<CursorPos X="14" Y="151"/>
<UsageCount Value="9"/>
<UsageCount Value="10"/>
</Unit2>
<Unit3>
<Filename Value="/usr/lib/lazarus/1.8.2/lcl/extdlgs.pas"/>
@ -81,123 +81,123 @@ @@ -81,123 +81,123 @@
<JumpHistory Count="30" HistoryIndex="29">
<Position1>
<Filename Value="scanner.pas"/>
<Caret Line="115" Column="25" TopLine="61"/>
<Caret Line="190" Column="21" TopLine="149"/>
</Position1>
<Position2>
<Filename Value="scanner.pas"/>
<Caret Line="58" Column="57" TopLine="17"/>
<Caret Line="185" Column="27" TopLine="151"/>
</Position2>
<Position3>
<Filename Value="scanner.pas"/>
<Caret Line="101" Column="63" TopLine="61"/>
<Caret Line="206" Column="9" TopLine="166"/>
</Position3>
<Position4>
<Filename Value="scanner.pas"/>
<Caret Line="109" Column="30" TopLine="69"/>
<Caret Line="195" Column="61" TopLine="166"/>
</Position4>
<Position5>
<Filename Value="scanner.pas"/>
<Caret Line="208" Column="15" TopLine="199"/>
<Caret Line="193" Column="21" TopLine="153"/>
</Position5>
<Position6>
<Filename Value="scanner.pas"/>
<Caret Line="214" Column="15" TopLine="199"/>
<Caret Line="194" Column="19" TopLine="153"/>
</Position6>
<Position7>
<Filename Value="scanner.pas"/>
<Caret Line="241" Column="104" TopLine="199"/>
<Caret Line="193" Column="21" TopLine="154"/>
</Position7>
<Position8>
<Filename Value="scanner.pas"/>
<Caret Line="97" Column="54" TopLine="40"/>
<Caret Line="195" Column="11" TopLine="154"/>
</Position8>
<Position9>
<Filename Value="scanner.pas"/>
<Caret Line="75" Column="122" TopLine="35"/>
<Caret Line="210" Column="29" TopLine="176"/>
</Position9>
<Position10>
<Filename Value="scanner.pas"/>
<Caret Line="18" Column="14" TopLine="5"/>
<Caret Line="52" Column="26" TopLine="12"/>
</Position10>
<Position11>
<Filename Value="scanner.pas"/>
<Caret Line="102" Column="18" TopLine="69"/>
<Caret Line="124" Column="32" TopLine="69"/>
</Position11>
<Position12>
<Filename Value="scanner.pas"/>
<Caret Line="105" Column="24" TopLine="64"/>
<Caret Line="128" Column="15" TopLine="98"/>
</Position12>
<Position13>
<Filename Value="scanner.pas"/>
<Caret Line="9" Column="27"/>
<Caret Line="56" Column="27" TopLine="16"/>
</Position13>
<Position14>
<Filename Value="scanner.pas"/>
<Caret Line="125" Column="25" TopLine="64"/>
<Caret Line="111" Column="28" TopLine="69"/>
</Position14>
<Position15>
<Filename Value="scanner.pas"/>
<Caret Line="141" Column="178" TopLine="85"/>
<Caret Line="124" Column="23" TopLine="70"/>
</Position15>
<Position16>
<Filename Value="scanner.pas"/>
<Caret Line="122" Column="9" TopLine="73"/>
<Caret Line="97" TopLine="79"/>
</Position16>
<Position17>
<Filename Value="scanner.pas"/>
<Caret Line="123" Column="30" TopLine="68"/>
<Caret Line="216" Column="3" TopLine="209"/>
</Position17>
<Position18>
<Filename Value="scanner.pas"/>
<Caret Line="125" Column="18" TopLine="83"/>
<Caret Line="102" TopLine="46"/>
</Position18>
<Position19>
<Filename Value="scanner.pas"/>
<Caret Line="85" Column="5" TopLine="61"/>
<Caret Line="104" TopLine="48"/>
</Position19>
<Position20>
<Filename Value="scanner.pas"/>
<Caret Line="86" Column="5" TopLine="62"/>
<Caret Line="229" Column="112" TopLine="209"/>
</Position20>
<Position21>
<Filename Value="scanner.pas"/>
<Caret Line="85" Column="5" TopLine="61"/>
<Caret Line="23" Column="29" TopLine="4"/>
</Position21>
<Position22>
<Filename Value="scanner.pas"/>
<Caret Line="84" Column="5" TopLine="60"/>
<Caret Line="29" Column="80"/>
</Position22>
<Position23>
<Filename Value="scanner.pas"/>
<Caret Line="179" TopLine="139"/>
<Caret Line="75" Column="128"/>
</Position23>
<Position24>
<Filename Value="scanner.pas"/>
<Caret Line="270" TopLine="84"/>
<Caret Line="106" Column="12" TopLine="66"/>
</Position24>
<Position25>
<Filename Value="scanner.pas"/>
<Caret Line="51" Column="20" TopLine="11"/>
<Caret Line="108" Column="26" TopLine="68"/>
</Position25>
<Position26>
<Filename Value="scanner.pas"/>
<Caret Line="175" Column="53" TopLine="111"/>
<Caret Line="305" Column="38" TopLine="252"/>
</Position26>
<Position27>
<Filename Value="scanner.pas"/>
<Caret Line="174" Column="53" TopLine="110"/>
<Caret Line="306" Column="6" TopLine="252"/>
</Position27>
<Position28>
<Filename Value="scanner.pas"/>
<Caret Line="148" Column="26" TopLine="110"/>
<Caret Line="268" Column="157" TopLine="253"/>
</Position28>
<Position29>
<Filename Value="scanner.pas"/>
<Caret Line="176" Column="28" TopLine="136"/>
<Caret Line="316" Column="106" TopLine="254"/>
</Position29>
<Position30>
<Filename Value="scanner.pas"/>
<Caret Line="266" Column="5" TopLine="212"/>
<Caret Line="75" Column="30" TopLine="50"/>
</Position30>
</JumpHistory>
</ProjectSession>

134
scanner.lfm

@ -1,50 +1,50 @@ @@ -1,50 +1,50 @@
object ScanForm: TScanForm
Left = 1534
Height = 1018
Height = 869
Top = 299
Width = 1215
Width = 1188
Caption = 'Belegscanner'
ClientHeight = 1018
ClientWidth = 1215
ClientHeight = 869
ClientWidth = 1188
OnCreate = FormCreate
LCLVersion = '1.8.2.0'
object TypeSelector: TComboBox
Left = 344
Left = 904
Height = 29
Top = 32
Width = 216
Top = 208
Width = 276
Enabled = False
ItemHeight = 0
OnChange = TypeSelectorChange
TabOrder = 3
TabOrder = 1
Text = 'Select Type'
end
object Origin: TComboBox
Left = 568
Left = 904
Height = 29
Top = 32
Width = 192
Top = 240
Width = 272
Enabled = False
ItemHeight = 0
OnChange = OriginChange
TabOrder = 5
TabOrder = 3
Text = 'Start'
end
object Destination: TComboBox
Left = 948
Left = 904
Height = 29
Top = 32
Width = 196
Top = 304
Width = 272
Enabled = False
ItemHeight = 0
OnChange = DestinationChange
TabOrder = 7
TabOrder = 5
Text = 'Ziel'
end
object FolderName: TLabel
Left = 344
Left = 8
Height = 19
Top = 64
Top = 840
Width = 103
Caption = 'Ordnername'
Font.Height = -16
@ -53,86 +53,53 @@ object ScanForm: TScanForm @@ -53,86 +53,53 @@ object ScanForm: TScanForm
ParentFont = False
end
object Product: TComboBox
Left = 568
Left = 904
Height = 29
Top = 32
Width = 192
Top = 240
Width = 276
Enabled = False
ItemHeight = 0
OnChange = ProductChange
TabOrder = 4
TabOrder = 2
Text = 'Produkt'
Visible = False
end
object ScanButton: TButton
Left = 664
Left = 904
Height = 49
Top = 88
Width = 112
Top = 400
Width = 272
Caption = 'scannen!'
Enabled = False
OnClick = ScanButtonClick
TabOrder = 8
end
object IWidth: TEdit
Left = 344
Height = 27
Top = 88
Width = 80
Alignment = taRightJustify
TabOrder = 0
Text = '209'
end
object Times: TLabel
Left = 426
Height = 17
Top = 93
Width = 6
Caption = 'x'
ParentColor = False
end
object IHeight: TEdit
Left = 440
Height = 27
Top = 88
Width = 80
TabOrder = 1
Text = '297'
end
object Pixels: TLabel
Left = 524
Height = 17
Top = 93
Width = 27
Caption = 'px @'
ParentColor = False
end
object Resolution: TComboBox
Left = 560
Left = 904
Height = 29
Top = 88
Width = 68
Top = 368
Width = 120
ItemHeight = 0
ItemIndex = 0
Items.Strings = (
'150'
'300'
)
TabOrder = 2
TabOrder = 7
Text = '150'
end
object DPI: TLabel
Left = 632
Left = 1032
Height = 17
Top = 93
Top = 376
Width = 17
Caption = 'dpi'
ParentColor = False
end
object BaseFolder: TLabel
Left = 344
Left = 8
Height = 19
Top = 8
Top = 816
Width = 88
Caption = 'BaseFolder'
Font.Height = -16
@ -142,31 +109,50 @@ object ScanForm: TScanForm @@ -142,31 +109,50 @@ object ScanForm: TScanForm
OnClick = BaseFolderClick
end
object Stop: TComboBox
Left = 768
Left = 904
Height = 29
Top = 32
Width = 176
Top = 272
Width = 272
Enabled = False
ItemHeight = 0
OnChange = StopChange
TabOrder = 6
TabOrder = 4
Text = 'Zwischenhalt'
end
object Preview: TImage
Left = 8
Height = 800
Top = 208
Width = 1200
Top = 8
Width = 880
Center = True
Proportional = True
end
object Calendar: TCalendar
Left = 8
Left = 904
Height = 190
Top = 8
Width = 324
Width = 276
DateTime = 43775
OnChange = CalendarChange
TabOrder = 0
end
object PicSize: TComboBox
Left = 904
Height = 29
Top = 336
Width = 272
ItemHeight = 0
TabOrder = 6
Text = '209 x 297 mm'
end
object DropButton: TButton
Left = 904
Height = 32
Top = 776
Width = 276
Caption = 'Löschen'
Enabled = False
OnClick = DropButtonClick
TabOrder = 9
end
object BaseFolderDialog: TSelectDirectoryDialog

81
scanner.pas

@ -13,28 +13,27 @@ type @@ -13,28 +13,27 @@ type
{ ScanThread }
ScanThread = class(TThread)
private
btn : TButton;
folder,w,h,r :String;
dbtn, sbtn : TButton;
folder,r :String;
s:TPoint;
p:TImage;
protected
procedure Execute; override;
public
constructor Create(button: TButton; dir: String; width: String; height: String; resolution: String; preview: TImage);
constructor Create(scanButton: TButton; dir: String; size: TPoint; resolution: String; preview: TImage; dropButton: TButton);
end;
{ TScanForm }
TScanForm = class(TForm)
DropButton: TButton;
Calendar: TCalendar;
PicSize: TComboBox;
Preview: TImage;
Stop: TComboBox;
DPI: TLabel;
BaseFolder: TLabel;
Resolution: TComboBox;
IHeight: TEdit;
Pixels: TLabel;
BaseFolderDialog: TSelectDirectoryDialog;
Times: TLabel;
IWidth: TEdit;
ScanButton: TButton;
Product: TComboBox;
Destination: TComboBox;
@ -43,6 +42,7 @@ type @@ -43,6 +42,7 @@ type
TypeSelector: TComboBox;
procedure BaseFolderClick(Sender: TObject);
procedure DropButtonClick(Sender: TObject);
procedure CalendarChange(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure ProductChange(Sender: TObject);
@ -58,6 +58,7 @@ type @@ -58,6 +58,7 @@ type
procedure MixLocations(d1: TComboBox; d2: TComboBox; d3: TComboBox);
private
date: TDateTime;
function getSize(): TPoint;
public
end;
@ -71,12 +72,12 @@ implementation @@ -71,12 +72,12 @@ implementation
{ ScanThread }
constructor ScanThread.Create(button: TButton; dir: String; width: String; height: String; resolution: String; preview: TImage);
constructor ScanThread.Create(scanButton: TButton; dir: String; size: TPoint; resolution: String; preview: TImage; dropButton: TButton );
begin
btn := button;
sbtn := scanButton;
dbtn := dropButton;
folder:=dir;
w:=width;
h:=height;
s:=size;
r:=resolution;
p:=preview;
inherited Create(false);
@ -92,18 +93,31 @@ begin @@ -92,18 +93,31 @@ begin
num := 0;
repeat
num := num +1;
fname := '/scan_';
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+'"');
fpSystem('scanimage -x '+IntToStr(s.x)+' -y '+IntToStr(s.y)+' --mode Color --resolution '+r+' --format jpeg > "'+folder+fname+'"');
try
pic:=TPicture.Create;
pic.LoadFromFile(folder+fname);
p.Picture:=pic;
p.Hint:=folder+fname;
finally
end;
btn.Enabled:=true;
dbtn.Hint:=folder+fname;
dbtn.Caption:=fname+' löschen';
dbtn.Enabled:=true;
sbtn.Enabled:=true;
end;
function allowed(s: String): boolean;
begin
Result := true;
if (s = '') then Result := false;
if (s = 'Start') then Result := false;
if (s = 'Ziel') then Result := false;
if (s = 'Zwischenhalt') then Result := false;
end;
procedure TScanForm.MixLocations(d1: TComboBox; d2: TComboBox; d3: TComboBox);
@ -112,9 +126,9 @@ var @@ -112,9 +126,9 @@ var
begin
list := TStringList.Create;
list.Sorted := True;
d1.Items.Add(d1.Text);
d2.Items.Add(d2.Text);
if not (d3.Text = '') then d3.Items.Add(d3.Text);
if (allowed(d1.Text)) then d1.Items.Add(d1.Text);
if (allowed(d2.Text)) then d2.Items.Add(d2.Text);
if (allowed(d3.Text)) then d3.Items.Add(d3.Text);
list.Assign(d1.Items);
list.AddStrings(d2.Items);
list.AddStrings(d3.Items);
@ -129,6 +143,7 @@ begin @@ -129,6 +143,7 @@ begin
Result := Result + 'items:' + ExportOptions(Product) + #13;
MixLocations(Origin, Destination, Stop);
Result := Result + 'locations:' + ExportOPtions(Origin) + #13;
Result := Result + 'sizes:' + ExportOptions(PicSize) +#13;
end;
function TScanForm.ExportOptions(dropDown: TComboBox): string;
@ -184,14 +199,30 @@ begin @@ -184,14 +199,30 @@ begin
UpdateFolder();
end;
function TScanForm.getSize(): TPoint;
var
arr: TStringArray;
s: String;
w, h: Integer;
begin
s:=PicSize.Text;
arr:=s.Split(['x','m']);
w:=StrToInt(arr[0].Trim);
h:=StrToInt(arr[1].Trim);
PicSize.Caption:=IntToStr(w)+' x '+IntToStr(h)+' mm';
Result := TPoint.Create(w,h);
end;
procedure TScanForm.ScanButtonClick(Sender: TObject);
var
config: TFileStream;
filename: string;
json: string;
size: TPoint;
begin
ScanButton.Enabled:=false;
filename := GetEnvironmentVariable('HOME') + '/.config/belegscanner.conf';
size := getSize();
json := ExportConfig();
try
config := TFilestream.Create(filename, fmCreate);
@ -199,7 +230,7 @@ begin @@ -199,7 +230,7 @@ begin
finally
config.Free;
end;
ScanThread.Create(ScanButton,BaseFolder.Caption+FolderName.Caption,IWidth.Caption,IHeight.Caption,Resolution.Caption,Preview);
ScanThread.Create(ScanButton,BaseFolder.Caption+FolderName.Caption+'/',size,Resolution.Caption,Preview,DropButton);
end;
procedure TScanForm.StopChange(Sender: TObject);
@ -245,6 +276,11 @@ begin @@ -245,6 +276,11 @@ begin
line := line.Substring(6);
Product.Items.AddStrings(line.Split(','));
end;
if line.StartsWith('sizes:') then
begin
line := line.Substring(6);
PicSize.Items.AddStrings(line.Split(','));
end;
if line.StartsWith('locations:') then
begin
line := line.Substring(10);
@ -264,13 +300,20 @@ begin @@ -264,13 +300,20 @@ begin
BaseFolder.Caption := BaseFolderDialog.FileName;
end;
procedure TScanForm.DropButtonClick(Sender: TObject);
begin
DeleteFile(DropButton.Hint);
Preview.Picture:=nil;
DropButton.Enabled:=false;
end;
procedure TScanForm.UpdateFolder();
var
tx: string;
begin
tx := FormatDateTime('YYYY', date) + '/' + FormatDateTime('YYYY-MM-DD', date) + ' - ';
if (Product.Enabled and (Product.Tag > 0)) then
if (Product.Enabled and (Product.Tag > 0) and not( Product.Text = '') and not (Product.Text = 'Produkt')) then
tx := tx + Product.Text + ' von ';
if (TypeSelector.Tag > 0) then
tx := tx + TypeSelector.Text;

Loading…
Cancel
Save