Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions examples/clock.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ def main():
now = datetime.datetime.now()
today_date = now.strftime("%d %b %y")

margin = 4
margin = 5

cx = 30
cy = min(device.height, 64) / 2
cy = min(device.height, 60) / 2
Comment on lines +39 to +42
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

While these changes fix the layout issue, they introduce 'magic numbers' (5, 60). To improve code readability and maintainability, it's a good practice to define these as named constants at a higher scope (e.g., at the top of the main function or module level). For example: MARGIN = 5, CLOCK_DIAMETER = 60. This would make the purpose of these values clearer and future adjustments easier.


left = cx - cy
right = cx + cy
Expand All @@ -58,8 +58,9 @@ def main():
draw.line((cx, cy, cx + mins[0], cy + mins[1]), fill="white")
draw.line((cx, cy, cx + secs[0], cy + secs[1]), fill="red")
draw.ellipse((cx - 2, cy - 2, cx + 2, cy + 2), fill="white", outline="white")
draw.text((2 * (cx + margin), cy - 8), today_date, fill="yellow")
draw.text((2 * (cx + margin), cy), today_time, fill="yellow")
text_x = 2 * (cx + margin)
draw.text((text_x, cy - 10), today_date, fill="yellow")
draw.text((text_x, cy + 2), today_time, fill="yellow")
Comment on lines +62 to +63
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The vertical offsets -10 and 2 for positioning the date and time are 'magic numbers'. To make the code more understandable, consider defining them as named constants, like DATE_Y_OFFSET = -10 and TIME_Y_OFFSET = 2. This clarifies their purpose and makes future adjustments easier.


time.sleep(0.1)

Expand Down