Beispiel #1
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)
Beispiel #2
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)