Ejemplo n.º 1
0
 def draw(self, context, layout):
     # Maybe we should have different style when self.state == 'pressed'
     # for user feed back?
     if not app.playback_manager.is_playing:
         return
     if self.current_time is None or self.duration is None:
         return
     elif self.display_remaining:
         text = '-' + displaytext.short_time_string(self.duration - self.current_time)
     else:
         text = displaytext.short_time_string(self.duration)
     layout.set_font(0.75)
     layout.set_text_color(widgetutil.WHITE)
     text = layout.textbox(text)
     width, height = text.get_size()
     text.draw(context, 10, 0, width, height)
Ejemplo n.º 2
0
 def draw(self, context, layout):
     # Maybe we should have different style when self.state == 'pressed'
     # for user feed back?
     if not app.playback_manager.is_playing:
         return
     if self.current_time is None or self.duration is None:
         return
     elif self.display_remaining:
         text = '-' + displaytext.short_time_string(self.duration - self.current_time)
     else:
         text = displaytext.short_time_string(self.duration)
     layout.set_font(0.75)
     layout.set_text_color(widgetutil.WHITE)
     text = layout.textbox(text)
     width, height = text.get_size()
     text.draw(context, self.PADDING_LEFT, 0, width, height)
Ejemplo n.º 3
0
 def draw(self, context, layout):
     if not app.playback_manager.is_playing:
         return
     if self.current_time is not None:
         layout.set_font(0.75)
         layout.set_text_color(widgetutil.WHITE)
         text = layout.textbox(displaytext.short_time_string(self.current_time))
         width, height = text.get_size()
         text.draw(context, context.width-width, 0, width, height)
Ejemplo n.º 4
0
 def draw(self, context, layout):
     if not app.playback_manager.is_playing:
         return
     if self.current_time is not None:
         layout.set_font(0.75)
         layout.set_text_color(widgetutil.WHITE)
         text = layout.textbox(displaytext.short_time_string(self.current_time))
         width, height = text.get_size()
         text.draw(context, context.width-width, 0, width, height)
Ejemplo n.º 5
0
    def _make_context_menu_single(self, item):
        """Make the context menu for a single item."""
        # Format for the menu list:
        #
        # Each item is either None or separated into (label,
        # callback), more or less, kinda.  If it's None, it's actually
        # a separator. Otherwise....
        #
        # The label is one of two things:
        #  - A string, which is used as the label for the menu item
        #  - A tuple of (label_text, icon_path), in case you need icons
        #
        # The callback is one of three things:
        #  - None, in which case the menu item is made insensitive
        #  - A list, which means a submenu... should be in the same format
        #    as this normal menu
        #  - A method of some form.  In other words, a *real* callback :)

        menu_sections = []
        section = []

        def play_externally():
            app.widgetapp.open_file(item.filename)
            messages.MarkItemWatched(item).send_to_backend()

        # drm items seem to go in misc and are always unplayable.
        # given that, we check for drm first.
        if item.has_drm:
            section.append((_('Play Externally'), play_externally))
            section.append((_("Edit Item Details"), app.widgetapp.edit_items))

        elif item.is_playable:
            # Show File in Finder
            if not item.remote and not item.is_container_item:
                # most recent conversion
                last_converter = conversion_manager.get_last_conversion()
                if last_converter is not None:
                    converter = conversion_manager.lookup_converter(
                        last_converter)
                    if converter:

                        def convert(converter=converter.identifier):
                            app.widgetapp.convert_items(converter)

                        section.append(
                            (_('Convert to %(conversion)s',
                               {"conversion": converter.displayname}),
                             convert))

                # Convert menu
                convert_menu = self._make_convert_menu()
                section.append((_('Convert to...'), convert_menu))

            if not (item.device or item.remote):
                section.append((_('Set media kind as...'),
                                self._make_edit_metadata_menu()))
            if not item.remote and not item.device:
                if item.net_lookup_enabled:
                    label = _("Don't Use Online Lookup Data")
                    callback = app.widgetapp.disable_net_lookup_for_selection
                else:
                    label = _("Use Online Lookup Data")
                    callback = app.widgetapp.enable_net_lookup_for_selection
                section.append((label, callback))

            if section:
                menu_sections.append(section)
                section = []

            # Play
            play_in_miro = app.config.get(prefs.PLAY_IN_MIRO)
            playing_item = app.playback_manager.get_playing_item()
            is_paused = app.playback_manager.is_paused

            if item != playing_item:
                section.append((_('Play'), app.widgetapp.play_selection))
            elif item == playing_item and is_paused:
                section.append((_('Play'), app.playback_manager.toggle_paused))
            else:
                section.append((_('Pause'), app.playback_manager.pause))
            # Resume
            if play_in_miro and item != playing_item and item.resume_time > 0:
                resumetime = displaytext.short_time_string(item.resume_time)
                text = _("Resume at %(resumetime)s",
                         {"resumetime": resumetime})
                section.append((text, app.widgetapp.resume_play_selection))

            if not (item.device or item.remote):
                if item.video_watched:
                    section.append(
                        (_('Mark as Unplayed'),
                         messages.MarkItemUnwatched(item).send_to_backend))
                else:
                    section.append(
                        (_('Mark as Played'),
                         messages.MarkItemWatched(item).send_to_backend))

            # XXX "Play Just This Item" does not work for shared items
            # and not quite sure why at this moment.
            if not item.remote and item != playing_item and play_in_miro:
                section.append(
                    (_('Play Just This Item'),
                     lambda: app.playback_manager.start_with_items([item])))
                section.append((_('Play Externally'), play_externally))

            if section:
                menu_sections.append(section)
                section = []

            if not (item.device or item.remote):
                section.append(
                    (_("Edit Item Details"), app.widgetapp.edit_items))

                if not item.is_container_item:
                    section.append(
                        (_('Add to Playlist'), app.widgetapp.add_to_playlist))

        elif item.is_download:
            if not menu_sections:
                # make sure that the default menu option isn't destructive
                # (re: #16715)
                section.append(None)
            section.append((_('Cancel Download'),
                            messages.CancelDownload(item.id).send_to_backend))
            if item.is_paused:
                section.append(
                    (_('Pause Download'),
                     messages.PauseDownload(item.id).send_to_backend))
            else:
                section.append(
                    (_('Resume Download'),
                     messages.ResumeDownload(item.id).send_to_backend))

        else:
            if not (item.device or item.remote):
                # Download
                if not item.downloaded:
                    section.append(
                        (_('Download'),
                         messages.StartDownload(item.id).send_to_backend))
                    if item.is_failed_download:
                        section.append(
                            (_('Cancel Download'),
                             messages.CancelDownload(item.id).send_to_backend))
                else:
                    # Other
                    section.append(
                        (_("Edit Item Details"), app.widgetapp.edit_items))

            else:
                # Play
                section.append((_('Play'), app.widgetapp.play_selection))

        if item.is_seeding:
            section.append((_('Stop Seeding'),
                            messages.StopUpload(item.id).send_to_backend))
        elif not item.is_seeding and item.is_torrent:
            section.append((_('Resume Seeding'),
                            messages.StartUpload(item.id).send_to_backend))

        if item.downloaded and not item.remote:
            if file_navigator_name:
                reveal_text = _('Show File in %(progname)s',
                                {"progname": file_navigator_name})
            else:
                reveal_text = _('File on Disk')

            section.append(
                (reveal_text,
                 lambda: app.widgetapp.check_then_reveal_file(item.filename)))
            remove = self._remove_context_menu_item([item])
            if remove:
                section.append(remove)

        if section:
            menu_sections.append(section)
            section = []

        # don't add this section if the item is remote or a device OR
        # if it has nothing to add to the section.  that way we don't
        # end up with just a separator.
        if ((not (item.device or item.remote) and item.permalink
             or item.has_shareable_url)):
            section.append(
                (_('Copy URL to clipboard'), app.widgetapp.copy_item_url))

            if item.permalink:
                section.append(
                    (_('View Web Page'),
                     lambda: app.widgetapp.open_url(item.permalink)))

            if item.has_shareable_url:
                section.append(
                    (_('Share'), lambda: app.widgetapp.share_item(item)))

        if section:
            menu_sections.append(section)

        # put separators between all the menu sections
        menu = []
        for section in menu_sections:
            menu.extend(section)
            menu.append(None)

        # remove the last separator from the menu ... but make sure that we
        # don't try to do this if we came out of the block without actually
        # creating any entries in the context menu.
        try:
            del menu[-1]
        except IndexError:
            pass

        return menu
Ejemplo n.º 6
0
    def _make_context_menu_single(self, item):
        """Make the context menu for a single item."""
        # Format for the menu list:
        #
        # Each item is either None or separated into (label,
        # callback), more or less, kinda.  If it's None, it's actually
        # a separator. Otherwise....
        #
        # The label is one of two things:
        #  - A string, which is used as the label for the menu item
        #  - A tuple of (label_text, icon_path), in case you need icons
        #
        # The callback is one of three things:
        #  - None, in which case the menu item is made insensitive
        #  - A list, which means a submenu... should be in the same format
        #    as this normal menu
        #  - A method of some form.  In other words, a *real* callback :)

        menu_sections = []
        section = []

        def play_externally():
            app.widgetapp.open_file(item.video_path)
            messages.MarkItemWatched(item).send_to_backend()

        # drm items seem to go in misc and are always unplayable.
        # given that, we check for drm first.
        if item.has_drm:
            section.append((_('Play Externally'), play_externally))
            section.append((_("Edit Item Details"), app.widgetapp.edit_items))

        elif item.is_playable:
            # Show File in Finder
            if not item.remote and not item.is_container_item:
                # most recent conversion
                last_converter = conversion_manager.get_last_conversion()
                if last_converter is not None:
                    converter = conversion_manager.lookup_converter(
                        last_converter)
                    if converter:
                        def convert(converter=converter.identifier):
                            app.widgetapp.convert_items(converter)
                        section.append((
                                _('Convert to %(conversion)s',
                                  {"conversion": converter.displayname}),
                                convert))

                # Convert menu
                convert_menu = self._make_convert_menu()
                section.append((_('Convert to...'), convert_menu))

            if section:
                menu_sections.append(section)
                section = []

            # Play
            play_in_miro = app.config.get(prefs.PLAY_IN_MIRO)
            playing_item = app.playback_manager.get_playing_item()
            is_paused = app.playback_manager.is_paused

            if item != playing_item or (item == playing_item and is_paused):
                section.append((_('Play'), app.widgetapp.play_selection))
            else:
                section.append((_('Pause'), app.playback_manager.pause))
            # Resume
            if play_in_miro and item != playing_item and item.resume_time > 0:
                resumetime = displaytext.short_time_string(item.resume_time)
                text = _("Resume at %(resumetime)s",
                         {"resumetime": resumetime})
                section.append((text, app.widgetapp.resume_play_selection))

            if not (item.device or item.remote):
                if item.video_watched:
                    section.append((_('Mark as Unplayed'),
                        messages.MarkItemUnwatched(item).send_to_backend))
                else:
                    section.append((_('Mark as Played'),
                        messages.MarkItemWatched(item).send_to_backend))

            # XXX "Play Just This Item" does not work for shared items
            # and not quite sure why at this moment.
            if not item.remote and item != playing_item and play_in_miro:
                section.append((
                        _('Play Just This Item'),
                        lambda: app.playback_manager.start_with_items(
                            [item])))
                section.append((_('Play Externally'), play_externally))

            if section:
                menu_sections.append(section)
                section = []

            # Edit Item Details, Delete, Resume/Stop Seeding
            # this doesn't work for device or remote items.
            if not (item.device or item.remote):
                section.append((
                        _("Edit Item Details"), app.widgetapp.edit_items))

            if not (item.device or item.remote):
                if item.seeding_status == 'seeding':
                    section.append((
                            _('Stop Seeding'),
                            messages.StopUpload(item.id).send_to_backend))
                elif item.seeding_status == 'stopped':
                    section.append((
                            _('Resume Seeding'),
                            messages.StartUpload(item.id).send_to_backend))
                if not item.is_container_item:
                    section.append((
                            _('Add to Playlist'),
                            app.widgetapp.add_to_playlist))

        elif ((item.download_info is not None and
               item.download_info.state != 'failed')):
            if item.download_info.state != 'finished':
                if not menu_sections:
                    # make sure that the default menu option isn't destructive
                    # (re: #16715)
                    section.append(None)
                section.append((
                        _('Cancel Download'),
                        messages.CancelDownload(item.id).send_to_backend))
                if item.download_info.state != 'paused':
                    section.append((
                            _('Pause Download'),
                            messages.PauseDownload(item.id).send_to_backend))
                else:
                    section.append((
                            _('Resume Download'),
                            messages.ResumeDownload(item.id).send_to_backend))

        else:
            if not (item.device or item.remote):
                # Download
                if not item.downloaded:
                    section.append((
                            _('Download'),
                            messages.StartDownload(item.id).send_to_backend))
                    if (item.download_info and
                        item.download_info.state == u'failed'):
                        section.append((
                            _('Cancel Download'),
                            messages.CancelDownload(
                                item.id).send_to_backend))
                else:
                    # Other
                    section.append((_("Edit Item Details"), app.widgetapp.edit_items))

            else:
                # Play
                section.append((_('Play'), app.widgetapp.play_selection))

        if item.downloaded and not item.remote:
            if file_navigator_name:
                reveal_text = _('Show File in %(progname)s',
                                {"progname": file_navigator_name})
            else:
                reveal_text = _('File on Disk')

            section.append((reveal_text,
                lambda: app.widgetapp.check_then_reveal_file(item.video_path)))
            remove = self._remove_context_menu_item([item])
            if remove:
                section.append(remove)

        if section:
            menu_sections.append(section)
            section = []

        # don't add this section if the item is remote or a device OR
        # if it has nothing to add to the section.  that way we don't
        # end up with just a separator.
        if ((not (item.device or item.remote) and
             item.permalink or item.has_shareable_url)):
            section.append((
                    _('Copy URL to clipboard'), app.widgetapp.copy_item_url))
            
            if item.permalink:
                section.append((
                        _('View Web Page'),
                        lambda: app.widgetapp.open_url(item.permalink)))

            if item.has_shareable_url:
                section.append((
                        _('Share'), lambda: app.widgetapp.share_item(item)))

        if section:
            menu_sections.append(section)

        # put separators between all the menu sections
        menu = []
        for section in menu_sections:
            menu.extend(section)
            menu.append(None)

        # remove the last separator from the menu ... but make sure that we
        # don't try to do this if we came out of the block without actually
        # creating any entries in the context menu.
        try:
            del menu[-1]
        except IndexError:
            pass

        return menu
Ejemplo n.º 7
0
 def get_value(self, info):
     return displaytext.short_time_string(info.duration)
Ejemplo n.º 8
0
 def get_value(self, info):
     return displaytext.short_time_string(info.duration)