<commit_before>#!/usr/bin/env python
"""
A class to represent the internal state of the program.

The internal state keeps track of:
- A list will all the loaded images.
- The position of the current image being shown in the list.
- A copy of the current image being shown, untouched.
- A scaled version of the current image.
- The same for the next image or the previous image, depending on the last
  operation having been 'next image' or 'previous image'
- The transformations(rotations) that where performed on the images.

The images are never fetched locally, they are always loaded using
'ImageLoader'.
"""
import os

from PyQt4 import QtGui, QtCore

from ImageLoader import ImageLoader, scale_image
from InternalException import InternalException

__author__ = "<NAME>"
__copyright__ = "Copyright 2010, <NAME>"
__credits__ = ["<NAME>"]
__license__ = "GPL"
__version__ = "1.0beta"
__maintainer__ = "<NAME>"
__email__ = "<EMAIL>"
__status__ = "Just for fun!"

alreadyInstantiated = False

class PreFetcher():
    def __init__(self, filename_image, viewportSize_imageScaled,
                 matrix=QtGui.QMatrix()):

        if isinstance(filename_image, QtGui.QPixmap) \
                 and isinstance(viewportSize_imageScaled, QtGui.QPixmap):
            self.image = filename_image
            self.imageScaled = viewportSize_imageScaled
            self.fromLoader = False
            self.toRescale = False
        elif isinstance(filename_image, str) \
               and isinstance(viewportSize_imageScaled, QtCore.QSize):
            self.loader = ImageLoader(filename_image, viewportSize_imageScaled,
                                      matrix)
            self.loader.start()
            self.fromLoader = True
            self.toRescale = False
        else:
            msg = 'Incorrect PreFetcher contructor: ' + \
                  str(type(filename_image)) + ', ' + \
                  str(type(viewportSize_imageScaled))
            raise InternalException(msg)

    def getImages(self):
        if self.fromLoader:
            self.loader.join()
            self.image = QtGui.QPixmap.fromImage(self.loader.image)
            self.imageScaled = QtGui.QPixmap.fromImage(self.loader.imageScaled)
            self.fromLoader = False<commit_msg>PreFetcher constructor accepts QString too now.<commit_after>#!/usr/bin/env python
"""
A class to represent the internal state of the program.

The internal state keeps track of:
- A list will all the loaded images.
- The position of the current image being shown in the list.
- A copy of the current image being shown, untouched.
- A scaled version of the current image.
- The same for the next image or the previous image, depending on the last
  operation having been 'next image' or 'previous image'
- The transformations(rotations) that where performed on the images.

The images are never fetched locally, they are always loaded using
'ImageLoader'.
"""
import os

from PyQt4 import QtGui, QtCore

from ImageLoader import ImageLoader, scale_image
from InternalException import InternalException

__author__ = "<NAME>"
__copyright__ = "Copyright 2010, <NAME>"
__credits__ = ["<NAME>"]
__license__ = "GPL"
__version__ = "1.0beta"
__maintainer__ = "<NAME>"
__email__ = "<EMAIL>"
__status__ = "Just for fun!"

alreadyInstantiated = False

class PreFetcher():
    def __init__(self, filename_image, viewportSize_imageScaled,
                 matrix=QtGui.QMatrix()):

        if isinstance(filename_image, QtGui.QPixmap) \
                 and isinstance(viewportSize_imageScaled, QtGui.QPixmap):
            self.image = filename_image
            self.imageScaled = viewportSize_imageScaled
            self.fromLoader = False
            self.toRescale = False
        elif (isinstance(filename_image, QtCore.QString) or \
                 isinstance(filename_image, str)) \
               and isinstance(viewportSize_imageScaled, QtCore.QSize):
            self.loader = ImageLoader(filename_image, viewportSize_imageScaled,
                                      matrix)
            self.loader.start()
            self.fromLoader = True
            self.toRescale = False
        else:
            msg = 'Incorrect PreFetcher contructor: ' + \
                  str(type(filename_image)) + ', ' + \
                  str(type(viewportSize_imageScaled))
            raise InternalException(msg)

    def getImages(self):
        if self.fromLoader:
            self.loader.join()
            self.image = QtGui.QPixmap.fromImage(self.loader.image)
            self.imageScaled = QtGui.QPixmap.fromImage(self.loader.imageScaled)
            self.fromLoader = False
{'fraction_non_alphanumeric': 0.08155339805825243, 'fraction_numerical': 0.0030204962243797194, 'mean_word_length': 2.679365079365079, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1597989', 'n_tokens_mistral': 1292, 'n_tokens_neox': 1253, 'n_words': 383}