コード例 #1
0
ファイル: config_ui.py プロジェクト: izderadicka/thetool
 def __init__(self, settings, power_actions, nm, parent=None):
     self.power_actions = power_actions
     self.dirty = set()
     self.pending_update_id = None
     self.settings = settings
     Gtk.Dialog.__init__(self, "Settings", parent, Gtk.DialogFlags.MODAL, (Gtk.STOCK_CLOSE, Gtk.ResponseType.CLOSE))
     self.ui = UiHelper(self)
     self.get_content_area().add(self.ui.get_widget(self.UI_ROOT))
     self._connect_widgets()
     self.nm = nm
     self.connect("response", self.on_close)
     self.connect("delete-event", lambda x, y: self.hide_on_delete())
コード例 #2
0
ファイル: config_ui.py プロジェクト: izderadicka/thetool
class SettingsDialog(Gtk.Dialog):
    UI_FILES = ["settings.ui"]
    UI_ROOT = "settings"

    def __init__(self, settings, power_actions, nm, parent=None):
        self.power_actions = power_actions
        self.dirty = set()
        self.pending_update_id = None
        self.settings = settings
        Gtk.Dialog.__init__(self, "Settings", parent, Gtk.DialogFlags.MODAL, (Gtk.STOCK_CLOSE, Gtk.ResponseType.CLOSE))
        self.ui = UiHelper(self)
        self.get_content_area().add(self.ui.get_widget(self.UI_ROOT))
        self._connect_widgets()
        self.nm = nm
        self.connect("response", self.on_close)
        self.connect("delete-event", lambda x, y: self.hide_on_delete())

    def set_netmanager(self, nm):
        self.nm = nm

    def on_close(self, dialog, resp_id, data=None):
        log.debug("Close settings")
        self.hide()

    def _connect_widgets(self):
        self.settings.bind(
            "enable-notifications", self.ui.get_widget("enable-notifications"), "active", Gio.SettingsBindFlags.DEFAULT
        )
        self.settings.bind(
            "monitor-networks", self.ui.get_widget("monitor-networks"), "active", Gio.SettingsBindFlags.DEFAULT
        )

        self.settings.bind(
            "notify-before-poweroff",
            self.ui.get_widget("notify-before-poweroff"),
            "value",
            Gio.SettingsBindFlags.DEFAULT,
        )
        self.settings.bind(
            "player-poweroff-timeout",
            self.ui.get_widget("player-poweroff-timeout"),
            "value",
            Gio.SettingsBindFlags.DEFAULT,
        )
        self.settings.bind("actions-file", self.ui.get_widget("actions-file"), "text", Gio.SettingsBindFlags.DEFAULT)

        self.ui.get_widget("power-off-intervals").set_text(
            utils.list_to_string(self.settings.get_unpacked("poweroff-intervals"))
        )
        self._validator_po = Validator(
            self.ui.get_widget("power-off-intervals"),
            allowed_chars="0123456789, ",
            regexp=r"(\d{1,6}\s?,?\s?){1,20}",
            min_length=1,
            on_check=self.on_power_off_intervals_changed,
            no_cb_inittialy=True,
        )

        wnames = ("shutdown", "suspend", "hibernate")
        for name in wnames:
            if self.power_actions.get_action(name).get_active():
                self.ui.get_widget(name).set_active(True)
        for name in wnames:
            self.ui.get_widget(name).connect("toggled", self.on_poweroff_type_activate, name)

    def on_poweroff_type_activate(self, item, name):
        if item.get_active():
            log.debug("Power Off radio selected  %s", name)
            self.power_actions.get_action(name).set_active(True)

    def on_power_off_intervals_changed(self, valid, item):
        log.debug("Power Intervals changed  to %s", item.get_text())
        if valid:
            self._plan_update("power-off-intervals")

    def _plan_update(self, item):
        self.dirty.add(item)
        if self.pending_update_id:
            GLib.source_remove(self.pending_update_id)
        self.pending_update_id = GLib.timeout_add(2000, self.do_update)

    def do_update(self):
        for name in self.dirty:
            log.debug("Syncing data to %s settings", name)
            wgt = self.ui.get_widget(name)
            if name == "power-off-intervals":
                try:
                    list = utils.string_to_list(wgt.get_text())
                except Exception, e:
                    log.debug("invalid value of list %s", e)
                    # wgt.override_color(Gtk.StateFlags.NORMAL, Gdk.RGBA(1.0, 0.0, 0.0, 1.0) )
                else:
                    # wgt.override_color(Gtk.StateFlags.NORMAL, None)
                    self.settings.set_formatted("poweroff-intervals", list, "ai")
        self.dirty.clear()
        self.pending_update_id = None
        return False