Create two new qlineedits for name and symptoms


Assignment: Introduction to Computer Science for Life Scientists

Exercise 1 (GUI Programming, 25 Points)

1747_The-main-window-with-the-list-widget.jpg
Figure 1: The main window with the list widget.

In this exercise, you will develop a small GUI application that shows a list of subjects with their personal data, and allows the user to interactively edit it. We provide a scaffold list.py on the course webpage that you may use as a starting point. It defines ListWindow as a class for the main window, containing a member list of type QListWidget to show the list of subjects. Buttons underneath should allow editing. The personal data (name, year of birth, gender and symptoms) is stored in the member variable ListWindow.data.

Implement the function updateList() in the class ListWindow. It should populate list with the subject names currently stored in data. This requires the use of QListWidget.addItem() for each subject. Since updateList() might get called repeatedly, you have to QListWidget.clear() all previous entries from list first.

When the user clicks on the button Edit, we want the function onEditClicked() to be called. In the Qt library you can set a function handling the clicked signal via some_button.clicked.connect(some_function).

Add a new function onDeleteClicked() to ListWindow, that deletes the subject in data that is currently selected by the user in list. Don't forget to also repopulate list.

Now it is time to implement the SubjectDialog. It should present the detailed information of a single subject. For this we need to add GUI elements in the constructor SubjectDia- log. init (). We want to be able to edit the subject's name (text), the year of birth (number), gender (multiple choice) and symptoms (again, text).

1740_The-dialog-box-for-the-subject-data.jpg
Figure 2: The dialog box for the subject data.

- Create two new QLineEdits for the name and symptoms respectively. (only creating them won't make them visible on the dialog box, we will take care of that later with the help of layouts)

- Create a new QSpinBox for the year of birth. Set an appropriate range of allowed values with setRange().

- For the gender, create 3 new QRadioButtons ('m', 'f ' and ' ?' ). Since only one choice should be possible simultaneously, we also need to create a QButtonGroup and add the 3 radio buttons to it.

- Create two buttons for Ok and Cancel. Qt already provides default handlers for both (self.accept and self.reject), but you still need to connect them to the buttons.

- Create a suitable layout. Use a QHBoxLayout to arrange the two buttons in a horizontal row. QFormLayout allows to stack the other widgets vertically and automatically add labels next to them ('Name' etc.). Stack these two layouts vertically using a QVBoxLayout and apply it to the dialog via self.setLayout().

Hint: layouts in Qt have separate functions addWidget() and addLayout() to add child GUI elements directly or another child layout.

- We need to transport our subject's data in and out of the dialog. For this we need two new functions getData() and setData() in SubjectDialog. setData(subject) should receive the data of a single subject (as a list) and fill out the appropriate GUI elements (for example QLineEdit.setText() and QRadioButton.setChecked()). getData() should read out the GUI elements (for example QLineEdit.text()), put the data into a list and return it.

We can now also add a function in ListWindow to handle clicking the Add button. Similarly to onEditClicked() this new function should also show the SubjectDialog but add the result to data instead of replacing an existing element.

Add two new buttons Load and Save to the main window that let the user choose a file (via QFileDialog.getOpenFileName() and QFileDialog.getSaveFileName()) and load/store data to the chosen file.

Hint: to store the subject list into a file, you can use your knowledge from previous assignments, but in this case, it is also permitted to use the pandas library, python's pickle mechanism or other methods you might prefer.

Request for Solution File

Ask an Expert for Answer!!
Computer Engineering: Create two new qlineedits for name and symptoms
Reference No:- TGS02530109

Expected delivery within 24 Hours