This function is called when the user clicks the 'Save' button.
        We save the last taken shot to the folder and name specified.
433783
def _save_cb(self, w):
        
        format = self.saved_type
        if format is None:
            return self.fv.show_error("Please save an image first.")

        # create filename
        filename = self.w.name.get_text().strip()
        if len(filename) == 0:
            return self.fv.show_error("Please set a name for saving the file")
        self.save_name = filename

        if not filename.lower().endswith('.' + format):
            filename = filename + '.' + format

        # join to path
        path = self.w.folder.get_text().strip()
        if path == '':
            path = filename
        else:
            self.save_path = path
            path = os.path.join(path, filename)

        # copy last saved file
        self.fv.error_wrap(shutil.copyfile, self.tmpname, path)
1204321
def save(title='Save', parent=None, current_name='', folder=None,
         _before_run=None, _before_overwrite=None):
    """"""
    filechooser = gtk.FileChooserDialog(title, parent,
                                        gtk.FILE_CHOOSER_ACTION_SAVE,
                                        (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
                                         gtk.STOCK_SAVE, gtk.RESPONSE_OK))
    if current_name:
        filechooser.set_current_name(current_name)
    filechooser.set_default_response(gtk.RESPONSE_OK)

    if folder:
        filechooser.set_current_folder(folder)

    path = None
    while True:
        if _before_run:
            _before_run(filechooser)
            _before_run = None  # XXX: find better implications
        response = filechooser.run()
        if response != gtk.RESPONSE_OK:
            path = None
            break

        path = filechooser.get_filename()
        if not os.path.exists(path):
            break

        if ask_overwrite(path, parent, _before_run=_before_overwrite):
            break
        _before_overwrite = None  # XXX: same
    _destroy(filechooser)
    return path
121171
def save_lastfile(self, tfi):
        
        tf = models.TaskFile.objects.get(task=tfi.task, version=tfi.version, releasetype=tfi.releasetype,
                                         descriptor=tfi.descriptor, typ=tfi.typ)
        c = self.get_config()
        c['lastfile'] = tf.pk
        c.write()
549897
def save_file(self, data, filename, size=None, thumbnail_size=None):
        
        max_size = size or self.max_size
        thumbnail_size = thumbnail_size or self.thumbnail_size
        if data and isinstance(data, FileStorage):
            try:
                self.image = Image.open(data)
            except Exception as e:
                raise ValidationError("Invalid image: %s" % e)

        path = self.get_path(filename)
        # If Path does not exist, create it
        if not op.exists(op.dirname(path)):
            os.makedirs(os.path.dirname(path), self.permission)

        # Figure out format
        filename, format = self.get_save_format(filename, self.image)
        if self.image and (self.image.format != format or max_size):
            if max_size:
                image = self.resize(self.image, max_size)
            else:
                image = self.image
            self.save_image(image, self.get_path(filename), format)
        else:
            data.seek(0)
            data.save(path)
        self.save_thumbnail(data, filename, format, thumbnail_size)

        return filename
494819
def save(self, *args, **kwargs):
        """"""

        if not self.image:

            # Fetch image
            url = "http://img.youtube.com/vi/%s/0.jpg" % self.youtube_id
            response = None
            try:
                response = requests.get(url)
            except requests.exceptions.RequestException:
                # Nothing we can really do in this case
                pass

            if response is not None:
                # Jump through filesystem hoop to please photologue
                filename = self.youtube_id + '.jpg'
                filepath = os.path.join(mkdtemp(), filename)
                fp = open(filepath, 'wb')
                try:
                    fp.write(response.content)
                finally:
                    fp.close()

                # Check for a valid image
                image = None
                try:
                    image = Image.open(filepath)
                except IOError:
                    os.remove(filepath)

                if image is not None:
                    try:
                        # Overlay a play button if possible
                        video_play_image = \
                            preferences.GalleryPreferences.video_play_image
                        if video_play_image:
                            overlay = Image.open(video_play_image)
                            # Downsize image_overlay if it is larger than image
                            w1, h1 = image.size
                            w2, h2 = overlay.size
                            if w2 > w1 or h2 > h1:
                                ratio1 = w1 / float(h1)
                                ratio2 = w2 / float(h2)
                                if ratio1 > ratio2:
                                    resize_fract = h1 / float(h2)
                                else:
                                    resize_fract = w1 / float(w2)

                                overlay.resize(
                                    w2 * resize_fract,
                                    h2 * resize_fract,
                                    Image.ANTIALIAS
                                )

                            image.paste(
                                overlay,
                                (int((w1 - w2) / 2.0), int((h1 - h2) / 2.0)),
                                mask=overlay
                            )
                            image.save(filepath)

                        # Finally set image
                        image = File(open(filepath, 'rb'))
                        image.name = filename
                        self.image = image
                    finally:
                        os.remove(filepath)

        super(VideoEmbed, self).save(*args, **kwargs)
271446
def save(self) -> None:
        
        for name, field in self.fields.items():
            value = self.cleaned_data[name]
            if isinstance(value, UploadedFile):
                # Delete old file
                fname = self._s.get(name, as_type=File)
                if fname:
                    try:
                        default_storage.delete(fname.name)
                    except OSError:  # pragma: no cover
                        logger.error('Deleting file %s failed.' % fname.name)

                # Create new file
                newname = default_storage.save(self.get_new_filename(value.name), value)
                value._name = newname
                self._s.set(name, value)
            elif isinstance(value, File):
                # file is unchanged
                continue
            elif isinstance(field, forms.FileField):
                # file is deleted
                fname = self._s.get(name, as_type=File)
                if fname:
                    try:
                        default_storage.delete(fname.name)
                    except OSError:  # pragma: no cover
                        logger.error('Deleting file %s failed.' % fname.name)
                del self._s[name]
            elif value is None:
                del self._s[name]
            elif self._s.get(name, as_type=type(value)) != value:
                self._s.set(name, value)
453050
def autosave(self):
        
        # make sure we're suppoed to
        if self.button_autosave.is_checked():

            # save the file
            self.save_file(_os.path.join(self._autosave_directory, "%04d " % (self.number_file.get_value()) + self._label_path.get_text()))

            # increment the counter
            self.number_file.increment()
1338544
def saveLastScreenImage(self):
        
        bitmap = self.getLastScreenImage()
        _, target_file = tempfile.mkstemp(".png")
        cv2.imwrite(target_file, bitmap)
253892
def save_camera_position(self):
        
        self.saved_camera_positions.append(self.camera_position)
        ncam = len(self.saved_camera_positions)
        camera_position = self.camera_position[:]  # py2.7 copy compatibility

        def load_camera_position():
            self.camera_position = camera_position

        self.saved_camera_menu.addAction('Camera Position %2d' % ncam,
                                         load_camera_position)
1164347
def save(self, filename):
        
        with open(filename, "wb") as fd:
            fd.write(self.__buff)
