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. :ccool:
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:
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:
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">É_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> |
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