Contenu | Rechercher | Menus

Annonce

Si vous avez des soucis pour rester connecté, déconnectez-vous puis reconnectez-vous depuis ce lien en cochant la case
Me connecter automatiquement lors de mes prochaines visites.

À propos de l'équipe du forum.

#1 Le 18/08/2011, à 22:00

Josepe36

[1/2Resolu]besoin d'un conseil pygtk gtkiconview, svp

Bonsoir à tous

je suis en cours de developpement d'une application en python, pygtk avec glade.
Dans l'enssemble ça va comme je veux mais  je butte sur gtkiconview, j'arrive a afficher ma liste d icone, interagir avec etc pas de soucis mais là ou est le probléme c est que le temp de charger ma liste de "pixbuf" et bien mon application met environ 10 secondes avant de s afficher ( c est moche) tongue
J ai essayé de threader mais rien a faire.

Donc ce code c est un control-center, et une partie est consacrée a la gestion du fond d'ecran, pour ce faire un iconview et un ListStore, donc la question c est :

comment faire pour que l application s ouvre de suite et que les icone apparaissent dans l iconview au fur et a mesure qu'elles sont chargées ?
(comme le fait le gestionnaire de fond d ecran de gnome3)

je poste le code et vous remercie par avance  smile

#!/usr/bin/python
# -*- coding:utf-8 -*-

#==========================================================================#
#    Josepe36 11/08/2011 - olivelinux36@gmail.com
#    This file is part of hy-geek.
#
#    hy-geek is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    hy-geek is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with Foobar.  If not, see <http://www.gnu.org/licenses/>.
#==========================================================================#


import pygtk
pygtk.require("2.0")
import gtk.glade
import gtk
import sys
import os
import re
import gmenu
import os.path
import ConfigParser
import urllib
import traceback
import glob
import gtkmozembed
import threading
import time

## Répertoire courant
realpath = os.path.dirname(os.path.realpath( __file__ ))
os.chdir(realpath)
## Nom de l'utilisateur
USER = os.environ.get("USER")
USER_DIR= "/home/"+USER
print USER_DIR

class hy_control_center:
    def __init__(self):
        interface = gtk.Builder()
        
        interface.add_from_file('hy-control-center.glade')
        self.window = interface.get_object("dialog1")
        self.image = gtk.Image()
        #self.window.set_decorated(False)
        self.scroll = interface.get_object("scrolledwindow1")
        self.scroll2 = interface.get_object("scrolledwindow2")
        self.content_box = interface.get_object("hbox1")
        self.button1 = interface.get_object("button1")
        self.button2 = interface.get_object("button2")
        self.geek1 = interface.get_object("frame1")
        self.geek2 = interface.get_object("frame2")
        self.icon_view1 = interface.get_object("iconview1")
        self.geek1.hide()
        self.geek2.hide()
        self.wall = interface.get_object("vbox3")
        self.wall2 = interface.get_object("vbox4")
        self.image = interface.get_object("image1")
        self.wall.hide()
        self.wall2.hide()

        interface.connect_signals(self)
        os.system("gsettings set org.gnome.desktop.background draw-background true")
        self.model = gtk.ListStore(str, gtk.gdk.Pixbuf)

        pixbuf = gtk.gdk.pixbuf_new_from_file("1.jpg") 
        #scaled_buf = pixbuf.scale_simple (40,40, gtk.gdk.INTERP_BILINEAR)       
        self.model.append(["Hy-geek", pixbuf])

        pixbuf = gtk.gdk.pixbuf_new_from_file("1.jpg") 
        #scaled_buf = pixbuf.scale_simple (40,40, gtk.gdk.INTERP_BILINEAR)       
        self.model.append(["Wallpaper", pixbuf])

        pixbuf = gtk.gdk.pixbuf_new_from_file("1.jpg") 
        #scaled_buf = pixbuf.scale_simple (40,40, gtk.gdk.INTERP_BILINEAR)       
        self.model.append(["Infos", pixbuf])

               self.icon_view2 = interface.get_object("iconview2")
        self.icon_view2.set_model(self.model)
                self.icon_view2.set_text_column(0)
                self.icon_view2.set_pixbuf_column(1)
                self.icon_view2.set_orientation(gtk.ORIENTATION_HORIZONTAL)
                self.icon_view2.set_selection_mode(gtk.SELECTION_SINGLE)
                

                self.icon_view2.set_columns(1)
                self.icon_view2.set_item_width(-1)
        self.icon_view2.connect('selection-changed', self.on_select, self.model)
                screen_x , screen_y = gtk.gdk.screen_width(), gtk.gdk.screen_height()
                

                
                self.icon_view2.select_path((0,)) # select a category, will create frame
        #os.system("mkdir " + USER_DIR + "/.thumbnails/normal/wall/ ;" + "for i in $(ls /usr/share/backgrounds/ugr-wallpapers/);do convert -resize 50x30 /usr/share/backgrounds/ugr-wallpapers/$i " + USER_DIR + "/.thumbnails/normal/wall/$i;done")

        self.liste2 = glob.glob("/usr/share/backgrounds/ugr-wallpapers/*")    
        self.model2 = gtk.ListStore(str, gtk.gdk.Pixbuf)  #gtk.ListStore(str, gtk.gdk.Pixbuf)
                #thread=threading.Thread(target=self.thread_miniatures)
            #thread.start()  
            #list_miniatures = glob.glob(USER_DIR + "/.thumbnails/normal/wall/*")
        for image in self.liste2:                
              pixbuf = gtk.gdk.pixbuf_new_from_file (image)
               scaled_buf = pixbuf.scale_simple (100,70, gtk.gdk.INTERP_BILINEAR)
            self.model2.append([image, scaled_buf])
            #model.append([image])
                
        self.icon_view1.set_model(self.model2)
            
        #self.icon_view1.set_text_column(0)
            self.icon_view1.set_pixbuf_column(1)
            self.icon_view1.set_orientation(gtk.ORIENTATION_HORIZONTAL)
            self.icon_view1.set_selection_mode(gtk.SELECTION_SINGLE)
                        
            self.icon_view1.set_columns(1)
            self.icon_view1.set_item_width(20)
        self.icon_view1.connect('selection-changed', self.on_select_wall, self.model2)
        self.icon_view1.select_path((0,)) # select a category, will create frame        


        self.icon_view3 = interface.get_object("iconview3")

        self.model3 = gtk.ListStore(str, gtk.gdk.Pixbuf)

    def on_button1_clicked(self, widget):
        selected = self.icon_view1.get_selected_items()
        i = selected[0][0]
        category = self.model2[i][0]
        print category
          pixbuf = gtk.gdk.pixbuf_new_from_file(category)
           scaled_buf = pixbuf.scale_simple (100,70, gtk.gdk.INTERP_BILINEAR)
        self.model3.append([category, scaled_buf])
                
        self.icon_view3.set_model(self.model3) 
            
        #self.icon_view3.set_text_column(0)
            self.icon_view3.set_pixbuf_column(1)
            
            self.icon_view3.set_selection_mode(gtk.SELECTION_SINGLE)
                        
            
            
        #self.icon_view1.connect('selection-changed', self.on_select_wall, model)
        self.icon_view3.select_path((0,)) # select a category, will create frame        



    def on_select_wall(self, icon_view, model=None):
        selected = icon_view.get_selected_items()
        if len(selected) == 0: return
        i = selected[0][0]
        category = model[i][0]
           pixbuf = gtk.gdk.pixbuf_new_from_file (category)
           scaled_buf = pixbuf.scale_simple (580,340, gtk.gdk.INTERP_BILINEAR)
        
        self.image.set_from_pixbuf(scaled_buf)
        print selected
        print i
        print category
        tmp = open('/tmp/wall', 'a')
        tmp.write(category + "\n")
        tmp.close()
        os.system("gsettings set org.gnome.desktop.background picture-uri file://" + category + "&")
        os.system("echo " + category + " > /tmp/wall")
    
        
    def on_select(self, icon_view, model=None):
        selected = icon_view.get_selected_items()
        if len(selected) == 0: return
        i = selected[0][0]
        category = model[i][0]
            
                if category == 'Infos':
            self.geek1.hide()
            self.geek2.hide()
            self.wall.hide()
            self.wall2.hide()
            self.scroll.hide()
            self.web = gtkmozembed.MozEmbed()
                    if self.web.show() is not None:
                return
                        
            else:
                self.content_box.add(self.web)
                self.web.load_url('file:///home/lapin36/.fleex/M_apps.html')
                self.web.show()
                if category == 'Hy-geek':
                    self.scroll.hide()
            self.wall.hide()
            self.wall2.hide()
            self.geek1.show()
            self.geek2.show()
            self.web.hide()

                if category == 'Wallpaper':
            self.geek1.hide()
            self.geek2.hide()

            self.wall.show()
            self.wall2.show()
            self.scroll.show()
            self.web.hide()
