I see i was doing it wrong from the begining. gui was my main class but it shouldn't.
2010/1/21 Pietro Battiston <[email protected]> Il giorno gio, 21/01/2010 alle 23.14 +0100, [email protected] 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 > >
_______________________________________________ pygtk mailing list [email protected] http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/
