Skip to content

Commit 265b1f7

Browse files
authored
Initial system GTK themes support
1 parent 0467ba3 commit 265b1f7

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

nettrayicon.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,29 @@
1414

1515
UPDATE_INTERVAL_MS = 5000
1616

17-
currpath = os.path.dirname(os.path.realpath(__file__))
18-
APP_NETWORK_ON = currpath + '/gtk-connect.svg'
19-
APP_NETWORK_OFF = currpath + '/gtk-disconnect.svg'
2017
COLLATE = "utf-8"
2118
STATUS_UP = "up"
2219
STATUS_DOWN = "down"
2320

21+
currpath = os.path.dirname(os.path.realpath(__file__))
22+
FALLBACK_APP_NETWORK_ON = currpath + '/gtk-connect.svg'
23+
FALLBACK_APP_NETWORK_OFF = currpath + '/gtk-disconnect.svg'
24+
25+
26+
def get_current_icon_theme():
27+
return Gtk.Settings.get_default().get_property("gtk-icon-theme-name")
28+
29+
30+
def set_icons():
31+
theme = get_current_icon_theme()
32+
iconpath = "/usr/share/icons/" + theme + "/scalable/status/"
33+
APP_NETWORK_ON = iconpath + 'network-idle.svg'
34+
APP_NETWORK_OFF = iconpath + 'network-offline.svg'
35+
if os.path.exists(APP_NETWORK_ON) and os.path.exists(APP_NETWORK_OFF):
36+
return APP_NETWORK_ON, APP_NETWORK_OFF
37+
else:
38+
return FALLBACK_APP_NETWORK_ON, FALLBACK_APP_NETWORK_OFF
39+
2440

2541
def get_ifaces():
2642
i = os.listdir("/sys/class/net/")
@@ -29,6 +45,7 @@ def get_ifaces():
2945

3046

3147
def update():
48+
APP_NETWORK_ON, APP_NETWORK_OFF = set_icons()
3249
ADDRINFO = []
3350
n_up = 0
3451
for IFACE in IFACES:
@@ -52,6 +69,7 @@ def update():
5269

5370

5471
if __name__ == "__main__":
72+
APP_NETWORK_ON, APP_NETWORK_OFF = set_icons()
5573
icon = Gtk.StatusIcon()
5674
icon.set_from_file(APP_NETWORK_OFF)
5775
icon.set_visible(True)

0 commit comments

Comments
 (0)