1
00:00:00,210 --> 00:00:08,730
Hi, welcome back in this video, we will program a fire destroyer, so that's a nap, which is useful

2
00:00:08,730 --> 00:00:13,950
if you have sensitive files in your computer, which you really want to permanently delete.

3
00:00:14,910 --> 00:00:19,950
And it's not simply about deleting, but it's about destroying them by overwriting them.

4
00:00:20,250 --> 00:00:30,060
Now, if you follow the course, we did have a lecture where we wrote a script without a graphical user

5
00:00:30,060 --> 00:00:34,050
interface, a jisa script which runs on the command line.

6
00:00:34,200 --> 00:00:43,290
So this script towards idiots is you specifying a folder in that script, for example, destination

7
00:00:43,290 --> 00:00:46,620
is a folder in here which may contain some files.

8
00:00:46,980 --> 00:00:52,770
And so the script then eight reads over that path object.

9
00:00:53,220 --> 00:01:04,080
So for path in that directory, it filters all the CSC files and then it opens each of that path, file

10
00:01:04,080 --> 00:01:11,880
path, and then it overrides an empty bytes string into that file.

11
00:01:12,000 --> 00:01:19,800
So basically, each file will be overwritten with some empty contents, and that's makes the file hard

12
00:01:19,800 --> 00:01:25,500
to recover if somebody else gets your computer and they try to recover your hard disk.

13
00:01:25,650 --> 00:01:29,790
Previous content because the file will be overridden by Python.

14
00:01:30,000 --> 00:01:33,990
And then finally, with the lead, that overwritten file.

15
00:01:34,530 --> 00:01:36,630
So first we overwrite, and then we deleted.

16
00:01:37,290 --> 00:01:45,930
This is a script that does this, but now we want to take this one step further and build a graphical

17
00:01:45,930 --> 00:01:46,950
user interface.

18
00:01:47,310 --> 00:01:52,920
So this is what we have built and this video and it has this description here.

19
00:01:52,920 --> 00:01:54,480
Select the files you want to destroy.

20
00:01:54,780 --> 00:01:59,370
And it was the user that the files of the permanently deleted.

21
00:01:59,820 --> 00:02:05,100
And then it has these two buttons over files, which shows you a file dialog.

22
00:02:05,970 --> 00:02:10,620
So here you can select multiple files that you want to delete.

23
00:02:10,740 --> 00:02:15,690
For example, these three open them and the program.

24
00:02:15,690 --> 00:02:22,740
The cooee will display the paths of those files in here, and then you can see destroy files and this

25
00:02:22,740 --> 00:02:30,480
destruction successful string shows up in here and the files will disappear from that folder so they

26
00:02:30,480 --> 00:02:34,080
will be overridden by Python and then deleted.

27
00:02:34,440 --> 00:02:36,090
So let's run this program.

28
00:02:37,020 --> 00:02:39,030
We will use PI two six.

29
00:02:39,040 --> 00:02:46,350
So if you have any solid, please do so with Pi Q to six people.

30
00:02:46,420 --> 00:02:48,860
Install Pi two two six seven.

31
00:02:48,870 --> 00:02:51,430
I'm going to use this code.

32
00:02:52,560 --> 00:02:55,950
So we did sort of write this code previously.

33
00:02:56,220 --> 00:02:58,650
And this creates an application instance.

34
00:02:58,650 --> 00:03:05,010
It creates a window instance as well, which is where all the widgets will be added to the buttons of

35
00:03:05,010 --> 00:03:07,020
the labels of text.

36
00:03:07,020 --> 00:03:10,810
So whatever you add to your main window of your green.

37
00:03:10,980 --> 00:03:12,990
So we said the title for the window.

38
00:03:13,860 --> 00:03:23,970
Oh, we also need a layout which is equal to Q the box layout, and you need to import that in here.

39
00:03:24,690 --> 00:03:27,930
Cuvee box layout.

40
00:03:29,010 --> 00:03:30,600
So we set then.

41
00:03:32,130 --> 00:03:36,210
That's the layout and use parentheses here as well.

