-
#!/usr/bin/python
-
# -*- coding: utf-8 -*-
-
-
#/ Ferdjaoui Sahid
-
#/ Mail: sahid@funraill.org
-
#/ WWW: http://sahid.funraill.org
-
#/
-
# Exemple de gestion des signaux Clipboard
-
# sur un gtk.Entry
-
-
-
# Module GTK
-
import gtk
-
-
# Interface graphique
-
class Wnd (object):
-
def __init__ (self):
-
“”” Construction de la fenetre ““”
-
# VBox
-
self.vbox = gtk.VBox ();
-
# Wnd
-
self.wnd = gtk.Window ();
-
self.wnd.set_title (“Exemple”);
-
self.wnd.set_size_request (175, 75);
-
self.wnd.connect (“destroy”, gtk.main_quit);
-
self.wnd.add (self.vbox);
-
-
# Menu
-
self.menu (self.wnd);
-
# Entry
-
self.entry ();
-
-
self.wnd.show_all ();
-
-
def menu (self, wnd):
-
“”” Generation du menu ““”
-
menu_items = (
-
(“/_Fichier”, None, None, 0, “<Branch>”),
-
(“/Fichier/_Quitter”, “<control>Q”, gtk.main_quit, 0, None),
-
(“/_Edition”, None, None, 0, “<Branch>”),
-
(“/Edition/_Couper”, “<control>X”, self.on_couper, 0, None),
-
(“/Edition/_Copier”, “<control>C”, self.on_copier, 0, None),
-
(“/Edition/_Coller”, “<control>V”, self.on_coller, 0, None),
-
);
-
-
item_factory = gtk.ItemFactory (gtk.MenuBar, “<main>”, None);
-
item_factory.create_items (menu_items);
-
self.vbox.pack_start (item_factory.get_widget (“<main>”), False, True, 0);
-
-
def entry (self):
-
“”” Ajout d’un gtk.Entry ““”
-
entry = gtk.Entry ();
-
self.vbox.pack_start (entry, True, True, 0);
-
-
def on_couper (self, action, widget):
-
“”” Gestion du signal cut ““”
-
w = self.wnd.get_focus ();
-
if (isinstance (w, gtk.Entry)):
-
w.emit (“cut-clipboard”);
-
-
def on_copier (self, action, widget):
-
“”” Gestion du signal copy ““”
-
w = self.wnd.get_focus ();
-
if (isinstance (w, gtk.Entry)):
-
w.emit (“copy-clipboard”);
-
-
def on_coller (self, action, widget):
-
“”” Gestion du signal paste ““”
-
w = self.wnd.get_focus ();
-
if (isinstance (w, gtk.Entry)):
-
w.emit (“paste-clipboard”);
-
-
-
if __name__ == “__main__”:
-
Wnd ();
-
gtk.main ()