2016-10-22 22:13:50 +02:00
|
|
|
#!/usr/bin/env python3
|
2016-10-19 00:12:14 +02:00
|
|
|
|
|
|
|
import gi
|
|
|
|
gi.require_version('Gtk', '3.0')
|
|
|
|
from gi.repository import Gtk
|
|
|
|
|
|
|
|
import rtc
|
|
|
|
import StatusUi
|
2016-10-22 22:13:50 +02:00
|
|
|
import SettingsUi
|
2016-10-19 00:12:14 +02:00
|
|
|
|
|
|
|
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):
|
2016-10-22 22:13:50 +02:00
|
|
|
Gtk.Window.__init__(self, title="RTCwake GUI", resizable=False)
|
2016-10-19 00:12:14 +02:00
|
|
|
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'))
|
|
|
|
|
|
|
|
|
2016-10-22 22:13:50 +02:00
|
|
|
self.pageSettings = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=10)
|
|
|
|
self.pageSettings.set_border_width(10)
|
|
|
|
|
|
|
|
self.settingUi = SettingsUi.Form(self, self.pageSettings, self.devices)
|
|
|
|
|
|
|
|
self.notebook.append_page(self.pageSettings, Gtk.Label('Settings'))
|
|
|
|
|
|
|
|
|
2016-10-19 00:12:14 +02:00
|
|
|
self.pageAbout = Gtk.Box()
|
|
|
|
self.pageAbout.set_border_width(10)
|
2016-10-22 22:13:50 +02:00
|
|
|
self.pageAbout.pack_start(Gtk.Label('Simple GUI for rtcwake.', selectable=True), True, True, 0)
|
2016-10-19 00:12:14 +02:00
|
|
|
|
|
|
|
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()
|