Hi.
In this video, you'll learn how to add a status bar to the program.
The status bar is this strip here that you see, and it usually contains data about the current status
of different elements of the program.
For example, you may as a programmer, you may want to display the current number of rows in the table
or the current value of the selected cell in the status bar.
So usually what you display there is texts of board.
Sometimes you may also have to display more interactive features such as these two buttons.
In fact, these two buttons will show when the user selects a cell in the table.
So normally they will not be shown here.
But once a cell is selected by the user in the program, for example.
Let's say the user selects this cell, then those two buttons will be displayed on the status bar so
that the user can add it or delete that particular entry, that row or cell of the table.
So let's do that.
Let's add.
A status report.
So that was the toolbar up to here.
Now let's add some more codes.
Create status bar and add status bar elements.
Status bar is equal to the toolbar was Q toolbar.
The status bar is Q status bar.
So let's go ahead and import it.
From cute widgets.
So that's the status bar.
And then we want to add it to self set status bar.
So that is status bar.
This variable.
And if we run the program now, we should see this trip here.
So that's that gray area is the status bar.
Now, to add elements to the status bar, you want to refer to the status bar, that add widget.
So this expects a widget.
Now, for example, a label let's say hello is equal to Q label.
Hell there, for example.
Then you provide the hallow variable here, which symbolizes the Q label instance.
And of course, you can duplicate that to add more widgets.
So let's say Hello world here.
And if I run this, you're going to see we have two elements.
Hello there and Hello World in the status bar.
Of course, the text can be dynamically generated from somewhere else in the program.
Perhaps you you get this from an SQL query where you get the number of students in the database, and
then you provide that result here as a string and so on.
But our interest is to show some buttons here instead of labels.
So I'll delete those and see how we can add some buttons.
So we want to add an edit button and a delete button.
But we want to show those buttons when the user presses or selects a cell.
So when they click on the cell in the table, then we show those buttons.
So therefore, we first want to capture the click.
In other words, we want to detect a.
Sell click.
And to do that, you want to refer to the table itself table and then you want to access the sell clicked.
That's connect.
So Sell Clicked is a property of table and Connect is a method of that property.
So what do you want to do when the user selects a sale in the table?
Well, we want to execute a method such as sell clicked.
Without the parentheses.
So just the method just mentioned the method they're referencing to self, to the actual class.
And so then you want to add to define the methods here.
So we're still inside the main window class, right?
That's in it.
That's load data.
Insert search.
So I'm just folding them.
I'm not deleting them.
So we want to write define.
Sell clicked, right?
Was it that name?
Self clicked with self as argument.
So when the cell is clicked, we want to generate an edit button which is equal to Q push button and
give it a name such as edit record.
It makes sense.
And when edit button is clicked, we connect it to self dot edit, which is going to be yet another
method.
So let's add that method below the search method.
Right.
Make a brick line.
Define edit self.
And inside edits.
We want to create a dialogue, right?
Just like we did for search.
We created a dialog.
There's going to be edit dialog and then.
Dialogue dot exec to execute it.
So that means we need to create a class added dialog now which inherits from queue dialog.
So that's the same thing that we did with insert dialog and other dialogs as well.
And inside edit dialog, now we want to generate that, that dialog which is going to look like.
This is the insert dialog.
We did that already.
That's the edit dialog.
So we want to add these three there, which is basically like the insert dialog box.
So for now I'll just write pass and I'll write, I'll complete that in the next video.
So for now, we want to focus on the status bar.
Let's run the code as it is now and see when we clicked one cell, we should expect the edit button
in here.
It's not there yet because we haven't added the button to the actual status bar.
To do that, we want to refer to self.
Self is the class the window, the main window.
And then we want to refer to the status bar variable of self.
However, this is just a local variable variable for now.
So let's turn it into.
And attribute self that status bar and make sure to turn that into an attribute as well.
And then here you say self that status bar dot ad widget.
So before we added a queue label widget to this method, now we want to add an edit button widget which
is also widget, right?
Edit button.
And let me quickly duplicate this with control dx or command dx.
And this time I want to write a delete Records button.
So delete.
This is a delete button, right?
Skip, push, button, delete record when clicked.
We want to execute self delete, which is also a method we need to add.
So let me just duplicate this method and this will be delete delete dialog which also needs to be created
as a class delete dialog.
Queue dialog.
And for now, let's just pass.
Right.
So here we are.
We created an edit button, we created a delete button, we added the edit button to the status bar,
and let's add the delete button also to the status bar.
Now let's run and see what happens.
So whenever I click a cell, now the buttons are added and they keep being added to the status bar.
That's something we'll fix, but at least we do see the buttons added in the status bar when we click
a cell.
Right.
So how do you remove them so that you don't have those duplicate buttons before you?
You add any buttons before you add the buttons to the status bar, you want to clean any other current
buttons.
For that you want to do self that find children and you want to find cute push button.
So these types of children so to say and you want to save that result into a variable.
And then you say if there are buttons.
So if children then you say for child in children.
Self that status bar.
So that's the status bar, right?
This one in here that's remove widget child.
So we remove that Q push button if any is found.
If I run this now.
I click on something, I click on something else.
Now we only have these two, right?
Currently, this simply shows an empty dialog window because this.
Is being instantiated this class.
So this generates a queue dialog, but it's empty for now, so we need to populate it with actual widgets.
So that's how you add a status bar.
That's the code here.
And if you want to dynamically add other widgets to that status bar, then you want to connect it to
a method self.
That self clicked in this case, so that method is executed.
And there you can write conditionals and generate widgets when something happens.
So that's about the status bar.
Let's build the add dialog box in the next video.
Thanks a lot.