Advertisement
xunilk

Untitled

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