1
00:00:05,580 --> 00:00:07,410
- [Instructor] So in the last
few videos, we've produced

2
00:00:07,410 --> 00:00:11,540
a scrollable subclass of
the tkinter Listbox class.

3
00:00:11,540 --> 00:00:15,680
We then populated the list
from our music database.

4
00:00:15,680 --> 00:00:17,820
So we've got everything we
need to move the database

5
00:00:17,820 --> 00:00:21,640
functionality into another
subclass to produce a listbox

6
00:00:21,640 --> 00:00:26,030
that automatically displays
data from a database table.

7
00:00:26,030 --> 00:00:28,780
But before we start, we
have to decide how we're

8
00:00:28,780 --> 00:00:32,740
going to initialise the
instances of our new class.

9
00:00:32,740 --> 00:00:34,240
Now, we're obviously
going to have to tell it

10
00:00:34,240 --> 00:00:36,050
the name of the table that it should get

11
00:00:36,050 --> 00:00:39,630
the data from and which
field it needs to display.

12
00:00:39,630 --> 00:00:43,120
So it's a good idea to provide
a database connexion as well

13
00:00:43,120 --> 00:00:46,500
so that our classes don't have
to rely on a global variable.

14
00:00:46,500 --> 00:00:48,850
A sort order would also be useful.

15
00:00:48,850 --> 00:00:50,910
The songs should be listed in track order,

16
00:00:50,910 --> 00:00:52,410
the order they appear on the album,

17
00:00:52,410 --> 00:00:54,760
but we're displaying the song titles.

18
00:00:54,760 --> 00:00:57,150
So sorting by the song title wouldn't be

19
00:00:57,150 --> 00:00:59,290
what users were expecting to see.

20
00:00:59,290 --> 00:01:02,310
Now, we can make the default
sort order the displayed field

21
00:01:02,310 --> 00:01:05,640
so that if a different
sort order isn't specified,

22
00:01:05,640 --> 00:01:08,980
the list will then sort
the items alphabetically.

23
00:01:08,980 --> 00:01:10,480
Now, at the moment, when
we run the programme,

24
00:01:10,480 --> 00:01:13,840
only one of our listboxes
displays data to start with.

25
00:01:13,840 --> 00:01:15,690
So what we need is some way to trigger

26
00:01:15,690 --> 00:01:18,950
the initial load of
data for those instances

27
00:01:18,950 --> 00:01:22,520
that will display data as
soon as they're created.

28
00:01:22,520 --> 00:01:23,570
And we also need some way

29
00:01:23,570 --> 00:01:26,110
to get the other listboxes
to load their data

30
00:01:26,110 --> 00:01:29,330
once we know the ID of
the artist or album,

31
00:01:29,330 --> 00:01:31,860
and in fact it would make
sense to use the same method

32
00:01:31,860 --> 00:01:35,350
in both cases and just
pass none for the ID

33
00:01:35,350 --> 00:01:37,640
when we're loading the first lists.

34
00:01:37,640 --> 00:01:39,780
All right, so that's probably
enough to start with.

35
00:01:39,780 --> 00:01:43,290
So let's go ahead now and
create DataListbox class

36
00:01:43,290 --> 00:01:46,650
and I'm gonna add this
after this Scrollbox class

37
00:01:46,650 --> 00:01:49,450
that we've created in the jukebox.py file.

38
00:01:49,450 --> 00:01:52,350
So I'm gonna add the customary two lines,

39
00:01:52,350 --> 00:01:54,770
two blank lines between classes here,

40
00:01:54,770 --> 00:01:58,520
and we're gonna start
with class DataListBox,

41
00:02:01,730 --> 00:02:06,120
and in parentheses, it's
going to be Scrollbox, colon,

42
00:02:06,120 --> 00:02:08,490
enter there, a space, and
then we're going to define

43
00:02:08,490 --> 00:02:11,910
our init method, so def, space, __init__,

44
00:02:12,860 --> 00:02:14,790
and I'll just select that automatically.

45
00:02:14,790 --> 00:02:17,920
The first parameter in parentheses
was added automatically,

46
00:02:17,920 --> 00:02:21,060
self, but we want these
other arguments now,

47
00:02:21,060 --> 00:02:23,060
so comma, space, window,

48
00:02:25,930 --> 00:02:27,910
comma, space, connexion,

49
00:02:27,910 --> 00:02:29,710
comma, space, table,

50
00:02:29,710 --> 00:02:31,440
comma, space, field,

51
00:02:31,440 --> 00:02:33,440
comma, space, sort_order

52
00:02:34,660 --> 00:02:38,030
equals, and two
parentheses, left and right.

53
00:02:38,030 --> 00:02:41,360
Then lastly, comma, space,
and then star, star,

54
00:02:41,360 --> 00:02:42,940
K-W-args or kwargs.

55
00:02:45,270 --> 00:02:47,800
All right, and I'm just gonna
put in, in a comment here,

56
00:02:47,800 --> 00:02:50,030
what the code would be for Python 2.

57
00:02:50,030 --> 00:02:54,200
Scrollbox.__init__(self,
window, **kwargs),

58
00:03:01,650 --> 00:03:03,420
and something there for Python 2,

59
00:03:03,420 --> 00:03:05,640
just so if you're following
along with Python 2,

60
00:03:05,640 --> 00:03:07,140
you'll know what to do there.

61
00:03:07,140 --> 00:03:09,540
All right, but in our case,
we're going to do a super,

62
00:03:09,540 --> 00:03:13,460
parentheses, dot __init__,
and we're gonna pass

63
00:03:15,040 --> 00:03:18,290
to this super call window and **kwargs.

64
00:03:22,230 --> 00:03:25,180
Next, we're going to
do self.cursor is equal

65
00:03:25,180 --> 00:03:26,930
to connection.cursor,

66
00:03:28,500 --> 00:03:31,020
or call to the cursor
method, to be more precise.

67
00:03:31,020 --> 00:03:34,650
We've got self.table is equal to table,

68
00:03:34,650 --> 00:03:38,060
and self.field is equal to field.

69
00:03:38,060 --> 00:03:39,310
Let's just move this up a little bit

70
00:03:39,310 --> 00:03:42,420
so we can see what we're doing here.

71
00:03:42,420 --> 00:03:46,590
And we wanna build a SQL
query now, so self.sql_select

72
00:03:48,150 --> 00:03:52,440
is equal to SELECT in
double quotes with a space,

73
00:03:52,440 --> 00:03:53,780
plus self.field,

74
00:03:55,280 --> 00:03:58,530
plus, double quotes, comma, space, _id,

75
00:04:01,050 --> 00:04:04,280
end of double quotes, plus
another set of double quotes

76
00:04:04,280 --> 00:04:07,260
with the word FROM with a
space around the word FROM

77
00:04:07,260 --> 00:04:11,430
plus self.table, and then
we'll put if sort_order,

78
00:04:14,450 --> 00:04:18,540
colon, and then we'll do
self.sql_select is equal

79
00:04:19,940 --> 00:04:22,870
to a space with double quotes with a space

80
00:04:22,870 --> 00:04:26,520
around the text, ORDER
BY, that we're adding,

81
00:04:26,520 --> 00:04:28,850
plus, then in single quotes,

82
00:04:30,210 --> 00:04:33,630
comma, .join(sort_order)

83
00:04:36,190 --> 00:04:38,840
and then we'll put an
else: otherwise for that.

84
00:04:38,840 --> 00:04:43,620
It's going to be
self.sql_select equals ORDER BY

85
00:04:43,620 --> 00:04:48,120
in double quotes with a
space around both terms,

86
00:04:48,120 --> 00:04:49,530
at the start and end, in other words,

87
00:04:49,530 --> 00:04:50,610
plus self_...

88
00:04:52,110 --> 00:04:54,120
Sorry, self.field.

89
00:04:54,120 --> 00:04:56,290
I'm gonna put another line
there to keep Python happy

90
00:04:56,290 --> 00:05:00,570
with the method, the function
that we've got below that.

91
00:05:00,570 --> 00:05:03,710
All right, so starting off
here, out init method is calling

92
00:05:03,710 --> 00:05:07,460
the super method for
Scrollbox, and I've included

93
00:05:07,460 --> 00:05:10,920
the Python 2 syntax on
line 29 as well for that.

94
00:05:10,920 --> 00:05:13,100
So next, we create data attributes

95
00:05:13,100 --> 00:05:16,100
from the parameters
passed to the init method.

96
00:05:16,100 --> 00:05:17,520
Now, we're going to work with a cursor

97
00:05:17,520 --> 00:05:19,310
so we store that rather
than the connexions.

98
00:05:19,310 --> 00:05:22,290
You can see here, we're
storing the actual cursor

99
00:05:22,290 --> 00:05:24,800
and not the connexion on line 32.

100
00:05:24,800 --> 00:05:27,330
Now, you should write a
class to accept a cursor

101
00:05:27,330 --> 00:05:30,500
rather than a connexion, but
it's probably more useful

102
00:05:30,500 --> 00:05:32,220
to provide a connexion.

103
00:05:32,220 --> 00:05:34,730
Now, I call it the column parameter field

104
00:05:34,730 --> 00:05:39,430
because we're working in the
grid layout_manager down here,

105
00:05:39,430 --> 00:05:41,770
and column could then get
confusing for that reason.

106
00:05:41,770 --> 00:05:43,670
And table of course is the table

107
00:05:43,670 --> 00:05:45,960
that we're going to be
selecting the data from.

108
00:05:45,960 --> 00:05:47,980
Now, the sort_order argument
here, we have to find that

109
00:05:47,980 --> 00:05:49,900
as a tuple to allow the caller

110
00:05:49,900 --> 00:05:53,020
to specify multiple columns
to sort on if they need to.

111
00:05:53,020 --> 00:05:55,590
Now, this doesn't make a lot
of sense with our tables,

112
00:05:55,590 --> 00:05:57,440
but if we use the view, for example,

113
00:05:57,440 --> 00:06:00,240
from the previous videos,
then it could get useful.

114
00:06:00,240 --> 00:06:02,580
And we're also trying to
make the classes as general

115
00:06:02,580 --> 00:06:05,340
as possible so they can't be
used in other programmes that

116
00:06:05,340 --> 00:06:10,250
perhaps have got more complicated
database schemes in place.

117
00:06:10,250 --> 00:06:12,950
So the sql_select attribute's
pretty straightforward,

118
00:06:12,950 --> 00:06:15,720
if you're reading that from line 36.

119
00:06:15,720 --> 00:06:17,520
Just contains a basic select statement

120
00:06:17,520 --> 00:06:20,350
to retrieve the required
field and the row ID.

121
00:06:20,350 --> 00:06:22,460
Now, we're putting a
restriction on the database

122
00:06:22,460 --> 00:06:24,240
that our class will work with.

123
00:06:24,240 --> 00:06:27,340
The table must have a column called _id.

124
00:06:27,340 --> 00:06:30,600
You can see that in here on
line 36, and that's of course

125
00:06:30,600 --> 00:06:33,320
used to uniquely identify
each row on the table.

126
00:06:33,320 --> 00:06:36,210
And actually that's not
unusual, but if you wanted

127
00:06:36,210 --> 00:06:38,530
to remove that restriction,
then you could request

128
00:06:38,530 --> 00:06:40,930
a primary key field as another parameter.

129
00:06:40,930 --> 00:06:42,580
We will not be doing that here.

130
00:06:42,580 --> 00:06:44,130
Now I've actually made a change here,

131
00:06:44,130 --> 00:06:46,370
so what I'm going to do is that's gonna be

132
00:06:46,370 --> 00:06:50,540
if sort_order, that actually
should have been if sql_sort...

133
00:06:52,490 --> 00:06:53,540
I'm confusing myself here.

134
00:06:53,540 --> 00:06:56,000
Sql_sort for that as well.

135
00:06:56,000 --> 00:06:58,970
So what I was trying to do
there is specify a SQL sort

136
00:06:58,970 --> 00:07:02,740
attribute with an order by
clause, and we're catering for

137
00:07:02,740 --> 00:07:06,810
the fact that they may be
passing that sort_order or not,

138
00:07:06,810 --> 00:07:09,540
so we're going to default to
the field and order by that

139
00:07:09,540 --> 00:07:13,640
if I don't pass a parameter
with the requested sort_order.

140
00:07:13,640 --> 00:07:15,200
Now, you could leave the default blank

141
00:07:15,200 --> 00:07:17,050
so that the data isn't sorted at all.

142
00:07:17,050 --> 00:07:18,670
That's the sort of detail you decide

143
00:07:18,670 --> 00:07:20,000
when designing your classes,

144
00:07:20,000 --> 00:07:23,460
and as long as the users
are aware of how it works,

145
00:07:23,460 --> 00:07:24,890
then that would be fine.

146
00:07:24,890 --> 00:07:27,300
Now, I'm not including doc
strings in the classes,

147
00:07:27,300 --> 00:07:29,160
because that would make
the videos too long,

148
00:07:29,160 --> 00:07:31,430
but that would certainly be
something you should add,

149
00:07:31,430 --> 00:07:33,050
especially when creating classes

150
00:07:33,050 --> 00:07:35,380
that should tend to be reused.

151
00:07:35,380 --> 00:07:37,800
All right, and again, in
the case of a sort_order

152
00:07:37,800 --> 00:07:40,360
being passed, we're using
.join with the sort_order

153
00:07:40,360 --> 00:07:42,750
and separating them by
commas as is required

154
00:07:42,750 --> 00:07:46,560
to fulfil the syntax for
an order by clause of SQL.

155
00:07:46,560 --> 00:07:49,770
All right, so the class at the
moment doesn't load any data,

156
00:07:49,770 --> 00:07:53,130
so we need to implement the requery method

157
00:07:53,130 --> 00:07:55,050
that it's going to need.

158
00:07:55,050 --> 00:07:57,910
Now, if we're going to allow
the listboxes to be requeried

159
00:07:57,910 --> 00:08:00,440
so that they can show new
data, we need some way

160
00:08:00,440 --> 00:08:03,490
to clear the existing data
out, so for that reason,

161
00:08:03,490 --> 00:08:05,320
we're also gonna add a clear method.

162
00:08:05,320 --> 00:08:07,980
So let's go ahead and add those.

163
00:08:09,320 --> 00:08:11,060
So we'll start with the clear method.

164
00:08:11,060 --> 00:08:14,260
So def clear, and of course self

165
00:08:14,260 --> 00:08:17,630
is the default parameter there, argument.

166
00:08:17,630 --> 00:08:19,960
Then we'll do a self.delete,

167
00:08:21,160 --> 00:08:23,560
in parentheses, zero, comma, space,

168
00:08:23,560 --> 00:08:27,730
tkinter.END, uppercase
letters, and right parenthesis.

169
00:08:31,250 --> 00:08:34,799
And the next one we want
is the requery method

170
00:08:34,799 --> 00:08:38,299
that we just talked about, so def requery,

171
00:08:40,100 --> 00:08:44,260
and argument is self again,
automatically added by IntelliJ.

172
00:08:44,260 --> 00:08:46,350
Then we're going to print

173
00:08:47,490 --> 00:08:51,660
(self.sql_select + self.sql_sort)

174
00:08:53,300 --> 00:08:54,740
for debugging purposes.

175
00:08:54,740 --> 00:08:55,570
But what we're going to do

176
00:08:55,570 --> 00:08:58,070
is put a TODO delete this line

177
00:09:00,100 --> 00:09:02,250
so we know to come back later

178
00:09:02,250 --> 00:09:05,150
once the testing is
complete and remove that.

179
00:09:05,150 --> 00:09:07,290
And in terms of what we're going to do now

180
00:09:07,290 --> 00:09:11,450
is from our requerying, we
first clear the listbox contents

181
00:09:12,410 --> 00:09:13,970
before re-loading, which would make sense

182
00:09:13,970 --> 00:09:16,150
so we haven't got duplicate entries.

183
00:09:16,150 --> 00:09:19,820
So we do a self.clear
to call our clear method

184
00:09:19,820 --> 00:09:22,260
that we just defined on line 43,

185
00:09:22,260 --> 00:09:25,350
and I just remove one of those lines.

186
00:09:26,220 --> 00:09:28,390
And after self.clear,

187
00:09:28,390 --> 00:09:33,120
then we're gonna put for
value in self.cursor...

188
00:09:33,120 --> 00:09:36,030
Oops, that should have been cursor.

189
00:09:36,890 --> 00:09:40,020
Then we wanna do self.insert,

190
00:09:40,020 --> 00:09:43,200
and the argument is gonna be tkinter.END,

191
00:09:43,200 --> 00:09:44,870
comma, space, value,

192
00:09:45,970 --> 00:09:49,370
and the value zero in square brackets,

193
00:09:49,370 --> 00:09:51,370
then end of parentheses.

194
00:09:54,040 --> 00:09:57,200
So the clear method, as
you can see on line 42,

195
00:09:57,200 --> 00:10:00,800
and the code's on line 43,
that uses the listbox delete

196
00:10:00,800 --> 00:10:04,110
method and we're specifying
the entire range of values,

197
00:10:04,110 --> 00:10:07,230
going from zero to tkinter.n constant,

198
00:10:07,230 --> 00:10:10,170
and that constant represents
the last item in the list.

199
00:10:10,170 --> 00:10:11,680
So consequently, calling that

200
00:10:11,680 --> 00:10:13,810
will actually delete all the entries.

201
00:10:13,810 --> 00:10:16,970
Now, the requery method that
we've defined on line 45,

202
00:10:16,970 --> 00:10:19,240
that's where our SQL statement's built up,

203
00:10:19,240 --> 00:10:23,880
from the sql_select part as
well as the sql_sort part.

204
00:10:23,880 --> 00:10:25,590
So I've printed that out,
but the other thing we need

205
00:10:25,590 --> 00:10:28,680
to do is actually add that,
so I'm talking about how it's

206
00:10:28,680 --> 00:10:30,290
being added, but we haven't
actually done that yet,

207
00:10:30,290 --> 00:10:33,370
so it's gonna be self.cursor.execute,

208
00:10:36,180 --> 00:10:40,340
and it's gonna be
self.sql_select + self.sql_sort.

209
00:10:42,760 --> 00:10:45,230
So obviously we're
printing it out on line 46.

210
00:10:45,230 --> 00:10:48,490
Line 47, we're actually
executing the combination

211
00:10:48,490 --> 00:10:52,830
of the sql_select that we've
generated on line 36 up here,

212
00:10:52,830 --> 00:10:55,750
then the sql_sort that we're creating

213
00:10:55,750 --> 00:10:58,780
on either line 38 or line
40, depending on whether

214
00:10:58,780 --> 00:11:02,230
that argument's been
passed for the sort_order.

215
00:11:02,230 --> 00:11:05,770
So then we're executing the SQL
code, as I said, on line 47.

216
00:11:05,770 --> 00:11:06,600
All right, once we've done that,

217
00:11:06,600 --> 00:11:08,810
the rest of this code
should look pretty familiar.

218
00:11:08,810 --> 00:11:10,070
We're executing the query

219
00:11:10,070 --> 00:11:13,140
and looping over the
cursor as you can see here.

220
00:11:13,140 --> 00:11:15,660
We're executing the query here on line 47.

221
00:11:15,660 --> 00:11:17,560
We're clearing the listbox contents

222
00:11:17,560 --> 00:11:20,560
and then we're looping
through the values one by one

223
00:11:20,560 --> 00:11:23,170
and then actually adding
each one to the listbox.

224
00:11:23,170 --> 00:11:25,740
And just a note here, on line 52,

225
00:11:25,740 --> 00:11:28,850
remember that we get a
tuple representing each row.

226
00:11:28,850 --> 00:11:31,340
Now as our query specified
the column we want

227
00:11:31,340 --> 00:11:34,450
and the ID, we add the
first item from the tuple

228
00:11:34,450 --> 00:11:37,140
into the list and that's
why we use the value zero

229
00:11:37,140 --> 00:11:40,790
in the square brackets to
indicate that first value.

230
00:11:40,790 --> 00:11:42,970
So at that point, that
should actually work.

231
00:11:42,970 --> 00:11:44,890
So we should be able
to test this class now

232
00:11:44,890 --> 00:11:48,870
before the video ends, so
let's remove all the code

233
00:11:48,870 --> 00:11:52,960
to populate the lists
from the artist listbox

234
00:11:52,960 --> 00:11:56,060
and replace it with a call
to this requery method

235
00:11:56,060 --> 00:11:58,580
just to check that and see
that it'll actually work.

236
00:11:58,580 --> 00:12:01,480
So to do that, we'll come down here,

237
00:12:01,480 --> 00:12:05,650
down to the setup here for
Artists Listbox on line 101.

