0

I am trying create alert dailog using glade,but its not working .am i doing anything wrong here.

test.glade :

    <?xml version="1.0"?>
<interface>
  <requires lib="gtk+" version="2.16"/>
  <!-- interface-naming-policy project-wide -->
  <object class="GtkWindow" id="window1">
    <child>
      <object class="GtkVBox" id="vbox1">
        <property name="visible">True</property>
        <child>
          <object class="GtkButton" id="hello">
            <property name="label" translatable="yes">hello</property>
            <property name="visible">True</property>
            <property name="can_focus">True</property>
            <property name="receives_default">True</property>
            <signal name="clicked" handler="on_hello_clicked"/>
          </object>
          <packing>
            <property name="position">0</property>
          </packing>
        </child>
      </object>
    </child>
  </object>
  <object class="GtkDialog" id="dialog1">
    <property name="border_width">5</property>
    <property name="type_hint">normal</property>
    <property name="has_separator">False</property>
    <child internal-child="vbox">
      <object class="GtkVBox" id="dialog-vbox1">
        <property name="visible">True</property>
        <property name="spacing">2</property>
        <child>
          <object class="GtkLayout" id="layout1">
            <property name="visible">True</property>
            <child>
              <object class="GtkLabel" id="click">
                <property name="width_request">100</property>
                <property name="height_request">80</property>
                <property name="visible">True</property>
                <property name="label" translatable="yes">process is not running</property>
              </object>
              <packing>
                <property name="x">99</property>
                <property name="y">58</property>
              </packing>
            </child>
          </object>
          <packing>
            <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="button1">
                <property name="label">gtk-yes</property>
                <property name="visible">True</property>
                <property name="can_focus">True</property>
                <property name="receives_default">True</property>
                <property name="use_stock">True</property>
                <signal name="clicked" handler="on_button1_clicked"/>
              </object>
              <packing>
                <property name="expand">False</property>
                <property name="fill">False</property>
                <property name="position">0</property>
              </packing>
            </child>
            <child>
              <object class="GtkButton" id="button2">
                <property name="label">gtk-no</property>
                <property name="visible">True</property>
                <property name="can_focus">True</property>
                <property name="receives_default">True</property>
                <property name="use_stock">True</property>
                <signal name="clicked" handler="on_button2_clicked"/>
              </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">button1</action-widget>
      <action-widget response="0">button2</action-widget>
    </action-widgets>
  </object>
</interface>

test.py

#!/usr/bin/python

import pygtk
import gtk
import gtk.glade
import os


class app:
    def __init__( self ):

            self.builder = gtk.Builder()
        self.builder.add_from_file("test.glade")

        self.window = self.builder.get_object('window1')
            self.alert = self.builder.get_object('dialog1')

            dic = { 
              "on_hello_clicked" : self.checkon,
            }

            self.builder.connect_signals( dic )
        self.window.show_all()

    def checkon(self, widget):
                check_process = os.popen('pgrep firefox').read()
                if check_process:
                    os.popen('pkill -9 firefox')
                else:
                    self.alert.show()


addgui = app()
gtk.main()

1 Answer 1

2

Two things off the top of my head (assuming your indentation is correct and not like it is above):

1.) You do not invoke the main loop like:

addgui = app()
gtk.main()

2.) You have a typo in

self.alert = self.builder.get_object('dailog1')  ## dialog is spelled wrong
Sign up to request clarification or add additional context in comments.

3 Comments

there is another typo in os.popen('pkill -9 fiefox')
yep i have misspelled ,good catch.can you please elaborate more on 1st point
@sush, the call to .main() starts the "main-loop" in pyGTK: en.wikipedia.org/wiki/Main_loop

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.