From 5a0a0f9d4b460a70a3b65918b4a9a53e64211b72 Mon Sep 17 00:00:00 2001 From: MisguidedEmails Date: Sun, 2 Sep 2018 20:19:06 +0100 Subject: [PATCH 1/7] Removed "Hi I'm" --- pride/main.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/pride/main.py b/pride/main.py index 240fa44..f0954ee 100644 --- a/pride/main.py +++ b/pride/main.py @@ -37,15 +37,11 @@ for num, colour in enumerate(colours): width_loc = int(num * colour_width) ugfx.area(width_loc, 0, int(colour_width), 320, ugfx.html_color(colour)) -# Message to display -prefix_message = "Hi I'm" ugfx.set_default_font(ugfx.FONT_NAME) # Calc center of screen center = (int(ugfx.width() / 2), int(ugfx.height() / 2)) -# Can't use label since the background covers the flag -ugfx.text(50, center[1] + name_height, prefix_message, ugfx.WHITE) # Process name given_name = homescreen.name("Set your name in the settings app") From f1ff8bef600082b21e91e0490818a4b3f5b20296 Mon Sep 17 00:00:00 2001 From: MisguidedEmails Date: Sun, 2 Sep 2018 20:20:01 +0100 Subject: [PATCH 2/7] Changed center to center_width --- pride/main.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pride/main.py b/pride/main.py index f0954ee..de41fd0 100644 --- a/pride/main.py +++ b/pride/main.py @@ -40,8 +40,8 @@ for num, colour in enumerate(colours): ugfx.set_default_font(ugfx.FONT_NAME) -# Calc center of screen -center = (int(ugfx.width() / 2), int(ugfx.height() / 2)) +# Calc width center of screen +center_width = int(ugfx.width() / 2) # Process name given_name = homescreen.name("Set your name in the settings app") @@ -64,7 +64,7 @@ while True: wifi_strength_value = homescreen.wifi_strength() if wifi_strength_value: wifi_message = 'WiFi: %s%%' % int(wifi_strength_value) - wifi_text = ugfx.text(center[0], ugfx.height() - info_height, wifi_message, ugfx.BLACK) + wifi_text = ugfx.text(center_width, ugfx.height() - info_height, wifi_message, ugfx.BLACK) battery_value = homescreen.battery() if battery_value: From 17d40f9c62dcbef9af892b18c37f8dd7729ac66c Mon Sep 17 00:00:00 2001 From: MisguidedEmails Date: Sun, 2 Sep 2018 21:53:11 +0100 Subject: [PATCH 3/7] Sectioned code into functions --- pride/main.py | 57 +++++++++++++++++++++++++++++---------------------- 1 file changed, 33 insertions(+), 24 deletions(-) diff --git a/pride/main.py b/pride/main.py index de41fd0..6c30413 100644 --- a/pride/main.py +++ b/pride/main.py @@ -28,37 +28,38 @@ max_name = 8 # Orientation for other people to see ugfx.orientation(90) -# Pride flag colours -colours = [0xE70000, 0xFF8C00, 0xFFEF00, 0x00811F, 0x0044FF, 0x760089] -# Draw each "band" of colour in the flag -colour_width = ugfx.width() / len(colours) -for num, colour in enumerate(colours): - width_loc = int(num * colour_width) - ugfx.area(width_loc, 0, int(colour_width), 320, ugfx.html_color(colour)) +def draw_flag(): + # Pride flag colours + colours = [0xE70000, 0xFF8C00, 0xFFEF00, 0x00811F, 0x0044FF, 0x760089] + + # Draw each "band" of colour in the flag + colour_width = ugfx.width() / len(colours) + for num, colour in enumerate(colours): + width_loc = int(num * colour_width) + ugfx.area(width_loc, 0, int(colour_width), 320, ugfx.html_color(colour)) -ugfx.set_default_font(ugfx.FONT_NAME) - -# Calc width center of screen -center_width = int(ugfx.width() / 2) - -# Process name -given_name = homescreen.name("Set your name in the settings app") -if len(given_name) <= max_name: +def draw_name(): ugfx.set_default_font(ugfx.FONT_NAME) -else: - ugfx.set_default_font(ugfx.FONT_MEDIUM_BOLD) -# Draw name -ugfx.Label(0, ugfx.height() - name_height, ugfx.width(), name_height, given_name, justification=ugfx.Label.CENTER) + + # Process name + given_name = homescreen.name("Set your name in the settings app") + if len(given_name) <= max_name: + ugfx.set_default_font(ugfx.FONT_NAME) + else: + ugfx.set_default_font(ugfx.FONT_MEDIUM_BOLD) + # Draw name + ugfx.Label(0, ugfx.height() - name_height, ugfx.width(), name_height, given_name, justification=ugfx.Label.CENTER) -# Draw for the user to see -ugfx.orientation(270) -ugfx.set_default_font(ugfx.FONT_SMALL) +def draw_user_info(): + # Draw for the user to see + ugfx.orientation(270) + # Calc width center of screen + center_width = int(ugfx.width() / 2) + ugfx.set_default_font(ugfx.FONT_SMALL) -# WiFi/Battery update loop -while True: ugfx.area(0, ugfx.height() - info_height, ugfx.width(), info_height, ugfx.WHITE) wifi_strength_value = homescreen.wifi_strength() @@ -71,6 +72,14 @@ while True: battery_message = 'Battery: %s%%' % int(battery_value) battery_text = ugfx.text(0, ugfx.height() - info_height, battery_message, ugfx.BLACK) + +draw_flag() +draw_name() + +# WiFi/Battery update loop +while True: + draw_user_info() + homescreen.sleep_or_exit(1.5) restart_to_default() From 1cad3553037192032205fe0892b62efbbcdd1df9 Mon Sep 17 00:00:00 2001 From: MisguidedEmails Date: Sun, 2 Sep 2018 21:53:42 +0100 Subject: [PATCH 4/7] Removed unecessary variable assignment. --- pride/main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pride/main.py b/pride/main.py index 6c30413..4fed2cd 100644 --- a/pride/main.py +++ b/pride/main.py @@ -65,12 +65,12 @@ def draw_user_info(): wifi_strength_value = homescreen.wifi_strength() if wifi_strength_value: wifi_message = 'WiFi: %s%%' % int(wifi_strength_value) - wifi_text = ugfx.text(center_width, ugfx.height() - info_height, wifi_message, ugfx.BLACK) + ugfx.text(center_width, ugfx.height() - info_height, wifi_message, ugfx.BLACK) battery_value = homescreen.battery() if battery_value: battery_message = 'Battery: %s%%' % int(battery_value) - battery_text = ugfx.text(0, ugfx.height() - info_height, battery_message, ugfx.BLACK) + ugfx.text(0, ugfx.height() - info_height, battery_message, ugfx.BLACK) draw_flag() From 599c504110894e386d2eb4ceff6a515e5c1680e9 Mon Sep 17 00:00:00 2001 From: MisguidedEmails Date: Sun, 2 Sep 2018 22:04:10 +0100 Subject: [PATCH 5/7] Fixed name orientation --- pride/main.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pride/main.py b/pride/main.py index 4fed2cd..10ba428 100644 --- a/pride/main.py +++ b/pride/main.py @@ -41,6 +41,9 @@ def draw_flag(): def draw_name(): + # Orientation for other people to see + ugfx.orientation(90) + ugfx.set_default_font(ugfx.FONT_NAME) # Process name From f19cffd3071fdf04cd65abc59d1d7213837804c4 Mon Sep 17 00:00:00 2001 From: MisguidedEmails Date: Sun, 2 Sep 2018 23:36:19 +0100 Subject: [PATCH 6/7] Added a selection of flags the user can switch between. --- pride/main.py | 49 ++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 40 insertions(+), 9 deletions(-) diff --git a/pride/main.py b/pride/main.py index 10ba428..ac45e3d 100644 --- a/pride/main.py +++ b/pride/main.py @@ -7,12 +7,14 @@ background is the pride flag. ___name___ = "Pride" ___license___ = "MIT" ___categories___ = ["Homescreens"] -___dependencies___ = ["homescreen", "app"] +___dependencies___ = ["homescreen", "app", "buttons"] from app import restart_to_default import ugfx import homescreen +from tilda import Buttons +import buttons homescreen.init() @@ -25,13 +27,19 @@ info_height = 20 # Maximum length of name before downscaling max_name = 8 -# Orientation for other people to see -ugfx.orientation(90) +flags = { + 'LGBT': [0xE70000, 0xFF8C00, 0xFFEF00, 0x00811F, 0x0044FF, 0x760089], + 'Non-Binary': [0xFFF433, 0xFFFFFF, 0x9B59D0, 0x000000], + 'Trans': [0x5BCEFA, 0xF5A9B8, 0xFFFFFF, 0xF5A9B8, 0x5BCEFA], + 'Asexual': [0x000000, 0xA3A3A3, 0xFFFFFF, 0x800080], + 'Bisexual': [0xFF0080, 0xFF0080, 0xA349A4, 0x0000FF, 0x0000FF], + 'Pansexual': [0xFF218E, 0xFCD800, 0x0194FC] +} -def draw_flag(): - # Pride flag colours - colours = [0xE70000, 0xFF8C00, 0xFFEF00, 0x00811F, 0x0044FF, 0x760089] +def draw_flag(colours): + # Orientation for other people to see + ugfx.orientation(90) # Draw each "band" of colour in the flag colour_width = ugfx.width() / len(colours) @@ -76,13 +84,36 @@ def draw_user_info(): ugfx.text(0, ugfx.height() - info_height, battery_message, ugfx.BLACK) -draw_flag() -draw_name() +# Set variables for WiFi/Battery loop +selection_change = True +flag_names = list(flags.keys()) +selection = flag_names.index('LGBT') # WiFi/Battery update loop +draw_name() while True: - draw_user_info() + # Buttons will cycle when it reaches either side of the list + if buttons.is_pressed(Buttons.JOY_Left): + if selection > 0: + selection -= 1 + else: + selection = len(flags) - 1 + selection_change = True + elif buttons.is_pressed(Buttons.JOY_Right): + if selection < len(flags) - 1: + selection += 1 + else: + selection = 0 + selection_change = True + + # Only triggers if the selection has changed + if selection_change: + draw_flag(flags[flag_names[selection]]) + selection_change = False + + # Redraw time-sensitive info on each iteration + draw_user_info() homescreen.sleep_or_exit(1.5) restart_to_default() From 229f09acd4a84988494bdb4e100761ee6394e12d Mon Sep 17 00:00:00 2001 From: MisguidedEmails Date: Sun, 2 Sep 2018 23:42:55 +0100 Subject: [PATCH 7/7] Only render the flag where it's visible. We now don't have to re-render the name on each flag change. --- pride/main.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pride/main.py b/pride/main.py index ac45e3d..3caefaa 100644 --- a/pride/main.py +++ b/pride/main.py @@ -45,7 +45,8 @@ def draw_flag(colours): colour_width = ugfx.width() / len(colours) for num, colour in enumerate(colours): width_loc = int(num * colour_width) - ugfx.area(width_loc, 0, int(colour_width), 320, ugfx.html_color(colour)) + flag_height = ugfx.height() - (name_height + info_height) + ugfx.area(width_loc, info_height, int(colour_width), flag_height, ugfx.html_color(colour)) def draw_name():