Exemplo n.º 1
0
    def __init__(self):
        super(PhotoListStore, self).__init__(GdkPixbuf.Pixbuf, str, str, str,
                                             int, object, object)

        self._delay_time = 0

        self.save = SaveListStore()
        for entry in self.save.load():
            self.append(entry, is_delay=True)

        self.queue = RecentQueue()
        self.ban_db = BlackList()
        self.photoframe = PhotoFrameFactory().create(self)
        self.idle = SessionIdle()
        self._start_timer()
Exemplo n.º 2
0
    def __init__(self):
        super(PhotoListStore, self).__init__(
            GdkPixbuf.Pixbuf, str, str, str, int, object, object)

        self._delay_time = 0

        self.save = SaveListStore()
        for entry in self.save.load():
            self.append(entry, is_delay=True)

        self.queue = RecentQueue()
        self.ban_db = BlackList()
        self.photoframe = PhotoFrameFactory().create(self)
        self.idle = SessionIdle()
        self._start_timer()
Exemplo n.º 3
0
class PhotoListStore(Gtk.ListStore):
    """ListStore for Photo sources.

    0,    1,      2,        3,      4,       5,      6
    icon, source, target, argument, weight, options, object
    """
    def __init__(self):
        super(PhotoListStore, self).__init__(GdkPixbuf.Pixbuf, str, str, str,
                                             int, object, object)

        self._delay_time = 0

        self.save = SaveListStore()
        for entry in self.save.load():
            self.append(entry, is_delay=True)

        self.queue = RecentQueue()
        self.ban_db = BlackList()
        self.photoframe = PhotoFrameFactory().create(self)
        self.idle = SessionIdle()
        self._start_timer()

    def append(self, d, iter=None, is_delay=False):
        # check for type of source names
        source_name = d['source']
        if isinstance(source_name, str):
            source_name = source_name.decode('utf-8')

        if 'source' not in d or source_name not in plugins.MAKE_PHOTO_TOKEN:
            return None

        obj = plugins.MAKE_PHOTO_TOKEN[source_name](d['target'], d['argument'],
                                                    d['weight'], d['options'],
                                                    self)
        pixbuf = plugins.PLUGIN_INFO_TOKEN[source_name]().get_icon_pixbuf()
        list = [
            pixbuf, d['source'], d['target'], d['argument'], d['weight'],
            d['options'], obj
        ]

        new_iter = self.insert_before(iter, list)

        # print d['source'], obj.delay_for_prepare, delay

        if is_delay and obj.delay_for_prepare:
            GLib.timeout_add_seconds(self._delay_time, obj.prepare)
            self._delay_time += 5
        else:
            obj.prepare()

        return new_iter

    def remove(self, iter):
        self.get_value(iter, 6).exit()  # liststore object
        super(PhotoListStore, self).remove(iter)

    def next_photo(self, *args):
        GObject.source_remove(self._timer)
        self._start_timer(change='force')

    def delete_photo(self, url):
        self.queue.remove(url)
        self.photoframe.remove_photo(url)

        GObject.source_remove(self._timer)
        self._start_timer(False)

    def save_settings(self):
        self.save.save(self)

    def _start_timer(self, change=True):
        frame = self.photoframe
        is_mouse_over = frame.check_mouse_on_frame() and change != 'force'

        if change and not is_mouse_over and not frame.has_trash_dialog():
            self.recursion_depth = 0
            updated = self._change_photo()
        else:
            updated = False

        if updated is False:
            interval = 3
            # print "skip!"
        elif frame.is_fullscreen() or frame.is_screensaver():
            interval = SETTINGS.get_int('interval-fullscreen')
        else:
            interval = SETTINGS.get_int('interval')

        self._timer = GLib.timeout_add_seconds(interval, self._start_timer)
        return False

    def _change_photo(self):
        if self.idle.check():
            return True

        # liststore object
        target_list = [x[6] for x in self if x[6].is_available()]
        if target_list:
            target = WeightedRandom(target_list)
            target().get_photo(self._show_photo_cb)
            updated = True
        else:
            self.photoframe.set_photo(None)
            updated = False

        return updated

    def _show_photo_cb(self, data, photo):
        if self.ban_db.check_banned_for(photo.get('url')):
            # print "ban!: %s" % photo.get('url')
            self._change_photo()
        elif self.photoframe.set_photo(photo):
            self.queue.append(photo)
        elif self.recursion_depth < 10:  # check recursion depth
            print "oops!: %s" % photo
            self.recursion_depth += 1
            self._change_photo()
