Il giorno mer, 27/01/2010 alle 10.47 +0000, Peyman ha scritto:
> >
> >
> > 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.
> >

I where not exactly able to solve the problem, but I may have understood
something more: the problem is that the action_area is a gtk.HBox, but
it seems it doesn't behave as a HBox in the fact that it doesn't take
care of the "homogeneous" property. Since the text field you add is 160
pixels wide, every other widget in the action_area takes up the same
space, and hence the window is huge.

Take a look at the attachment: I just stopped using the action_area and
added a new HBox, and it works. If instead you uncomment the
"set_homogeneous(True)" call, the problem is here again.

Now: I realize this is not a solution, and if I made no mistakes you may
also want to file a bug about that HBox not behaving like a HBox;
however, about your problem, my advice is that you're using the action
area - and, in general, the Dialog object - in a way that it is not
intended to be used: usually a dialog is really a lot of stuff, and some
_buttons_ in the bottom of the window (the action_area), so if I was in
you I would:
- just use a gtk.Window, or
- just move those controls, which are atypical for an action_area, in
other parts of the dialog.

bye

Pietro
#!/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)

	return dialog

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=gtk.HBox()
	dialog.vbox.pack_end(hBox)
#	hBox.set_homogeneous(True)

	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)
	hBox.show_all()

	#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)
		d=make_deffective_dialog(window)
		d.run()


		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