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

📄 example-2.py

📁 Developing with Gnome一书examples例子代码
💻 PY
字号:
#!/usr/bin/env python# This program displays a "pulsing" (or whatever it's called)# ProgressBar, adds a timeout function to keep it updated, and shows# how to obtain an individual widget that libglade created.## Note that most programs update progress bars during some kind of# function that doesn't return to the main event loop (unlike this# simple example).  In that case, you must manually tell gtk to update# widgets yourself by calling gtk.events_pending() and# gtk.main_iteration().  (See example-3.py for an example of doing# this in a different context).import gtkimport gtk.gladeimport timeclass WasteTimeWindow:  def __init__(self, glade_file):    # Parse the glade file    self.what_a_waste = gtk.glade.XML(glade_file)    # Get the progress bar widget and change it to "activity mode",    # i.e. a block that bounces back and forth instead of a normal    # progress bar that fills to completion.    self.progress_bar = self.what_a_waste.get_widget("Progress Bar")    self.progress_bar.pulse()    # Add a timeout to update the progress bar every 100 milliseconds or so    self.timeout_handler_id = gtk.timeout_add(100, self.update_progress_bar)    # Start a timer to see how long the user runs this program    self.start = time.time()    # Connect signals specified in the .glade file    self.what_a_waste.signal_autoconnect(      {"inform_user_of_time_wasted" : self.inform_user_of_time_wasted })  # This is the callback for the delete_event, i.e. window closing  def inform_user_of_time_wasted(self, window, event):    # Tell the user how much time they used    print 'You wasted %.2f seconds with this program' % (time.time()-self.start)    # Remove the timer so that gtk doesn't try to keep updating the progress bar    gtk.timeout_remove(self.timeout_handler_id)    # Make the main event loop quit    gtk.mainquit()    # No other handlers need be called...    return gtk.FALSE  def update_progress_bar(self):    self.progress_bar.pulse()    # Return true so the function will be called again; returning    # false removes this timeout function.    return gtk.TRUE# Create the WasteTimeWindowwindow = WasteTimeWindow("example-2.glade")# start the event loopgtk.main()

⌨️ 快捷键说明

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