Skip to content

Instantly share code, notes, and snippets.

@jtsagata
Created September 28, 2017 16:14
Show Gist options
  • Select an option

  • Save jtsagata/23a2e98d7da426e7ca541a5ad33c1e04 to your computer and use it in GitHub Desktop.

Select an option

Save jtsagata/23a2e98d7da426e7ca541a5ad33c1e04 to your computer and use it in GitHub Desktop.
A Simple GUI to show syslog
#!/usr/bin/python3
import signal, os, gi
# You may need to adjust the versions, or just comment
gi.require_version('Gtk', '3.0')
gi.require_version('Vte', '2.91')
from gi.repository import GLib, Gtk, Vte, Gdk, Pango
signal.signal(signal.SIGINT, signal.SIG_DFL)
# Window
win = Gtk.Window()
win.set_icon_name('utilities-log-viewer')
win.set_title("System Logger")
win.connect('delete-event', Gtk.main_quit)
# Move to bottom left
screen=Gdk.Screen.get_default()
win.set_gravity(Gdk.Gravity.SOUTH_EAST)
win.move(screen.get_width(),screen.get_height())
# Command to run
log_file="/var/log/syslog"
sub_cmd="clear ; tail -f %s | ccze -A" % log_file
command='exec bash -c "%s"\n' % sub_cmd
# Terminal
term = Vte.Terminal()
pty_flags = Vte.PtyFlags.DEFAULT
home_dir = os.environ['HOME']
spawn_flage = GLib.SpawnFlags.DO_NOT_REAP_CHILD
term.spawn_sync(pty_flags, home_dir, ['/bin/bash'], [], spawn_flage)
term.feed_child(command, len(command))
term.connect('child-exited', Gtk.main_quit)
# Font for terminal
font = Pango.FontDescription()
font.set_family("Ubuntu Mono")
font.set_size(9 * Pango.SCALE)
term.set_font(font)
term.set_size(160,15)
win.add(term)
win.show_all()
Gtk.main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment