-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpy_xnconvert_gui.py
102 lines (82 loc) · 3.21 KB
/
py_xnconvert_gui.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import sys
import os
from PyQt4 import QtCore, QtGui
class main_list_widget(QtGui.QListWidget):
def __init__(self,type,parent=None):
super(main_list_widget,self).__init__(parent)
self.setAcceptDrops(True)
def dragEnterEvent(self,event):
if event.mimeData().hasUrls:
event.accept()
else:
event.ignore()
def dragMoveEvent(self,event):
if event.mimeData().hasUrls:
event.setDropAction(QtCore.Qt.CopyAction)
event.accept()
else:
event.ignore()
def dropEvent(self,event):
if event.mimeData().hasUrls:
event.setDropAction(QtCore.Qt.CopyAction)
event.accept()
links=[]
for url in event.mimeData().urls():
links.append(str(url.toLocalFile()))
self.emit(QtCore.SIGNAL("dropped"),links)
else:
event.ignore()
class MainForm(QtGui.QMainWindow):
def __init__(self,parent=None):
super(MainForm,self).__init__(parent)
wid = QtGui.QWidget(self)
self.setCentralWidget(wid)
layout = QtGui.QVBoxLayout()
wid.setLayout(layout)
#
self.label1 = QtGui.QLabel("Drag drop folder to below (new file will replace old one) :")
#
self.folder_list_widget=main_list_widget(self)
self.connect(self.folder_list_widget,QtCore.SIGNAL("dropped"),self.object_dropped)
#
self.resize_button = QtGui.QPushButton(self)
self.resize_button.setText("Resize images (on it's own folder)")
self.connect(self.resize_button,QtCore.SIGNAL("clicked()"),self.do_resize)
#
self.remove_selected_button=QtGui.QPushButton(self)
self.remove_selected_button.setText("Remove Selected")
self.connect(self.remove_selected_button,QtCore.SIGNAL("clicked()"),self.do_remove_selected)
#
layout.addWidget(self.label1)
layout.addWidget(self.folder_list_widget)
layout.addWidget(self.remove_selected_button)
layout.addWidget(self.resize_button)
def do_remove_selected(self):
list_items = self.folder_list_widget.selectedItems()
if not list_items:
return
for item in list_items:
self.folder_list_widget.takeItem(self.folder_list_widget.row(item))
def do_resize(self):
items=[]
for index in xrange(self.folder_list_widget.count()):
items.append(str(self.folder_list_widget.item(index).text()))
for i in items:
arg = r'-ratio -rtype lanczos -rflag decr -resize 50%% 50%% -overwrite {}/*.png'.format(i)
os.system("X:/UNITY/XnView/nconvert.exe " + arg)
qm=QtGui.QMessageBox()
qm.question(self,'Info',"Done")
qm.show()
def object_dropped(self,l):
for url in l:
if os.path.exists(url):
print(url)
item=QtGui.QListWidgetItem(url,self.folder_list_widget)
item.setStatusTip(url)
def main():
app=QtGui.QApplication(sys.argv)
form=MainForm()
form.show()
app.exec_()
if __name__=='__main__':
main()