[pygtk] pygtk Digest, Vol 83, Issue 22

Peyman paskari007 at yahoo.ca
Mon Jan 25 02:03:50 WST 2010


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-request at daa.com.au wrote:

> Send pygtk mailing list submissions to
> 	pygtk at 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-request at daa.com.au
>
> You can reach the person managing the list at
> 	pygtk-owner at 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? (middleofdreams at 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? (middleofdreams at gmail.com)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Thu, 21 Jan 2010 23:13:53 +0100
> From: Pietro Battiston <toobaz at email.it>
> Subject: Re: [pygtk] Dialog
> To: PYGTK <pygtk at daa.com.au>
> Message-ID: <1264112033.4712.276.camel at 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
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: widgets_output_window.py
Type: text/x-python-script
Size: 5605 bytes
Desc: not available
Url : http://www.daa.com.au/pipermail/pygtk/attachments/20100124/c367748d/attachment-0001.bin 
-------------- next part --------------
>
>
>
> ------------------------------
>
> Message: 2
> Date: Thu, 21 Jan 2010 23:14:41 +0100
> From: "middleofdreams at gmail.com" <middleofdreams at gmail.com>
> Subject: [pygtk] How to organize my app?
> To: pygtk at daa.com.au
> Message-ID:
> 	<edd960ed1001211414o715a0d3ev2518197446f2e1a5 at 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 <toobaz at email.it>
> Subject: Re: [pygtk] How to organize my app?
> To: PYGTK <pygtk at daa.com.au>
> Message-ID: <1264113807.4712.414.camel at vousci>
> Content-Type: text/plain; charset="UTF-8"
>
> Il giorno gio, 21/01/2010 alle 23.14 +0100, middleofdreams at 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 <toobaz at email.it>
> Subject: Re: [pygtk] How to organize my app?
> To: PYGTK <pygtk at daa.com.au>
> Message-ID: <1264114477.4712.451.camel at 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,  
>> middleofdreams at 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: "middleofdreams at gmail.com" <middleofdreams at gmail.com>
> Subject: Re: [pygtk] How to organize my app?
> To: pygtk at daa.com.au
> Message-ID:
> 	<edd960ed1001211600w72ddd8e8jb9f1f43f1f3e4c9d at 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 <toobaz at email.it>
>
> Il giorno gio, 21/01/2010 alle 23.14 +0100, middleofdreams at 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 at 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
> *************************************



More information about the pygtk mailing list