9.2. Flechas

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 con el control Label (Etiqueta), no 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 flechacon el tipo y apariencia indicados. La segunda permite cambiar estos valores respectivamente. 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 shadow_type 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:

Figura 9.2. Ejemplos de Botones con Flechas

Ejemplos de Botones con Flechas

El código fuente del programa arrow.py es:

    1   #!/usr/bin/env python
    2   
    3   # example arrow.py
    4   
    5   import gtk
    6   
    7   # Create an Arrow widget with the specified parameters
    8   # and pack it into a button
    9   def create_arrow_button(arrow_type, shadow_type):
   10       button = gtk.Button();
   11       arrow = gtk.Arrow(arrow_type, shadow_type);
   12       button.add(arrow)
   13       button.show()
   14       arrow.show()
   15       return button
   16   
   17   class Arrows:
   18       def __init__(self):
   19           # Create a new window
   20           window = gtk.Window(gtk.WINDOW_TOPLEVEL)
   21   
   22           window.set_title("Arrow Buttons")
   23   
   24           # It's a good idea to do this for all windows.
   25           window.connect("destroy", gtk.mainquit)
   26   
   27           # Sets the border width of the window.
   28           window.set_border_width(10)
   29   
   30           # Create a box to hold the arrows/buttons
   31           box = gtk.HBox(gtk.FALSE, 0)
   32           box.set_border_width(2)
   33           window.add(box)
   34   
   35           # Pack and show all our widgets
   36           box.show()
   37   
   38           button = create_arrow_button(gtk.ARROW_UP, gtk.SHADOW_IN)
   39           box.pack_start(button, gtk.FALSE, gtk.FALSE, 3)
   40   
   41           button = create_arrow_button(gtk.ARROW_DOWN, gtk.SHADOW_OUT)
   42           box.pack_start(button, gtk.FALSE, gtk.FALSE, 3)
   43     
   44           button = create_arrow_button(gtk.ARROW_LEFT, gtk.SHADOW_ETCHED_IN)
   45           box.pack_start(button, gtk.FALSE, gtk.FALSE, 3)
   46     
   47           button = create_arrow_button(gtk.ARROW_RIGHT, gtk.SHADOW_ETCHED_OUT)
   48           box.pack_start(button, gtk.FALSE, gtk.FALSE, 3)
   49     
   50           window.show()
   51   
   52   def main():
   53       gtk.main()
   54       return 0
   55   
   56   if __name__ == "__main__":
   57       Arrows()
   58       main()