Skip to content

Commit 3282835

Browse files
author
Neagu Marinel
committedJan 29, 2024
Add the new app, clock_alarm
1 parent 45fb08f commit 3282835

File tree

6 files changed

+77
-30
lines changed

6 files changed

+77
-30
lines changed
 

Diff for: ‎PYTHON APPS/Alarm_Clock/backend_alarm.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
from threading import Event
44
from typing import List
55
from configuration import TIME_RELAPSE, TIME_SPEED
6+
from pygame import mixer
7+
8+
mixer.init()
9+
sound = mixer.Sound('media/sound/alarm.mp3')
610

711

812
def get_date_now() -> int:
@@ -56,7 +60,8 @@ def counter_timer(self) -> None:
5660
5761
"""
5862
current_time = get_date_now()
59-
if current_time >= self.total_time:
63+
if current_time == self.total_time:
64+
sound.play() # It start the alarm sound
6065
time.sleep(TIME_RELAPSE)
6166
self.start_alarm()
6267
else:

Diff for: ‎PYTHON APPS/Alarm_Clock/configuration.py

+33-2
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,47 @@
11
# Configuration for the app size and title
22
from typing import Dict, Tuple, List
33

4-
WIDTH: int = 600
4+
WIDTH: int = 700
55
HEIGHT: int = 700
66
ICON_PATH: str = 'media/image/empty.ico'
77
TITLE_APP: str = ''
88
THEME: str = 'darkly'
99

10+
CLOCK = {
11+
'X': 0,
12+
'Y': 0,
13+
'WIDTH': 1,
14+
'HEIGHT': 0.3,
15+
}
16+
PANEL = {
17+
'X': 0,
18+
'Y': 0.3,
19+
'WIDTH': 1,
20+
'HEIGHT': 0.6,
21+
}
22+
BUTTON = {
23+
'X': 0.5,
24+
'Y': 0.95,
25+
}
26+
27+
TIME = {
28+
'ROW': 0,
29+
'COLUMN': 0,
30+
'SPAN': 2,
31+
'STICKY': 'ns'
32+
}
33+
DATE = {
34+
'ROW': 1,
35+
'COLUMN': 0,
36+
'SPAN': 2,
37+
'STICKY': 'n'
38+
}
1039
# Configuration for the top level
1140
LIST_DAY: tuple[str:] = ('Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat',)
12-
TOP_LEVEL: dict[str, int] = dict(WIDTH = 300, HEIGHT = 300)
41+
TOP_LEVEL: dict[str, int] = dict(WIDTH = 300, HEIGHT = 200)
1342

1443
# Configuration for the backend of alarm
1544
TIME_RELAPSE = 60
1645
TIME_SPEED = 1
46+
47+
# TODO: I need to make the configuration file and to make a much clean code

Diff for: ‎PYTHON APPS/Alarm_Clock/main.py

+12-12
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from configuration import (
66
WIDTH, HEIGHT,
77
ICON_PATH, TITLE_APP,
8-
THEME,
8+
THEME, CLOCK, BUTTON, PANEL,
99
)
1010
from widgets import (
1111
ClockFrame, AlarmClockPanel,
@@ -48,22 +48,22 @@ def __init__(self):
4848

4949
# set layout for widgets(place method)
5050
self.clock_frame.place(
51-
relx = 0,
52-
rely = 0,
53-
relwidth = 1,
54-
relheight = 0.3,
51+
relx = CLOCK['X'],
52+
rely = CLOCK['Y'],
53+
relwidth = CLOCK['WIDTH'],
54+
relheight = CLOCK['HEIGHT'],
5555
anchor = 'nw'
5656
)
5757
self.alarm_panel.place(
58-
relx = 0,
59-
rely = 0.3,
60-
relwidth = 1,
61-
relheight = 0.6,
62-
anchor = 'nw'
58+
relx = PANEL['X'],
59+
rely = PANEL['Y'],
60+
relwidth = PANEL['WIDTH'],
61+
relheight = PANEL['HEIGHT'],
62+
anchor = 'nw',
6363
)
6464
self.button_top_level.place(
65-
relx = 0.5,
66-
rely = 0.95,
65+
relx = BUTTON['X'],
66+
rely = BUTTON['Y'],
6767
anchor = 'center'
6868
)
6969

Diff for: ‎PYTHON APPS/Alarm_Clock/media/image/clock.png

-8.91 KB
Binary file not shown.

Diff for: ‎PYTHON APPS/Alarm_Clock/toplevel.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def __init__(
5454
# The spinbox
5555
self.top_level_style.configure(
5656
style = 'PAUSE.TLabel',
57-
font = ('Helvetica', 30, 'bold'),
57+
font = ('Helvetica', 20, 'bold'),
5858
anchor = 'center'
5959

6060
)
@@ -79,7 +79,7 @@ def __init__(
7979
to = 23,
8080
)
8181

82-
# Create the ":"
82+
# Create the ":" for spacing
8383
self.space_label = ttk.Label(
8484
master = self,
8585
style = 'PAUSE.TLabel',
@@ -102,7 +102,6 @@ def __init__(
102102
text = 'OK',
103103
style = 'OK.TButton',
104104
command = ok_function
105-
106105
)
107106
# Create the CANCEL button
108107
self.cancel_button = ttk.Button(

Diff for: ‎PYTHON APPS/Alarm_Clock/widgets.py

+24-12
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from frame_alarm import AlarmsFrame
2+
from configuration import TIME, DATE
23
from ttkbootstrap.scrolled import ScrolledFrame
34
import ttkbootstrap as ttk
45
import time
@@ -22,19 +23,21 @@ def __init__(self, parent, ):
2223

2324
# set set style
2425
self.style = ttk.Style()
26+
# Configure the style of time label
2527
self.style.configure(
2628
style = 'Time.TLabel',
2729
font = ('Helvetica', 30, 'bold'),
2830
anchor = 'center'
2931
)
3032

33+
# Configure the style of time label
3134
self.style.configure(
3235
style = 'Data.TLabel',
3336
font = ('Helvetica', 30, 'bold'),
3437
anchor = 'center'
3538
)
3639

37-
# set widgets
40+
# Creating the widgets for the time and the date
3841

3942
self.label_time = ttk.Label(
4043
master = self,
@@ -51,16 +54,16 @@ def __init__(self, parent, ):
5154
# set layout
5255

5356
self.label_time.grid(
54-
row = 0,
55-
column = 0,
56-
columnspan = 2,
57-
sticky = 'ns'
57+
row = TIME['ROW'],
58+
column = TIME['COLUMN'],
59+
columnspan = TIME['SPAN'],
60+
sticky = TIME['STICKY']
5861
)
5962
self.label_date.grid(
60-
row = 1,
61-
column = 0,
62-
columnspan = 2,
63-
sticky = 'n'
63+
row = DATE['ROW'],
64+
column = DATE['COLUMN'],
65+
columnspan = DATE['SPAN'],
66+
sticky = DATE['STICKY']
6467
)
6568

6669
def update_time(self):
@@ -92,11 +95,20 @@ class AddAlarmClock(ttk.Frame):
9295
def __init__(self, parent, button_function):
9396
super().__init__(master = parent)
9497

95-
# button
98+
# set style for the button
99+
self.style = ttk.Style()
100+
self.style.configure(
101+
style = 'Alarm.TButton',
102+
font = ('Helvetica', 20, 'bold'),
103+
anchor = 'center'
104+
)
105+
106+
# Create the button for adding alarms
96107
self.button = ttk.Button(
97108
master = self,
98-
text = '+',
109+
text = '',
99110
command = button_function,
100111
style = 'Alarm.TButton',
101112
)
102-
self.button.pack(expand = True, fill = 'both')
113+
# pack the button
114+
self.button.pack()

0 commit comments

Comments
 (0)
Please sign in to comment.