import
sys
import
os
import
base64
from
PyQt5.QtWidgets
import
QApplication, QDialog, QMessageBox, QLineEdit, QFileDialog
from
PyQt5
import
QtWidgets, QtCore
from
tupianzengda
import
Ui_MainWindow
from
file50_jpg
import
img as file50
from
file100_jpg
import
img as file100
from
file150_jpg
import
img as file150
class
my(Ui_MainWindow):
def
__init__(
self
):
self
.file_name
=
sys.argv
self
.file_fujia
=
"file100.jpg"
self
.daxiao
=
0
def
setupUi(
self
, MainWindow):
super
(my,
self
).setupUi(MainWindow)
self
.pushButton.clicked.connect(
self
.wenjianxuanze)
self
.pushButton_2.clicked.connect(
self
.tuxiangchuli)
def
wenjianxuanze(
self
):
self
.mulu
=
os.getcwd()
if
not
os.path.exists(
"file50.data"
):
tmp
=
open
(
"file50.data"
,
'wb'
)
tmp.write(base64.b64decode(file50))
tmp.close()
if
not
os.path.exists(
"file100.data"
):
tmp
=
open
(
"file100.data"
,
'wb'
)
tmp.write(base64.b64decode(file100))
tmp.close()
if
not
os.path.exists(
"file150.data"
):
tmp
=
open
(
"file150.data"
,
'wb'
)
tmp.write(base64.b64decode(file150))
tmp.close()
file_name, file_type
=
QFileDialog.getOpenFileName(
None
,
"选择图像文件"
,
self
.mulu,
"图像文件 (*.jpg *.jpeg *.png *.bmp *.gif)"
)
if
file_name
=
=
"":
self
.statusBar.showMessage(
"没有选中任何文件"
)
else
:
self
.lineEdit.setText(file_name)
self
.statusBar.showMessage(
"已经选中了目标文件,大小是%.fKB"
%
(os.path.getsize(file_name)
/
1024
) )
def
daxiaoxuanze(
self
):
daxiao_filename
=
[
'file50.data'
,
'file100.data'
,
'file150.data'
]
self
.file_fujia
=
daxiao_filename[
self
.comboBox.currentIndex()]
def
tuxiangchuli(
self
):
self
.daxiaoxuanze()
file_old
=
self
.lineEdit.text()
if
len
(file_old)
=
=
0
:
self
.lineEdit.setText(
"还没有选择要修改的图像文件"
)
return
file_old_name
=
file_old.split(r
'/'
)[
-
1
]
file_new
=
file_old_name.split(r
'.'
)[
0
]
+
"_add"
+
self
.comboBox.currentText()
+
".jpg"
print
(file_old_name, file_new)
os.chdir(os.getcwd() )
print
(os.getcwd())
zhixing
=
r
"copy /b "
+
file_old.replace(
'/'
,r
'\\'
)
+
"+"
+
self
.file_fujia
+
" "
+
file_new
print
(zhixing)
jieguo
=
os.popen(zhixing)
print
(jieguo.read())
old_size
=
os.path.getsize(file_old)
/
1024
new_size
=
os.path.getsize(file_new)
/
1024
self
.statusBar.showMessage(
"原文件大小:%.0fKB 处理后大小:%.0fKB"
%
(old_size, new_size ))
os.system(
"explorer.exe %s"
%
(os.getcwd() ) )
myapp
=
QApplication(sys.argv)
mydlg
=
QtWidgets.QMainWindow()
myui
=
my()
myui.setupUi(mydlg)
mydlg.show()
sys.exit(myapp.exec_())