Skip to content

Commit

Permalink
Minor UI fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
melianmiko committed Mar 19, 2023
1 parent 69c265c commit ef5d2c9
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 27 deletions.
14 changes: 10 additions & 4 deletions src/openfreebuds/device/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,21 @@
from openfreebuds.device import huawei


DEVICE_PROFILES = huawei.devices
SUPPORTED_DEVICES = huawei.devices
PROFILES = huawei.profiles


def is_supported(name: str):
return name in DEVICE_PROFILES
if name not in SUPPORTED_DEVICES:
return False

level, profile = SUPPORTED_DEVICES[name]
return level == "full" or level == "partial"


def create(name: str, address: str) -> BaseDevice | None:
if name not in DEVICE_PROFILES:
if name not in SUPPORTED_DEVICES:
return None

return DEVICE_PROFILES[name](address)
level, profile = SUPPORTED_DEVICES[name]
return profile(address)
15 changes: 11 additions & 4 deletions src/openfreebuds/device/huawei/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
from openfreebuds.device.huawei.profiles import FreeLaceProDevice, FreeBuds4iDevice

devices = {
profiles = {
"HUAWEI FreeBuds 4i": FreeBuds4iDevice,
"HUAWEI FreeBuds 5i": FreeBuds4iDevice,
"HONOR Earbuds 2 Lite": FreeBuds4iDevice,
"HUAWEI FreeLace Pro": FreeLaceProDevice,
"HUAWEI FreeBuds Pro 2": FreeBuds4iDevice,
}

# (implementation_level, profile)
devices = {
"HUAWEI FreeBuds 4i": ("full", FreeBuds4iDevice),
"HONOR Earbuds 2 Lite": ("full", FreeBuds4iDevice),
"HUAWEI FreeLace Pro": ("full", FreeLaceProDevice),

"HUAWEI FreeBuds 5i": ("partial", FreeBuds4iDevice),
"HUAWEI FreeBuds Pro 2": ("partial", FreeBuds4iDevice),
}
6 changes: 3 additions & 3 deletions src/openfreebuds_applet/ui/device_select_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def start(settings: SettingsStorage, manager: FreebudsManager):

tk_tools.setup_window(root)

ttk.Label(root, text=t("first_run_message")) \
ttk.Label(root, text=t("action_select_device")) \
.grid(sticky=tkinter.NW, columnspan=10, row=0, column=0, padx=16, pady=16)

pane = ttk.Panedwindow(root, height=300)
Expand Down Expand Up @@ -72,7 +72,7 @@ def on_select(_):
if values[0] != "pin":
status.config(text=" ")
return
status.config(text=t("address_prefix") + ": " + values[1])
status.config(text=t("address_prefix") + ": " + values[2])

# Rebuild list
# noinspection PyTypeChecker
Expand Down Expand Up @@ -106,7 +106,7 @@ def rebuild_treeview():

@tk_tools.ui_thread
def setup_manually_ui(address, settings, manager):
profiles = list(device.DEVICE_PROFILES.keys())
profiles = list(device.PROFILES.keys())

root = tkinter.Toplevel()
selected = tkinter.StringVar(value=profiles[0])
Expand Down
30 changes: 14 additions & 16 deletions src/openfreebuds_applet/ui/settings_ui/tab_about.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,10 @@
import webbrowser
from tkinter import ttk

from PIL import ImageTk, Image

import openfreebuds.device
import openfreebuds_backend
from openfreebuds_applet import utils
from openfreebuds_applet.l18n import t
from openfreebuds_applet.ui import dev_console
from openfreebuds_applet.modules import self_check


def make_about(parent, applet):
Expand All @@ -21,13 +17,14 @@ def website():
def source():
webbrowser.open("https://github.com/melianmiko/OpenFreebuds")

def do_report(_):
report = self_check.generate_report(applet)
path = str(utils.get_app_storage_dir()) + "/report.txt"
with open(path, "w") as f:
f.write(report)

openfreebuds_backend.open_file(path)
# TODO: Refactor report tool
# def do_report(_):
# report = self_check.generate_report(applet)
# path = str(utils.get_app_storage_dir()) + "/report.txt"
# with open(path, "w") as f:
# f.write(report)
#
# openfreebuds_backend.open_file(path)

def do_console(_):
dev_console.start(applet.manager)
Expand Down Expand Up @@ -55,18 +52,19 @@ def do_console(_):
.grid(row=30, padx=16, pady=16, columnspan=3, sticky=tkinter.NW)

counter = 31
for a in openfreebuds.device.DEVICE_PROFILES:
ttk.Label(frame, text="- {}".format(a)).grid(row=counter, padx=16, pady=4, columnspan=3, sticky=tkinter.NW)
for name in openfreebuds.device.SUPPORTED_DEVICES:
ttk.Label(frame, text="- {}".format(name))\
.grid(row=counter, padx=16, pady=4, columnspan=3, sticky=tkinter.NW)
counter += 1

# Adv. label
ttk.Label(frame, text=t("category_extras"), font=h2_font)\
.grid(row=60, padx=16, pady=16, columnspan=3, sticky=tkinter.NW)

# Report button
link = ttk.Label(frame, text=t("action_mk_report"), foreground="#04F", cursor="hand2")
link.bind("<Button-1>", do_report)
link.grid(row=61, columnspan=3, padx=16, pady=4, sticky=tkinter.NW)
# link = ttk.Label(frame, text=t("action_mk_report"), foreground="#04F", cursor="hand2")
# link.bind("<Button-1>", do_report)
# link.grid(row=61, columnspan=3, padx=16, pady=4, sticky=tkinter.NW)

# Console button
link = ttk.Label(frame, text=t("action_dev_console"), foreground="#04F", cursor="hand2")
Expand Down

0 comments on commit ef5d2c9

Please sign in to comment.