From b5dd4f4d82645ee283929ad3e687a38a25e010de Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Sat, 22 Jun 2013 17:54:15 +0400 Subject: [PATCH] added image sord dialog... Signed-off-by: Alex A. Naanou --- buildcache.py | 13 ++++++-- ui/keybindings.js | 8 +++-- ui/ui.js | 85 ++++++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 98 insertions(+), 8 deletions(-) diff --git a/buildcache.py b/buildcache.py index 8172e388..be0ff3ae 100755 --- a/buildcache.py +++ b/buildcache.py @@ -1,7 +1,7 @@ #======================================================================= __version__ = '''0.0.01''' -__sub_version__ = '''20130613200255''' +__sub_version__ = '''20130622165505''' __copyright__ = '''(c) Alex A. Naanou 2011''' @@ -329,7 +329,11 @@ def build_previews(image, path=None, config=CONFIG, dry_run=True, verbosity=0): image['preview'][str(max(*img.size)) + 'px'] = img_path # previews... - for k, spec in sizes.items(): + preview = None + # NOTE: do the big previews first... + s = sizes.items() + s.sort(lambda a, b: cmp(b[1], a[1])) + for k, spec in s: if k in image['preview'].keys(): continue @@ -344,6 +348,11 @@ def build_previews(image, path=None, config=CONFIG, dry_run=True, verbosity=0): # add image to index... if not os.path.exists(p): + # use the preview to speed things up... + # NOTE: this will degrade the quality of previews after + # several resizes... +## if preview != None: +## img = preview scale = spec/float(max(*img.size)) preview = img.resize((int(img.size[0]*scale), int(img.size[1]*scale)), Image.ANTIALIAS) diff --git a/ui/keybindings.js b/ui/keybindings.js index c9ccb48f..cd072ac1 100755 --- a/ui/keybindings.js +++ b/ui/keybindings.js @@ -274,7 +274,7 @@ var KEYBOARD_CONFIG = { // XXX STUB: use a real path browser... O: doc('Open a directory path', function(){ - loadDirectory() + loadDirectoryDialog() }), @@ -451,6 +451,10 @@ var KEYBOARD_CONFIG = { S: { default: doc('Start slideshow', function(){ toggleSlideShowMode('on') }), + shift: doc('Sort images', + function(){ + sortImagesDialog() + }), ctrl: doc('Save current state', function(){ event.preventDefault() @@ -477,7 +481,7 @@ var KEYBOARD_CONFIG = { }), 'ctrl+shift': doc('Export', function(){ - exportPreviews() + exportPreviewsDialog() }), }, Z: { diff --git a/ui/ui.js b/ui/ui.js index 2f59d879..5607e49d 100755 --- a/ui/ui.js +++ b/ui/ui.js @@ -490,6 +490,43 @@ var FIELD_TYPES = { return field.find('.path').val() }, }, + + choice: { + type: 'choice', + text: null, + default: false, + html: '
'+ + ''+ + '
'+ + ''+ + ''+ + '
'+ + '
', + // format: ['a', 'b', 'c', ...] + test: function(val){ + return typeof(val) == typeof([]) && val.constructor.name == 'Array' + }, + set: function(field, value){ + var t = field.find('.text').text() + var item = field.find('.item').last() + for(var i=0; i < value.length; i++){ + item.find('.value') + .val(value[i]) + item.find('.item-text') + .text(value[i]) + item.appendTo(field) + + item = item.clone() + } + field.find('.value') + .attr('name', t) + .first() + .attr('checked', '') + }, + get: function(field){ + return $(field).find('.value:checked').val() + }, + }, } // Show a complex form dialog @@ -642,8 +679,11 @@ function getDir(message, dfl, btn){ } + +/***************************************** Domain-specific dialogs ***/ + // XXX do reporting... -function exportPreviews(dfl){ +function exportPreviewsDialog(dfl){ dfl = dfl == null ? BASE_URL : dfl var res = $.Deferred() @@ -653,7 +693,7 @@ function exportPreviews(dfl){ 'Image name pattern': '%f', 'Fav directory name': 'fav', 'Destination': {ndir: dfl}, - }, 'OK', 'exportPreviews') + }, 'OK', 'exportPreviewsDialog') .done(function(data){ exportTo( data['Destination'], @@ -675,7 +715,7 @@ function exportPreviews(dfl){ } -function loadDirectory(dfl){ +function loadDirectoryDialog(dfl){ dfl = dfl == null ? BASE_URL : dfl // browser version... var getter = window.listDir != null ? getDir : prompt @@ -697,8 +737,45 @@ function loadDirectory(dfl){ } +function sortImagesDialog(message){ + updateStatus('Sort...').show() + + message = message == null ? 'Sort images by:' : message + cfg = {} + cfg[message] = [ + 'Date (ascending)', + 'Name (ascending)', + 'Date (decending)', + 'Name (decending)', + ] + + formDialog(null, '', + cfg, + 'OK', + 'sortImagesDialog') + .done(function(res){ + res = res[message] + + if(/Date/.test(res)){ + var method = sortImagesByDate + } else { + var method = sortImagesByName + } + if(/\(ascending\)/.test(res)){ + var reverse = null + } else { + var reverse = true + } + + showStatusQ('Sorting by: '+res+'...') + + method(reverse) + }) + .fail(function(){ + showStatusQ('Sort: canceled.') + }) +} -/************************************************ Specific dialogs ***/ function showImageInfo(){ var gid = getImageGID(getImage())