1
# -*- coding: utf-8 -*-
2
#####################################################################
3
# Rafael Proença <cypherbios@ubuntu.com>
5
# Copyright 2006 APTonCD DevTeam.
7
# This program is free software; you can redistribute it and/or modify
8
# it under the terms of the GNU General Public License as published
9
# by the Free Software Foundation; version 2 only.
11
# This program is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
# GNU General Public License for more details.
15
#####################################################################
18
class ContextMenu(gtk.Menu):
19
""" Creates context menus accessed by mouse right click. """
20
def __init__(self, *args):
21
gtk.Menu.__init__(self)
24
def addMenuItem(self, menuName, actionFunction=None, menuImage=None, forceName=False):
28
@menuName is the text showed in the menu option.
29
If you pass a - (minus) as parameter value,
30
it will create a separation menu item.
31
@actionFunction is the procedure called when activate signal is triggered from the menu.
35
self.menuItem = gtk.SeparatorMenuItem()
38
if isinstance(menuImage, gtk.Image):
39
self.menuItem = gtk.ImageMenuItem(menuName)
40
self.menuItem.set_image(menuImage)
41
elif isinstance(menuImage, gtk.gdk.Pixbuf):
42
self.menuItem = gtk.ImageMenuItem(menuName)
44
img.set_from_pixbuf(menuImage)
45
self.menuItem.set_image(img)
48
self.menuItem = gtk.ImageMenuItem(menuImage)
50
self.menuItem = gtk.ImageMenuItem(menuName)
52
img.set_from_stock(menuImage,gtk.ICON_SIZE_MENU)
53
self.menuItem.set_image(img)
55
self.menuItem = gtk.ImageMenuItem(menuName)
57
if actionFunction is not None :
58
self.menuItem.connect("activate", actionFunction)
60
self.append(self.menuItem)