42
00:03:36,660 --> 00:03:41,850
And then we said that layout as the main layout of the window will show the window and then we execute

43
00:03:41,850 --> 00:03:47,640
the app instance so that it generates our application.

44
00:03:50,170 --> 00:03:54,460
So currently, this is our winter looks like it has this title.

45
00:03:55,270 --> 00:03:58,030
And so we are ready to add widgets now.

46
00:03:58,300 --> 00:04:07,090
So we said that first we're going to have you're on top a label, so let's add a label for that.

47
00:04:07,210 --> 00:04:11,080
We need to label the Q label widgets.

48
00:04:13,960 --> 00:04:22,480
Let's say description is a sequel to Q label, and then we add some info here, which goes inside quotes,

49
00:04:22,480 --> 00:04:29,200
so it's a string using single quotes here and I'm going to paste the string, which I wrote previously.

50
00:04:30,160 --> 00:04:35,680
So what this is is select the fast you want to destroy.

51
00:04:35,680 --> 00:04:44,200
I'm telling the user what the app is about and how they can use it, and then the files will be permanently

52
00:04:44,410 --> 00:04:52,930
deleted and permanently is in red phones so you can use these simple tags as you see in here.

53
00:04:53,800 --> 00:04:56,200
So red's a acing double quotes.

54
00:04:56,210 --> 00:05:00,530
That's why I use single quotes for this since I was using double quotes.

55
00:05:00,800 --> 00:05:09,850
So the string, once you have created the label object, then you want to add the label to layout.

56
00:05:10,120 --> 00:05:16,660
So layout that at widgets and description is the label, and let's see what we have.

57
00:05:17,910 --> 00:05:21,300
Yeah, so that's the label and permanently is in red color.

58
00:05:21,870 --> 00:05:29,070
So as we develop this program, I'm going to introduce you to advanced concepts of PI cutesy, such

59
00:05:29,070 --> 00:05:35,490
as this styling of texting here, and we have more and more concepts to discover in this video.

60
00:05:35,910 --> 00:05:38,020
So let's add more widgets.

61
00:05:38,100 --> 00:05:39,180
What's next?

62
00:05:40,140 --> 00:05:41,640
Well, it has to be a button.

63
00:05:41,940 --> 00:05:45,780
So let's say open beta and a sequel to Q.

64
00:05:47,070 --> 00:05:50,070
Well, we need to import the button.

65
00:05:51,030 --> 00:06:01,910
So let's not have that line infinitely long and have another import statement here from public six.

66
00:06:01,920 --> 00:06:03,210
That's cutesy widgets.

67
00:06:03,210 --> 00:06:05,790
Import queue push button.

68
00:06:06,890 --> 00:06:13,940
Q push button goes there, and the title of the button will be open files.

69
00:06:16,930 --> 00:06:23,770
Adverts, bots and to layouts using and widgets open bottom tested.

70
00:06:25,070 --> 00:06:25,850
Yeah, is there?

71
00:06:26,150 --> 00:06:26,440
No.

72
00:06:27,020 --> 00:06:36,740
If you want to add a tip option feature to this bottom, you can do so because currently, as you see,

73
00:06:36,740 --> 00:06:41,030
when I offer the mouse over the button, I don't see any info popping up.

74
00:06:41,210 --> 00:06:50,030
So if you want to have that, then you want to refer to the variable associated to your button object

75
00:06:50,030 --> 00:06:53,300
and then say sets to tip.

76
00:06:58,700 --> 00:07:04,160
And you can use the same string open files and run.

77
00:07:04,730 --> 00:07:10,040
So if I hover the most button, here you see this small prompt open file.

78
00:07:10,400 --> 00:07:16,820
This could be useful, especially when you have icons instead of buttons with text so icons don't have

79
00:07:16,820 --> 00:07:24,710
labels, and it becomes very crucial to have these popups so that the user can see what these icons

80
00:07:24,710 --> 00:07:25,280
are in bold.

81
00:07:25,670 --> 00:07:30,760
However, this is not an icon is just a button with plain text.

