Newbie: Gtk shell

Matej Cepl cepl at bigfoot.com
Sun May 27 05:22:49 CEST 2001


Hi,

I have created small BASH script doing all my Internet chores (connect, 
set up time according to ntp, send mail, synchronize news, get mail, 
disconnect) and then I wanted to make some small script gluining it 
into GNOME. Basically, I have a button on my taskbar which runs the 
script and then it says, that work is done:

#!/usr/bin/env python
# $Id: procppp-done.py,v 1.4 2001/05/22 21:47:57 matej Exp $
from gtk import *    # importing all the widgets from gtk
from os import system
from time import sleep

class Workhorse:                 # Problem domain
    def __init__(self):
        self.status = 0
        self.run_script()

    def run_script(self):
        self.status = system('pp')

    def print_report(self):
        if self.status == 0:
            print "OK"
        else:
            print "Failed"

class Application(GtkWindow): # User Interface
    def __init__(self):
        GtkWindow.__init__(self,WINDOW_TOPLEVEL)
        self.work = Workhorse()
        self.connect("destroy",self.destroy_cb)
        self.create_button()

    def create_button(self):
        button = GtkButton("The mail is being served.")
        button.connect("clicked",self.work_cb)
        self.add(button)

    def work_cb(self,*args):
        self.work.print_report()
        self.destroy_cb()

    def destroy_cb(self,*args):
        self.hide()
        mainquit()

if __name__=='__main__':
    app = Application()
    app.show_all()
    mainloop()

I would like to create new version of the script, which would have 
slightly different design:

                +--------------------------+
		| The mail is being served |   -- title of dialog
		+--------------------------+
		|  +----+     +----------+ |
		|  | OK |     | Run mutt | |   -- two buttons
		|  +----+     +----------+ |
		+--------------------------+

I think, that it is clear what I want. However, when I tried to change 
function Application.create_buttons() as follows:

    def create_buttons(self):
         Label = GtkLabel("The mail is being served.")
         self.add(Label)
         OKButton = GnomeStockButton("OK")
         OKButton.connect("clicked",self.work_cb)
         self.add(OKButton)
         MuttButton = GtkButton("Mutt")
         MuttButton.connect("clicked",self.work_mutt)
         self.add(MuttButton)

or (other desperat attempt):

    def create_buttons(self):
         table = GtkTable(2,2)
         self.add(table)
         Label = GtkLabel("The mail is being served.")
         table.attach(Label,0,1,0,1)
         OKButton = GnomeStockButton("OK")
         OKButton.connect("clicked",self.work_cb)
         table.attach(OKButton,0,1,1,1)
         MuttButton = GtkButton("Mutt")
         MuttButton.connect("clicked",self.work_mutt)
         table.attach(MuttButton,1,0,1,0)

(Of course, that new method Application.work_mutt was added which 
basically calls self.work.run_mutt() which does the work).

Neither of these versions work -- result is a label with the text (The 
mail is being served) which must be killed by other means, because 
there is no button present.

What I am doing wrong? (Please answer to the e-mail as I do not want to 
be only because of this silly thing subscribed to comp.lang.python).

		Thanks
		
			    Matej Cepl



More information about the Python-list mailing list