| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 
 | #!/usr/bin/env python
# -*- coding:Utf-8 -*-
 
# exemple treemodelfilter.py
print "coucou"
import sys
print  "Version de python",(sys.version)
python_version = sys.version[:3]
 
 
 
import pygtk
pygtk.require('2.0')
import gtk
 
 
 
 
version_gtk=str(gtk.gtk_version[0])+"."+str(gtk.gtk_version[1])+"."+str(gtk.gtk_version[2])
version_pygtk=str(gtk.pygtk_version[0])+"."+str(gtk.pygtk_version[1])+"."+str(gtk.pygtk_version[2])
print "version de gtk",version_gtk
print "version de PyGtk",version_pygtk
print  "Version de python",(sys.version)
python_version = sys.version[:3]
if python_version != '2.3' and python_version != '2.4' :
        print('WARNING - This python version has not yet been tested. Try and move to Python version 2.3 or 2.4 if you encounter problems')
 
 
bugdata="""121339 RESO important JOB Trimestriel  dsextras.py installation directory is incorrect
121611 RESO important JOB Trimestriel  argument is guint, should be guint32
121943 RESO important JOB Trimestriel  gtk.mainiteration and gtk.mainloop defeat the caller's ex...
122260 RESO important JOB Trimestriel  Could not compile
122569 NEW  urgent JOB hebdomadaire gtk.Window derived class segfaults
122591 RESO important JOB Trimestriel  cannot return None from CellRenderer.on_start_editing
122755 RESO important JOB Trimestriel  _wrap_gdk_window_NEW  urgent JOB hebdomadaire veri memo personnel mensuel urgent personnel mensuels to ref return value
122786 RESO important JOB Trimestriel  don't import Numeric until it is first used
123014 NEW  urgent JOB hebdomadaire PyGtk build problem on Win32 using the 'distutils' approach.
123037 NEW  urgent JOB hebdomadaire gtk.ListStore.set_column_types is missing
123456 RESO important JOB Trimestriel  ItemFactory.create_items and <ImageItem> bug
123458 veri memo personnel mensuel urgent personnel mensuel pygtk does not wrap all of gdk-pixbuf
123891 NEW  urgent JOB hebdomadaire gobject.PARAM_CONSTRUCT problem
124181 veri memo personnel mensuel urgent personnel mensuel Python Shell inside a gtk GUI
124338 RESO important JOB Trimestriel  Memleak when using pixbuf
124593 RESO important JOB Trimestriel  TreeModel.iter_children should accept None as parent
125172 RESO important JOB Trimestriel  gtk.TreeModelSort returns an unusable object
125272 RESO important JOB Trimestriel  error in gtk_widget_translate_coordinates wrapping
125445 NEW  urgent JOB hebdomadaire pygtk gives no acces to PangoLayoutIter's
125533 RESO important JOB Trimestriel  set_skip_taskbar_hint and set_skip_pager_hint not wrapped
126109 RESO important JOB Trimestriel  gtk.Entry focus_out event core
126323 RESO important JOB Trimestriel  gtk_disable_setlocale cannot be used
126406 RESO important JOB Trimestriel  gtk.TreeView.expand_row() should return gboolean not None
126479 RESO important JOB Trimestriel  None iter's in custom TreeModel cause SystemException's
127083 RESO important JOB Trimestriel  Binding generation of methods which use gpointer does not...
127178 RESO important JOB Trimestriel  gtk.Widget color modify methods do not allow None for col...
127504 NEW  urgent JOB hebdomadaire wrap GtkTreeViewColumnDropFunc
128623 RESO important JOB Trimestriel  Allow NULL as set_tip argument
128988 RESO important JOB Trimestriel  missing space in prototype confuses h2def.py
129032 NEW  urgent JOB hebdomadaire GObject Interfaces (GInterface) support
129414 RESO important JOB Trimestriel  h2def.py doesn't see gda_log_enable()
129490 RESO important JOB Trimestriel  Provide hardware_keycode to python
129754 RESO important JOB Trimestriel  memory leak with gtk.gdk.pixmap_foreign_NEW  urgent JOB hebdomadaire()
129843 NEW  urgent JOB hebdomadaire Make all constructors work through g_object_NEW  urgent JOB hebdomadaire()
129966 RESO important JOB Trimestriel  convert GValue containing GValueArray to PyObject
131837 RESO important JOB Trimestriel  Cannot set or get \"markup\" property from CellRendererText
132040 NEW  urgent JOB hebdomadaire abusing setdefaultencoding()
132058 RESO important JOB Trimestriel  gtkgl bus error on constructor to gtk.gl.Area
132507 RESO important JOB Trimestriel  gtk_accel_group_connect seems to be missing
132837 NEW  urgent JOB hebdomadaire set_from_pixmap creates a different gtk.Image than set_fr...
133681 RESO important JOB Trimestriel  memory leak in gdk.drawable.get_image
134462 RESO important JOB Trimestriel  pygtk2 segfaults
134491 RESO important JOB Trimestriel  OverflowError occurs when menu pops up.
134494 RESO important JOB Trimestriel  The Definition of argument for gtk.gdk.Pixbuf.fill should...
135279 RESO important JOB Trimestriel  codegen is using private functions
135439 RESO important JOB Trimestriel  Integrate SDL into pygtk widgets
135963 RESO important JOB Trimestriel  gc of gtk.ListStore aborts intrepeter after gtk.threads_i...
136204 RESO important JOB Trimestriel  GtkTextSearchFlags warning
136205 RESO important JOB Trimestriel  GdkPixbuf.fill passed arg changed type originating crash
136297 RESO important JOB Trimestriel  Explanatory additions to gtk.DrawingArea
136597 RESO important JOB Trimestriel  gtkgl still referenced in build files
136688 RESO important JOB Trimestriel  installation directory of pygtk 2.2
136705 RESO important JOB Trimestriel  mainquit vs. main_quit usage
136707 RESO important JOB Trimestriel  gtk.gdk.Window.raise uses reserved keyword.
136731 RESO important JOB Trimestriel  setup.py should not install the libglade DLL
136811 RESO important JOB Trimestriel  h2def ignores some functions
136984 RESO important JOB Trimestriel  Seemingly Invalid Flag for gtk.MessageDialog
136989 NEW  urgent JOB hebdomadaire should pixbufloader throw two GErrors?
137086 NEW  urgent JOB hebdomadaire gtk.gdk.window_lookup assertion
137091 RESO important JOB Trimestriel  \"constants\" for selection atoms
137935 RESO important JOB Trimestriel  description of gtk.gdk.atom_intern() should be in gtk.gdk...
137969 NEW  urgent JOB hebdomadaire GenericTreeModel/TreeSelection returning GtkTreeIter inst...
138104 RESO important JOB Trimestriel  gtk_widget_style_get_property is not wrapped
138163 veri memo personnel mensuelNOTA gtk.main_iteration(TRUE) unblocks every .1 seconds
138476 RESO important JOB Trimestriel  gtk.Layout is veri memo personnel mensuel urgent personnel mensueled by gnome.canvas but is missing from ...
138487 RESO important JOB Trimestriel  PyGTK Tutorial: in Calendar sample date string is 1 day b...
138576 RESO important JOB Trimestriel  gtk.IconSet now has 2 constructors in gtk.defs, while on...
138619 NEW  urgent JOB mensuel codegen/definitions.py could use some refactoring
138772 RESO important JOB Trimestriel  Callback parameters to input_add are incorrect
138804 NEW  urgent JOB mensuel In gtk2.4, gdk_font_get_display and gdk_pixmap_lookup is ...
138944 NEW  urgent JOB mensuel Cannot import gtk when pygtk installed using 'make install'
139128 NEW  urgent JOB mensuel All constructors should be defined as constructors
139130 NEW  urgent JOB hebdomadaire GtkEntry's constructor veri memo personnel mensuel urgent personnel mensuels to be rewritten
139312 veri memo personnel mensuel urgent personnel mensuel gtk.gdk.Window.get_screen method undocumented.
139921 RESO important JOB Trimestriel  Support tp_NEW  urgent JOB hebdomadaire
140071 NEW  urgent JOB hebdomadaire Register custom widget classes.
140665 RESO important JOB Trimestriel  TypeError when creating user defined signals having third...
140718 NEW  urgent JOB mensuel Enhance codegen with user defined type wrapper.
140946 NEW  urgent JOB mensuel filechooser example broken
141042 RESO important JOB Trimestriel  Garbage collection causes lossage in Pango
141886 NEW  urgent JOB mensuel Add a PyGEnum_Type
142030 RESO important JOB Trimestriel  Possible ref count error in gtk.GC
142738 RESO important JOB Trimestriel  Fatal error with multi-depth menus
142997 NEW  urgent JOB mensuel require() breaks sys.path if libs found in /usr/local/r/local
444444 BIDO urgent JOB Trimestriel breaks sys.path if libs found in /usr/local/r/local ligne bidon"""
 
