summaryrefslogtreecommitdiffstats
path: root/superkaramba/examples/popupMenu/popupMenu.py
blob: 39010f74d4d781483319c8ac2c6b3da5fd29ac80 (plain)
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
#this import statement allows access to the karamba functions
import karamba

menu1 = 0
menu2 = 0
id1 = 0
id2 = 0
id3 = 0
id4 = 0
id5 = 0

#this is called when you widget is initialized
def initWidget(widget):
	global menu1
	global menu2
	global id1
	global id2
	global id3
	global id4
	global id5

	menu1 = karamba.createMenu(widget)
	print("menu 1 created!")
	menu2 = karamba.createMenu(widget)
	print("menu 2 created!")

	id1 = karamba.addMenuItem(widget, menu1, "menu 1 first item", "kword")
	print("item 1 entered in menu 1")
	id2 = karamba.addMenuItem(widget, menu1, "menu 1 second item", "kate")
	print("item 2 entered in menu 1")

	id3 = karamba.addMenuItem(widget, menu2, "menu 2 first item", "kword")
	print("item 1 entered in menu 2")
	id4 = karamba.addMenuItem(widget, menu2, "menu 2 second item", "kate")
	print("item 2 entered in menu 2")
	id5 = karamba.addMenuItem(widget, menu2, "menu 2 third item", "/opt/kde/share/icons/kdeclassic/16x16/apps/kicker.png")
	print("item 3 entered in menu 2")



#this is called everytime your widget is updated
#the update inverval is specified in the .theme file
def widgetUpdated(widget):
    pass


#This gets called everytime our widget is clicked.
#Notes:
#  widget = reference to our widget
#  x = x position (relative to our widget)
#  y = y position (relative to our widget)
#  botton = button clicked:
#                    1 = Left Mouse Button
#                    2 = Middle Mouse Button
#                    3 = Right Mouse Button, but this will never happen
#                        because the right mouse button brings up the
#                        Karamba menu.
#                    4,5 = Scroll wheel up and down
def widgetClicked(widget, x, y, button):
	global menu1
	global menu2

	if(button == 1):
		karamba.popupMenu(widget, menu1, -100, -100)
	elif(button == 2):
		karamba.popupMenu(widget, menu2, 200, 200)


#This gets called everytime our widget is clicked.
#Notes
#  widget = reference to our widget
#  x = x position (relative to our widget)
#  y = y position (relative to our widget)
#  botton = button being held:
#                    0 = No Mouse Button
#                    1 = Left Mouse Button
#                    2 = Middle Mouse Button
#                    3 = Right Mouse Button, but this will never happen
#                        because the right mouse button brings up the
#                        Karamba menu.
def widgetMouseMoved(widget, x, y, button):
    #Warning:  Don't do anything too intensive here
    #You don't want to run some complex piece of code everytime the mouse moves
    pass


def menuItemClicked(widget, menu, id):
	global menu1
	global menu2
	global id1
	global id2
	global id3
	global id4
	global id5

	if (menu == menu1):
		if(id == id1):
			print("item 1 in menu 1 clicked.")
		elif(id == id2):
			print("item 2 in menu 1 clicked, removing item 2 in menu 2")
			karamba.removeMenuItem(widget, menu2, id4)
	elif (menu == menu2):
		if(id == id3):
			print("item 1 in menu 2 clicked.")
		elif(id == id4):
			print("item 2 in menu 2 clicked, deleting menu 1 (if menu1 still exists...)")
			karamba.deleteMenu(widget, menu1)
		elif(id == id5):
			print("item 3 in menu 2 clicked, removing item 2 in menu 1 (if menu1 still exists...)")
			karamba.removeMenuItem(widget, menu1, id2)



# This will be printed when the widget loads.
print("Loaded my python extension!")