IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

GTK+ avec Python Discussion :

Statusbar -> gtk + python + glade


Sujet :

GTK+ avec Python

  1. #1
    Membre averti
    Profil pro
    Inscrit en
    Septembre 2010
    Messages
    20
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2010
    Messages : 20
    Par défaut Statusbar -> gtk + python + glade
    Bonjour à tous !!

    Comme dirais un proverbe chinois : au fond du puit l'horizon parait bien étroit...

    Je me présente je suis un petit nouveau sur ce site et j'aurais aimé avoir votre aide sur l'utilisation du widget statusbar en gtk ...

    Je débute sous python (premier script) et encore davantage sous glade mais bon faut débuter un jour donc je me lance.

    J'ai repris un fichier glade et un script python que j'ai adapté pour faire mes tests et je rajoute des choses au fur et à mesure pour comprendre le fonctionnement de python et de GTK .

    Je voudrais afficher dans une statusbar un texte au démarrage de l'interface graphique.

    texte recuperé par une commande system.

    genre -> toto = os.system("cat /tmp/titi.lst | head -1 | awk '{print $1}' ")
    toto devant être affiché dans la statusbar

    je comprends pas bien le fonctionnement de l'implémentation d'un widget donc les docs dessus ne m'aide pas trop donc si un pro du codage peux m'indiquer quelques pistes ou me décrire le processus de mise en place cela serait cool...


    ci-dessous le script python
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    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
     
    #!/usr/bin/python
    # -*- coding: utf-8 -*-
     
    import pygtk
    pygtk.require("2.0")
    import gtk
    import os
     
    #class qui permet l'affichage et l'interaction avec l'interface graphique sous glade
    class Window:
    	def __init__(self):
    		self.interface = gtk.Builder()
    		self.interface.add_from_file('projet.glade')
    		self.interface.connect_signals(self)
     
     
     
    	# fermeture de la fenetre
    	def on_mainWindow_destroy(self, widget):
    		gtk.main_quit()
     
     
    	# au clic sur le bouton fichier>quitter
    	def on_imagemenuitem_quit_activate(self, widget):
    		gtk.main_quit()
     
    	# au clic sur le bouton aide>à propos
    	def on_imagemenuitem10_activate(self, widget):
    		self.interface.get_object("aboutdialog").run()
    		self.interface.get_object("aboutdialog").hide()
     
     
    	# tentative de l'appel dans glade de la statusbar
    	def on_statusbar_activate(self,widget):
    		gtkstatusbar()
     
     
     
    if __name__ == "__main__":
    	Window()
    	gtk.main()
    ===============================================================
    et le fichier glade pour tester
    ================================================================

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    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
     
    <?xml version="1.0"?>
    <interface>
      <requires lib="gtk+" version="2.16"/>
      <!-- interface-naming-policy project-wide -->
      <object class="GtkWindow" id="window1">
        <property name="visible">True</property>
        <property name="window_position">center-always</property>
        <property name="default_width">650</property>
        <property name="default_height">650</property>
        <signal name="destroy" handler="on_mainWindow_destroy"/>
        <child>
          <object class="GtkVBox" id="vbox1">
            <property name="visible">True</property>
            <property name="orientation">vertical</property>
            <child>
              <object class="GtkMenuBar" id="menubar1">
                <property name="visible">True</property>
                <child>
                  <object class="GtkMenuItem" id="menuitem1">
                    <property name="visible">True</property>
                    <property name="label" translatable="yes">_Fichier</property>
                    <property name="use_underline">True</property>
                    <child type="submenu">
                      <object class="GtkMenu" id="menu1">
                        <property name="visible">True</property>
                        <child>
                          <object class="GtkImageMenuItem" id="imagemenuitem1">
                            <property name="label">gtk-new</property>
                            <property name="visible">True</property>
                            <property name="use_underline">True</property>
                            <property name="use_stock">True</property>
                          </object>
                        </child>
                        <child>
                          <object class="GtkImageMenuItem" id="imagemenuitem2">
                            <property name="label">gtk-open</property>
                            <property name="visible">True</property>
                            <property name="use_underline">True</property>
                            <property name="use_stock">True</property>
                          </object>
                        </child>
                        <child>
                          <object class="GtkImageMenuItem" id="imagemenuitem3">
                            <property name="label">gtk-save</property>
                            <property name="visible">True</property>
                            <property name="use_underline">True</property>
                            <property name="use_stock">True</property>
                          </object>
                        </child>
                        <child>
                          <object class="GtkImageMenuItem" id="imagemenuitem4">
                            <property name="label">gtk-save-as</property>
                            <property name="visible">True</property>
                            <property name="use_underline">True</property>
                            <property name="use_stock">True</property>
                          </object>
                        </child>
                        <child>
                          <object class="GtkSeparatorMenuItem" id="separatormenuitem1">
                            <property name="visible">True</property>
                          </object>
                        </child>
                        <child>
                          <object class="GtkImageMenuItem" id="imagemenuitem5">
                            <property name="label">gtk-quit</property>
                            <property name="visible">True</property>
                            <property name="use_underline">True</property>
                            <property name="use_stock">True</property>
                            <signal name="activate" handler="on_imagemenuitem_quit_activate"/>
                          </object>
                        </child>
                      </object>
                    </child>
                  </object>
                </child>
                <child>
                  <object class="GtkMenuItem" id="menuitem2">
                    <property name="visible">True</property>
                    <property name="label" translatable="yes">&#xC9;_dition</property>
                    <property name="use_underline">True</property>
                    <child type="submenu">
                      <object class="GtkMenu" id="menu2">
                        <property name="visible">True</property>
                        <child>
                          <object class="GtkImageMenuItem" id="imagemenuitem6">
                            <property name="label">gtk-cut</property>
                            <property name="visible">True</property>
                            <property name="use_underline">True</property>
                            <property name="use_stock">True</property>
                          </object>
                        </child>
                        <child>
                          <object class="GtkImageMenuItem" id="imagemenuitem7">
                            <property name="label">gtk-copy</property>
                            <property name="visible">True</property>
                            <property name="use_underline">True</property>
                            <property name="use_stock">True</property>
                          </object>
                        </child>
                        <child>
                          <object class="GtkImageMenuItem" id="imagemenuitem8">
                            <property name="label">gtk-paste</property>
                            <property name="visible">True</property>
                            <property name="use_underline">True</property>
                            <property name="use_stock">True</property>
                          </object>
                        </child>
                        <child>
                          <object class="GtkImageMenuItem" id="imagemenuitem9">
                            <property name="label">gtk-delete</property>
                            <property name="visible">True</property>
                            <property name="use_underline">True</property>
                            <property name="use_stock">True</property>
                          </object>
                        </child>
                      </object>
                    </child>
                  </object>
                </child>
                <child>
                  <object class="GtkMenuItem" id="menuitem3">
                    <property name="visible">True</property>
                    <property name="label" translatable="yes">_Affichage</property>
                    <property name="use_underline">True</property>
                  </object>
                </child>
                <child>
                  <object class="GtkMenuItem" id="menuitem4">
                    <property name="visible">True</property>
                    <property name="label" translatable="yes">Aid_e</property>
                    <property name="use_underline">True</property>
                    <child type="submenu">
                      <object class="GtkMenu" id="menu3">
                        <property name="visible">True</property>
                        <child>
                          <object class="GtkImageMenuItem" id="imagemenuitem10">
                            <property name="label">gtk-about</property>
                            <property name="visible">True</property>
                            <property name="use_underline">True</property>
                            <property name="use_stock">True</property>
                            <signal name="activate" handler="on_imagemenuitem10_activate"/>
                          </object>
                        </child>
                      </object>
                    </child>
                  </object>
                </child>
              </object>
              <packing>
                <property name="expand">False</property>
                <property name="position">0</property>
              </packing>
            </child>
            <child>
              <placeholder/>
            </child>
            <child>
              <object class="GtkVBox" id="vbox2">
                <property name="visible">True</property>
                <property name="orientation">vertical</property>
                <child>
                  <placeholder/>
                </child>
                <child>
                  <placeholder/>
                </child>
                <child>
                  <object class="GtkStatusbar" id="statusbar">
                    <property name="visible">True</property>
                    <property name="spacing">2</property>
                    <signal name="text_pushed" handler="on_statusbar_text_pushed"/>
                    <signal name="text_popped" handler="on_statusbar_text_popped"/>
                  </object>
                  <packing>
                    <property name="expand">False</property>
                    <property name="position">2</property>
                  </packing>
                </child>
              </object>
              <packing>
                <property name="position">2</property>
              </packing>
            </child>
          </object>
        </child>
      </object>
      <object class="GtkAboutDialog" id="aboutdialog">
        <property name="border_width">5</property>
        <property name="window_position">center-always</property>
        <property name="type_hint">normal</property>
        <property name="has_separator">False</property>
        <property name="program_name">Free Software </property>
        <property name="version">1.0</property>
        <property name="website">http://www.toto.net</property>
        <property name="authors">toto</property>
        <child internal-child="vbox">
          <object class="GtkVBox" id="dialog-vbox1">
            <property name="visible">True</property>
            <property name="orientation">vertical</property>
            <property name="spacing">2</property>
            <child>
              <placeholder/>
            </child>
            <child internal-child="action_area">
              <object class="GtkHButtonBox" id="dialog-action_area1">
                <property name="visible">True</property>
                <property name="layout_style">end</property>
              </object>
              <packing>
                <property name="expand">False</property>
                <property name="pack_type">end</property>
                <property name="position">0</property>
              </packing>
            </child>
          </object>
        </child>
      </object>
    </interface>

  2. #2
    Membre éclairé
    Homme Profil pro
    Étudiant
    Inscrit en
    Novembre 2008
    Messages
    327
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 34
    Localisation : France, Seine et Marne (Île de France)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Novembre 2008
    Messages : 327
    Par défaut
    Bonjour a toi,

    J'ai voulu testé chez moi, mais le fichier glade donné comme sa est illisible et je vais pas m'amuser à refair eles tabulations ^^

    Sinon, moi j'aurai mis sa comme sa dans mon __init__

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    import gtk.glade
     
    def __init__(self):
            #self.interface = gtk.Builder()
            self.interface = gtk.glade.XML("projet.glade", "nom_de_la_fenetre_principale")
            #self.interface.add_from_file('projet.glade')
            self.interface.connect_signals(self)
    Pour le reste, je n'ai pas trop bien saisie le problème... Qu'est ce qui ne fonctionne pas réellement, rien ne s'affiche, rien ne se lance, etc

    Tiens moi au courant

  3. #3
    Membre averti
    Profil pro
    Inscrit en
    Septembre 2010
    Messages
    20
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2010
    Messages : 20
    Par défaut implementer une statusbar
    Le problème ne viens pas du fichier glade puisque l'application fonctionne..
    pour info un copier/coller dans gedit et enregistrer sous -> projet.glade fonctionne bien pas de pb de tabulation...

    Mais d'un rajout d'une fonctionnalité

    Je voudrais afficher dans une statusbar un texte au démarrage de l'interface graphique.

    texte recuperé par une commande system.

    genre -> toto = os.system("cat /tmp/titi.lst | head -1 | awk '{print $1}' ")
    toto devant être affiché dans la statusbar

  4. #4
    Membre éclairé
    Homme Profil pro
    Étudiant
    Inscrit en
    Novembre 2008
    Messages
    327
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 34
    Localisation : France, Seine et Marne (Île de France)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Novembre 2008
    Messages : 327
    Par défaut
    Okai, je n'ai pas reessayé ton fichier glade mais voila ce que tu as à faire :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    import gtk.glade
    import os
     
    toto = os.system("cat /tmp/titi.lst | head -1 | awk '{print $1}' ")
     
    class Window:
     
        def __init__(self):
            self.interface = gtk.glade.XML("projet.glade", "window1")
            self.interface.get_widget("statusbar").set_text(toto)
     
    if __name__ == "__main__":
        Window()
        gtk.main()


    Cela devrait faire l'affaire...

    A bientot.

  5. #5
    Membre averti
    Profil pro
    Inscrit en
    Septembre 2010
    Messages
    20
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2010
    Messages : 20
    Par défaut voilà ...
    Comme j'utilise gtkbuilder il faut utiliser get_object et pas get_widget et subprocess pour ramener le résultat de la commande.


    self.interface.get_object("statusbar").set_text(toto)

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. python glade eclipse shell idle
    Par linedubeth dans le forum GTK+ avec Python
    Réponses: 4
    Dernier message: 10/09/2009, 13h51
  2. GTK et Glade-3
    Par KiKiTiTi dans le forum GTK+ avec C & C++
    Réponses: 0
    Dernier message: 18/02/2008, 00h06
  3. Le programme python-glade
    Par Olivier Regnier dans le forum Applications et environnements graphiques
    Réponses: 2
    Dernier message: 11/02/2007, 15h09
  4. Sélecteur de couleurs avec GTK+ et GLADE
    Par Le Chti Guigui dans le forum GTK+ avec C & C++
    Réponses: 2
    Dernier message: 05/01/2007, 10h53
  5. Réponses: 17
    Dernier message: 10/10/2006, 19h57

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo