Esempio n. 1
0
 def change_item(self, old, new):
     """
     Replace the item 'old' with the 'new'.
     """
     ItemList.change_item(self, old, new)
     old.menu = None
     new.menu = weakref(self)
Esempio n. 2
0
File: object.py Progetto: clones/kaa
    def _canvased(self, canvas):
        if canvas == self._canvas:
            return

        self._canvas = weakref(canvas)
        if self["name"]:
            self._canvas._register_object_name(self["name"], self)
Esempio n. 3
0
 def browse(self):
     """
     Show the items in the directory in the menu
     """
     if not os.path.exists(self.filename):
         freevo.MessageWindow(_('Directory does not exist')).show()
         return
     self.item_menu = None
     try:
         # we need to lock the menustack here because during the
         # beacon query the parent item may get a notification to
         # rebuild its items and after that this item creates a
         # menu but is not connected to the stack anymore. The lock
         # will prevent any reloading.
         self.menustack.locked = True
         self._beacon_query = yield kaa.beacon.query(parent=self.info)
     finally:
         self.menustack.locked = False
     self._beacon_query.signals['changed'].connect_weak(self._query_update)
     self._beacon_query.monitor()
     item_menu = freevo.Menu(self.name,
                             self._get_items(False),
                             type=self.menu_type)
     item_menu.autoselect = self.config2value('autoplay_single_item')
     self.menustack.pushmenu(item_menu)
     self.item_menu = weakref(item_menu)
Esempio n. 4
0
 def pushmenu(self, menu):
     """
     Add a new Menu to the stack and show it
     """
     if not menu.choices:
         freevo.OSD_MESSAGE.post('directory is empty')
         return
     if menu.type != 'submenu':
         # remove submenus from the stack
         self.back_submenu(False)
     # set stack (self) pointer to menu
     menu.stack = weakref(self)
     if len(self._stack) > 0:
         previous = self._stack[-1]
     else:
         previous = None
     # set menu.pos and append
     menu.pos = len(self._stack)
     self._stack.append(menu)
     if menu.autoselect and len(menu.choices) == 1:
         log.info('autoselect action')
         # autoselect only item in the menu
         menu.choices[0]._get_actions()[0]()
         return
     # refresh will do the update
     self.refresh()
Esempio n. 5
0
 def __init__(self, stream):
     """
     Create object and add it to a stream.
     """
     super(Feature, self).__init__()
     self.stream = weakref(stream)
     stream.add_feature(self)
Esempio n. 6
0
 def change_item(self, old, new):
     """
     Replace the item 'old' with the 'new'.
     """
     ItemList.change_item(self, old, new)
     old.menu = None
     new.menu = weakref(self)
Esempio n. 7
0
 def pushmenu(self, menu):
     """
     Add a new Menu to the stack and show it
     """
     if not menu.choices:
         freevo.OSD_MESSAGE.post('directory is empty')
         return
     if menu.type != 'submenu':
         # remove submenus from the stack
         self.back_submenu(False)
     # set stack (self) pointer to menu
     menu.stack = weakref(self)
     if len(self._stack) > 0:
         previous = self._stack[-1]
     else:
         previous = None
     # set menu.pos and append
     menu.pos = len(self._stack)
     self._stack.append(menu)
     if menu.autoselect and len(menu.choices) == 1:
         log.info('autoselect action')
         # autoselect only item in the menu
         menu.choices[0]._get_actions()[0]()
         return
     # refresh will do the update
     self.refresh()
Esempio n. 8
0
File: client.py Progetto: clones/kaa
 def query(self, **query):
     """
     Query the database.
     """
     result = Query(self, **query)
     self._queries.append(weakref(result))
     yield kaa.inprogress(result)
     yield result
Esempio n. 9
0
 def select(self):
     """
     Display the media menu
     """
     # generate all other items
     items = yield self._get_items()
     type = '%s main menu' % self.media_type
     item_menu = freevo.Menu(self.name, items, type = type, reload_func = self.reload)
     item_menu.autoselect = True
     self.item_menu = weakref(item_menu)
     self.menustack.pushmenu(item_menu)
Esempio n. 10
0
 def select(self):
     """
     Display the media menu
     """
     # generate all other items
     items = yield self._get_items()
     type = '%s main menu' % self.media_type
     item_menu = freevo.Menu(self.name, items, type = type, reload_func = self.reload)
     item_menu.autoselect = True
     self.item_menu = weakref(item_menu)
     self.menustack.pushmenu(item_menu)
Esempio n. 11
0
File: object.py Progetto: clones/kaa
    def _wrap(self, evas_object):
        self._o = evas_object
        self._clip_object = None
        if not self._o:
            return

        self._o._canvas_object = weakref(self)
        self._force_sync_all_properties()
        #self._sync_properties()
        self._apply_parent_clip()
        self._queue_render()

        self.signals["wrapped"].emit()
Esempio n. 12
0
File: ipc.py Progetto: clones/kaa
    def __init__(self, parent, script, gdb=False):
        # Launch (-u is unbuffered stdout)
        self._parent = weakref(parent)

        if gdb:
            self._child = kaa.Process("gdb")
            self._gdb = script
        else:
            self._child = kaa.Process([sys.executable, '-u', script])
            self._gdb = None
        self._child.stdout.signals['readline'].connect_weak(self._handle_line)
        self._child.stderr.signals['readline'].connect_weak(self._handle_line)
        self._name = os.path.basename(os.path.dirname(script))
Esempio n. 13
0
 def __init__(self, parent):
     """
     Init the item. Sets all needed variables, if parent is given also
     inherit some settings from there.
     """
     self.__name = u''
     self.__description  = ''
     self.__image = None
     self.info = {}
     self.menu = None
     self.parent = None
     if parent:
         self.parent = weakref(parent)
Esempio n. 14
0
 def __init__(self, parent):
     """
     Init the item. Sets all needed variables, if parent is given also
     inherit some settings from there.
     """
     self.__name = u''
     self.__description = ''
     self.__image = None
     self.info = {}
     self.menu = None
     self.parent = None
     if parent:
         self.parent = weakref(parent)
Esempio n. 15
0
    def browse(self):
        """
        Show the items in the directory in the menu
        """
        if not os.path.exists(self.filename):
	    freevo.MessageWindow(_('Directory does not exist')).show()
            return
        self.item_menu = None
        self._beacon_query = yield kaa.beacon.query(parent=self.info)
        self._beacon_query.signals['changed'].connect_weak(self._get_items)
        self._beacon_query.monitor()
        item_menu = freevo.Menu(self.name, self._get_items(False), type = self.menu_type)
        item_menu.autoselect = self.config2value('autoplay_single_item')
        self.menustack.pushmenu(item_menu)
        self.item_menu = weakref(item_menu)
Esempio n. 16
0
File: movie.py Progetto: clones/kaa
    def _open(self, mrl):

        if self._player.has_capability(kaa.popcorn.CAP_OSD):
            self.osd.set_player(weakref.weakref(self._player))
            self.osd._queue_render()
        else:
            self.osd.set_player(None)

        self._aspect = None
        self._waiting_for_render = False

        self._create_canvas_subwindow()
        self._force_sync_property("detached")
        self._force_sync_property("visible")
        self._player.open(mrl, caps = kaa.popcorn.CAP_CANVAS)
Esempio n. 17
0
 def set_items(self, items, refresh=True):
     """
     Set/replace the items in this menu. If refresh is True, the menu
     stack will be refreshed and redrawn.
     """
     # delete ref to menu for old choices
     for c in self.choices:
         c.menu = None
     # set new choices and selection
     ItemList.set_items(self, items)
     # set menu (self) pointer to the items
     sref = weakref(self)
     for c in self.choices:
         c.menu = sref
     if refresh and self.stack:
         self.stack.refresh()
Esempio n. 18
0
 def set_items(self, items, refresh=True):
     """
     Set/replace the items in this menu. If refresh is True, the menu
     stack will be refreshed and redrawn.
     """
     # delete ref to menu for old choices
     for c in self.choices:
         c.menu = None
     # set new choices and selection
     ItemList.set_items(self, items)
     # set menu (self) pointer to the items
     sref = weakref(self)
     for c in self.choices:
         c.menu = sref
     if refresh and self.stack:
         self.stack.refresh()
Esempio n. 19
0
    def browse(self):
        """
        Show the items in the directory in the menu
        """
        if not os.path.exists(self.filename):
	    freevo.MessageWindow(_('Directory does not exist')).show()
            return
        self.item_menu = None
        try:
            # we need to lock the menustack here because during the
            # beacon query the parent item may get a notification to
            # rebuild its items and after that this item creates a
            # menu but is not connected to the stack anymore. The lock
            # will prevent any reloading.
            self.menustack.locked = True
            self._beacon_query = yield kaa.beacon.query(parent=self.info)
        finally:
            self.menustack.locked = False
        self._beacon_query.signals['changed'].connect_weak(self._query_update)
        self._beacon_query.monitor()
        item_menu = freevo.Menu(self.name, self._get_items(False), type = self.menu_type)
        item_menu.autoselect = self.config2value('autoplay_single_item')
        self.menustack.pushmenu(item_menu)
        self.item_menu = weakref(item_menu)
Esempio n. 20
0
 def __init__(self, player):
     self._player = weakref(player)
Esempio n. 21
0
 def connect(self, monitor):
     """
     Connect a new monitor.
     """
     self.monitors.append((weakref(monitor), [ False, [] ]))
Esempio n. 22
0
 def __init__(self, job, id, priority):
     self.valid = weakref(job)
     self.id = id
     self.priority = priority
     self.signal = kaa.Signal()
     Job.all.append(self)
Esempio n. 23
0
File: proxy.py Progetto: clones/kaa
 def __init__(self, player):
     self._player = weakref(player)
Esempio n. 24
0
 def __init__(self, item):
     self.__item = weakref(item)
Esempio n. 25
0
File: canvas.py Progetto: clones/kaa
 def _register_object_name(self, name, object):
     # FIXME: handle cleanup
     self._names[name] = weakref(object)
Esempio n. 26
0
 def __init__(self, item):
     self.__item = weakref(item)
