[pygtk] GtkNotebook problem (with broken code)

2000-09-12 Thread Randolph Bentson

First: I apologize if this is more of a GTK problem than a PyGtk
problem.  I haven't used GTK other than by Python, so it seems
best to start here.

I've bumped up against problems using GtkNotebook, for which I'd
appreciate any help I can get.

I would like to update the contents of a page of a notebook just
before it is displayed.  'page_callback' does just that in a trivial
manner, at least when it's connected to a button callback as shown
by #X# lines.  When I try the code below, page_callback falls into
a recursion hole at the line marked #.

I see two possible solutions: somehow call off the callback when
the page is removed and inserted, or find an entirely different
way to change the contents of what's being displayed on a page.
The problem is that I've found no examples or descriptions of how
either of these might be accomplished.

(I've considered mucking around inside a frame inside the page,
but don't see a clean way to get a handle on the right frame
(or is this what .get_data and .set_data are all about?))

Can anyone give me a hand?

-- 
Randolph Bentson
[EMAIL PROTECTED]


#!/usr/bin/env python

from gtk import *
import GtkExtra

def page_callback(notebook, crap, page, cnt=[0], *args):
#X#def page_callback(btn, notebook, crap, page, cnt=[0], *args):
cnt[0] = cnt[0] + 1

notebook.remove_page(page)
box = GtkVBox()
box.pack_start(GtkLabel(`cnt[0]`))
box.show_all()
label = GtkLabel("Tab " + str(page))
label.show_all()
notebook.insert_page(box, label, page) #
notebook.set_page(page)

return

win = GtkWindow()
win.connect("destroy", mainquit)
win.connect("delete_event", mainquit)
box1 = GtkVBox(FALSE, 0)
win.add(box1)

button = GtkButton("close")
button.connect("clicked", mainquit)
box1.pack_end(button, expand=FALSE)

notebook = GtkNotebook()
notebook.set_tab_pos(POS_TOP)
box1.pack_start(notebook)

notebook.connect("switch-page", page_callback)
#X#btn = GtkButton("change page 0")
#X#btn.connect('clicked', page_callback, notebook, 'crap', 0)
#X#box1.pack_end(btn)

for i in range(2):
box = GtkVBox()
box.pack_start(GtkLabel("stuff"))
label = GtkLabel("Tab " + str(i))
notebook.append_page(box, label)

win.show_all()
mainloop()




[pygtk] wandering 'connect'

2000-04-25 Thread Randolph Bentson

I'm having problems with button.connect() which puzzle me.  I've attached
a simple example program which was extracted from a much larger program.

Clicking "start TASK" starts the TASK function, which opens a status
window and updates the label ten times a second.  Every time I click
"start TASK" before the current TASK finishes, the current TASK is
interrupted and a new TASK is started.  When the newer TASK finishes,
the interrupted TASK proceeds to completion.  (Absent threads, it is
quite reasonable that one TASK would displace another in this nested
manner.  I know how to prevent this nesting if that's desired.)

If TASK is not running, clicking the "QUIT" button invokes quit_pgm,
but if I click "QUIT" while the first TASK is running, I see a new
TASK started!

If I click "QUIT" before the second TASK finishes, a third instance
starts, but surprisingly if I click "QUIT" after the second or third
loop terminates, quit_pgm is called and the main window goes away.

I haven't got much further in the analysis, but it looks like the
button connections follow these rules (where each entry to state
1 starts TASK):
 click
  event | click "QUIT" | "start TASK" | TASK exit
  --+--+--+--
state 0 |exit  |  1   |   N/A
  1 |  1   |  1   |0

In confirmation of this observation, I've found that while TASK
is running, the "QUIT" button no longer shows a PRELIGHT color,
and the "start TASK" button shows the ACTIVE color.  This holds
until one instance of TASK has finished.

I'm about to rewrite this example in C, just to see if the problem
is fundamental to GTK, but meanwhile I'd like to see if anyone
can identify a problem in my code.  Is this behavior some function
of widget state?

-- 
Randolph Bentson
[EMAIL PROTECTED]



#!/usr/bin/python -v
from gtk import *   # from pygtk
import time

def quit_pgm(*args):
print "Quit Pgm"
win.hide()
mainquit()

def TASK(*args):
newin = GtkWindow()
lbl = GtkLabel('__')
newin.add(lbl)
lbl.show()
newin.show()

for i in range(0,50):
lbl.set_text('%d'%i)
time.sleep(0.1)
while events_pending(): mainiteration()
newin.hide()

rc_parse("gtkrc")

win = GtkWindow()

vbox0 = GtkVBox()
win.add(vbox0)

btn1 = GtkButton(' start TASK ')
btn1.connect("button_release_event", TASK)
vbox0.pack_start(btn1,FALSE,FALSE)

btn2 = GtkButton(' QUIT ')
btn2.connect("button_release_event", quit_pgm)
vbox0.pack_start(btn2,FALSE,FALSE)

vbox0.show()
btn1.show()
btn2.show()
win.show()

mainloop()




Re: [pygtk] PyQt/PyKDE Bindings

2000-03-23 Thread Randolph Bentson

On Fri, Mar 24, 2000 at 01:03:58AM +0800, James Henstridge wrote:
 On Thu, 23 Mar 2000, Moshe Zadka wrote:
  As long as you're breaking things anyway, let me suggest one change:
  have the "Gtk" prefix stripped from the classes' names (GtkText - Text,
  etc) and recommend that Gtk is imported via
 
 I am more in favour of keeping the Gtk prefix, as this seems to be common
 in some of the other language bindings (even the java bindings kept the
 Gtk prefix when the classes were in a gtk package).  Most of your
 application is made up of manipulating widgets, rather than constructing
 them, so the extra three characters is not that much of a problem.

I rather liked Moshe's proposal because it supports the "principle of
least surprise".  This is especially important when there's any chance
of name collision.  The issue of three vs. four character prefix,
("Gtk" vs. "Gtk."), seems to be too small to be a consideration.

-- 
Randolph Bentson
[EMAIL PROTECTED]
-
To unsubscribe: echo "unsubscribe" | mail [EMAIL PROTECTED]



[pygtk] destruction of window causes abort

2000-01-11 Thread Randolph Bentson


When I run the attached code and use my window manager to
"delete" the window, the code works as desired. But I get
core dumps when I "destroy" the window.

When I run the code under the fvwm window manager,
the error messages are:
Gdk-ERROR **: an x io error occurred
aborting...
Abort (core dumped)

At first I thought I failed to include some essential element
in my code, but just before sending the first draft of this
note, I tried to "destroy" windows in example code in the pygtk
distribution.  Those programs exhibit the same basic failure mode.

I'm running version 1.5 of python, version 1.2 of libgtk,
version 1.2.1 of gtk+, and version 0.63 of pygtk.  I'd be
most happy with answers which point me to some new release
which solves the problem.  My second choice would be advise
on how to make this code more robst.  Any takers?

Randolph Bentson


#!/usr/bin/python
import gtk
# using 'from gtk import *' only causes a simple
# change to the code below, the problem remains

try:
win = gtk.GtkWindow()
win.connect("delete_event", gtk.mainquit)
win.connect("destroy", gtk.mainquit)
win.show()
gtk.mainloop()
except:
import sys
print 'error!', sys.exc_type, sys.exc_value

To unsubscribe: echo "unsubscribe" | mail [EMAIL PROTECTED]



Re: [pygtk] destruction of window causes abort

2000-01-11 Thread Randolph Bentson

Hmm, I get to follow-up to my own post.

I've run the program on another system which is
Red Hat 6.1 at the core.  Since I don't have
trouble there, I'm going to try to isolate what
is different.

Randolph Bentson
To unsubscribe: echo "unsubscribe" | mail [EMAIL PROTECTED]