GLObject

Tagged:

J'ai remarqué que j'ai rajouté quelques fonctionnalitées à une classe dont je parle tout le temps ... J'ai aussi ajouté des commentaires ... enfin pour faire suite a ce billet et surtout pour le compléter je met ici un copié collé de ma class GLObject. Je rappelle quand même a quoi elle sert pour ceux qui sont a la traine : cette classe permet de définir rapidement des applications glade based ... On crée notre fichier glade on étend cette classe pour chaque fenêtre et ça marche tout seul !

J'ai ajouté la fonction de child windows permettant d'ouvrir un certain nom de fenêtres et lors d'un destroy sur l'une d'entre elle, toutes les fenêtres enregistrées comme child windows sont détruite aussi ... La je travaille passivement entre deux sur la possibilité de sauvegarder la position et la taille des fenêtres dans un fichiers sans s'en préocuper ... Comme ça lors du reboot de l'appli les fenêtres reprendront les positions que l'utilisateur a choisit !!!

Bref on parlais code y'a un moment le vla :

#!/usr/bin/env python
#               PyMyAdmin/gui/tools/GLObject.py - Copyright Jonathan Adami 
# 
 
import gtk.glade
 
class GLObject:
 
    """
    This class is the base of all window managements. It provide tools to autoconnect signals, 
    to make window dependencies, accessing to all widgets and obviously, make the link
    between the glade file and the window.
    
    @author Jonathan Adami
    """
 
    def __init__(self,glFile,rootWidget):
        """
        This function is able to launch the window, to connect all signals and to initialize some variables
        
        @param string glFile : The real path to access the glade file
        @param string rootWidget : Indicate where in the glade xml file,
            this window have to point to. Most of the time, the rootWidget
            correspond to the name of the window in the gladefile
        """
        self.widgets = gtk.glade.XML(glFile,rootWidget,None)
        self.rootWidget = rootWidget
        sig = {}
        for it in dir(self):
            sig[it] = getattr(self,it)
        self.widgets.signal_autoconnect(sig)
        self.childs = []
        
    def destroy(self):
        """
        This function destory the widget (often the window) and all its child
        widgets registered bu the addChildWindow function
 
        """
        for child in self.childs:
            child.destroy()
        root = self.getRoot()
        if root != None:
            root.destroy()
    
    def getRoot(self):
        """
        This function return the link of the root widget
 
        @return gtk.Widget : The rootWidget
        """
        return self.widgets.get_widget(self.rootWidget)
    
    def addChildWindow(self,which):
        """
        If the GLObject represent a window, most of the time this function is called
        in order to register child windows. In this case, when the window is destroyed,
        all it's child windows are destroy recursively
 
        @param gtk.Widget which : The widget to destroy with the actual widget
        """
        self.childs.append(which)