Exemplo n.º 1
0
 def grain_table_update(self):
     """ Fill cells in the grain stock table with instances
     from grain_list. If grain not in stock the text is greyed.
     """
     self.ui.grain_stock.clearContents()
     row_count = len(self.grain_list)  # Ensure extra rows available
     if row_count > 6:
         self.ui.grain_stock.setRowCount(row_count + 1)
     for item in self.grain_list:
         pos = self.grain_list.index(item)
         name = Grain.get_name(item)
         ebc = Grain.get_ebc(item)
         extr = Grain.get_extr(item)
         wgt = Grain.get_wgt(item)
         name = QtWidgets.QTableWidgetItem(name)
         if float(wgt) <= 0:
             in_stock = False
         else:
             in_stock = True
         self.ui.grain_stock.setItem(pos, 0, name)
         col = QtWidgets.QTableWidgetItem(ebc)
         self.ui.grain_stock.setItem(pos, 1, col)
         extr = QtWidgets.QTableWidgetItem(extr)
         self.ui.grain_stock.setItem(pos, 2, extr)
         qty = QtWidgets.QTableWidgetItem(wgt)
         self.ui.grain_stock.setItem(pos, 3, qty)
         if not in_stock:
             for col in range(4):
                 self.ui.grain_stock.item(pos, col).setForeground\
                     (QtGui.QColor('#697076'))
Exemplo n.º 2
0
 def used_grain_update(self):
     """ Re-populate used grain table."""
     self.ui.rcg.grain_use.clearContents()
     for item in self.used_grain_list:
         pos = self.used_grain_list.index(item)
         name = Grain.get_name(item)
         wgt = str(Grain.get_wgt(item))
         name = QtWidgets.QTableWidgetItem(name)
         #name.setFlags(name.flags() & ~QtCore.Qt.ItemIsEditable)
         #name.setFlags(name.flags() & ~QtCore.Qt.ItemIsDropEnabled)
         self.ui.rcg.grain_use.setItem(pos, 0, name)
         wgt = QtWidgets.QTableWidgetItem(wgt)
         self.ui.rcg.grain_use.setItem(pos, 1, wgt)
     self.use_grain()
Exemplo n.º 3
0
 def commit(self):
     """ Subtract used grain and hops from stock and command data
     save.
     """
     reply = QtWidgets.QMessageBox.question(
         self, "Commit Changes", "Commit changes to Database?",
         QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No
         | QtWidgets.QMessageBox.Cancel)
     if reply == QtWidgets.QMessageBox.Cancel:
         return False
     elif reply == QtWidgets.QMessageBox.No:
         return True
     elif reply == QtWidgets.QMessageBox.Yes:
         for used_grain in self.used_grain_list:
             used_name = Grain.get_name(used_grain)
             used_wgt = float(Grain.get_wgt(used_grain))
             for grain in self.grain_list:
                 grain_name = Grain.get_name(grain)
                 if grain_name == used_name:
                     grain.wgt = float(grain.wgt)
                     grain.wgt -= used_wgt
                     grain.wgt = Decimal(grain.wgt)
                     grain.wgt = round(grain.wgt, 2)
                     if grain.wgt < 0:
                         grain.wgt = 0
                     grain.wgt = str(grain.wgt)
                     self.grain_table_update()
         for used_hop in self.used_hop_list:
             used_name = Hop.get_name(used_hop)
             used_wgt = float(Hop.get_wgt(used_hop))
             for hop in self.hop_list:
                 hop_name = Hop.get_name(hop)
                 if hop_name == used_name:
                     hop.wgt = float(hop.wgt)
                     hop.wgt -= used_wgt
                     hop.wgt = Decimal(hop.wgt)
                     hop.wgt = round(hop.wgt, 1)
                     if hop.wgt < 0:
                         hop.wgt = 0
                         hop.wgt = str(hop.wgt)
                     self.hop_table_update()
         self.ui.rcg.button_commit.setEnabled(False)
         self.save_data()
         self.stock_dirty = False
         return True
Exemplo n.º 4
0
 def grain_info_calc(self):
     """ Calculate wort OG and EBC."""
     if len(self.used_grain_list) > 0:
         mash_deg = 0
         total_col = 0
         mash_eff = int(self.ui.rcg.mash_eff_disp.text())
         vol = float(self.ui.rcg.vol_disp.text())
         for item in self.used_grain_list:
             wgt = float(Grain.get_wgt(item))
             extr = float(Grain.get_extr(item))
             col = int(Grain.get_ebc(item))
             deg = (extr * wgt * (float(mash_eff) / 100)) / vol
             mash_deg += deg
             col *= wgt
             total_col += col
         OG = int(mash_deg)
         OG = str(OG)
         total_col = int(total_col * 10 * (float(mash_eff) / 100)) / vol
         colour = int(total_col)
         self.ui.rcg.ebc_disp.setText(str(colour))
         self.ui.rcg.og_disp.setText(OG)
Exemplo n.º 5
0
    def use_grain(self):
        """ Populate used_grain_list and calculate percentage use."""
        total = 0
        self.used_grain_list = []
        stock_list = []
        for row in range(self.ui.rcg.grain_use.rowCount()):
            if self.ui.rcg.grain_use.item(row, 0) is not None:
                if self.ui.rcg.grain_use.item(row, 1) is None:
                    wgt = QtWidgets.QTableWidgetItem()
                    self.ui.rcg.grain_use.setItem(row, 1, wgt)
                    wgt.setText(str(0))

                name = self.ui.rcg.grain_use.item(row, 0).text()
                wgt = float(self.ui.rcg.grain_use.item(row, 1).text())
                for item in self.grain_list:
                    if name == item.get_name():
                        stock_name = item.get_name()
                        stock_list.append(stock_name)
                        extr = item.get_extr()
                        ebc = item.get_ebc()
                if name not in stock_list:
                    self.error_message("Warning: " + name + " not in stock")
                    self.ui.rcg.grain_use.removeRow(row)
                else:
                    total += wgt
                    a_used_grain = Grain(name, ebc, extr, wgt)
                    self.used_grain_list.append(a_used_grain)
        if total > 0:  # Calculate percentages in table
            for item in self.used_grain_list:
                pos = self.used_grain_list.index(item)
                wgt = float(Grain.get_wgt(item))
                perCent = int((wgt / total) * 100)
                perCent = str(perCent)
                perCent = QtWidgets.QTableWidgetItem(perCent)
                self.ui.rcg.grain_use.setItem(pos, 2, perCent)
        row_count = len(self.used_grain_list)  # Ensure extra rows available
        if row_count > 5:
            self.ui.rcg.grain_use.setRowCount(row_count + 1)
        self.ui.rcg.grain_use.clearSelection()
        self.grain_info_calc()
Exemplo n.º 6
0
 def grain_recipe_update(self):
     """ Re-populate used grain table and adjusts row count to allow
     new entries."""
     self.ui.hcg.grain_use.clearContents()
     total = 0
     for item in self.grainRecipe_list:
         pos = self.grainRecipe_list.index(item)
         name = Grain.get_name(item)
         wgt = str(Grain.get_wgt(item))
         calc_wgt = float(Grain.get_wgt(item))
         total += calc_wgt
         percent = int((calc_wgt / total) * 100)
         percent = str(percent)
         name = QtWidgets.QTableWidgetItem(name)
         self.ui.hcg.grain_use.setItem(pos, 0, name)
         wgt = QtWidgets.QTableWidgetItem(wgt)
         self.ui.hcg.grain_use.setItem(pos, 1, wgt)
         percent = QtWidgets.QTableWidgetItem(percent)
         self.ui.hcg.grain_use.setItem(pos, 2, percent)
     row_count = len(self.grainRecipe_list)  # Ensure extra rows available
     if len(self.grainRecipe_list) > 4:
         self.ui.hcg.grain_use.setRowCount(row_count + 1)
Exemplo n.º 7
0
 def use_recipe(self):
     """ Load recipe from history panel into recipe panel."""
     if self.grain_list == []:
         msg = "Error: no stock data"
         self.errorMessage(msg)
     elif self.hop_list == []:
         msg = "Error: no stock data"
         self.errorMessage(msg)
     else:
         self.ui.rcg.grain_use.clearContents()
         self.ui.rcg.hop_use.clearContents()
         for item in self.grainRecipe_list:
             pos = self.grainRecipe_list.index(item)
             name = Grain.get_name(item)
             wgt = str(Grain.get_wgt(item))
             name = QtWidgets.QTableWidgetItem(name)
             self.ui.rcg.grain_use.setItem(pos, 0, name)
             wgt = QtWidgets.QTableWidgetItem(wgt)
             self.ui.rcg.grain_use.setItem(pos, 1, wgt)
         self.use_grain()
         for item in self.hopRecipe_list:
             pos = self.hopRecipe_list.index(item)
             name = Hop.get_name(item)
             wgt = str(Hop.get_wgt(item))
             time = str(Hop.get_time(item))
             name = QtWidgets.QTableWidgetItem(name)
             self.ui.rcg.hop_use.setItem(pos, 0, name)
             wgt = QtWidgets.QTableWidgetItem(wgt)
             self.ui.rcg.hop_use.setItem(pos, 1, wgt)
             time = QtWidgets.QTableWidgetItem(time)
             self.ui.rcg.hop_use.setItem(pos, 2, time)
         self.use_hop()
         temp = self.ui.hcg.mash_temp_disp.text()
         self.ui.rcg.mash_temp_disp.setText(temp)
         self.ui.recipe_box.setTitle("Unsaved Brew")
         self.ui.tabbed_area.setCurrentIndex(0)
Exemplo n.º 8
0
 def grain_grp_update(self):
     """ Add an instance of class Grain to grain_list list of
     instances, sorts the list by EBC value and calls grain_table_update.
     """
     self.grain_list = []
     for row in range(self.ui.grain_stock.rowCount()):
         if self.ui.grain_stock.item(row, 0) is not None:
             if self.ui.grain_stock.item(row, 0).text() != "":
                 name = self.ui.grain_stock.item(row, 0).text()
                 ebc = self.ui.grain_stock.item(row, 1).text()
                 extr = self.ui.grain_stock.item(row, 2).text()
                 wgt = self.ui.grain_stock.item(row, 3).text()
                 a_grain = Grain(name, ebc, extr, wgt)
                 if name != "":
                     self.grain_list.append(a_grain)
     num = -1 + len(self.grain_list)
     if len(self.grain_list) > 5:
         self.ui.grain_stock.setRowCount(num + 1)
     # sort using int or 3, 10, 1 sorts to 1, 10, 3
     self.grain_list.sort(key=lambda Grain: int(Grain.ebc))
     self.grain_table_update()