1
00:00:04,460 --> 00:00:07,510
Alright, so continuing on with our project.

2
00:00:07,510 --> 00:00:09,330
We're almost done at this point,

3
00:00:09,330 --> 00:00:12,730
but what if our data listBox isn't linked to another one?

4
00:00:12,730 --> 00:00:13,750
So we're going to need some way

5
00:00:13,750 --> 00:00:15,830
of linking two listBoxes together

6
00:00:15,830 --> 00:00:20,700
and this on_select method you can see here on line 59.

7
00:00:20,700 --> 00:00:22,410
Well, that should only try to requery

8
00:00:22,410 --> 00:00:24,930
another listBox if there actually is one.

9
00:00:24,930 --> 00:00:26,160
Now in a minute, what we're going to do

10
00:00:26,160 --> 00:00:28,250
is add another couple of fields to the class

11
00:00:28,250 --> 00:00:29,680
to handle the link.

12
00:00:29,680 --> 00:00:31,690
We're gonna finish off this method first, though.

13
00:00:31,690 --> 00:00:33,180
We're gonna get it to check

14
00:00:33,180 --> 00:00:34,910
that there is a link to this box

15
00:00:34,910 --> 00:00:39,020
before trying to requery one, so let's do that.

16
00:00:39,020 --> 00:00:41,270
We're going to put if self.

17
00:00:42,490 --> 00:00:45,660
so that's linked, and it's called box:

18
00:00:46,680 --> 00:00:49,110
we're gonna add that field shortly as I said,

19
00:00:49,110 --> 00:00:50,530
and then we're going to indent everything else.

20
00:00:50,530 --> 00:00:53,490
I'm gonna remove this extra commented out code now,

21
00:00:53,490 --> 00:00:55,650
which we no longer need.

22
00:00:55,650 --> 00:00:58,570
I'm also going to indent this code.

23
00:00:59,820 --> 00:01:03,630
And I'll just put another tab or space in there

24
00:01:03,630 --> 00:01:05,349
because IntelliJ was complaining

25
00:01:05,349 --> 00:01:08,850
that the hash was too close to the code,

26
00:01:08,850 --> 00:01:10,300
you need to put at least two spaces

27
00:01:10,300 --> 00:01:11,800
when you're actually adding a comment.

28
00:01:11,800 --> 00:01:13,550
So I've got rid of that warning.

29
00:01:13,550 --> 00:01:15,080
The other thing we're going to do here

30
00:01:15,080 --> 00:01:17,750
is change this albumList.requery,

31
00:01:17,750 --> 00:01:22,600
let's change that self.linked_box is what it should be.

32
00:01:22,600 --> 00:01:26,100
So that's self.linked_box.requery link id,

33
00:01:29,570 --> 00:01:32,650
so we haven't got the aristList hard coded anymore.

34
00:01:32,650 --> 00:01:34,980
So before we can see the new class working

35
00:01:34,980 --> 00:01:36,520
we need to add a way to link

36
00:01:36,520 --> 00:01:38,560
one data listBox to another.

37
00:01:38,560 --> 00:01:40,600
Now, not all listBoxes will be linked.

38
00:01:40,600 --> 00:01:43,300
Our songs list doesn't cause another box to be updated

39
00:01:43,300 --> 00:01:45,680
and we may want to use a single data listBox

40
00:01:45,680 --> 00:01:47,640
to display a database table

41
00:01:47,640 --> 00:01:50,120
without linking it to anything else.

42
00:01:50,120 --> 00:01:52,950
So rather than insisting that another data listBox

43
00:01:52,950 --> 00:01:55,450
is provided in the class init method,

44
00:01:55,450 --> 00:01:57,230
we're going to add a link method

45
00:01:57,230 --> 00:01:59,190
that can be used if required.

46
00:01:59,190 --> 00:02:00,630
Now we're going to use the link method

47
00:02:00,630 --> 00:02:03,650
by passing it a widget that we wanna link to

48
00:02:03,650 --> 00:02:06,250
and a database column that forms that link,

49
00:02:06,250 --> 00:02:07,580
and that means we're going to need

50
00:02:07,580 --> 00:02:10,449
another couple of data attributes in our class.

51
00:02:10,449 --> 00:02:13,680
Let's go back up to the top and add those data attributes,

52
00:02:13,680 --> 00:02:14,920
and we're going to put them just after

53
00:02:14,920 --> 00:02:17,760
the super call here in line 30.

54
00:02:17,760 --> 00:02:21,930
So first one, self. and it's going to be linked_box,

55
00:02:22,870 --> 00:02:25,290
we set that to none initially,

56
00:02:25,290 --> 00:02:27,950
and likewise for self.link_field

57
00:02:28,970 --> 00:02:30,490
we're going to set that to none,

58
00:02:30,490 --> 00:02:33,110
so that's our two attributes.

59
00:02:33,110 --> 00:02:34,410
And again, we're defaulting to none

60
00:02:34,410 --> 00:02:36,380
so that there's no link to start with.

61
00:02:36,380 --> 00:02:38,580
Now, if we need to link two listBoxes

62
00:02:38,580 --> 00:02:40,610
then we're going to call that link method,

63
00:02:40,610 --> 00:02:41,620
so let's add that method,

64
00:02:41,620 --> 00:02:45,780
and I'm gonna add that just after the clear method here,

65
00:02:46,800 --> 00:02:48,970
so it's gonna be def link,

66
00:02:50,420 --> 00:02:51,840
we've got self as an argument,

67
00:02:51,840 --> 00:02:53,670
, widget , link_field:

68
00:02:57,590 --> 00:03:01,760
and we're gonna put self.linked_box = widget

69
00:03:03,730 --> 00:03:07,140
and then we're gonna do widget.link_field

70
00:03:09,680 --> 00:03:12,100
gonna set that to link_field,

71
00:03:13,290 --> 00:03:14,980
so we're basically saving the value

72
00:03:14,980 --> 00:03:17,190
that was passed in the argument.

73
00:03:17,190 --> 00:03:18,540
So at this point whenever we want

74
00:03:18,540 --> 00:03:20,560
to link two listBoxes together,

75
00:03:20,560 --> 00:03:24,070
we can call this new link method of the master listBox,

76
00:03:24,070 --> 00:03:25,390
then we're passing in a reference

77
00:03:25,390 --> 00:03:27,590
to the data listBox that we wanna link to

78
00:03:27,590 --> 00:03:29,450
as well as the name of the column

79
00:03:29,450 --> 00:03:31,830
in the linked data listBoxes table.

80
00:03:31,830 --> 00:03:33,880
I'm gonna go through what this method's doing again

81
00:03:33,880 --> 00:03:35,570
once we've seen it working

82
00:03:35,570 --> 00:03:37,930
and can refer to the actual widgets.

83
00:03:37,930 --> 00:03:39,590
So that's fixed some of the warnings,

84
00:03:39,590 --> 00:03:41,780
if we have a look at our own query method,

85
00:03:41,780 --> 00:03:43,210
that's looking a lot better now,

86
00:03:43,210 --> 00:03:44,780
we fixed some of those warnings,

87
00:03:44,780 --> 00:03:46,920
but we've still got one more error to fix,

88
00:03:46,920 --> 00:03:48,040
so we come over here and have a look

89
00:03:48,040 --> 00:03:51,210
in our right margin and click on that,

90
00:03:52,070 --> 00:03:55,150
and you can see I've got a problem on line 115,

91
00:03:55,150 --> 00:03:56,480
and you can see with the code there

92
00:03:56,480 --> 00:03:59,200
that that's where we downed the listBox select event

93
00:03:59,200 --> 00:04:01,490
to the get_albums function.

94
00:04:01,490 --> 00:04:02,710
Now we've moved that function

95
00:04:02,710 --> 00:04:04,870
into the class and renamed it,

96
00:04:04,870 --> 00:04:07,090
which is why we're now, of course, getting that error.

97
00:04:07,090 --> 00:04:08,780
Now there's no reason why we have to perform

98
00:04:08,780 --> 00:04:10,450
the bind in the main programme.

99
00:04:10,450 --> 00:04:12,220
Our data listBox class knows

100
00:04:12,220 --> 00:04:13,620
that it's got a nonselect method,

101
00:04:13,620 --> 00:04:15,670
so we can bind to the method itself.

102
00:04:15,670 --> 00:04:19,670
So I'm gonna cut that line of code out,

103
00:04:19,670 --> 00:04:22,450
and I'm going to paste it to the data listBox init method,

104
00:04:22,450 --> 00:04:24,080
so I'm gonna go right up to the top,

105
00:04:24,080 --> 00:04:26,080
the init method up here,

106
00:04:27,410 --> 00:04:29,840
and I'm going to paste it after our data attributes

107
00:04:29,840 --> 00:04:32,140
before the sql select statement,

108
00:04:32,140 --> 00:04:33,620
paste it in there like that.

109
00:04:33,620 --> 00:04:37,800
Now we're no longer binding to the get_albums function

110
00:04:37,800 --> 00:04:40,660
so we have to change that in our on_select method,

111
00:04:40,660 --> 00:04:42,150
and we also wanna use self, though,

112
00:04:42,150 --> 00:04:44,920
instead of referring to the artistList widget,

113
00:04:44,920 --> 00:04:47,170
so I'm gonna change that to

114
00:04:48,630 --> 00:04:53,020
remove the artistList call there, that should be self.bind.

115
00:04:53,020 --> 00:04:54,710
The listBox select is still correct,

116
00:04:54,710 --> 00:04:57,640
but instead of the get_albums function

117
00:04:57,640 --> 00:05:00,230
it's going to be self, or method I should say,

118
00:05:00,230 --> 00:05:02,900
it's going to be self.on_select,

119
00:05:05,700 --> 00:05:07,250
and be careful when you're making that change

120
00:05:07,250 --> 00:05:10,670
because you can see here that IntelliJ tried to be helpful

121
00:05:10,670 --> 00:05:14,040
and added the parenthesis after the on_select.

122
00:05:14,040 --> 00:05:16,420
We actually don't want that, we wanna remove that,

123
00:05:16,420 --> 00:05:17,810
and again, the reason we're moving it is

124
00:05:17,810 --> 00:05:20,240
that if we left it with the parenthesis

125
00:05:20,240 --> 00:05:21,620
then that would result in binding

126
00:05:21,620 --> 00:05:23,510
to the result of calling the method

127
00:05:23,510 --> 00:05:25,360
and our method returns none in this case,

128
00:05:25,360 --> 00:05:26,960
which, by the way, is the default

129
00:05:26,960 --> 00:05:28,570
for all functions and methods

130
00:05:28,570 --> 00:05:30,950
if you don't explicitly return anything,

131
00:05:30,950 --> 00:05:32,620
and we wanna bind to the method,

132
00:05:32,620 --> 00:05:35,330
not to the value that calling it returns,

133
00:05:35,330 --> 00:05:36,310
so watch out for that.

134
00:05:36,310 --> 00:05:38,270
I'm saying, I know we've talked about that in the past,

135
00:05:38,270 --> 00:05:40,050
but it's a very easy mistake to make,

136
00:05:40,050 --> 00:05:41,780
especially with IntelliJ's, you know,

137
00:05:41,780 --> 00:05:43,920
quote unquote helpfulness here.

138
00:05:43,920 --> 00:05:44,810
Alright, so I fixed that,

139
00:05:44,810 --> 00:05:46,840
now I'm going to delete one of those lines

140
00:05:46,840 --> 00:05:48,990
to keep IntelliJ happy.

141
00:05:48,990 --> 00:05:52,390
Okay, so once our main code's created the albumList

142
00:05:52,390 --> 00:05:54,850
we can actually link it to the artistList,

143
00:05:54,850 --> 00:05:57,620
so let's go ahead and do that.

144
00:05:57,620 --> 00:05:59,620
We're gonna go down here

145
00:06:01,330 --> 00:06:04,300
and the moment we've got this albumList.bind

146
00:06:04,300 --> 00:06:08,470
to get_songs, so I'm actually gonna comment that out.

147
00:06:09,800 --> 00:06:10,930
What we're going to do instead

148
00:06:10,930 --> 00:06:12,930
is do an artistList.link

149
00:06:15,470 --> 00:06:18,670
and it's going to be to albumList,

150
00:06:18,670 --> 00:06:20,840
and then the field artist.

151
00:06:22,940 --> 00:06:24,490
Moving down we can do the same

152
00:06:24,490 --> 00:06:27,480
to link the songList to the albumList,

153
00:06:27,480 --> 00:06:30,810
so let's go ahead and do that.

154
00:06:30,810 --> 00:06:34,060
Then we'll do, this case albumList.link

155
00:06:35,800 --> 00:06:38,770
and that's going to be to songList in this case

156
00:06:38,770 --> 00:06:43,470
and then album, that's the column name, or the field.

157
00:06:43,470 --> 00:06:45,050
Alright, so let's run the programme.

158
00:06:45,050 --> 00:06:47,830
It should allow the album and songLists to be updated

159
00:06:47,830 --> 00:06:50,840
when items are selected in the list that they're linked to,

160
00:06:50,840 --> 00:06:54,090
so we'll actually run that and see.

161
00:06:54,090 --> 00:06:57,170
Go ahead and have a look at the code,

162
00:06:58,250 --> 00:07:00,420
and we can select, should be able to select an artist,

163
00:07:00,420 --> 00:07:02,970
we can see that's updating okay,

164
00:07:02,970 --> 00:07:05,520
and if I come over and click on an album

165
00:07:05,520 --> 00:07:07,630
we actually get a crash,

166
00:07:07,630 --> 00:07:09,320
so it's almost working.

167
00:07:09,320 --> 00:07:11,740
So selecting the artists you saw worked fine

168
00:07:11,740 --> 00:07:13,340
and the correct albums are displayed,

169
00:07:13,340 --> 00:07:15,410
but soon as I actually selected an album

170
00:07:15,410 --> 00:07:17,020
we actually had a crash.

171
00:07:17,020 --> 00:07:19,150
And if you come down here and look at the error,

172
00:07:19,150 --> 00:07:21,600
and I'll just close that down for now,

173
00:07:21,600 --> 00:07:22,830
and the error's saying here

174
00:07:22,830 --> 00:07:25,270
that there's no such column artists.

175
00:07:25,270 --> 00:07:26,810
Well the songs table doesn't actually have

176
00:07:26,810 --> 00:07:29,200
an artists column, so we shouldn't be referring

177
00:07:29,200 --> 00:07:31,500
to the artists column in the songs table,

178
00:07:31,500 --> 00:07:34,190
so obviously at this point something's not right.

179
00:07:34,190 --> 00:07:37,150
So if you click on this link to here in the error trace,

180
00:07:37,150 --> 00:07:41,190
that actually takes us to the line where the problem is.

181
00:07:41,190 --> 00:07:42,240
Well, that's actually the line

182
00:07:42,240 --> 00:07:43,980
that's actually executing the sql,

183
00:07:43,980 --> 00:07:46,150
but if you look above on line 56

184
00:07:46,150 --> 00:07:48,050
that's actually where the problem is.

185
00:07:48,050 --> 00:07:50,340
So I've still got the artists column hard coded

186
00:07:50,340 --> 00:07:53,660
as you can see here, into the sql where clause,

187
00:07:53,660 --> 00:07:56,060
and what we should be doing is using the link field,

188
00:07:56,060 --> 00:07:58,810
the one that was set when we call the link method,

189
00:07:58,810 --> 00:08:00,130
so let's go ahead and change that.

190
00:08:00,130 --> 00:08:04,050
So I'm going to delete the artist in the double quotes

191
00:08:04,050 --> 00:08:08,220
and we're going to replace that with self.link_field

192
00:08:09,390 --> 00:08:11,940
so we get the right column for the right table.

193
00:08:11,940 --> 00:08:13,980
But that raises another question, now,

194
00:08:13,980 --> 00:08:15,180
and that question is, what happens

195
00:08:15,180 --> 00:08:17,420
if we don't have a link field,

196
00:08:17,420 --> 00:08:20,180
because the listBox hasn't been linked to another one?

197
00:08:20,180 --> 00:08:22,020
Well in that cause, calling requery

198
00:08:22,020 --> 00:08:24,240
should populate the list with all the rows

199
00:08:24,240 --> 00:08:25,730
so we wanna execute the code

200
00:08:25,730 --> 00:08:27,650
in the else block in that scenario.

201
00:08:27,650 --> 00:08:31,200
So we can fix this by adding a test for the link_field

202
00:08:31,200 --> 00:08:33,299
as well as the link_value.

203
00:08:33,299 --> 00:08:34,480
So if we go ahead and do that,

204
00:08:34,480 --> 00:08:37,980
so I've got if link_value here on line 55,

205
00:08:38,880 --> 00:08:43,049
if we do or add the words "and" and self.link_field

206
00:08:45,970 --> 00:08:47,400
we're now only gonna execute that

207
00:08:47,400 --> 00:08:49,240
if there is a link that has been established

208
00:08:49,240 --> 00:08:51,640
between the two listBoxes.

209
00:08:51,640 --> 00:08:54,040
Otherwise the else code is gonna be executed,

210
00:08:54,040 --> 00:08:56,750
and reflectively going to get the entire contents

211
00:08:56,750 --> 00:08:58,790
of the table added to the listBox

212
00:08:58,790 --> 00:09:01,400
and that's actually what we want in this scenario.

213
00:09:01,400 --> 00:09:05,360
Alright, so we're going to also make a change down here

214
00:09:05,360 --> 00:09:07,750
after the call to self.clear,

215
00:09:07,750 --> 00:09:09,980
then we're actually through and adding the code there

216
00:09:09,980 --> 00:09:13,510
so you can see that adds the entries to the listBox.

217
00:09:13,510 --> 00:09:16,030
What we need to do also is down here

218
00:09:16,030 --> 00:09:18,950
put in some code if self.linked_box

219
00:09:22,210 --> 00:09:25,460
then we wanna do self.linked_box.clear.

220
00:09:28,830 --> 00:09:29,730
Now the reason we're doing that,

221
00:09:29,730 --> 00:09:32,900
that's to clear out the data in any linked data listBox

222
00:09:32,900 --> 00:09:35,420
so that way when we select a new artist

223
00:09:35,420 --> 00:09:38,620
the songs for the previous album aren't still displayed,

224
00:09:38,620 --> 00:09:39,720
and that's the reason, by the way,

225
00:09:39,720 --> 00:09:42,600
that we added a clear method in the first place

226
00:09:42,600 --> 00:09:45,430
rather than just deleting the list items earlier.

227
00:09:45,430 --> 00:09:47,350
So we need a method on the linked listBox

228
00:09:47,350 --> 00:09:49,300
to tell it to delete its contents.

229
00:09:49,300 --> 00:09:50,960
Alright, so let's actually try running this again,

230
00:09:50,960 --> 00:09:55,130
and hopefully things will actually work properly now.

231
00:09:58,980 --> 00:10:01,320
Alright, so if I select an artist,

232
00:10:01,320 --> 00:10:02,520
okay, so we've got an error there,

233
00:10:02,520 --> 00:10:04,040
let's just have a look.

234
00:10:04,040 --> 00:10:07,090
Can't convert DataListBox object to string implicitly,

235
00:10:07,090 --> 00:10:08,640
okay just click on that,

236
00:10:08,640 --> 00:10:09,840
and I've made a typo here,

237
00:10:09,840 --> 00:10:13,140
I've actually typed in self.linked_box,

238
00:10:13,140 --> 00:10:14,870
but it actually should be link_field,

239
00:10:14,870 --> 00:10:17,610
because the field is ultimately gonna be

240
00:10:17,610 --> 00:10:18,980
the column name for the database

241
00:10:18,980 --> 00:10:20,080
that we're trying to add,

242
00:10:20,080 --> 00:10:22,940
so that's just a typo, so I'll fix that.

243
00:10:22,940 --> 00:10:26,290
Link_field, that should fix that up,

244
00:10:26,290 --> 00:10:29,370
so let's just try running that again.

245
00:10:35,150 --> 00:10:37,990
Let's see how we go this time.

246
00:10:37,990 --> 00:10:40,590
Alright so, we'll try running it again,

247
00:10:40,590 --> 00:10:41,980
this time we haven't got an error there, that's good,

248
00:10:41,980 --> 00:10:43,510
so we've got artists showing,

249
00:10:43,510 --> 00:10:45,790
albums you saw was updating automatically,

250
00:10:45,790 --> 00:10:46,870
so each time we're clicking we're getting

251
00:10:46,870 --> 00:10:48,610
the list of albums, so that's good,

252
00:10:48,610 --> 00:10:50,400
and multiple albums are being shown.

253
00:10:50,400 --> 00:10:52,170
Now if we click on an album

