Good afternoon everyone! I need to reuse the data from lineEdit's obj and obj1 in another class, but when I try to do this, I get the error: AppCAD 'object has no attribute' coord. Where am I going wrong?
import sys
import PyQt4.QtCore as qc
import PyQt4.QtGui as qg
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.figure import Figure
import numpy as np
from matplotlib.lines import Line2D
from matplotlib import pyplot as plt
class AppCAD(qg.QMainWindow):
def __init__(self, parent=None):
qg.QMainWindow.__init__(self, parent)
self.setWindowTitle('CAD Input Python')
self.setGeometry(100,100,800,600)
self.create_main_frame()
#botão plotar, caixa para entrada de coordenadas e canvas
def create_main_frame(self):
self.main_frame = qg.QWidget()
self.dpi = 70
self.fig = Figure((5.0, 5.0), dpi=self.dpi)
self.canvas = FigureCanvas(self.fig)
self.axes = self.fig.add_subplot(111)
self.axes.axis('equal')
self.axes.set_xlim(-10,10)
self.axes.set_ylim(-10,10)
self.axes.xaxis.set_major_locator(plt.MultipleLocator(5.0))
self.axes.xaxis.set_minor_locator(plt.MultipleLocator(1.0))
self.axes.yaxis.set_major_locator(plt.MultipleLocator(5.0))
self.axes.yaxis.set_minor_locator(plt.MultipleLocator(1.0))
self.axes.grid(which='major', axis='x', linewidth=0.75, linestyle='-', color='0.75')
self.axes.grid(which='minor', axis='x', linewidth=0.25, linestyle='-', color='0.75')
self.axes.grid(which='major', axis='y', linewidth=0.75, linestyle='-', color='0.75')
self.axes.grid(which='minor', axis='y', linewidth=0.25, linestyle='-', color='0.75')
grid = qg.QGridLayout()
self.buttonA = qg.QPushButton("Plotar")
self.obj = qg.QLineEdit()
self.obj1 = qg.QLineEdit()
self.connect(self.buttonA, qc.SIGNAL('clicked()'), self.press_buttonA)
self.main_frame.setLayout(grid)
self.setCentralWidget(self.main_frame)
grid.addWidget(self.buttonA,4,0)
grid.addWidget(self.canvas,0,1,3,3)
grid.addWidget(self.obj, 0,0)
grid.addWidget(self.obj1, 0,1)
# Coordenadas -------------------------------------------------------------
def i2o_coordenadas(self):
self.coord = []
cx = float(self.obj.text())
cy = float(self.obj1.text())
self.coord.append([cx,cy]) #Aqui o programa deveria salvar as coordendas dadas pelo usuário na lista self.coord
#plotagem
def press_buttonA(self):
px = self.coord[0]
py = self.coord[1]
self.axes.plot(px, py, marker='o', color='black', markersize=7.5, linewidth=0, zorder=13) #aqui o programa deveria utilizar as coordenadas para plotar no grafico, via matplotlib
def main():
app = qg.QApplication(sys.argv)
form = AppCAD()
form.show()
app.exec_()
if __name__ == "__main__":
main()