#!/usr/bin/env python # -*- coding: UTF-8 -*- # GTKacl is a final grade calculator based on the rules most # professors at Universidade Federal Fluminense use. # It is based on the JCalculator program writen in Java by # Marcus José # Copyright (C) 2007 Flávio Amieiro # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; version 2 dated June, 1991. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Library General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, see . # # If you find any bugs or have any suggestions email: amieiro.flavio@gmail.com __author__ = "Flávio Amieiro" __version__ = "1.0" try: import pygtk pygtk.require("2.0") except: pass try: import gtk import gtk.glade except: sys.exit(1) class GTKalc: def __init__(self): self.gladefile = "gtkalc.glade" self.wTree = gtk.glade.XML(self.gladefile) dic = {"on_calcular_clicked":self.calcular, "on_limpar_clicked":self.limpar, "on_GTKalc_destroy":gtk.main_quit} self.wTree.signal_autoconnect(dic) self.enP1 = self.wTree.get_widget("enP1") self.enP2 = self.wTree.get_widget("enP2") self.enP3 = self.wTree.get_widget("enP3") self.enResultado = self.wTree.get_widget("enResultado") def calcular(self, widget): """calcula a média final""" self.p1 = self.enP1.get_text() self.p2 = self.enP2.get_text() self.p3 = self.enP3.get_text() res = (float(self.p1)*2 + float(self.p2)*2 + float(self.p3)*3) / 7 self.resultado = self.enResultado.set_text(str(res)[:4]) print res def limpar(self, widget): """limpa todos os campos""" self.enP1.set_text("") self.enP2.set_text("") self.enP3.set_text("") self.enResultado.set_text("") print "limpo!" if __name__ == "__main__": GTKalc = GTKalc() gtk.main()