254
00:10:52,170 --> 00:10:53,760
we're correctly getting the list of songs,

255
00:10:53,760 --> 00:10:56,090
and that's updating as well.

256
00:10:56,090 --> 00:10:58,460
So that's good, everything's now working great,

257
00:10:58,460 --> 00:11:00,230
and you can see that as I was selecting items

258
00:11:00,230 --> 00:11:01,860
in any one odd data listBox,

259
00:11:01,860 --> 00:11:03,770
the corresponding data is displayed

260
00:11:03,770 --> 00:11:05,880
in the linked data listBox,

261
00:11:05,880 --> 00:11:08,200
and I think at this point that's pretty impressive.

262
00:11:08,200 --> 00:11:11,290
So we've taken the basic tkinter listbox

263
00:11:11,290 --> 00:11:14,350
and now created our own scrollable version of it,

264
00:11:14,350 --> 00:11:16,870
and with that extended that further

265
00:11:16,870 --> 00:11:18,460
to produce a data listBox that can

266
00:11:18,460 --> 00:11:21,300
load its own data from a database table

267
00:11:21,300 --> 00:11:24,550
as well as triggering loading in another data listBox.

268
00:11:24,550 --> 00:11:27,340
So the code in the main programme becomes a lot cleaner

269
00:11:27,340 --> 00:11:30,270
and easier to instal as a result of this,

270
00:11:30,270 --> 00:11:31,750
but with that said we've still got a bit

271
00:11:31,750 --> 00:11:34,430
of tidying up to do there in the code

272
00:11:34,430 --> 00:11:35,880
before I end this video,

273
00:11:35,880 --> 00:11:38,770
and I'm just gonna close this down.

274
00:11:38,770 --> 00:11:40,400
Now to start with, we don't need

275
00:11:40,400 --> 00:11:43,280
this get_songs function anymore

276
00:11:43,280 --> 00:11:46,820
'cause that's now all handled by our data listBox class,

277
00:11:46,820 --> 00:11:48,840
and we also don't need to connect to the database

278
00:11:48,840 --> 00:11:50,750
right at the start of the programme.

279
00:11:50,750 --> 00:11:52,810
Now, we did that originally because our functions

280
00:11:52,810 --> 00:11:55,200
were using the global database connexion,

281
00:11:55,200 --> 00:11:56,760
but now that we're passing the connexion

282
00:11:56,760 --> 00:11:58,550
to our data listBox objects

283
00:11:58,550 --> 00:12:01,200
that code can come down to the main programme.

284
00:12:01,200 --> 00:12:02,860
We should also add a condition

285
00:12:02,860 --> 00:12:04,500
so that the main code isn't executed

286
00:12:04,500 --> 00:12:06,920
when the module's imported by another programme,

287
00:12:06,920 --> 00:12:08,840
and that'll then let other programmes

288
00:12:08,840 --> 00:12:11,690
use our scroll box and data listBox classes.

289
00:12:11,690 --> 00:12:12,750
Let's go ahead and do that,

290
00:12:12,750 --> 00:12:15,960
so I'm actually going to delete the get_songs function

291
00:12:15,960 --> 00:12:17,370
because that's existed in quite a few

292
00:12:17,370 --> 00:12:20,120
other versions of the video prior to this,

293
00:12:20,120 --> 00:12:23,690
or videos prior to this, so we don't need to preserve that,

294
00:12:23,690 --> 00:12:25,720
and clean up some of this.

295
00:12:25,720 --> 00:12:28,210
Let's also add that code there

296
00:12:28,210 --> 00:12:30,200
to make sure that the main code

297
00:12:30,200 --> 00:12:32,080
isn't executed when the module's imported.

298
00:12:32,080 --> 00:12:35,330
So if __name__ is equal to '__main__' :

299
00:12:43,530 --> 00:12:45,060
and from there we want to indent the code

300
00:12:45,060 --> 00:12:48,810
but we gotta start by moving this connexion,

301
00:12:49,740 --> 00:12:52,680
I'll comment that out and we'll delete this,

302
00:12:52,680 --> 00:12:55,110
clear up some spaces there,

303
00:12:55,110 --> 00:12:58,360
then I'm gonna come down and put that code in here,

304
00:12:58,360 --> 00:13:01,520
and then we're going to indent this other code,