238
00:12:07,420 --> 00:12:09,410
And what we wanna do
first is we wanna change

239
00:12:09,410 --> 00:12:12,160
the definition, so we
wanna change Scrollbox now

240
00:12:12,160 --> 00:12:13,850
to use our new class we've created,

241
00:12:13,850 --> 00:12:17,060
so that's going to be
DataListBox, and next,

242
00:12:17,060 --> 00:12:20,400
we're going to remove the SQL code here.

243
00:12:22,060 --> 00:12:23,390
And instead, we're going to replace that

244
00:12:23,390 --> 00:12:26,220
with a call to artistList.requery.

245
00:12:27,980 --> 00:12:28,970
We're just gonna be calling the code

246
00:12:28,970 --> 00:12:30,540
that we've just written.

247
00:12:30,540 --> 00:12:34,540
So let's check that first
to make sure it works.

248
00:12:37,160 --> 00:12:38,840
And we've got an error,
and of course the reason is

249
00:12:38,840 --> 00:12:40,900
we haven't specified our other parameters.

250
00:12:40,900 --> 00:12:42,140
We need to go ahead and do that.

251
00:12:42,140 --> 00:12:44,350
So we've got at the moment,
we've got DataListBox,

252
00:12:44,350 --> 00:12:47,990
we've got mainWindow, but
we also need a connexion,

253
00:12:47,990 --> 00:12:50,360
we need a table name, and we also need

254
00:12:50,360 --> 00:12:53,090
the column that we want to be displaying.

255
00:12:53,090 --> 00:12:54,630
So, we'll add those.

256
00:12:54,630 --> 00:12:57,600
So comma, space, conn, for the connexion.

257
00:12:57,600 --> 00:13:01,880
Comma, space, artists in double
quote, being the table name,

258
00:13:01,880 --> 00:13:03,800
and comma, space, name,

259
00:13:05,000 --> 00:13:07,060
being the actual field or column.

260
00:13:07,060 --> 00:13:09,560
And there's another option
there for sort_order,

261
00:13:09,560 --> 00:13:11,080
but we're not going to add that yet.

262
00:13:11,080 --> 00:13:12,760
We can add that option in later,

263
00:13:12,760 --> 00:13:15,000
just to see that it does work.

264
00:13:15,000 --> 00:13:18,830
Let's go ahead and do
that and run that again.

265
00:13:20,150 --> 00:13:23,230
This time, you can see we've
got the SQL printing out,

266
00:13:23,230 --> 00:13:25,210
and if we go back and
have a look at our code,

267
00:13:25,210 --> 00:13:27,500
we can see that we have
got our artists populated,

268
00:13:27,500 --> 00:13:30,130
so it is working now, which is fantastic.

269
00:13:30,130 --> 00:13:31,420
All right, so let's continue on now.

270
00:13:31,420 --> 00:13:32,750
Close that down.

271
00:13:34,110 --> 00:13:35,350
All right, so now that we've done that,

272
00:13:35,350 --> 00:13:37,980
we should be able to
replace the other two calls

273
00:13:37,980 --> 00:13:40,730
to our albums and also our songs.

274
00:13:42,610 --> 00:13:44,140
So we wanna change albumList here

275
00:13:44,140 --> 00:13:45,850
where it's just calling Scrollbox.

276
00:13:45,850 --> 00:13:49,750
We wanna change that now
to call our DataListBox

277
00:13:49,750 --> 00:13:53,050
and the arguments are going
to be mainWindow again,

278
00:13:53,050 --> 00:13:56,310
conn for our connexion,
comma, space, this time it's

279
00:13:56,310 --> 00:13:59,030
going to be albums for the
table name, comma, space,

280
00:13:59,030 --> 00:14:02,750
name for the field/column name,

281
00:14:02,750 --> 00:14:05,720
comma, space, this time
we'll add a sort_order,

282
00:14:05,720 --> 00:14:08,800
so I'm going to do sort_order equals,

283
00:14:09,880 --> 00:14:13,270
and I want parentheses,
and within the parentheses,

284
00:14:13,270 --> 00:14:17,170
we want name in double quotes and a comma,

285
00:14:17,170 --> 00:14:19,950
and we add a second parenthesis there.

286
00:14:19,950 --> 00:14:23,040
Okay, like so, and we'll
delete that line there.

287
00:14:23,040 --> 00:14:24,180
Last entry.

288
00:14:24,180 --> 00:14:26,670
Then what we need to do on the
line immediately after that,

289
00:14:26,670 --> 00:14:30,840
we wanna put albumList.requery,
and we leave the grid

290
00:14:32,140 --> 00:14:33,660
and the configures there were before,

291
00:14:33,660 --> 00:14:37,270
and we also leave the
binding as it was before.

292
00:14:37,270 --> 00:14:41,420
And lastly, for songList, we've
got the Scrollbox code here.

293
00:14:41,420 --> 00:14:44,740
We'll change that also to be DataListBox,

294
00:14:44,740 --> 00:14:49,660
and the arguments for that
will be mainWindow, conn again,

295
00:14:49,660 --> 00:14:53,570
and for the table, it's going
to be songs, comma, space,

296
00:14:53,570 --> 00:14:56,030
title is going to be
the name of the field,

297
00:14:56,030 --> 00:15:00,560
and let's also specify a
sort_order for this one,

298
00:15:00,560 --> 00:15:04,870
and we can just specify
that as track and title

299
00:15:04,870 --> 00:15:08,810
in parentheses, double
quotes, separated by a comma,

300
00:15:08,810 --> 00:15:10,820
and finish off the right parenthesis.

301
00:15:10,820 --> 00:15:12,970
And then of course on the next line,

302
00:15:12,970 --> 00:15:16,720
we need to do a requery,
so songList.requery.

303
00:15:20,020 --> 00:15:23,190
All right, so let's
actually try running this.

304
00:15:23,190 --> 00:15:25,390
You can see the three sets of
SQL that have been executed

305
00:15:25,390 --> 00:15:28,940
there for artists, albums,
and songs, and incidentally,

306
00:15:28,940 --> 00:15:31,560
there's no good reason
for sorting the songList

307
00:15:31,560 --> 00:15:35,100
on both track and title,
really other than to prove

308
00:15:35,100 --> 00:15:37,640
that the code doesn't crash
and so that we can check

309
00:15:37,640 --> 00:15:39,140
the SQL statement that we're printing out,

310
00:15:39,140 --> 00:15:42,320
and you can see there's multiple
sort_orders quite happily

311
00:15:42,320 --> 00:15:45,320
separated both with a comma
and made that valid code.

312
00:15:45,320 --> 00:15:48,000
But importantly, let's just
actually check this works.

313
00:15:48,000 --> 00:15:50,660
And you can see that we've
got it all working nicely.

314
00:15:50,660 --> 00:15:52,540
And now all three Listboxes at this point

315
00:15:52,540 --> 00:15:54,720
are now showing data,
which is what we wanted,

316
00:15:54,720 --> 00:15:57,580
and again, the SQL output
that we've got over here,

317
00:15:57,580 --> 00:16:00,530
I'll just move this
over, looks fine as well.

318
00:16:00,530 --> 00:16:02,260
So that's actually pretty cool.

319
00:16:02,260 --> 00:16:05,600
With subclass of tkinter.listbox
to reduce our scrollable

320
00:16:05,600 --> 00:16:08,800
listbox, and just to confirm,
we have got scrolling enabled

321
00:16:08,800 --> 00:16:13,550
for all three listboxes there,
so that's working nicely,

322
00:16:13,550 --> 00:16:15,220
and we can now load that data

323
00:16:15,220 --> 00:16:16,890
from a database table as you can see.

324
00:16:16,890 --> 00:16:18,280
Working pretty well.

325
00:16:18,280 --> 00:16:20,110
But we're still not done at this point,

326
00:16:20,110 --> 00:16:21,610
and in the next video,
we're going to add the code

327
00:16:21,610 --> 00:16:24,470
to allow our DataListboxes
to be linked together.

328
00:16:24,470 --> 00:16:27,100
Then, when we select an item
in one list, the related

329
00:16:27,100 --> 00:16:29,540
data will show in another
like it was doing earlier

330
00:16:29,540 --> 00:16:32,470
before we made the change to
move over to the DataListbox.

331
00:16:32,470 --> 00:16:35,520
But let's work on that in the next video.

