Output to a text window

G

google

Hi,

I'm going around in circles so I'm asking for help. I want to read a
simple text file and output the contents to a GUI window when I click
on a button. I have written a small python program to read the
contents of a file when a button is clicked but can only output this
to a console window. I'm using the pygtk binding with glade for the
gui.

I know it must be quiet simple but a mental block has rapidly
descended.

Any help would be appreciated.
 
J

Joshua J. Kugler

Hi,

I'm going around in circles so I'm asking for help. I want to read a
simple text file and output the contents to a GUI window when I click
on a button. I have written a small python program to read the
contents of a file when a button is clicked but can only output this
to a console window. I'm using the pygtk binding with glade for the
gui.

I know it must be quiet simple but a mental block has rapidly
descended.

Any help would be appreciated.

What does your code look like? What are you using to print? Are you
writing to the GUI or using the 'print statement?'

j
 
G

google

What does your code look like? What are you using to print? Are you
writing to the GUI or using the 'print statement?'

j

This is the code, it was adapted from code I found on the net. Code as
follows,

#!/usr/bin/python

import pygtk
import gtk
import gtk.glade
import string
import os
import gobject

class gui:
def __init__(self):
self.wTree=gtk.glade.XML('dansgui.glade')
dic = { "on_Read_File": self.on_Read_File,
"on_cancel": (gtk.main_quit)}
self.wTree.signal_autoconnect(dic)
self.count = 0
self.win = self.wTree.get_widget("window1")
self.win.connect("delete_event", self.on_delete_event)
self.win.show()

def on_Read_File(self, widget):
print "Opening Dansguardian bannedsitelist file for reading..."
print; print
lineoftext = open('/etc/dansguardian/lists/bannedsitelist', 'r')
myarray = []
lnum = 0
for line in lineoftext:
line = line.rstrip('\n')
line = line.rstrip( )
lnum = lnum + 1
print lnum , line
myarray.append(line);
lineoftext.close( )

def on_delete_event(self, widget, event):
self.win.set_sensitive(False)
dialog = gtk.MessageDialog(self.win,
gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
gtk.MESSAGE_INFO, gtk.BUTTONS_YES_NO, None)
dialog.set_markup('<big><b>Are you sure you want to quit?</
b></big>')
dialog.connect("destroy", lambda w:
self.win.set_sensitive(True))
answer = dialog.run()
if answer == -8:
dialog.destroy()
return False

if answer == -9:
dialog.destroy()
return True

app = gui()
gtk.main()
 
D

Dennis Lee Bieber

This is the code, it was adapted from code I found on the net. Code as
follows,

def on_Read_File(self, widget):
print "Opening Dansguardian bannedsitelist file for reading..."
print; print

"print" only goes to stdout, so your program is behaving correctly.
lineoftext = open('/etc/dansguardian/lists/bannedsitelist', 'r')
myarray = []
lnum = 0
for line in lineoftext:
line = line.rstrip('\n')
line = line.rstrip( )
lnum = lnum + 1
print lnum , line

Same comment

You need to set the contents of some multi-line text box defined on
the application window to the value of the lines you want to display.

Probably will need to handle scrolling bars too, if the text has
more lines than the text-box can physically display.
--
Wulfraed Dennis Lee Bieber KD6MOG
(e-mail address removed) (e-mail address removed)
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: (e-mail address removed))
HTTP://www.bestiaria.com/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,681
Members
48,796
Latest member
Greg L.

Latest Threads

Top