图形操作,无命令行
自己写了一个
PS:本人不会gtk,用Qt的
mainwindow.py:
代码: 全选
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Module implementing MainWindow.
"""
import sys, os
from PyQt4.QtGui import *
from PyQt4.QtCore import *
from Ui_mainwindow import Ui_MainWindow
class MainWindow(QMainWindow, Ui_MainWindow):
"""
Class documentation goes here.
"""
def __init__(self, parent = None):
"""
Constructor
"""
QMainWindow.__init__(self, parent)
self.setupUi(self)
self.connect(self.runBtn, SIGNAL("clicked()"), self.runBtn_clicked)
def runBtn_clicked(self):
"""
Slot documentation goes here.
"""
# raise NotImplementedError
from os.path import isfile
self.sourcefile = str(self.sourceFile.text())
self.tofile = str(self.toFile.text())
self.sourceencode = str(self.sourceEncode.text())
self.toencode = str(self.toEncode.text())
if isfile(self.sourcefile):
if self.sourcefile != self.tofile:
if self.sourceencode != self.toencode:
os.system('iconv -f '+ self.sourceencode + ' -t ' + self.toencode + ' ' + self.sourcefile + ' -o ' + self.tofile
#+ ' > ~/.encodeswlog\nkdialog "`cat ~/.encodeswlog`"'
)
self.errlabel.setText(u'完成')
else:
self.errlabel.setText(u'错误:编码相同')
else:
self.errlabel.setText(u'错误:文件相同')
else:
self.errlabel.setText(u'错误:没有该文件')
if __name__ == "__main__":
app = QApplication(sys.argv)
myapp = MainWindow()
myapp.show()
sys.exit(app.exec_())
代码: 全选
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>489</width>
<height>337</height>
</rect>
</property>
<property name="windowTitle">
<string>encodingSwitcher</string>
</property>
<widget class="QWidget" name="centralWidget">
<widget class="QLineEdit" name="sourceFile">
<property name="geometry">
<rect>
<x>120</x>
<y>30</y>
<width>351</width>
<height>31</height>
</rect>
</property>
</widget>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>30</x>
<y>30</y>
<width>81</width>
<height>31</height>
</rect>
</property>
<property name="text">
<string>源文件:</string>
</property>
</widget>
<widget class="QLabel" name="label_2">
<property name="geometry">
<rect>
<x>30</x>
<y>110</y>
<width>81</width>
<height>31</height>
</rect>
</property>
<property name="text">
<string>目标文件:</string>
</property>
</widget>
<widget class="QLineEdit" name="toFile">
<property name="geometry">
<rect>
<x>120</x>
<y>110</y>
<width>351</width>
<height>31</height>
</rect>
</property>
</widget>
<widget class="QPushButton" name="runBtn">
<property name="geometry">
<rect>
<x>70</x>
<y>260</y>
<width>111</width>
<height>34</height>
</rect>
</property>
<property name="text">
<string>执行!</string>
</property>
</widget>
<widget class="QPushButton" name="exitBtn">
<property name="geometry">
<rect>
<x>260</x>
<y>260</y>
<width>111</width>
<height>34</height>
</rect>
</property>
<property name="text">
<string>退出</string>
</property>
</widget>
<widget class="QLabel" name="label_3">
<property name="geometry">
<rect>
<x>30</x>
<y>70</y>
<width>81</width>
<height>31</height>
</rect>
</property>
<property name="text">
<string>编码:</string>
</property>
</widget>
<widget class="QLineEdit" name="sourceEncode">
<property name="geometry">
<rect>
<x>120</x>
<y>70</y>
<width>113</width>
<height>31</height>
</rect>
</property>
</widget>
<widget class="QLabel" name="label_4">
<property name="geometry">
<rect>
<x>30</x>
<y>160</y>
<width>81</width>
<height>31</height>
</rect>
</property>
<property name="text">
<string>编码:</string>
</property>
</widget>
<widget class="QLineEdit" name="toEncode">
<property name="geometry">
<rect>
<x>120</x>
<y>160</y>
<width>113</width>
<height>31</height>
</rect>
</property>
</widget>
<widget class="QLabel" name="errlabel">
<property name="geometry">
<rect>
<x>30</x>
<y>220</y>
<width>431</width>
<height>24</height>
</rect>
</property>
<property name="text">
<string>无错误。</string>
</property>
</widget>
</widget>
</widget>
<tabstops>
<tabstop>sourceFile</tabstop>
<tabstop>sourceEncode</tabstop>
<tabstop>toFile</tabstop>
<tabstop>toEncode</tabstop>
<tabstop>runBtn</tabstop>
<tabstop>exitBtn</tabstop>
</tabstops>
<resources/>
<connections>
<connection>
<sender>exitBtn</sender>
<signal>clicked()</signal>
<receiver>MainWindow</receiver>
<slot>close()</slot>
<hints>
<hint type="sourcelabel">
<x>350</x>
<y>196</y>
</hint>
<hint type="destinationlabel">
<x>383</x>
<y>239</y>
</hint>
</hints>
</connection>
</connections>
</ui>
代码: 全选
pyuic4 mainwindow.ui > Ui_mainwindow.py
代码: 全选
python mainwindow.py