Esempio n. 1
0
 def on_filter_changed(self, pspec, data):
     """Change filename extension."""
     current_name = self.dialog.get_filename().rsplit(".", 1)
     if len(current_name) == 2:
         ff = gtk.FileFilter()
         ff = self.dialog.get_filter()
         for i in gdk.pixbuf_get_formats():
             if i["description"] == ff.get_name():
                 for ext in i["extensions"]:
                     if current_name[1] == ext:
                         return
                 self.dialog.set_current_name("%s.%s" % (os.path.basename(current_name[0]), i["extensions"][0]))
Esempio n. 2
0
    def on_save_as_activated(self, widget):
        """Run FileChooserDialog and save file."""
        self.dialog = gtk.FileChooserDialog(
            _("Save comic as…"),
            buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_SAVE, gtk.RESPONSE_OK),
            action=gtk.FILE_CHOOSER_ACTION_SAVE,
        )
        self.dialog.set_icon_from_file(os.path.join(UI_DIR, "comics.svg"))
        self.dialog.set_do_overwrite_confirmation(True)
        self.dialog.set_current_name(self.__link.text + ".jpg")

        # Set filters, default jpg, without ico
        for format in gdk.pixbuf_get_formats():
            if format["is_writable"] and format["name"] != "ico":
                ff = gtk.FileFilter()
                ff.set_name(format["description"])
                for i in format["mime_types"]:
                    ff.add_mime_type(i)
                self.dialog.add_filter(ff)
                if format["name"] == "jpeg":
                    self.dialog.set_filter(ff)
        self.dialog.connect("notify::filter", self.on_filter_changed)

        if self.dialog.run() == gtk.RESPONSE_OK:
            ff = gtk.FileFilter()
            ff = self.dialog.get_filter()
            name = ff.get_name()
            for format in gdk.pixbuf_get_formats():
                if format["description"] == name:
                    name = format["name"]
                    break
            try:
                self.__pixbuf.save(self.dialog.get_filename(), name)
            except Exception:
                self.applet.show_message(
                    _("Failed to save <i>%s</i>.") % self.dialog.get_filename(), gtk.STOCK_DIALOG_ERROR
                )
        self.dialog.destroy()