82
00:07:30,770 --> 00:07:36,470
So perhaps this is not necessary in this case, but it's just there so that you know that this exists.

83
00:07:37,310 --> 00:07:40,850
And do you want to make the button maybe smaller?

84
00:07:41,210 --> 00:07:48,530
Well, you can do that by referring again to the bottom and then you set fixed width.

85
00:07:49,820 --> 00:07:55,340
So with that, let's say 60 and run.

86
00:07:56,990 --> 00:07:59,060
So it's too small.

87
00:08:00,460 --> 00:08:04,420
Perhaps a hundred so this.

88
00:08:07,240 --> 00:08:07,630
Run.

89
00:08:08,910 --> 00:08:12,870
Now it looks better, so try to experiment with other sizes.

90
00:08:14,010 --> 00:08:20,010
And let's also align the button to be the center of the window for that, you can use alignment equal

91
00:08:20,010 --> 00:08:31,440
to so alignment inside the ads widget method that will be equal to cutesy alignment and cutesy is something

92
00:08:31,440 --> 00:08:37,950
that needs to be imported from pie cute six dot cuticle import.

93
00:08:40,799 --> 00:08:46,440
So alignment flag and that's a center property.

94
00:08:48,150 --> 00:08:51,030
Varun and the botanist of the Sentinel.

95
00:08:52,170 --> 00:08:52,440
Right.

96
00:08:52,450 --> 00:08:54,360
So what does this button do?

97
00:08:55,320 --> 00:08:59,430
Well, that's connected to a slots, which will be a function of that.

98
00:08:59,430 --> 00:09:02,760
We will do right on top here.

99
00:09:03,810 --> 00:09:08,190
So to connect the button, you should refer to the button.

100
00:09:08,850 --> 00:09:13,590
So we're talking about doing something when the button is clicked.

101
00:09:14,220 --> 00:09:19,530
So open button that's clicked, then we connected to a function.

102
00:09:19,830 --> 00:09:24,780
So when the button is clicked, this function now will be cold.

103
00:09:26,330 --> 00:09:30,560
Let's name this function open files and then define that function.

104
00:09:30,570 --> 00:09:32,490
Open files in here.

105
00:09:34,350 --> 00:09:42,090
And so what should the app do when we press the open files button?

106
00:09:42,600 --> 00:09:49,710
When the user presses that button well, the app should open a dialog box that allows the user to select

107
00:09:49,710 --> 00:09:53,970
files on their file system on their operating system.

108
00:09:55,200 --> 00:10:04,110
So for that, we need something called Q File dialog, and so you need to import that.

109
00:10:08,030 --> 00:10:13,160
And here and then create that object instance.

110
00:10:13,970 --> 00:10:21,500
So for that, I'm going to say file names and just another score.

111
00:10:21,620 --> 00:10:28,190
So we have two variables here, and these two variables are equal to Q file dialog.

112
00:10:29,180 --> 00:10:33,260
I'm having two variables because this returns to objects.

113
00:10:33,920 --> 00:10:37,640
The first object is a list of file names.

114
00:10:37,970 --> 00:10:45,950
So if the user selects three files than a list will be generated containing the absolute paths of all

115
00:10:45,950 --> 00:10:48,200
those files of each of those files.

116
00:10:48,710 --> 00:10:54,440
And then we have this, which is some extra information about the dialogue action, which we don't need.

117
00:10:54,440 --> 00:11:01,250
So it's we just leave it as an underscore, which is just a variable, but it's just a throwaway variable.

118
00:11:02,170 --> 00:11:03,990
So queue file dialog.

119
00:11:04,010 --> 00:11:11,360
Actually, we need to call the get open file names of that class.

120
00:11:12,810 --> 00:11:20,220
The first argument will be the window, a window is the variable that contains a cue widgets object

121
00:11:20,940 --> 00:11:25,230
and then you won't specify a label for the dialog window.

122
00:11:25,890 --> 00:11:29,190
Let's say select files, and that's it.

123
00:11:29,340 --> 00:11:36,600
Now, just to show you what file names is, I'm going to print it out on the terminal and then I'll

