Isoraqathedh

scan.ahk

Sep 12th, 2013
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*  scan.ahk BOOK OF CONWORLDS SCAN PROCESSING SYSTEM
  2.     VERSION 3.β.23.00
  3.     — Isoraķatheð Zorethan Füzokhalye "Lelyan"
  4.     (cc-by-sa-3.0)
  5. */
  6. #SingleInstance force
  7. #Ltrim
  8. ;BeginRegion Globals
  9. IniRead Book, scan.ini, scan2, book
  10. IniRead pathin, scan.ini, scan2, pathin
  11. IniRead pathout, scan.ini, scan2, pathout
  12. IniRead JpegCropLoc, scan.ini, scan2, jpegcrop
  13. IniRead JpegRotate, scan.ini, scan2, jpegrot
  14. IniRead langsDescs, scan.ini, languages
  15. IniRead PlanetsDescs, scan.ini, planets
  16. inFile = %pathin%Scan.jpeg
  17. loop parse, langsDescs, `n, %A_Space%
  18. {
  19.     ;ifEqual, A_index, 0, continue
  20.     StringSplit data, A_LoopField, =, %A_Space%
  21.     langsNames .= "|" . data1
  22. }
  23. loop parse, PlanetsDescs, `n, %A_Space%
  24. {
  25.     StringSplit data, A_LoopField, =, %A_Space%
  26.     worldNames .= "|" . data1
  27. }
  28. othersDescs = These do not have a value, so the placeholder Nnn is used.
  29. ;EndRegion
  30. ;BeginRegion GUI Creation
  31. GUI -Resize -MaximizeBox
  32. GUI font, s9, Segoe UI
  33. ;BeginRegion Starting Image
  34.     GUI add, GroupBox, w575 r2, Starting Image
  35.     GUI add, text, w300 r1 yp+25 xp+15 vInPath, %inFile%
  36.     GUI add, button, w100 r1 yp-5 xp+425 gChangePath, Change
  37. ;EndRegion StartingImage
  38. ;BeginRegion Filename
  39.     GUI add, button, xm yp+45 gCalculate, Estimate Correct Name
  40.     GUI add, tab2, w575 r12 section vDestType gUpdate, BoC|MoR|Non-BoC Conworld|Non-Conworld
  41.     ;BeginRegion Conworld pages
  42.         GUI tab, BoC
  43.         GUI add, text, xm+30 ys+30, Page Category
  44.         GUI add, radio, w100 yp xp+95 gLang vlangss Checked, Languages
  45.         GUI add, radio, w100 yp xp+105 gWorld vworld, Planets
  46.         GUI add, radio, w100 yp xp+105 gOther vother, Other
  47.         GUI add, Edit, w50 xm+30 yp+30 vDispBook
  48.         GUI add, Updown, vBook Range1-99, %Book%
  49.         GUI add, Text, yp xp+55, :
  50.         GUI add, Edit, w50 yp xp+10 vDispPage
  51.         GUI add, Updown, vPage Range1-99, 1
  52.         GUI add, Edit, w50 yp xp+65 vDispSubpage
  53.         GUI add, Updown, vSubpage gSubpageLetter Range1-26, 1
  54.         GUI add, Text, yp xp+55, -
  55.         GUI add, DropDownList, w50 limit3 yp xp+10 vLangSuffix, Trl|%langsNames%
  56.         GUI add, Text, yp xp+55, -
  57.         GUI add, Edit, w210 yp xp+10 vPageName, Untitled
  58.         GUI add, text, yp xp+215, .jpg
  59.         ; ----- labels
  60.         GUI add, text, xm+36 yp+23 c888888, Book #
  61.         GUI add, text, xp+65 yp c888888, Page #
  62.         GUI add, text, xp+60 yp c888888 w56, Subpage letter
  63.         GUI add, text, xp+74 yp c888888 w56, Code
  64.         GUI add, text, xp+140 yp c888888, Page title
  65.         GUI add, text, xm+30 yp+35 w500 vDestDesc, %LangsDescs%
  66.     ;EndRegion Conworld pages
  67.     ;BeginRegion Non-Book conworld pages
  68.         GUI tab, Non-BoC
  69.         GUI add, text, w85 xm+30 ys+30, Page Category
  70.         GUI add, radio, w100 yp xp+95 gNBoCLang vNBoClangss Checked, Languages
  71.         GUI add, radio, w100 yp xp+105 gNBoCWorld vNBoCworld, Planets
  72.         GUI add, radio, w100 yp xp+105 gNBoCOther vNBoCother, Other
  73.         GUI add, Edit, w50 xm+30 yp+30 vNBoCDispPage
  74.         GUI add, Updown, vNBoCPage Range1-99, 1
  75.         GUI add, Edit, w50 yp xp+65 vNBoCDispSubpage
  76.         GUI add, Updown, vNBoCSubpage gSubpageLetter Range1-26, 1
  77.         GUI add, Text, yp xp+55, -
  78.         GUI add, DropDownList, w50 limit3 yp xp+10 vNBoCLangSuffix, Trl|%langsNames%
  79.         GUI add, Text, yp xp+55, -
  80.         GUI add, Edit, w210 yp xp+10 vNBoCPageName, Untitled
  81.         GUI add, text, yp xp+215, .jpg
  82.         ; ----- labels
  83.         GUI add, text, xm+35 yp+25 c888888, Page #
  84.         GUI add, text, xp+60 yp c888888 w56, Subpage letter
  85.         GUI add, text, xp+74 yp c888888 w56, Code
  86.         GUI add, text, xp+140 yp c888888, Page title
  87.         GUI add, text, xm+30 yp+35 w500 vNBoCDestDesc, %LangsDescs%
  88.     ;EndRegion Non-Book conworld pages
  89.     ;BeginRegion Misc Pages
  90.         GUI tab, Non-Conworld
  91.         GUI add, edit, xm+30 ys+30 w70 r1 vMiscScans readOnly, Scan0000
  92.         GUI add, text, xp+75 yp r1, .jpg
  93.         GUI add, text, xm+48 yp+23 c888888, Serial
  94.     ;EndRegion Misc Pages
  95.     ;BeginRegion Month-in-Review pages
  96.         GUI tab, MoR
  97.         GUI add, dateTime, w100 xm+30 ys+30 vDestIfDate, yyyy-MM
  98.         GUI add, text, yp xp+105, .jpg
  99.         GUI add, text, xp-85 yp+23 c888888, MOR Month  
  100.     ;EndRegion Month-in-Review pages
  101.     GUI tab
  102. ;EndRegion Filename
  103. ;BeginRegion Additional Options
  104.     GUI add, GroupBox, xm w280 r3 section, Additional Options
  105.     GUI add, CheckBox, w50 yp+25 xp+15 vCrop Checked, Crop
  106.     GUI add, CheckBox, yp xp+55 vLeave, Make copy of original
  107. ;EndRegion Additional Options
  108. ;BeginRegion Rotate
  109.     GUI add, GroupBox, ys xm+290 w285 r3, Rotate?
  110.     GUI add, Radio, vRotN w50 yp+25 xp+15 Checked, 0°
  111.     GUI add, Radio, vRotU w50 yp xp+55, 180°
  112.     GUI add, Radio, vRotR w50 yp xp+55, +90°
  113.     GUI add, Radio, vRotL w50 yp xp+55,90°
  114. ;EndRegion Rotate
  115. ;BeginRegion Destination File
  116.     GUI add, GroupBox, xm w875 r2, Destination file path
  117.     GUI add, edit, readOnly w850 yp+25 xp+15 vFinalDest, \\psf\Home\Documents\My Scans\
  118. ;EndRegion Destination
  119. ;BeginRegion Check for Existence
  120.     GUI add, GroupBox, xm+600 ym w275 r4 section, Check for Existence
  121.     GUI add, button, w100 r1 yp+25 xp+15 gCheckExist, Input File
  122.     GUI add, text, yp+5 xp+125 c888888 vExistState, Undetermined
  123.     GUI add, button, w100 r1 yp+25 xs+15 gCheckExistOut, Output Serial
  124.     GUI add, text, yp+5 xp+125 c888888 vExistStateOut, Undetermined
  125. ;EndRegion Check for Existence
  126. ;BeginRegion Action!
  127.     GUI add, GroupBox, xs w275 r4, Action
  128.     GUI add, button, w250 yp+25 xp+15 gUpdate, Update destination
  129.     GUI add, button, w250 gBegin vBegin Disabled, Begin!
  130. ;EndRegion Action!
  131. ;BeginRegion Exiting
  132.     GUI add, GroupBox, xs w275 h162, Exiting Commands
  133.     GUI add, button, w250 gEndProgram yp+25 xp+15, Exit.
  134.     GUI add, button, w250 gReloadProgram, Reload.
  135.     GUI add, button, w250 gShowFolder vShowFolder +Disabled, Show Destination Folder.
  136.     GUI add, button, w250 gShowFolderExit vShowFolderExit +Disabled, Show Destination Folder and Exit.
  137. ;EndRegion Exiting
  138. ;BeginRegion Meta
  139. GUI add, GroupBox, xs w275 r3, Meta
  140. GUI add, text, c888888 yp+25 xp+15,
  141. (
  142. Book of Conworlds Scan Processing System
  143. Version: v.3.β.54.00
  144. )
  145. GUI add, StatusBar,, Ready
  146. ;EndRegion
  147. GUI show, Center, scan.ahk Book Of Conworlds Scan Processing System
  148. GUIControl,, DispSubpage, a
  149. GUIControl,, NBoCDispSubpage, a
  150. Return
  151. ;EndRegion GUI creation
  152.  
  153.  
  154.  
  155. ;BeginRegion Main Action Sequence
  156. Begin:
  157.     GoSub Update
  158.     GUI submit, noHide
  159.     ;Set copy
  160.     SB_SetText("Copying…")
  161.     if Leave
  162.         FileCopy %inPath%, %inPath%_c
  163.     ;Set crop
  164.     SB_SetText("Cropping…")
  165.     if Crop
  166.         RunWait %comspec% /c ""%JpegCropLoc%" "%InFile%"", Z:\Documents\AHK Scripts, Hide
  167.     ;Set rotate
  168.     SB_SetText("Rotating…")
  169.     if RotU
  170.         turn = u
  171.     else if RotR
  172.         turn = r
  173.     else if RotL
  174.         turn = l
  175.     if turn
  176.         RunWait %comspec% /c ""%JpegRotate%" -%turn% -s "%InFile%"", Z:\Documents\AHK Scripts, Hide
  177.     turn =
  178.     ;Move
  179.     SB_SetText("Moving…")
  180.     FileMove %InFile%, %FinalDest%
  181.     if Leave
  182.     {
  183.         SB_SetText("Restoring…")
  184.         FileMove %InFile%_c, %InFile%
  185.     }
  186.     ;Activate exit
  187.     GUIControl, Enable, ShowFolder
  188.     GUIControl, Enable, ShowFolderExit
  189.     SB_SetText("Ready")
  190. Return
  191. ;EndRegion Main Action Sequence
  192.  
  193.  
  194.  
  195. ;BeginRegion Button Subroutines
  196. ;BeginRegion Language code swappers
  197. NBoCLang:
  198.     GUIControl, enable, NBoCLangSuffix
  199.     GUIControl,, NBoCLangSuffix, |Trl|%langsNames%
  200.     GUIControl,, NBoCDestDesc, %LangsDescs%
  201. Return
  202. Lang:
  203.     GUIControl, enable, LangSuffix
  204.     GUIControl,, LangSuffix, |Trl|%langsNames%
  205.     GUIControl,, DestDesc, %LangsDescs%
  206. NBoCWorld:
  207.     GUIControl, enable, NBoCLangSuffix
  208.     GUIControl,, NBoCLangSuffix, |Tpl|%worldNames%
  209.     GUIControl,, NBoCDestDesc, %PlanetsDescs%
  210. Return
  211. World:
  212.     GUIControl, enable, LangSuffix
  213.     GUIControl,, LangSuffix, |Tpl|%worldNames%
  214.     GUIControl,, DestDesc, %PlanetsDescs%
  215. Return
  216. NBoCOther:
  217.     GUIControl,, NBoCLangSuffix, |Nnn||
  218.     GUIControl, disable, NBoCLangSuffix
  219.     GUIControl,, NBoCDestDesc, %othersDescs%
  220. Return
  221. Other:
  222.     GUIControl,, LangSuffix, |Nnn||
  223.     GUIControl, disable, LangSuffix
  224.     GUIControl,, DestDesc, %othersDescs%
  225. Return
  226. ;EndRegion Language Code swappers
  227. Update: ;BeginRegion Update Exit Code
  228.     GUIControlGet, actualDestType,, DestType
  229.     if actualDestType = BoC
  230.         GoSub SelBoC
  231.     else if actualDestType = MoR
  232.         GoSub SelMoR
  233.     else if actualDestType = Non-BoC Conworld
  234.         GoSub SelConworld
  235.     else
  236.         GoSub SelNotConworld
  237. Return ;EndRegion Update Exit Code
  238. SelBoC: ;BeginRegion SelectBOC
  239.     GUIControlGet, FinalBookNumber,, Book
  240.     GUIControlGet, FinalPageNumber,, Page
  241.     GUIControlGet, FinalSubpageNumber,, DispSubpage
  242.     GUIControlGet, FinalPageName,, PageName
  243.     GUIControlGet, FinalLangSuffix,, LangSuffix
  244.     FinalPageNumber := SubStr("0" . FinalPageNumber, -1)
  245.     GUIControl,, FinalDest, %pathout%Book of Conworlds\Book %FinalBookNumber%\%FinalPageNumber%%FinalSubpageNumber%-%FinalLangSuffix%-%FinalPageName%.jpg
  246. Return ;EndRegion SelectBOC
  247. SelMoR: ;BeginRegion SelectMonthReview
  248.     GUIControlGet, FinalDate,, DestIfDate
  249.     FormatTime, FinalDate, %FinalDate%, yyyy-MM
  250.     GUIControl,, FinalDest, %pathout%Book of Conworlds\Non-BoC\Months in Review\%FinalDate%.jpg
  251. Return ;EndRegion SelectMonthReview
  252. SelConworld: ;BeginRegion SelectConworld
  253.     FormatTime, FinalDate,, yyyy-MM (MMM)
  254.     GUIControlGet, FinalPageNumber,, NBoCPage
  255.     GUIControlGet, FinalSubpageNumber,, NBoCDispSubpage
  256.     GUIControlGet, FinalPageName,, NBoCPageName
  257.     GUIControlGet, FinalLangSuffix,, NBoCLangSuffix
  258.     FinalPageNumber := SubStr("0" . FinalPageNumber, -1)
  259.     GUIControl,, FinalDest, %pathout%Book of Conworlds\Non-BoC\%FinalDate%\%FinalPageNumber%%FinalSubpageNumber%-%FinalLangSuffix%-%FinalPageName%.jpg
  260. Return ;EndRegion SelectConworld
  261. SelNotConworld: ;BeginRegion SelectNotConworld
  262.     FormatTime, FinalDate,, yyyy-MM (MMM)
  263.     GUIControlGet, FinalFileName,, MiscScans
  264.     GUIControl,, FinalDest, %pathout%Unsorted By Date\%FinalDate%\%FinalFileName%.jpg
  265. Return ;EndRegion Select Not Conworld
  266. ChangePath: ;BeginRegion Change Path
  267.     FileSelectFile inFile, 3, %inFile%
  268.     GUIControl,, InPath, %inFile%
  269. Return ;EndRegion change Path
  270. CheckExist: ;BeginRegion Check if input exists
  271.     GUIControlGet, checkFile,, inPath
  272.     IfExist %checkFile%
  273.     {
  274.         GUI font, cGreen
  275.         GUIControl, font, ExistState
  276.         GUIControl,, ExistState, Existent
  277.         GUIControlGet, otherItem,, ExistStateOut
  278.         if otherItem = Serial unused
  279.             GUIControl, enable, Begin
  280.         else, GUIControl, disable, Begin
  281.     }
  282.     else
  283.     {
  284.         GUI font, cRed
  285.         GUIControl font, ExistState
  286.         GUIControl,, ExistState, Nonexistent
  287.         GUIControl, disable, Begin
  288.     }
  289.     GUI font, cDefault
  290. Return ;EndRegion Check if input exists
  291. CheckExistOut: ;BeginRegion Check if output exists
  292.     goSub Update
  293.     GUIControlGet, testFile,, FinalDest
  294.     If InStr(testFile, "Unsorted By Date") or RegexMatch(testFile, "20[0-9][0-9]-[0-9][0-9].jpg") {
  295.         ;Basic unsorted files & Months in Review
  296.         IfExist %testFile%
  297.             goSub outFileExists
  298.         else
  299.             goSub outFileDoesNotExist
  300.     }
  301.     else { ;Conworld-related items have serial numbers
  302.         testFileReplaced := RegexReplace(testFile, "(\\\d\d.)-.+\.jpg$", "$1-*.jpg")
  303.         ;MsgBox %testFileReplaced%
  304.         ifExist %testFileReplaced%
  305.             goSub outFileExists
  306.         else
  307.             goSub outFileDoesNotExist
  308.     }
  309.     GUI font, cDefault
  310. Return ;EndRegion Check if output Exists
  311. outFileExists:
  312.     GUI font, cRed
  313.     GUIControl font, ExistStateOut
  314.     GUIControl,, ExistStateOut, Serial used
  315.     GUIControl, disable, Begin
  316. Return
  317. outFileDoesNotExist:
  318.     GUI font, cGreen
  319.     GUIControl, font, ExistStateOut
  320.     GUIControl,, ExistStateOut, Serial unused
  321.     GUIControlGet, otherItem,, ExistState
  322.     If otherItem = Existent
  323.         GUIControl, enable, Begin
  324.     else, GUIControl, disable, Begin
  325. Return
  326. Calculate: ;BeginRegion Calculate Correct Name Estimation
  327.     GUIControlGet, actualDestType,, DestType
  328.     if actualDestType = BoC
  329.     {
  330.         GUIControlGet, testBookNumber,, Book
  331.         Loop 99 { ;Page number
  332.             if mod(A_Index, 5) = 1 {
  333.                 SB_SetText("Checking pages " . A_Index . " to " . (A_Index + 4) . "…")
  334.             }
  335.             testPageNumber := SubStr("0" . A_Index, -1)
  336.             IfNotExist %pathout%Book of Conworlds\Book %testBookNumber%\%testPageNumber%?-*.jpg
  337.             {
  338.                 GUIControl,, Page, %testPageNumber%
  339.                 MsgBox, 4, Slot Open, There is a slot open at page %A_Index%. Do you wish to populate it?
  340.                 IfMsgBox Yes
  341.                 {
  342.                     SB_SetText("Ready")
  343.                     break
  344.                 }
  345.                 else, continue
  346.             }
  347.         }
  348.     }
  349.     else if actualDestType = MoR
  350.     {
  351.         PrevMonth := A_Now
  352.         PrevMonth += -30, days
  353.         GUIControl,, DestIfDate, %PrevMonth%
  354.     }
  355.     else if actualDestType = Non-BoC Conworld
  356.     {
  357.         FormatTime, testDate,, yyyy-MM (MMM)
  358.         Loop 99 {
  359.             testPageNumber := SubStr("0" . (A_Index), -1)
  360.             if mod(A_Index, 5) = 1 {
  361.                 SB_SetText("Checking pages " . A_Index . " to " . (A_Index + 4) . "…")
  362.             }
  363.             IfNotExist %pathout%Book of Conworlds\Non-BoC\%testDate%\%testPageNumber%?-*.jpg
  364.             {
  365.                 GUIControl,, NBoCPage, %testPageNumber%
  366.                 SB_SetText("Ready")
  367.                 break
  368.             }
  369.         }
  370.     }
  371.     else
  372.     {
  373.         FormatTime, testDate,, yyyy-MM (MMM)
  374.         Loop 10000 {
  375.             testPageNumber := SubStr("000" . (A_Index - 1), -3)
  376.             if mod(A_Index, 5) = 1 {
  377.                 SB_SetText("Checking pages " . A_Index . " to " . (A_Index + 4) . "…")
  378.             }
  379.             IfNotExist %pathout%Unsorted By Date\%testDate%\Scan%testPageNumber%.jpg
  380.             {
  381.                 GUIControl,, MiscScans, Scan%testPageNumber%
  382.                 SB_SetText("Ready")
  383.                 break
  384.             }
  385.         }
  386.     }
  387. Return ;EndRegion Calculate Correct Name Estimation
  388. EndProgram: ;BeginRegion End Program
  389.     GUI destroy
  390.     ExitApp
  391. ;EndRegion End Program
  392. ReloadProgram: ;BeginRegion Reload Program
  393.     Reload
  394. Return ;EndRegion Reload Program
  395. !a:: ;BeginRegion Focus on LangSuffix
  396.     GUIControl, Focus, LangSuffix
  397. Return ;EndRegion Focus on LangSuffix
  398. OnExit: ;BeginRegion Exit
  399. GUI Destroy
  400. ExitApp ;EndRegion exit
  401. ShowFolder: ;BeginRegion Show Folder
  402.     oneLess := FinalDest
  403.     Loop 512 {
  404.         StringRight testLetter, oneLess, 1
  405.         if testLetter = \
  406.             break
  407.         else
  408.             StringTrimRight oneLess, oneLess, 1
  409.     }
  410.     Run, %oneLess%
  411.     ;MsgBox %oneLess%
  412. Return ;EndRegion Show Folder
  413. ShowFolderExit: ;BeginRegion Show Folder and Exit
  414.     GoSub ShowFolder
  415.     ExitApp
  416. Return ;EndRegion Show Folder and Exit
  417. SubpageLetter: ;BeginRegion Subpage Number-to-letter
  418.     GUIControlGet, subpageValue,, Subpage
  419.     subpageValue := Chr(subpageValue + 96)
  420.     GUIControl,, DispSubpage, %subpageValue%
  421.     GUIControlGet, subpageValue,, NBoCSubpage
  422.     subpageValue := Chr(subpageValue + 96)
  423.     GUIControl,, NBoCDispSubpage, %subpageValue%
  424. Return ;EndRegion Subpage Number-to-letter
  425. ;EndRegion Button Subroutines
Advertisement
Add Comment
Please, Sign In to add comment