Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* scan.ahk BOOK OF CONWORLDS SCAN PROCESSING SYSTEM
- VERSION 3.β.23.00
- — Isoraķatheð Zorethan Füzokhalye "Lelyan"
- (cc-by-sa-3.0)
- */
- #SingleInstance force
- #Ltrim
- ;BeginRegion Globals
- IniRead Book, scan.ini, scan2, book
- IniRead pathin, scan.ini, scan2, pathin
- IniRead pathout, scan.ini, scan2, pathout
- IniRead JpegCropLoc, scan.ini, scan2, jpegcrop
- IniRead JpegRotate, scan.ini, scan2, jpegrot
- IniRead langsDescs, scan.ini, languages
- IniRead PlanetsDescs, scan.ini, planets
- inFile = %pathin%Scan.jpeg
- loop parse, langsDescs, `n, %A_Space%
- {
- ;ifEqual, A_index, 0, continue
- StringSplit data, A_LoopField, =, %A_Space%
- langsNames .= "|" . data1
- }
- loop parse, PlanetsDescs, `n, %A_Space%
- {
- StringSplit data, A_LoopField, =, %A_Space%
- worldNames .= "|" . data1
- }
- othersDescs = These do not have a value, so the placeholder Nnn is used.
- ;EndRegion
- ;BeginRegion GUI Creation
- GUI -Resize -MaximizeBox
- GUI font, s9, Segoe UI
- ;BeginRegion Starting Image
- GUI add, GroupBox, w575 r2, Starting Image
- GUI add, text, w300 r1 yp+25 xp+15 vInPath, %inFile%
- GUI add, button, w100 r1 yp-5 xp+425 gChangePath, Change
- ;EndRegion StartingImage
- ;BeginRegion Filename
- GUI add, button, xm yp+45 gCalculate, Estimate Correct Name
- GUI add, tab2, w575 r12 section vDestType gUpdate, BoC|MoR|Non-BoC Conworld|Non-Conworld
- ;BeginRegion Conworld pages
- GUI tab, BoC
- GUI add, text, xm+30 ys+30, Page Category
- GUI add, radio, w100 yp xp+95 gLang vlangss Checked, Languages
- GUI add, radio, w100 yp xp+105 gWorld vworld, Planets
- GUI add, radio, w100 yp xp+105 gOther vother, Other
- GUI add, Edit, w50 xm+30 yp+30 vDispBook
- GUI add, Updown, vBook Range1-99, %Book%
- GUI add, Text, yp xp+55, :
- GUI add, Edit, w50 yp xp+10 vDispPage
- GUI add, Updown, vPage Range1-99, 1
- GUI add, Edit, w50 yp xp+65 vDispSubpage
- GUI add, Updown, vSubpage gSubpageLetter Range1-26, 1
- GUI add, Text, yp xp+55, -
- GUI add, DropDownList, w50 limit3 yp xp+10 vLangSuffix, Trl|%langsNames%
- GUI add, Text, yp xp+55, -
- GUI add, Edit, w210 yp xp+10 vPageName, Untitled
- GUI add, text, yp xp+215, .jpg
- ; ----- labels
- GUI add, text, xm+36 yp+23 c888888, Book #
- GUI add, text, xp+65 yp c888888, Page #
- GUI add, text, xp+60 yp c888888 w56, Subpage letter
- GUI add, text, xp+74 yp c888888 w56, Code
- GUI add, text, xp+140 yp c888888, Page title
- GUI add, text, xm+30 yp+35 w500 vDestDesc, %LangsDescs%
- ;EndRegion Conworld pages
- ;BeginRegion Non-Book conworld pages
- GUI tab, Non-BoC
- GUI add, text, w85 xm+30 ys+30, Page Category
- GUI add, radio, w100 yp xp+95 gNBoCLang vNBoClangss Checked, Languages
- GUI add, radio, w100 yp xp+105 gNBoCWorld vNBoCworld, Planets
- GUI add, radio, w100 yp xp+105 gNBoCOther vNBoCother, Other
- GUI add, Edit, w50 xm+30 yp+30 vNBoCDispPage
- GUI add, Updown, vNBoCPage Range1-99, 1
- GUI add, Edit, w50 yp xp+65 vNBoCDispSubpage
- GUI add, Updown, vNBoCSubpage gSubpageLetter Range1-26, 1
- GUI add, Text, yp xp+55, -
- GUI add, DropDownList, w50 limit3 yp xp+10 vNBoCLangSuffix, Trl|%langsNames%
- GUI add, Text, yp xp+55, -
- GUI add, Edit, w210 yp xp+10 vNBoCPageName, Untitled
- GUI add, text, yp xp+215, .jpg
- ; ----- labels
- GUI add, text, xm+35 yp+25 c888888, Page #
- GUI add, text, xp+60 yp c888888 w56, Subpage letter
- GUI add, text, xp+74 yp c888888 w56, Code
- GUI add, text, xp+140 yp c888888, Page title
- GUI add, text, xm+30 yp+35 w500 vNBoCDestDesc, %LangsDescs%
- ;EndRegion Non-Book conworld pages
- ;BeginRegion Misc Pages
- GUI tab, Non-Conworld
- GUI add, edit, xm+30 ys+30 w70 r1 vMiscScans readOnly, Scan0000
- GUI add, text, xp+75 yp r1, .jpg
- GUI add, text, xm+48 yp+23 c888888, Serial
- ;EndRegion Misc Pages
- ;BeginRegion Month-in-Review pages
- GUI tab, MoR
- GUI add, dateTime, w100 xm+30 ys+30 vDestIfDate, yyyy-MM
- GUI add, text, yp xp+105, .jpg
- GUI add, text, xp-85 yp+23 c888888, MOR Month
- ;EndRegion Month-in-Review pages
- GUI tab
- ;EndRegion Filename
- ;BeginRegion Additional Options
- GUI add, GroupBox, xm w280 r3 section, Additional Options
- GUI add, CheckBox, w50 yp+25 xp+15 vCrop Checked, Crop
- GUI add, CheckBox, yp xp+55 vLeave, Make copy of original
- ;EndRegion Additional Options
- ;BeginRegion Rotate
- GUI add, GroupBox, ys xm+290 w285 r3, Rotate?
- GUI add, Radio, vRotN w50 yp+25 xp+15 Checked, 0°
- GUI add, Radio, vRotU w50 yp xp+55, 180°
- GUI add, Radio, vRotR w50 yp xp+55, +90°
- GUI add, Radio, vRotL w50 yp xp+55, −90°
- ;EndRegion Rotate
- ;BeginRegion Destination File
- GUI add, GroupBox, xm w875 r2, Destination file path
- GUI add, edit, readOnly w850 yp+25 xp+15 vFinalDest, \\psf\Home\Documents\My Scans\
- ;EndRegion Destination
- ;BeginRegion Check for Existence
- GUI add, GroupBox, xm+600 ym w275 r4 section, Check for Existence
- GUI add, button, w100 r1 yp+25 xp+15 gCheckExist, Input File
- GUI add, text, yp+5 xp+125 c888888 vExistState, Undetermined
- GUI add, button, w100 r1 yp+25 xs+15 gCheckExistOut, Output Serial
- GUI add, text, yp+5 xp+125 c888888 vExistStateOut, Undetermined
- ;EndRegion Check for Existence
- ;BeginRegion Action!
- GUI add, GroupBox, xs w275 r4, Action
- GUI add, button, w250 yp+25 xp+15 gUpdate, Update destination
- GUI add, button, w250 gBegin vBegin Disabled, Begin!
- ;EndRegion Action!
- ;BeginRegion Exiting
- GUI add, GroupBox, xs w275 h162, Exiting Commands
- GUI add, button, w250 gEndProgram yp+25 xp+15, Exit.
- GUI add, button, w250 gReloadProgram, Reload.
- GUI add, button, w250 gShowFolder vShowFolder +Disabled, Show Destination Folder.
- GUI add, button, w250 gShowFolderExit vShowFolderExit +Disabled, Show Destination Folder and Exit.
- ;EndRegion Exiting
- ;BeginRegion Meta
- GUI add, GroupBox, xs w275 r3, Meta
- GUI add, text, c888888 yp+25 xp+15,
- (
- Book of Conworlds Scan Processing System
- Version: v.3.β.54.00
- )
- GUI add, StatusBar,, Ready
- ;EndRegion
- GUI show, Center, scan.ahk Book Of Conworlds Scan Processing System
- GUIControl,, DispSubpage, a
- GUIControl,, NBoCDispSubpage, a
- Return
- ;EndRegion GUI creation
- ;BeginRegion Main Action Sequence
- Begin:
- GoSub Update
- GUI submit, noHide
- ;Set copy
- SB_SetText("Copying…")
- if Leave
- FileCopy %inPath%, %inPath%_c
- ;Set crop
- SB_SetText("Cropping…")
- if Crop
- RunWait %comspec% /c ""%JpegCropLoc%" "%InFile%"", Z:\Documents\AHK Scripts, Hide
- ;Set rotate
- SB_SetText("Rotating…")
- if RotU
- turn = u
- else if RotR
- turn = r
- else if RotL
- turn = l
- if turn
- RunWait %comspec% /c ""%JpegRotate%" -%turn% -s "%InFile%"", Z:\Documents\AHK Scripts, Hide
- turn =
- ;Move
- SB_SetText("Moving…")
- FileMove %InFile%, %FinalDest%
- if Leave
- {
- SB_SetText("Restoring…")
- FileMove %InFile%_c, %InFile%
- }
- ;Activate exit
- GUIControl, Enable, ShowFolder
- GUIControl, Enable, ShowFolderExit
- SB_SetText("Ready")
- Return
- ;EndRegion Main Action Sequence
- ;BeginRegion Button Subroutines
- ;BeginRegion Language code swappers
- NBoCLang:
- GUIControl, enable, NBoCLangSuffix
- GUIControl,, NBoCLangSuffix, |Trl|%langsNames%
- GUIControl,, NBoCDestDesc, %LangsDescs%
- Return
- Lang:
- GUIControl, enable, LangSuffix
- GUIControl,, LangSuffix, |Trl|%langsNames%
- GUIControl,, DestDesc, %LangsDescs%
- NBoCWorld:
- GUIControl, enable, NBoCLangSuffix
- GUIControl,, NBoCLangSuffix, |Tpl|%worldNames%
- GUIControl,, NBoCDestDesc, %PlanetsDescs%
- Return
- World:
- GUIControl, enable, LangSuffix
- GUIControl,, LangSuffix, |Tpl|%worldNames%
- GUIControl,, DestDesc, %PlanetsDescs%
- Return
- NBoCOther:
- GUIControl,, NBoCLangSuffix, |Nnn||
- GUIControl, disable, NBoCLangSuffix
- GUIControl,, NBoCDestDesc, %othersDescs%
- Return
- Other:
- GUIControl,, LangSuffix, |Nnn||
- GUIControl, disable, LangSuffix
- GUIControl,, DestDesc, %othersDescs%
- Return
- ;EndRegion Language Code swappers
- Update: ;BeginRegion Update Exit Code
- GUIControlGet, actualDestType,, DestType
- if actualDestType = BoC
- GoSub SelBoC
- else if actualDestType = MoR
- GoSub SelMoR
- else if actualDestType = Non-BoC Conworld
- GoSub SelConworld
- else
- GoSub SelNotConworld
- Return ;EndRegion Update Exit Code
- SelBoC: ;BeginRegion SelectBOC
- GUIControlGet, FinalBookNumber,, Book
- GUIControlGet, FinalPageNumber,, Page
- GUIControlGet, FinalSubpageNumber,, DispSubpage
- GUIControlGet, FinalPageName,, PageName
- GUIControlGet, FinalLangSuffix,, LangSuffix
- FinalPageNumber := SubStr("0" . FinalPageNumber, -1)
- GUIControl,, FinalDest, %pathout%Book of Conworlds\Book %FinalBookNumber%\%FinalPageNumber%%FinalSubpageNumber%-%FinalLangSuffix%-%FinalPageName%.jpg
- Return ;EndRegion SelectBOC
- SelMoR: ;BeginRegion SelectMonthReview
- GUIControlGet, FinalDate,, DestIfDate
- FormatTime, FinalDate, %FinalDate%, yyyy-MM
- GUIControl,, FinalDest, %pathout%Book of Conworlds\Non-BoC\Months in Review\%FinalDate%.jpg
- Return ;EndRegion SelectMonthReview
- SelConworld: ;BeginRegion SelectConworld
- FormatTime, FinalDate,, yyyy-MM (MMM)
- GUIControlGet, FinalPageNumber,, NBoCPage
- GUIControlGet, FinalSubpageNumber,, NBoCDispSubpage
- GUIControlGet, FinalPageName,, NBoCPageName
- GUIControlGet, FinalLangSuffix,, NBoCLangSuffix
- FinalPageNumber := SubStr("0" . FinalPageNumber, -1)
- GUIControl,, FinalDest, %pathout%Book of Conworlds\Non-BoC\%FinalDate%\%FinalPageNumber%%FinalSubpageNumber%-%FinalLangSuffix%-%FinalPageName%.jpg
- Return ;EndRegion SelectConworld
- SelNotConworld: ;BeginRegion SelectNotConworld
- FormatTime, FinalDate,, yyyy-MM (MMM)
- GUIControlGet, FinalFileName,, MiscScans
- GUIControl,, FinalDest, %pathout%Unsorted By Date\%FinalDate%\%FinalFileName%.jpg
- Return ;EndRegion Select Not Conworld
- ChangePath: ;BeginRegion Change Path
- FileSelectFile inFile, 3, %inFile%
- GUIControl,, InPath, %inFile%
- Return ;EndRegion change Path
- CheckExist: ;BeginRegion Check if input exists
- GUIControlGet, checkFile,, inPath
- IfExist %checkFile%
- {
- GUI font, cGreen
- GUIControl, font, ExistState
- GUIControl,, ExistState, Existent
- GUIControlGet, otherItem,, ExistStateOut
- if otherItem = Serial unused
- GUIControl, enable, Begin
- else, GUIControl, disable, Begin
- }
- else
- {
- GUI font, cRed
- GUIControl font, ExistState
- GUIControl,, ExistState, Nonexistent
- GUIControl, disable, Begin
- }
- GUI font, cDefault
- Return ;EndRegion Check if input exists
- CheckExistOut: ;BeginRegion Check if output exists
- goSub Update
- GUIControlGet, testFile,, FinalDest
- If InStr(testFile, "Unsorted By Date") or RegexMatch(testFile, "20[0-9][0-9]-[0-9][0-9].jpg") {
- ;Basic unsorted files & Months in Review
- IfExist %testFile%
- goSub outFileExists
- else
- goSub outFileDoesNotExist
- }
- else { ;Conworld-related items have serial numbers
- testFileReplaced := RegexReplace(testFile, "(\\\d\d.)-.+\.jpg$", "$1-*.jpg")
- ;MsgBox %testFileReplaced%
- ifExist %testFileReplaced%
- goSub outFileExists
- else
- goSub outFileDoesNotExist
- }
- GUI font, cDefault
- Return ;EndRegion Check if output Exists
- outFileExists:
- GUI font, cRed
- GUIControl font, ExistStateOut
- GUIControl,, ExistStateOut, Serial used
- GUIControl, disable, Begin
- Return
- outFileDoesNotExist:
- GUI font, cGreen
- GUIControl, font, ExistStateOut
- GUIControl,, ExistStateOut, Serial unused
- GUIControlGet, otherItem,, ExistState
- If otherItem = Existent
- GUIControl, enable, Begin
- else, GUIControl, disable, Begin
- Return
- Calculate: ;BeginRegion Calculate Correct Name Estimation
- GUIControlGet, actualDestType,, DestType
- if actualDestType = BoC
- {
- GUIControlGet, testBookNumber,, Book
- Loop 99 { ;Page number
- if mod(A_Index, 5) = 1 {
- SB_SetText("Checking pages " . A_Index . " to " . (A_Index + 4) . "…")
- }
- testPageNumber := SubStr("0" . A_Index, -1)
- IfNotExist %pathout%Book of Conworlds\Book %testBookNumber%\%testPageNumber%?-*.jpg
- {
- GUIControl,, Page, %testPageNumber%
- MsgBox, 4, Slot Open, There is a slot open at page %A_Index%. Do you wish to populate it?
- IfMsgBox Yes
- {
- SB_SetText("Ready")
- break
- }
- else, continue
- }
- }
- }
- else if actualDestType = MoR
- {
- PrevMonth := A_Now
- PrevMonth += -30, days
- GUIControl,, DestIfDate, %PrevMonth%
- }
- else if actualDestType = Non-BoC Conworld
- {
- FormatTime, testDate,, yyyy-MM (MMM)
- Loop 99 {
- testPageNumber := SubStr("0" . (A_Index), -1)
- if mod(A_Index, 5) = 1 {
- SB_SetText("Checking pages " . A_Index . " to " . (A_Index + 4) . "…")
- }
- IfNotExist %pathout%Book of Conworlds\Non-BoC\%testDate%\%testPageNumber%?-*.jpg
- {
- GUIControl,, NBoCPage, %testPageNumber%
- SB_SetText("Ready")
- break
- }
- }
- }
- else
- {
- FormatTime, testDate,, yyyy-MM (MMM)
- Loop 10000 {
- testPageNumber := SubStr("000" . (A_Index - 1), -3)
- if mod(A_Index, 5) = 1 {
- SB_SetText("Checking pages " . A_Index . " to " . (A_Index + 4) . "…")
- }
- IfNotExist %pathout%Unsorted By Date\%testDate%\Scan%testPageNumber%.jpg
- {
- GUIControl,, MiscScans, Scan%testPageNumber%
- SB_SetText("Ready")
- break
- }
- }
- }
- Return ;EndRegion Calculate Correct Name Estimation
- EndProgram: ;BeginRegion End Program
- GUI destroy
- ExitApp
- ;EndRegion End Program
- ReloadProgram: ;BeginRegion Reload Program
- Reload
- Return ;EndRegion Reload Program
- !a:: ;BeginRegion Focus on LangSuffix
- GUIControl, Focus, LangSuffix
- Return ;EndRegion Focus on LangSuffix
- OnExit: ;BeginRegion Exit
- GUI Destroy
- ExitApp ;EndRegion exit
- ShowFolder: ;BeginRegion Show Folder
- oneLess := FinalDest
- Loop 512 {
- StringRight testLetter, oneLess, 1
- if testLetter = \
- break
- else
- StringTrimRight oneLess, oneLess, 1
- }
- Run, %oneLess%
- ;MsgBox %oneLess%
- Return ;EndRegion Show Folder
- ShowFolderExit: ;BeginRegion Show Folder and Exit
- GoSub ShowFolder
- ExitApp
- Return ;EndRegion Show Folder and Exit
- SubpageLetter: ;BeginRegion Subpage Number-to-letter
- GUIControlGet, subpageValue,, Subpage
- subpageValue := Chr(subpageValue + 96)
- GUIControl,, DispSubpage, %subpageValue%
- GUIControlGet, subpageValue,, NBoCSubpage
- subpageValue := Chr(subpageValue + 96)
- GUIControl,, NBoCDispSubpage, %subpageValue%
- Return ;EndRegion Subpage Number-to-letter
- ;EndRegion Button Subroutines
Advertisement
Add Comment
Please, Sign In to add comment