python - Print bash command result in Gtk Textview -



python - Print bash command result in Gtk Textview -

i want print file attributes using bash command , write result in textview. here path selected through select button.file path stored in text. os.system("stat"+text+"") prints on terminals.i want store result of command.

class="snippet-code-css lang-css prettyprint-override">#/usr/bin/python import pygtk,gtk,os class project: def enter_callback(self,widget,entry): entry_text=entry.get_text() print("entry contents: %s \n" % entry_text) def file_ok_sel(self,w): print("%s " % self.filew.get_filename()) text=self.filew.get_filename() print(text) os.system("stat " + text + "") def button1_select(self,widget,data=none): self.filew=gtk.fileselection("file selection") self.filew.connect("destroy",self.destroy) self.filew.ok_button.connect("clicked",self.file_ok_sel) self.filew.cancel_button.connect("clicked",lambda w:self.filew.destroy()) self.filew.set_filename("penguin.png") self.filew.show() def destroy(self,widget): print("quit") def __init__(self): self.window=gtk.window(gtk.window_toplevel) self.window.set_title("printing") self.window.connect("delete_event",lambda a1,a2:gtk.main_quit()) self.window.set_border_width(20) vbox=gtk.vbox(true,2) self.window.add(vbox) label=gtk.label("select file") label.set_alignment(0,0) vbox.pack_start(label,false,false,0) label.show() #adding textview print bash command result textview = gtk.textview() textbuffer = textview.get_buffer() self.window.add(textview) vbox.pack_start(textview,true,true,0) textview.show() vbox.show() self.window.show() #button used select file button=gtk.button("select") button.connect("clicked",self.button1_select,"select 1") vbox.pack_start(button,true,true,2) button.show() def main(): gtk.main() homecoming 0 if __name__=="__main__": project() main()

in init add together

self.textbuffer = textview.get_buffer()

then when want update it, do:

self.result = os.system("stat"+text+"") self.textbuffer.set_text(self.result)`

python bash gtk

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -