2

I'm quite new in programming, even in speaking in English.. so I'm just trying to explain my problem here:

I'm building a GUI using Glade 3, which need show all output of 'print' in a TextView or some Widgets else of Glade 3,

My python code is something like this:

#ab.py
def a():
    print 'AAAAA'

def b():
    print 'BBBBB'

and

#button_c.py
def button_c():
    if:
      print '11111'
    elif:
      print '22222'
    else:
      print '33333'

    a()
    b()

if __name__ == '__main__':

    button_c()

I'm trying use some code like this to show all of the output of 'print' in the object textview1 in a real time, just like the Python Interpreter did:

    def on_button_c_clicked(self, widget):
        button_c()
        self.builder.get_object("textview1").get_buffer().set_text(??????)

I've googled a lot and seeing something about sys.stdout, thread, subprocess and textbuffer, but I still can't figure it out, the only idea i have in the moment is change all 'print' parte of the code as:

    def a():
        # print 'AAAAA'
        output_gui = 'AAAAA'
        print output_gui
        self.builder.get_object("textview1").get_buffer().set_text(output_gui)

I haven't tried this yet because there must be another smarter way, no?

4

1 回答 1

0

您可以查看 Codimension (python IDE) 源代码。有一种解决方案。所有用 python 编写的源代码。

靠近点:

如果安装了 .deb 包(我有 Debian linux) - /usr/share/codimension/ui/mainwindow.py、CodimensionMainWindow 类、__ init__() 或来自 tarball 的同一个文件。它也使用重定向器(我认为是自己编写的)模块(非常小) - /usr/share/codimension/ui/redirector.py

于 2013-07-09T08:03:13.640 回答