Example #1
0
 def init_menu(self):
     # first time calling this function, we need to set up the menu.
     encoding_menu = self.menu_item_fetcher["SubtitleEncodingMenu"]
     encoding_menu.show()
     self.default_item = RadioMenuItem(_('Default (UTF-8)'),
                                       self.action_name(None))
     self.default_item.set_state(True)
     self.default_item.connect("activate", self.on_activate, None)
     encoding_menu.append(self.default_item)
Example #2
0
    def populate_menu(self):
        """Add MenuItems to our menu."""
        if not self.track_info:
            self.make_empty_menu()
            self.currently_displayed_tracks = self.track_info
            return

        group = []
        for (track_id, label) in self.track_info:
            menu_item = RadioMenuItem(label, self.action_name(track_id))
            self.menu.append(menu_item)
            menu_item.connect('activate', self._on_track_change,
                              track_id)
            group.append(menu_item)

        for item in group[1:]:
            item.set_group(group[0])
        self.currently_displayed_tracks = self.track_info
Example #3
0
 def populate_submenu(self, category_menu, encodings):
     for encoding, name in encodings:
         label = '%s (%s)' % (name, encoding)
         menu_item = RadioMenuItem(label,
                                   self.action_name(encoding))
         menu_item.set_state(False)
         menu_item.connect("activate", self.on_activate, encoding)
         category_menu.append(menu_item)
         menu_item.set_group(self.default_item)
Example #4
0
    def make_items_for_tracks(self):
        """Get MenuItems for subtitle tracks embedded in the video."""

        if not self.all_tracks:
            return [self.none_available]

        items = []
        first_item = None
        for track_id, label in self.all_tracks:
            menu_item = RadioMenuItem(label, self.action_name(track_id))
            menu_item.connect("activate", self.on_change_track, track_id)
            items.append(menu_item)
            if first_item is None:
                first_item = menu_item
            else:
                menu_item.set_group(first_item)

        items.append(Separator())
        disable = RadioMenuItem(_("Disable Subtitles"), "DisableSubtitles")
        disable.connect("activate", self.on_disable)
        disable.set_group(first_item)
        items.append(disable)
        return items
Example #5
0
class SubtitleEncodingMenuUpdater(object):
    """Handles updating the subtitles encoding menu.

    This class is responsible for:
        - populating the subtitles encoding method
        - enabling/disabling the menu items
    """

    def __init__(self):
        self.menu_item_fetcher = MenuItemFetcher()
        self.default_item = None
        self.category_counter = itertools.count()

    def action_name(self, encoding):
        """Get the name of the menu item for a given encoding.

        :param: string name of the encoding, or None for the default encoding
        """
        if encoding is None:
            return 'SubtitleEncoding-Default'
        else:
            return 'SubtitleEncoding-%s' % encoding

    def has_encodings(self):
        return self.default_item is not None

    def update(self, reasons):
        encoding_menu = self.menu_item_fetcher["SubtitleEncodingMenu"]
        if app.playback_manager.is_playing_video:
            encoding_menu.enable()
        else:
            encoding_menu.disable()

    def add_menu(self, category_label, encodings):
        if not self.has_encodings():
            self.init_menu()
        category_menu = self.add_submenu(category_label)
        self.populate_submenu(category_menu, encodings)

    def init_menu(self):
        # first time calling this function, we need to set up the menu.
        encoding_menu = self.menu_item_fetcher["SubtitleEncodingMenu"]
        encoding_menu.show()
        self.default_item = RadioMenuItem(_('Default (UTF-8)'),
                                          self.action_name(None))
        self.default_item.set_state(True)
        self.default_item.connect("activate", self.on_activate, None)
        encoding_menu.append(self.default_item)

    def add_submenu(self, label):
        encoding_menu = self.menu_item_fetcher["SubtitleEncodingMenu"]
        name = "SubtitleEncodingCat-%s" % self.category_counter.next()
        category_menu = Menu(label, name, [])
        encoding_menu.append(category_menu)
        return category_menu

    def populate_submenu(self, category_menu, encodings):
        for encoding, name in encodings:
            label = '%s (%s)' % (name, encoding)
            menu_item = RadioMenuItem(label,
                                      self.action_name(encoding))
            menu_item.set_state(False)
            menu_item.connect("activate", self.on_activate, encoding)
            category_menu.append(menu_item)
            menu_item.set_group(self.default_item)

    def on_activate(self, menu_item, encoding):
        app.playback_manager.select_subtitle_encoding(encoding)