예제 #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)
예제 #2
0
 def addRichTypes(self, l):
     """set the list of richtypes"""
     for q in l:
         i = len(self.richTypes)
         self.richTypes.append(q)
         l = QLabel(self)
         self.qlabels.append(l)
         l.setText(q.name)
         l.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.MinimumExpanding)
         l.setToolTip(q.descr)
         self.gridLayout.addWidget(l, i, 0, 1, 1)
         cls = q.__class__
         if cls == Text:
             w = QLineEdit(self)
             w.setMinimumSize(300, 30)
             if q.maxLen: w.setMaxLength(q.maxLen)
             w.setText(q.v)
         elif cls == MLText:
             w = QTextEdit(self)
             w.setAcceptRichText(False)
             w.setMinimumSize(300, 60)
             w.setText(q.v)
         elif cls == Choice:
             w = QComboBox(self)
             c = [unicode(x) for x in q.choices]
             c.sort()
             w.addItems(c)
             idx = w.findText(unicode(q.v))
             if idx >= 0:
                 w.setCurrentIndex(idx)
         elif cls == MultiChoice:
             w = QListWidget(self)
             w.setSelectionMode(QAbstractItemView.MultiSelection)
             w.setMinimumSize(100, 60)
             c = [unicode(x) for x in q.choices]
             c.sort()
             v = [unicode(x) for x in q.v]
             for ii, s in enumerate(c):
                 w.addItem(s)
                 if s in v:
                     w.item(ii).setSelected(True)
         elif cls == Bool:
             w = QCheckBox(self)
             if q.v:
                 w.setCheckState(Qt.Checked)
             else:
                 w.setCheckState(Qt.Unchecked)
         elif cls == Integer:
             w = QSpinBox(self)
             if q.min is not None:
                 w.setMinimum(q.min)
             if q.max is not None:
                 w.setMaximum(q.max)
             if q.step is not None:
                 w.setSingleStep(q.step or 0.01)
             if q.unit: w.setSuffix(' '+q.unit)
             w.setValue(q.v)
         elif cls == Float:
             w = QDoubleSpinBox(self)
             if q.min is not None:
                 w.setMinimum(q.min)
             if q.max is not None:
                 w.setMaximum(q.max)
             w.setSingleStep(q.step or 0.01)
             if q.unit: w.setSuffix(' '+q.unit)
             w.setValue(q.v)
         elif cls == DateTime:
             w = QDateTimeEdit(self)
             w.setCalendarPopup(True)
             dt = QDateTime()
             dt.setTime_t(q.v)
             w.setDateTime(dt)
             if q.min is not None:
                 mindt = QDateTime()
                 mindt.setTime_t(q.min)
                 w.setMinimumDate(mindt.date())
             if q.max is not None:
                 maxdt = QDateTime()
                 maxdt.setTime_t(q.max)
                 w.setMaximumDate(maxdt.date())
         l.setBuddy(w)
         w.setToolTip(q.descr)
         w.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Expanding)
         w.adjustSize()
         self.gridLayout.addWidget(w, i, 1, 1, 1)
         self.qwidgets.append(w)
     self.adjustSize()