I tried this too, and this didnt work, the command runs, but the gui is locked
Code:
#!/usr/bin/env python
import pygtk
import os, threading, locale
pygtk.require("2.0")
import gtk
import gtk.glade
encoding = locale.getpreferredencoding()
utf8conv = lambda x : unicode(x, encoding).encode('utf8')
class main:
def __init__(self):
self.principal = gtk.glade.XML("lazy.glade")
dic = {"on_principal_destroy" : self.Destroy,
"on_btn_apply_clicked" : self.Apply,
"on_btn_quit_clicked" : self.Destroy}
self.principal.signal_autoconnect(dic)
self.list()
self.terminal()
gtk.main()
def Destroy(self, *args):
gtk.main_quit()
def list(self):
tree = self.principal.get_widget("list")
self.list = gtk.ListStore(bool,str)
options = [[1,"programa1"],[2,"programa2"],[3,"programa3"]]
renderer1 = gtk.CellRendererToggle()
renderer1.set_property('activatable', True)
renderer1.connect( 'toggled', self.selection, self.list)
tree.insert_column_with_attributes(0, "Select",renderer1, active=0)
renderer2 = gtk.CellRendererText()
tree.insert_column_with_attributes(1,"Install",renderer2, text=1)
i = 0
for option in options:
self.list.append(option)
self.list[i][0] = False
i += 1
tree.set_model(self.list)
def Apply(self, obj):
thr = threading.Thread(target= self.read_output, args=(self.textbuffer, self.command))
thr.run()
def terminal(self):
self.command = "ls -R"
textview = self.principal.get_widget("terminal")
self.textbuffer = textview.get_buffer()
def read_output(self, buffer, command):
stdin, stdouterr = os.popen4(command)
for line in stdouterr.readlines():
buffer.insert(buffer.get_end_iter(), utf8conv(line))
def selection( self, cell, path, model ):
model[path][0] = not model[path][0]
a = testit(self.textbuffer)
a.start()
# self.textbuffer.set_text(subprocess.Popen(cmd, shell=True, bufsize=1024, stdout=subprocess.PIPE).stdout)
return
main()
The lazy.glade and lazy.py are attached, thanx.
Bookmarks