예제 #1
0
 def load_results(self, entry, append, searched=set()):
     """Load a few search results based on what's been typed.
     
     Requires at least three letters typed, and is careful not to load
     duplicate results.
     
     The searched argument persists across calls to this method, and should
     not be passed as an argument unless your intention is to trigger the
     loading of duplicate results.
     """
     text  = entry.get_text().lower()
     three = text[0:3]
     self.search, search = [ re_compile('(^|\s)' + string,
         flags=IGNORECASE).search for string in (text, three) ]
     if len(three) == 3 and three not in searched:
         searched.add(three)
         with open(join(PKG_DATA_DIR, 'cities.txt')) as cities:
             for line in cities:
                 city, lat, lon, country, state = line.split('\t')[0:5]
                 if search(city):
                     append([format_list([city,
                                          get_state(country, state),
                                          get_country(country)]),
                             float(lat),
                             float(lon)])
예제 #2
0
 def load_results(self, entry, append, searched=set()):
     """Load a few search results based on what's been typed.
     
     Requires at least three letters typed, and is careful not to load
     duplicate results.
     
     The searched argument persists across calls to this method, and should
     not be passed as an argument unless your intention is to trigger the
     loading of duplicate results.
     """
     text = entry.get_text().lower()
     three = text[0:3]
     self.search, search = [
         re_compile('(^|\s)' + string, flags=IGNORECASE).search
         for string in (text, three)
     ]
     if len(three) == 3 and three not in searched:
         searched.add(three)
         with open(join(PKG_DATA_DIR, 'cities.txt')) as cities:
             for line in cities:
                 city, lat, lon, country, state = line.split('\t')[0:5]
                 if search(city):
                     append([
                         format_list([
                             city,
                             get_state(country, state),
                             get_country(country)
                         ]),
                         float(lat),
                         float(lon)
                     ])
예제 #3
0
 def pretty_geoname(self):
     """Override Coordinates.pretty_geoname to read from IPTC."""
     names = []
     for key in [ 'City', 'ProvinceState', 'CountryName' ]:
         try: names.extend(self.exif[IPTC + key].values)
         except KeyError: pass
     length = sum(map(len, names))
     return format_list(names, ',\n' if length > 35 else ', ')
예제 #4
0
 def pretty_geoname(self):
     """Override Coordinates.pretty_geoname to read from IPTC."""
     names = []
     for key in ['City', 'ProvinceState', 'CountryName']:
         try:
             names.extend(self.exif[IPTC + key].values)
         except KeyError:
             pass
     length = sum(map(len, names))
     return format_list(names, ',\n' if length > 35 else ', ')