305
00:13:01,520 --> 00:13:02,420
then go right down to the bottom

306
00:13:02,420 --> 00:13:05,080
and indent all of that, like so.

307
00:13:07,350 --> 00:13:09,100
Now we also were loading data

308
00:13:09,100 --> 00:13:11,790
into the albums and songLists when the programme starts,

309
00:13:11,790 --> 00:13:13,840
and if you recall we did that when testing earlier

310
00:13:13,840 --> 00:13:16,480
but we can now go ahead and delete those lines now.

311
00:13:16,480 --> 00:13:18,330
So in terms of that code you've got

312
00:13:18,330 --> 00:13:21,310
this requery here, firstly for albums,

313
00:13:21,310 --> 00:13:23,710
so let's, I'll just comment that out.

314
00:13:23,710 --> 00:13:26,000
You could just as easily delete that if you prefer.

315
00:13:26,000 --> 00:13:29,100
We've also got another one in the songs,

316
00:13:29,100 --> 00:13:31,040
the songlist.requery, which we no longer need

317
00:13:31,040 --> 00:13:32,580
to have that code there anymore.

318
00:13:32,580 --> 00:13:33,790
But of course we do wanna leave

319
00:13:33,790 --> 00:13:35,290
the original artists in there,

320
00:13:35,290 --> 00:13:37,100
so that all the artists are initially loaded,

321
00:13:37,100 --> 00:13:39,550
so that's good, that's now fixed.

322
00:13:39,550 --> 00:13:41,340
And down here for the main loop

323
00:13:41,340 --> 00:13:42,810
we can also get rid of the testList

324
00:13:42,810 --> 00:13:45,230
and the albumLV.set tuple,

325
00:13:45,230 --> 00:13:48,110
you don't actually want that to be populated either,

326
00:13:48,110 --> 00:13:49,680
so let's actually get rid of that as well,

327
00:13:49,680 --> 00:13:51,570
comment that out.

328
00:13:51,570 --> 00:13:54,630
Which really only leaves the code for the main loop

329
00:13:54,630 --> 00:13:56,970
in printing, the fact that we're closing

330
00:13:56,970 --> 00:13:59,830
the database connexion and then the connection.close,

331
00:13:59,830 --> 00:14:03,990
so let's just run this to make sure that it still works.

332
00:14:08,300 --> 00:14:10,740
So I've now only got the artists populated initially.

333
00:14:10,740 --> 00:14:13,740
We can click on a particular artist.

334
00:14:14,940 --> 00:14:17,210
By the way, we can click on songs as well,

335
00:14:17,210 --> 00:14:20,240
and because that's not associated with any other listBox

336
00:14:20,240 --> 00:14:21,240
we're not getting any errors,

337
00:14:21,240 --> 00:14:23,940
and that's working as well as we think it should be working,

338
00:14:23,940 --> 00:14:26,420
and we're still getting our other selects working correctly

339
00:14:26,420 --> 00:14:29,990
and the various data listBoxes being updated on the screen.

340
00:14:29,990 --> 00:14:33,440
So that's actually it, that's our data ListBox finished.

341
00:14:33,440 --> 00:14:35,120
I think you'd agree that the main program's now

342
00:14:35,120 --> 00:14:37,020
a lot tidier than what it was,

343
00:14:37,020 --> 00:14:39,180
and we haven't got any code copied and pasted,

344
00:14:39,180 --> 00:14:40,600
more to the point.

345
00:14:40,600 --> 00:14:44,350
We've also now got two completely reusable classes

346
00:14:44,350 --> 00:14:46,330
that we can import into other projects

347
00:14:46,330 --> 00:14:47,810
whenever we need a scrolling listBox

348
00:14:47,810 --> 00:14:51,620
or one that can display data from a database table.

349
00:14:51,620 --> 00:14:54,480
Now, there is a bug in the data listBox class, though.

350
00:14:54,480 --> 00:14:55,400
Let's see if you can figure out

351
00:14:55,400 --> 00:14:57,180
and try and spot what that is.

352
00:14:57,180 --> 00:14:59,630
In the next video I'm gonna show you what the bug is

353
00:14:59,630 --> 00:15:02,550
and then set you a challenge to fix that bug,

354
00:15:02,550 --> 00:15:04,880
so I will see you in the next video.

