예제 #1
0
 def __init__(self, ingredient, parent=None):
     QtGui.QWidget.__init__(self, parent)
     
     self.ingredient = ingredient
     
     layout = QVBoxLayout()
     self.setLayout(layout)
     
     formlayout = QtGui.QFormLayout()
     layout.addLayout(formlayout)
     
     layout.addWidget(QLabel("Changes to Current Amount \nwill not be reflected in graphs."))
     
     self.inputs = {}
     
     self.fields = ('name', 'barcode', 'size', 'current_amount', 'threshold', 'potency', 'note', 'hidden')
     
     for a in self.fields:
         value = getattr(ingredient, a)
         vt = type(value)
         if vt in (str, unicode):
             i = QLineEdit(text=value)
         elif vt in (int, float, long):
             i = QDoubleSpinBox()
             i.setDecimals(0)
             i.setRange(0, 10000)
             i.setSuffix(" mL")
             i.setValue(value)
             
         if a == "potency":
             i.setDecimals(2)
             i.setSuffix("%")
             
         if a == "hidden":
             i = QtGui.QCheckBox("Hidden from shopping list")
             i.setChecked(value)
         
         label = a.replace("_", " ").title()+":"
         formlayout.addRow(label, i)
         
         self.inputs.update({a:i})
         
     save = QPushButton("Save")
     save.connect(save, SIGNAL("clicked()"), self.save_data)
     layout.addWidget(save)