Ejemplo n.º 1
0
    def __init__(self, filename):
        super(MyImageViewer, self).__init__()

        self.filename = filename
        self.goTo = 0
        self.frameIdx = 0
        self.doZoom = False
        self.showOverlay = True

        self.imageFile = ImageFile(self.filename)
        self.initUI()
        self.updateUI()
Ejemplo n.º 2
0
def sort_images(source, destination, structure, use_modified_date=False):
    """Sort images"""

    if not os.path.exists(source):
        raise Exception("Source directory does not exist.")

    # Walk through the source looking for new images
    for root, folders, files in os.walk(source):
        for file in files:
            full_path = root.rstrip("/") + "/" + file.lstrip("/")

            # Ignore directories
            if os.path.isdir(full_path):
                continue

            # Create a ImageFile wrapper object for the file
            imagefile = ImageFile(
                full_path,
                use_modified_date=use_modified_date)

            # If no date is found ignore the file
            date = imagefile.get_timestamp()
            if date is None:
                continue

            # Generate destination path
            destination_path = "{}/{}/".format(
                destination.rstrip("/"),
                date.strftime(structure))

            # Move file
            imagefile.move(destination_path)

            print("Moved {} to {}.\n".format(
                full_path,
                imagefile.file_path))
Ejemplo n.º 3
0
class MyImageViewer(QMainWindow):
    def __init__(self, filename):
        super(MyImageViewer, self).__init__()

        self.filename = filename
        self.goTo = 0
        self.frameIdx = 0
        self.doZoom = False
        self.showOverlay = True

        self.imageFile = ImageFile(self.filename)
        self.initUI()
        self.updateUI()

    def prevFrame(self):
        if self.frameIdx > 0:
            self.frameIdx -= 1
            self.updateUI()

    def nextFrame(self):
        if self.frameIdx < self.imageFile.frameMax:
            self.frameIdx += 1
            self.updateUI()

    def firstFrame(self):
        self.frameIdx = 0
        self.updateUI()

    def lastFrame(self):
        self.frameIdx = self.imageFile.frameMax
        self.updateUI()

    def toggleZoom(self):
        self.doZoom = not self.doZoom
        self.updateUI()

    def toggleOverlay(self):
        self.showOverlay = not self.showOverlay
        # don't recenter since we're not changing the frame
        self.updateUI(updateCenter=False)

    def keyPressEvent(self, e):
        # tab key toggles overlay
        if e.key() == 16777217:
            self.toggleOverlay()
        # enter key goes to number entered
        elif e.key() == 16777220:
            if self.goTo >= 0 and self.goTo <= self.imageFile.frameMax:
                self.frameIdx = self.goTo
                self.updateUI()
            self.goTo = 0
        # ascii characters
        elif e.key() < 128:
            # number keys: store digits to build number of goto frame
            if chr(e.key()).isnumeric():
                self.goTo = 10 * self.goTo + int(chr(e.key()))
            # z toggles zoom
            elif chr(e.key()) == 'Z':
                self.toggleZoom()
            else:
                #print("key:",e.key())
                pass

    def updateUI(self, updateCenter=True):
        self.pixmap.setPixmap(self.getFramePixmap(self.frameIdx))
        outlineBox = self.imageFile.box(
            self.imageFile.findCenterOfMass(self.frameIdx))
        if self.boxRect: self.boxRect.setRect(*outlineBox)
        if self.doZoom:
            self.view.resetTransform()
            self.view.scale(2, 2)
            if updateCenter:
                self.view.centerOn(
                    *self.imageFile.findCenterOfMass(self.frameIdx))
        else:
            self.view.resetTransform()
        self.setWindowTitle(
            "%s... [%d/%d]" %
            (self.filename[:20], self.frameIdx, self.imageFile.frameMax))

    def getFramePixmap(self, i):
        image = QtGui.QImage(self.imageFile.getFrame(i, self.showOverlay),
                             self.imageFile.imgH, self.imageFile.imgW,
                             QtGui.QImage.Format_ARGB32)
        return QtGui.QPixmap.fromImage(image)

    def initUI(self):
        self.scene = QGraphicsScene()
        self.pixmap = QGraphicsPixmapItem()
        self.scene.addItem(self.pixmap)

        self.boxRect = None
        # option to draw box around overlay spots
        if False:
            outlineBox = self.imageFile.box(
                self.imageFile.findCenterOfMass(self.frameIdx))
            self.scene.addRect(QRect(*outlineBox),
                               pen=QtGui.QPen(QtCore.Qt.blue, 1))
            self.boxRect = self.scene.items()[
                0]  # not the best way to get rect

        self.view = MyGraphicsView(self)
        self.view.setDragMode(QGraphicsView.ScrollHandDrag)
        self.view.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        self.view.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        self.view.setScene(self.scene)

        self.setCentralWidget(self.view)

        controlDock = QDockWidget()
        controlDock.setFeatures(QDockWidget.NoDockWidgetFeatures)
        self.addDockWidget(Qt.TopDockWidgetArea, controlDock)

        main_layout = QHBoxLayout()
        main_layout.setContentsMargins(0, 0, 0, 0)
        # first frame button
        firstButton = QPushButton('<<', self)
        firstButton.clicked.connect(self.firstFrame)
        main_layout.addWidget(firstButton)
        # previous frame button
        prevButton = QPushButton('<', self)
        prevButton.clicked.connect(self.prevFrame)
        main_layout.addWidget(prevButton)
        # next frame button
        nextButton = QPushButton('>', self)
        nextButton.clicked.connect(self.nextFrame)
        main_layout.addWidget(nextButton)
        # last frame button
        lastButton = QPushButton('>>', self)
        lastButton.clicked.connect(self.lastFrame)
        main_layout.addWidget(lastButton)
        # zoom button
        zoomButton = QPushButton('zoom', self)
        zoomButton.clicked.connect(self.toggleZoom)
        main_layout.addWidget(zoomButton)
        # zoom button
        overlayButton = QPushButton('color', self)
        overlayButton.clicked.connect(self.toggleOverlay)
        main_layout.addWidget(overlayButton)
        # add dock widget
        dockContainerWidget = QWidget(controlDock)
        dockContainerWidget.setLayout(main_layout)
        dockContainerWidget.setGeometry(0, 0, self.imageFile.imgW, 20)

        self.setFixedSize(self.imageFile.imgW,
                          self.imageFile.imgH + dockContainerWidget.height())
        self.show()
Ejemplo n.º 4
0
 def __init__(self, directory):
     ImageFile.__init__(self, "")
     self.directory = directory
Ejemplo n.º 5
0
 def __init__(self, filename):
     ImageFile.__init__(self, filename)
     self.lock = Lock()
Ejemplo n.º 6
0
 def __init__(self, filename):
     ImageFile.__init__(self, filename)
     self.delegate = self.build_delegate(filename)
Ejemplo n.º 7
0
 def __init__(self, filename):
     ImageFile.__init__(self, filename)
     self.anim_enabled = False