Пример #1
0
 def save_file(self, filename, export=False, **options):
     thumbnail_pixbuf = self.save_doc_to_file(filename, self.doc, export=export, **options)
     if "multifile" in options:
         # Skip thumbnail generation and recentmanager stuff: filename
         # is not reflective of actual disk filenames in this case, and it
         # would be incorrect to save a combined thumb for each file.
         return
     if not export:
         self.filename = os.path.abspath(filename)
         recent_mgr = pygtkcompat.gtk.recent_manager_get_default()
         uri = helpers.filename2uri(self.filename)
         recent_data = dict(
             app_name="mypaint",
             app_exec=sys.argv_unicode[0].encode("utf-8"),
             # todo: get mime_type
             mime_type="application/octet-stream",
         )
         if pygtkcompat.USE_GTK3:
             # No Gtk.RecentData.new() as of 3.4.2-0ubuntu0.3,
             # nor can we set the fields of an empty one :(
             recent_mgr.add_item(uri)
         else:
             recent_mgr.add_full(uri, recent_data)
     if not thumbnail_pixbuf:
         thumbnail_pixbuf = self.doc.model.render_thumbnail()
     helpers.freedesktop_thumbnail(filename, thumbnail_pixbuf)
Пример #2
0
 def save_file(self, filename, export=False, **options):
     thumbnail_pixbuf = self.save_doc_to_file(filename,
                                              self.doc,
                                              export=export,
                                              **options)
     if "multifile" in options or not os.path.isfile(filename):
         # Multifile save, or failed save (error dialog was already shown).
         # Skip thumbnail generation attempt and recentmanager stuff.
         return
     if not export:
         self.filename = os.path.abspath(filename)
         recent_mgr = gtk2compat.gtk.recent_manager_get_default()
         uri = helpers.filename2uri(self.filename)
         recent_data = dict(
             app_name='mypaint',
             app_exec=sys.argv_unicode[0].encode('utf-8'),
             # todo: get mime_type
             mime_type='application/octet-stream')
         if gtk2compat.USE_GTK3:
             # No Gtk.RecentData.new() as of 3.4.2-0ubuntu0.3,
             # nor can we set the fields of an empty one :(
             recent_mgr.add_item(uri)
         else:
             recent_mgr.add_full(uri, recent_data)
     if not thumbnail_pixbuf:
         options["background"] = not options.get("alpha", False)
         thumbnail_pixbuf = self.doc.model.render_thumbnail(**options)
     helpers.freedesktop_thumbnail(filename, thumbnail_pixbuf)
Пример #3
0
    def save_file(self, filename, export=False, **options):
        thumbnail_pixbuf = self.save_doc_to_file(filename, self.doc, export=export, **options)
        if not export:
            self.filename = os.path.abspath(filename)
            gtk.recent_manager_get_default().add_full(helpers.filename2uri(self.filename),
                    {
                        'app_name': 'mypaint',
                        'app_exec': sys.argv_unicode[0].encode('utf-8'),
                        # todo: get mime_type
                        'mime_type': 'application/octet-stream'
                    }
            )

        if not thumbnail_pixbuf:
            thumbnail_pixbuf = self.doc.model.render_thumbnail()
        helpers.freedesktop_thumbnail(filename, thumbnail_pixbuf)
Пример #4
0
    def save_file(self, filename, export=False, **options):
        """Saves the main document to one or more files (app/toplevel)

        :param filename: The base filename to save
        :param bool export: True if exporting
        :param **options: Pass-through options

        This method invokes `_save_doc_to_file()` with the main working
        doc, but also attempts to save thumbnails and perform recent
        files list management, when appropriate.

        See `_save_doc_to_file()`
        """
        thumbnail_pixbuf = self._save_doc_to_file(
            filename,
            self.doc,
            export=export,
            statusmsg=True,
            **options
        )
        if "multifile" in options:  # thumbs & recents are inappropriate
            return
        if not os.path.isfile(filename):  # failed to save
            return
        if not export:
            self.filename = os.path.abspath(filename)
            basename, ext = os.path.splitext(self.filename)
            recent_mgr = Gtk.RecentManager.get_default()
            uri = lib.glib.filename_to_uri(self.filename)
            recent_data = Gtk.RecentData()
            recent_data.app_name = "mypaint"
            recent_data.app_exec = sys.argv_unicode[0].encode("utf-8")
            mime_default = "application/octet-stream"
            fmt, mime_type = self.ext2saveformat.get(ext, (None, mime_default))
            recent_data.mime_type = mime_type
            recent_mgr.add_full(uri, recent_data)
        if not thumbnail_pixbuf:
            options["render_background"] = not options.get("alpha", False)
            thumbnail_pixbuf = self.doc.model.render_thumbnail(**options)
        helpers.freedesktop_thumbnail(filename, thumbnail_pixbuf)
