~sporiff/soap-calculator

ref: 97bfc58faa8813f679dc50d357f6eb35a48d3d32 soap-calculator/src/__main__.py -rw-r--r-- 1.8 KiB
97bfc58f — CiarĂ¡n Ainsworth Ingest dictionary at init 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
45
46
47
48
49
50
51
52
53
54
55
56
import gi
from calc import calculation
from dict import saponification_values

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

class Handler:

    def __init__(self):
        oil1Tree = builder.get_object("oil1Picker")
        oil2Tree = builder.get_object("oil2Picker")
        oil_store = Gtk.ListStore(str)
        for key in saponification_values:
            oil_store.append([key])
        oil1Tree.set_model(oil_store)
        oil1Tree.set_active(15)
        oil2Tree.set_model(oil_store)
        oil2Tree.set_active(43)

    # 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()