[Glade-users] Possible bug with File-chooser dialog?



I am just new to glade so not sure if this is a bug or a
misunderstanding on my part as I have an alternative way of doing what I
want working.

To give a bit of a background, I am converting GTK hardcoded code in my
python program to glade files. One part of the GTK code in my program is
a dialog which has a text entry and a button beside it when clicked
opens a filechooser dialog which populates the text entry with selected
folder. The glade file is as follows:

File: options.glade
******************************************************
<?xml version="1.0"?>
<interface>
  <requires lib="gtk+" version="2.16"/>
  <!-- interface-naming-policy project-wide -->
  <object class="GtkDialog" id="dialog">
    <property name="border_width">5</property>
    <property name="title" translatable="yes">Options</property>
    <property name="modal">True</property>
    <property name="window_position">center</property>
    <property name="destroy_with_parent">True</property>
    <property name="type_hint">normal</property>
    <property name="has_separator">False</property>
    <signal name="response" handler="response_cb"/>
    <child internal-child="vbox">
      <object class="GtkVBox" id="dialog-vbox1">
        <property name="visible">True</property>
        <property name="orientation">vertical</property>
        <property name="spacing">2</property>
        <child>
          <object class="GtkHBox" id="hbox1">
            <property name="visible">True</property>
            <child>
              <object class="GtkLabel" id="label">
                <property name="visible">True</property>
                <property name="label" translatable="yes">MP3 Player
Folder</property>
              </object>
              <packing>
                <property name="position">0</property>
              </packing>
            </child>
            <child>
              <object class="GtkEntry" id="mp3_entry">
                <property name="visible">True</property>
                <property name="can_focus">True</property>
                <property name="invisible_char">&#x25CF;</property>
              </object>
              <packing>
                <property name="position">1</property>
              </packing>
            </child>
            <child>
              <object class="GtkButton" id="mp3_button">
                <property name="label"
translatable="yes">Browse...</property>
                <property name="visible">True</property>
                <property name="can_focus">True</property>
                <property name="receives_default">True</property>
                <signal name="clicked" handler="mp3_button_cp"/>
              </object>
              <packing>
                <property name="position">2</property>
              </packing>
            </child>
          </object>
          <packing>
            <property name="expand">False</property>
            <property name="fill">False</property>
            <property name="position">1</property>
          </packing>
        </child>
        <child internal-child="action_area">
          <object class="GtkHButtonBox" id="dialog-action_area1">
            <property name="visible">True</property>
            <property name="layout_style">end</property>
            <child>
              <object class="GtkButton" id="dialog_cancel">
                <property name="label"
translatable="yes">Cancel</property>
                <property name="visible">True</property>
                <property name="can_focus">True</property>
                <property name="receives_default">True</property>
              </object>
              <packing>
                <property name="expand">False</property>
                <property name="fill">False</property>
                <property name="position">0</property>
              </packing>
            </child>
            <child>
              <object class="GtkButton" id="dialog_ok">
                <property name="label" translatable="yes">OK</property>
                <property name="visible">True</property>
                <property name="can_focus">True</property>
                <property name="receives_default">True</property>
              </object>
              <packing>
                <property name="expand">False</property>
                <property name="fill">False</property>
                <property name="position">1</property>
              </packing>
            </child>
          </object>
          <packing>
            <property name="expand">False</property>
            <property name="pack_type">end</property>
            <property name="position">0</property>
          </packing>
        </child>
      </object>
    </child>
    <action-widgets>
      <action-widget response="1">dialog_cancel</action-widget>
      <action-widget response="2">dialog_ok</action-widget>
    </action-widgets>
  </object>
  <object class="GtkFileChooserDialog" id="mp3_fcd">
    <property name="border_width">5</property>
    <property name="title" translatable="yes">Select MP3 Player Mount
Folder..</property>
    <property name="modal">True</property>
    <property name="window_position">center</property>
    <property name="destroy_with_parent">True</property>
    <property name="type_hint">normal</property>
    <property name="has_separator">False</property>
    <property name="action">select-folder</property>
    <property name="create_folders">False</property>
    <child internal-child="vbox">
      <object class="GtkVBox" id="dialog-vbox2">
        <property name="visible">True</property>
        <property name="orientation">vertical</property>
        <property name="spacing">2</property>
        <child>
          <placeholder/>
        </child>
        <child internal-child="action_area">
          <object class="GtkHButtonBox" id="dialog-action_area2">
            <property name="visible">True</property>
            <property name="layout_style">end</property>
            <child>
              <object class="GtkButton" id="fc_cancel">
                <property name="label">gtk-cancel</property>
                <property name="visible">True</property>
                <property name="can_focus">True</property>
                <property name="receives_default">True</property>
                <property name="use_stock">True</property>
              </object>
              <packing>
                <property name="expand">False</property>
                <property name="fill">False</property>
                <property name="position">0</property>
              </packing>
            </child>
            <child>
              <object class="GtkButton" id="fc_select">
                <property name="label">gtk-ok</property>
                <property name="visible">True</property>
                <property name="can_focus">True</property>
                <property name="receives_default">True</property>
                <property name="use_stock">True</property>
              </object>
              <packing>
                <property name="expand">False</property>
                <property name="fill">False</property>
                <property name="position">1</property>
              </packing>
            </child>
          </object>
          <packing>
            <property name="expand">False</property>
            <property name="pack_type">end</property>
            <property name="position">0</property>
          </packing>
        </child>
      </object>
    </child>
    <action-widgets>
      <action-widget response="0">fc_cancel</action-widget>
      <action-widget response="1">fc_select</action-widget>
    </action-widgets>
  </object>
  <object class="GtkAction" id="action1"/>
</interface>
************************************************************

The test file written in python is as follows:

options.py
************************************************************
import sys
import gtk
  
class template:
        def mp3_button_cp(self, widget, data=None):
                self.mp3_fcd.set_current_folder("/")
                response = self.mp3_fcd.run()
                print "this is response " + str (response)
                if response == 1:
                        self.mp3_entry.set_text(self.mp3_fcd.get_filename())
                self.mp3_fcd.destroy()  
        
        def response_cb(self, widget, response_id):
                print "This is response_id" + str(response_id)
                self.dialog.destroy()

        def __init__(self):
                builder = gtk.Builder()
                builder.add_from_file("options.glade") 
                self.dialog = builder.get_object("dialog")
                self.mp3_fcd = builder.get_object("mp3_fcd")    
                self.mp3_entry = builder.get_object("mp3_entry")
                builder.connect_signals(self)
                self.dialog.show()

if __name__ == "__main__":
        editor = template()
        gtk.main()
**************************************************************

The program works properly until you click on Browse... button again
where a blank filechooser dialog button appears and the following error
messages appear in console:


*****************************************************
options.py:6: GtkWarning: gtk_file_chooser_set_current_folder_file:
assertion `GTK_IS_FILE_CHOOSER (chooser)' failed
  self.mp3_fcd.set_current_folder("/")
options.py:7: GtkWarning: gtk_container_foreach: assertion
`GTK_IS_CONTAINER (container)' failed
  response = self.mp3_fcd.run()
options.py:7: GtkWarning: gtk_widget_map: assertion `GTK_IS_WIDGET
(widget)' failed
  response = self.mp3_fcd.run()
options.py:7: GtkWarning: _gtk_file_chooser_embed_initial_focus:
assertion `GTK_IS_FILE_CHOOSER_EMBED (chooser_embed)' failed
  response = self.mp3_fcd.run()
this is response -1
options.py:11: GtkWarning: gtk_widget_unmap: assertion `GTK_IS_WIDGET
(widget)' failed
  self.mp3_fcd.destroy()
*****************************************************

I have amended the code for the following and the behaviour still
occurs:

* create a new gtk.builder (calling it builder2) object solely for
mp3_fcd glade object
* moved mp3cp_fcd creation in mp3_button_cp callback function
* create a gtk.builder variable and mp3cp_fcd in mp3_button_cp function

I then proceeded to create a new glade file with just the fildechooser
dialog in it and obviously amending the code to create a new gtk.builder
object for it. I then ran the program and it worked properly with no
errors.

Is this a bug or has certain dialog got to be in separate files?





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]