made sure everything is compatible, moved to $.getJSON(...) for reading json files instead of a CEF extension...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2013-05-22 03:00:38 +04:00
parent c8cd7d1bf0
commit 04e4e6ccb8
3 changed files with 72 additions and 55 deletions

View File

@ -1,7 +1,7 @@
#======================================================================= #=======================================================================
__version__ = '''0.0.01''' __version__ = '''0.0.01'''
__sub_version__ = '''20130522014220''' __sub_version__ = '''20130522020247'''
__copyright__ = '''(c) Alex A. Naanou 2011''' __copyright__ = '''(c) Alex A. Naanou 2011'''
@ -12,6 +12,7 @@ import Image
import json import json
import sha import sha
import urllib2 import urllib2
import time
from pli.logictypes import OR from pli.logictypes import OR
@ -72,7 +73,6 @@ TARGET: %(target-file)s
#----------------------------------------------------------------------- #-----------------------------------------------------------------------
# Helpers... # Helpers...
#------------------------------------------------------------pathjoin--- #------------------------------------------------------------pathjoin---
def pathjoin(*p): def pathjoin(*p):
''' '''
@ -87,7 +87,7 @@ def getpath(root, path, absolute=False):
if absolute == True: if absolute == True:
return 'file:///' + urllib2.quote(pathjoin(root, path), safe='/:') return 'file:///' + urllib2.quote(pathjoin(root, path), safe='/:')
else: else:
return urllib2.quote(path, safe='/') return urllib2.quote(pathjoin(path), safe='/:')
#-------------------------------------------------------------log_err--- #-------------------------------------------------------------log_err---
@ -139,11 +139,15 @@ def report_progress(img, status):
def make_inline_report_progress(state=None): def make_inline_report_progress(state=None):
if state == None: if state == None:
state = {} state = {}
if 'started at' not in state:
state['started at'] = time.time()
def _inline_report_progress(img, status): def _inline_report_progress(img, status):
created = state.get('created', 0) created = state.get('created', 0)
skipped = state.get('skipped', 0) skipped = state.get('skipped', 0)
partial = state.get('partial', 0) partial = state.get('partial', 0)
# created all previews... # created all previews...
if False not in status: if False not in status:
created += 1 created += 1
@ -159,6 +163,8 @@ def make_inline_report_progress(state=None):
partial += 1 partial += 1
state['partial'] = partial state['partial'] = partial
state['done at'] = time.time()
print 'Previews created: %s partial: %s skipped: %s...\r' % (created, partial, skipped), print 'Previews created: %s partial: %s skipped: %s...\r' % (created, partial, skipped),
return img return img
@ -168,7 +174,6 @@ def make_inline_report_progress(state=None):
#----------------------------------------------------------------------- #-----------------------------------------------------------------------
# API... # API...
#----------------------------------------------------build_cache_dirs--- #----------------------------------------------------build_cache_dirs---
def build_cache_dirs(path, config=CONFIG): def build_cache_dirs(path, config=CONFIG):
''' '''
@ -306,7 +311,6 @@ def build_data(images, path, config=CONFIG):
#----------------------------------------------------------------------- #-----------------------------------------------------------------------
# High-level API... # High-level API...
#---------------------------------------------------------build_cache--- #---------------------------------------------------------build_cache---
##!!! DO NOT OVERWRITE EXISTING DATA... ##!!! DO NOT OVERWRITE EXISTING DATA...
def build_cache(path, config=CONFIG, gid_generator=hash_gid, def build_cache(path, config=CONFIG, gid_generator=hash_gid,

View File

@ -647,51 +647,49 @@ function saveLocalStorageMarks(attr){
* Extension API (CEF/PhoneGap/...) * Extension API (CEF/PhoneGap/...)
*/ */
function loadFileImages(path){ function loadFileImages(path, callback){
if(window.CEF_loadJSON != null){ return $.getJSON(path, function(json){
IMAGES = CEF_loadJSON(path) IMAGES = json
localStorage[DATA_ATTR + '_IMAGES_FILE'] = path localStorage[DATA_ATTR + '_IMAGES_FILE'] = path
console.log('Loaded IMAGES...') console.log('Loaded IMAGES...')
return IMAGES
} else { callback != null && callback()
// XXX })
}
} }
function loadFile(data_path, image_path){ function loadFile(data_path, image_path, callback){
// CEF // CEF
if(window.CEF_loadJSON != null){ return $.getJSON(data_path, function(json){
var json = CEF_loadJSON(data_path)
console.log('Loaded DATA...')
// legacy format... // legacy format...
if(json.version == null){ if(json.version == null){
json = convertDataGen1(json) json = convertDataGen1(json)
DATA = json.data DATA = json.data
IMAGES = json.images IMAGES = json.images
return loadData() loadData()
// version 2.0 // version 2.0
// XXX needs a more flexible protocol... // XXX needs a more flexible protocol...
} else if(json.version == '2.0') { } else if(json.version == '2.0') {
DATA = json DATA = json
if(image_path != null){ if(image_path != null){
loadFileImages(image_path) loadFileImages(image_path, function(){
loadData()
callback != null && callback()
})
} else if(DATA.image_file != null) { } else if(DATA.image_file != null) {
loadFileImages(DATA.image_file) loadFileImages(DATA.image_file, function(){
loadData()
callback != null && callback()
})
} }
return loadData()
} else { } else {
console.error('unknown format.') console.error('unknown format.')
return return
} }
})
// PhoneGap
} else if(false) {
// XXX
}
} }
function saveFile(name){ function saveFile(name){

View File

@ -316,32 +316,6 @@ $(function(){
toggleTheme('gray') toggleTheme('gray')
//setElementOrigin($('.ribbon-set'), 'top', 'left')
// we have an image file...
if((DATA_ATTR + '_IMAGES_FILE') in localStorage){
loadFileImages(localStorage[DATA_ATTR + '_IMAGES_FILE'])
DATA = loadLocalStorageData()
loadData()
// everything is in localStorage...
} else if('DATA' in localStorage){
loadLocalStorage()
// legacy default data...
} else {
DATA = convertDataGen1(image_list)
DATA = DATA.data
IMAGES = DATA.images
loadData()
}
// XXX this will reload everything...
if('MARKED' in localStorage){
loadLocalStorageMarks()
}
// NOTE: this is global so as to not to add any extra complexity to // NOTE: this is global so as to not to add any extra complexity to
// the internal workings... // the internal workings...
$('.viewer') $('.viewer')
@ -364,9 +338,50 @@ $(function(){
setupDataBindings() setupDataBindings()
// XXX stub...
//centerView(focusImage($('.image').first()), 'css') //setElementOrigin($('.ribbon-set'), 'top', 'left')
updateImages()
// we have an image file...
if((DATA_ATTR + '_IMAGES_FILE') in localStorage){
loadFileImages(localStorage[DATA_ATTR + '_IMAGES_FILE'])
.done(function(){
DATA = loadLocalStorageData()
loadData()
// XXX this will reload everything...
if('MARKED' in localStorage){
loadLocalStorageMarks()
}
// XXX stub...
//centerView(focusImage($('.image').first()), 'css')
updateImages()
})
} else {
// everything is in localStorage...
if('DATA' in localStorage){
loadLocalStorage()
// legacy default data...
} else {
DATA = convertDataGen1(image_list)
DATA = DATA.data
IMAGES = DATA.images
loadData()
}
// XXX this will reload everything...
if('MARKED' in localStorage){
loadLocalStorageMarks()
}
// XXX stub...
//centerView(focusImage($('.image').first()), 'css')
updateImages()
}
}) })