2015-05-18 25 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

相关问题