Advertisement
xunilk

output_file.py

Oct 19th, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.41 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. from PyQt4 import QtCore, QtGui
  3. from PyQt4.QtGui import QFileDialog
  4. from qgis.gui import QgsMessageBar
  5. import output_file_dialog
  6. from os import chdir
  7.  
  8. class OutputFile(QtGui.QDialog):
  9.  
  10.     def __init__(self):
  11.         QtGui.QDialog.__init__(self)
  12.         # Set up the user interface from Designer.
  13.         # After setupUI you can access any designer object by doing:
  14.         # self.<objectname>
  15.         self.ui = output_file_dialog.Ui_Dialog()
  16.         self.ui.setupUi(self)
  17.  
  18.         # #As in a QGIS plugin
  19.         # self.ui.lineEdit.clear()
  20.         # self.ui.pushButton.clicked.connect(self.select_output_file)
  21.  
  22.     def select_output_file(self):
  23.         chdir('c:/Users')
  24.         filename = QFileDialog.getSaveFileName(self, "Select output file ","", '*.txt')
  25.         self.ui.lineEdit.setText(filename)
  26.         self.save_file()
  27.  
  28.     def save_file(self):
  29.         filename = self.ui.lineEdit.text()
  30.         output_file = open(filename, 'w')
  31.         output_file.write("My text")
  32.         output_file.close()
  33.  
  34. # Create the dialog and keep reference
  35. reload(output_file_dialog)
  36. dlg = OutputFile() #create Dialog object
  37. dlg.show() #show Dialog object
  38.  
  39. dlg.ui.lineEdit.clear() #clear text in lineEdit object
  40. dlg.ui.pushButton.clicked.connect(dlg.select_output_file) #send signal if
  41.                                                                                   #pushButton is clicked
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement