Automated steam tables

Okay , the code that I wrote in the previous post , sucked and it sucked badly. There were many bugs while using it , i was iterating through lists multiple times , when I could have used a simple inbuilt python module. I have revised(rewritten) the code and can be found in this gist .

Now , I have just built a mini – gui for these tables . Its quite easy , and you could use the information to build your own useful GUI apps . I will be explaining each line of code , unlike other times where I usually paste the code 😀 .

First you need to call the main window.

self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
self.window.set_size_request(500 , 500)
self.window.set_title('Steam Solver')
self.window.connect('delete-event' ,  gtk.main_quit)

self.window.modify_bg(gtk.STATE_NORMAL , gtk.gdk.Color(red = 20000, blue = 20000 , green = 20000))

The first three lines are self explanatory , a window is created , the size of the window is set to 500 * 500 , and the window is named Steam Solver . The next line is you connect the event in a window to a function . Here it means that when the window is closed , the gtk loop also exits . Otherwise when you exit the window , the program would still hang .The reason on should use self is because the window or any other thing that you prepend with self can be accessed outside the function throughout the class. The last line is to call the TableCreator function , which is given below.

self.table = gtk.Table(500 ,500 , True)

self.label = gtk.Label('Choose any one')
self.table.attach(self.label , 25 , 225 , 25 , 60 ) = gtk.combo_box_new_text()'Pressure')'Temperature')'changed' , self.PresTemp)
self.table.attach( , 275 , 450 , 25 , 60)

You always need a container to hold your widgets. A container can be either a box or a table . I generally prefer tables as they are easier to understand. The table that Ive used is 500 pixels long and 500 pixels wide . True stands for it is homogenous meaning all the pixels are of the same size. gtk.Label creates a label , which is labelled as ‘Choose any one’  . It is then attached to the table . The four numbers that come after self.label are the four co-ordinates , (x1 , y1) , (x2 , y2) of where the label should be attached . gtk.combo_box_new_text creates a combo – box and , appends two strings to the combo box .(The combo box is one in which an user can choose items from a dropdown list) .  You then connect your box to another function , by using the ‘changed’ event . You then add your box to the table and the table to the window.

This is how your window should look.

The next is the PresTemp Function .

index = widget.get_active()
self.Entry1 = gtk.Entry()
self.table.attach(self.Entry1 , 275 , 450 , 25 , 60)
self.PresTempLab = gtk.Label()
self.PresTempEnt = gtk.Entry()
self.table.attach(self.PresTempLab , 25 , 225 , 120 , 155)
self.table.attach(self.PresTempEnt , 275 , 450 , 120 , 155)

self.button = gtk.Button('Process')
self.button.connect('clicked' , self.Process , index)
self.table.attach(self.button , 200 , 300 , 420 , 480)

Widget.get_active gives the index of the item selected in the combo – box. As soon as you call it , it is destroyed and is replaced by an entry widget. gtk.button creates a button named Process and on clicking it , it links to a function Process.The rest of the lines are self explanatory . Well after you change the combo – box the window looks like this.

Process Function:

UserEntry = self.PresTempEnt.get_text()
self.SecondStateLab = gtk.Label('Enter Second Property')
self.Combo = gtk.combo_box_new_text()
for Property in self.PropertyList:
self.Combo.connect('changed' , self.SecState)
self.table.attach(self.SecondStateLab , 25 , 225 , 215 , 250)
self.table.attach(self.Combo , 275 , 450 , 215 , 250)

As soon as the user clicks the process button , the text from the user is stored and non – editable , so that he cannot use it again . Nothing new other than the fact that another combo box has been added. Please notice the fact that the co-ordinates should be chosen so that the widgets dont co-incide . The combo – box has been linked to function which is called SecState which is similar to the PresTemp function , and Im sure you can write it yourself . This is how the window looks after both functions.

The button Process is then linked to the final function , which destroys all the existing tables and combo – boxes , and adds new labels and boxes with the answers.

This is part of the function , which gives only the temperature entry.


self.TemperatureEntry = gtk.Entry()
self.TemperatureLabel = gtk.Label('Temperature')

self.table.attach(self.TemperatureLabel, 25 , 225 , 25 , 55)
self.table.attach(self.TemperatureEntry , 275 , 450 , 25 , 55)

widget.connect('clicked' , self.destroy)

def destroy(self , widget):



Nothing much to explain ,  except that the destroy function destroys the table and brings you back to square one 😀

The entire code can be found here. .

P . S :  Sorry for the really long post . I think my post seems to be inspired by the IMDB top ten movies which go on and on and never seem to end . Anyway thanks for reading.



  1. nice work da!!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: