In yesterday's bonus example, we built a zip creator program.
Today we're going to do the opposite.
We're going to create a program which extracts.
A zip file to a destination directory.
So this will be a new program and therefore, I want to take advantage of this opportunity to explain
once again the steps of building any program.
And so we're going to go through these four steps in this video.
So if your ideas were scattered before, you didn't know where to start.
This video will make sure that.
You have a clear understanding of where to start a program and how to finish it.
So let's start with the first point designing the front end.
Now, this can mean different things.
If it's a simple program, you can just use a piece of paper where you make a drawing how your app front
end will look like.
If it's a more complex program, you can use software such as Figma, which will cover later on.
So Figma is a software which allows you to create designs for your apps before you build your apps.
Usually you create a design for graphical user interfaces, which could be desktop apps as the one we're
building.
All web apps also.
Later on, we're going to build web apps in the course.
So usually you don't do this if it's just a command line interface.
That's because graphical user interfaces are more involved.
So it's good to have some drawing beforehand before we go ahead and build the actual interface with
Python.
So in our case, the program would look.
Something like this.
Here we have the default buttons of any window to close, minimize and maximize the window.
So these are created by default, by by simple QE.
And then in this area here, we have the title of the window.
Such as archive extractor.
Then we're going to have a label select archive.
The input box.
And the button.
Choose.
Another label select.
Destination directory.
Another input box and the button choose.
So what we have here is the input box where the path of the archive of the zip file is going to be placed.
So we choose the file using that button and the path of that file will be rendered here as text in this
input box.
That's a common practice when you pick files using a file picker.
Such as.
This button here, the same we have here.
But in this case, this will be a directory.
This will be the directory where the files of the zip file will be extracted.
So again, we have an input text.
And a folder browse button.
So that is a file browse button.
And that is a folder.
Browse button.
And finally, we need to give the user an extract button down here as well.
And that's it.
So that's the front end.
So the next step then, is to code the front end.
So you might want to keep the design open somewhere while you do the coding part.
So I'll just keep it here and then create a new bonus.
$18 p file.
So that's the file.
It's in my bonus folder and I'm going to import P was simple.
So I'm going to be quick with this app.
I'm not going to type in all the code because we already did most of these codes in the previous app
yesterday in bonus examples where we build the zip, create a program.
So you know what this code does.
So we set the theme of the program as black, so as is possible with the module, and then I'm going
to create the widgets in here.
So there we go.
We have a label, the first label Select Archive, which is going to create this label here.
And the next to select archive, we're going to have the input box.
So that creates the input box and then the choose button, the first button which is a file browse.
Yesterday we had.
I files browse.
You see, it's plural files.
Today we have file.
That is because today we only want to select.
We only want to let the user select one zip file only.
Yesterday we wanted the user to select multiple files if they wanted, so all those files would be put
in a zip file.
But now we want to let the user just select one file, not more.
In that case, we use file instead of files.
Right.
So those were the widgets of the first row.
And then we're going to have the widgets for the second row.
So I'm going to place them in here.
We have the label, select this directory, this one here, and then we have the input box.
And then next to that we have the Choose button, which is going to be a folder Browse.
For instance.
So with that name choose and we have the key for that button and we have the key for that other button
as well.
Archive for this folder for this.
So later on we can refer to this to get the actual paths of the files.
And lastly, we're going to have the last row.
So that is a strong button, this one in here.
And next to the button we're going to display the text extraction was successful.
So that means.
There will be a second stage of the interface.
Where are we going to show here?
Obstruction.
Completed or something like that.
So for that we have a text widget which doesn't have a label, so it's an empty string.
It does have a key and it does have a color for the text, but currently by default it is an empty field
as you see in this first interface here in the first design.
And once we have created the widgets and we store those widgets in variables so we can create the window
instance with that window.
That's the title of the window, which corresponds to that.
And then we have the layout argument, which is a list of lists.
So the list has lists inside, and each inside list represents a row.
So we have the label, the input one, choose button one, which will create that first row and then
the second row of the interface and then the last row where the extra button is and the output label,
which by default is empty.
So we are about to complete step number two.
All we have to do is just read the window and then apply window dot close and then run the program and
see how it will work out.
So that's an interface.
It looks similar to the one we designed.
So that's complete code in the front end.
So design the front end and code the front end are completed.
Now we work on the back end.
So step number three.
For the back end.
As I have explained to you before, it's good to create a separate file.
So under bonus where Bonus 18 is in the same directory I want to create.
A zip.
Extracted that P file.
We're going to use the zip file standard module.
So you don't need to install that module and we need a function extract archive.
So in our program we get as input the archive path and also we get us input the.
Path of destination directory where the files will be extracted.
So that means the function also will need to parameters.
File path or archive path.
Let's say archive path.
And destination directory.
So the next question is, what do we do with these?
Well, we're going to get that file and we're going to extract it in that directory.
So for that, we need to use with zip file that zip file.
Archive path.
So here goes the archive file and then the second argument of the zip file.
It's read before we use roids.
When we want to create a zip file, we use the right arguments.
But when you want to see the contents of the zip file, then you want to read that zip file.
Therefore, we use reads for that.
So that would be as archive.
Perhaps this is just a variable name, so don't confuse archive with archive path that those are two
different names, different variables.
The first one represents the path and the second one represents the actual file object.
A file entity, not a file path.
A file has a path, but they are not the same.
And then we point to that file to that zip file, and then we point to extract all.
We extract everything in the destination directory.
That's it.
So now we are almost done with the back end with a third step here.
But we also need to test this function before we go to the next step, finishing up, which is going
to be connecting the front end to the back end.
So first, let's make sure that this backend works for that we need to use if.
Name is equal to main.
So double underscore.
Double underscore, double underscore, double underscore.
So this, as I explained before, this allows us to.
Run the script as the main script like this and get that output so this function will not be called.
When the file is imported as a script, as a module in the other main file.
Bonus 18.
So this is only executed when we run the script now.
Okay.
Excellent archive.
Let's give some.
Directory.
So in my.
Bonus directory where this zip extracted file is.
I have this compressed zip.
File.
So please download the compressed zip file from the lecture resources.
And put it in the same directory with your zip extractor and your bonus.
18.
Files.
But if you want, you can use your own zip files if you have something.
So in my case it will be compressed with double s dot zip.
So that has to reflect the actual file name.
Exactly.
And the destination directory
is going to be an existing directory.
For example, I have this file directory which is inside bonus, but this can be any directory.
However, it's important that you give.
The actual absolute path of that directory.
So in my case, I want to go to right click and copy path reference and I want to copy the absolute
path and then I want to provide tier that absolute path which I copied.
So that's absolute path.
And it's a good idea to actually use absolute faith for compressed zip as well, because these paths
are also going to be absolute paths in the gooey interface.
So for compress as well, I can right click copy path, reference, absolute path, and then replace
that with the absolute path.
And I'll split here because the line is too long.
So I'm calling the function and I expect that to the files will be extracted in this file directory.
So let me run.
Zip extractor.
Yeah.
There we go.
A the text.
Be the text and see the text.
These were the files that were inside that compressed.
That zip archive.
So these are just empty files, but it's working.
And that completes step three.
And we move on to step number four, finishing up.
What does this mean?
Well, this means connecting everything together and completing the program.
So it means connecting the front end to the back end, because currently the front ends.
Is just a static program which doesn't do anything.
Therefore, we want to.
Bring it to life using a while.
True loop.
So.
We store events and values in windows that read window that close to its outside lets print event and
values to see what we actually get.
So Ron Bones, 18, choose the archive.
So that should be the presidency file.
It can be anywhere in your computer and the directory also can be anywhere.
So I'll just choose this directory.
And if I press an extract now, I'm going to see that I've got extract as a value of event.
And then this dictionary.
So the dictionary has this archive key with its value.
The value is this one in here, so that the value is a string, one single string, and it represents
the path of the zip file, the absolute path.
And we also have the folder key and its value.
And its value is the absolute path of the destination directory.
So in other words, archive path is stored in values.
What was the key again?
It was archive.
Yes.
Which corresponds to that.
And so that is the archive path and the destination directory path is values.
Was it folder?
Yes.
Folder.
So now we are storing that string in here and that string in here.
That's allows us to.
Call the extract archive function, which underlines in red because we need to import it from.
Zip extractor imports.
Extract.
Archive.
And then we use the function and we pass archive path as the first argument and test directory as a
second argument.
So that value goes in here and that value goes in here.
So these two strings are going to be used in here and the function will do its job.
And then lastly, we want to point to window outputs that hidden label and updated.
By setting its value to.
Extraction completed and let's run.
Select archive that will be.
The president zip file select destination directory that is going to be this directory extract extraction
completed so I can check.
Dest.
And these are the three files they were extracted in that destination directory.
And that is a complete.
Codes for this app.
And that's also the steps we took.
To create this app.
So basically, these are the steps for any app that you want to create.
So start with designing the front end.
It's good to know what the user will see first because that could also define what we do in the next
steps.
So the user is important because you are creating the programs for the user, so you want to satisfy
the user's needs.
That's why it is important to have the design first and then we call the frontend and then you call
the backend and then you connect everything up.
So thanks a lot for following this.
I'll see you later.