WEBVTT 1 00:00:01.024 --> 00:00:04.079 Alright, so continuing on with our project. 2 00:00:04.079 --> 00:00:05.898 We're almost done at this point, 3 00:00:05.898 --> 00:00:09.293 but what if our data listBox isn't linked to another one? 4 00:00:09.293 --> 00:00:10.319 So we're going to need some way 5 00:00:10.319 --> 00:00:12.399 of linking two listBoxes together 6 00:00:12.399 --> 00:00:17.261 and this on_select method you can see here on line 59. 7 00:00:17.261 --> 00:00:18.973 Well, that should only try to requery 8 00:00:18.973 --> 00:00:21.493 another listBox if there actually is one. 9 00:00:21.493 --> 00:00:22.720 Now in a minute, what we're going to do 10 00:00:22.720 --> 00:00:24.812 is add another couple of fields to the class 11 00:00:24.812 --> 00:00:26.247 to handle the link. 12 00:00:26.247 --> 00:00:28.251 We're gonna finish off this method first, though. 13 00:00:28.251 --> 00:00:29.745 We're gonna get it to check 14 00:00:29.745 --> 00:00:31.476 that there is a link to this box 15 00:00:31.476 --> 00:00:35.582 before trying to requery one, so let's do that. 16 00:00:35.582 --> 00:00:37.832 We're going to put if self. 17 00:00:39.055 --> 00:00:42.222 so that's linked, and it's called box: 18 00:00:43.244 --> 00:00:45.679 we're gonna add that field shortly as I said, 19 00:00:45.679 --> 00:00:47.091 and then we're going to indent everything else. 20 00:00:47.091 --> 00:00:50.059 I'm gonna remove this extra commented out code now, 21 00:00:50.059 --> 00:00:52.214 which we no longer need. 22 00:00:52.214 --> 00:00:55.131 I'm also going to indent this code. 23 00:00:56.380 --> 00:01:00.197 And I'll just put another tab or space in there 24 00:01:00.197 --> 00:01:01.916 because IntelliJ was complaining 25 00:01:01.916 --> 00:01:05.411 that the hash was too close to the code, 26 00:01:05.411 --> 00:01:06.866 you need to put at least two spaces 27 00:01:06.866 --> 00:01:08.361 when you're actually adding a comment. 28 00:01:08.361 --> 00:01:10.114 So I've got rid of that warning. 29 00:01:10.114 --> 00:01:11.642 The other thing we're going to do here 30 00:01:11.642 --> 00:01:14.318 is change this albumList.requery, 31 00:01:14.318 --> 00:01:19.163 let's change that self.linked_box is what it should be. 32 00:01:19.163 --> 00:01:22.663 So that's self.linked_box.requery link id, 33 00:01:26.136 --> 00:01:29.218 so we haven't got the aristList hard coded anymore. 34 00:01:29.218 --> 00:01:31.545 So before we can see the new class working 35 00:01:31.545 --> 00:01:33.087 we need to add a way to link 36 00:01:33.087 --> 00:01:35.122 one data listBox to another. 37 00:01:35.122 --> 00:01:37.167 Now, not all listBoxes will be linked. 38 00:01:37.167 --> 00:01:39.863 Our songs list doesn't cause another box to be updated 39 00:01:39.863 --> 00:01:42.246 and we may want to use a single data listBox 40 00:01:42.246 --> 00:01:44.200 to display a database table 41 00:01:44.200 --> 00:01:46.683 without linking it to anything else. 42 00:01:46.683 --> 00:01:49.511 So rather than insisting that another data listBox 43 00:01:49.511 --> 00:01:52.011 is provided in the class init method, 44 00:01:52.011 --> 00:01:53.794 we're going to add a link method 45 00:01:53.794 --> 00:01:55.755 that can be used if required. 46 00:01:55.755 --> 00:01:57.193 Now we're going to use the link method 47 00:01:57.193 --> 00:02:00.215 by passing it a widget that we wanna link to 48 00:02:00.215 --> 00:02:02.812 and a database column that forms that link, 49 00:02:02.812 --> 00:02:04.143 and that means we're going to need 50 00:02:04.143 --> 00:02:07.016 another couple of data attributes in our class. 51 00:02:07.016 --> 00:02:10.241 Let's go back up to the top and add those data attributes, 52 00:02:10.241 --> 00:02:11.483 and we're going to put them just after 53 00:02:11.483 --> 00:02:14.327 the super call here in line 30. 54 00:02:14.327 --> 00:02:18.494 So first one, self. and it's going to be linked_box, 55 00:02:19.432 --> 00:02:21.851 we set that to none initially, 56 00:02:21.851 --> 00:02:24.518 and likewise for self.link_field 57 00:02:25.533 --> 00:02:27.052 we're going to set that to none, 58 00:02:27.052 --> 00:02:29.670 so that's our two attributes. 59 00:02:29.670 --> 00:02:30.970 And again, we're defaulting to none 60 00:02:30.970 --> 00:02:32.948 so that there's no link to start with. 61 00:02:32.948 --> 00:02:35.148 Now, if we need to link two listBoxes 62 00:02:35.148 --> 00:02:37.174 then we're going to call that link method, 63 00:02:37.174 --> 00:02:38.180 so let's add that method, 64 00:02:38.180 --> 00:02:42.347 and I'm gonna add that just after the clear method here, 65 00:02:43.364 --> 00:02:45.531 so it's gonna be def link, 66 00:02:46.986 --> 00:02:48.402 we've got self as an argument, 67 00:02:48.402 --> 00:02:50.235 , widget , link_field: 68 00:02:54.159 --> 00:02:58.326 and we're gonna put self.linked_box = widget 69 00:03:00.290 --> 00:03:03.707 and then we're gonna do widget.link_field 70 00:03:06.245 --> 00:03:08.662 gonna set that to link_field, 71 00:03:09.857 --> 00:03:11.540 so we're basically saving the value 72 00:03:11.540 --> 00:03:13.758 that was passed in the argument. 73 00:03:13.758 --> 00:03:15.109 So at this point whenever we want 74 00:03:15.109 --> 00:03:17.122 to link two listBoxes together, 75 00:03:17.122 --> 00:03:20.632 we can call this new link method of the master listBox, 76 00:03:20.632 --> 00:03:21.956 then we're passing in a reference 77 00:03:21.956 --> 00:03:24.153 to the data listBox that we wanna link to 78 00:03:24.153 --> 00:03:26.018 as well as the name of the column 79 00:03:26.018 --> 00:03:28.394 in the linked data listBoxes table. 80 00:03:28.394 --> 00:03:30.444 I'm gonna go through what this method's doing again 81 00:03:30.444 --> 00:03:32.139 once we've seen it working 82 00:03:32.139 --> 00:03:34.498 and can refer to the actual widgets. 83 00:03:34.498 --> 00:03:36.157 So that's fixed some of the warnings, 84 00:03:36.157 --> 00:03:38.344 if we have a look at our own query method, 85 00:03:38.344 --> 00:03:39.771 that's looking a lot better now, 86 00:03:39.771 --> 00:03:41.345 we fixed some of those warnings, 87 00:03:41.345 --> 00:03:43.482 but we've still got one more error to fix, 88 00:03:43.482 --> 00:03:44.607 so we come over here and have a look 89 00:03:44.607 --> 00:03:47.774 in our right margin and click on that, 90 00:03:48.637 --> 00:03:51.718 and you can see I've got a problem on line 115, 91 00:03:51.718 --> 00:03:53.040 and you can see with the code there 92 00:03:53.040 --> 00:03:55.768 that that's where we downed the listBox select event 93 00:03:55.768 --> 00:03:58.051 to the get_albums function. 94 00:03:58.051 --> 00:03:59.273 Now we've moved that function 95 00:03:59.273 --> 00:04:01.434 into the class and renamed it, 96 00:04:01.434 --> 00:04:03.651 which is why we're now, of course, getting that error. 97 00:04:03.651 --> 00:04:05.342 Now there's no reason why we have to perform 98 00:04:05.342 --> 00:04:07.014 the bind in the main programme. 99 00:04:07.014 --> 00:04:08.781 Our data listBox class knows 100 00:04:08.781 --> 00:04:10.181 that it's got a nonselect method, 101 00:04:10.181 --> 00:04:12.233 so we can bind to the method itself. 102 00:04:12.233 --> 00:04:16.234 So I'm gonna cut that line of code out, 103 00:04:16.234 --> 00:04:19.016 and I'm going to paste it to the data listBox init method, 104 00:04:19.016 --> 00:04:20.641 so I'm gonna go right up to the top, 105 00:04:20.641 --> 00:04:22.641 the init method up here, 106 00:04:23.972 --> 00:04:26.405 and I'm going to paste it after our data attributes 107 00:04:26.405 --> 00:04:28.703 before the sql select statement, 108 00:04:28.703 --> 00:04:30.185 paste it in there like that. 109 00:04:30.185 --> 00:04:34.367 Now we're no longer binding to the get_albums function 110 00:04:34.367 --> 00:04:37.228 so we have to change that in our on_select method, 111 00:04:37.228 --> 00:04:38.710 and we also wanna use self, though, 112 00:04:38.710 --> 00:04:41.489 instead of referring to the artistList widget, 113 00:04:41.489 --> 00:04:43.739 so I'm gonna change that to 114 00:04:45.197 --> 00:04:49.580 remove the artistList call there, that should be self.bind. 115 00:04:49.580 --> 00:04:51.274 The listBox select is still correct, 116 00:04:51.274 --> 00:04:54.203 but instead of the get_albums function 117 00:04:54.203 --> 00:04:56.796 it's going to be self, or method I should say, 118 00:04:56.796 --> 00:04:59.463 it's going to be self.on_select, 119 00:05:02.263 --> 00:05:03.810 and be careful when you're making that change 120 00:05:03.810 --> 00:05:07.234 because you can see here that IntelliJ tried to be helpful 121 00:05:07.234 --> 00:05:10.600 and added the parenthesis after the on_select. 122 00:05:10.600 --> 00:05:12.982 We actually don't want that, we wanna remove that, 123 00:05:12.982 --> 00:05:14.377 and again, the reason we're moving it is 124 00:05:14.377 --> 00:05:16.808 that if we left it with the parenthesis 125 00:05:16.808 --> 00:05:18.181 then that would result in binding 126 00:05:18.181 --> 00:05:20.078 to the result of calling the method 127 00:05:20.078 --> 00:05:21.922 and our method returns none in this case, 128 00:05:21.922 --> 00:05:23.528 which, by the way, is the default 129 00:05:23.528 --> 00:05:25.130 for all functions and methods 130 00:05:25.130 --> 00:05:27.511 if you don't explicitly return anything, 131 00:05:27.511 --> 00:05:29.189 and we wanna bind to the method, 132 00:05:29.189 --> 00:05:31.893 not to the value that calling it returns, 133 00:05:31.893 --> 00:05:32.872 so watch out for that. 134 00:05:32.872 --> 00:05:34.838 I'm saying, I know we've talked about that in the past, 135 00:05:34.838 --> 00:05:36.615 but it's a very easy mistake to make, 136 00:05:36.615 --> 00:05:38.342 especially with IntelliJ's, you know, 137 00:05:38.342 --> 00:05:40.488 quote unquote helpfulness here. 138 00:05:40.488 --> 00:05:41.376 Alright, so I fixed that, 139 00:05:41.376 --> 00:05:43.401 now I'm going to delete one of those lines 140 00:05:43.401 --> 00:05:45.551 to keep IntelliJ happy. 141 00:05:45.551 --> 00:05:48.950 Okay, so once our main code's created the albumList 142 00:05:48.950 --> 00:05:51.414 we can actually link it to the artistList, 143 00:05:51.414 --> 00:05:54.185 so let's go ahead and do that. 144 00:05:54.185 --> 00:05:56.185 We're gonna go down here 145 00:05:57.890 --> 00:06:00.863 and the moment we've got this albumList.bind 146 00:06:00.863 --> 00:06:05.030 to get_songs, so I'm actually gonna comment that out. 147 00:06:06.360 --> 00:06:07.499 What we're going to do instead 148 00:06:07.499 --> 00:06:09.499 is do an artistList.link 149 00:06:12.036 --> 00:06:15.233 and it's going to be to albumList, 150 00:06:15.233 --> 00:06:17.400 and then the field artist. 151 00:06:19.505 --> 00:06:21.052 Moving down we can do the same 152 00:06:21.052 --> 00:06:24.041 to link the songList to the albumList, 153 00:06:24.041 --> 00:06:27.370 so let's go ahead and do that. 154 00:06:27.370 --> 00:06:30.620 Then we'll do, this case albumList.link 155 00:06:32.361 --> 00:06:35.337 and that's going to be to songList in this case 156 00:06:35.337 --> 00:06:40.035 and then album, that's the column name, or the field. 157 00:06:40.035 --> 00:06:41.613 Alright, so let's run the programme. 158 00:06:41.613 --> 00:06:44.399 It should allow the album and songLists to be updated 159 00:06:44.399 --> 00:06:47.406 when items are selected in the list that they're linked to, 160 00:06:47.406 --> 00:06:50.654 so we'll actually run that and see. 161 00:06:50.654 --> 00:06:53.737 Go ahead and have a look at the code, 162 00:06:54.816 --> 00:06:56.988 and we can select, should be able to select an artist, 163 00:06:56.988 --> 00:06:59.539 we can see that's updating okay, 164 00:06:59.539 --> 00:07:02.083 and if I come over and click on an album 165 00:07:02.083 --> 00:07:04.190 we actually get a crash, 166 00:07:04.190 --> 00:07:05.881 so it's almost working. 167 00:07:05.881 --> 00:07:08.308 So selecting the artists you saw worked fine 168 00:07:08.308 --> 00:07:09.901 and the correct albums are displayed, 169 00:07:09.901 --> 00:07:11.971 but soon as I actually selected an album 170 00:07:11.971 --> 00:07:13.580 we actually had a crash. 171 00:07:13.580 --> 00:07:15.713 And if you come down here and look at the error, 172 00:07:15.713 --> 00:07:18.162 and I'll just close that down for now, 173 00:07:18.162 --> 00:07:19.398 and the error's saying here 174 00:07:19.398 --> 00:07:21.835 that there's no such column artists. 175 00:07:21.835 --> 00:07:23.371 Well the songs table doesn't actually have 176 00:07:23.371 --> 00:07:25.764 an artists column, so we shouldn't be referring 177 00:07:25.764 --> 00:07:28.065 to the artists column in the songs table, 178 00:07:28.065 --> 00:07:30.753 so obviously at this point something's not right. 179 00:07:30.753 --> 00:07:33.719 So if you click on this link to here in the error trace, 180 00:07:33.719 --> 00:07:37.752 that actually takes us to the line where the problem is. 181 00:07:37.752 --> 00:07:38.807 Well, that's actually the line 182 00:07:38.807 --> 00:07:40.546 that's actually executing the sql, 183 00:07:40.546 --> 00:07:42.713 but if you look above on line 56 184 00:07:42.713 --> 00:07:44.616 that's actually where the problem is. 185 00:07:44.616 --> 00:07:46.902 So I've still got the artists column hard coded 186 00:07:46.902 --> 00:07:50.225 as you can see here, into the sql where clause, 187 00:07:50.225 --> 00:07:52.620 and what we should be doing is using the link field, 188 00:07:52.620 --> 00:07:55.372 the one that was set when we call the link method, 189 00:07:55.372 --> 00:07:56.694 so let's go ahead and change that. 190 00:07:56.694 --> 00:08:00.619 So I'm going to delete the artist in the double quotes 191 00:08:00.619 --> 00:08:04.786 and we're going to replace that with self.link_field 192 00:08:05.956 --> 00:08:08.509 so we get the right column for the right table. 193 00:08:08.509 --> 00:08:10.542 But that raises another question, now, 194 00:08:10.542 --> 00:08:11.741 and that question is, what happens 195 00:08:11.741 --> 00:08:13.982 if we don't have a link field, 196 00:08:13.982 --> 00:08:16.745 because the listBox hasn't been linked to another one? 197 00:08:16.745 --> 00:08:18.584 Well in that cause, calling requery 198 00:08:18.584 --> 00:08:20.800 should populate the list with all the rows 199 00:08:20.800 --> 00:08:22.294 so we wanna execute the code 200 00:08:22.294 --> 00:08:24.217 in the else block in that scenario. 201 00:08:24.217 --> 00:08:27.768 So we can fix this by adding a test for the link_field 202 00:08:27.768 --> 00:08:29.869 as well as the link_value. 203 00:08:29.869 --> 00:08:31.040 So if we go ahead and do that, 204 00:08:31.040 --> 00:08:34.540 so I've got if link_value here on line 55, 205 00:08:35.446 --> 00:08:39.613 if we do or add the words "and" and self.link_field 206 00:08:42.534 --> 00:08:43.964 we're now only gonna execute that 207 00:08:43.964 --> 00:08:45.804 if there is a link that has been established 208 00:08:45.804 --> 00:08:48.209 between the two listBoxes. 209 00:08:48.209 --> 00:08:50.600 Otherwise the else code is gonna be executed, 210 00:08:50.600 --> 00:08:53.315 and reflectively going to get the entire contents 211 00:08:53.315 --> 00:08:55.357 of the table added to the listBox 212 00:08:55.357 --> 00:08:57.968 and that's actually what we want in this scenario. 213 00:08:57.968 --> 00:09:01.920 Alright, so we're going to also make a change down here 214 00:09:01.920 --> 00:09:04.316 after the call to self.clear, 215 00:09:04.316 --> 00:09:06.545 then we're actually through and adding the code there 216 00:09:06.545 --> 00:09:10.073 so you can see that adds the entries to the listBox. 217 00:09:10.073 --> 00:09:12.596 What we need to do also is down here 218 00:09:12.596 --> 00:09:15.513 put in some code if self.linked_box 219 00:09:18.775 --> 00:09:22.025 then we wanna do self.linked_box.clear. 220 00:09:25.391 --> 00:09:26.295 Now the reason we're doing that, 221 00:09:26.295 --> 00:09:29.466 that's to clear out the data in any linked data listBox 222 00:09:29.466 --> 00:09:31.981 so that way when we select a new artist 223 00:09:31.981 --> 00:09:35.188 the songs for the previous album aren't still displayed, 224 00:09:35.188 --> 00:09:36.286 and that's the reason, by the way, 225 00:09:36.286 --> 00:09:39.168 that we added a clear method in the first place 226 00:09:39.168 --> 00:09:41.999 rather than just deleting the list items earlier. 227 00:09:41.999 --> 00:09:43.910 So we need a method on the linked listBox 228 00:09:43.910 --> 00:09:45.869 to tell it to delete its contents. 229 00:09:45.869 --> 00:09:47.523 Alright, so let's actually try running this again, 230 00:09:47.523 --> 00:09:51.690 and hopefully things will actually work properly now. 231 00:09:55.546 --> 00:09:57.881 Alright, so if I select an artist, 232 00:09:57.881 --> 00:09:59.088 okay, so we've got an error there, 233 00:09:59.088 --> 00:10:00.602 let's just have a look. 234 00:10:00.602 --> 00:10:03.653 Can't convert DataListBox object to string implicitly, 235 00:10:03.653 --> 00:10:05.209 okay just click on that, 236 00:10:05.209 --> 00:10:06.407 and I've made a typo here, 237 00:10:06.407 --> 00:10:09.704 I've actually typed in self.linked_box, 238 00:10:09.704 --> 00:10:11.434 but it actually should be link_field, 239 00:10:11.434 --> 00:10:14.176 because the field is ultimately gonna be 240 00:10:14.176 --> 00:10:15.544 the column name for the database 241 00:10:15.544 --> 00:10:16.640 that we're trying to add, 242 00:10:16.640 --> 00:10:19.508 so that's just a typo, so I'll fix that. 243 00:10:19.508 --> 00:10:22.855 Link_field, that should fix that up, 244 00:10:22.855 --> 00:10:25.938 so let's just try running that again. 245 00:10:31.716 --> 00:10:34.558 Let's see how we go this time. 246 00:10:34.558 --> 00:10:37.150 Alright so, we'll try running it again, 247 00:10:37.150 --> 00:10:38.547 this time we haven't got an error there, that's good, 248 00:10:38.547 --> 00:10:40.078 so we've got artists showing, 249 00:10:40.078 --> 00:10:42.352 albums you saw was updating automatically, 250 00:10:42.352 --> 00:10:43.432 so each time we're clicking we're getting 251 00:10:43.432 --> 00:10:45.171 the list of albums, so that's good, 252 00:10:45.171 --> 00:10:46.964 and multiple albums are being shown. 253 00:10:46.964 --> 00:10:48.738 Now if we click on an album 254 00:10:48.738 --> 00:10:50.321 we're correctly getting the list of songs, 255 00:10:50.321 --> 00:10:52.651 and that's updating as well. 256 00:10:52.651 --> 00:10:55.025 So that's good, everything's now working great, 257 00:10:55.025 --> 00:10:56.794 and you can see that as I was selecting items 258 00:10:56.794 --> 00:10:58.420 in any one odd data listBox, 259 00:10:58.420 --> 00:11:00.331 the corresponding data is displayed 260 00:11:00.331 --> 00:11:02.449 in the linked data listBox, 261 00:11:02.449 --> 00:11:04.764 and I think at this point that's pretty impressive. 262 00:11:04.764 --> 00:11:07.858 So we've taken the basic tkinter listbox 263 00:11:07.858 --> 00:11:10.913 and now created our own scrollable version of it, 264 00:11:10.913 --> 00:11:13.435 and with that extended that further 265 00:11:13.435 --> 00:11:15.026 to produce a data listBox that can 266 00:11:15.026 --> 00:11:17.868 load its own data from a database table 267 00:11:17.868 --> 00:11:21.111 as well as triggering loading in another data listBox. 268 00:11:21.111 --> 00:11:23.905 So the code in the main programme becomes a lot cleaner 269 00:11:23.905 --> 00:11:26.833 and easier to instal as a result of this, 270 00:11:26.833 --> 00:11:28.311 but with that said we've still got a bit 271 00:11:28.311 --> 00:11:30.998 of tidying up to do there in the code 272 00:11:30.998 --> 00:11:32.446 before I end this video, 273 00:11:32.446 --> 00:11:35.339 and I'm just gonna close this down. 274 00:11:35.339 --> 00:11:36.969 Now to start with, we don't need 275 00:11:36.969 --> 00:11:39.843 this get_songs function anymore 276 00:11:39.843 --> 00:11:43.389 'cause that's now all handled by our data listBox class, 277 00:11:43.389 --> 00:11:45.407 and we also don't need to connect to the database 278 00:11:45.407 --> 00:11:47.317 right at the start of the programme. 279 00:11:47.317 --> 00:11:49.375 Now, we did that originally because our functions 280 00:11:49.375 --> 00:11:51.765 were using the global database connexion, 281 00:11:51.765 --> 00:11:53.329 but now that we're passing the connexion 282 00:11:53.329 --> 00:11:55.111 to our data listBox objects 283 00:11:55.111 --> 00:11:57.763 that code can come down to the main programme. 284 00:11:57.763 --> 00:11:59.420 We should also add a condition 285 00:11:59.420 --> 00:12:01.066 so that the main code isn't executed 286 00:12:01.066 --> 00:12:03.481 when the module's imported by another programme, 287 00:12:03.481 --> 00:12:05.407 and that'll then let other programmes 288 00:12:05.407 --> 00:12:08.254 use our scroll box and data listBox classes. 289 00:12:08.254 --> 00:12:09.315 Let's go ahead and do that, 290 00:12:09.315 --> 00:12:12.527 so I'm actually going to delete the get_songs function 291 00:12:12.527 --> 00:12:13.933 because that's existed in quite a few 292 00:12:13.933 --> 00:12:16.685 other versions of the video prior to this, 293 00:12:16.685 --> 00:12:20.250 or videos prior to this, so we don't need to preserve that, 294 00:12:20.250 --> 00:12:22.283 and clean up some of this. 295 00:12:22.283 --> 00:12:24.777 Let's also add that code there 296 00:12:24.777 --> 00:12:26.767 to make sure that the main code 297 00:12:26.767 --> 00:12:28.642 isn't executed when the module's imported. 298 00:12:28.642 --> 00:12:31.892 So if __name__ is equal to '__main__' : 299 00:12:40.092 --> 00:12:41.625 and from there we want to indent the code 300 00:12:41.625 --> 00:12:45.375 but we gotta start by moving this connexion, 301 00:12:46.304 --> 00:12:49.246 I'll comment that out and we'll delete this, 302 00:12:49.246 --> 00:12:51.675 clear up some spaces there, 303 00:12:51.675 --> 00:12:54.926 then I'm gonna come down and put that code in here, 304 00:12:54.926 --> 00:12:58.085 and then we're going to indent this other code, 305 00:12:58.085 --> 00:12:58.980 then go right down to the bottom 306 00:12:58.980 --> 00:13:01.647 and indent all of that, like so. 307 00:13:03.913 --> 00:13:05.663 Now we also were loading data 308 00:13:05.663 --> 00:13:08.350 into the albums and songLists when the programme starts, 309 00:13:08.350 --> 00:13:10.406 and if you recall we did that when testing earlier 310 00:13:10.406 --> 00:13:13.042 but we can now go ahead and delete those lines now. 311 00:13:13.042 --> 00:13:14.895 So in terms of that code you've got 312 00:13:14.895 --> 00:13:17.878 this requery here, firstly for albums, 313 00:13:17.878 --> 00:13:20.276 so let's, I'll just comment that out. 314 00:13:20.276 --> 00:13:22.565 You could just as easily delete that if you prefer. 315 00:13:22.565 --> 00:13:25.669 We've also got another one in the songs, 316 00:13:25.669 --> 00:13:27.606 the songlist.requery, which we no longer need 317 00:13:27.606 --> 00:13:29.142 to have that code there anymore. 318 00:13:29.142 --> 00:13:30.350 But of course we do wanna leave 319 00:13:30.350 --> 00:13:31.853 the original artists in there, 320 00:13:31.853 --> 00:13:33.662 so that all the artists are initially loaded, 321 00:13:33.662 --> 00:13:36.110 so that's good, that's now fixed. 322 00:13:36.110 --> 00:13:37.901 And down here for the main loop 323 00:13:37.901 --> 00:13:39.371 we can also get rid of the testList 324 00:13:39.371 --> 00:13:41.791 and the albumLV.set tuple, 325 00:13:41.791 --> 00:13:44.673 you don't actually want that to be populated either, 326 00:13:44.673 --> 00:13:46.248 so let's actually get rid of that as well, 327 00:13:46.248 --> 00:13:48.138 comment that out. 328 00:13:48.138 --> 00:13:51.196 Which really only leaves the code for the main loop 329 00:13:51.196 --> 00:13:53.534 in printing, the fact that we're closing 330 00:13:53.534 --> 00:13:56.390 the database connexion and then the connection.close, 331 00:13:56.390 --> 00:14:00.557 so let's just run this to make sure that it still works. 332 00:14:04.865 --> 00:14:07.302 So I've now only got the artists populated initially. 333 00:14:07.302 --> 00:14:10.302 We can click on a particular artist. 334 00:14:11.500 --> 00:14:13.775 By the way, we can click on songs as well, 335 00:14:13.775 --> 00:14:16.805 and because that's not associated with any other listBox 336 00:14:16.805 --> 00:14:17.806 we're not getting any errors, 337 00:14:17.806 --> 00:14:20.509 and that's working as well as we think it should be working, 338 00:14:20.509 --> 00:14:22.982 and we're still getting our other selects working correctly 339 00:14:22.982 --> 00:14:26.551 and the various data listBoxes being updated on the screen. 340 00:14:26.551 --> 00:14:30.004 So that's actually it, that's our data ListBox finished. 341 00:14:30.004 --> 00:14:31.689 I think you'd agree that the main program's now 342 00:14:31.689 --> 00:14:33.586 a lot tidier than what it was, 343 00:14:33.586 --> 00:14:35.746 and we haven't got any code copied and pasted, 344 00:14:35.746 --> 00:14:37.169 more to the point. 345 00:14:37.169 --> 00:14:40.911 We've also now got two completely reusable classes 346 00:14:40.911 --> 00:14:42.892 that we can import into other projects 347 00:14:42.892 --> 00:14:44.374 whenever we need a scrolling listBox 348 00:14:44.374 --> 00:14:48.186 or one that can display data from a database table. 349 00:14:48.186 --> 00:14:51.042 Now, there is a bug in the data listBox class, though. 350 00:14:51.042 --> 00:14:51.960 Let's see if you can figure out 351 00:14:51.960 --> 00:14:53.740 and try and spot what that is. 352 00:14:53.740 --> 00:14:56.198 In the next video I'm gonna show you what the bug is 353 00:14:56.198 --> 00:14:59.113 and then set you a challenge to fix that bug, 354 00:14:59.113 --> 00:15:01.444 so I will see you in the next video.