<s> import os <EOL> import hashlib <EOL> import threading <EOL> from ginga import GingaPlugin <EOL> from ginga . misc import Bunch <EOL> from ginga . util import iohelper <EOL> from ginga . misc import Bunch <EOL> from ginga . gw import GwHelp , Widgets , Viewers <EOL> class Thumbs ( GingaPlugin . GlobalPlugin ) : <EOL> def __init__ ( self , fv ) : <EOL> super ( Thumbs , self ) . __init__ ( fv ) <EOL> self . thumbDict = { } <EOL> self . thumbList = [ ] <EOL> self . thumbRowList = [ ] <EOL> self . thumbNumRows = <NUM_LIT:20> <EOL> self . thumbNumCols = <NUM_LIT:1> <EOL> self . thumbRowCount = <NUM_LIT:0> <EOL> self . thumbColCount = <NUM_LIT:0> <EOL> self . thumbSep = <NUM_LIT:15> <EOL> tt_keywords = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> prefs = self . fv . get_preferences ( ) <EOL> self . settings = prefs . createCategory ( '<STR_LIT>' ) <EOL> self . settings . addDefaults ( cache_thumbs = False , <EOL> cache_location = '<STR_LIT>' , <EOL> auto_scroll = True , <EOL> rebuild_wait = <NUM_LIT> , <EOL> tt_keywords = tt_keywords , <EOL> mouseover_name_key = '<STR_LIT>' , <EOL> thumb_length = <NUM_LIT> , <EOL> sort_order = None , <EOL> label_length = <NUM_LIT> , <EOL> label_cutoff = '<STR_LIT:right>' , <EOL> highlight_tracks_keyboard_focus = True , <EOL> label_font_color = '<STR_LIT>' , <EOL> label_bg_color = '<STR_LIT>' ) <EOL> self . settings . load ( onError = '<STR_LIT>' ) <EOL> self . thumbWidth = self . settings . get ( '<STR_LIT>' , <NUM_LIT> ) <EOL> self . thmbtask = fv . get_timer ( ) <EOL> self . thmbtask . set_callback ( '<STR_LIT>' , self . redo_delay_timer ) <EOL> self . lagtime = self . settings . get ( '<STR_LIT>' , <NUM_LIT> ) <EOL> self . thmblock = threading . RLock ( ) <EOL> self . keywords = self . settings . get ( '<STR_LIT>' , tt_keywords ) <EOL> self . keywords . insert ( <NUM_LIT:0> , self . settings . get ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> self . highlight_tracks_keyboard_focus = self . settings . get ( <EOL> '<STR_LIT>' , True ) <EOL> self . _tkf_highlight = set ( [ ] ) <EOL> fv . set_callback ( '<STR_LIT>' , self . add_image_cb ) <EOL> fv . set_callback ( '<STR_LIT>' , self . add_image_info_cb ) <EOL> fv . set_callback ( '<STR_LIT>' , self . remove_image_cb ) <EOL> fv . set_callback ( '<STR_LIT>' , self . add_channel_cb ) <EOL> fv . set_callback ( '<STR_LIT>' , self . delete_channel_cb ) <EOL> fv . add_callback ( '<STR_LIT>' , self . focus_cb ) <EOL> self . gui_up = False <EOL> def build_gui ( self , container ) : <EOL> width , height = <NUM_LIT> , <NUM_LIT> <EOL> cm , im = self . fv . cm , self . fv . im <EOL> tg = Viewers . ImageViewCanvas ( logger = self . logger ) <EOL> tg . configure_window ( <NUM_LIT:200> , <NUM_LIT:200> ) <EOL> tg . enable_autozoom ( '<STR_LIT>' ) <EOL> tg . set_autocut_params ( '<STR_LIT>' ) <EOL> tg . enable_autocuts ( '<STR_LIT>' ) <EOL> tg . enable_auto_orient ( True ) <EOL> tg . defer_redraw = False <EOL> tg . set_bg ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) <EOL> self . thumb_generator = tg <EOL> sw = Widgets . ScrollArea ( ) <EOL> sw . add_callback ( '<STR_LIT>' , self . thumbpane_resized_cb ) <EOL> vbox = Widgets . GridBox ( ) <EOL> vbox . set_margins ( <NUM_LIT:4> , <NUM_LIT:4> , <NUM_LIT:4> , <NUM_LIT:4> ) <EOL> vbox . set_column_spacing ( <NUM_LIT> ) <EOL> self . w . thumbs = vbox <EOL> sw . set_widget ( vbox ) <EOL> self . w . thumbs_scroll = sw <EOL> container . add_widget ( sw , stretch = <NUM_LIT:1> ) <EOL> captions = ( ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , ) <EOL> w , b = Widgets . build_info ( captions ) <EOL> self . w . update ( b ) <EOL> b . auto_scroll . set_tooltip ( <EOL> "<STR_LIT>" ) <EOL> b . clear . set_tooltip ( "<STR_LIT>" ) <EOL> b . clear . add_callback ( '<STR_LIT>' , lambda w : self . clear ( ) ) <EOL> auto_scroll = self . settings . get ( '<STR_LIT>' , True ) <EOL> b . auto_scroll . set_state ( auto_scroll ) <EOL> container . add_widget ( w , stretch = <NUM_LIT:0> ) <EOL> self . gui_up = True <EOL> def _get_thumb_key ( self , chname , image ) : <EOL> path = image . get ( '<STR_LIT:path>' , None ) <EOL> return self . get_thumb_key ( chname , image . get ( '<STR_LIT:name>' ) , path ) <EOL> def get_thumb_key ( self , chname , imname , path ) : <EOL> if path is not None : <EOL> path = os . path . abspath ( path ) <EOL> thumbkey = ( chname , imname , path ) <EOL> return thumbkey <EOL> def add_image_cb ( self , viewer , chname , image , image_info ) : <EOL> if not self . gui_up : <EOL> return False <EOL> nothumb = image . get ( '<STR_LIT>' , False ) <EOL> if nothumb : <EOL> return <EOL> idx = image . get ( '<STR_LIT>' , None ) <EOL> path = image_info . path <EOL> if path is not None : <EOL> path = os . path . abspath ( path ) <EOL> name = image_info . name <EOL> thumbname = name <EOL> self . logger . info ( "<STR_LIT>" % ( thumbname ) ) <EOL> future = image_info . image_future <EOL> chinfo = self . fv . get_channelInfo ( chname ) <EOL> prefs = chinfo . settings <EOL> if not prefs . get ( '<STR_LIT>' , False ) : <EOL> return <EOL> thumbkey = self . get_thumb_key ( chname , name , path ) <EOL> with self . thmblock : <EOL> if thumbkey in self . thumbDict : <EOL> return <EOL> header = image . get_header ( ) <EOL> metadata = { } <EOL> for kwd in self . keywords : <EOL> metadata [ kwd ] = header . get ( kwd , '<STR_LIT>' ) <EOL> metadata [ self . settings . get ( '<STR_LIT>' , '<STR_LIT>' ) ] = name <EOL> thumbpath = self . get_thumbpath ( path ) <EOL> with self . thmblock : <EOL> self . copy_attrs ( chinfo . fitsimage ) <EOL> self . thumb_generator . set_image ( image ) <EOL> imgwin = self . thumb_generator . get_image_as_widget ( ) <EOL> label_length = self . settings . get ( '<STR_LIT>' , None ) <EOL> label_cutoff = self . settings . get ( '<STR_LIT>' , '<STR_LIT:right>' ) <EOL> if label_length is not None : <EOL> thumbname = iohelper . shorten_name ( thumbname , label_length , <EOL> side = label_cutoff ) <EOL> self . insert_thumbnail ( imgwin , thumbkey , thumbname , chname , name , path , <EOL> thumbpath , metadata , future ) <EOL> def _add_image ( self , viewer , chname , image ) : <EOL> chinfo = self . fv . get_channelInfo ( chname ) <EOL> try : <EOL> info = chinfo . get_image_info ( image . name ) <EOL> except KeyError : <EOL> return <EOL> self . add_image_cb ( viewer , chname , image , info ) <EOL> def remove_image_cb ( self , viewer , chname , name , path ) : <EOL> if not self . gui_up : <EOL> return <EOL> self . logger . info ( "<STR_LIT>" % ( name ) ) <EOL> try : <EOL> thumbkey = self . get_thumb_key ( chname , name , path ) <EOL> self . remove_thumb ( thumbkey ) <EOL> except Exception as e : <EOL> self . logger . error ( "<STR_LIT>" % ( <EOL> name , str ( e ) ) ) <EOL> def remove_thumb ( self , thumbkey ) : <EOL> with self . thmblock : <EOL> if thumbkey not in self . thumbDict : <EOL> return <EOL> self . clear_widget ( ) <EOL> del self . thumbDict [ thumbkey ] <EOL> self . thumbList . remove ( thumbkey ) <EOL> chname = thumbkey [ <NUM_LIT:0> ] <EOL> channel = self . fv . get_channelInfo ( chname ) <EOL> self . _tkf_highlight . discard ( thumbkey ) <EOL> channel . extdata . thumbs_old_highlight . discard ( thumbkey ) <EOL> self . reorder_thumbs ( ) <EOL> def update_thumbs ( self , nameList ) : <EOL> invalid = set ( self . thumbList ) - set ( nameList ) <EOL> if len ( invalid ) > <NUM_LIT:0> : <EOL> with self . thmblock : <EOL> for thumbkey in invalid : <EOL> self . thumbList . remove ( thumbkey ) <EOL> del self . thumbDict [ thumbkey ] <EOL> self . _tkf_highlight . discard ( thumbkey ) <EOL> self . reorder_thumbs ( ) <EOL> def thumbpane_resized_cb ( self , widget , width , height ) : <EOL> self . logger . info ( "<STR_LIT>" % ( width ) ) <EOL> with self . thmblock : <EOL> cols = max ( <NUM_LIT:1> , width // ( self . thumbWidth + self . thumbSep ) ) <EOL> if self . thumbNumCols == cols : <EOL> return False <EOL> self . logger . info ( "<STR_LIT>" % ( cols ) ) <EOL> self . thumbNumCols = cols <EOL> self . reorder_thumbs ( ) <EOL> return False <EOL> def load_file ( self , thumbkey , chname , name , path , image_future ) : <EOL> self . logger . debug ( "<STR_LIT>" % ( str ( thumbkey ) ) ) <EOL> self . fv . switch_name ( chname , name , path = path , <EOL> image_future = image_future ) <EOL> def clear ( self ) : <EOL> with self . thmblock : <EOL> self . clear_widget ( ) <EOL> self . thumbList = [ ] <EOL> self . thumbDict = { } <EOL> self . _tkf_highlight = set ( [ ] ) <EOL> self . reorder_thumbs ( ) <EOL> def add_channel_cb ( self , viewer , chinfo ) : <EOL> """<STR_LIT>""" <EOL> fitsimage = chinfo . fitsimage <EOL> fitssettings = fitsimage . get_settings ( ) <EOL> for name in [ '<STR_LIT>' ] : <EOL> fitssettings . getSetting ( name ) . add_callback ( '<STR_LIT>' , <EOL> self . cutset_cb , fitsimage ) <EOL> fitsimage . add_callback ( '<STR_LIT>' , self . transform_cb ) <EOL> rgbmap = fitsimage . get_rgbmap ( ) <EOL> rgbmap . add_callback ( '<STR_LIT>' , self . rgbmap_cb , fitsimage ) <EOL> chinfo . extdata . setdefault ( '<STR_LIT>' , set ( [ ] ) ) <EOL> def focus_cb ( self , viewer , channel ) : <EOL> fitsimage = channel . fitsimage <EOL> image = fitsimage . get_image ( ) <EOL> if image is not None : <EOL> chname = channel . name <EOL> thumbkey = self . _get_thumb_key ( chname , image ) <EOL> new_highlight = set ( [ thumbkey ] ) <EOL> if not self . have_thumbnail ( fitsimage , image ) : <EOL> self . _add_image ( viewer , chname , image ) <EOL> return <EOL> self . redo_delay ( fitsimage ) <EOL> else : <EOL> new_highlight = set ( [ ] ) <EOL> if self . highlight_tracks_keyboard_focus : <EOL> self . update_highlights ( self . _tkf_highlight , new_highlight ) <EOL> self . _tkf_highlight = new_highlight <EOL> def transform_cb ( self , fitsimage ) : <EOL> self . redo_delay ( fitsimage ) <EOL> return True <EOL> def cutset_cb ( self , setting , value , fitsimage ) : <EOL> self . redo_delay ( fitsimage ) <EOL> return True <EOL> def rgbmap_cb ( self , rgbmap , fitsimage ) : <EOL> self . redo_delay ( fitsimage ) <EOL> return True <EOL> def redo_delay ( self , fitsimage ) : <EOL> self . thmbtask . data . setvals ( fitsimage = fitsimage ) <EOL> self . thmbtask . set ( self . lagtime ) <EOL> return True <EOL> def redo_delay_timer ( self , timer ) : <EOL> self . fv . gui_do ( self . redo_thumbnail , timer . data . fitsimage ) <EOL> def copy_attrs ( self , fitsimage ) : <EOL> fitsimage . copy_attributes ( self . thumb_generator , <EOL> [ '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ] ) <EOL> def update_highlights ( self , old_highlight_set , new_highlight_set ) : <EOL> """<STR_LIT>""" <EOL> with self . thmblock : <EOL> un_hilite_set = old_highlight_set - new_highlight_set <EOL> re_hilite_set = new_highlight_set - old_highlight_set <EOL> for thumbkey in un_hilite_set : <EOL> if thumbkey in self . thumbDict : <EOL> namelbl = self . thumbDict [ thumbkey ] . get ( '<STR_LIT>' ) <EOL> namelbl . set_color ( bg = None , fg = None ) <EOL> bg = self . settings . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> fg = self . settings . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> for thumbkey in re_hilite_set : <EOL> if thumbkey in self . thumbDict : <EOL> namelbl = self . thumbDict [ thumbkey ] . get ( '<STR_LIT>' ) <EOL> namelbl . set_color ( bg = bg , fg = fg ) <EOL> def redo ( self , channel , image ) : <EOL> """<STR_LIT>""" <EOL> self . logger . debug ( "<STR_LIT>" ) <EOL> chname = channel . name <EOL> old_highlight = channel . extdata . thumbs_old_highlight <EOL> if image is not None : <EOL> thumbkey = self . _get_thumb_key ( chname , image ) <EOL> new_highlight = set ( [ thumbkey ] ) <EOL> else : <EOL> new_highlight = set ( [ ] ) <EOL> if not self . have_thumbnail ( channel . fitsimage , image ) : <EOL> self . _add_image ( self . fv , chname , image ) <EOL> self . logger . debug ( "<STR_LIT>" ) <EOL> if self . highlight_tracks_keyboard_focus : <EOL> self . update_highlights ( self . _tkf_highlight , new_highlight ) <EOL> self . _tkf_highlight = new_highlight <EOL> else : <EOL> self . update_highlights ( old_highlight , new_highlight ) <EOL> channel . extdata . thumbs_old_highlight = new_highlight <EOL> def have_thumbnail ( self , fitsimage , image ) : <EOL> """<STR_LIT>""" <EOL> chname = self . fv . get_channelName ( fitsimage ) <EOL> idx = image . get ( '<STR_LIT>' , None ) <EOL> path = image . get ( '<STR_LIT:path>' , None ) <EOL> if path is not None : <EOL> path = os . path . abspath ( path ) <EOL> name = self . fv . name_image_from_path ( path , idx = idx ) <EOL> else : <EOL> name = '<STR_LIT>' <EOL> name = image . get ( '<STR_LIT:name>' , name ) <EOL> thumbkey = self . get_thumb_key ( chname , name , path ) <EOL> with self . thmblock : <EOL> return thumbkey in self . thumbDict <EOL> def redo_thumbnail ( self , fitsimage , save_thumb = None ) : <EOL> self . logger . debug ( "<STR_LIT>" ) <EOL> image = fitsimage . get_image ( ) <EOL> if image is None : <EOL> return <EOL> if save_thumb is None : <EOL> save_thumb = self . settings . get ( '<STR_LIT>' , False ) <EOL> chname = self . fv . get_channelName ( fitsimage ) <EOL> header = image . get_header ( ) <EOL> metadata = { } <EOL> for kwd in self . keywords : <EOL> metadata [ kwd ] = header . get ( kwd , '<STR_LIT>' ) <EOL> idx = image . get ( '<STR_LIT>' , None ) <EOL> path = image . get ( '<STR_LIT:path>' , None ) <EOL> if path is not None : <EOL> path = os . path . abspath ( path ) <EOL> name = self . fv . name_image_from_path ( path , idx = idx ) <EOL> else : <EOL> name = '<STR_LIT>' <EOL> name = image . get ( '<STR_LIT:name>' , name ) <EOL> metadata [ self . settings . get ( '<STR_LIT>' , '<STR_LIT>' ) ] = name <EOL> thumbkey = self . get_thumb_key ( chname , name , path ) <EOL> with self . thmblock : <EOL> if thumbkey not in self . thumbDict : <EOL> self . _add_image ( self . fv , chname , image ) <EOL> return <EOL> fitsimage . copy_attributes ( self . thumb_generator , <EOL> [ '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ] ) <EOL> self . thumb_generator . set_image ( image ) <EOL> if save_thumb : <EOL> thumbpath = self . get_thumbpath ( path ) <EOL> if thumbpath is not None : <EOL> self . thumb_generator . save_image_as_file ( thumbpath , <EOL> format = '<STR_LIT>' ) <EOL> imgwin = self . thumb_generator . get_image_as_widget ( ) <EOL> self . update_thumbnail ( thumbkey , imgwin , name , metadata ) <EOL> def delete_channel_cb ( self , viewer , chinfo ) : <EOL> """<STR_LIT>""" <EOL> chname_del = chinfo . name <EOL> self . logger . info ( "<STR_LIT>" % ( chname_del ) ) <EOL> with self . thmblock : <EOL> self . clear_widget ( ) <EOL> newThumbList = [ ] <EOL> un_hilite_set = set ( [ ] ) <EOL> for thumbkey in self . thumbList : <EOL> chname = thumbkey [ <NUM_LIT:0> ] <EOL> if chname != chname_del : <EOL> newThumbList . append ( thumbkey ) <EOL> else : <EOL> del self . thumbDict [ thumbkey ] <EOL> un_hilite_set . add ( thumbkey ) <EOL> self . thumbList = newThumbList <EOL> self . _tkf_highlight -= un_hilite_set <EOL> self . reorder_thumbs ( ) <EOL> def _make_thumb ( self , chname , image , name , path , thumbkey , <EOL> image_future , save_thumb = False , thumbpath = None ) : <EOL> with self . thmblock : <EOL> self . thumb_generator . set_image ( image ) <EOL> if save_thumb and ( thumbpath is not None ) : <EOL> self . thumb_generator . save_image_as_file ( thumbpath , <EOL> format = '<STR_LIT>' ) <EOL> imgwin = self . thumb_generator . get_image_as_widget ( ) <EOL> image = self . thumb_generator . get_image ( ) <EOL> header = image . get_header ( ) <EOL> metadata = { } <EOL> for kwd in self . keywords : <EOL> metadata [ kwd ] = header . get ( kwd , '<STR_LIT>' ) <EOL> thumbname = name <EOL> self . insert_thumbnail ( imgwin , thumbkey , thumbname , <EOL> chname , name , path , thumbpath , metadata , <EOL> image_future ) <EOL> self . fv . update_pending ( timeout = <NUM_LIT> ) <EOL> def _gethex ( self , s ) : <EOL> return hashlib . sha1 ( s . encode ( ) ) . hexdigest ( ) <EOL> def get_thumbpath ( self , path , makedir = True ) : <EOL> if path is None : <EOL> return None <EOL> path = os . path . abspath ( path ) <EOL> dirpath , filename = os . path . split ( path ) <EOL> cache_location = self . settings . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> if cache_location == '<STR_LIT>' : <EOL> prefs = self . fv . get_preferences ( ) <EOL> thumbDir = os . path . join ( prefs . get_baseFolder ( ) , '<STR_LIT>' ) <EOL> thumbdir = os . path . join ( thumbDir , self . _gethex ( dirpath ) ) <EOL> else : <EOL> thumbdir = os . path . join ( dirpath , '<STR_LIT>' ) <EOL> if not os . path . exists ( thumbdir ) : <EOL> if not makedir : <EOL> self . logger . error ( "<STR_LIT>" % ( <EOL> thumbdir ) ) <EOL> return None <EOL> try : <EOL> os . makedirs ( thumbdir ) <EOL> metafile = os . path . join ( thumbdir , "<STR_LIT>" ) <EOL> with open ( metafile , '<STR_LIT:w>' ) as out_f : <EOL> out_f . write ( "<STR_LIT>" % ( dirpath ) ) <EOL> except OSError as e : <EOL> self . logger . error ( "<STR_LIT>" % ( <EOL> thumbdir , str ( e ) ) ) <EOL> return None <EOL> modtime = os . stat ( path ) . st_mtime <EOL> thumb_fname = self . _gethex ( "<STR_LIT>" % ( filename , modtime ) ) <EOL> thumbpath = os . path . join ( thumbdir , thumb_fname + "<STR_LIT>" ) <EOL> self . logger . debug ( "<STR_LIT>" % ( thumbpath ) ) <EOL> return thumbpath <EOL> def insert_thumbnail ( self , imgwin , thumbkey , thumbname , chname , name , path , <EOL> thumbpath , metadata , image_future ) : <EOL> menu = self . _mk_context_menu ( thumbkey , chname , name , path , image_future ) <EOL> thumbw = Widgets . Image ( native_image = imgwin , menu = menu , <EOL> style = '<STR_LIT>' ) <EOL> wd , ht = self . thumb_generator . get_window_size ( ) <EOL> thumbw . resize ( wd , ht ) <EOL> thumbw . add_callback ( '<STR_LIT>' , <EOL> lambda w : self . load_file ( thumbkey , chname , name , <EOL> path , image_future ) ) <EOL> text = self . query_thumb ( thumbkey , name , metadata ) <EOL> thumbw . set_tooltip ( text ) <EOL> vbox = Widgets . VBox ( ) <EOL> vbox . set_margins ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> vbox . set_spacing ( <NUM_LIT:0> ) <EOL> namelbl = Widgets . Label ( text = thumbname , halign = '<STR_LIT:left>' ) <EOL> vbox . add_widget ( namelbl , stretch = <NUM_LIT:0> ) <EOL> vbox . add_widget ( thumbw , stretch = <NUM_LIT:0> ) <EOL> vbox . cfg_expand ( <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> bnch = Bunch . Bunch ( widget = vbox , image = thumbw , <EOL> name = name , imname = name , namelbl = namelbl , <EOL> chname = chname , path = path , thumbpath = thumbpath , <EOL> image_future = image_future ) <EOL> with self . thmblock : <EOL> self . thumbDict [ thumbkey ] = bnch <EOL> self . thumbList . append ( thumbkey ) <EOL> sort_order = self . settings . get ( '<STR_LIT>' , None ) <EOL> if sort_order : <EOL> self . thumbList . sort ( ) <EOL> self . reorder_thumbs ( ) <EOL> return <EOL> self . w . thumbs . add_widget ( vbox , <EOL> self . thumbRowCount , self . thumbColCount ) <EOL> self . thumbColCount = ( self . thumbColCount + <NUM_LIT:1> ) % self . thumbNumCols <EOL> if self . thumbColCount == <NUM_LIT:0> : <EOL> self . thumbRowCount += <NUM_LIT:1> <EOL> self . _auto_scroll ( ) <EOL> self . logger . debug ( "<STR_LIT>" % ( name ) ) <EOL> def _auto_scroll ( self ) : <EOL> scrollp = self . w . auto_scroll . get_state ( ) <EOL> if scrollp : <EOL> self . fv . update_pending ( ) <EOL> self . w . thumbs_scroll . scroll_to_end ( ) <EOL> def clear_widget ( self ) : <EOL> """<STR_LIT>""" <EOL> with self . thmblock : <EOL> self . w . thumbs . remove_all ( ) <EOL> def reorder_thumbs ( self ) : <EOL> self . logger . debug ( "<STR_LIT>" ) <EOL> with self . thmblock : <EOL> self . clear_widget ( ) <EOL> self . thumbColCount = <NUM_LIT:0> <EOL> self . thumbRowCount = <NUM_LIT:0> <EOL> for thumbkey in self . thumbList : <EOL> bnch = self . thumbDict [ thumbkey ] <EOL> self . w . thumbs . add_widget ( bnch . widget , <EOL> self . thumbRowCount , self . thumbColCount ) <EOL> self . thumbColCount = ( ( self . thumbColCount + <NUM_LIT:1> ) % <EOL> self . thumbNumCols ) <EOL> if self . thumbColCount == <NUM_LIT:0> : <EOL> self . thumbRowCount += <NUM_LIT:1> <EOL> self . _auto_scroll ( ) <EOL> self . logger . debug ( "<STR_LIT>" ) <EOL> def query_thumb ( self , thumbkey , name , metadata ) : <EOL> result = [ ] <EOL> for kwd in self . keywords : <EOL> try : <EOL> text = kwd + '<STR_LIT>' + str ( metadata [ kwd ] ) <EOL> except Exception as e : <EOL> self . logger . warning ( "<STR_LIT>" % ( <EOL> kwd , str ( e ) ) ) <EOL> text = "<STR_LIT>" % ( kwd ) <EOL> result . append ( text ) <EOL> return '<STR_LIT:\n>' . join ( result ) <EOL> def _mk_context_menu ( self , thumbkey , chname , name , path , image_future ) : <EOL> menu = Widgets . Menu ( ) <EOL> item = menu . add_name ( "<STR_LIT>" ) <EOL> item . add_callback ( '<STR_LIT>' , <EOL> lambda w : self . load_file ( <EOL> thumbkey , chname , name , path , image_future ) ) <EOL> menu . add_separator ( ) <EOL> item = menu . add_name ( "<STR_LIT>" ) <EOL> item . add_callback ( '<STR_LIT>' , <EOL> lambda w : self . fv . remove_image_by_name ( <EOL> chname , name , impath = path ) ) <EOL> return menu <EOL> def update_thumbnail ( self , thumbkey , imgwin , name , metadata ) : <EOL> with self . thmblock : <EOL> try : <EOL> bnch = self . thumbDict [ thumbkey ] <EOL> except KeyError : <EOL> self . logger . debug ( "<STR_LIT>" <EOL> "<STR_LIT>" % ( str ( thumbkey ) ) ) <EOL> return <EOL> self . logger . info ( "<STR_LIT>" % ( name ) ) <EOL> bnch . image . _set_image ( imgwin ) <EOL> self . logger . debug ( "<STR_LIT>" ) <EOL> def add_image_info_cb ( self , viewer , channel , info ) : <EOL> save_thumb = self . settings . get ( '<STR_LIT>' , False ) <EOL> chname = channel . name <EOL> thumbkey = self . get_thumb_key ( chname , info . name , info . path ) <EOL> thumbpath = self . get_thumbpath ( info . path ) <EOL> with self . thmblock : <EOL> try : <EOL> bnch = self . thumbDict [ thumbkey ] <EOL> if bnch . thumbpath == thumbpath : <EOL> return <EOL> except KeyError : <EOL> pass <EOL> image = None <EOL> if ( thumbpath is not None ) and os . path . exists ( thumbpath ) : <EOL> save_thumb = False <EOL> try : <EOL> image = self . fv . load_image ( thumbpath ) <EOL> except Exception as e : <EOL> pass <EOL> try : <EOL> if image is None : <EOL> image = info . image_loader ( info . path ) <EOL> image . set ( name = info . name ) <EOL> self . fv . gui_do ( self . _make_thumb , chname , image , info . name , <EOL> info . path , thumbkey , info . image_future , <EOL> save_thumb = save_thumb , <EOL> thumbpath = thumbpath ) <EOL> except Exception as e : <EOL> self . logger . error ( "<STR_LIT>" % ( <EOL> info . path , str ( e ) ) ) <EOL> def __str__ ( self ) : <EOL> return '<STR_LIT>' </s>