124
00:11:36,600 --> 00:11:39,150
select some files, not through the green.

125
00:11:40,860 --> 00:11:45,840
But first, make sure you have some sample files that you want to destroy.

126
00:11:46,320 --> 00:11:53,160
So open your file explorer, perhaps put some simple files which you don't need there.

127
00:11:53,340 --> 00:12:00,120
So putting one here, one file, I'm going to just duplicated copy and paste control of reconstruct

128
00:12:00,140 --> 00:12:01,740
the make several copies.

129
00:12:01,920 --> 00:12:10,470
So you have some files to to play around with and then run the code and open files.

130
00:12:10,800 --> 00:12:12,930
The dialog will appear.

131
00:12:13,140 --> 00:12:15,780
Go to the folder where you have those files.

132
00:12:16,080 --> 00:12:18,660
Those sample files and selects.

133
00:12:19,020 --> 00:12:21,810
A couple of them open.

134
00:12:23,360 --> 00:12:33,320
And now when you pressed the open button on the terminal, I got a list printed out of the lease has

135
00:12:33,320 --> 00:12:42,140
three items and each item is the absolute path to each of those files that we selected in the dialog

136
00:12:42,140 --> 00:12:42,530
box.

137
00:12:43,830 --> 00:12:51,180
So that gives us snow, the possibility to manipulate and lead those files.

138
00:12:52,690 --> 00:12:58,780
So for that, I'm going to write here a loop for file name and file names.

139
00:12:59,980 --> 00:13:02,710
And I prefer to use the path library.

140
00:13:02,920 --> 00:13:05,470
So from path lib.

141
00:13:05,500 --> 00:13:06,610
It's a standard library.

142
00:13:06,610 --> 00:13:09,310
You don't need to install its import path.

143
00:13:09,760 --> 00:13:14,170
So I'm going to convert each file name into a path object.

144
00:13:14,380 --> 00:13:21,160
A path is a specialized object in Python, which makes dealing with files more efficient.

145
00:13:21,580 --> 00:13:23,800
So path is legal to path.

146
00:13:24,550 --> 00:13:25,320
That's class.

147
00:13:25,330 --> 00:13:27,280
And then we provide file name here.

148
00:13:27,790 --> 00:13:33,640
That's file name, which in the first loop will be that first string.

149
00:13:33,760 --> 00:13:39,610
So file name is just a string and file name goes inside the path and it becomes like path object now,

150
00:13:39,620 --> 00:13:40,570
not a string.

151
00:13:42,250 --> 00:13:53,770
So and then we say with open path, that's current path object, we open, it's as a right binary and

152
00:13:53,770 --> 00:13:54,970
we say as file.

153
00:13:55,390 --> 00:13:59,500
So file now is an open file in Python.

154
00:13:59,680 --> 00:14:02,260
It's a specific file object.

155
00:14:02,500 --> 00:14:05,320
So we have a string in file name.

156
00:14:05,320 --> 00:14:09,880
We have a we have a path object in path and we have a file object in file.

157
00:14:10,240 --> 00:14:15,310
And this file we can write a bytes string.

158
00:14:15,670 --> 00:14:19,300
So the file is open now and we can modify it with Python.

159
00:14:19,510 --> 00:14:26,590
So what we do is write a bi string there and that will overwrite whatever content the file has inside.

160
00:14:26,860 --> 00:14:31,990
So that's like modifying the file and the previous content is just lost.

161
00:14:32,290 --> 00:14:36,790
So that's a very safe deletion of your sensitive files.

162
00:14:37,810 --> 00:14:42,160
So with that, you write the file, so you modified.

163
00:14:42,990 --> 00:14:52,840
Then if you want to delete that overwritten file, you can do so by using a first, you have to on indent.

164
00:14:53,710 --> 00:14:56,710
So the file will be saved on disk at that point.

165
00:14:57,160 --> 00:15:03,410
And then if you want, you can save Path Dot on a link to delete the file.

166
00:15:03,430 --> 00:15:06,880
The Unlink method will delete that path.

167
00:15:07,750 --> 00:15:11,140
So the file associated with that path object.