Exemplo n.º 4
0
class PhotoListStore(Gtk.ListStore):
    """ListStore for Photo sources.

    0,    1,      2,        3,      4,       5,      6
    icon, source, target, argument, weight, options, object
    """

    def __init__(self):
        super(PhotoListStore, self).__init__(
            GdkPixbuf.Pixbuf, str, str, str, int, object, object)

        self._delay_time = 0

        self.save = SaveListStore()
        for entry in self.save.load():
            self.append(entry, is_delay=True)

        self.queue = RecentQueue()
        self.ban_db = BlackList()
        self.photoframe = PhotoFrameFactory().create(self)
        self.idle = SessionIdle()
        self._start_timer()

    def append(self, d, iter=None, is_delay=False):
        # check for type of source names
        source_name = d['source']
        if isinstance(source_name, str):
            source_name = source_name.decode('utf-8')

        if 'source' not in d or source_name not in plugins.MAKE_PHOTO_TOKEN:
            return None

        obj = plugins.MAKE_PHOTO_TOKEN[ source_name ](
            d['target'], d['argument'], d['weight'], d['options'], self)
        pixbuf = plugins.PLUGIN_INFO_TOKEN[ source_name ]().get_icon_pixbuf()
        list = [ pixbuf, d['source'],
                 d['target'], d['argument'], d['weight'], d['options'], obj ]

        new_iter = self.insert_before(iter, list)

        # print d['source'], obj.delay_for_prepare, delay

        if is_delay and obj.delay_for_prepare:
            GLib.timeout_add_seconds(self._delay_time, obj.prepare)
            self._delay_time += 5
        else:
            obj.prepare()

        return new_iter

    def remove(self, iter):
        self.get_value(iter, 6).exit() # liststore object
        super(PhotoListStore, self).remove(iter)

    def next_photo(self, *args):
        GObject.source_remove(self._timer)
        self._start_timer(change='force')

    def delete_photo(self, url):
        self.queue.remove(url)
        self.photoframe.remove_photo(url)

        GObject.source_remove(self._timer)
        self._start_timer(False)

    def save_settings(self):
        self.save.save(self)

    def _start_timer(self, change=True):
        frame = self.photoframe
        is_mouse_over = frame.check_mouse_on_frame() and change != 'force'

        if change and not is_mouse_over and not frame.has_trash_dialog():
            self.recursion_depth = 0
            updated = self._change_photo()
        else:
            updated = False

        if updated is False:
            interval = 3
            # print "skip!"
        elif frame.is_fullscreen() or frame.is_screensaver():
            interval = SETTINGS.get_int('interval-fullscreen')
        else:
            interval = SETTINGS.get_int('interval')

        self._timer = GLib.timeout_add_seconds(interval, self._start_timer)
        return False

    def _change_photo(self):
        if self.idle.check():
            return True

        # liststore object
        target_list = [ x[6] for x in self if x[6].is_available() ]
        if target_list:
            target = WeightedRandom(target_list)
            target().get_photo(self._show_photo_cb)
            updated = True
        else:
            self.photoframe.set_photo(None)
            updated = False

        return updated

    def _show_photo_cb(self, data, photo):
        if self.ban_db.check_banned_for(photo.get('url')):
            # print "ban!: %s" % photo.get('url')
            self._change_photo()
        elif self.photoframe.set_photo(photo):
            self.queue.append(photo)
        elif self.recursion_depth < 10: # check recursion depth
            print "oops!: %s" % photo
            self.recursion_depth += 1
            self._change_photo()