El control Arrow (Flecha) dibuja la cabeza de una flecha, apuntando a un número de direcciones posibles y con un número de estilos posibles. Puede ser muy útil en un botón en muchas aplicaciones. Al igual que el control Label (Etiqueta), tampoco emite ninguna señal.
Sólo hay dos llamadas para manipular un control Arrow :
arrow = gtk.Arrow(arrow_type, shadow_type) arrow.set(arrow_type, shadow_type) |
La primera crea un control flecha con el tipo y apariencia indicados. La segunda permite cambiar cualquiera de estos valores. El argumento arrow_type puede tomar uno de lo siguientes valores:
ARROW_UP #(Arriba) ARROW_DOWN #(Abajo) ARROW_LEFT #(Izquierda) ARROW_RIGHT #(Derecha) |
Estos valores obviamente indican la dirección hacia la que apunta la flecha. El argumento <keyword>shadow_type</keyword> puede tomar uno de los siguientes valores:
SHADOW_IN SHADOW_OUT # valor predeterminado SHADOW_ETCHED_IN SHADOW_ETCHED_OUT |
El programa de ejemplo arrow.py ilustra brevemente su uso. La figura Figura 9.2, “Ejemplos de Botones con Flechas” muestra el resultado de ejecutar el programa:
El código fuente del programa arrow.py es:
1 #!/usr/bin/env python
2
3 # example arrow.py
4
5 import pygtk
6 pygtk.require('2.0')
7 import gtk
8
9 # Crea un control de Flecha con los parámetros especificados
10 # y lo empaqueta en un botón
11 def create_arrow_button(arrow_type, shadow_type):
12 button = gtk.Button();
13 arrow = gtk.Arrow(arrow_type, shadow_type);
14 button.add(arrow)
15 button.show()
16 arrow.show()
17 return button
18
19 class Arrows:
20 def __init__(self):
21 # Creamos una ventana nueva
22 window = gtk.Window(gtk.WINDOW_TOPLEVEL)
23
24 window.set_title("Arrow Buttons")
25
26 # Es buena idea hacer esto con todas las ventanas
27 window.connect("destroy", lambda x: gtk.main_quit())
28
29 # Establecer el ancho del borde de ventana
30 window.set_border_width(10)
31
32 # Creamos una caja para poner las flechas/botones
33 box = gtk.HBox(gtk.FALSE, 0)
34 box.set_border_width(2)
35 window.add(box)
36
37 # Empaquetar y mostrar todos los controles
38 box.show()
39
40 button = create_arrow_button(gtk.ARROW_UP, gtk.SHADOW_IN)
41 box.pack_start(button, gtk.FALSE, gtk.FALSE, 3)
42
43 button = create_arrow_button(gtk.ARROW_DOWN, gtk.SHADOW_OUT)
44 box.pack_start(button, gtk.FALSE, gtk.FALSE, 3)
45
46 button = create_arrow_button(gtk.ARROW_LEFT, gtk.SHADOW_ETCHED_IN)
47 box.pack_start(button, gtk.FALSE, gtk.FALSE, 3)
48
49 button = create_arrow_button(gtk.ARROW_RIGHT, gtk.SHADOW_ETCHED_OUT)
50 box.pack_start(button, gtk.FALSE, gtk.FALSE, 3)
51
52 window.show()
53
54 def main():
55 gtk.main()
56 return 0
57
58 if __name__ == "__main__":
59 Arrows()
60 main()
|