72 lines
1.9 KiB
Python
72 lines
1.9 KiB
Python
|
#!/usr/bit/python
|
||
|
|
||
|
import gi
|
||
|
gi.require_version('Gtk', '3.0')
|
||
|
from gi.repository import Gtk
|
||
|
|
||
|
import rtc
|
||
|
import StatusUi
|
||
|
|
||
|
def readFile(path):
|
||
|
file = open(path)
|
||
|
value = file.read()
|
||
|
file.close()
|
||
|
|
||
|
return value.rstrip()
|
||
|
|
||
|
class MyWindow(Gtk.Window):
|
||
|
devices = {}
|
||
|
statusBoxes = {}
|
||
|
|
||
|
def __init__(self):
|
||
|
self.initRTC()
|
||
|
self.initUI()
|
||
|
|
||
|
def initRTC(self):
|
||
|
for device in rtc.getDevices():
|
||
|
self.devices[device] = rtc.RtcDevice(name=device)
|
||
|
|
||
|
def initUI(self):
|
||
|
Gtk.Window.__init__(self, title="RTCwake GUI")
|
||
|
self.set_border_width(3)
|
||
|
|
||
|
self.notebook = Gtk.Notebook()
|
||
|
self.add(self.notebook)
|
||
|
|
||
|
self.pageStatus = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
|
||
|
self.pageStatus.set_border_width(10)
|
||
|
|
||
|
for name, device in self.devices.items():
|
||
|
self.statusBoxes[name] = StatusUi.StatusDevice(self.pageStatus, device)
|
||
|
|
||
|
buttonRefresh = Gtk.Button.new_with_label("Refresh")
|
||
|
buttonRefresh.connect("clicked", self.buttonRefresh_on_click)
|
||
|
|
||
|
self.pageStatus.pack_start(buttonRefresh, False, True, 0)
|
||
|
|
||
|
self.notebook.append_page(self.pageStatus, Gtk.Label('Status'))
|
||
|
|
||
|
|
||
|
self.pageAbout = Gtk.Box()
|
||
|
self.pageAbout.set_border_width(10)
|
||
|
self.pageAbout.pack_start(Gtk.Label('Simple GUI for rtcwake.'), True, True, 0)
|
||
|
|
||
|
self.notebook.append_page(self.pageAbout, Gtk.Label('About'))
|
||
|
|
||
|
def initShow(self):
|
||
|
self.show_all()
|
||
|
|
||
|
for name, device in self.devices.items():
|
||
|
if not self.devices[name].devStatus["active"]:
|
||
|
self.statusBoxes[name].line3.box.hide()
|
||
|
|
||
|
def buttonRefresh_on_click(self, button):
|
||
|
for name, device in self.devices.items():
|
||
|
device.status()
|
||
|
self.statusBoxes[name].update()
|
||
|
|
||
|
win = MyWindow()
|
||
|
win.connect("delete-event", Gtk.main_quit)
|
||
|
win.initShow()
|
||
|
Gtk.main()
|