Skip to content

Commit

Permalink
reload battery status
Browse files Browse the repository at this point in the history
  • Loading branch information
agnesk92 committed Dec 30, 2020
1 parent b2df72b commit ca17e04
Showing 1 changed file with 18 additions and 29 deletions.
47 changes: 18 additions & 29 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,57 +16,46 @@ def __init__(self, icon, parent=None, app=None):
menu = QMenu(parent)
self.app = app

reloadAction = menu.addAction("Reload..")
reloadAction.triggered.connect(self.reload_tooltip)

exitAction = menu.addAction("Exit")
exitAction.triggered.connect(self.close)

self.setContextMenu(menu)

def reload_tooltip(self):
print("Getting battery levels..")
b_left, b_right, b_case = get_earbud_battery_info()
tooltip_battery = f"Battery {b_left}%, {b_right}%, {b_case}%"
self.setToolTip(tooltip_battery)

def close(self):
print("Exiting app")
self.app.quit()


def get_earbud_info():
def get_earbud_battery_info():
approx_name = "Galaxy Buds"
device_manager = DeviceInfo()

# conndevs = device_manager.connected_devices
# print(conndevs)

name = device_manager.get_similar_device_names(approx_name)[0]
print(name)

address = device_manager.get_device_address(name)
print(address)

is_conn = device_manager.is_device_connected(address=address)
print(f"Is conn: {is_conn}")


def main():
print("Getting battery levels..")
device_man = DeviceInfo()
device_name = device_man.get_similar_device_names("Galaxy Buds")[0]
device_name = device_man.get_similar_device_names(approx_name)[0]
device_address = device_man.get_device_address(device_name)

b_left, b_right, b_case = get_battery_levels(device_address)
# b_left = 95
# b_right = 95
# b_case = 17

return get_battery_levels(device_address)

def main():
print("Create app")
app = QApplication(sys.argv)
buds_widget = QWidget()

print("Creating tray icon..")
trayIcon = SystemTrayIcon(QtGui.QIcon("galaxy-icon.png"), buds_widget, app=app)

# tooltip_battery = QtCore.QString("battery level indicator")
# tooltip_battery = QtCore.RichText("<b>bold</b> text")
# tooltip_battery = "<b>bold</b> text"
print("Getting battery levels..")
b_left, b_right, b_case = get_earbud_battery_info()

tooltip_battery = f"Battery {b_left}%, {b_right}%, {b_case}%"
trayIcon.setToolTip(tooltip_battery)
trayIcon.toolTip() #.setText("test3")
trayIcon.toolTip()
trayIcon.show()

sys.exit(app.exec_())
Expand Down

0 comments on commit ca17e04

Please sign in to comment.