bluez-utils instead of python-pybluez #72

This commit is contained in:
piotr
2021-12-14 01:08:23 +01:00
parent e69b01d93b
commit 0005c1db1f
6 changed files with 37 additions and 18 deletions

View File

@@ -28,6 +28,7 @@ commands = {
"playerctl": False, "playerctl": False,
"netifaces": False, "netifaces": False,
"pybluez": False, "pybluez": False,
"btmgmt": False,
"wlr-randr": False, "wlr-randr": False,
"upower": False "upower": False
} }

View File

@@ -1903,7 +1903,11 @@ class EditorWrapper(object):
self.ctrl_comp_net.set_active("net" in settings["components"]) self.ctrl_comp_net.set_active("net" in settings["components"])
self.ctrl_comp_bluetooth = builder.get_object("ctrl-comp-bluetooth") self.ctrl_comp_bluetooth = builder.get_object("ctrl-comp-bluetooth")
self.ctrl_comp_bluetooth.set_active("bluetooth" in settings["components"]) if is_command("btmgmt"):
self.ctrl_comp_bluetooth.set_active("bluetooth" in settings["components"])
else:
self.ctrl_comp_bluetooth.set_active(False)
self.ctrl_comp_bluetooth.set_sensitive(False)
self.ctrl_comp_battery = builder.get_object("ctrl-comp-battery") self.ctrl_comp_battery = builder.get_object("ctrl-comp-battery")
self.ctrl_comp_battery.set_active("battery" in settings["components"]) self.ctrl_comp_battery.set_active("battery" in settings["components"])

View File

@@ -2,7 +2,7 @@
<!-- Generated with glade 3.38.2 --> <!-- Generated with glade 3.38.2 -->
<interface> <interface>
<requires lib="gtk+" version="3.24"/> <requires lib="gtk+" version="3.24"/>
<!-- n-columns=4 n-rows=12 --> <!-- n-columns=4 n-rows=13 -->
<object class="GtkGrid" id="grid"> <object class="GtkGrid" id="grid">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can-focus">False</property> <property name="can-focus">False</property>
@@ -107,8 +107,7 @@
<object class="GtkImage"> <object class="GtkImage">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can-focus">False</property> <property name="can-focus">False</property>
<property name="tooltip-text" translatable="yes">Depends on `python-pybluez` <property name="tooltip-text" translatable="yes">Depends on `bluez-utils`.</property>
(python3-bluez / p3-bluez).</property>
<property name="halign">start</property> <property name="halign">start</property>
<property name="stock">gtk-about</property> <property name="stock">gtk-about</property>
</object> </object>
@@ -215,7 +214,7 @@ Depends on `python-netifaces`.</property>
<object class="GtkImage"> <object class="GtkImage">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can-focus">False</property> <property name="can-focus">False</property>
<property name="tooltip-text" translatable="yes">Depends on the `light` package.</property> <property name="tooltip-text" translatable="yes">Depends on `light` or `brightnessctl`.</property>
<property name="halign">start</property> <property name="halign">start</property>
<property name="stock">gtk-about</property> <property name="stock">gtk-about</property>
</object> </object>
@@ -460,5 +459,11 @@ Depends on `python-netifaces`.</property>
<child> <child>
<placeholder/> <placeholder/>
</child> </child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
</object> </object>
</interface> </interface>

View File

@@ -11,7 +11,7 @@ gi.require_version('GtkLayerShell', '0.1')
from gi.repository import Gtk, Gdk, GLib, GtkLayerShell from gi.repository import Gtk, Gdk, GLib, GtkLayerShell
from nwg_panel.tools import check_key, get_brightness, set_brightness, get_volume, set_volume, get_battery, \ from nwg_panel.tools import check_key, get_brightness, set_brightness, get_volume, set_volume, get_battery, \
get_interface, update_image, bt_adr, eprint, list_sinks, toggle_mute get_interface, update_image, bt_info, eprint, list_sinks, toggle_mute
from nwg_panel.common import commands from nwg_panel.common import commands
@@ -130,10 +130,10 @@ class Controls(Gtk.EventBox):
self.net_ip_addr = get_interface(self.settings["net-interface"]) self.net_ip_addr = get_interface(self.settings["net-interface"])
GLib.idle_add(self.update_net, self.net_ip_addr) GLib.idle_add(self.update_net, self.net_ip_addr)
if commands["pybluez"]: if commands["btmgmt"]:
adr = bt_adr() name, powered = bt_info()
if "bluetooth" in self.settings["components"]: if "bluetooth" in self.settings["components"]:
GLib.idle_add(self.update_bt, adr) GLib.idle_add(self.update_bt, name, powered)
if "brightness" in self.settings["components"]: if "brightness" in self.settings["components"]:
try: try:
@@ -180,15 +180,15 @@ class Controls(Gtk.EventBox):
if self.net_label: if self.net_label:
self.net_label.set_text("{}".format(self.settings["net-interface"])) self.net_label.set_text("{}".format(self.settings["net-interface"]))
def update_bt(self, adr): def update_bt(self, name, powered):
icon_name = "bluetooth-active-symbolic" if adr != "off" else "bluetooth-disabled-symbolic" icon_name = "bluetooth-active-symbolic" if powered else "bluetooth-disabled-symbolic"
if icon_name != self.bt_icon_name: if icon_name != self.bt_icon_name:
update_image(self.bt_image, icon_name, self.icon_size, self.icons_path) update_image(self.bt_image, icon_name, self.icon_size, self.icons_path)
self.bt_icon_name = icon_name self.bt_icon_name = icon_name
self.bt_name = adr self.bt_name = name
if self.bt_label: if self.bt_label:
self.bt_label.set_text(adr) self.bt_label.set_text(name)
def update_brightness(self): def update_brightness(self):
value = get_brightness() value = get_brightness()

View File

@@ -605,12 +605,21 @@ def create_pixbuf(icon_name, icon_size, icons_path=""):
return pixbuf return pixbuf
def bt_adr(): def bt_info():
name, powered = "", False
try: try:
adr = bluetooth.read_local_bdaddr() info = subprocess.check_output("btmgmt info", shell=True).decode("utf-8").strip().splitlines()
return adr[0] for line in info:
if "current settings" in line:
if "powered" in line:
powered = True
continue
if "name" in line and "short" not in line:
name = line.split("name")[1].strip()
except: except:
return "off" pass
return name, powered
def list_configs(config_dir): def list_configs(config_dir):

View File

@@ -8,7 +8,7 @@ def read(f_name):
setup( setup(
name='nwg-panel', name='nwg-panel',
version='0.5.1', version='0.5.2',
description='GTK3-based panel for sway window manager', description='GTK3-based panel for sway window manager',
packages=find_packages(), packages=find_packages(),
include_package_data=True, include_package_data=True,