dragfils
import sys
import os
from PyQt5.Qt import *
from PyQt5.QtGui import *
from PyQt5.QtCore import *
import cv2
import numpy as np
import os
from PyQt5.Qt import *
from PyQt5.QtGui import *
from PyQt5.QtCore import *
import cv2
import numpy as np
class TestListView(QListWidget):
dropped = pyqtSignal(list)
def __init__(self, type, parent=None):
super(TestListView, self).__init__(parent)
self.setAcceptDrops(True)
self.setIconSize(QSize(72, 72))
dropped = pyqtSignal(list)
def __init__(self, type, parent=None):
super(TestListView, self).__init__(parent)
self.setAcceptDrops(True)
self.setIconSize(QSize(72, 72))
def dragEnterEvent(self, event):
if event.mimeData().hasUrls:
event.accept()
else:
event.ignore()
if event.mimeData().hasUrls:
event.accept()
else:
event.ignore()
def dragMoveEvent(self, event):
if event.mimeData().hasUrls:
event.setDropAction(Qt.CopyAction)
event.accept()
else:
event.ignore()
if event.mimeData().hasUrls:
event.setDropAction(Qt.CopyAction)
event.accept()
else:
event.ignore()
def dropEvent(self, event):
if event.mimeData().hasUrls:
event.setDropAction(Qt.CopyAction)
event.accept()
links = []
for url in event.mimeData().urls():
links.append(str(url.toLocalFile()))
self.dropped.emit(links)
else:
event.ignore()
if event.mimeData().hasUrls:
event.setDropAction(Qt.CopyAction)
event.accept()
links = []
for url in event.mimeData().urls():
links.append(str(url.toLocalFile()))
self.dropped.emit(links)
else:
event.ignore()
class MainForm(QMainWindow):
def __init__(self, parent=None):
super(MainForm, self).__init__(parent)
def __init__(self, parent=None):
super(MainForm, self).__init__(parent)
self.view = TestListView(self)
self.view.dropped.connect(self.pictureDropped)
self.setCentralWidget(self.view)
self.file1=""
self.file2=""
self.urlnum=0
self.view.dropped.connect(self.pictureDropped)
self.setCentralWidget(self.view)
self.file1=""
self.file2=""
self.urlnum=0
def pictureDropped(self, l):
print(self.urlnum)
if(self.urlnum!=0 and self.urlnum%2==0):
print("clear")
self.view.clear()
self.file1=""
self.file2=""
for url in l:
if os.path.exists(url):
print(url)
if(self.file1=="" and self.file2==""):
self.file1=url
else:
self.file2=url
if(self.file1 is not "" and self.file2 is not ""):
img1=cv2.imread(self.file1,0)
img1=cv2.copyMakeBorder(img1, 5, 5, 4, 4, cv2.BORDER_CONSTANT, value=0)
img1=cv2.cvtColor(img1, cv2.COLOR_GRAY2BGR)
img2=cv2.imread(self.file2,0)
img2=cv2.copyMakeBorder(img2, 5, 5, 4, 4, cv2.BORDER_CONSTANT, value=0)
img2=cv2.cvtColor(img2, cv2.COLOR_GRAY2BGR)
stkimg=np.vstack([img1,img2])
strname="./stack/"+str(self.urlnum/2)+".jpg"
cv2.imwrite(strname,stkimg)
#cv2.waitKey(0)
self.urlnum=self.urlnum+1
icon = QIcon(url)
pixmap = icon.pixmap(72, 72)
icon = QIcon(pixmap)
item = QListWidgetItem(url, self.view)
item.setIcon(icon)
item.setStatusTip(url)
print(self.urlnum)
if(self.urlnum!=0 and self.urlnum%2==0):
print("clear")
self.view.clear()
self.file1=""
self.file2=""
for url in l:
if os.path.exists(url):
print(url)
if(self.file1=="" and self.file2==""):
self.file1=url
else:
self.file2=url
if(self.file1 is not "" and self.file2 is not ""):
img1=cv2.imread(self.file1,0)
img1=cv2.copyMakeBorder(img1, 5, 5, 4, 4, cv2.BORDER_CONSTANT, value=0)
img1=cv2.cvtColor(img1, cv2.COLOR_GRAY2BGR)
img2=cv2.imread(self.file2,0)
img2=cv2.copyMakeBorder(img2, 5, 5, 4, 4, cv2.BORDER_CONSTANT, value=0)
img2=cv2.cvtColor(img2, cv2.COLOR_GRAY2BGR)
stkimg=np.vstack([img1,img2])
strname="./stack/"+str(self.urlnum/2)+".jpg"
cv2.imwrite(strname,stkimg)
#cv2.waitKey(0)
self.urlnum=self.urlnum+1
icon = QIcon(url)
pixmap = icon.pixmap(72, 72)
icon = QIcon(pixmap)
item = QListWidgetItem(url, self.view)
item.setIcon(icon)
item.setStatusTip(url)
def main():
app = QApplication(sys.argv)
form = MainForm()
form.show()
app.exec_()
app = QApplication(sys.argv)
form = MainForm()
form.show()
app.exec_()
if __name__ == '__main__':
main()
main()