コード例 #1
0
ファイル: filechooser.py プロジェクト: kogodm/meld
    def make_encoding_combo(self):
        """Create the combo box for text encoding selection"""

        # On Windows, the "current" encoding is the "system default
        # ANSI code-page", which is probably not what the user wants,
        # so we default to UTF-8.
        if sys.platform == 'win32':
            current = GtkSource.encoding_get_utf8()
        else:
            current = GtkSource.encoding_get_current()

        codecs = [
            (current.to_string(), current.get_charset()),
            (None, None),
        ]
        for encoding in GtkSource.encoding_get_all():
            codecs.append((encoding.to_string(), encoding.get_charset()))

        self.encoding_store.clear()
        for entry in codecs:
            self.encoding_store.append(entry)

        combo = Gtk.ComboBox()
        combo.set_model(self.encoding_store)
        cell = Gtk.CellRendererText()
        combo.pack_start(cell, True)
        combo.add_attribute(cell, 'text', 0)
        combo.set_row_separator_func(
            lambda model, it, data: not model.get_value(it, 1), None)
        combo.props.active = 0
        return combo