[Glade-users] Hide on delete



Hello.

I'm not sure what is the problem here. Connecting delete-event to some
function that returns TRUE in order to keep window alive should really
not be too difficult.

My Python skills suck, but I did manage to create a working
application in couple of minutes. I attached it below, along with it's
glade file. Hopefully, this app will get you up and running properly.

--- CODE ---
delete-event.py:

#!/usr/bin/env python
# vim: set fileencoding=utf-8

import pygtk
pygtk.require( "2.0" )
import gtk

class SampleApp():
        def __init__( self ):
                builder = gtk.Builder()
                builder.add_from_file( "delete-event.glade" )
                builder.connect_signals( self )

                window = builder.get_object( "window1" )
                window.show()

        def gtk_widget_hide_on_delete( self, widget, event ):
                return widget.hide_on_delete()

        def gtk_main_quit( self, widget ):
                gtk.main_quit()

        def gtk_window_present( self, window ):
                window.present()

def main():
        SampleApp()
        gtk.main()

if __name__ == '__main__':
        main()

delete-event.glade:

<?xml version="1.0"?>
<interface>
  <requires lib="gtk+" version="2.14"/>
  <!-- interface-naming-policy project-wide -->
  <object class="GtkWindow" id="window1">
    <property name="default_width">300</property>
    <property name="default_height">300</property>
    <signal name="destroy" handler="gtk_main_quit"/>
    <child>
      <object class="GtkButton" id="button1">
        <property name="label" translatable="yes">Show popup</property>
        <property name="visible">True</property>
        <property name="can_focus">True</property>
        <property name="receives_default">True</property>
        <signal name="clicked" handler="gtk_window_present" object="window2"/>
      </object>
    </child>
  </object>
  <object class="GtkWindow" id="window2">
    <property name="modal">True</property>
    <property name="default_width">200</property>
    <property name="default_height">200</property>
    <property name="destroy_with_parent">True</property>
    <property name="transient_for">window1</property>
    <signal name="delete_event" handler="gtk_widget_hide_on_delete"/>
    <child>
      <object class="GtkLabel" id="label1">
        <property name="visible">True</property>
        <property name="label" translatable="yes">I'm popup.</property>
      </object>
    </child>
  </object>
</interface>
--- /CODE ---

Tadej

-- 
Tadej Borov?ak
tadeboro.blogspot.com
tadeboro at gmail.com
tadej.borovsak at gmail.com




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