168
00:15:12,720 --> 00:15:14,700
So let me try to run the code.

169
00:15:20,470 --> 00:15:29,200
And then click on open files, go to the Files Directory, where I have these files, I'm selecting

170
00:15:29,200 --> 00:15:32,890
a two, three and four and press on open.

171
00:15:34,270 --> 00:15:43,840
So with that, if I go to this directory now, I see that files two, three and four are gone.

172
00:15:44,020 --> 00:15:46,240
So they are overwritten and then deleted.

173
00:15:46,720 --> 00:15:54,880
But this is not the best user interface because I think we are missing a button here.

174
00:15:55,210 --> 00:16:02,170
So if you run the program again, the best user experience is that the user first should open the files

175
00:16:03,220 --> 00:16:05,830
so they select the files they want to delete.

176
00:16:06,130 --> 00:16:12,040
And then here should be another bottom that should they should say something like destroy the files

177
00:16:12,340 --> 00:16:18,520
and then bots and should execute this part of the code, not the open files button.

178
00:16:19,720 --> 00:16:25,650
So what we need is another bulletin under the open button.

179
00:16:27,190 --> 00:16:33,880
So let's say destroy button between a sequel to Cute.

180
00:16:35,940 --> 00:16:45,660
Push a button, and let's name this this trolley files, let's it's a width four, that's a swirl and

181
00:16:45,660 --> 00:16:47,880
puts it at the center here.

182
00:16:48,180 --> 00:16:56,460
And then finally, make sure you change these from open button to destroy bottom.

183
00:16:56,700 --> 00:16:59,160
And also here destroy button.

184
00:17:00,720 --> 00:17:07,260
And then finally, you referred to destroy boats and to collect to connect.

185
00:17:07,800 --> 00:17:10,560
And we want to connect that to another function.

186
00:17:11,099 --> 00:17:14,339
Let's say this throwing files.

187
00:17:14,730 --> 00:17:15,990
This is a new function.

188
00:17:16,290 --> 00:17:23,400
We need to write somewhere in here define destroy files.

189
00:17:26,180 --> 00:17:28,160
And then this code.

190
00:17:29,740 --> 00:17:39,700
Is transferred to this function so that this code executes when the user presses that destroyed button.

191
00:17:40,060 --> 00:17:41,680
But we have a problem here.

192
00:17:42,100 --> 00:17:50,710
File names is a variable defined inside this function and that makes the that's the variable local.

193
00:17:50,890 --> 00:17:54,250
So it only has a scope inside this function.

194
00:17:54,580 --> 00:18:01,930
It will not be recognized outside of that function unless we declare that as a global variable.

195
00:18:03,250 --> 00:18:10,240
Now, using global, so making variable global in Python is not the best practice.

196
00:18:10,630 --> 00:18:18,970
And this could cause some issues later on when you expand your program unless you are very, very careful

197
00:18:18,970 --> 00:18:20,140
with what you're doing.

198
00:18:20,440 --> 00:18:22,030
And you can avoid those problems.

199
00:18:22,030 --> 00:18:28,660
But the best practice to avoid using global variables is to use object oriented programming.

200
00:18:28,960 --> 00:18:37,300
So to structure your programs using classes and you can do that with Piketty, so you can use classes

201
00:18:37,570 --> 00:18:44,950
and you can write the same program using classes and avoids using globals because inside that class,

202
00:18:45,280 --> 00:18:50,420
you can use instant variables instead of global variables.

203
00:18:50,440 --> 00:18:54,040
And that would solve the issue with not having to use global variables.

204
00:18:55,300 --> 00:18:57,850
So that's something you should know about using global.

205
00:18:59,110 --> 00:19:04,510
With that in mind, let's keep our current structure without going to object oriented programming.

206
00:19:05,440 --> 00:19:07,810
So this will do the job just fine.

207
00:19:08,980 --> 00:19:14,650
So by doing global file names, that means the final names can be accessed now from other parts of the

208
00:19:14,650 --> 00:19:17,950
court and not only inside from inside this function.

209
00:19:21,040 --> 00:19:23,010
So let's try to run the code again.

