2015-05-18 21 views
0

我已經使用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_()) 
+2

這不是'__init__'的工作方式。 –

+0

這是我在windows上工作的.pyw文件。 – kamome

+0

你的類中只應該有一個__init__定義。現在,每個後續的__init__將替換現有的__init__,這就是爲什麼只有最後一個被實際使用。 – brm

回答

2

也許這個作品:

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) 
     QtCore.QObject.connect(self.ui.pushButtonxxxx02, QtCore.SIGNAL ('clicked()') ,self.xxxx02) 
     QtCore.QObject.connect(self.ui.pushButtonxxxx03, QtCore.SIGNAL ('clicked()') ,self.xxxx03) 
     QtCore.QObject.connect(self.ui.pushButtonT3, QtCore.SIGNAL ('clicked()') ,self.boyaT3) 
     QtCore.QObject.connect(self.ui.pushButtonTOSCA12, QtCore.SIGNAL ('clicked()') ,self.boyaTOSCA12) 
     QtCore.QObject.connect(self.ui.pushButtonT14, QtCore.SIGNAL ('clicked()') 

    etc.... 

哦,etc...並不意味着更多的inits;它意味着你的其他類的方法。

__init__是一個類的python構造函數。它將在創建類時執行一次。你在這裏做的是多次聲明__init__,所以你實際上覆蓋了你以前的__init__的。只有最後一個被執行,這將是正在工作的按鈕。

哦,請看this Python風格指南,因爲你的(類)命名是可怕的。

+0

這將工作,但請向OP解釋他爲什麼只能有一個'__init__' – Leon

+0

@Leon是的,讓我們嘗試做到這一點... – RickyA

+0

謝謝。可能是我必須瞭解__init__如何工作 – kamome

0

每個班只能有一個__init__。每當口譯人員看到一個__init__它正在用新的定義替換定義,即。只有最後的__init__會做點什麼

+0

'因爲你的(類)命名是可怕的' 你是對的我會盡力解決它 – kamome

相關問題