1
00:00:00,730 --> 00:00:01,560
Hey, welcome back.

2
00:00:01,569 --> 00:00:07,450
I'm very excited to tell you that in this video we're going to finish the development of our program.

3
00:00:07,630 --> 00:00:08,290
Exactly.

4
00:00:08,290 --> 00:00:09,940
We're going to do three things.

5
00:00:09,940 --> 00:00:13,000
First, we're going to fix a couple of errors that we have.

6
00:00:13,000 --> 00:00:15,970
We're going to handle them using, try and accept.

7
00:00:16,690 --> 00:00:24,190
Second, we're going to add a life date and time with a second ticking on the guy.

8
00:00:24,700 --> 00:00:30,310
And third, we're going to polish the program, change the theme of the program, play around with the

9
00:00:30,310 --> 00:00:32,320
sizes of the elements and so on.

10
00:00:32,350 --> 00:00:35,050
Let's begin by fixing the errors.

11
00:00:35,530 --> 00:00:40,570
So when the user runs the program and without selecting anything, they press on.

12
00:00:40,570 --> 00:00:44,350
Edit Then we get this error index error.

13
00:00:44,350 --> 00:00:51,250
That is because in line 34 and here this values is a dictionary.

14
00:00:51,250 --> 00:00:57,370
So it is this dictionary and values to dos gives us this list.

15
00:00:57,370 --> 00:01:01,330
So we access the value of to dos, which is a list.

16
00:01:01,330 --> 00:01:08,080
And then this port tries to access the first item of that list you see with index zero.

17
00:01:08,080 --> 00:01:14,140
But there is no such item because the user hasn't selected any items from the list box.

18
00:01:14,140 --> 00:01:22,510
Therefore we get an index error, as you might know already to handle errors we use, try and accept.

19
00:01:22,630 --> 00:01:33,280
So we're going to indent all that block and place it under a try statement and then go here on indent

20
00:01:33,280 --> 00:01:39,580
so that you are in the same level with try and say accept and look at the error we got.

21
00:01:39,850 --> 00:01:41,280
So it's an index error.

22
00:01:46,300 --> 00:01:55,450
And let's try first to print out something such as Please select an item first.

23
00:01:58,110 --> 00:01:59,850
Let's try this around.

24
00:02:00,300 --> 00:02:08,639
Edit And we get the printing successfully executed so the tricep block is working.

25
00:02:10,300 --> 00:02:19,490
However, note that when we create this group programs, what the user will see is the actual gooey.

26
00:02:19,540 --> 00:02:23,500
They will not see any command line interface.

27
00:02:23,650 --> 00:02:32,010
Therefore, any messages that you show to the user you should show them here on the graphical user interface.

28
00:02:32,020 --> 00:02:37,610
Or you could create a popup window telling them what they did wrong.

29
00:02:37,630 --> 00:02:39,280
So let's create a pop up.

30
00:02:39,550 --> 00:02:47,230
I'll close this and instead of printing this out, we want to use the s g dot pop up.

31
00:02:50,810 --> 00:02:55,400
So SJ is pi simple, gooey and pop.

32
00:02:55,400 --> 00:03:00,350
Pop is a function of that module.

33
00:03:00,350 --> 00:03:07,490
So if you right click here and go to implementations, it's going to take you to the function definition,

34
00:03:07,490 --> 00:03:09,590
to the pop up function definition.

35
00:03:10,340 --> 00:03:15,740
This is the docstring or that in green, and then that's the code of the library.

36
00:03:15,920 --> 00:03:22,370
So the library is written in Python, as is the case with all third party libraries which you install

37
00:03:22,370 --> 00:03:23,090
with PIP.

38
00:03:24,450 --> 00:03:27,570
So let's try to run this and see what happens.

39
00:03:27,780 --> 00:03:28,260
Press on.

40
00:03:28,260 --> 00:03:30,670
Edit and we get this window.

41
00:03:30,690 --> 00:03:33,360
So it says, Please select an item first.

42
00:03:33,390 --> 00:03:35,070
The user can close, it can press.

43
00:03:35,070 --> 00:03:42,660
Okay, We can make that pop up window bigger by applying a font argument.

44
00:03:42,660 --> 00:03:43,860
So just like.

45
00:03:45,980 --> 00:03:49,520
This window method has that formed argument?

46
00:03:50,430 --> 00:03:51,310
The pop.

47
00:03:52,830 --> 00:03:56,310
Function also has that font arguments.

48
00:03:56,760 --> 00:04:06,840
So this gets the font family and the size right click run, go press and edit.

49
00:04:06,840 --> 00:04:08,280
And that's the window.

50
00:04:08,280 --> 00:04:09,480
So it looks better.

51
00:04:12,400 --> 00:04:15,760
We have the same issue with complete the complete case.

52
00:04:15,760 --> 00:04:22,000
So if the user presses complete without selecting an item, we still have an error here.

53
00:04:22,000 --> 00:04:24,460
So let's quickly do the same here.

54
00:04:24,580 --> 00:04:26,860
Indent try then.

55
00:04:30,340 --> 00:04:33,310
Except this is also an index error.

56
00:04:35,830 --> 00:04:39,010
And so I'm going to copy that and paste it here.

57
00:04:40,660 --> 00:04:42,580
So let me put this in here.

58
00:04:44,590 --> 00:04:49,570
Run press and complete and we get this window popping up.

59
00:04:49,810 --> 00:04:51,400
So it's working fine.

60
00:04:52,780 --> 00:04:53,050
All right.

61
00:04:53,050 --> 00:04:55,900
So that's about error handling.

62
00:04:56,710 --> 00:04:57,160
Next.

63
00:04:57,160 --> 00:05:05,380
What we want to do is on top of this label as the first row, we want to add the current date and time.

64
00:05:05,380 --> 00:05:06,550
So let's do that.

65
00:05:06,670 --> 00:05:10,660
We set on top of this label, so we want to create another label here.

66
00:05:10,990 --> 00:05:14,320
Label is equal to as the text.

67
00:05:15,610 --> 00:05:23,170
First we leave it empty and then we update that as g text that label object, which actually needs to

68
00:05:23,170 --> 00:05:24,610
be a different name.

69
00:05:24,610 --> 00:05:26,650
So we have that label variable there.

70
00:05:26,650 --> 00:05:35,620
So let's call this maybe time or clock because you don't want to use time because we're going to import

71
00:05:35,620 --> 00:05:36,280
time.

72
00:05:36,880 --> 00:05:39,790
So this is the name of the module we're going to use.

73
00:05:39,790 --> 00:05:47,890
Therefore, don't use variable names which have the same name with keywords, modules, objects, functions,

74
00:05:47,890 --> 00:05:51,550
etc. So just use something like a clock.

75
00:05:51,550 --> 00:05:59,200
So we import time because as you know from our previous command line interface, we use time to get

76
00:05:59,200 --> 00:06:05,080
the actual time with that staff time function.

77
00:06:05,080 --> 00:06:08,980
So when do we update that text?

78
00:06:09,370 --> 00:06:13,270
Well, we update it somewhere in here.

79
00:06:13,360 --> 00:06:24,580
So after we apply window that reads, we say window and we point to this clock instance, we should

80
00:06:24,580 --> 00:06:29,620
give a key to that so that this clock has an identifier.

81
00:06:29,620 --> 00:06:31,120
So let's say clock.

82
00:06:31,120 --> 00:06:36,730
And that clock now should be mentioned in here.

83
00:06:36,730 --> 00:06:37,390
Here we are.

84
00:06:37,390 --> 00:06:37,720
Yeah.

85
00:06:38,410 --> 00:06:38,980
Clock.

86
00:06:38,980 --> 00:06:46,390
So that's access is the window clock, that label and we update the contents of that label.

87
00:06:46,390 --> 00:06:49,750
The current content is an empty string as you see here.

88
00:06:49,750 --> 00:06:52,030
So we update that to.

89
00:06:55,900 --> 00:07:01,240
Value time that s t r f time.

90
00:07:02,470 --> 00:07:04,000
So we call that.

91
00:07:04,060 --> 00:07:05,620
Methods, actually.

92
00:07:05,950 --> 00:07:08,650
And that was this one.

93
00:07:08,650 --> 00:07:10,090
So let me copy that.

94
00:07:11,080 --> 00:07:14,980
Go to that p y And we are here.

95
00:07:15,370 --> 00:07:16,270
So that's it.

96
00:07:16,270 --> 00:07:21,940
The new value is going to be the output of this method and the output of that method is the time and

97
00:07:21,940 --> 00:07:22,630
the date.

98
00:07:26,130 --> 00:07:28,710
And let's make sure that.

99
00:07:30,220 --> 00:07:32,350
We have added now this.

100
00:07:33,760 --> 00:07:34,630
Clock.

101
00:07:34,900 --> 00:07:38,200
Instance to the layout here in SD window.

102
00:07:38,200 --> 00:07:42,700
So we said we wanted to add another item above the label.

103
00:07:42,850 --> 00:07:47,680
Therefore, this is going to be at least an inside the list is clock.

104
00:07:48,520 --> 00:07:52,360
Let me indent this and don't forget the comma here.

105
00:07:53,800 --> 00:07:56,050
So that should be fine.

106
00:07:57,030 --> 00:07:58,290
Let's run the code.

107
00:08:02,710 --> 00:08:10,030
Now we have this space here, but it's still an empty string, so the time somehow is not being displayed.

108
00:08:10,060 --> 00:08:16,390
To fix that, you want to go to window the street and say time out is equal to ten.

109
00:08:17,830 --> 00:08:18,760
Run again.

110
00:08:20,240 --> 00:08:21,560
And now we see the time.

111
00:08:23,070 --> 00:08:23,620
There you go.

112
00:08:23,640 --> 00:08:25,380
So it's working.

113
00:08:25,380 --> 00:08:34,659
And you can see in the command line that, no, this world loop is being executed every 10 milliseconds.

114
00:08:34,679 --> 00:08:43,830
We had to apply a timeout because otherwise the loop runs only when an event happens, when the user

115
00:08:43,830 --> 00:08:45,660
presses the buttons and so on.

116
00:08:45,660 --> 00:08:53,100
But when you apply that timeout ten that the loop runs every 10 milliseconds, which is a fraction of

117
00:08:53,100 --> 00:08:53,760
a second.

118
00:08:53,760 --> 00:09:02,250
Therefore, that continuous running will allow this part here to be executed every 10 milliseconds.

119
00:09:02,250 --> 00:09:11,520
And that makes it possible to see the actual time here updated every second you see, you can also get

120
00:09:11,520 --> 00:09:15,120
away with another bigger value, such as two hundreds.

121
00:09:15,120 --> 00:09:18,300
So a second has 1000 milliseconds.

122
00:09:18,300 --> 00:09:21,870
So 200 is still less than a second and.

123
00:09:24,420 --> 00:09:25,790
It's not displaying.

124
00:09:25,800 --> 00:09:27,060
Let me run it again.

125
00:09:28,950 --> 00:09:30,900
So 200 is also fine.

126
00:09:31,380 --> 00:09:37,890
And it's also better for the program because it's not running so heavily every 10 milliseconds.

127
00:09:39,090 --> 00:09:39,360
Right.

128
00:09:39,360 --> 00:09:42,510
I'll leave it as it is and I'll delete these.

129
00:09:42,510 --> 00:09:44,580
Now, we don't need these anymore.

130
00:09:44,580 --> 00:09:47,160
We don't need to print them out in the command line.

131
00:09:47,160 --> 00:09:51,060
So those print functions were printing out these lines.

132
00:09:53,110 --> 00:09:57,430
And lastly, let's change the theme of the program.

133
00:09:57,610 --> 00:10:01,270
To change the theme, you want to apply that theme.

134
00:10:02,860 --> 00:10:06,410
So what theme can you apply for your program?

135
00:10:06,430 --> 00:10:11,860
Well, if you go to Google and search for POI Simple, go with themes and go to images.

136
00:10:12,070 --> 00:10:15,160
Then the first image, you can click it.

137
00:10:16,150 --> 00:10:17,260
You can open it.

138
00:10:21,510 --> 00:10:26,460
And that should give you all the available themes you can apply.

139
00:10:26,490 --> 00:10:35,970
For example, if you want Dark purple for this one here, up here, then you want to write here dark.

140
00:10:36,720 --> 00:10:42,840
Purple for so Ron Gooey and that's what you get.

141
00:10:44,240 --> 00:10:50,350
I think the black theme is fine, so I hope you agree with me.

142
00:10:50,360 --> 00:10:54,350
Otherwise, just find one of the themes on the page I showed you.

143
00:10:55,670 --> 00:11:01,200
Lastly, I want to talk about the sizes you give to your widgets.

144
00:11:01,220 --> 00:11:07,610
For example, we used size equal to that list, which has two elements, two numbers.

145
00:11:07,610 --> 00:11:10,040
That was the size for the list box.

146
00:11:10,070 --> 00:11:14,480
Now, how do I know what size to give you and how can you know?

147
00:11:14,660 --> 00:11:18,720
Well, for such things, you don't even have to ask me.

148
00:11:18,740 --> 00:11:27,470
You can right click over this box, go to implementations and then look at the size description in the

149
00:11:27,470 --> 00:11:28,160
docstring.

150
00:11:28,160 --> 00:11:30,080
So you see the triple quotes here.

151
00:11:30,380 --> 00:11:37,670
So if you scroll down somewhere here, that's the size and on the sides here is the description.

152
00:11:39,420 --> 00:11:41,290
Of the size parameter.

153
00:11:41,330 --> 00:11:47,390
So this is saying that this size has white as the first character.

