tags:

views:

198

answers:

2

When my gtk application loads, the first item on the toolbar is automatically selected (it is highlighted, it is pressed when it hit enter). This is just a minor problem, but I would prefer for nothing to be selected by default.

Here is some basic sample code:

import gtk
import gtk.glade

window_tree = gtk.glade.XML('testtoolbar.glade')

gtk.main()

testtoolbar.glade

<?xml version="1.0"?>
<glade-interface>
  <!-- interface-requires gtk+ 2.16 -->
  <!-- interface-naming-policy project-wide -->
  <widget class="GtkWindow" id="window1">
    <property name="width_request">200</property>
    <property name="visible">True</property>
    <child>
      <widget class="GtkToolbar" id="toolbar1">
        <property name="visible">True</property>
        <child>
          <widget class="GtkToolButton" id="toolbutton1">
            <property name="visible">True</property>
            <property name="label" translatable="yes">toolbutton1</property>
            <property name="use_underline">True</property>
            <property name="stock_id">gtk-new</property>
          </widget>
          <packing>
            <property name="expand">False</property>
            <property name="homogeneous">True</property>
          </packing>
        </child>
        <child>
          <widget class="GtkToolButton" id="toolbutton2">
            <property name="visible">True</property>
            <property name="label" translatable="yes">toolbutton2</property>
            <property name="use_underline">True</property>
            <property name="stock_id">gtk-open</property>
          </widget>
          <packing>
            <property name="expand">False</property>
            <property name="homogeneous">True</property>
          </packing>
        </child>
      </widget>
    </child>
  </widget>
</glade-interface>
+2  A: 

This is probably just GTK+ handing the focus to some widget, it likes to have a widget focused if possible.

You can use grab_focus() to move the focus elsewhere, to get the desired behavior. If the toolbar is all the widgetry you have, it might be hard to find a suitable focus "target", though.

unwind
+1  A: 

You can always add a widget and make it invisible, and transfer focus to it. Though I don't really find this to be an issue or know of anyone else who did.

Vadi