Nichols and Sense

All Things Coding and CyberSecurity

Let's Wrap It Up

We have finally reached the end of our journey for the ASCII art project. In this post, we will be wrapping all of the code in a GUI to make using our script much easier. To do this, we are going to be using the PyQt module

Below, you can see what our final result will look like.

processing image

So let's get started.


Step 1: Modifying our old code

In order to wrap our existing script in a GUI, we need to make a couple of changes. Our GUI code is going to be long, so it is best if it is seperated into it's own file. This means that we will need a way to import our code from our original script. To do this, we are going to split up the code in our original script into functions that can be imported into other scripts. 

Each function serves a specific purpose which makes it easy to cleanly use it in another script. Once we have split all of our code into unique functions, we can start building the GUI.


Step 2: Creating the GUI

Using PyQt, I created a window that allows you to open any gif and convert it to ASCII. How to specically create a GUI is very complicated and out of the scope of these kinds of posts, but I'll give a brief overview of how it works.  A base window is created, and an ImageLabel widget is added that fills up the entire window. Then menu items, such as "File > Open" are created and added to our window which are then connected to code that open a file dialogue box, where a gif file can be selected and moved into our ImageLable Widget. The Window will now display the gif that you have selected. After doing this, another File option, "File > Convert to Gif" is enabled and clicking this option calls the code from our original script from the previous post. The image is converted to ASCII art in the background while a progress bar displays the progress of the conversion. This progress bar is a custom QObject that runs in a seperate thread and tracks the progress of our conversion. It then emits a signal to our GUI, updating the progress bar what percentage of our frames have been converted. Finally, after the gif has been converted and saved, the Window ImageLabel is updated with our new gif file.


I have moved this code to it's own repository with instructions on how to run it if you would like to try it for yourself.

Source Code