rtcwake_gui/rtcwake_gui.py
2016-10-22 22:13:50 +02:00

74 lines
2.1 KiB
Python
Executable File

#!/usr/bin/env python3
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
import rtc
import StatusUi
import SettingsUi
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", resizable=False)
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.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'))
self.pageAbout = Gtk.Box()
self.pageAbout.set_border_width(10)
self.pageAbout.pack_start(Gtk.Label('Simple GUI for rtcwake.', selectable=True), 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()