~sporiff/soap-calculator

764a231c47528c7aeb2e1c66b188c2712b9af4e4 — Ciarán Ainsworth 4 months ago 041cd1d
Changed all numeric inputs to spin
3 files changed, 43 insertions(+), 57 deletions(-)

M screenshot.png
M src/__main__.py
M src/soap-calculator.glade
M screenshot.png => screenshot.png +0 -0

M src/__main__.py => src/__main__.py +6 -22
@@ 30,16 30,6 @@ class Handler:
            builder.get_object("reductionAmount").set_editable(0)
            builder.get_object("reductionAmount").set_value(0)

    def updateOil1(self, *args):
        text = builder.get_object("oil1").get_text()
        builder.get_object("oil1").set_text(''.join([i for i in text if i in '0123456789.']))
        calculation()

    def updateOil2(self, *args):
        text = builder.get_object("oil2").get_text()
        builder.get_object("oil2").set_text(''.join([i for i in text if i in '0123456789.']))
        calculation()

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



@@ 51,18 41,8 @@ def calculation():
    oil1Lye = get_saponification(builder.get_object("oil1Picker").get_active_text())
    oil2Lye = get_saponification(builder.get_object("oil2Picker").get_active_text())

    oil1Text = builder.get_object("oil1").get_text()
    if oil1Text == '' or oil1Text == None:
        oil1Amount = 0
    else:
        oil1Amount = float(builder.get_object("oil1").get_text())

    oil2Text = builder.get_object("oil2").get_text()
    if oil2Text == '' or oil2Text == None:
        oil2Amount = 0
    else:
        oil2Amount = float(builder.get_object("oil2").get_text())

    oil1Amount = float(builder.get_object("oil1").get_value())
    oil2Amount = float(builder.get_object("oil2").get_value())
    reductionAmount = float(builder.get_object("reductionAmount").get_value())

    use_reduction = builder.get_object("reduction").get_active()


@@ 82,6 62,10 @@ 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")

M src/soap-calculator.glade => src/soap-calculator.glade +37 -35
@@ 31,7 31,7 @@ Author: Ciarán Ainsworth
  <object class="GtkWindow" id="window1">
    <property name="name">Soap Calculator</property>
    <property name="can_focus">False</property>
    <property name="default_width">700</property>
    <property name="default_width">500</property>
    <property name="default_height">300</property>
    <signal name="destroy" handler="onDestroy" swapped="no"/>
    <child>


@@ 65,40 65,6 @@ Author: Ciarán Ainsworth
            <property name="row_homogeneous">True</property>
            <property name="column_homogeneous">True</property>
            <child>
              <object class="GtkEntry" id="oil1">
                <property name="visible">True</property>
                <property name="can_focus">True</property>
                <property name="tooltip_text" translatable="yes">Results will be rounded to 3 decimal places</property>
                <property name="halign">center</property>
                <property name="margin_bottom">10</property>
                <property name="hexpand">True</property>
                <property name="placeholder_text" translatable="yes">e.g. 100</property>
                <property name="input_purpose">number</property>
                <signal name="changed" handler="updateOil1" swapped="no"/>
              </object>
              <packing>
                <property name="left_attach">0</property>
                <property name="top_attach">0</property>
              </packing>
            </child>
            <child>
              <object class="GtkEntry" id="oil2">
                <property name="visible">True</property>
                <property name="can_focus">True</property>
                <property name="tooltip_text" translatable="yes">Results will be rounded to 3 decimal places</property>
                <property name="halign">center</property>
                <property name="margin_top">10</property>
                <property name="hexpand">True</property>
                <property name="placeholder_text" translatable="yes">e.g. 199</property>
                <property name="input_purpose">number</property>
                <signal name="changed" handler="updateOil2" swapped="no"/>
              </object>
              <packing>
                <property name="left_attach">0</property>
                <property name="top_attach">1</property>
              </packing>
            </child>
            <child>
              <object class="GtkComboBoxText" id="oil1Picker">
                <property name="visible">True</property>
                <property name="can_focus">False</property>


@@ 289,6 255,42 @@ Author: Ciarán Ainsworth
                <property name="top_attach">1</property>
              </packing>
            </child>
            <child>
              <object class="GtkSpinButton" id="oil1">
                <property name="visible">True</property>
                <property name="can_focus">True</property>
                <property name="halign">center</property>
                <property name="hexpand">True</property>
                <property name="text" translatable="yes">0.000</property>
                <property name="input_purpose">number</property>
                <property name="digits">3</property>
                <property name="numeric">True</property>
                <signal name="change-value" handler="calculate" swapped="no"/>
                <signal name="value-changed" handler="calculate" swapped="no"/>
              </object>
              <packing>
                <property name="left_attach">0</property>
                <property name="top_attach">0</property>
              </packing>
            </child>
            <child>
              <object class="GtkSpinButton" id="oil2">
                <property name="visible">True</property>
                <property name="can_focus">True</property>
                <property name="halign">center</property>
                <property name="hexpand">True</property>
                <property name="text" translatable="yes">0.000</property>
                <property name="input_purpose">number</property>
                <property name="digits">3</property>
                <property name="numeric">True</property>
                <signal name="change-value" handler="calculate" swapped="no"/>
                <signal name="value-changed" handler="calculate" swapped="no"/>
              </object>
              <packing>
                <property name="left_attach">0</property>
                <property name="top_attach">1</property>
              </packing>
            </child>
          </object>
          <packing>
            <property name="expand">False</property>