[pygtk] Fwd: applet & gtk.label

Pachi pachi at rvburke.com
Sun Feb 13 02:41:40 WST 2011


Sending to the right list (pygtk-web is for website related issues only)

-------- Original Message --------
Subject: 	applet & gtk.label
Date: 	Sat, 12 Feb 2011 13:52:44 +0100
From: 	Cyril Mella <myhpep at gmail.com>
To: 	pygtk-web at async.com.br



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hello,
i've a problem and i can't found any solution
i explain it but if you think i can go somewhere to ask, just say me
thx

i create a applet to follow number of manga
first time i click, all ok, but second time, return to original value
ex: Bleach:308 ->  Bleach:309 ->  Bleach:308

in the fmanga.txt just type this:
Bleach:308
Naruto:200

the file.py:
#!/usr/bin/env python

import os
import sys
import string
import gtk
import pygtk
import gnomeapplet
import shutil

pygtk.require('2.0')


def add_num(button):
     n=button.get_label()
     n=n.split(":")
     fichier = open("/home/HPep/SH/fmanga.txt", "r")
     fout = open("/home/HPep/SH/fmanga2.txt", "w")
     for i in fichier:
         i=i.replace("\n","")
         l=i.split(":")
         if l[0] == n[0]:
             num = int(l[1]) + 1
             nom = l[0] + ":" + str(num)
             i=nom
             button.set_label(nom)
         fout.write(i+"\n")
     fichier.close()
     fout.close()
     shutil.copy("/home/HPep/SH/fmanga2.txt","/home/HPep/SH/fmanga.txt")
     return True

def applet_factory(applet, iid):
     lab=""
     box = gtk.HBox()
     fichier = open("/home/HPep/SH/fmanga.txt", "r")
     for i in fichier:
         i = i.replace("\n","")
         label = gtk.Button(i)
         label.connect("clicked", add_num)
         box.add(label)

     label = gtk.Label(" ")
     box.add(label)

     applet.add(box)
     applet.show_all()
     xml="""<popup name="button3">
     <menuitem name="ItemPreferences" verb="Preferences"
label="_Preferences" pixtype="stock" pixname="gtk-preferences"/>
     </popup>"""
     verbs = [('Preferences', show_preferences)]
     applet.setup_menu(xml, verbs, None)
     return True

def show_preferences(*arguments):
     return True

if len(sys.argv) == 2 and sys.argv[1] == "run-in-window":
     main_window = gtk.Window(gtk.WINDOW_TOPLEVEL)
     main_window.set_title("Python Applet")
     main_window.connect("destroy", gtk.mainquit)
     app = gnomeapplet.Applet()
     applet_factory(app, None)
     app.reparent(main_window)
     main_window.show_all()
     gtk.main()
     sys.exit()

if __name__ == '__main__': # testing for execution
     gnomeapplet.bonobo_factory('OAFIID:FMangaApplet_Factory',
gnomeapplet.Applet.__gtype__, 'Sample Applet', '0.1', applet_factory)



-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org/

iQEcBAEBAgAGBQJNVoKbAAoJEEPfZNMebfLI304IAKhudf9IP4bLJXZ6n5n7x79/
9b7WsXP5sjZLq9c7UmGui0N37S9JPFqCZd0tS8QESztEwVRuMKCy4Lzq+xwWgKtC
TeCCfJfzZOlSXfkZMgwGJG2JQxAxvvGohpgP94AvV30XDuOfj3qRo/X4uR8HVJWN
c+w8yXNGvexTqYCup2XHJDFC5eTQ8n2wHxIwwKxpopPlEsHJ9qTD3RHd4dpPfEYZ
eEVsc2sW1ws/450wamUF/21/ujFxKTIbtt6jfWkaHwMiktW39mGZR62LFMbiN3S3
qzrxA9w9LBndOZs0Dj8OLg3WCW+T+qTIxCyzl9sb6+y7b0K/Vev784arlx5lhpU=
=ZlRH
-----END PGP SIGNATURE-----


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.daa.com.au/pipermail/pygtk/attachments/20110212/f2a1c3a8/attachment.html>


More information about the pygtk mailing list