1117473
def save(self, file_or_wfs, filename=None, bbox=None, overwrite=None):
        ''''''
        self._mark_as_changed()
        override = filename is not None
        filename = filename or getattr(file_or_wfs, 'filename')

        if self.basename and not override:
            basename = self.basename(self._instance)
        elif filename:
            basename = splitext(filename)[0]
        else:
            raise ValueError('Filename is required')

        ext = extension(filename)
        prefix = self.upload_to(self._instance) if callable(self.upload_to) else self.upload_to
        kwargs = {'prefix': prefix, 'overwrite': overwrite}

        if self.optimize is not None:
            should_optimize = self.optimize
        else:
            should_optimize = current_app.config['FS_IMAGES_OPTIMIZE']

        def name(size=None):
            if size:
                return '.'.join(['-'.join([basename, str(size)]), ext])
            else:
                return '.'.join([basename, ext])

        if self.max_size:
            resized = resize(file_or_wfs, self.max_size)
            file_or_wfs.seek(0)
            if resized:
                self.original = self.fs.save(file_or_wfs, name('original'), **kwargs)
                self.filename = self.fs.save(resized, name(), **kwargs)
            else:
                self.filename = self.fs.save(file_or_wfs, name(), **kwargs)
        elif should_optimize:
            optimized = optimize(file_or_wfs)
            file_or_wfs.seek(0)
            self.original = self.fs.save(file_or_wfs, name('original'), **kwargs)
            self.filename = self.fs.save(optimized, name(), **kwargs)
        else:
            self.filename = self.fs.save(file_or_wfs, name(), **kwargs)

        if self.thumbnail_sizes:
            self.bbox = bbox
            for size in self.thumbnail_sizes:
                file_or_wfs.seek(0)
                thumbnail = make_thumbnail(file_or_wfs, size, self.bbox)
                self.thumbnails[str(size)] = self.fs.save(FileStorage(thumbnail),
                                                          name(size),
                                                          **kwargs)
        return self.filename
831709
def save_images(self):
        
        res_dict = self.treeview.get_selected()
        clobber = self.settings.get('clobber', False)
        self.treeview.clear_selection()  # Automatically disables Save button

        # If user gives empty string, no suffix.
        if self.suffix:
            sfx = '_' + self.suffix
        else:
            sfx = ''

        # Also include channel name in suffix. This is useful if user likes to
        # open the same image in multiple channels.
        if self.settings.get('include_chname', True):
            sfx += '_' + self.chname

        # Process each selected file. Each can have multiple edited extensions.
        for infile in res_dict:
            f_pfx = os.path.splitext(infile)[0]  # prefix
            f_ext = '.fits'  # Only FITS supported
            oname = f_pfx + sfx + f_ext
            outfile = os.path.join(self.outdir, oname)

            self.w.status.set_text(
                'Writing out {0} to {1} ...'.format(shorten_name(infile, 10),
                                                    shorten_name(oname, 10)))
            self.logger.debug(
                'Writing out {0} to {1} ...'.format(infile, oname))

            if os.path.exists(outfile) and not clobber:
                self.logger.error('{0} already exists'.format(outfile))
                continue

            bnch = res_dict[infile]

            if bnch.path is None or not os.path.isfile(bnch.path):
                self._write_mosaic(f_pfx, outfile)
            else:
                shutil.copyfile(bnch.path, outfile)
                self._write_mef(f_pfx, bnch.extlist, outfile)

            self.logger.info('{0} written'.format(outfile))

        self.w.status.set_text('Saving done, see log')
545515
def save_files(self, selections) -> None:
        """"""
        try:
            currentpath = self.currentpath
            selections = selectiontools.Selections(selections)
            for selection in selections:
                if selection.name == 'complete':
                    continue
                path = os.path.join(currentpath, selection.name+'.py')
                selection.save_networkfile(filepath=path)
        except BaseException:
            objecttools.augment_excmessage(
                'While trying to save selections `%s` into network files'
                % selections)
698597
def save_last_response_to_file(self, filename):
        
        response = self.get_last_response()
        return self.save_response_to_file(response, filename)
945424
def _save_state(self, state_file, last_pk):
        """"""
        fp = open(state_file, 'w+')
        try:
            fp.write(str(last_pk))
        finally:
            fp.close()
987370
def _button_save_clicked(self):
        
        self.set_name(str(self._combobox_cmaps.currentText()))
        self.save_colormap()
        self._button_save.setEnabled(False)
        self._load_cmap_list()
489737
public function save()
	{
		if (self::$file_added)
			file_put_contents($this->getFileListName(), '<?php return ' . var_export(self::$files[$this->prefix], true) . ';');

		self::$file_added = false;
	}