9.2. Arrows

The Arrow widget draws an arrowhead, facing in a number of possible directions and having a number of possible styles. It can be very useful when placed on a button in many applications. Like the Label widget, it emits no signals.

There are only two calls for manipulating an Arrow widget:
 
aroow = GtkArrow(arrow_type, shadow_type)

arrow.set(arrow_type, shadow_type)

The first creates a new arrow widget with the indicated type and appearance. The second allows these values to be altered retrospectively. The arrow_type argument may take one of the following values:
 
  ARROW_UP
  ARROW_DOWN
  ARROW_LEFT
  ARROW_RIGHT

These values obviously indicate the direction in which the arrow will point. The shadow_type argument may take one of these values:
 
  SHADOW_IN
  SHADOW_OUT   # the default
  SHADOW_ETCHED_IN
  SHADOW_ETCHED_OUT

The arrow.py example program briefly illustrates their use. Figure 9.2 illustrates the result of running the program:

Figure 9.2 Arrows Buttons Example

The source code for arrow.py is:
 
    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.GtkButton();
   11       arrow = gtk.GtkArrow(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.GtkWindow(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.GtkHBox(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.mainloop()
   54       return 0
   55   
   56   if __name__ == "__main__":
   57       Arrows()
   58       main()