Пример #5
0
    def save_file(self, filename, export=False, **options):
        """Saves the main document to one or more files (app/toplevel)

        :param filename: The base filename to save
        :param bool export: True if exporting
        :param **options: Pass-through options

        This method invokes `_save_doc_to_file()` with the main working
        doc, but also attempts to save thumbnails and perform recent
        files list management, when appropriate.

        See `_save_doc_to_file()`
        """
        thumbnail_pixbuf = self._save_doc_to_file(
            filename,
            self.doc,
            export=export,
            statusmsg=True,
            **options
        )
        if "multifile" in options:  # thumbs & recents are inappropriate
            return
        if not os.path.isfile(filename):  # failed to save
            return
        if not export:
            self.filename = os.path.abspath(filename)
            basename, ext = os.path.splitext(self.filename)
            recent_mgr = Gtk.RecentManager.get_default()
            uri = lib.glib.filename_to_uri(self.filename)
            recent_data = Gtk.RecentData()
            recent_data.app_name = "mypaint"
            recent_data.app_exec = sys.argv_unicode[0].encode("utf-8")
            mime_default = "application/octet-stream"
            fmt, mime_type = self.ext2saveformat.get(ext, (None, mime_default))
            recent_data.mime_type = mime_type
            recent_mgr.add_full(uri, recent_data)
        if not thumbnail_pixbuf:
            options["render_background"] = not options.get("alpha", False)
            thumbnail_pixbuf = self.doc.model.render_thumbnail(**options)
        helpers.freedesktop_thumbnail(filename, thumbnail_pixbuf)
Пример #6
0
 def update_preview_cb(self, file_chooser, preview):
     filename = file_chooser.get_preview_filename()
     if filename:
         filename = filename.decode('utf-8')
         pixbuf = helpers.freedesktop_thumbnail(filename)
         if pixbuf:
             # if pixbuf is smaller than 256px in width, copy it onto a transparent 256x256 pixbuf
             pixbuf = helpers.pixbuf_thumbnail(pixbuf, 256, 256, True)
             preview.set_from_pixbuf(pixbuf)
             file_chooser.set_preview_widget_active(True)
         else:
             #TODO display "no preview available" image
             pass
Пример #7
0
 def update_preview_cb(self, file_chooser, preview):
     filename = file_chooser.get_preview_filename()
     if filename:
         filename = filename.decode('utf-8')
         pixbuf = helpers.freedesktop_thumbnail(filename)
         if pixbuf:
             # if pixbuf is smaller than 256px in width, copy it onto a transparent 256x256 pixbuf
             pixbuf = helpers.pixbuf_thumbnail(pixbuf, 256, 256, True)
             preview.set_from_pixbuf(pixbuf)
             file_chooser.set_preview_widget_active(True)
         else:
             #TODO display "no preview available" image
             pass
Пример #8
0
 def save_file(self, filename, export=False, **options):
     thumbnail_pixbuf = self.save_doc_to_file(filename, self.doc, export=export, **options)
     if "multifile" in options or not os.path.isfile(filename):
         # Multifile save, or failed save (error dialog was already shown).
         # Skip thumbnail generation attempt and recentmanager stuff.
         return
     if not export:
         self.filename = os.path.abspath(filename)
         recent_mgr = gtk2compat.gtk.recent_manager_get_default()
         uri = helpers.filename2uri(self.filename)
         recent_data = dict(app_name='mypaint',
                            app_exec=sys.argv_unicode[0].encode('utf-8'),
                            # todo: get mime_type
                            mime_type='application/octet-stream')
         if gtk2compat.USE_GTK3:
             # No Gtk.RecentData.new() as of 3.4.2-0ubuntu0.3,
             # nor can we set the fields of an empty one :(
             recent_mgr.add_item(uri)
         else:
             recent_mgr.add_full(uri, recent_data)
     if not thumbnail_pixbuf:
         thumbnail_pixbuf = self.doc.model.render_thumbnail()
     helpers.freedesktop_thumbnail(filename, thumbnail_pixbuf)
Пример #9
0
                print 'Saved to', self.filename
                gtk.recent_manager_get_default().add_full(helpers.filename2uri(self.filename),
                        {
                            'app_name': 'mypaint',
                            'app_exec': sys.argv_unicode[0].encode('utf-8'),
                            # todo: get mime_type
                            'mime_type': 'application/octet-stream'
                        }
                )
            else:
                file_location = os.path.abspath(filename)
                print 'Exported to', os.path.abspath(file_location)

            if not thumbnail_pixbuf:
                thumbnail_pixbuf = self.doc.model.render_thumbnail()
            helpers.freedesktop_thumbnail(file_location, thumbnail_pixbuf)

    def update_preview_cb(self, file_chooser, preview):
        filename = file_chooser.get_preview_filename()
        if filename:
            filename = filename.decode('utf-8')
            pixbuf = helpers.freedesktop_thumbnail(filename)
            if pixbuf:
                # if pixbuf is smaller than 256px in width, copy it onto a transparent 256x256 pixbuf
                pixbuf = helpers.pixbuf_thumbnail(pixbuf, 256, 256, True)
                preview.set_from_pixbuf(pixbuf)
                file_chooser.set_preview_widget_active(True)
            else:
                #TODO display "no preview available" image
                pass