Skip to content

Commit

Permalink
Cleanup code
Browse files Browse the repository at this point in the history
Merge all config file opening script in a function
  • Loading branch information
XAli-SHX committed Mar 17, 2023
1 parent 834e960 commit bc8237a
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions main.pyw
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def sendNotification(title: str, text: str):
notification.send(block=False)


def onIconClicked(stray, query):
def onIconRightClicked(stray, query):
query = str(query)
config = Config()
if query == Const.STRAY_ENABLE:
Expand All @@ -84,7 +84,7 @@ def onIconClicked(stray, query):
config.en = False
sendNotification("Alert Disabled", "You can turn it on from the system tray icon.")
elif query == Const.STRAY_OPEN_CONFIG:
os.startfile(str(os.path.dirname(os.path.abspath(__file__))) + '\\config.txt')
openConfigFile()
elif query == Const.STRAY_EXIT:
config.en = False
config.writeConfig()
Expand All @@ -93,15 +93,24 @@ def onIconClicked(stray, query):
config.writeConfig()


# left click on icon is currently not supported by pystray library
def onIconLeftClicked(icon, item):
openConfigFile()


def openConfigFile():
os.startfile(str(os.path.dirname(os.path.abspath(__file__))) + '\\config.txt')


def setupStray():
image = Image.open("./assets/icon.png")
stray = pystray.Icon("Battery-Percentage-Alert", image,
"Battery-Percentage-Alert",
menu=pystray.Menu(
pystray.MenuItem(Const.STRAY_ENABLE, onIconClicked),
pystray.MenuItem(Const.STRAY_DISABLE, onIconClicked),
pystray.MenuItem(Const.STRAY_OPEN_CONFIG, onIconClicked),
pystray.MenuItem(Const.STRAY_EXIT, onIconClicked)))
pystray.MenuItem(Const.STRAY_ENABLE, onIconRightClicked),
pystray.MenuItem(Const.STRAY_DISABLE, onIconRightClicked),
pystray.MenuItem(Const.STRAY_OPEN_CONFIG, onIconRightClicked),
pystray.MenuItem(Const.STRAY_EXIT, onIconRightClicked)))
stray.run()


Expand Down

0 comments on commit bc8237a

Please sign in to comment.