Esempio n. 1
0
class SelectParts(QDialog):
    def __init__(self, parent=None):
        QDialog.__init__(self)
        self.ui = Ui_dlgParts()
        self.ui.setupUi(self)
        self.ui.lstItems.addItems([k for k, v in prices.iteritems()])
        self.ui.lstItems.setCurrentRow(0)
        self.ui.lstItems.setFocus()
        self.set_prices(self.ui.lstItems.currentItem())
        self.item = None
        self.price = None
        self.done = False
        QObject.connect(self.ui.lstItems, SIGNAL("itemClicked(QListWidgetItem*)"), self.set_prices)
        QObject.connect(self.ui.txtPrice, SIGNAL("returnPressed()"), self.price_entered)
        QObject.connect(self.ui.txtPrice, SIGNAL("textEdited(const QString&)"), self.price_entered)

    def price_entered(self, price=None):
        print price

    def advance(self):
        if self.ui.lstItems.hasFocus():
            pass
            # self.ui.txtPrice.setFocus()
        else:
            print "What"

    def keyPressEvent(self, keyEvent):
        if keyEvent.key() == Qt.Key_Return:
            self.advance()

    def get_prices(self, item):
        text = str(item.text())
        if text in prices:
            return prices[text]
        else:
            return []

    def set_prices(self, item):
        self.ui.lstPrices.clear()
        self.ui.lstPrices.addItems(self.get_prices(item))

    def accept(self):
        if self.ui.lstPrices.currentItem() != None:
            self.done = True
            self.item = self.ui.lstItems.currentItem().text()
            self.price = self.ui.lstPrices.currentItem().text()

        # self.emit(SIGNAL("acceptedItem(item, price)"), self.item, self.price)
        QDialog.accept(self)
Esempio n. 2
0
 def __init__(self, parent=None):
     QDialog.__init__(self)
     self.ui = Ui_dlgParts()
     self.ui.setupUi(self)
     self.ui.lstItems.addItems([k for k, v in prices.iteritems()])
     self.ui.lstItems.setCurrentRow(0)
     self.ui.lstItems.setFocus()
     self.set_prices(self.ui.lstItems.currentItem())
     self.item = None
     self.price = None
     self.done = False
     QObject.connect(self.ui.lstItems, SIGNAL("itemClicked(QListWidgetItem*)"), self.set_prices)
     QObject.connect(self.ui.txtPrice, SIGNAL("returnPressed()"), self.price_entered)
     QObject.connect(self.ui.txtPrice, SIGNAL("textEdited(const QString&)"), self.price_entered)