Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only add color_extra controls if the keyboard supports it #12

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
13 changes: 12 additions & 1 deletion src/usr/share/tuxedo-backlight-control/backlight_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class BacklightControl():

colors = colors
regions = ('left', 'center', 'right', 'extra')
params = ('state', 'mode', 'color_left', 'color_center', 'color_right', 'color_extra')
params = ('state', 'mode', 'color_left', 'color_center', 'color_right', 'color_extra', 'brightness')

@staticmethod
def get_device_param(prop):
Expand Down Expand Up @@ -166,6 +166,17 @@ def color_extra(self, value):
""" set hex code for color_extra, with color name present in colors dict """
self.set_device_param('color_extra', self.find_color_by_key(value))

@property
def brightness(self):
""" get brightness value """
return self.get_device_color('extra')

@color_extra.setter
def color_extra(self, value):
""" set hex code for color_extra, with color name present in colors dict """
self.set_device_param('color_extra', self.find_color_by_key(value))


@staticmethod
def display_modes():
""" return a capitalized item-list of all backlight modes """
Expand Down
86 changes: 63 additions & 23 deletions src/usr/share/tuxedo-backlight-control/ui.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/pkexec /usr/bin/python3

import tkinter as tk
from tkinter import ttk
from tkinter import ttk, HORIZONTAL
from backlight_control import backlight


Expand All @@ -28,9 +28,10 @@ def __init__(self, parent):
self.regions = (
'color_left',
'color_center',
'color_right',
'color_extra'
'color_right'
)
if backlight.color_extra:
self.regions.append('color_extra')

self.bg_frame = ttk.Frame(self.parent)
self.bg_frame.grid(sticky=tk.NSEW, column=0, row=0)
Expand All @@ -46,6 +47,7 @@ def __init__(self, parent):

self.labels = {
'mode': ttk.Label(self.bg_frame, text='Backlight mode: '),
'brightness': ttk.Label(self.bg_frame, text='Brightness: '),
'color': ttk.Label(self.bg_frame, text='Backlight color: '),
'color_mode': ttk.Label(self.bg_frame, text='Color mode: '),
'color_left': ttk.Label(self.bg_frame, text='Color left: '),
Expand All @@ -61,12 +63,14 @@ def __init__(self, parent):

self.values = {
'mode': tk.StringVar(self, value=initial_mode),
'brightness': tk.StringVar(self, value=backlight.get_device_param('brightness')),
'color_mode': tk.StringVar(self, value=self.color_mode),
'color_left': tk.StringVar(self, value=backlight.color_left.capitalize()),
'color_center': tk.StringVar(self, value=backlight.color_center.capitalize()),
'color_right': tk.StringVar(self, value=backlight.color_right.capitalize()),
'color_extra': tk.StringVar(self, value=backlight.color_extra.capitalize())
}
if backlight.color_extra:
self.values.color_extra = tk.StringVar(self, value=backlight.color_extra.capitalize())

def set_single_color(color):
if not color == 'Select...':
Expand All @@ -80,6 +84,13 @@ def set_single_color(color):
*backlight.display_modes(),
command=self.on_mode_switch
),
'brightness': ttk.Scale(
self.bg_frame,
from_ = 1,
to_ = 255,
orient=HORIZONTAL,
command=self.on_brightness_change
),
'color': ttk.OptionMenu(
self.bg_frame,
self.values['color_left'],
Expand Down Expand Up @@ -108,15 +119,16 @@ def set_single_color(color):
backlight.color_right.capitalize(),
*backlight.display_colors(),
command=self.color_setter('right')
),
'color_extra': ttk.OptionMenu(
)
}
if backlight.color_extra:
self.widgets.color_extra: ttk.OptionMenu(
self.bg_frame,
self.values['color_extra'],
backlight.color_extra.capitalize(),
*backlight.display_colors(),
command=self.color_setter('extra')
)
}

def cmd():
self.on_color_mode_switch(self.values['color_mode'].get())
Expand Down Expand Up @@ -151,10 +163,16 @@ def cmd():
self.widgets['color_left']['menu'].config(**menuconfig)
self.widgets['color_center']['menu'].config(**menuconfig)
self.widgets['color_right']['menu'].config(**menuconfig)
self.widgets['color_extra']['menu'].config(**menuconfig)

if backlight.color_extra:
self.widgets['color_extra']['menu'].config(**menuconfig)

self.labels['mode'].grid(column=0, row=0, sticky='EW')
self.widgets['mode'].grid(column=1, row=0, sticky='EW', padx=10)

self.labels['brightness'].grid(column=0, row=1, sticky='EW')
self.widgets['brightness'].grid(column=1, row=1, sticky='EW', padx=10)

self.init_footer()

if backlight.state == 1:
Expand Down Expand Up @@ -242,18 +260,10 @@ def hide_colors(self):

def init_color_mode_radio(self):
self.values['color_mode'].set(self.color_mode)
self.labels['color_mode'].grid(row=1, column=0, sticky=tk.EW)
self.widgets['color_mode']['frame'].grid(row=1, column=1, sticky=tk.EW)
self.widgets['color_mode']['options'][0].grid(
row=1,
column=0,
sticky=tk.EW
)
self.widgets['color_mode']['options'][1].grid(
row=1,
column=1,
sticky=tk.EW
)
self.labels['color_mode'].grid(row=2, column=0, sticky=tk.EW)
self.widgets['color_mode']['frame'].grid(row=2, column=1, sticky=tk.EW)
self.widgets['color_mode']['options'][0].grid(row=2, column=0, sticky=tk.EW)
self.widgets['color_mode']['options'][1].grid(row=2, column=1, sticky=tk.EW)

def on_color_mode_switch(self, value):
if value == 'multiple':
Expand All @@ -266,12 +276,12 @@ def on_color_mode_switch(self, value):
self.init_single_color()

def init_single_color(self):
self.labels['color'].grid(column=0, row=2, sticky='EW')
self.widgets['color'].grid(column=1, row=2, sticky='EW', padx=10)
self.labels['color'].grid(column=0, row=3, sticky='EW')
self.widgets['color'].grid(column=1, row=3, sticky='EW', padx=10)

def init_multiple_colors(self):
for index, region in enumerate(self.regions):
row = index + 2
row = index + 3
from_device = getattr(backlight, region)
self.labels[region].grid(column=0, row=row, sticky='EW')
self.values[region].set(from_device.capitalize())
Expand All @@ -289,6 +299,9 @@ def on_mode_switch(self, value):
self.init_mode(value.lower())
self.mode = value

def on_brightness_change(self, value):
backlight.set_device_param('brightness', int(float(value)))

@property
def mode(self):
return backlight.mode.capitalize()
Expand Down Expand Up @@ -338,6 +351,33 @@ def init_footer(self):
)
self.off_button.grid(sticky=tk.E, column=1, row=6, padx=10, pady=10)

self.save_button = ttk.Button(
self.bg_frame,
text="Apply on boot",
command=self.save_module_params
)
self.save_button.grid(sticky=tk.E, column=1, row=7, padx=10, pady=10)

def save_module_params(self):
mode = backlight.get_device_param('mode').rstrip()
brightness = backlight.get_device_param('brightness').rstrip()
hex_left = "0x" + backlight.get_device_param('color_left').rstrip().upper()
hex_center = "0x" + backlight.get_device_param('color_center').rstrip().upper()
hex_right = "0x" + backlight.get_device_param('color_right').rstrip().upper()
state = backlight.get_device_param('state').rstrip()

moduleString = f"options tuxedo-keyboard mode={mode} brightness={brightness} color_left={hex_left} color_center={hex_center} color_right={hex_right} state={state}"
if backlight.color_extra:
hex_extra = "0x" + backlight.get_device_param('color_extra').rstrip().upper()
moduleString = f"options tuxedo-keyboard mode={mode} brightness={brightness} color_left={hex_left} color_center={hex_center} color_right={hex_right} color_extra={hex_extra} state={state}"

moduleFile="/etc/modprobe.d/tuxedo_keyboard.conf"
f = open(moduleFile, "w")
f.write(moduleString)
f.close()

ttk.Label(text="Written to " + moduleFile).grid(row=8)


def init():
root = tk.Tk()
Expand Down