我已经使用pyqt4做了一个应用程序。PyQt4按钮,但只有一个作品。为什么?
它有七个按钮。六个完全一样,但最后一个工作。 另一个是退出按钮
每个按钮都运行一个脚本,用于在某些ESRI SHP文件中转换csv文件。
错误在哪里?
import sys
from archivo import *
import datetime
import os
import pandas as pd
import shapefile as shp
import csv
import tkinter.filedialog
class importo_script_py (QtGui.QDialog):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
self.ui = Ui_Dialog()
self.ui.setupUi(self)
QtCore.QObject.connect(self.ui.pushButtonxxxx01, QtCore.SIGNAL ('clicked()') ,self.xxxx01)
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
self.ui = Ui_Dialog()
self.ui.setupUi(self)
QtCore.QObject.connect(self.ui.pushButtonxxxx02, QtCore.SIGNAL ('clicked()') ,self.xxxx02)
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
self.ui = Ui_Dialog()
self.ui.setupUi(self)
QtCore.QObject.connect(self.ui.pushButtonxxxx03, QtCore.SIGNAL ('clicked()') ,self.xxxx03)
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
self.ui = Ui_Dialog()
self.ui.setupUi(self)
QtCore.QObject.connect(self.ui.pushButtonT3, QtCore.SIGNAL ('clicked()') ,self.boyaT3)
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
self.ui = Ui_Dialog()
self.ui.setupUi(self)
QtCore.QObject.connect(self.ui.pushButtonTOSCA12, QtCore.SIGNAL ('clicked()') ,self.boyaTOSCA12)
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
self.ui = Ui_Dialog()
self.ui.setupUi(self)
QtCore.QObject.connect(self.ui.pushButtonT14, QtCore.SIGNAL ('clicked()') ,self.boya14)
def boyaxxx01(self):
#sasemar1
boya ='http://XXXXXXXX.csv'
if not os.path.exists('C:\Export\SASEMAR01'):
os.makedirs('C:\Export\SASEMAR01')
df = pd.read_csv(boya, sep=',', names=['boya', 'cod_boya', 'y', 'x', 'time_stamp'])
out_file = 'C:/Export/SASEMAR01/sasemar1'
y = df['y'].astype(float).tolist()
x = df['x'].astype(float).tolist()
date = df['time_stamp'].tolist()
w = shp.Writer(shp.POINT)
w.autoBalance = 1 #ensures gemoetry and attributes match
w.field('longitud-x', 'F', 10, 5)
w.field('latitud-y', 'F', 10, 5) #float - needed for coordinates
w.field('DATE_TIME', 'C', 35)
for j, k in enumerate(x):
w.point(k, y[j]) #write the geometry
w.record(k, y[j], date[j]) #write the attributes
prj = open(out_file + '.prj', 'w')
proyeccion = 'GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137.0,298.257223563]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]]'
prj.write(proyeccion)
prj.close()
w.save(out_file)
def boyaXXX2(self):
boya= 'http://xxxx.csv'
if not os.path.exists('C:\Export\SASEMAR02'):
os.makedirs('C:\Export\SASEMAR02')
df = pd.read_csv(boya, sep=',', names=['boya', 'cod_boya', 'y', 'x', 'time_stamp'])
out_file = 'C:/Export/SASEMAR02/sasemar2'
y = df['y'].astype(float).tolist()
x = df['x'].astype(float).tolist()
date = df['time_stamp'].tolist()
w = shp.Writer(shp.POINT)
w.autoBalance = 1 #ensures gemoetry and attributes match
w.field('longitud-x', 'F', 10, 5)
w.field('latitud-y', 'F', 10, 5) #float - needed for coordinates
w.field('DATE_TIME', 'C', 35)
for j, k in enumerate(x):
w.point(k, y[j]) #write the geometry
w.record(k, y[j], date[j]) #write the attributes
prj = open(out_file + '.prj', 'w')
proyeccion = 'GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137.0,298.257223563]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]]'
prj.write(proyeccion)
prj.close()
w.save(out_file)
..... .....
if __name__=='__main__':
app = QtGui.QApplication(sys.argv)
myapp = boyasTodas()
myapp.show()
sys.exit(app.exec_())
这不是'__init__'的工作方式。 –
这是我在windows上工作的.pyw文件。 – kamome
你的类中只应该有一个__init__定义。现在,每个后续的__init__将替换现有的__init__,这就是为什么只有最后一个被实际使用。 – brm