def __init__(self, db_query):
     SignalContainer.__init__(self)
     self.__db_query = db_query
     self.artist_missions_threadpool = MissionThreadPool(
         5, 1000, self.feedback)
     self.album_missions_threadpool = MissionThreadPool(
         5, 1000, self.feedback)
 def __init__(self, pkg_cache):
     '''
     init docs
     '''
     MissionThreadPool.__init__(
         self, 
         1,
         1,
         self.clean_action,
         )
     
     self.pkg_cache = pkg_cache
     self.install_action_dict = {}
     self.uninstall_action_dict = {}
     self.upgrade_action_dict = {}
     
     global_event.register_event("action-start", self.start_action)
     global_event.register_event("action-update", self.update_action)
 def __init__(self, db_query):
     SignalContainer.__init__(self)
     self.__db_query = db_query
     self.artist_missions_threadpool = MissionThreadPool(5, 1000, self.feedback)
     self.album_missions_threadpool = MissionThreadPool(5, 1000, self.feedback)
class FetchManager(SignalContainer):    
    
    def __init__(self, db_query):
        SignalContainer.__init__(self)
        self.__db_query = db_query
        self.artist_missions_threadpool = MissionThreadPool(5, 1000, self.feedback)
        self.album_missions_threadpool = MissionThreadPool(5, 1000, self.feedback)
        
    def connect_to_db(self):    
        self.autoconnect(self.__db_query, "full-update", self.__full_update)
        self.autoconnect(self.__db_query, "added", self.add_new_missions)
        self.__db_query.set_query("")
    
    def __full_update(self, db_query):    
        self.init_artist_missions()
        self.init_album_missions()
        
        self.artist_missions_threadpool.start()
        self.album_missions_threadpool.start()
        
    def add_new_missions(self, db_query, songs):    
        artist_keys = self.filter_artists([song.get_str("artist") for song in songs])
        album_infos = self.filter_albums([(song.get_str("artist"), song.get_str("album")) for song in songs])
        if artist_keys:
            if is_network_connected():
                self.artist_missions_threadpool.add_missions([FetchArtistCover(artist) for artist in artist_keys])
        if album_infos:    
            if is_network_connected():
                self.album_missions_threadpool.add_missions([FetchAlbumCover(album_info) for album_info in album_infos])
        
    def filter_artists(self, artist_keys):    
        artist_results = [artist.replace("/", "") for artist in artist_keys if not os.path.exists(get_cover_save_path(artist.replace("/", ""))) and artist]
        artist_results.sort()
        return artist_results
        
    def filter_albums(self, infos):
        results = []
        for key, value in infos:
            artist_name = key.replace("/", "")
            album_name = value.replace("/", "")
            if not os.path.exists(get_cover_save_path("%s-%s" % (artist_name, album_name))):
                results.append((artist_name, album_name))
        results.sort()        
        return results        
        
    def get_infos_from_db(self, tag, values=None):
        genres = []
        artists = []
        extened = False
        infos_dict =  self.__db_query.get_info(tag, genres, artists, values, extened)
        
        if tag == "artist":
            all_artist_keys = infos_dict.keys()
            if all_artist_keys:
                artist_results = [artist.replace("/", "") for artist in all_artist_keys if not os.path.exists(get_cover_save_path(artist.replace("/", ""))) and artist]
                artist_results.sort()
                return artist_results
            return []
            
        elif tag == "album":
            results = []
            for key, values in infos_dict.iteritems():
                artist_name = values[0].replace("/", "")
                album_name = key.replace("/", "")
                if not os.path.exists(get_cover_save_path("%s-%s" % (artist_name, album_name))):
                    results.append((artist_name, album_name))
            results.sort()        
            return results        
        else:
            return []
        
    def init_artist_missions(self):    
        artists = self.get_infos_from_db("artist")
        artist_missions = []
        if artists:
            if is_network_connected():
                artist_missions = [FetchArtistCover(artist_name.replace("/", "")) for artist_name in artists]
            
        if artist_missions:    
            if is_network_connected():
                self.artist_missions_threadpool.add_missions(artist_missions)
            
    def init_album_missions(self):        
        albums = self.get_infos_from_db("album")
        album_missions = []
        if albums:
            album_missions = [FetchAlbumCover(album_info) for album_info in albums]
            
        if album_missions:    
            self.album_missions_threadpool.add_missions(album_missions)
            
    @post_gui        
    def feedback(self, infos):        
        Dispatcher.reload_browser(infos)
            
            # utils.clip_surface(new_path)
            return True
        
