我已經使用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