Advertisement
Guest User

Untitled

a guest
Sep 17th, 2013
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.12 KB | None | 0 0
  1. #! usr/bin/env python
  2.  
  3. # GUI of main window
  4.  
  5. import pygtk
  6. pygtk.require('2.0')
  7. import gtk
  8. import gtk.glade
  9.  
  10.  
  11. import time
  12. from multiprocessing import Process
  13. import threading
  14.  
  15. class sample():
  16.    
  17.     def __init__(self , testmode ):
  18.        
  19.         self.builder = gtk.Builder()
  20.         self.builder.add_from_file('test.glade')
  21.         self.list_store = self.builder .get_object('liststore1')
  22.         self.win = self.builder.get_object('window1')
  23.         self.win.set_default_size(200 , 400)
  24.         self.win.show()
  25.         self.list_ = [0,31,2,5,4,61,8,20,10]
  26.        
  27.         if testmode == '0' or testmode == 'normal' :
  28.             for item in self.list_  :
  29.                     item = [item]
  30.                     print item
  31.                     self.list_store.prepend(item)
  32.                    
  33.         elif testmode == '1' or testmode == 'loop':
  34.             gtk.gdk.threads_enter()
  35.             tar = self.list_updater
  36.             arg = ()
  37.             t = Process(target = tar , args = arg )
  38.             t.start()
  39.             gtk.gdk.threads_leave()
  40.  
  41.        
  42.     def list_updater(self ):
  43.        
  44.        
  45.             while True:    
  46.                
  47.                 for item in self.list_  :
  48.                     item = [item]
  49.                     print item
  50.                     self.list_store.prepend(item)
  51.                     time.sleep(1)
  52.                            
  53.                        
  54.         ###############################################4
  55.                  
  56.    
  57.        
  58.     def main(self):
  59.         gtk.main()
  60.        
  61. if __name__ == '__main__':
  62.     testmode= raw_input('''please enter 0 or 1 \n
  63.      enter  0 or 'normal' to show the result without error
  64.      the treeview will be filled with  9 rows \n \n
  65.      enter 1 or loop to show the error occuring in the loop mode \n
  66.      \n error is : no rows added to the gtk treeview despite of the code works well in the background
  67.      the expected action is continious adding of rows in each cycle of the loop
  68.      ''')
  69.     sample1 = sample(testmode)
  70.     gtk.gdk.threads_enter()
  71.     sample1.main()
  72.     gtk.gdk.threads_leave()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement