Created
October 10, 2011 11:45
-
-
Save SpyDude/1275119 to your computer and use it in GitHub Desktop.
Calculations
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import gtk | |
import math | |
class Solver(object): | |
@staticmethod | |
def calc(c, m, lyamdach, b3, lyamdacb): | |
qu1 = (c / ( m / lyamdach + b3 / lyamdacb )) | |
if qu1 < 0: | |
return None | |
return (c / ( m / lyamdach + b3 / lyamdacb )) | |
@staticmethod | |
def calc2(c, s, m, lyamdau, b3, lyamdacb): | |
qu2 = ((c-s) / ( m / lyamdau + b3 / lyamdacb )) | |
if qu2 < 0: | |
return None | |
return ((c-s) / ( m / lyamdau + b3 / lyamdacb )) | |
class YuriCalculator(object): | |
def on_window_destroy(self, widget, data=None): | |
gtk.main_quit() | |
def on_calc_result_clicked(self, widget, data=None): | |
lyamdau = float(self.entry_lyamdau.get_text()) | |
m = float(self.entry_m.get_text()) | |
b3 = float(self.entry_b3.get_text()) | |
c = float(self.entry_c.get_text()) | |
lyamdacb = float(self.entry_lyamdacb.get_text()) | |
lyamdach = float(self.entry_lyamdach.get_text()) | |
q1 = Solver.calc(c, m, lyamdach, b3, lyamdacb) | |
if q1 is None: | |
text = "Нет решений" | |
elif isinstance(q1, tuple): | |
text = "{0:g}".format(*q1) | |
else: | |
text = "{0:g}".format(q1) | |
self.result_q1.set_markup(text) | |
q2 = Solver.calc2(c, s, m, lyamdau, b3, lyamdacb) | |
if q2 is None: | |
text = "Нет решений" | |
elif isinstance(q2, tuple): | |
text = "{0:g}".format(*q2) | |
else: | |
text = "{0:g}".format(q2) | |
self.result_q2.set_markup(text) | |
def __init__(self): | |
builder = gtk.Builder() | |
builder.add_from_file("diplom-first.glade") | |
self.window = builder.get_object("window") | |
self.calc_result = builder.get_object("calc_result") | |
self.entry_lyamdau = builder.get_object("entry_lyamdau") | |
self.entry_l = builder.get_object("entry_l") | |
self.entry_l1 = builder.get_object("entry_l1") | |
self.entry_m = builder.get_object("entry_m") | |
self.entry_b3 = builder.get_object("entry_b3") | |
self.entry_c = builder.get_object("entry_c") | |
self.entry_s = builder.get_object("entry_s") | |
self.entry_lyamdacb = builder.get_object("entry_lyamdacb") | |
self.entry_lyamdach = builder.get_object("entry_lyamdach") | |
self.result_q1 = builder.get_object("result_q1") | |
self.result_q2 = builder.get_object("result_q2") | |
builder.connect_signals(self) | |
if __name__ == "__main__": | |
calc = YuriCalculator() | |
calc.window.show() | |
gtk.main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment