I am trying to create a configuration tool that helps link attributes of one tool with another. I have created the config window using PyQt5. I want to:
- Save the value of the line edit, into a text file. ---> when clicked on Save
- Load the values of a text file , into the line edit ---> when clicked on Load
This is how the UI looks
The UI of the config file- Config.ui
I have tried the functions getSaveFileName , getOpenFileName but all i get is the path on the cmd, and no actual file is saved or opened.
what should be done in order to save the file contents ?
Please be kind with your answers :)
This is how the programming GUI looks like :
# Config program using PyQt5
import sys
from PyQt5 import QtCore, QtGui, uic, QtWidgets
from PyQt5.QtWidgets import QFileDialog
form_class = uic.loadUiType("Config.ui")[0] # Load the UI
class Mapper(QtWidgets.QMainWindow, form_class):
def __init__(self, parent=None):
QtWidgets.QMainWindow.__init__(self, parent)
self.setupUi(self)
# Bind the event handlers to the buttons
self.saveButton.clicked.connect(self.saveFileDialog)
self.loadButton.clicked.connect(self.loadFileDialog)
def saveFileDialog(self):
options = QFileDialog.Options()
options |= QFileDialog.DontUseNativeDialog
fileName, _ = QFileDialog.getSaveFileName(self, "QFileDialog.getSaveFileName()", "",
"All Files (*);;Text Files (*.txt)", options=options)
if fileName:
print(fileName)
def loadFileDialog(self):
options = QFileDialog.Options()
options |= QFileDialog.DontUseNativeDialog
files, _ = QFileDialog.getOpenFileNames(self, "QFileDialog.getOpenFileNames()", "",
"All Files (*);;Python Files (*.py)", options=options)
if files:
print(files)
app = QtWidgets.QApplication(sys.argv)
myWindow = Mapper()
myWindow.show()
app.exec_()
This is how the Config.ui looks :
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>545</width>
<height>728</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Ignored" vsizetype="Ignored">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<property name="windowTitle">
<string>Configuration Window</string>
</property>
<widget class="QWidget" name="centralwidget">
<widget class="QFrame" name="mainFrame">
<property name="geometry">
<rect>
<x>20</x>
<y>-10</y>
<width>911</width>
<height>721</height>
</rect>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<widget class="QGroupBox" name="mapGroupBox">
<property name="geometry">
<rect>
<x>30</x>
<y>20</y>
<width>481</width>
<height>581</height>
</rect>
</property>
<property name="title">
<string>MAPPING ATTRIBUTES</string>
</property>
<widget class="QGroupBox" name="ecuGroupBox">
<property name="geometry">
<rect>
<x>20</x>
<y>30</y>
<width>211</width>
<height>531</height>
</rect>
</property>
<property name="title">
<string>ECU TEST Attributes</string>
</property>
<widget class="QLabel" name="ModuleName">
<property name="geometry">
<rect>
<x>10</x>
<y>30</y>
<width>111</width>
<height>16</height>
</rect>
</property>
<property name="font">
<font>
<family>Nirmala UI</family>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>ModuleName</string>
</property>
</widget>
<widget class="QLabel" name="aObjectType">
<property name="geometry">
<rect>
<x>10</x>
<y>60</y>
<width>81</width>
<height>16</height>
</rect>
</property>
<property name="font">
<font>
<family>Nirmala UI</family>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>aObjectType</string>
</property>
</widget>
<widget class="QLabel" name="TestDescription">
<property name="geometry">
<rect>
<x>10</x>
<y>90</y>
<width>101</width>
<height>16</height>
</rect>
</property>
<property name="font">
<font>
<family>Nirmala UI</family>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>TestDescription</string>
</property>
</widget>
<widget class="QLabel" name="Preconditions">
<property name="geometry">
<rect>
<x>10</x>
<y>390</y>
<width>91</width>
<height>16</height>
</rect>
</property>
<property name="font">
<font>
<family>Nirmala UI</family>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Preconditions</string>
</property>
</widget>
<widget class="QLabel" name="Testcase_ID">
<property name="geometry">
<rect>
<x>10</x>
<y>210</y>
<width>91</width>
<height>16</height>
</rect>
</property>
<property name="font">
<font>
<family>Nirmala UI</family>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Testcase_ID</string>
</property>
</widget>
<widget class="QLabel" name="function">
<property name="geometry">
<rect>
<x>10</x>
<y>330</y>
<width>81</width>
<height>16</height>
</rect>
</property>
<property name="font">
<font>
<family>Nirmala UI</family>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Function</string>
</property>
</widget>
<widget class="QLabel" name="Priority">
<property name="geometry">
<rect>
<x>10</x>
<y>300</y>
<width>55</width>
<height>16</height>
</rect>
</property>
<property name="font">
<font>
<family>Nirmala UI</family>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Priority</string>
</property>
</widget>
<widget class="QLabel" name="TestName">
<property name="geometry">
<rect>
<x>10</x>
<y>240</y>
<width>71</width>
<height>16</height>
</rect>
</property>
<property name="font">
<font>
<family>Nirmala UI</family>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>TestName</string>
</property>
</widget>
<widget class="QLabel" name="TestFocus">
<property name="geometry">
<rect>
<x>10</x>
<y>150</y>
<width>81</width>
<height>16</height>
</rect>
</property>
<property name="font">
<font>
<family>Nirmala UI</family>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>TestFocus</string>
</property>
</widget>
<widget class="QLabel" name="Action">
<property name="geometry">
<rect>
<x>10</x>
<y>420</y>
<width>61</width>
<height>16</height>
</rect>
</property>
<property name="font">
<font>
<family>Nirmala UI</family>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Action</string>
</property>
</widget>
<widget class="QLabel" name="CreatedBy">
<property name="geometry">
<rect>
<x>10</x>
<y>480</y>
<width>81</width>
<height>16</height>
</rect>
</property>
<property name="font">
<font>
<family>Nirmala UI</family>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>CreatedBy</string>
</property>
</widget>
<widget class="QLabel" name="TestLocation">
<property name="geometry">
<rect>
<x>10</x>
<y>360</y>
<width>101</width>
<height>16</height>
</rect>
</property>
<property name="font">
<font>
<family>Nirmala UI</family>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>TestLocation</string>
</property>
</widget>
<widget class="QLabel" name="Status">
<property name="geometry">
<rect>
<x>10</x>
<y>270</y>
<width>55</width>
<height>16</height>
</rect>
</property>
<property name="font">
<font>
<family>Nirmala UI</family>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Status</string>
</property>
</widget>
<widget class="QLabel" name="Req_ID">
<property name="geometry">
<rect>
<x>10</x>
<y>180</y>
<width>55</width>
<height>16</height>
</rect>
</property>
<property name="font">
<font>
<family>Nirmala UI</family>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Req_ID</string>
</property>
</widget>
<widget class="QLabel" name="TestPictureName">
<property name="geometry">
<rect>
<x>10</x>
<y>120</y>
<width>111</width>
<height>16</height>
</rect>
</property>
<property name="font">
<font>
<family>Nirmala UI</family>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>TestPictureName</string>
</property>
</widget>
<widget class="QLabel" name="ExpectedResult">
<property name="geometry">
<rect>
<x>10</x>
<y>450</y>
<width>111</width>
<height>16</height>
</rect>
</property>
<property name="font">
<font>
<family>Nirmala UI</family>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>ExpectedResult</string>
</property>
</widget>
</widget>
<widget class="QGroupBox" name="doorsGroupBox">
<property name="geometry">
<rect>
<x>250</x>
<y>29</y>
<width>211</width>
<height>531</height>
</rect>
</property>
<property name="title">
<string>DOORS Attributes</string>
</property>
<widget class="QLineEdit" name="lineEdit">
<property name="geometry">
<rect>
<x>10</x>
<y>30</y>
<width>181</width>
<height>22</height>
</rect>
</property>
</widget>
<widget class="QLineEdit" name="lineEdit_2">
<property name="geometry">
<rect>
<x>10</x>
<y>60</y>
<width>181</width>
<height>22</height>
</rect>
</property>
</widget>
<widget class="QLineEdit" name="lineEdit_3">
<property name="geometry">
<rect>
<x>10</x>
<y>90</y>
<width>181</width>
<height>22</height>
</rect>
</property>
</widget>
<widget class="QLineEdit" name="lineEdit_4">
<property name="geometry">
<rect>
<x>10</x>
<y>120</y>
<width>181</width>
<height>22</height>
</rect>
</property>
</widget>
<widget class="QLineEdit" name="lineEdit_5">
<property name="geometry">
<rect>
<x>10</x>
<y>150</y>
<width>181</width>
<height>22</height>
</rect>
</property>
</widget>
<widget class="QLineEdit" name="lineEdit_6">
<property name="geometry">
<rect>
<x>10</x>
<y>180</y>
<width>181</width>
<height>22</height>
</rect>
</property>
</widget>
<widget class="QLineEdit" name="lineEdit_7">
<property name="geometry">
<rect>
<x>10</x>
<y>210</y>
<width>181</width>
<height>22</height>
</rect>
</property>
</widget>
<widget class="QLineEdit" name="lineEdit_8">
<property name="geometry">
<rect>
<x>10</x>
<y>240</y>
<width>181</width>
<height>22</height>
</rect>
</property>
</widget>
<widget class="QLineEdit" name="lineEdit_9">
<property name="geometry">
<rect>
<x>10</x>
<y>270</y>
<width>181</width>
<height>22</height>
</rect>
</property>
</widget>
<widget class="QLineEdit" name="lineEdit_10">
<property name="geometry">
<rect>
<x>10</x>
<y>300</y>
<width>181</width>
<height>22</height>
</rect>
</property>
</widget>
<widget class="QLineEdit" name="lineEdit_11">
<property name="geometry">
<rect>
<x>10</x>
<y>330</y>
<width>181</width>
<height>22</height>
</rect>
</property>
</widget>
<widget class="QLineEdit" name="lineEdit_12">
<property name="geometry">
<rect>
<x>10</x>
<y>360</y>
<width>181</width>
<height>22</height>
</rect>
</property>
</widget>
<widget class="QLineEdit" name="lineEdit_13">
<property name="geometry">
<rect>
<x>10</x>
<y>390</y>
<width>181</width>
<height>22</height>
</rect>
</property>
</widget>
<widget class="QLineEdit" name="lineEdit_14">
<property name="geometry">
<rect>
<x>10</x>
<y>420</y>
<width>181</width>
<height>22</height>
</rect>
</property>
</widget>
<widget class="QLineEdit" name="lineEdit_15">
<property name="geometry">
<rect>
<x>10</x>
<y>450</y>
<width>181</width>
<height>22</height>
</rect>
</property>
</widget>
<widget class="QLineEdit" name="lineEdit_16">
<property name="geometry">
<rect>
<x>10</x>
<y>480</y>
<width>181</width>
<height>22</height>
</rect>
</property>
</widget>
</widget>
</widget>
<widget class="QPushButton" name="saveButton">
<property name="geometry">
<rect>
<x>30</x>
<y>630</y>
<width>93</width>
<height>28</height>
</rect>
</property>
<property name="toolTip">
<string>Save The Current Configuration</string>
</property>
<property name="toolTipDuration">
<number>1</number>
</property>
<property name="text">
<string>Save</string>
</property>
</widget>
<widget class="QPushButton" name="loadButton">
<property name="geometry">
<rect>
<x>140</x>
<y>630</y>
<width>93</width>
<height>28</height>
</rect>
</property>
<property name="toolTip">
<string>Load Existing Configuration</string>
</property>
<property name="toolTipDuration">
<number>1</number>
</property>
<property name="text">
<string>Load</string>
</property>
</widget>
</widget>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>545</width>
<height>26</height>
</rect>
</property>
</widget>
<widget class="QStatusBar" name="statusbar"/>
</widget>
<resources/>
<connections/>
</ui>