You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

174 lines
8.7 KiB

  1. appmode = args.get('appmode', 'standard')
  2. dialogHeights = {
  3. 'standard': 325,
  4. 'music': 345,
  5. 'picture': 255,
  6. }
  7. result = Window(410, dialogHeights[appmode], "dupeGuru Preferences")
  8. tabView = TabView(result)
  9. basicTab = tabView.addTab("Basic")
  10. advancedTab = tabView.addTab("Advanced")
  11. thresholdSlider = Slider(basicTab.view, 1, 100, 80)
  12. thresholdLabel = Label(basicTab.view, "Filter hardness:")
  13. moreResultsLabel = Label(basicTab.view, "More results")
  14. fewerResultsLabel = Label(basicTab.view, "Fewer results")
  15. thresholdValueLabel = Label(basicTab.view, "")
  16. fontSizeCombo = Combobox(basicTab.view, ["11", "12", "13", "14", "18", "24"])
  17. fontSizeLabel = Label(basicTab.view, "Font Size:")
  18. if appmode in ('standard', 'music'):
  19. wordWeightingBox = Checkbox(basicTab.view, "Word weighting")
  20. matchSimilarWordsBox = Checkbox(basicTab.view, "Match similar words")
  21. elif appmode == 'picture':
  22. matchDifferentDimensionsBox = Checkbox(basicTab.view, "Match pictures of different dimensions")
  23. mixKindBox = Checkbox(basicTab.view, "Can mix file kind")
  24. removeEmptyFoldersBox = Checkbox(basicTab.view, "Remove empty folders on delete or move")
  25. checkForUpdatesBox = Checkbox(basicTab.view, "Automatically check for updates")
  26. if appmode == 'standard':
  27. ignoreSmallFilesBox = Checkbox(basicTab.view, "Ignore files smaller than:")
  28. smallFilesThresholdText = TextField(basicTab.view, "")
  29. smallFilesThresholdSuffixLabel = Label(basicTab.view, "KB")
  30. elif appmode == 'music':
  31. tagsToScanLabel = Label(basicTab.view, "Tags to scan:")
  32. trackBox = Checkbox(basicTab.view, "Track")
  33. artistBox = Checkbox(basicTab.view, "Artist")
  34. albumBox = Checkbox(basicTab.view, "Album")
  35. titleBox = Checkbox(basicTab.view, "Title")
  36. genreBox = Checkbox(basicTab.view, "Genre")
  37. yearBox = Checkbox(basicTab.view, "Year")
  38. tagBoxes = [trackBox, artistBox, albumBox, titleBox, genreBox, yearBox]
  39. regexpCheckbox = Checkbox(advancedTab.view, "Use regular expressions when filtering")
  40. ignoreHardlinksBox = Checkbox(advancedTab.view, "Ignore duplicates hardlinking to the same file")
  41. debugModeCheckbox = Checkbox(advancedTab.view, "Debug mode (restart required)")
  42. customCommandLabel = Label(advancedTab.view, "Custom command (arguments: %d for dupe, %r for ref):")
  43. customCommandText = TextField(advancedTab.view, "")
  44. copyMoveLabel = Label(advancedTab.view, "Copy and Move:")
  45. copyMovePopup = Popup(advancedTab.view, ["Right in destination", "Recreate relative path", "Recreate absolute path"])
  46. resetToDefaultsButton = Button(result, "Reset To Defaults")
  47. thresholdSlider.bind('value', defaults, 'values.minMatchPercentage')
  48. thresholdValueLabel.bind('value', defaults, 'values.minMatchPercentage')
  49. fontSizeCombo.bind('value', defaults, 'values.TableFontSize')
  50. mixKindBox.bind('value', defaults, 'values.mixFileKind')
  51. removeEmptyFoldersBox.bind('value', defaults, 'values.removeEmptyFolders')
  52. checkForUpdatesBox.bind('value', defaults, 'values.SUEnableAutomaticChecks')
  53. regexpCheckbox.bind('value', defaults, 'values.useRegexpFilter')
  54. ignoreHardlinksBox.bind('value', defaults, 'values.ignoreHardlinkMatches')
  55. debugModeCheckbox.bind('value', defaults, 'values.DebugMode')
  56. customCommandText.bind('value', defaults, 'values.CustomCommand')
  57. copyMovePopup.bind('selectedIndex', defaults, 'values.recreatePathType')
  58. if appmode in ('standard', 'music'):
  59. wordWeightingBox.bind('value', defaults, 'values.wordWeighting')
  60. matchSimilarWordsBox.bind('value', defaults, 'values.matchSimilarWords')
  61. disableWhenContentScan = [thresholdSlider, wordWeightingBox, matchSimilarWordsBox]
  62. for control in disableWhenContentScan:
  63. vtname = 'vtScanTypeMusicIsNotContent' if appmode == 'music' else 'vtScanTypeIsNotContent'
  64. prefname = 'values.scanTypeMusic' if appmode == 'music' else 'values.scanTypeStandard'
  65. control.bind('enabled', defaults, prefname, valueTransformer=vtname)
  66. if appmode == 'standard':
  67. ignoreSmallFilesBox.bind('value', defaults, 'values.ignoreSmallFiles')
  68. smallFilesThresholdText.bind('value', defaults, 'values.smallFileThreshold')
  69. elif appmode == 'music':
  70. for box in tagBoxes:
  71. box.bind('enabled', defaults, 'values.scanTypeMusic', valueTransformer='vtScanTypeIsTag')
  72. trackBox.bind('value', defaults, 'values.scanTagTrack')
  73. artistBox.bind('value', defaults, 'values.scanTagArtist')
  74. albumBox.bind('value', defaults, 'values.scanTagAlbum')
  75. titleBox.bind('value', defaults, 'values.scanTagTitle')
  76. genreBox.bind('value', defaults, 'values.scanTagGenre')
  77. yearBox.bind('value', defaults, 'values.scanTagYear')
  78. elif appmode == 'picture':
  79. matchDifferentDimensionsBox.bind('value', defaults, 'values.matchScaled')
  80. thresholdSlider.bind('enabled', defaults, 'values.scanTypePicture', valueTransformer='vtScanTypeIsFuzzy')
  81. result.canResize = False
  82. result.canMinimize = False
  83. thresholdValueLabel.formatter = NumberFormatter(NumberStyle.Decimal)
  84. thresholdValueLabel.formatter.maximumFractionDigits = 0
  85. allLabels = [thresholdValueLabel, moreResultsLabel, fewerResultsLabel,
  86. thresholdLabel, fontSizeLabel, customCommandLabel, copyMoveLabel]
  87. allCheckboxes = [mixKindBox, removeEmptyFoldersBox, checkForUpdatesBox, regexpCheckbox,
  88. ignoreHardlinksBox, debugModeCheckbox]
  89. if appmode == 'standard':
  90. allLabels += [smallFilesThresholdSuffixLabel]
  91. allCheckboxes += [ignoreSmallFilesBox, wordWeightingBox, matchSimilarWordsBox]
  92. elif appmode == 'music':
  93. allLabels += [tagsToScanLabel]
  94. allCheckboxes += tagBoxes + [wordWeightingBox, matchSimilarWordsBox]
  95. elif appmode == 'picture':
  96. allCheckboxes += [matchDifferentDimensionsBox]
  97. for label in allLabels:
  98. label.controlSize = ControlSize.Small
  99. fewerResultsLabel.alignment = TextAlignment.Right
  100. for checkbox in allCheckboxes:
  101. checkbox.font = thresholdValueLabel.font
  102. resetToDefaultsButton.action = Action(defaults, 'revertToInitialValues:')
  103. thresholdLabel.width = fontSizeLabel.width = 94
  104. fontSizeCombo.width = 66
  105. thresholdValueLabel.width = 25
  106. resetToDefaultsButton.width = 136
  107. if appmode == 'standard':
  108. smallFilesThresholdText.width = 60
  109. smallFilesThresholdSuffixLabel.width = 40
  110. elif appmode == 'music':
  111. for box in tagBoxes:
  112. box.width = 70
  113. tabView.packToCorner(Pack.UpperLeft)
  114. tabView.fill(Pack.Right)
  115. resetToDefaultsButton.packRelativeTo(tabView, Pack.Below, align=Pack.Right)
  116. tabView.fill(Pack.Below, margin=14)
  117. tabView.setAnchor(Pack.UpperLeft, growX=True, growY=True)
  118. thresholdLayout = HLayout([thresholdLabel, thresholdSlider, thresholdValueLabel], filler=thresholdSlider)
  119. thresholdLayout.packToCorner(Pack.UpperLeft)
  120. thresholdLayout.fill(Pack.Right)
  121. # We want to give the labels as much space as possible, and we only "know" how much is available
  122. # after the slider's fill operation.
  123. moreResultsLabel.width = fewerResultsLabel.width = thresholdSlider.width // 2
  124. moreResultsLabel.packRelativeTo(thresholdSlider, Pack.Below, align=Pack.Left, margin=6)
  125. fewerResultsLabel.packRelativeTo(thresholdSlider, Pack.Below, align=Pack.Right, margin=6)
  126. fontSizeCombo.packRelativeTo(moreResultsLabel, Pack.Below)
  127. fontSizeLabel.packRelativeTo(fontSizeCombo, Pack.Left)
  128. if appmode == 'music':
  129. tagsToScanLabel.packRelativeTo(fontSizeCombo, Pack.Below)
  130. tagsToScanLabel.fill(Pack.Left)
  131. tagsToScanLabel.fill(Pack.Right)
  132. trackBox.packRelativeTo(tagsToScanLabel, Pack.Below)
  133. trackBox.x += 10
  134. artistBox.packRelativeTo(trackBox, Pack.Right)
  135. albumBox.packRelativeTo(artistBox, Pack.Right)
  136. titleBox.packRelativeTo(trackBox, Pack.Below)
  137. genreBox.packRelativeTo(titleBox, Pack.Right)
  138. yearBox.packRelativeTo(genreBox, Pack.Right)
  139. viewToPackCheckboxesUnder = titleBox
  140. else:
  141. viewToPackCheckboxesUnder = fontSizeCombo
  142. if appmode == 'standard':
  143. checkboxesToLayout = [wordWeightingBox, matchSimilarWordsBox, mixKindBox, removeEmptyFoldersBox,
  144. ignoreSmallFilesBox]
  145. elif appmode == 'music':
  146. checkboxesToLayout = [wordWeightingBox, matchSimilarWordsBox, mixKindBox, removeEmptyFoldersBox,
  147. checkForUpdatesBox]
  148. elif appmode == 'picture':
  149. checkboxesToLayout = [matchDifferentDimensionsBox, mixKindBox, removeEmptyFoldersBox,
  150. checkForUpdatesBox]
  151. checkboxLayout = VLayout(checkboxesToLayout)
  152. checkboxLayout.packRelativeTo(viewToPackCheckboxesUnder, Pack.Below)
  153. checkboxLayout.fill(Pack.Left)
  154. checkboxLayout.fill(Pack.Right)
  155. if appmode == 'standard':
  156. smallFilesThresholdText.packRelativeTo(ignoreSmallFilesBox, Pack.Below, margin=4)
  157. checkForUpdatesBox.packRelativeTo(smallFilesThresholdText, Pack.Below, margin=4)
  158. checkForUpdatesBox.fill(Pack.Right)
  159. smallFilesThresholdText.x += 20
  160. smallFilesThresholdSuffixLabel.packRelativeTo(smallFilesThresholdText, Pack.Right)
  161. advancedLayout = VLayout(advancedTab.view.subviews[:])
  162. advancedLayout.packToCorner(Pack.UpperLeft)
  163. advancedLayout.fill(Pack.Right)