if __name__ == "__main__":

    hy_control_center()
    gtk.main()

Dernière modification par Josepe36 (Le 20/08/2011, à 09:38)


Développeur distribution Hybryde
www.hybryde.org

Hors ligne

#2 Le 18/08/2011, à 22:06

Josepe36

Re : [1/2Resolu]besoin d'un conseil pygtk gtkiconview, svp

voici une capture :
fo_ubu.png

Dernière modification par Josepe36 (Le 18/08/2011, à 22:08)


Développeur distribution Hybryde
www.hybryde.org

Hors ligne

#3 Le 18/08/2011, à 22:43

Josepe36

Re : [1/2Resolu]besoin d'un conseil pygtk gtkiconview, svp

ha oui j oubliai , cette application fonctionnera pour ubuntu, sera sous gpl-3 et pis rien d autre a ajouter big_smile


Développeur distribution Hybryde
www.hybryde.org

Hors ligne

#4 Le 19/08/2011, à 00:27

CKDevelop

Re : [1/2Resolu]besoin d'un conseil pygtk gtkiconview, svp

le premier conseil serait de fournir un script python indenter big_smile
quelle misère ....je regarde tkt ++

Dernière modification par CKDevelop (Le 19/08/2011, à 00:27)


Home -> Debian Jessie & Home server -> Debian Wheezy
Office -> Ubuntu 14.04 & Office server -> Ubuntu 12.04
Embedded -> Raspbian / Debian Wheezy

Hors ligne

#5 Le 19/08/2011, à 00:32

CKDevelop

Re : [1/2Resolu]besoin d'un conseil pygtk gtkiconview, svp

voilà pour l'indentation, il me faudrait le fichier glade c'est possible?

#!/usr/bin/python
# -*- coding:utf-8 -*-

#==========================================================================#
#    Josepe36 11/08/2011 - olivelinux36@gmail.com
#    This file is part of hy-geek.
#
#    hy-geek is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    hy-geek is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with Foobar.  If not, see <http://www.gnu.org/licenses/>.
#==========================================================================#


import pygtk
pygtk.require("2.0")
import gtk.glade
import gtk
import sys
import os
import re
import gmenu
import os.path
import ConfigParser
import urllib
import traceback
import glob
import gtkmozembed
import threading
import time

## Répertoire courant
realpath = os.path.dirname(os.path.realpath( __file__ ))
os.chdir(realpath)
## Nom de l'utilisateur
USER = os.environ.get("USER")
USER_DIR= "/home/"+USER
print USER_DIR

class hy_control_center:
    def __init__(self):
        interface = gtk.Builder()
        
        interface.add_from_file('hy-control-center.glade')
        self.window = interface.get_object("dialog1")
        self.image = gtk.Image()
        #self.window.set_decorated(False)
        self.scroll = interface.get_object("scrolledwindow1")
        self.scroll2 = interface.get_object("scrolledwindow2")
        self.content_box = interface.get_object("hbox1")
        self.button1 = interface.get_object("button1")
        self.button2 = interface.get_object("button2")
        self.geek1 = interface.get_object("frame1")
        self.geek2 = interface.get_object("frame2")
        self.icon_view1 = interface.get_object("iconview1")
        self.geek1.hide()
        self.geek2.hide()
        self.wall = interface.get_object("vbox3")
        self.wall2 = interface.get_object("vbox4")
        self.image = interface.get_object("image1")
        self.wall.hide()
        self.wall2.hide()

        interface.connect_signals(self)
        os.system("gsettings set org.gnome.desktop.background draw-background true")
        self.model = gtk.ListStore(str, gtk.gdk.Pixbuf)

        pixbuf = gtk.gdk.pixbuf_new_from_file("1.jpg") 
        #scaled_buf = pixbuf.scale_simple (40,40, gtk.gdk.INTERP_BILINEAR)       
        self.model.append(["Hy-geek", pixbuf])

        pixbuf = gtk.gdk.pixbuf_new_from_file("1.jpg") 
        #scaled_buf = pixbuf.scale_simple (40,40, gtk.gdk.INTERP_BILINEAR)       
        self.model.append(["Wallpaper", pixbuf])

        pixbuf = gtk.gdk.pixbuf_new_from_file("1.jpg") 
        #scaled_buf = pixbuf.scale_simple (40,40, gtk.gdk.INTERP_BILINEAR)       
        self.model.append(["Infos", pixbuf])

        self.icon_view2 = interface.get_object("iconview2")
        self.icon_view2.set_model(self.model)
        self.icon_view2.set_text_column(0)
        self.icon_view2.set_pixbuf_column(1)
        self.icon_view2.set_orientation(gtk.ORIENTATION_HORIZONTAL)
        self.icon_view2.set_selection_mode(gtk.SELECTION_SINGLE)
                

        self.icon_view2.set_columns(1)
        self.icon_view2.set_item_width(-1)
        self.icon_view2.connect('selection-changed', self.on_select, self.model)
        screen_x , screen_y = gtk.gdk.screen_width(), gtk.gdk.screen_height()
                

                
        self.icon_view2.select_path((0,)) # select a category, will create frame
        #os.system("mkdir " + USER_DIR + "/.thumbnails/normal/wall/ ;" + "for i in $(ls /usr/share/backgrounds/ugr-wallpapers/);do convert -resize 50x30 /usr/share/backgrounds/ugr-wallpapers/$i " + USER_DIR + "/.thumbnails/normal/wall/$i;done")

        self.liste2 = glob.glob("/usr/share/backgrounds/ugr-wallpapers/*")    
        self.model2 = gtk.ListStore(str, gtk.gdk.Pixbuf)  #gtk.ListStore(str, gtk.gdk.Pixbuf)
        #thread=threading.Thread(target=self.thread_miniatures)
        #thread.start()  
        #list_miniatures = glob.glob(USER_DIR + "/.thumbnails/normal/wall/*")
        for image in self.liste2:                
            pixbuf = gtk.gdk.pixbuf_new_from_file (image)
            scaled_buf = pixbuf.scale_simple (100,70, gtk.gdk.INTERP_BILINEAR)
        self.model2.append([image, scaled_buf])
        #model.append([image])
                
        self.icon_view1.set_model(self.model2)
            
        #self.icon_view1.set_text_column(0)
        self.icon_view1.set_pixbuf_column(1)
        self.icon_view1.set_orientation(gtk.ORIENTATION_HORIZONTAL)
        self.icon_view1.set_selection_mode(gtk.SELECTION_SINGLE)
                        
        self.icon_view1.set_columns(1)
        self.icon_view1.set_item_width(20)
        self.icon_view1.connect('selection-changed', self.on_select_wall, self.model2)
        self.icon_view1.select_path((0,)) # select a category, will create frame        


        self.icon_view3 = interface.get_object("iconview3")

        self.model3 = gtk.ListStore(str, gtk.gdk.Pixbuf)

    def on_button1_clicked(self, widget):
        selected = self.icon_view1.get_selected_items()
        i = selected[0][0]
        category = self.model2[i][0]
        print category
        pixbuf = gtk.gdk.pixbuf_new_from_file(category)
        scaled_buf = pixbuf.scale_simple (100,70, gtk.gdk.INTERP_BILINEAR)
        self.model3.append([category, scaled_buf])
                
        self.icon_view3.set_model(self.model3) 
            
        #self.icon_view3.set_text_column(0)
        self.icon_view3.set_pixbuf_column(1)
            
        self.icon_view3.set_selection_mode(gtk.SELECTION_SINGLE)
                        
            
            
        #self.icon_view1.connect('selection-changed', self.on_select_wall, model)
        self.icon_view3.select_path((0,)) # select a category, will create frame        



    def on_select_wall(self, icon_view, model=None):
        selected = icon_view.get_selected_items()
        if len(selected) == 0: 
            return
        i = selected[0][0]
        category = model[i][0]
        pixbuf = gtk.gdk.pixbuf_new_from_file (category)
        scaled_buf = pixbuf.scale_simple (580,340, gtk.gdk.INTERP_BILINEAR)
        
        self.image.set_from_pixbuf(scaled_buf)
        print selected
        print i
        print category
        tmp = open('/tmp/wall', 'a')
        tmp.write(category + "\n")
        tmp.close()
        os.system("gsettings set org.gnome.desktop.background picture-uri file://" + category + "&")
        os.system("echo " + category + " > /tmp/wall")
    
        
    def on_select(self, icon_view, model=None):
        selected = icon_view.get_selected_items()
        if len(selected) == 0: 
            return
        i = selected[0][0]
        category = model[i][0]
            
        if category == 'Infos':
            self.geek1.hide()
            self.geek2.hide()
            self.wall.hide()
            self.wall2.hide()
            self.scroll.hide()
            self.web = gtkmozembed.MozEmbed()
        if self.web.show() is not None:
            return
                        
        else:
            self.content_box.add(self.web)
            self.web.load_url('file:///home/lapin36/.fleex/M_apps.html')
            self.web.show()
            if category == 'Hy-geek':
                self.scroll.hide()
                self.wall.hide()
                self.wall2.hide()
                self.geek1.show()
                self.geek2.show()
                self.web.hide()

            if category == 'Wallpaper':
                self.geek1.hide()
                self.geek2.hide()

                self.wall.show()
                self.wall2.show()
                self.scroll.show()
                self.web.hide()
