⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 example-1.py

📁 Developing with Gnome一书examples例子代码
💻 PY
字号:
#!/usr/bin/env python# This program monitors the /apps/metacity/general/reduced_resources# gconf key, and allows the user to change it as well.import gtkimport gtk.gladeimport gconfclass ExampleWindow:  def __init__(self, glade_file):    # Parse the glade file    self.all_da_widgets = gtk.glade.XML(glade_file)    # Get the GConf::Client, tell it we want to monitor /apps/metacity/general    self.conf_client = gconf.client_get_default()    self.conf_client.add_dir("/apps/metacity/general", gconf.CLIENT_PRELOAD_NONE)    # Get the check_button    self.checkbutton = self.all_da_widgets.get_widget("Reduced Resources")    # Connect the check_button to a callback that can toggle it when the option    # is changed by some outside program.    self.conf_client.notify_add("/apps/metacity/general/reduced_resources", \                                self.key_changed);    # Connect the check_button's clicked callback up so that it can change the    # gconf setting.    self.checkbutton.connect("clicked", self.checkbutton_toggled)    # Determine whether button should start activated or not    self.old_setting = \      self.conf_client.get_bool("/apps/metacity/general/reduced_resources")    self.checkbutton.set_active(self.old_setting)    # Get the close button and connect it to hide    close_button = self.all_da_widgets.get_widget("CloseButton")    close_button.connect("clicked", gtk.mainquit)    # Get the close button and connect it to hide    main_window = self.all_da_widgets.get_widget("MainWindow")    main_window.connect("delete_event", gtk.mainquit)  def key_changed(self, client, connection_id, entry, args):    # Make sure the preference has a valid value    if (entry.get_value().type == gconf.VALUE_BOOL):      # Get the new value      new_setting = entry.get_value().get_bool()      # Try to handle asynchronous-ness of GConf and prevent calling      # checkbutton_toggled again if this function was called as a      # result of the self.conf_client.set() function call.      if (new_setting != self.old_setting):        self.old_setting = new_setting;        self.checkbutton.set_active(new_setting);  def checkbutton_toggled(self, checkbutton_widget):    # Determine whether the checkbutton is already set or not    is_set = self.checkbutton.get_active()     # Try to handle asynchronous-ness of GConf and prevent calling    # key_changed again if this function was called as a result of the    # self.checkbutton.set_active() function call.    if (is_set != self.old_setting):      self.old_setting = is_set      self.conf_client.set_bool("/apps/metacity/general/reduced_resources", \                                is_set)# Create the ExampleWindowwindow = ExampleWindow("example-1.glade")# start the event loopgtk.main()

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -