~sporiff/soap-calculator

ref: fb6a387e0f27d73fb98dc12f91137b1612be7a90 soap-calculator/src/__main__.py -rw-r--r-- 1.4 KiB
fb6a387e — CiarĂ¡n Ainsworth Split calculation out of main function for neatness 5 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import gi
from calc import calculation

gi.require_version("Gtk", "3.0")
from gi.repository import Gtk

class Handler:

    # Allow the x button to destroy the window

    def onDestroy(self, *args):
        Gtk.main_quit()

    # If the "Use Reduction" tickbox is checked, activate the percentage input
    # field. If not, set this to zero and deactivate

    def useReduction(self, *args):
        use_reduction = builder.get_object("reduction").get_active()
        if use_reduction == 1:
            builder.get_object("reductionAmount").set_editable(1)
            builder.get_object("reductionAmount").set_range(0.00,10.00)
            builder.get_object("reductionAmount").set_increments(1,0.1)
        else:
            builder.get_object("reductionAmount").set_editable(0)
            builder.get_object("reductionAmount").set_value(0)

    def calculate(self, *args):
        calculation(builder)

if __name__ == "__main__":

    builder = Gtk.Builder()
    builder.add_from_file("soap-calculator.glade")
    builder.connect_signals(Handler())
    builder.get_object("oil1").set_increments(1,0.1)
    builder.get_object("oil2").set_increments(1,0.1)
    builder.get_object("oil1").set_range(0.00,1000000)
    builder.get_object("oil2").set_range(0.00,1000000)

    window = builder.get_object("window1")
    window.set_title ("Soap Calculator")
    window.show_all()

    Gtk.main()