From 62d477cc8154cfdfe68f0e039f800a2e841f9907 Mon Sep 17 00:00:00 2001 From: Denver P <23412100+DrTexxOfficial@users.noreply.github.com> Date: Sat, 13 Jul 2019 22:26:14 +1000 Subject: [PATCH 01/16] Create README.md --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..4716e9d --- /dev/null +++ b/README.md @@ -0,0 +1,8 @@ +# screenlifx +Set LIFX color with the average screen color + +## Requirements +[] + +## Installation +[] From 7a777f1bf3de7fe93a94a650cb73f68d01abe4e5 Mon Sep 17 00:00:00 2001 From: DrTexxOfficial <23412100+DrTexxOfficial@users.noreply.github.com> Date: Sat, 13 Jul 2019 22:53:16 +1000 Subject: [PATCH 02/16] update shebang to python3 --- screenlifx.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/screenlifx.py b/screenlifx.py index b9995ec..e2dc882 100644 --- a/screenlifx.py +++ b/screenlifx.py @@ -1,4 +1,4 @@ -#! python2.7-32 +#!/usr/bin/env python3 # some quick & dirty code to set LIFX color with the average # screen color. Works for VLC, some games, etc. From ee66ec7bee2a3ef2379358ec719644ecafe43b4e Mon Sep 17 00:00:00 2001 From: DrTexxOfficial <23412100+DrTexxOfficial@users.noreply.github.com> Date: Sat, 13 Jul 2019 22:55:20 +1000 Subject: [PATCH 03/16] add brackets where needed (py2to3) --- screenlifx.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) mode change 100644 => 100755 screenlifx.py diff --git a/screenlifx.py b/screenlifx.py old mode 100644 new mode 100755 index e2dc882..63b1131 --- a/screenlifx.py +++ b/screenlifx.py @@ -5,7 +5,7 @@ # use the LIFX LAN protocol via the excellent library by Meghan Clark # https://github.com/mclarkk/lifxlan -from lifxlan import * # +from lifxlan import * # from PIL import ImageGrab from PIL import Image @@ -17,16 +17,16 @@ def rgb2hsv(r, g, b): h = h * 0xffff s = s * 0xffff v = v * 0xffff - return h , s, v + return(h, s, v) def main(): # start with the LIFX business... - lifx = LifxLAN(1) - print "Discovering lights..." + lifx = LifxLAN(None) + print("Discovering lights...") devices = lifx.get_lights() for d in devices: - print "{} ({}) HSBK: {}".format(d.get_label(), d.mac_addr, d.get_color()) - print + print("{} ({}) HSBK: {}".format(d.get_label(), d.mac_addr, d.get_color())) + print() # the block of data to analyze. # PIL resizing to 1x1 seems to do strange things; a bigger box works better @@ -54,8 +54,8 @@ def main(): blue = blue / totpixels t2 = time.clock() - print "\rRGB %3d %3d %3d" % (red, green, blue), - print "- Time %2.4f" % (t2-t1), + print("\rRGB %3d %3d %3d".format(red, green, blue)) + print("- Time %2.4f".format(t2-t1)) h, s, v = rgb2hsv(red, green, blue) color = (h, s, v, 0) From a389e07c1993d8649ee6714b7d2b6306cf825dce Mon Sep 17 00:00:00 2001 From: DrTexxOfficial <23412100+DrTexxOfficial@users.noreply.github.com> Date: Sat, 13 Jul 2019 22:58:09 +1000 Subject: [PATCH 04/16] add requirements.txt --- requirements.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 requirements.txt diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..8bdd1cb --- /dev/null +++ b/requirements.txt @@ -0,0 +1,3 @@ +lifxlan==1.2.5 +mss==4.0.3 +Pillow==6.1.0 From 605a76cbb24b0d4d879adb959956b5b02dcd37af Mon Sep 17 00:00:00 2001 From: DrTexxOfficial <23412100+DrTexxOfficial@users.noreply.github.com> Date: Sat, 13 Jul 2019 23:41:53 +1000 Subject: [PATCH 05/16] ignore temp image file --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 9f33c8d..df06075 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -lifxlan/ \ No newline at end of file +lifxlan/ +monitor-1.png From f716ede4764b74f65714905f115461071ae06689 Mon Sep 17 00:00:00 2001 From: DrTexxOfficial <23412100+DrTexxOfficial@users.noreply.github.com> Date: Sat, 13 Jul 2019 23:43:40 +1000 Subject: [PATCH 06/16] increase refresh hz --- screenlifx.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/screenlifx.py b/screenlifx.py index 63b1131..802fb7d 100755 --- a/screenlifx.py +++ b/screenlifx.py @@ -61,7 +61,7 @@ def main(): color = (h, s, v, 0) lifx.set_color_all_lights(color, 150, rapid=True) - time.sleep(1/50) + time.sleep(1/60) if __name__ == '__main__': main() From 7f187d02096f9b8eacd737771638f104aa14ba37 Mon Sep 17 00:00:00 2001 From: DrTexxOfficial <23412100+DrTexxOfficial@users.noreply.github.com> Date: Sat, 13 Jul 2019 23:45:58 +1000 Subject: [PATCH 07/16] replace time.clock with time.process_time in python 3.8 onwards time.clock will be made obsolete --- screenlifx.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/screenlifx.py b/screenlifx.py index 802fb7d..f18a830 100755 --- a/screenlifx.py +++ b/screenlifx.py @@ -38,7 +38,7 @@ def main(): # screen scanning loop while True: img = ImageGrab.grab() - t1 = time.clock() + t1 = time.process_time() # let PIL to shrink the image into a more manageable size # (just few ms in your average machine) img = img.resize((rx, ry)) @@ -52,7 +52,7 @@ def main(): red = red / totpixels green = green / totpixels blue = blue / totpixels - t2 = time.clock() + t2 = time.process_time() print("\rRGB %3d %3d %3d".format(red, green, blue)) print("- Time %2.4f".format(t2-t1)) From ed95906ace2e21a1e17ce870be530063d67649c8 Mon Sep 17 00:00:00 2001 From: DrTexxOfficial <23412100+DrTexxOfficial@users.noreply.github.com> Date: Sat, 13 Jul 2019 23:46:38 +1000 Subject: [PATCH 08/16] change xrange to range support for xrange was dropped in python3 --- screenlifx.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/screenlifx.py b/screenlifx.py index f18a830..32a6b76 100755 --- a/screenlifx.py +++ b/screenlifx.py @@ -43,8 +43,8 @@ def main(): # (just few ms in your average machine) img = img.resize((rx, ry)) red = green = blue = 0 - for y in xrange(0, img.size[1]): - for x in xrange(0, img.size[0]): + for y in range(0, img.size[1]): + for x in range(0, img.size[0]): c = img.getpixel((x,y)) red = red + c[0] green = green + c[1] From 992d6d3629f27136dfa564388c5c11965edc7fa6 Mon Sep 17 00:00:00 2001 From: DrTexxOfficial <23412100+DrTexxOfficial@users.noreply.github.com> Date: Sat, 13 Jul 2019 23:47:12 +1000 Subject: [PATCH 09/16] change string formatting from py2 to py3 --- screenlifx.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/screenlifx.py b/screenlifx.py index 32a6b76..a9af045 100755 --- a/screenlifx.py +++ b/screenlifx.py @@ -54,8 +54,8 @@ def main(): blue = blue / totpixels t2 = time.process_time() - print("\rRGB %3d %3d %3d".format(red, green, blue)) - print("- Time %2.4f".format(t2-t1)) + print("\rRGB {:.1f} {:.1f} {:.1f}".format(red, green, blue)) + print("- Time {}".format(t2-t1)) h, s, v = rgb2hsv(red, green, blue) color = (h, s, v, 0) From b0200cccafa93ba075676f0ee16856c1bef07257 Mon Sep 17 00:00:00 2001 From: DrTexxOfficial <23412100+DrTexxOfficial@users.noreply.github.com> Date: Sat, 13 Jul 2019 23:48:44 +1000 Subject: [PATCH 10/16] replace ImageGrab with mss and implement supporting code --- screenlifx.py | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/screenlifx.py b/screenlifx.py index a9af045..1392a51 100755 --- a/screenlifx.py +++ b/screenlifx.py @@ -7,10 +7,21 @@ # https://github.com/mclarkk/lifxlan from lifxlan import * # -from PIL import ImageGrab +from mss import mss from PIL import Image import time, os, colorsys +# preferences +factor = 0.75 + +# split image filename into name and extension +#name, ext = os.path.splitext(image_file) + +# create a new file name for saving the result +#new_image_file = "%s%s%s" % (name, str(factor), ext) +#img_anti.save(new_image_file) +#print("resized file saved as %s" % new_image_file) + # helper for colors conversion/scaling def rgb2hsv(r, g, b): h, s, v = colorsys.rgb_to_hsv(r / 255.0, g / 255.0, b / 255.0) @@ -37,7 +48,23 @@ def main(): # screen scanning loop while True: - img = ImageGrab.grab() + + with mss() as sct: image_file = sct.shot() + + img_org = Image.open(image_file) + + width_org, height_org = img_org.size + + width = int(width_org * factor) + height = int(height_org * factor) + + # best down-sizing filter + #img_resized = img_org.resize((width, height), Image.ANTIALIAS) + # quickest down-sizing filter + img_resized = img_org.resize((width, height), Image.NEAREST) + + img = img_resized + t1 = time.process_time() # let PIL to shrink the image into a more manageable size # (just few ms in your average machine) From d9e954941624fae29b2250f169f65088d667898f Mon Sep 17 00:00:00 2001 From: DrTexxOfficial <23412100+DrTexxOfficial@users.noreply.github.com> Date: Sun, 14 Jul 2019 00:13:49 +1000 Subject: [PATCH 11/16] demo video placeholder + recommendation --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 4716e9d..175d1b6 100644 --- a/README.md +++ b/README.md @@ -6,3 +6,8 @@ Set LIFX color with the average screen color ## Installation [] + +## Demo +[video coming soon] + +Once you've got it working, give this video a crack yourself: [NZXT 340 Trailer]() From 0568cf7543ac82bfb16730fc1c8f160d717c189a Mon Sep 17 00:00:00 2001 From: DrTexxOfficial <23412100+DrTexxOfficial@users.noreply.github.com> Date: Sun, 14 Jul 2019 00:17:03 +1000 Subject: [PATCH 12/16] add notes and things to consider --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 175d1b6..b02bb7d 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,9 @@ Set LIFX color with the average screen color ## Installation [] +## Notes and things to consider +Programs such as Flux or other 'Night Light' alternatives may impact colours. I can confirm this is definately the case for Gnome's Night Light. + ## Demo [video coming soon] From 6b0bbccfa7e375cd63f26a8c6ed84881c67881fa Mon Sep 17 00:00:00 2001 From: DrTexxOfficial <23412100+DrTexxOfficial@users.noreply.github.com> Date: Sun, 14 Jul 2019 01:22:21 +1000 Subject: [PATCH 13/16] add basic launch/close instructions (wip) --- README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README.md b/README.md index b02bb7d..4fd4e98 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,16 @@ Set LIFX color with the average screen color ## Installation [] +## Launching and closing +### Launch screenlifx +```bash +$ source ~/Applications/screenlifx/bin/activate +$ python3 ~/github/screenlifx/screenlifx.py +``` + +### Closing screenlifx +Ctrl + C in terminal window + ## Notes and things to consider Programs such as Flux or other 'Night Light' alternatives may impact colours. I can confirm this is definately the case for Gnome's Night Light. From 1708872ea4a1937fe26093ca883ac5fbb7d56c86 Mon Sep 17 00:00:00 2001 From: DrTexxOfficial <23412100+DrTexxOfficial@users.noreply.github.com> Date: Sun, 14 Jul 2019 18:15:15 +1000 Subject: [PATCH 14/16] updated readme --- README.md | 28 ++++++---------------------- 1 file changed, 6 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 4fd4e98..88537d6 100644 --- a/README.md +++ b/README.md @@ -1,26 +1,10 @@ -# screenlifx +# Screenlifx Set LIFX color with the average screen color -## Requirements -[] - -## Installation -[] - -## Launching and closing -### Launch screenlifx -```bash -$ source ~/Applications/screenlifx/bin/activate -$ python3 ~/github/screenlifx/screenlifx.py +## Open +``` +python3 screenlifx.py ``` -### Closing screenlifx -Ctrl + C in terminal window - -## Notes and things to consider -Programs such as Flux or other 'Night Light' alternatives may impact colours. I can confirm this is definately the case for Gnome's Night Light. - -## Demo -[video coming soon] - -Once you've got it working, give this video a crack yourself: [NZXT 340 Trailer]() +## Close +Ctrl + C in Python3 interpreter From 34cc4d5c4456e57e35f925cdc6319007a6d50a58 Mon Sep 17 00:00:00 2001 From: DrTexxOfficial <23412100+DrTexxOfficial@users.noreply.github.com> Date: Sun, 14 Jul 2019 18:19:46 +1000 Subject: [PATCH 15/16] remove empty comment --- screenlifx.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/screenlifx.py b/screenlifx.py index 1392a51..cab4e88 100755 --- a/screenlifx.py +++ b/screenlifx.py @@ -5,7 +5,7 @@ # use the LIFX LAN protocol via the excellent library by Meghan Clark # https://github.com/mclarkk/lifxlan -from lifxlan import * # +from lifxlan import * from mss import mss from PIL import Image From 4813a8a768fee5e04dfb7eeb0d81f38abb6c378f Mon Sep 17 00:00:00 2001 From: DrTexxOfficial <23412100+DrTexxOfficial@users.noreply.github.com> Date: Sun, 14 Jul 2019 18:27:17 +1000 Subject: [PATCH 16/16] remove unnecessary code + whitespace --- screenlifx.py | 24 +++--------------------- 1 file changed, 3 insertions(+), 21 deletions(-) diff --git a/screenlifx.py b/screenlifx.py index cab4e88..369cf49 100755 --- a/screenlifx.py +++ b/screenlifx.py @@ -11,17 +11,6 @@ from PIL import Image import time, os, colorsys -# preferences -factor = 0.75 - -# split image filename into name and extension -#name, ext = os.path.splitext(image_file) - -# create a new file name for saving the result -#new_image_file = "%s%s%s" % (name, str(factor), ext) -#img_anti.save(new_image_file) -#print("resized file saved as %s" % new_image_file) - # helper for colors conversion/scaling def rgb2hsv(r, g, b): h, s, v = colorsys.rgb_to_hsv(r / 255.0, g / 255.0, b / 255.0) @@ -48,23 +37,16 @@ def main(): # screen scanning loop while True: - with mss() as sct: image_file = sct.shot() - img_org = Image.open(image_file) - width_org, height_org = img_org.size - - width = int(width_org * factor) - height = int(height_org * factor) - + width = int(width_org * 0.75) + height = int(height_org * 0.75) # best down-sizing filter #img_resized = img_org.resize((width, height), Image.ANTIALIAS) # quickest down-sizing filter img_resized = img_org.resize((width, height), Image.NEAREST) - img = img_resized - t1 = time.process_time() # let PIL to shrink the image into a more manageable size # (just few ms in your average machine) @@ -88,7 +70,7 @@ def main(): color = (h, s, v, 0) lifx.set_color_all_lights(color, 150, rapid=True) - time.sleep(1/60) + time.sleep(1/50) if __name__ == '__main__': main()