Esempio n. 27
0
File: object.py Progetto: clones/kaa
 def _adopted(self, parent):
     self._parent = weakref(parent)
     self._force_sync_all_properties()
Esempio n. 28
0
 def __init__(self, job, id, priority):
     self.valid = weakref(job)
     self.id = id
     self.priority = priority
     self.signal = kaa.Signal()
     Job.all.append(self)
Esempio n. 29
0
 def connect(self, monitor):
     """
     Connect a new monitor.
     """
     self.monitors.append((weakref(monitor), [False, []]))
Esempio n. 30
0
class Playlist(freevo.MediaItem, freevo.ItemList):
    """
    Class for playlists. A playlist can be created with a list of items, a
    filename containing the playlist or a (list of) beacon query(s).
    """

    REPEAT_OFF = 0
    REPEAT_ITEM = 1
    REPEAT_PLAYLIST = 2

    type = 'playlist'

    def __init__(self,
                 name='',
                 playlist=[],
                 parent=None,
                 type=None,
                 random=False,
                 autoplay=False,
                 repeat=REPEAT_OFF):
        """
        Init the playlist

        @param playlist:
          - a filename to a playlist file (e.g. m3u)
          - a list of Items, beacon Items or filenames
          - a beacon query
          - an inprogress object pointing to something from the above
        @param type: either a media (video,audio,image) or None for all
        """
        freevo.MediaItem.__init__(self, parent)
        freevo.ItemList.__init__(self)
        self.name = kaa.str_to_unicode(name)
        if self.type == 'tv':
            type = 'video'
        # variables only for Playlist
        self._playlist = playlist
        self.autoplay = autoplay
        self.repeat = repeat
        self.media_type = type
        self.next = None
        self._playlist_valid = playlist == []
        self._random = random
        # create a basic info object
        self.info = {}

    @property
    def num_items(self):
        """
        Return the number of items in the playlist
        """
        return len(self.choices)

    def set_items(self, items, selected=None):
        """
        Set/replace the items.
        """
        super(Playlist, self).set_items(items, selected)
        self._playlist_valid = True

    def _read_m3u(self, plsname, content):
        """
        This is the (m3u) playlist reading function.
        """
        pl_lines = [l for l in content if not l.startswith('#')]
        curdir = os.path.dirname(plsname)
        playlist = []
        for line in pl_lines:
            line = line.replace('\\', '/').strip()
            if os.path.exists(os.path.join(curdir, line)):
                playlist.append(os.path.join(curdir, line))
        return playlist

    def _read_pls(self, plsname, content):
        """
        This is the (pls) playlist reading function.

        Arguments: plsname  - the playlist filename
        Returns:   The list of interesting lines in the playlist
        """
        pl_lines = [l for l in content if l.startswith('File')]
        for pos, line in enumerate(pl_lines):
            numchars = line.find("=") + 1
            if numchars > 0:
                pl_lines[pos] = line[numchars:]
        curdir = os.path.dirname(plsname)
        playlist = []
        for line in pl_lines:
            line = line.replace('\\', '/').strip()
            if os.path.exists(os.path.join(curdir, line)):
                playlist.append(os.path.join(curdir, line))
        return playlist

    @kaa.coroutine(policy=kaa.POLICY_SINGLETON)
    def _playlist_create_items(self):
        """
        Build the playlist. Create a list of items and filenames. This function
        will load the playlist file or expand directories
        """
        self._playlist_valid = True
        items = []
        if isinstance(self._playlist, kaa.InProgress):
            # something not finished, wait
            # This may happen for a beacon query
            self._playlist = yield self._playlist
        if isinstance(self._playlist, (str, unicode)):
            # playlist is a filename, load the file and create playlist
            self.set_url(self._playlist)
            log.info('create playlist for %s' % self._playlist)
            try:
                f = open(self._playlist)
                content = map(lambda l: l.strip(' \n\r'), f.readlines())
                f.close()
                if content and content[0].find("[playlist]") > -1:
                    self._playlist = self._read_pls(self._playlist, content)
                else:
                    self._playlist = self._read_m3u(self._playlist, content)
            except (OSError, IOError), e:
                log.error('playlist error: %s' % e)
                self._playlist = []
        if isinstance(self._playlist, kaa.beacon.Query):
            self._playlist = [self._playlist]
        # Note: playlist is a list of Items, strings (filenames) or a
        # beacon query now.
        plugins = freevo.MediaPlugin.plugins(self.media_type)
        for item in self._playlist:
            if isinstance(item, freevo.Item):
                # Item object, correct parent
                item = copy.copy(item)
                item.parent = weakref(self)
                items.append(item)
                continue
            if not isinstance(item, kaa.beacon.Query):
                # make item a beacon query
                item = yield kaa.beacon.query(filename=item)
            playlist = []
            fitems = item.get(filter='extmap')
            for p in plugins:
                playlist.extend(p.get(self, fitems))
            # sort beacon query on url
            playlist.sort(lambda x, y: cmp(x.url, y.url))
            # add to playlist
            items.extend(playlist)
        self.set_items(items, 0)
        self._playlist = []