Martin Preishuber wrote:
>
> Hi there,
>
> I have 2 problems with using pygtk:
>
> - This one should be pretty easy ... Can i define the size of entry
> fields
> somehow ? I mean without messing around with boxes ..
I use code something like this to create, for example, a GtkEntry that
will hold 10 characters:
length=10
e=GtkEntry()
e.set_max_length(length)
e.set_usize((length+2)*9,-1)
The formula in set_usize I got by trial and error, using the default
font. I'm not sure how to do this in a non-font-specific manner.
> - Second I want to insert the output of some program into a GtkText
> field.
> I've done this this way:
>
> pipe = popen(command, "r")
>
> line = "full"
> while (line != ""):
> line = pipe.readline()
> if (line != ""):
> text.insert_defaults(line)
> mainiteration()
> pipe.close()
>
> Now there are a couple of problems: first the windows hangs as long as
> no output
You want select() -- search the Python library reference...
> comes from the pipe. second some programs overwrite the output of a
> line (e.g
> those %-counter ... xx% where xx counts up) and this appears really
> messy in
> the text box ...
Some programs do this with backspaces, others with carriage returns.
Some use real terminal addressing. In the first two cases, you've got a
chance. I don't know how you would handle the terminal addressing case
though...
I haven't tested this, but something like this should work for the
backspace/CR cases. This is coded for the backspace case...all that is
left is to include
the select() statement where noted...
sep = "\b"
data = ""
eof=0
while (not eof):
# select here with appropriate timeout
# Process any pending events
# If no input, next loop (continue)
tmp = pipe.read(1024)
if (not len(tmp)):
# end of data -- make sure last "line" is processed
tmp = sep
eof = 1
# data may hold residual data from the previous read
data = data + tmp
lines = string.split(data,sep)
# the last line may not be completed yet -- save it as
# residual for the next line. Note that above, when
# we reach eof, we mark the last line as completed.
data = lines[-1]
lines = lines[:-1]
for line in lines:
line = string.strip(line)
if (len(line)):
# do something with line
--
Richard Fish Enhanced Software Technologies, Inc.
Software Developer 4014 E Broadway Rd Suite 405
[EMAIL PROTECTED] Phoenix, AZ 85040
(602) 470-1115 http://www.estinc.com
To unsubscribe: echo "unsubscribe" | mail [EMAIL PROTECTED]