class TreeModelFilterExemple:
 
    # ferme la fenetre et quitte
    def delete_event(self, widget, event, donnees=None):
        gtk.main_quit()
        return False
 
    def __init__(self):
        # Cree une nouvelle fenetre
        self.fenetre = gtk.Window(gtk.WINDOW_TOPLEVEL)
 
        self.fenetre.set_title("Exemple TreeModelFilter")
 
        self.fenetre.set_size_request(600, 400)
 
        self.fenetre.connect("delete_event", self.delete_event)
 
        # creea un liststore avec une colonne de type chaine comme modele
        self.liststore = gtk.ListStore(int, str, str,str,str,str)
 
        self.filtremodele = self.liststore.filter_new() #le modèle de filtrage ici appliqué sur le list store normal c'est sur les donnees q'ont filtrent
 
        # cree le TreeView
        self.treeview = gtk.TreeView()
 
        # cree les colonnes du TreeView pour afficher les donnees
        self.treeview.colonnes = [None]*6
        self.treeview.colonnes[0] = gtk.TreeViewColumn('Bug No.')
        self.treeview.colonnes[1] = gtk.TreeViewColumn('Statut')
        self.treeview.colonnes[2] = gtk.TreeViewColumn('importance')
        self.treeview.colonnes[3] = gtk.TreeViewColumn('domaine')
        self.treeview.colonnes[4] = gtk.TreeViewColumn(u'périodicité')
        self.treeview.colonnes[5] = gtk.TreeViewColumn('Description')
 
 
        # ajoute les donnees de bug
        self.etats = []
        compteur=1
        for line in bugdata.split('\n'):
            l = line.split()
            """
            print "longueur ligne= ",len(l)
            print "liste = ",l
            print "Compteur= ",compteur
            compteur=compteur+1
            print l[0]
            print l[1]
            print l[2]
            print l[3]
            print l[4]
            print l[5]
            print l[6]
            """
            liste=[int(l[0]), l[1],l[2],l[3], l[4],' '.join(l[5:])]
            #print "long= ",len(liste)," ",liste
            self.liststore.append(liste)
            #self.liststore.append([int(l[0]), l[1], l[2],' '.join(l[2:])])
            #self.liststore.append([int(l[0]), l[1],l[2],l[3], ' '.join(l[4:])])
            if not l[1] in self.etats:
                self.etats.append(l[1]) # les clés de filtrage faites ici
 
 
        self.montre_etats = self.etats[:]
        self.filtremodele.set_visible_func(self.visible_cb, self.montre_etats) # mecanisme qui va appliquer le mécanisme à l'init
        #  et en permanence
 
        self.treeview.set_model(self.filtremodele) # lien avec le modele qui visualise les données
        self.treeview.set_reorderable(True)
 
        for n in range(6):
            #self.treeview.colonnes[n].set_search_column(1)
            self.treeview.colonnes[n].set_sort_column_id(n)
            # ajoute les colonnes au treeview
            self.treeview.append_column(self.treeview.colonnes[n])
            # cree un CellRenderers pour formater les donnees
            self.treeview.colonnes[n].cell = gtk.CellRendererText()
            # ajoute les cellules aux colonnes
            self.treeview.colonnes[n].pack_start(self.treeview.colonnes[n].cell,
                                                True)
 
 
 
 
            self.treeview.colonnes[n].set_resizable(True)
            self.treeview.colonnes[n].set_reorderable(n)
            self.treeview.colonnes[n].set_sort_column_id(n)
            # fixe les attibuts de cellule a la colonne adequate
            self.treeview.colonnes[n].set_attributes(
                self.treeview.colonnes[n].cell, text=n)
 
 
        # autorise la recherche dans le treeview
        self.treeview.set_search_column(3)
 
        # cree l'interface utilisateur
        self.boitever = gtk.VBox()
        self.fen_deroule = gtk.ScrolledWindow()
        self.boite_bouton = gtk.HButtonBox()
        self.boitever.pack_start(self.fen_deroule)
        self.boitever.pack_start(self.boite_bouton, False)
        # cree un bouton bascule pour choisir les filtres utilises
        # selon l'etat des bugs et rend les boutons actifs
        for state in self.etats:
            bouton = gtk.ToggleButton(state)
            self.boite_bouton.pack_start(bouton)
            bouton.set_active(True)
            bouton.connect('toggled', self.verif_boutons) #  le connect qui change la clef de filtrage sur click
 
        bouton2=gtk.ToggleButton("job")
        bouton2.set_active(True)
        self.boite_bouton.pack_start(bouton2)
        bouton3=gtk.ToggleButton("personnel")
        bouton3.set_active(True)
        self.boite_bouton.pack_start(bouton3)
 
 
        bouton3=gtk.ToggleButton("modifier")
        bouton3.set_active(True)
        self.boite_bouton.pack_start(bouton3)
        bouton3.connect('toggled', self.modify)
 
        #bouton2.connect('toggled', self.verif_boutonsjob) #  le connect qui change la clef de filtrage sur click
        #bouton3.connect('toggled', self.verif_boutonsperso) #  le connect qui change la clef de filtrage sur click
 
        self.fen_deroule.add(self.treeview)
        self.fenetre.add(self.boitever)
 
        self.fenetre.show_all()
        return
 
    def modify(self, donnees):
        TreeSelection =self.treeview.get_selection()
 
	# Get the selection iter
	TreeModel, selection_iter = TreeSelection.get_selected()
        if selection_iter==None:
            self.show_error_dlg("Sélectionnez une ligne pour la modifier")
        else:
            child_iter = self.filtremodele.convert_iter_to_child_iter(selection_iter)
            if gtk.TREE_MODEL_ITERS_PERSIST==self.liststore.get_flags() :
                print "treeview persistant"
            else:
                 print "treeview PAS persistant"
            if self.liststore.iter_is_valid(child_iter):
                # comme selection_iter est valide ici je peux accéder aux données pour les modifier, etc...
                print "Iter valide"
                print self.liststore.get_value(child_iter,0)
            else:
                print "Iter invalide"
                # comme selection_iter est invalide ici je ne peux pas accéder aux données pour les modifier, etc...
 
    # determine la visibilite des donnees selon l'etat des boutons de filtre
    def visible_cb(self, modele, iter, donnees):
        flag=False # faut afficaher ou pas
 
        return modele.get_value(iter, 1) in donnees
 
    def visible_cbjob(self, modele, iter, donnees):
        flag=False # faut afficaher ou pas
 
        return modele.get_value(iter, 1) in donnees
 
    # construit la liste des etats de bug a afficher et les filtre
    def verif_boutons(self, tb):
        del self.montre_etats[:]
        for bouton in self.boite_bouton.get_children():
            if bouton.get_active():
                self.montre_etats.append(bouton.get_label())
        self.filtremodele.refilter()
        return
    def show_error_dlg(self,error_string):
        """This Function is used to show an error dialog when
        an error occurs.
        error_string - The error string that will be displayed
        on the dialog.
        """
        error_dlg = gtk.MessageDialog(type=gtk.MESSAGE_ERROR
                                            , message_format=error_string
                                            , buttons=gtk.BUTTONS_OK)
        error_dlg.run()
        error_dlg.destroy()
 
def main():
    gtk.main()
 
if __name__ == "__main__":
    exempletmf = TreeModelFilterExemple()
    main() |