Blame platform-demos/C/menubutton.py.page

Packit 1470ea
Packit 1470ea
Packit 1470ea
      xmlns:its="http://www.w3.org/2005/11/its"
Packit 1470ea
      xmlns:xi="http://www.w3.org/2001/XInclude"
Packit 1470ea
      type="guide" style="task"
Packit 1470ea
      id="menubutton.py">
Packit 1470ea
  <info>
Packit 1470ea
  <title type="text">MenuButton</title>
Packit 1470ea
    <link type="guide" xref="beginner.py#buttons"/>
Packit 1470ea
    <link type="next" xref="toolbar.py"/>
Packit 1470ea
    <revision version="0.1" date="2012-08-19" status="draft"/>
Packit 1470ea
Packit 1470ea
    <credit type="author copyright">
Packit 1470ea
      <name>Tiffany Antopolski</name>
Packit 1470ea
      <email its:translate="no">tiffany.antopolski@gmail.com</email>
Packit 1470ea
      <years>2012</years>
Packit 1470ea
    </credit>
Packit 1470ea
Packit 1470ea
    <credit type="author copyright">
Packit 1470ea
      <name>Marta Maria Casetti</name>
Packit 1470ea
      <email its:translate="no">mmcasetti@gmail.com</email>
Packit 1470ea
      <years>2012</years>
Packit 1470ea
    </credit>
Packit 1470ea
Packit 1470ea
    <desc>A widget that shows a menu when clicked on</desc>
Packit 1470ea
  </info>
Packit 1470ea
Packit 1470ea
  <title>MenuButton</title>
Packit 1470ea
  <media type="image" mime="image/png" src="media/menubutton.png"/>
Packit 1470ea
  

The GtkMenuButton widget is used to display a menu when clicked on. This menu can be provided either as a GtkMenu, or an abstract GMenuModel. The GtkMenuButton widget can hold any valid child widget. That is, it can hold almost any other standard GtkWidget. The most commonly used child is the provided GtkArrow.

Packit 1470ea
Packit 1470ea
  <note>

You need to be running GNOME 3.6 for the MenuButton to work.

</note>
Packit 1470ea
Packit 1470ea
  <links type="section" />
Packit 1470ea
    
Packit 1470ea
  <section id="code">
Packit 1470ea
  <title>Code used to generate this example</title>
Packit 1470ea
    <xi:include href="samples/menubutton.py" parse="text"><xi:fallback/></xi:include>
Packit 1470ea
  </section>
Packit 1470ea
Packit 1470ea
  <section id="methods">
Packit 1470ea
  <title>Useful methods for a MenuButton widget</title>
Packit 1470ea
      

In line 33 the signal "activate" from the action about_action is connected to the callback function about_callback() using action.connect(signal, callback function). See <link xref="signals-callbacks.py"/> for a more detailed explanation.

Packit 1470ea
Packit 1470ea
    

The positioning of the menu is determined by the "direction" property of the menu button and the "halign" or "valign" properties of the menu. For example, when the direction is Gtk.ArrowType.DOWN (other option: UP) and the horizontal alignment is Gtk.Align.START (other options: CENTER and END), the menu will be positioned below the button, with the starting edge (depending on the text direction) of the menu aligned with the starting edge of the button. If there is not enough space below the button, the menu is popped up above the button instead. If the alignment would move part of the menu offscreen, it is 'pushed in'.

Packit 1470ea
    
Packit 1470ea
    

In the case of vertical alignment, the possible ArrowType directions are LEFT and RIGHT and the vertical alignment is again START, CENTER or END.

Packit 1470ea
    
Packit 1470ea
    

set_align_widget(alignment) and set_direction(direction) can be used to set these properties.

Packit 1470ea
  </section>
Packit 1470ea
  
Packit 1470ea
  <section id="references">
Packit 1470ea
  <title>API References</title>
Packit 1470ea
    

In this sample we used the following:

Packit 1470ea
    <list>
Packit 1470ea
      <item>

<link href="http://developer.gnome.org/gtk3/unstable/GtkMenuButton.html">MenuButton</link>

</item>
Packit 1470ea
    </list>
Packit 1470ea
  </section>
Packit 1470ea
</page>