我们从Python开源项目中,提取了以下21个代码示例,用于说明如何使用gi.repository.Gio.Settings()。
def Set( self ): desktops = self.desktops() if desktops and 'plasma' in desktops: print( '\n\n[KDE]' ) if self.verbose: print( '{0} Found Plasma DE installed'.format( self.date() ) ) config = os.path.join( os.path.expanduser( '~' + str( self.get_sudoer() ) ), '.kde/share/config', 'kioslaverc' ) if os.path.isfile( config ): config_file = ConfigObj( config ) section = config_file.get( 'Proxy Settings' ) section[ 'ftpProxy' ] = 'http://' + self.http section[ 'httpProxy' ] = 'http://' + self.http section[ 'httpsProxy' ] = 'http://' + self.http section[ 'socksProxy' ] = 'http://' + self.http section[ 'ProxyType' ] = 1 config_file.write( open( config, 'w' ) ) if self.verbose: print( '{0} Proxy successfully set'.format( self.date() ) ) else: if self.verbose: print( '{0} Proxy configuration file doesn\'t exist, skipping...'.format( self.date() ) ) else: if self.verbose: print( '{0} Plasma DE doesn\'t exist on this system. Skipping'.format( self.date() ) ) super( KDE, self ).Set()
def Unset( self ): desktops = self.desktops() if desktops and 'plasma' in desktops: print( '\n\n[KDE]') if self.verbose: print( '{0} Found Plasma DE installed'.format( self.date() ) ) config = os.path.join( os.path.expanduser( '~' + str( self.get_sudoer() ) ), '.kde/share/config', 'kioslaverc' ) if os.path.isfile( config ): config_file = ConfigObj( config ) section = config_file.get( 'Proxy Settings' ) section[ 'ProxyType' ] = 0 config_file.write( open( config, 'w' ) ) if self.verbose: print( '{0} Proxy successfully removed'.format( self.date() ) ) else: if self.verbose: print( '{0} Proxy configuration file doesn\'t exist, skipping...'.format( self.date() ) ) else: if self.verbose: print( '{0} Plasma DE doesn\'t exist on this system. Skipping'.format( self.date() ) ) super( KDE, self ).Unset()
def get_settings(schema_id, schema_dir=None): if not schema_dir: schema_source = Gio.SettingsSchemaSource.get_default() else: schema_source = Gio.SettingsSchemaSource.new_from_directory( schema_dir, Gio.SettingsSchemaSource.get_default(), False ) settings = schema_source.lookup(schema_id, True) if not settings: raise SettingsSchemaNotFound( 'Schema "{schema}"" could not be found'.format(schema=schema_id) ) return Gio.Settings(settings_schema=settings)
def __init_bindings(self): """ Bind Gio.Settings to widgets in settings dialog. """ sl_switch = self.settings_builder.get_object("symlinks_switch") self.settings.bind("symlinks", sl_switch, "active", Gio.SettingsBindFlags.DEFAULT) auto_scan_switch = self.settings_builder.get_object("auto_scan_switch") self.settings.bind("autoscan", auto_scan_switch, "active", Gio.SettingsBindFlags.DEFAULT) timer_suspend_switch = self.settings_builder.get_object( "timer_suspend_switch") self.settings.bind("suspend", timer_suspend_switch, "active", Gio.SettingsBindFlags.DEFAULT) replay_switch = self.settings_builder.get_object("replay_switch") self.settings.bind("replay", replay_switch, "active", Gio.SettingsBindFlags.DEFAULT)
def __load_last_book(self): """ Loads the last book into the player """ player.load_last_book() if db.Settings.get().last_played_book is not None: self.__update_track_ui() self.__update_ui_time(self.progress_scale) cur_m, cur_s = player.get_current_duration_ui() self.progress_scale.set_value(cur_m * 60 + cur_s) pos = int(player.get_current_track().position) if self.settings.get_boolean("replay"): log.info("Replaying the previous 30 seconds.") amount = 30 * 1000000000 if (pos < amount): pos = 0 else: pos = pos - amount self.progress_scale.set_value(int(pos / 1000000000))
def __on_folder_changed(self, sender): """ Clean the database when the audio book location is changed. """ log.debug("Audio book location changed, rebasing the location in db.") self.location_chooser.set_sensitive(False) settings = db.Settings.get() oldPath = settings.path settings.path = self.location_chooser.get_file().get_path() settings.save() self.switch_to_working(_("Changing audio book location..."), False) thread = Thread(target=importer.rebase_location, args=( self, oldPath, settings.path)) thread.start()
def __init__(self, uuid): super().__init__() self.uuid = uuid self.button = Gtk.ToggleButton.new() self.button.set_relief(Gtk.ReliefStyle.NONE) self.button.set_active(False) self.add(self.button) self.image = Gtk.Image.new_from_icon_name('gnome-power-manager-symbolic', Gtk.IconSize.BUTTON) self.button.add(self.image) self.button.set_tooltip_text('Disable screen dimming') self.show_all() self.power_settings = Gio.Settings(self.POWER_SCHEMA_NAME) self.desktop_settings = Gio.Settings(self.DESKTOP_SCHEMA_NAME) self.defaults = dict() # Saved settings self.button.connect_after('clicked', self.on_click)
def __init__(self): Gio.Settings.__init__(self)
def new(): gsettings = Gio.Settings.new("org.gnome.Authenticator") gsettings.__class__ = Settings return gsettings
def reset_font(self): """Sets the widget's font from GSettings, if any. """ giosss = Gio.SettingsSchemaSource.get_default() schema = giosss.lookup('org.gnome.desktop.interface', True) if not schema: self.set_font(Pango.FontDescription(string='Monospace')) return settings = Gio.Settings(settings_schema=schema) value = settings.get_string('monospace-font-name') self.set_font(Pango.FontDescription(string=value))
def new(): gsettings = Gio.Settings.new("org.gnome.IconRequests") gsettings.__class__ = Settings return gsettings
def __init__(self, program_path): Gio.Resource.load(_find_resources_path(program_path))._register() Gtk.Application.__init__(self, application_id=APP_ID, resource_base_path="/" + DEFAULT_APP_ID.replace(".", "/"), flags=Gio.ApplicationFlags.FLAGS_NONE) self.settings = Gio.Settings(schema_id=DEFAULT_APP_ID, path="/" + APP_ID.replace(".", "/") + "/") self.riot_url = self.settings.get_string("riot-url") self.window = None self.statusicon = None self.connect("shutdown", self.__on_shutdown) self.connect("activate", self.__on_activate) self.connect("startup", self.__on_startup)
def __on_startup(self, app): gtk_settings = Gtk.Settings.get_default() gtk_settings.set_property("gtk-dialogs-use-header", self.settings.get_boolean("use-header-bar")) css_provider = Gtk.CssProvider() css_provider.load_from_resource(self.get_resource_base_path() + "/gtk/custom.css") Gtk.StyleContext.add_provider_for_screen(Gdk.Screen.get_default(), css_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION) self.statusicon = StatusIcon(self) self.__action("quit", lambda *arg: self.quit()) self.__action("about", self.__on_app_about) self.__action("preferences", self.__on_app_preferences) self.__action("riot-settings", self.__on__riot_settings)
def __on_activate(self, app): if self.window is None: saved_state_path = self.settings.get_property("path") saved_state_path += "saved-state/main-window/" saved_state = Gio.Settings(schema_id=DEFAULT_APP_ID + ".WindowState", path=saved_state_path) self.window = MainWindow(self, saved_state).load_riot() self.show()
def __init_resources(self): """ Initialize all resources like gresource and glade windows. """ resource = Gio.resource_load( os.path.join(self.pkgdir, 'cozy.ui.gresource')) Gio.Resource._register(resource) resource = Gio.resource_load( os.path.join(self.pkgdir, 'cozy.img.gresource')) Gio.Resource._register(resource) self.settings = Gio.Settings.new("com.github.geigi.cozy") self.window_builder = Gtk.Builder.new_from_resource( "/de/geigi/cozy/main_window.ui") self.search_builder = Gtk.Builder.new_from_resource( "/de/geigi/cozy/search_popover.ui") self.speed_builder = Gtk.Builder.new_from_resource( "/de/geigi/cozy/playback_speed_popover.ui") self.timer_builder = Gtk.Builder.new_from_resource( "/de/geigi/cozy/timer_popover.ui") self.settings_builder = Gtk.Builder.new_from_resource( "/de/geigi/cozy/settings.ui") self.menu_builder = Gtk.Builder.new_from_resource( "/de/geigi/cozy/app_menu.ui") self.about_builder = Gtk.Builder.new_from_resource( "/de/geigi/cozy/about.ui")
def check_for_tracks(self): """ Check if there are any imported files. If there aren't display a welcome screen. """ if db.books().count() < 1: self.no_media_file_chooser.set_current_folder( db.Settings.get().path) self.main_stack.props.visible_child_name = "no_media" self.block_ui_buttons(True) self.progress_scale.set_visible(False) else: self.main_stack.props.visible_child_name = "main" self.search_button.set_sensitive(True)
def init_db_settings(self): """ Display settings from the database in the ui. """ chooser = self.settings_builder.get_object("location_chooser") chooser.set_current_folder(db.Settings.get().path)
def isA11yEnabled(): """ Checks if accessibility is enabled via DConf. """ from gi.repository.Gio import Settings try: InterfaceSettings = Settings(schema_id=a11yDConfKey) except TypeError: # if we have older glib that has deprecated param name InterfaceSettings = Settings(schema=a11yDConfKey) dconfEnabled = InterfaceSettings.get_boolean('toolkit-accessibility') if os.environ.get('GTK_MODULES', '').find('gail:atk-bridge') == -1: envEnabled = False else: envEnabled = True # pragma: no cover return (dconfEnabled or envEnabled)
def enableA11y(enable=True): """ Enables accessibility via DConf. """ from gi.repository.Gio import Settings InterfaceSettings = Settings(schema_id=a11yDConfKey) InterfaceSettings.set_boolean('toolkit-accessibility', enable)
def create_window(self): self.settings = Gio.Settings(schema="com.pia.manager") self.skip_dns = self.settings.get_boolean(SKIP_DNS_KEY) gladefile = "/usr/share/pia-manager/main.ui" self.builder = Gtk.Builder() self.builder.add_from_file(gladefile) self.window = self.builder.get_object("main_window") self.username = self.builder.get_object("entry_username") self.password = self.builder.get_object("entry_password") self.gateway = self.builder.get_object("combobox_gateway") self.button = self.builder.get_object("button_ok") self.window.set_title("PIA") self.window.set_icon_name("pia-manager") self.builder.get_object("link_forgot_password").set_markup("<a href='#'>%s</a>" % self.builder.get_object("link_forgot_password").get_text()) (username, password, self.gateway_value) = self.read_configuration() self.username.set_text(username) self.password.set_text(password) renderer = Gtk.CellRendererText() self.gateway.pack_start(renderer, True) self.gateway.add_attribute(renderer, "text", 1) self.load_combo() self.window.show() self.add_window(self.window) self.infobar = self.builder.get_object("infobar") self.infobar.hide() # Configuration self.use_ip_addresses_checkbox = self.builder.get_object("menuitem_skip_dns") self.use_ip_addresses_checkbox.set_active(self.skip_dns) # Signals self.use_ip_addresses_checkbox.connect("toggled", self.on_menuitem_use_ip_addresses_toggled) self.builder.get_object("menuitem_quit").connect("activate", self.on_quit) self.builder.get_object("menuitem_help_contents").connect("activate", self.on_menuitem_help_contents_activated) self.builder.get_object("menuitem_help_about").connect("activate", self.on_menuitem_help_about_activated) self.builder.get_object("entry_password").connect("icon-press", self.on_entry_icon_pressed) self.builder.get_object("button_cancel").connect("clicked", self.on_quit) self.builder.get_object("link_forgot_password").connect("activate-link", self.on_forgot_password_clicked) self.builder.get_object("button_refresh").connect("clicked", self.on_button_refresh_clicked) self.username.connect("changed", self.check_entries) self.password.connect("changed", self.check_entries) self.gateway.connect("changed", self.on_combo_changed) self.button.connect("clicked", self.save_configuration)