Skip to content

Commit

Permalink
Huge processor and networking performance boosts. All threads are now
Browse files Browse the repository at this point in the history
daemon, so os._exit() is out!
  • Loading branch information
samclane committed Sep 15, 2018
1 parent 1a8b905 commit f1f8b9b
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 15 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
config.ini
.idea/
.pytest_cache
__pycache__
.pytest_cache/
__pycache__/
build/
dist/
venv/
4 changes: 2 additions & 2 deletions _constants.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION = "1.5.0"
BUILD_DATE = "2018-08-16T12:33:01.052526"
BUILD_DATE = "2018-08-25T13:37:23.114329"
AUTHOR = "Sawyer McLane"
DEBUGGING = True
DEBUGGING = False
2 changes: 1 addition & 1 deletion color_thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def mode_screen_color(initial_color):

class ColorThread(threading.Thread):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
super().__init__(*args, daemon=True, **kwargs)
self._stop = threading.Event()

def stop(self):
Expand Down
2 changes: 1 addition & 1 deletion default.ini
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ defaultmonitor = get_primary_monitor()
[Info]
version = 1.5.0
author = Sawyer McLane
builddate = 2018-08-16T12:33:01.052526
builddate = 2018-08-25T13:37:23.114329
31 changes: 22 additions & 9 deletions gui.pyw
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,20 @@ class Color:
def __setitem__(self, key, value):
self.__setattr__(self.__slots__[key], value)

def __str__(self):
return "[{}, {}, {}, {}]".format(self.hue,
self.saturation,
self.brightness,
self.kelvin)

def __repr__(self):
return [self.hue,
self.saturation,
self.brightness,
self.kelvin
].__repr__()



class LifxFrame(ttk.Frame):
def __init__(self, master, lifx_instance): # We take a lifx instance so we can theoretically inject our own.
Expand Down Expand Up @@ -99,6 +113,7 @@ class LifxFrame(ttk.Frame):
try:
product = product_map[light.get_product()]
label = light.get_label()
light.get_color()
light.updated = False
self.lightsdict[label] = light
self.logger.info('Light found: {}:({})'.format(product, label))
Expand All @@ -107,9 +122,7 @@ class LifxFrame(ttk.Frame):
if not (group_label in self.groupsdict.keys()):
self.groupsdict[group_label] = self.lifx.get_devices_by_group(group_label)
self.group_icons.draw_group_icon(group, group_label)
# self.logger.info('Group found {}: {}'.format(group_label, [d.get_label() for d in
# self.lifx.get_devices_by_group(
# group_label)]))
self.logger.info("Group found: {}".format(group_label))
except WorkflowException as e:
self.logger.warning("Error when communicating with LIFX device: {}".format(e))

Expand All @@ -133,9 +146,9 @@ class LifxFrame(ttk.Frame):

def run_tray_icon():
SysTrayIcon.SysTrayIcon(resource_path('res/icon_vector_9fv_icon.ico'), "LIFX-Control-Panel", tray_options,
on_quit=lambda *_: os._exit(1))
on_quit=lambda *_: self.on_closing)

self.systray_thread = threading.Thread(target=run_tray_icon)
self.systray_thread = threading.Thread(target=run_tray_icon, daemon=True)
self.systray_thread.start()
self.master.bind('<Unmap>', lambda *_: self.master.withdraw()) # Minimize to taskbar

Expand Down Expand Up @@ -252,7 +265,7 @@ class LifxFrame(ttk.Frame):
def on_closing(self):
self.logger.info('Shutting down.\n')
self.master.destroy()
os._exit(1)
sys.exit(0)


class LightFrame(ttk.Labelframe):
Expand Down Expand Up @@ -925,11 +938,11 @@ class BulbIconList(Frame):
# update sizing info
self.current_icon_width += self.icon_width

def update_icon(self, bulb):
def update_icon(self, bulb: lifxlan.Light):
try:
bulb_color = bulb.get_color()
bulb_color = bulb.color
bulb_brightness = bulb_color[2]
sprite, image, text = self.bulb_dict[bulb.get_label()]
sprite, image, text = self.bulb_dict[bulb.label]
except WorkflowException:
return
brightness_scale = (bulb_brightness / 65535) * sprite.height()
Expand Down

0 comments on commit f1f8b9b

Please sign in to comment.