Hey, welcome back.
I'm very excited to tell you that in this video we're going to finish the development of our program.
Exactly.
We're going to do three things.
First, we're going to fix a couple of errors that we have.
We're going to handle them using, try and accept.
Second, we're going to add a life date and time with a second ticking on the guy.
And third, we're going to polish the program, change the theme of the program, play around with the
sizes of the elements and so on.
Let's begin by fixing the errors.
So when the user runs the program and without selecting anything, they press on.
Edit Then we get this error index error.
That is because in line 34 and here this values is a dictionary.
So it is this dictionary and values to dos gives us this list.
So we access the value of to dos, which is a list.
And then this port tries to access the first item of that list you see with index zero.
But there is no such item because the user hasn't selected any items from the list box.
Therefore we get an index error, as you might know already to handle errors we use, try and accept.
So we're going to indent all that block and place it under a try statement and then go here on indent
so that you are in the same level with try and say accept and look at the error we got.
So it's an index error.
And let's try first to print out something such as Please select an item first.
Let's try this around.
Edit And we get the printing successfully executed so the tricep block is working.
However, note that when we create this group programs, what the user will see is the actual gooey.
They will not see any command line interface.
Therefore, any messages that you show to the user you should show them here on the graphical user interface.
Or you could create a popup window telling them what they did wrong.
So let's create a pop up.
I'll close this and instead of printing this out, we want to use the s g dot pop up.
So SJ is pi simple, gooey and pop.
Pop is a function of that module.
So if you right click here and go to implementations, it's going to take you to the function definition,
to the pop up function definition.
This is the docstring or that in green, and then that's the code of the library.
So the library is written in Python, as is the case with all third party libraries which you install
with PIP.
So let's try to run this and see what happens.
Press on.
Edit and we get this window.
So it says, Please select an item first.
The user can close, it can press.
Okay, We can make that pop up window bigger by applying a font argument.
So just like.
This window method has that formed argument?
The pop.
Function also has that font arguments.
So this gets the font family and the size right click run, go press and edit.
And that's the window.
So it looks better.
We have the same issue with complete the complete case.
So if the user presses complete without selecting an item, we still have an error here.
So let's quickly do the same here.
Indent try then.
Except this is also an index error.
And so I'm going to copy that and paste it here.
So let me put this in here.
Run press and complete and we get this window popping up.
So it's working fine.
All right.
So that's about error handling.
Next.
What we want to do is on top of this label as the first row, we want to add the current date and time.
So let's do that.
We set on top of this label, so we want to create another label here.
Label is equal to as the text.
First we leave it empty and then we update that as g text that label object, which actually needs to
be a different name.
So we have that label variable there.
So let's call this maybe time or clock because you don't want to use time because we're going to import
time.
So this is the name of the module we're going to use.
Therefore, don't use variable names which have the same name with keywords, modules, objects, functions,
etc. So just use something like a clock.
So we import time because as you know from our previous command line interface, we use time to get
the actual time with that staff time function.
So when do we update that text?
Well, we update it somewhere in here.
So after we apply window that reads, we say window and we point to this clock instance, we should
give a key to that so that this clock has an identifier.
So let's say clock.
And that clock now should be mentioned in here.
Here we are.
Yeah.
Clock.
So that's access is the window clock, that label and we update the contents of that label.
The current content is an empty string as you see here.
So we update that to.
Value time that s t r f time.
So we call that.
Methods, actually.
And that was this one.
So let me copy that.
Go to that p y And we are here.
So that's it.
The new value is going to be the output of this method and the output of that method is the time and
the date.
And let's make sure that.
We have added now this.
Clock.
Instance to the layout here in SD window.
So we said we wanted to add another item above the label.
Therefore, this is going to be at least an inside the list is clock.
Let me indent this and don't forget the comma here.
So that should be fine.
Let's run the code.
Now we have this space here, but it's still an empty string, so the time somehow is not being displayed.
To fix that, you want to go to window the street and say time out is equal to ten.
Run again.
And now we see the time.
There you go.
So it's working.
And you can see in the command line that, no, this world loop is being executed every 10 milliseconds.
We had to apply a timeout because otherwise the loop runs only when an event happens, when the user
presses the buttons and so on.
But when you apply that timeout ten that the loop runs every 10 milliseconds, which is a fraction of
a second.
Therefore, that continuous running will allow this part here to be executed every 10 milliseconds.
And that makes it possible to see the actual time here updated every second you see, you can also get
away with another bigger value, such as two hundreds.
So a second has 1000 milliseconds.
So 200 is still less than a second and.
It's not displaying.
Let me run it again.
So 200 is also fine.
And it's also better for the program because it's not running so heavily every 10 milliseconds.
Right.
I'll leave it as it is and I'll delete these.
Now, we don't need these anymore.
We don't need to print them out in the command line.
So those print functions were printing out these lines.
And lastly, let's change the theme of the program.
To change the theme, you want to apply that theme.
So what theme can you apply for your program?
Well, if you go to Google and search for POI Simple, go with themes and go to images.
Then the first image, you can click it.
You can open it.
And that should give you all the available themes you can apply.
For example, if you want Dark purple for this one here, up here, then you want to write here dark.
Purple for so Ron Gooey and that's what you get.
I think the black theme is fine, so I hope you agree with me.
Otherwise, just find one of the themes on the page I showed you.
Lastly, I want to talk about the sizes you give to your widgets.
For example, we used size equal to that list, which has two elements, two numbers.
That was the size for the list box.
Now, how do I know what size to give you and how can you know?
Well, for such things, you don't even have to ask me.
You can right click over this box, go to implementations and then look at the size description in the
docstring.
So you see the triple quotes here.
So if you scroll down somewhere here, that's the size and on the sides here is the description.
Of the size parameter.
So this is saying that this size has white as the first character.
You see down here, it's it's supposed to receive two integers.
The first one is going to be the width, and this is the number of characters.
So what I'm giving here for the list box is 45 characters wide.
So that means the width of the list box is equal to 45 characters and ten.
As you can see here, ten is the height in number of rules.
So this program now is like one, two, three, four, five, six, seven, eight, nine, ten rows
high.
That's how sizing works for all the widgets, not only for the list box, but for other widgets as well.
And it also says something else.
If an int is instead supplied instead of a tuple, then the height is set to one by default.
So that means you can also give, for example, for a button, you can give the size equal to ten and
you see that the button is now wider.
However, the height doesn't change because the height is by default, want a row unit.
And that's the idea also about our problem.
One last tip before we close the video.
If you are using poor charm, I do suggest you to use the Rainbow plugin which you can install by going
to settings and then going to plugins and then going to marketplace and search for rainbow.
Install it.
Then restored power charm.
And what that plugin does is it colors the brackets, parentheses and brackets.
So now this yellow parentheses corresponds to that yellow parentheses.
So the code is visually more readable.
You see that this green bracket closes here and so on.
If you are on another IDE other than porch or perhaps you could Google something like Rainbow Alternative
for Visual Studio codes or Atom wherever ID you are using.
And probably there is such a plugin for your favorite IDE as well.
So I wanted to show you this because from now on the code is more complex, such as this one here,
so it is helpful to see more emphasized syntax highlighting.
Let's also commit the changes.
Change theme at clock handle, edit and complete errors.
That's what we did so commit.
Then I'm going to push the changes to GitHub.
So with that we are done with our program.
It was quite a long journey to build this first app and it was a bit slow because this was the first
app and I had to explain you a lot, a lot of concepts.
I had to explain you the features of Python, the types of objects function, etc. So for the next apps,
now we have a common language, you know what type is.
So when ever I built something I just mentioned, I just tell you that, Oh, this is a type and this
is an instance and we use that for this and everything is going to be much easier than it was.
It's also going to be more fun with the next apps because this app was basically simple.
We just had to work with texts.
So the two two items were text, but we're going to work with more interesting data formats later in
the course, such as PDFs and images, graphs, etc..
So all of that can be handled with Python and it's a lot of fun.
So stay tuned and I'll see you in the next videos by.