When replying, please edit your Subject line so it is more specific
than "Re: Contents of pygtk digest..."
Understood


Il giorno dom, 24/01/2010 alle 18.03 +0000, Peyman ha scritto:
Sorry for the late reply, but I skipped over this e-mail. I have
commented your e-mail below.

Please, *do not* reply to digests, _in particular_ do not leave parts
that have nothing to do with the mail you're answering to.
I do not understand, is this a 'digest' ([email protected])? Who should I send the e-mails to otherwise?

If you ask for help, it is your job to put together some code that runs, isn't huge and reproduces the problem. Attaching a single file depending
on tons of imports doesn't help.
No problem, I will will provide a self contained example. Attached is a simple example executes two methods. The first, effective_dialog(), creates a dialog which is the appropriate size. I created the most basic dialog for this. The second, deffective_dialog(), creates a dialog which is too large. This is how I implement it in my program, and it is causing problems.

On the other hand, I recognize if you do the job if isolating the
problem, you'll maybe solve it yourself.
I think it may have to do with the way I create the buttons in the create_buttons_with_image() helper function.

Pietro

Cheers


Peter

#!/usr/bin/env python

import sys
try:
	import pygtk
	pygtk.require("2.0")
except:
	pass
try:
	import gtk
	import gtk.glade
except:
	sys.exit(1)

def make_effective_dialog(window):
	"""Create all the widgets in here
	"""
	dialog=gtk.Dialog(title='Effective Dialog',parent=window,flags=gtk.DIALOG_MODAL|gtk.DIALOG_DESTROY_WITH_PARENT)

	#disable the separator
	
	#get the vbox
	vBox=dialog.vbox

	#create and entry
	label=gtk.Label("I'm afraid I can't do that, Dave")

	#add entry to vertical box
	vBox.pack_start(label,expand=True,fill=True,padding=10)

	window.show_all()
	label.show()

	if dialog.run():
		print True
	else:
		print False

	dialog.destroy()

def make_deffective_dialog(window):
	dialog=gtk.Dialog(title='Deffective Dialog',parent=window,flags=gtk.DIALOG_MODAL|gtk.DIALOG_DESTROY_WITH_PARENT)
	
	dialog.resize(300,300)

	fill_dialog(dialog)

	dialog.run()

def fill_dialog(dialog):
	"""Recursively create the widgets, starting from the vertical box
	"""
	#get vertical box
	vBox=dialog.vbox

	#add the drawing area and the menubar as left and right children	
	vBox.pack_start(create_da(),expand=True,fill=True,padding=0)
	
	create_buttons(dialog)

def create_da():
	"""Create the drawing area for this window
	"""
	#create the scrolled window
	outputWindowScrolledWindow=gtk.ScrolledWindow()

	#create the event box
	eventBox=gtk.EventBox()

	#set the events
	eventBox.set_events(gtk.gdk.POINTER_MOTION_MASK|gtk.gdk.BUTTON1_MOTION_MASK|gtk.gdk.BUTTON_PRESS_MASK|gtk.gdk.BUTTON_RELEASE_MASK|gtk.gdk.SCROLL_MASK)
	
	#create the drawing area and pixmap
	da=gtk.DrawingArea()
	
	#add da to eventbox
	eventBox.add(da)

	#minimum size of the drawing area
	da.set_size_request(1,1)

	#set the scrolled window policies
	outputWindowScrolledWindow.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)

	#first add the vBox to the scrolled windows
	outputWindowScrolledWindow.add_with_viewport(eventBox)

	#show all the widgets
	outputWindowScrolledWindow.show()
	da.show()
	eventBox.show()

	return outputWindowScrolledWindow
	
def create_buttons(dialog):
	"""Create the bar with the relevant information
	"""
	
	#get horizontal box
	hBox=dialog.action_area

	playButton=create_button_with_image(gtk.STOCK_MEDIA_PLAY)
	pauseButton=create_button_with_image(gtk.STOCK_MEDIA_PAUSE)
	nextButton=create_button_with_image(gtk.STOCK_MEDIA_NEXT)
	stopButton=create_button_with_image(gtk.STOCK_MEDIA_STOP)
	iterationAdjustment=gtk.Adjustment(value=0,lower=0,upper=1000000,step_incr=1,page_incr=100,page_size=100)
	iterationSpinButton=gtk.SpinButton(iterationAdjustment)
	zoomAdjustment=gtk.Adjustment(value=1,lower=1,upper=10,step_incr=1,page_incr=1,page_size=1)
	zoomScrollbar=gtk.HScrollbar(zoomAdjustment)
	zoomScrollbar.set_increments(1,1)
	paddingAdjustment=gtk.Adjustment(value=1,lower=1,upper=100,step_incr=1,page_incr=1,page_size=1)
	paddingScrollbar=gtk.HScrollbar(paddingAdjustment)
	paddingScrollbar.set_increments(10,10)
	timeEntry=gtk.Entry()

	#add it to the horizontal box
	hBox.pack_start(playButton,expand=False,fill=False,padding=0)
	hBox.pack_start(pauseButton,expand=False,fill=False,padding=0)
	hBox.pack_start(nextButton,expand=False,fill=False,padding=0)
	hBox.pack_start(stopButton,expand=False,fill=False,padding=0)
	hBox.pack_start(iterationSpinButton,expand=False,fill=False,padding=5)
	hBox.pack_start(zoomScrollbar,expand=True,fill=True,padding=5)
	hBox.pack_start(paddingScrollbar,expand=True,fill=True,padding=5)
	hBox.pack_start(timeEntry,expand=False,fill=False,padding=5)

	#call show on the widgets
	playButton.show()
	pauseButton.show()
	nextButton.show()
	stopButton.show()
	iterationSpinButton.show()
	zoomScrollbar.show()
	paddingScrollbar.show()
	timeEntry.show()


def on_main_window_delete_event(widget,data=None):
	"""Return false so the window gets destroyed
	"""
	return False

def on_main_window_destroy(widget,data=None):
	"""Return false so the window gets destroyed
	"""
	gtk.main_quit()

def create_button_with_image(stock_name,label_text="",size=gtk.ICON_SIZE_BUTTON):
	# Create box for image and label
	box = gtk.HBox(False, 0)
	box.set_border_width(2)

	#create the button
	button=gtk.Button()

	# Now on to the image stuff
	image = gtk.Image()
	#image.set_from_file(image_filename)
	image.set_from_stock(stock_name,size)

	# Create a label for the button
	label = gtk.Label(label_text)

	# Pack the pixmap and label into the box
	box.pack_start(image, False, False, 3)
	box.pack_start(label, False, False, 3)

	#add the box to the button
	button.add(box)

	#call show on all the widgets
	image.show()
	label.show()
	box.show()
	button.show()

	#return the button to the calling widget
	return button

if __name__ == '__main__':

	try:
		window=gtk.Window()
		window.set_title("main")
		window.show()

		window.connect('destroy',on_main_window_destroy)
		window.connect('delete_event',on_main_window_delete_event)

		make_effective_dialog(window)
		make_deffective_dialog(window)


		gtk.main()
	except KeyboardInterrupt:
		sys.exit(1)







_______________________________________________
pygtk mailing list   [email protected]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/

Reply via email to