if __name__ == "__main__":

    hy_control_center()
    gtk.main()

Home -> Debian Jessie & Home server -> Debian Wheezy
Office -> Ubuntu 14.04 & Office server -> Ubuntu 12.04
Embedded -> Raspbian / Debian Wheezy

Hors ligne

#6 Le 19/08/2011, à 02:09

AnsuzPeorth

Re : [1/2Resolu]besoin d'un conseil pygtk gtkiconview, svp

Bjr,
Fallait utiliser G2S .... => [ ]

Plus serieusement, à première vue,  pour y remedier, une solution serait de charger les treestore dans une fonction qui serait appelé sur le signal realize de la window par exemple (ou un autre signal).
Ou alors lancer un timer qui laisse le temps à l'interface de s'ouvrir (gobject.timeout_add).
Doit encore avoir d'autre moyens .... Mais là, vu que tu récupère tes images et charge les treestore dans le init (avant le main), c'est normal que rien ne s'affiche avant que ce soit fini.


Interface graphique pour bash, python ou autre: glade2script
Support Tchat: http://chat.jabberfr.org/muckl_int/inde … ade2script  (Hors ligne)

Hors ligne

#7 Le 19/08/2011, à 07:45

Josepe36

Re : [1/2Resolu]besoin d'un conseil pygtk gtkiconview, svp

Bonjour

merci de repondre présent, @AnsuzPeorth oui glade2script vraiment bien comme moteur cool, mais ici ce que je cherche a faire c est a me detacher du bash
pour essayer d'apprendre python et la lib gtk plus en profondeur.
bon je fille au taf et je vous post une archive vers 12 h00 , ce sera plus imple (le temp de commenter un peu le code).

merci @+


Développeur distribution Hybryde
www.hybryde.org

Hors ligne

#8 Le 19/08/2011, à 13:28

AnsuzPeorth

Re : [1/2Resolu]besoin d'un conseil pygtk gtkiconview, svp

c est a me detacher du bash pour essayer d'apprendre python

Ben tu peux coder en python avec g2s.

la lib gtk plus en profondeur

là, oui, avec g2s tu ne verra pas gtk en profondeur.


Sinon, avec les 2 méthodes possible que j'ai donnée, tu devrait t'en sortir  !


Interface graphique pour bash, python ou autre: glade2script
Support Tchat: http://chat.jabberfr.org/muckl_int/inde … ade2script  (Hors ligne)

Hors ligne

#9 Le 20/08/2011, à 09:37

Josepe36

Re : [1/2Resolu]besoin d'un conseil pygtk gtkiconview, svp

Bonjour

bon j ai trouvé une solution, mais hors context gtk.

La partie gourmande en ressources est la partie de redimensionement des pixbufs, donc la finalitée est d afficher des icones au lieu d un texte.
Pour compenser, j'ai utiliser "convert" par le biais d un script bash , dans le but de creer ces vignettes en amonts, une fois que ces vignettes sont crées et stockés
gtk n a plus qu a les afficher.

Inconvenient : on stock sur le disque autant de vignettes que l on a de background dans /usr/share/background/

Donc en attendant de trouver mieux, je vais mettre un 1/2Resolu  wink


Développeur distribution Hybryde
www.hybryde.org

Hors ligne