210
00:19:25,430 --> 00:19:27,740
Ron, Maine, now we have this button here.

211
00:19:27,980 --> 00:19:29,780
So first, we want to open files.

212
00:19:32,510 --> 00:19:36,380
Let's select five and six open.

213
00:19:38,350 --> 00:19:40,960
Press on destroy and check.

214
00:19:42,700 --> 00:19:44,320
If fires are still there or not.

215
00:19:44,470 --> 00:19:47,290
Yeah, so they are destroyed five and six.

216
00:19:48,610 --> 00:19:59,560
We can do more by adding a label under the lost bolts in here so that we let the user know what's going

217
00:19:59,560 --> 00:19:59,770
on.

218
00:20:00,190 --> 00:20:06,280
So what I'll do is I'll go down here and at.

219
00:20:09,670 --> 00:20:17,950
A message valuable, which a sequel to Q label cannot of this will be empty, and I'll add this to the

220
00:20:17,950 --> 00:20:18,310
layout.

221
00:20:18,310 --> 00:20:27,770
So now that the widget's message of I'm in here was the user opens the file instead of printing all

222
00:20:27,790 --> 00:20:30,430
the files and the file names on the terminal.

223
00:20:30,820 --> 00:20:43,270
I want to print them out all that's labeled so message dot set text and then you want to enter file

224
00:20:43,270 --> 00:20:50,740
names, notes file names because file names, as currently you know, it's an it's a full list which

225
00:20:50,740 --> 00:20:54,670
looks something like that A, B and C and so on.

226
00:20:55,390 --> 00:20:59,740
So a list cannot be accepted by the set text method.

227
00:21:00,220 --> 00:21:05,920
So what we want to do instead is we want to see him join.

228
00:21:06,940 --> 00:21:14,200
So I string that join the file names and what we do we want to join them with.

229
00:21:14,650 --> 00:21:22,660
You can see a dash, for example, and you'll get something like that, a Dash B or you can do better

230
00:21:22,660 --> 00:21:26,920
and see backslash, which creates a brake line.

231
00:21:28,030 --> 00:21:35,950
Well, here on the terminal, it doesn't look like a brake line, but if you printed out on on a label

232
00:21:35,950 --> 00:21:40,090
widgets or use a print function here, then you will see that.

233
00:21:40,450 --> 00:21:42,490
So it will be a brake line.

234
00:21:42,490 --> 00:21:49,150
So Max, listen, now you see, that's a one line, and then we have the brake line, which connects

235
00:21:49,480 --> 00:21:55,900
the two so backslash and is converted into a brake line when you use a print function or when you print

236
00:21:55,900 --> 00:21:56,860
it out on a label.

237
00:21:57,850 --> 00:22:03,130
So that means we should say backslash and dot join.

238
00:22:03,310 --> 00:22:08,770
So join all the elements or file names using that separator.

239
00:22:10,120 --> 00:22:13,090
And then in here we exit the loop.

240
00:22:13,450 --> 00:22:14,950
So in this?

241
00:22:16,170 --> 00:22:27,060
Place in here in the same indentation label with a for loop, and that's a message that sent text destruction

242
00:22:28,050 --> 00:22:31,410
successful and run.

243
00:22:33,280 --> 00:22:37,900
So open files and select a few files.

244
00:22:41,730 --> 00:22:48,480
Seven, eight, nine using the shift, and so these are the files that were selected.

245
00:22:50,130 --> 00:22:54,540
And you press on destroy files and you have Vats labeled destruction successful.

246
00:22:54,990 --> 00:23:01,530
You can put the label more on the censor by using alignment.

247
00:23:01,980 --> 00:23:09,140
A sequel to Kutty, that alignment flag, that's a line censor and that should solve the issue.

248
00:23:10,900 --> 00:23:11,830
So open files.

249
00:23:17,020 --> 00:23:19,400
And now the label is at the center.

250
00:23:20,580 --> 00:23:22,980
So that concludes this video.

251
00:23:25,230 --> 00:23:28,020
Thanks a lot for falling and to see you in the next videos.

