make class:
class OpenFile(QtGui.QMainWindow):
def __init__(self, parent=None):
QtGui.QMainWindow.__init__( self, parent)
self.setGeometry(300, 300, 350, 300)
self.setWindowTitle(' SaveFile')
self.textEdit = QtGui.QTextEdit()
self.setCentralWidget(self. textEdit)
self.statusBar()
self.setFocus()
exit = QtGui.QAction(QtGui.QIcon(' open.png'), 'Open', self)
exit.setShortcut('Ctrl+O')
exit.setStatusTip('Open new File')
self.connect(exit, QtCore.SIGNAL('triggered()'), self.showDialog)
menubar = self.menuBar()
file = menubar.addMenu('&File')
file.addAction(exit)
def showDialog(self,text):
filename = QtGui.QFileDialog. getSaveFileName(self, 'Save file', '')
f=open(filename.toUtf8(). data().decode('utf-8').encode( 'cp1251'),'w')
f.write(text.toUtf8().data(). decode('utf-8').encode(' cp1251'))
in MainWindow class writing:
def __init__(self, win_parent = None):
...
#save stats in file
self.connect(self.saveButton, QtCore.SIGNAL("clicked()"), self.saveFile)
def saveFile(self):
cd = OpenFile()
cd.showDialog(self. textStatistic.toPlainText())
Комментариев нет:
Отправить комментарий