Sorry for the late reply, but I skipped over this e-mail. I have commented your e-mail below.

On 22 Jan 2010, at 04:00, pygtk-requ...@daa.com.au wrote:

Send pygtk mailing list submissions to
        pygtk@daa.com.au

To subscribe or unsubscribe via the World Wide Web, visit
        http://www.daa.com.au/mailman/listinfo/pygtk
or, via email, send a message with subject or body 'help' to
        pygtk-requ...@daa.com.au

You can reach the person managing the list at
        pygtk-ow...@daa.com.au

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


Today's Topics:

  1. Re: Dialog (Pietro Battiston)
  2. How to organize my app? (middleofdre...@gmail.com)
  3. Re: How to organize my app? (Pietro Battiston)
  4. Re: How to organize my app? (Pietro Battiston)
  5. Re: How to organize my app? (middleofdre...@gmail.com)


----------------------------------------------------------------------

Message: 1
Date: Thu, 21 Jan 2010 23:13:53 +0100
From: Pietro Battiston <too...@email.it>
Subject: Re: [pygtk] Dialog
To: PYGTK <pygtk@daa.com.au>
Message-ID: <1264112033.4712.276.ca...@vousci>
Content-Type: text/plain; charset="UTF-8"

Il giorno gio, 21/01/2010 alle 09.36 +0000, Peyman ha scritto:
Hello

I recently switched a few of my windows from being of type gtk.Window
to gtk.Dialog.

If you can show us the code, it will be much simpler...
No problem I have attached it for you, but I essentially create the Dialog with the following call window = gtk ..Dialog (title=title,parent=widgets['main_window'],flags=gtk.DIALOG_MODAL| gtk.DIALOG_DESTROY_WITH_PARENT)

I fixed everything so the dialogs show up, but now
they are HUGE.

In one dimension or both?
Generally in the horizontal dimension (because the buttons are expanded), but in one case (embedded shell console) it is in both directions

This has to do with the size_request of the horizontal
boxes (action_area).

How do you know? How are things distributed?
I discovered this by doing a size request call on both the dialog and the action_area (where the buttons are), and they both had the same width whereas the vertical box was much smaller

Both the vbox and the action_area have
homogeneous=False and spacing=0

What about running

while widget:
   print widget, widget.size_request(), widget.get_size_request()
   parent = widget.get_parent()
   if parent:
       try:
           print parent.child_get_property('expand')
           print parent.child_get_property('fill')
       except:
           pass


?
When I run the above code I get the following output
<gtk.Dialog object (GtkDialog) at 0xb7b6e7d4> (1400,129) (-1,-1)

There is no parent, even though I created the dialog with a parent passed as a parameter

When you can't for some reason provide code, please at least provide
lots of informations.

Pietro

Thanks
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)

from global_variables import widgets
from callbacks_universal import destroy_window
from widgets_universal import create_button_with_image

from callbacks_output_window import on_pause_button_clicked
from callbacks_output_window import on_play_button_clicked
from callbacks_output_window import on_next_button_clicked
from callbacks_output_window import on_stop_button_clicked
from callbacks_output_window import on_zoom_scale_value_changed
from callbacks_output_window import on_neuron_pad_scale_value_changed
from callbacks_output_window import on_iteration_spinbutton_value_changed
from callbacks_output_window import on_drawing_area_expose_event
from callbacks_output_window import on_drawing_area_configure_event

from helper_functions_drawing_area import initialize_drawing_area

def create_output_window(title="Output Window",width=300,height=300,show=True,maximize=False):
	"""Create a window and call it 'output_window'
	"""
	global widgets

	if 'output_window' in widgets:
		print "Error, can not create window because it already exists: output_window"
		raise Exception

	else:
		window=gtk.Dialog(title=title,parent=widgets['main_window'],flags=gtk.DIALOG_MODAL|gtk.DIALOG_DESTROY_WITH_PARENT)
		#window.set_icon_from_file("600px-Awesome.png")

		if maximize:
			window.maximize()
		else:
			window.resize(width,height)

		widgets['output_window']=window

	#connect the destroy signal to the universal destroy signal
	window.connect("destroy",destroy_window,'output_window')

	#fill this window with all its children
	fill_output_window()

def run_output_window():
	"""The run routine is called after the window has been loaded
	"""
	global widgets

	window=widgets['output_window']

	if window.run():
		window.destroy()
		return True
	else:
		window.destroy()
		return False

def fill_output_window():
	"""Recursively create the widgets, starting from the vertical box
	"""
	global widgets

	#First get the main window
	window=widgets['output_window']
	
	#get vertical box
	vBox=window.vbox

	#add the drawing area and the menubar as left and right children	
	vBox.pack_start(create_output_window_da(),expand=True,fill=True,padding=0)
	#vBox.pack_start(create_output_window_bar(),expand=False,fill=False,padding=0)
	
	create_output_window_bar()

	#add it to the main window
	#window.add(vBox)
	
	#call show on the vertical box
	#vBox.show()

	#return vBox

def create_output_window_da():
	"""Create the drawing area for this window
	"""
	global widgets

	#create the scrolled window
	outputWindowScrolledWindow=gtk.ScrolledWindow()
	
	#create the drawing area and pixmap
	da=gtk.DrawingArea()
	
	#minimum size of the drawing area
	da.set_size_request(1,1)

	#connect the drawing area callbacks
	da.connect('expose-event',on_drawing_area_expose_event)
	da.connect('configure-event',on_drawing_area_configure_event)

	#retain access to the drawing area and pixmap
	widgets['output_drawing_area']=da

	#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(da)

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

	return outputWindowScrolledWindow
	
def create_output_window_bar():
	"""Create the bar with the relevant information
	"""
	global widgets

	#First get the main window
	window=widgets['output_window']
	
	#get horizontal box
	hBox=window.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=0,lower=0,upper=100,step_incr=10,page_incr=10,page_size=10)
	zoomScrollbar=gtk.HScrollbar(zoomAdjustment)
	paddingAdjustment=gtk.Adjustment(value=0,lower=0,upper=100,step_incr=10,page_incr=10,page_size=10)
	paddingScrollbar=gtk.HScrollbar(paddingAdjustment)
	timeEntry=gtk.Entry()
	
	#connect the signals
	playButton.connect("clicked",on_play_button_clicked)
	pauseButton.connect("clicked",on_pause_button_clicked)
	nextButton.connect("clicked",on_next_button_clicked)
	stopButton.connect("clicked",on_stop_button_clicked)
	iterationSpinButton.connect("value-changed",on_iteration_spinbutton_value_changed)
	zoomScrollbar.connect("value-changed",on_zoom_scale_value_changed)
	paddingScrollbar.connect("value-changed",on_neuron_pad_scale_value_changed)	

	#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
	#hBox.show()
	playButton.show()
	pauseButton.show()
	nextButton.show()
	stopButton.show()
	iterationSpinButton.show()
	zoomScrollbar.show()
	paddingScrollbar.show()
	timeEntry.show()

	#return the horizontal box
	#return hBox



















------------------------------

Message: 2
Date: Thu, 21 Jan 2010 23:14:41 +0100
From: "middleofdre...@gmail.com" <middleofdre...@gmail.com>
Subject: [pygtk] How to organize my app?
To: pygtk@daa.com.au
Message-ID:
        <edd960ed1001211414o715a0d3ev2518197446f2e...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Hi,
I don't have experience in creating big apps. I want to know how to split app into files. For example - I have main class in main file and I want to move widgets (loading widgets from gladefile) into new file. It should be in the mainclass i think.. but i can't import something inside class (it works but it's not proper). Or signal handlers - how to move them into other file
and do it right? Another thing is i have some (not main) class, but it
should interact with gui (some changes like showing widgets etc). It's
assigned in mainclass and constructor of it looks like this:

__init__(gui):
self.gui=gui

and then.. in functions of this class I can change for example
self.gui.some_widget.show()
And again.. I don't think it's proper method for doing this.

Some tips, please?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
http://www.daa.com.au/pipermail/pygtk/attachments/20100121/85a606db/attachment.html

------------------------------

Message: 3
Date: Thu, 21 Jan 2010 23:43:27 +0100
From: Pietro Battiston <too...@email.it>
Subject: Re: [pygtk] How to organize my app?
To: PYGTK <pygtk@daa.com.au>
Message-ID: <1264113807.4712.414.ca...@vousci>
Content-Type: text/plain; charset="UTF-8"

Il giorno gio, 21/01/2010 alle 23.14 +0100, middleofdre...@gmail.com ha
scritto:
Hi,
I don't have experience in creating big apps. I want to know how to
split app into files. For example - I have main class in main file and I want to move widgets (loading widgets from gladefile) into new file.
It should be in the mainclass i think.. but i can't import something
inside class (it works but it's not proper).

"If you don't want it into the same file of the main class, you
certainly don't want it into the main class" is a rule for which I'm not
able to see any exception.

That said, what I do in many projects is creating this file:


import gtk

class Ui(object):
   def __init__(self, APP, filename):
       self._builder = gtk.Builder()
       self._builder.set_translation_domain(APP)
       self._builder.add_from_file(filename)

   def __getattr__(self, attr_name):
       try:
           return object.__getattribute__(self, attr_name)
       except AttributeError:
           obj = self._builder.get_object(attr_name)
           if obj:
               self.obj = obj
               return obj
           else:
               raise AttributeError, "no object named \"%s\" in the
GUI." % attr_name



and importing Ui from it; then, the main class will, in __init__, do
something like

   self.ui = Ui("nameoftheapp", "path/to/the/file.glade")

so that from now on you just access widgets as

   self.ui.name_of_the_widget


_But_ this is just what _I_ find convenient, and not really because I
want to separate it from the main class, but just to avoid some
get_object() calls and get cleaner code. In general, there are no
particular requirements to separate something from some class: if you
see it grew too big and there is something that can be separated from
it, just separate it.


Or signal handlers - how to move them into other file and do it right?

I'm not really sure I would want to move signal handlers... if all your handlers are method of this main class and you want to save some coding,
just use signals_autoconnect.

Another thing is i have some (not main) class, but it should interact
with gui (some changes like showing widgets etc). It's assigned in
mainclass and constructor of it looks like this:


__init__(gui):
self.gui=gui


and then.. in functions of this class I can change for example
self.gui.some_widget.show()
And again.. I don't think it's proper method for doing this.


Well, in my opinion it's hard to say _in general_ that this is wrong.
When you choose the optimal size for some class, just think in terms of
functionalities: the best rule to respect is that it must be
comfortable.

Certainly, if "self.gui.some_widget.show()" is part of a block of code
that works on the gui, it may be smart to move it to a method of the gui
and call that from your class.



Some tips, please?


Read other people's code, and just try. And obviously, be ready to
change things that you find not optimal.

Pietro




------------------------------

Message: 4
Date: Thu, 21 Jan 2010 23:54:37 +0100
From: Pietro Battiston <too...@email.it>
Subject: Re: [pygtk] How to organize my app?
To: PYGTK <pygtk@daa.com.au>
Message-ID: <1264114477.4712.451.ca...@vousci>
Content-Type: text/plain; charset="UTF-8"

Il giorno gio, 21/01/2010 alle 23.43 +0100, Pietro Battiston ha scritto:
Il giorno gio, 21/01/2010 alle 23.14 +0100, middleofdre...@gmail.com ha
scritto:
Hi,
I don't have experience in creating big apps. I want to know how to
split app into files. For example - I have main class in main file and I want to move widgets (loading widgets from gladefile) into new file.
It should be in the mainclass i think.. but i can't import something
inside class (it works but it's not proper).

"If you don't want it into the same file of the main class, you
certainly don't want it into the main class" is a rule for which I'm not
able to see any exception.

Wait, just forget that. Your problem is obviously not that you want the _code_ in your main class, but that you want another object as a member
of your main class. Which is perfectly fine.

Pietro



------------------------------

Message: 5
Date: Fri, 22 Jan 2010 01:00:38 +0100
From: "middleofdre...@gmail.com" <middleofdre...@gmail.com>
Subject: Re: [pygtk] How to organize my app?
To: pygtk@daa.com.au
Message-ID:
        <edd960ed1001211600w72ddd8e8jb9f1f43f1f3e4...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

I see i was doing it wrong from the begining. gui was my main class but it
shouldn't.

2010/1/21 Pietro Battiston <too...@email.it>

Il giorno gio, 21/01/2010 alle 23.14 +0100, middleofdre...@gmail.com ha
scritto:
Hi,
I don't have experience in creating big apps. I want to know how to
split app into files. For example - I have main class in main file and I want to move widgets (loading widgets from gladefile) into new file.
It should be in the mainclass i think.. but i can't import something
inside class (it works but it's not proper).

"If you don't want it into the same file of the main class, you
certainly don't want it into the main class" is a rule for which I'm not
able to see any exception.

That said, what I do in many projects is creating this file:


import gtk

class Ui(object):
  def __init__(self, APP, filename):
      self._builder = gtk.Builder()
      self._builder.set_translation_domain(APP)
      self._builder.add_from_file(filename)

  def __getattr__(self, attr_name):
      try:
          return object.__getattribute__(self, attr_name)
      except AttributeError:
          obj = self._builder.get_object(attr_name)
          if obj:
              self.obj = obj
              return obj
          else:
              raise AttributeError, "no object named \"%s\" in the
GUI." % attr_name



and importing Ui from it; then, the main class will, in __init__, do
something like

  self.ui = Ui("nameoftheapp", "path/to/the/file.glade")

so that from now on you just access widgets as

  self.ui.name_of_the_widget


Interesting... but.. if I use this method where I should do
signals_autoconnect?


Or signal handlers - how to move them into other file and do it right?

I'm not really sure I would want to move signal handlers... if all your handlers are method of this main class and you want to save some coding,
just use signals_autoconnect.


I meant... functions for signals. They was in main class. for example:

dic={"blabla": self.blabla}

and then
def blabla(self):
 self.label.set_text("blabla")

Can I create class for handling signals only?  If so - how?



Another thing is i have some (not main) class, but it should interact
with gui (some changes like showing widgets etc). It's assigned in
mainclass and constructor of it looks like this:


__init__(gui):
self.gui=gui


and then.. in functions of this class I can change for example
self.gui.some_widget.show()
And again.. I don't think it's proper method for doing this.


Well, in my opinion it's hard to say _in general_ that this is wrong.
When you choose the optimal size for some class, just think in terms of
functionalities: the best rule to respect is that it must be
comfortable.

Certainly, if "self.gui.some_widget.show()" is part of a block of code that works on the gui, it may be smart to move it to a method of the gui
and call that from your class.


But sometimes I have to change something in gui when some class signal is emited (in new thread). I just don't know how to do it most cleanly and
lightweight way.




Some tips, please?


Read other people's code, and just try. And obviously, be ready to
change things that you find not optimal.


Maybe some example app you can recommend? I was looking for something but found only apps with bilion of lines of code... i'm not smart enough to get
through it.


Pietro


-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
http://www.daa.com.au/pipermail/pygtk/attachments/20100122/ecf90aac/attachment-0001.htm

------------------------------

_______________________________________________
pygtk mailing list pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


End of pygtk Digest, Vol 83, Issue 22
*************************************

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

Reply via email to