def __init__(self, battery): GObject.GObject.__init__(self) self._battery = UPowerGlib.Device() self._battery.set_object_path_sync(battery, None) self._connect_battery() self._fetch_properties_from_upower() self._timeout_sid = False
def __init__(self, battery): GObject.GObject.__init__(self) self._battery = UPowerGlib.Device() self._battery.set_object_path_sync(battery, None) self._connect_battery() self._fetch_properties_from_upower() self._timeout_sid = False self.warning_capacity = _settings_get('warning-capacity') self._minimum_capacity = _settings_get('minimum-capacity') self._grace_time = _settings_get('grace-time') self._grace = time.time()
def on_module_selected(self): if self.loaded: # self.loaded = False return print "Loading Power module" self.up_client = UPowerGlib.Client() self.csd_power_proxy = Gio.DBusProxy.new_sync( Gio.bus_get_sync(Gio.BusType.SESSION, None), Gio.DBusProxyFlags.NONE, None, "org.cinnamon.SettingsDaemon", "/org/cinnamon/SettingsDaemon/Power", "org.cinnamon.SettingsDaemon.Power", None) device_types = [x[1] for x in self.csd_power_proxy.GetDevices()] self.has_battery = UPowerGlib.DeviceKind.BATTERY in device_types or UPowerGlib.DeviceKind.UPS in device_types self.has_lid = self.up_client.get_lid_is_present() self.sidePage.stack = SettingsStack() self.sidePage.add_widget(self.sidePage.stack) # Power power_page = SettingsPage() section = power_page.add_section(_("Power Options")) lid_options, button_power_options, critical_options = get_available_options( self.up_client) size_group = Gtk.SizeGroup(mode=Gtk.SizeGroupMode.HORIZONTAL) if self.has_battery: header = SettingsWidget() label_ac = Gtk.Label() label_ac.set_markup("<b>%s</b>" % _("On A/C power")) size_group.add_widget(label_ac) label_battery = Gtk.Label() label_battery.set_markup("<b>%s</b>" % _("On battery power")) size_group.add_widget(label_battery) header.pack_end(label_battery, False, False, 0) header.pack_end(label_ac, False, False, 0) section.add_row(header) section.add_row( GSettings2ComboBox(_("Turn off the screen when inactive for"), CSD_SCHEMA, "sleep-display-ac", "sleep-display-battery", SLEEP_DELAY_OPTIONS, valtype="int", size_group=size_group)) section.add_row( GSettings2ComboBox(_("Suspend when inactive for"), CSD_SCHEMA, "sleep-inactive-ac-timeout", "sleep-inactive-battery-timeout", SLEEP_DELAY_OPTIONS, valtype="int", size_group=size_group)) if self.has_lid: section.add_row( GSettings2ComboBox(_("When the lid is closed"), CSD_SCHEMA, "lid-close-ac-action", "lid-close-battery-action", lid_options, size_group=size_group)) else: section.add_row( GSettingsComboBox(_("Turn off the screen when inactive for"), CSD_SCHEMA, "sleep-display-ac", SLEEP_DELAY_OPTIONS, valtype="int", size_group=size_group)) section.add_row( GSettingsComboBox(_("Suspend when inactive for"), CSD_SCHEMA, "sleep-inactive-ac-timeout", SLEEP_DELAY_OPTIONS, valtype="int", size_group=size_group)) if self.has_lid: section.add_row( GSettingsComboBox(_("When the lid is closed"), CSD_SCHEMA, "lid-close-ac-action", lid_options, size_group=size_group)) section = power_page.add_section(_("Extra options")) size_group = Gtk.SizeGroup(mode=Gtk.SizeGroupMode.HORIZONTAL) section.add_row( GSettingsComboBox(_("When the power button is pressed"), CSD_SCHEMA, "button-power", button_power_options, size_group=size_group)) if self.has_battery and UPowerGlib.MAJOR_VERSION == 0 and UPowerGlib.MINOR_VERSION < 99: section.add_row( GSettingsComboBox(_("When the battery is critically low"), CSD_SCHEMA, "critical-battery-action", critical_options, size_group=size_group)) # Batteries self.battery_page = SettingsPage() self.show_battery_page = False self.battery_label_size_group = Gtk.SizeGroup( Gtk.SizeGroupMode.HORIZONTAL) self.build_battery_page() self.csd_power_proxy.connect("g-properties-changed", self.build_battery_page) primary_output = None try: screen = CinnamonDesktop.RRScreen.new(Gdk.Screen.get_default()) outputs = CinnamonDesktop.RRScreen.list_outputs(screen) for output in outputs: if (output.is_connected() and output.is_laptop()): try: # Try to get the backlight info, if it fails just move on (we used to rely on output.get_backlight_min() and output.get_backlight_max() but these aren't reliable) output.get_backlight() primary_output = output break except: pass except Exception, detail: print "Failed to query backlight information in cs_power module: %s" % detail