def composite_images(files, width, height, write_file):
    try:
        surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, width, height)
        context = cairo.Context(surface)
        cr = gtk.gdk.CairoContext(context)
        cut_width = cut_height = width / 2
        for index, f in enumerate(files):
            pixbuf = get_optimum_pixbuf_from_file(f, cut_width, cut_height)
            if index % 2 == 0:
                start_x = 0
            else:    
                start_x = cut_width
            if index <= 1:    
                start_y = 0
            else:    
                start_y = cut_height
            cr.set_source_pixbuf(pixbuf, start_x, start_y)
            cr.paint()
        surface.write_to_png(write_file)    
        return write_file
    except:    
        return None

DoubanCover = DoubanCoverManager()        
cover_thread_pool = MissionThreadPool(5)
cover_thread_pool.start()
        try:
            pixbuf = get_optimum_pixbuf_from_file(old_path, SMALL_SIZE["x"], SMALL_SIZE["y"])
            
        except gobject.GError:    
            try:
                if os.path.exists(old_path): os.unlink(old_path)                            
            except: pass
            
            try:
                if os.path.exists(new_path): os.unlink(new_path)
            except: pass
            
            return False
        else:
            try:
                if os.path.exists(new_path): os.unlink(new_path)
            except: pass
            
            try:
                if os.path.exists(old_path): os.unlink(old_path)                            
            except: pass
            
            pixbuf.save(new_path, "jpeg", {"quality" : "100"})
            del pixbuf  
            return True

cache_manager = CacheManager()        
cache_thread_pool = MissionThreadPool(5)
cache_thread_pool.start()
        
Example #7
0
        self.pixbuf = None
        return True


if __name__ == '__main__':
    gtk.gdk.threads_init()
    module_frame = ModuleFrame(
        os.path.join(get_parent_dir(__file__, 2), "config.ini"))

    scrolled_window = ScrolledWindow()
    scrolled_window.set_size_request(788, 467)
    wallpaper_view = WallpaperView()
    scrolled_window.add_child(wallpaper_view)
    module_frame.add(scrolled_window)

    scrolled_window.connect("vscrollbar-state-changed",
                            wallpaper_view.load_more_background)

    download_pool = MissionThreadPool(5)
    download_pool.start()

    def message_handler(*message):
        (message_type, message_content) = message
        if message_type == "show_again":
            module_frame.send_module_info()
        elif message_type == "exit":
            module_frame.exit()

    module_frame.module_message_handler = message_handler
    module_frame.run()
Example #8
0
            return True


def composite_images(files, width, height, write_file):
    try:
        surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, width, height)
        context = cairo.Context(surface)
        cr = gtk.gdk.CairoContext(context)
        cut_width = cut_height = width / 2
        for index, f in enumerate(files):
            pixbuf = get_optimum_pixbuf_from_file(f, cut_width, cut_height)
            if index % 2 == 0:
                start_x = 0
            else:
                start_x = cut_width
            if index <= 1:
                start_y = 0
            else:
                start_y = cut_height
            cr.set_source_pixbuf(pixbuf, start_x, start_y)
            cr.paint()
        surface.write_to_png(write_file)
        return write_file
    except:
        return None


DoubanCover = DoubanCoverManager()
cover_thread_pool = MissionThreadPool(5)
cover_thread_pool.start()
            try:
                if os.path.exists(old_path): os.unlink(old_path)
            except:
                pass

            try:
                if os.path.exists(new_path): os.unlink(new_path)
            except:
                pass

            return False
        else:
            try:
                if os.path.exists(new_path): os.unlink(new_path)
            except:
                pass

            try:
                if os.path.exists(old_path): os.unlink(old_path)
            except:
                pass

            pixbuf.save(new_path, "jpeg", {"quality": "100"})
            del pixbuf
            return True


cache_manager = CacheManager()
cache_thread_pool = MissionThreadPool(5)
cache_thread_pool.start()
Example #10
0
from xdg import get_cache_file
from posterlib import Poster
image_poster = Poster()


def get_save_file(name):
    return get_cache_file("app/%s" % name)

class FetchImage(MissionThread):
    
    def __init__(self, name):
        MissionThread.__init__(self)
        self.app_name = name
        
    def start_mission(self):    
        image_uri = image_poster.query_image(self.app_name)
        if image_uri:
            utils.download(image_uri, get_save_file(self.app_name))
            
if __name__ == "__main__":            
    import gtk
    gtk.gdk.threads_init()
    app_list = "amarok chromium chrome exaile emacs".split()
    image_missions_pool = MissionThreadPool(5, exit_when_finish=True)
    if app_list:
        image_missions_pool.add_missions([FetchImage(app_name) for app_name in app_list])
    image_missions_pool.start()    
    gtk.main()

    
    
