Coding — Unit 1#
The first step of your coding will always be setting up a new development environment. Instead of starting from scratch you will be provided with a code template. This is called boilerplate code in the industry.
Boilerplate development environment#
The Boilerplate for your code is hosted on GitHub, so we will fork this repo and create your own repo
To do this:
Go to the PyQt6 Boiler Plate repo
Click on the green Code button
Click on the copy button beside the https url
Open GitHub Desktop
Open the File menu
Click Clone Repository
Choose the URL tab
Paste repo URL into URL or username/repository box
Click Clone
The repo should now be copied onto your computer and ready for use.
Opening repo in VS Code#
We’re going to use GitHub Desktop to coordinate our programming. We will use it to:
Open our code in VS Code and set up the workspace correctly
Save (commit) our finished code to our local repo
Sync (Push) our committed code up to GitHub (origin)
Git and GitHub terminology
Git and GitHub uses a range of different terminology. Here are some of the terms we will be using:
Repository or repo: A repository is a special folder that stores all the files and their history for a project.
Commit: When you make changes to files in a repository, a commit is takes a snapshot of those changes. Each commit has a unique name and a message explaining what changes were made.
Pull: Pulling means getting the latest changes made by others and adding them to your own copy of the project.
Push: Pushing is when you share your changes with others by sending them to a central place, like a website or server.
Remote: A remote is a way to connect your local copy of the project with the online version. weare using GitHub. It allows you to share your work and collaborate with others.
Clone: Cloning is making a copy of a project from a remote location to your own computer so you can work on it.
Local: the copy of the repo that is on your computer
Origin: the copy of the repo that is on a remote location
Fork: making your own copy of someone else’s project.
Note: the other that you could be working with might be you on another computer.
To use GitHub Desktop to open VS Code:
Open GitHub Desktop
Make sure the Current repository (top lefthand) is PyQt6-Boiler-Plate
Click Open Visual Studio Code
VS Code should now launch and you file panel of the lefthand side should show:
PYQT6-BOILER-PLATE
all the files in the image below
Virtual Environment#
Python virtual environments enables you to designate distinct areas for various Python projects. It’s like having various rooms in your home, each with its unique furnishings and accents. You can work on various projects in a virtual environment without their interfering with one another. Each project gets a special “playground” with its own Python installation and particular libraries. A virtual environment is similar to walking into a specific room, and any Python programmes or libraries you use are exclusive to that project once you enter it. You can easily work on numerous Python projects because everything is kept organised and conflicts between projects are avoided.
requirements.txt
The requirements.txt
file lists all the external libraries that we need to install for this project.
You can add extra libraries to this file, but to install them you will need to run the command:
Windows:
pip install -r requirements.txt
macOS:
pip3 install -r requirements.txt
Create Virtual Environment#
Windows Users
If you are a Windows user, you might need to run a Powershell command before you create a virtual environment for the first time.
To do this:
Open Powershell as Adminstrator
Type the following:
Set-ExecutionPolicy Unrestricted -Force
then Enter
You shouldn’t need to do this again, unless you get a new computer.
To create a virtual environment for this project:
Press
Ctrl
+Shift
+P
(Windows) /Shift
+Command
+P
(macOS)Type
Python
at the top and choosePython: Create Environment...
At the top choose the Venv option
Then choose the latest version of Python that you just installed
Tick the box beside requirements.txt and then ok
VS Code will now:
create your virtual environment
perform any necessary updates
install the libraries in the requirements.txt file
activate your virtual environment
Make first commit and push#
Change the text in README.md to the text below and then save it:
# FIA2 Project
This is my code for my FIA2 Project
In GitHub desktop write “Made first change” in the Summary (required) box
Then click Commit to main
Click Push origin (you will receive an error)
Choose to Fork this repository
Choose For my own purposes and Continue
Click Push origin again
Creating MVC Programs#
In Unit 1 you will be creating a productivity application (desktop app) using the MVC Architecture. The videos below will introduce the concepts behind developing a MVC program using PyQt.
Programming Habits#
The videos below show good Python programming practice.