Skip to content

Commit 42224ac

Browse files
committed
Added Memory Monitor desktop Widget using GTK
1 parent 143a0fa commit 42224ac

File tree

3 files changed

+61
-0
lines changed

3 files changed

+61
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
*/.ipynb_checkpoints/*
22
.ipynb_checkpoints
33
__pycache__/
4+
.swp
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
from gi.repository import WebKit, Gtk, Gdk, Gio, GLib
2+
import signal, os
3+
import gi
4+
gi.require_version('WebKit', '3.0')
5+
class MainWin(Gtk.Window):
6+
def __init__(self):
7+
Gtk.Window.__init__(self, skip_pager_hint=True, skip_taskbar_hint=True)
8+
self.set_wmclass("sildesktopwidget","sildesktopwidget")
9+
self.set_type_hint(Gdk.WindowTypeHint.DOCK)
10+
self.set_size_request(400,20)
11+
self.set_keep_below(True)
12+
13+
#Set transparency
14+
screen = self.get_screen()
15+
rgba = screen.get_rgba_visual()
16+
self.set_visual(rgba)
17+
self.override_background_color(Gtk.StateFlags.NORMAL, Gdk.RGBA(255,0,0,1))
18+
19+
#Add all the parts
20+
self.view = WebKit.WebView()
21+
self.view.set_transparent(True)
22+
self.view.override_background_color(Gtk.StateFlags.NORMAL, Gdk.RGBA(0,255,0,0))
23+
self.view.props.settings.props.enable_default_context_menu = False
24+
pa= os.path.dirname(os.path.abspath(__file__))
25+
self.view.load_uri("file:///"+pa+"/memory.html")
26+
27+
box = Gtk.Box(spacing=6)
28+
self.add(box)
29+
box.pack_start(self.view, True, True, 0)
30+
self.set_decorated(False)
31+
self.connect("destroy", lambda q: Gtk.main_quit())
32+
33+
#Show all the parts
34+
self.show_all()
35+
self.move(100,100)
36+
37+
def refresh_file(*args):
38+
#print(args)
39+
mainwin.view.reload()
40+
41+
def file_changed(monitor, file, unknown, event):
42+
# reload
43+
GLib.timeout_add_seconds(2, refresh_file)
44+
45+
if __name__ == '__main__':
46+
pa = os.path.dirname(os.path.abspath(__file__))
47+
gio_file = Gio.File.new_for_path(pa+"/memory.html")
48+
monitor = gio_file.monitor_file(Gio.FileMonitorFlags.NONE, None)
49+
monitor.connect("changed", file_changed)
50+
51+
mainwin = MainWin()
52+
signal.signal(signal.SIGINT, signal.SIG_DFL) # make ^c work
53+
Gtk.main()
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/python3
2+
import time
3+
import os,subprocess
4+
5+
while(1):
6+
os.system("bash -c \"echo \`awk '/^Mem/' <(free -h)\`> memory.html\"")
7+
time.sleep(3)

0 commit comments

Comments
 (0)