class FetchManager(SignalContainer):
    def __init__(self, db_query):
        SignalContainer.__init__(self)
        self.__db_query = db_query
        self.artist_missions_threadpool = MissionThreadPool(
            5, 1000, self.feedback)
        self.album_missions_threadpool = MissionThreadPool(
            5, 1000, self.feedback)

    def connect_to_db(self):
        self.autoconnect(self.__db_query, "full-update", self.__full_update)
        self.autoconnect(self.__db_query, "added", self.add_new_missions)
        self.__db_query.set_query("")

    def __full_update(self, db_query):
        self.init_artist_missions()
        self.init_album_missions()

        self.artist_missions_threadpool.start()
        self.album_missions_threadpool.start()

    def add_new_missions(self, db_query, songs):
        artist_keys = self.filter_artists(
            [song.get_str("artist") for song in songs])
        album_infos = self.filter_albums([
            (song.get_str("artist"), song.get_str("album")) for song in songs
        ])
        if artist_keys:
            if is_network_connected():
                self.artist_missions_threadpool.add_missions(
                    [FetchArtistCover(artist) for artist in artist_keys])
        if album_infos:
            if is_network_connected():
                self.album_missions_threadpool.add_missions([
                    FetchAlbumCover(album_info) for album_info in album_infos
                ])

    def filter_artists(self, artist_keys):
        artist_results = [
            artist.replace("/", "") for artist in artist_keys
            if not os.path.exists(get_cover_save_path(artist.replace("/", "")))
            and artist
        ]
        artist_results.sort()
        return artist_results

    def filter_albums(self, infos):
        results = []
        for key, value in infos:
            artist_name = key.replace("/", "")
            album_name = value.replace("/", "")
            if not os.path.exists(
                    get_cover_save_path("%s-%s" % (artist_name, album_name))):
                results.append((artist_name, album_name))
        results.sort()
        return results

    def get_infos_from_db(self, tag, values=None):
        genres = []
        artists = []
        extened = False
        infos_dict = self.__db_query.get_info(tag, genres, artists, values,
                                              extened)

        if tag == "artist":
            all_artist_keys = infos_dict.keys()
            if all_artist_keys:
                artist_results = [
                    artist.replace("/", "") for artist in all_artist_keys
                    if not os.path.exists(
                        get_cover_save_path(artist.replace("/", "")))
                    and artist
                ]
                artist_results.sort()
                return artist_results
            return []

        elif tag == "album":
            results = []
            for key, values in infos_dict.iteritems():
                artist_name = values[0].replace("/", "")
                album_name = key.replace("/", "")
                if not os.path.exists(
                        get_cover_save_path("%s-%s" %
                                            (artist_name, album_name))):
                    results.append((artist_name, album_name))
            results.sort()
            return results
        else:
            return []

    def init_artist_missions(self):
        artists = self.get_infos_from_db("artist")
        artist_missions = []
        if artists:
            if is_network_connected():
                artist_missions = [
                    FetchArtistCover(artist_name.replace("/", ""))
                    for artist_name in artists
                ]

        if artist_missions:
            if is_network_connected():
                self.artist_missions_threadpool.add_missions(artist_missions)

    def init_album_missions(self):
        albums = self.get_infos_from_db("album")
        album_missions = []
        if albums:
            album_missions = [
                FetchAlbumCover(album_info) for album_info in albums
            ]

        if album_missions:
            self.album_missions_threadpool.add_missions(album_missions)

    @post_gui
    def feedback(self, infos):
        Dispatcher.reload_browser(infos)
        # Return True to tell IconView call gc.collect() to release memory resource.
        if self.pixbuf:
            del self.pixbuf
        self.pixbuf = None    
        return True
    
if __name__ == '__main__':
    gtk.gdk.threads_init()
    module_frame = ModuleFrame(os.path.join(get_parent_dir(__file__, 2), "config.ini"))

    scrolled_window = ScrolledWindow()
    scrolled_window.set_size_request(788, 467)
    wallpaper_view = WallpaperView()
    scrolled_window.add_child(wallpaper_view)
    module_frame.add(scrolled_window)
    
    scrolled_window.connect("vscrollbar-state-changed", wallpaper_view.load_more_background)
    
    download_pool = MissionThreadPool(5)
    download_pool.start()
    
    def message_handler(*message):
        (message_type, message_content) = message
        if message_type == "show_again":
            module_frame.send_module_info()
        elif message_type == "exit":
            module_frame.exit()

    module_frame.module_message_handler = message_handler        
    module_frame.run()