154
00:11:47,780 --> 00:11:52,080
You see down here, it's it's supposed to receive two integers.

155
00:11:52,100 --> 00:11:57,350
The first one is going to be the width, and this is the number of characters.

156
00:11:57,350 --> 00:12:03,460
So what I'm giving here for the list box is 45 characters wide.

157
00:12:03,470 --> 00:12:13,130
So that means the width of the list box is equal to 45 characters and ten.

158
00:12:13,160 --> 00:12:19,760
As you can see here, ten is the height in number of rules.

159
00:12:19,760 --> 00:12:29,450
So this program now is like one, two, three, four, five, six, seven, eight, nine, ten rows

160
00:12:29,450 --> 00:12:30,050
high.

161
00:12:31,010 --> 00:12:37,850
That's how sizing works for all the widgets, not only for the list box, but for other widgets as well.

162
00:12:37,850 --> 00:12:39,950
And it also says something else.

163
00:12:39,950 --> 00:12:47,320
If an int is instead supplied instead of a tuple, then the height is set to one by default.

164
00:12:47,330 --> 00:12:56,420
So that means you can also give, for example, for a button, you can give the size equal to ten and

165
00:12:56,420 --> 00:12:59,150
you see that the button is now wider.

166
00:12:59,390 --> 00:13:05,450
However, the height doesn't change because the height is by default, want a row unit.

167
00:13:07,340 --> 00:13:10,760
And that's the idea also about our problem.

168
00:13:11,910 --> 00:13:14,240
One last tip before we close the video.

169
00:13:14,250 --> 00:13:21,420
If you are using poor charm, I do suggest you to use the Rainbow plugin which you can install by going

170
00:13:21,420 --> 00:13:28,800
to settings and then going to plugins and then going to marketplace and search for rainbow.

171
00:13:29,970 --> 00:13:30,930
Install it.

172
00:13:32,380 --> 00:13:34,530
Then restored power charm.

173
00:13:39,920 --> 00:13:46,030
And what that plugin does is it colors the brackets, parentheses and brackets.

174
00:13:46,040 --> 00:13:50,270
So now this yellow parentheses corresponds to that yellow parentheses.

175
00:13:50,270 --> 00:13:53,060
So the code is visually more readable.

176
00:13:53,060 --> 00:13:56,780
You see that this green bracket closes here and so on.

177
00:13:56,780 --> 00:14:04,970
If you are on another IDE other than porch or perhaps you could Google something like Rainbow Alternative

178
00:14:04,970 --> 00:14:08,720
for Visual Studio codes or Atom wherever ID you are using.

179
00:14:08,720 --> 00:14:13,640
And probably there is such a plugin for your favorite IDE as well.

180
00:14:13,730 --> 00:14:19,550
So I wanted to show you this because from now on the code is more complex, such as this one here,

181
00:14:19,730 --> 00:14:25,220
so it is helpful to see more emphasized syntax highlighting.

182
00:14:25,700 --> 00:14:28,730
Let's also commit the changes.

183
00:14:32,150 --> 00:14:39,620
Change theme at clock handle, edit and complete errors.

184
00:14:39,710 --> 00:14:42,270
That's what we did so commit.

185
00:14:43,430 --> 00:14:45,890
Then I'm going to push the changes to GitHub.

186
00:14:46,280 --> 00:14:49,850
So with that we are done with our program.

187
00:14:50,390 --> 00:14:57,740
It was quite a long journey to build this first app and it was a bit slow because this was the first

188
00:14:57,740 --> 00:15:01,520
app and I had to explain you a lot, a lot of concepts.

189
00:15:01,520 --> 00:15:08,180
I had to explain you the features of Python, the types of objects function, etc. So for the next apps,

190
00:15:08,180 --> 00:15:12,320
now we have a common language, you know what type is.

191
00:15:12,320 --> 00:15:18,770
So when ever I built something I just mentioned, I just tell you that, Oh, this is a type and this

192
00:15:18,770 --> 00:15:24,790
is an instance and we use that for this and everything is going to be much easier than it was.

193
00:15:24,800 --> 00:15:30,260
It's also going to be more fun with the next apps because this app was basically simple.

194
00:15:30,260 --> 00:15:32,450
We just had to work with texts.

195
00:15:32,450 --> 00:15:39,320
So the two two items were text, but we're going to work with more interesting data formats later in

196
00:15:39,320 --> 00:15:43,070
the course, such as PDFs and images, graphs, etc..

197
00:15:43,580 --> 00:15:47,900
So all of that can be handled with Python and it's a lot of fun.

198
00:15:47,900 --> 00:15:51,950
So stay tuned and I'll see you in the next videos by.

