PyQT Project: Tea Timer


I love tea.

My morning routine includes having a nice cup of black tea with lots of half n half.  When I was working in the office I would make a stop at a Tim Hortons on my way in for a medium steeped tea with double cream to go with my breakfast sandwich.  Lately I have been getting into coffee, but my love is for tea.  My tastes range from a nice Yorkshire Gold to a cheap Lipton.  Sometimes a cup of green tea is all I need, or at night I'm drinking an herbal with chamomile to relax.  When I am sick I turn to an herbal of lemon ginger to settle my stomach, and I like to have a cup of Bubbla/Boba tea a couple times a month.

I'm not picky when it comes to how long I steep my brew.  Sometimes I steep it for a couple minutes, or up to almost 5 if I want something stronger.  (And sometimes even longer if I forget my tea is sitting on the counter.)  Using a single-setting electric kettle means I am not picky about brewing temperature either.  However, there is in fact a set of guidelines for how long and how hot to brew tea depending on the type.  This is a chart I got from https://www.thespruceeats.com/tea-brewing-times-and-temperatures-1328730 that shows just the ideal temperatures and times.

Tea Brewing Times and Temperatures

Tea TypeCelsiusFahrenheitBrewing Time
White Tea65-70ºC150-155ºF1-2 min.
Green Tea75-80ºC165-175ºF1-2 min.
Oolong Tea80-85ºC175-185ºF2-3 min.
Black Tea100ºC (boiling)210ºF2-3 min.
Herbal Tea100ºC (boiling)210ºF3-6 min.

Using this information, I am creating a desktop app for those who do care how long and how hot to steep their tea.

The basic features of this program will be:

  •  Functions for each tea type.
    • Tea name.
    • Recommended brewing temperatures in Celsius and Fahrenheit.
    • Recommended brewing time.
  •  Radio buttons to switch between tea types.
  •  A timer which gives noise alert when tea is done.
  •  Fun facts and quotes about tea.
The language used will be Python and the PyQT library, specifically Pyside6, and will be built using PyCharm.  I first attempted to use QT Designer for this, but after some frustrations with getting QT Designer to work I decided to just write the code by hand.

My code as of this date so far includes of course the imports:
import sys
from PySide6.QtWidgets import QApplication, QMainWindow, QWidget, QRadioButton, QGridLayout, QPushButton
A stylesheet for displaying the background image, which I found on https://unsplash.com/ (This site is fantastic if you need free images for personal projects):
# Where we display the background image.
stylesheet = """
QMainWindow {
background-image: url("C:/Users/Stars/Pictures/References/teamug2.jpg");
background-repeat: no-repeat;
background-position: center;
}
"""
The main class where the GUI gets built:
# Setting up the GUI
class TeaTimer(QMainWindow):
def __init__(self):
QMainWindow.__init__(self)
self.setWindowTitle("It's Tea Time!")
self.setFixedSize(600, 400) # width, height
self._centralWidget = QWidget(self)
self.setCentralWidget(self._centralWidget)

layout = QGridLayout(self._centralWidget)

# Need to squish all this together so it looks nicer
layout.addWidget(QRadioButton("Black"))
layout.addWidget(QRadioButton("Green"))
layout.addWidget(QRadioButton("White"))
layout.addWidget(QRadioButton("Oolong"))
layout.addWidget(QRadioButton("Herbal"))

self.setLayout(layout)
Function outlines for each tea type:
# Make the functions for the different tea types
def blacktea():
"""
celsius_temp = 100
fahrenheit_temp = 210
min_time = 2 # In minutes
max_time = 6 # In minutes
:return:
"""
pass

def greentea():
"""
celsius_temp_min = 75
celsius_temp_max = 80
fahrenheit_temp_min = 165
fahrenheit_temp_max = 175
min_time = 1 # In minutes
max_time = 2 # In minutes
"""
pass

def whitetea():
"""
celsius_temp_min = 65
celsius_temp_max = 70
fahrenheit_temp_min = 150
fahrenheit_temp_max = 155
min_time = 1 # In minutes
max_time = 2 # In minutes
"""
pass

def oolongtea():
"""
celsius_temp_min = 80
celsius_temp_max = 85
fahrenheit_temp_min = 175
fahrenheit_temp_max = 185
min_time = 2 # In minutes
max_time = 3 # In minutes
"""
pass

def herbaltea():
"""
celsius_temp = 100
fahrenheit_temp = 210
min_time = 3 # In minutes
max_time = 6 # In minutes
:return:
"""
pass
And the main area to call the window:
if __name__ == "__main__":
app = QApplication([])
app.setStyleSheet(stylesheet)
window = TeaTimer()
window.show()
sys.exit(app.exec())

What my program looks like put together is this:

Meh.

We have radio buttons, but the layout for them needs some work.  With the way they are called now it just extends down the left side, which does not look good.  My plan is to use QGroupBox to organize not only these buttons, but also the timer, information, and the fun facts/quotes into separate areas.  Those radio buttons need to go on the top left above that tea mug.  Selecting one of those buttons will change what shows up on the right side, with the brewing information on top, the timer in the middle, and the facts/quotes down below.  My main resource for the QGroupBox idea has come from the main PyQT site here: https://doc.qt.io/qtforpython/examples/example_widgets_layouts_basiclayouts.html  Once I get the boxes to look better I will start connecting the functions to their respective buttons.

Updates to follow.  In the meantime, enjoy your tea.

Comments

Popular posts from this blog

So...what is this blog for?