本文整理汇总了Python中PySide.QtCore.QLocale.toDouble方法的典型用法代码示例。如果您正苦于以下问题:Python QLocale.toDouble方法的具体用法?Python QLocale.toDouble怎么用?Python QLocale.toDouble使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PySide.QtCore.QLocale
的用法示例。
在下文中一共展示了QLocale.toDouble方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: BookEditForm
# 需要导入模块: from PySide.QtCore import QLocale [as 别名]
# 或者: from PySide.QtCore.QLocale import toDouble [as 别名]
#.........这里部分代码省略.........
self.set_image(QImage(image_path), clean_visible=True)
self._image_set = True
self._image_changed = True
def set_image(self, img, clean_visible=False):
pix = QPixmap.fromImage(img)
pix = pix.scaled(self.IMG_SIZE[0], self.IMG_SIZE[1], Qt.KeepAspectRatio)
self.edImage.setPixmap(pix)
self.edImage.setScaledContents(True)
self.btnCleanImage.setVisible(clean_visible)
def check_changes(self, txt):
# getting sender info
sender = self.sender().objectName().split('ed')[1].lower()
if sender != 'subject' and self._old_data[sender] != txt:
self._dirty = True
def check_barcode(self, txt):
if len(txt) == self.edBarcode.maxLength():
self.edBarcode.focusNextChild()
def extract_input(self, text_only=False):
data = {}
data['barcode'] = self.edBarcode.text()
data['title'] = self.edTitle.text()
# completer fields
for c_field, line_edit in [("author", self.edAuthor), ("s_author", self.edSAuthor), ("publisher", self.edPublisher)]:
if not text_only:
data[c_field] = self._get_cfield_value(c_field, line_edit.text())
else:
data[c_field] = line_edit.text()
data['year'] = self.edYear.value()
data['price'] = self._locale.toDouble(self.edPrice.text())[0]
data['description'] = self.edDescription.toPlainText()
if not text_only and self._image_changed and self._image_set:
data['image'] = qpixmap_to_qbytearray(self.edImage.pixmap())
data['availability'] = self.radioAvailability.checkedId()
return data
def setup_model(self):
db = Db_Instance("edit_book").get_instance()
if not db.open():
self.log.error(db.lastError().text())
message = unicode("Erro de conexão\n\n""Banco de dados indisponível".decode('utf-8'))
QMessageBox.critical(self, unicode("Seareiros - Edição de Livro".decode('utf-8')), message)
else:
# book
self._model = QSqlRelationalTableModel(self, db=db)
self._model.setTable("book")
self._model.setFilter("id = " + str(self._record_id))
# self._model.setRelation(self.column["author"], QSqlRelation("author", "id", "name"))
# self._model.setRelation(self.column["s_author"], QSqlRelation("s_author", "id", "name"))
# self._model.setRelation(self.column["publisher"], QSqlRelation("publisher", "id", "name"))
self._model.select()
self._record = self._model.record(0)
# models for setting up qcompleters:
# book_in_subject
self._book_in_subj_model = QSqlTableModel(self, db=db)
self._book_in_subj_model.setTable("book_in_subject")
# subject
self._subject_model = QSqlTableModel(self, db=db)
self._subject_model.setTable("subject")
self._subject_model.select()
示例2: BookAddForm
# 需要导入模块: from PySide.QtCore import QLocale [as 别名]
# 或者: from PySide.QtCore.QLocale import toDouble [as 别名]
#.........这里部分代码省略.........
# known register
data = [id, txt]
else:
# new data
data = [None, txt]
not_a_duplicate = self.add_subject(data)
if not_a_duplicate:
self.refresh_tableSubjects()
self.edSubject.clear()
self.edSubject.setFocus()
@QtCore.Slot()
def on_btnCleanSubjects_clicked(self):
self.clear_table()
self.edSubject.setFocus()
def clear_table(self):
self._subject_list = []
self.tableSubjects.clear()
self.refresh_tableSubjects()
def add_subject(self, data):
""" adds a subject to the list except for duplicates """
if data in self._subject_list:
return False
else:
self._subject_list.append(data)
# sorts by name
self._subject_list.sort(key=operator.itemgetter(1))
return True
def refresh_tableSubjects(self):
if len(self._subject_list) > 0:
self.tableSubjects.setColumnCount(len(self._subject_list[0]) + 1)
col_labels = ["", "Nome", ""]
self.tableSubjects.setHorizontalHeaderLabels(col_labels)
self.tableSubjects.setColumnHidden(0, True)
else:
self.tableSubjects.setColumnCount(0)
self.tableSubjects.setRowCount(len(self._subject_list))
for i, row in enumerate(self._subject_list):
for j, col in enumerate(row):
item = QTableWidgetItem(col)
self.tableSubjects.setItem(i, j, item)
# icon to remove rows individually
remove_icon = QIcon(":icons/conn_failed.png")
remove_btn = QPushButton(remove_icon, "")
remove_btn.clicked.connect(partial(self.remove_subject, subject=row))
self.tableSubjects.setCellWidget(i, len(row), remove_btn)
self.tableSubjects.resizeColumnsToContents()
self.tableSubjects.horizontalHeader().setResizeMode(1, QHeaderView.Stretch)
def remove_subject(self, subject):
# remove a row based on its value
self._subject_list.remove(subject)
self.refresh_tableSubjects()
def extract_input(self):
data = {}
data["barcode"] = self.edBarcode.text()
data["title"] = self.edTitle.text()
# completer fields
for c_field, line_edit in [
("author", self.edAuthor),
("s_author", self.edSAuthor),
("publisher", self.edPublisher),
]:
data[c_field] = self._get_cfield_value(c_field, line_edit.text())
data["year"] = self.edYear.value()
data["price"] = self._locale.toDouble(self.edPrice.text())[0]
data["description"] = self.edDescription.toPlainText()
if self._image_set:
data["image"] = qpixmap_to_qbytearray(self.edImage.pixmap())
data["availability"] = self.radioAvailability.checkedId()
return data
def _get_cfield_value(self, c_field, text):
if text == "":
return None
id = self._get_id_from_name(c_field, text)
if id:
return id
else:
return text
def extract_subjects_input(self):
# grab id of selected activities
subjects = []
new_subjects = []
for subj in self._subject_list:
if subj[0]:
# selected from previously added subjects
subjects.append(subj[0])
else:
# new subject
new_subjects.append(subj[1])
return (subjects, new_subjects)
示例3: testToNumberDouble
# 需要导入模块: from PySide.QtCore import QLocale [as 别名]
# 或者: from PySide.QtCore.QLocale import toDouble [as 别名]
def testToNumberDouble(self):
obj = QLocale(QLocale.C)
self.assertEqual((ctypes.c_double(37.109).value, True),
obj.toDouble('37.109'))
示例4: ProductOrderForm
# 需要导入模块: from PySide.QtCore import QLocale [as 别名]
# 或者: from PySide.QtCore.QLocale import toDouble [as 别名]
#.........这里部分代码省略.........
return True
# failed to insert a row
return False
def clear(self):
""" Globally cleans this form """
self._dirty = False
for lineEdit in self.findChildren(QLineEdit):
lineEdit.clear()
# product
# edProduct is a QLineEdit so... already clean
self.clear_table()
self.lblTotal.setText("0,00")
self.edQuantity.setValue(1)
# associate
self.clear_associate()
self.edProductName.setFocus()
def clear_associate(self):
# resets associate frame
self.lblName.clear()
self.lblNickname.clear()
self._associate_id = None
self.frameAssociate.setVisible(False)
self.btnCleanAssociate.setVisible(False)
# can't allow an order to be paid later without an associate to relate to
self.rdNotPaid.setEnabled(False)
self.rdPaid.setChecked(True)
@QtCore.Slot()
def on_btnAddProduct_clicked(self):
txt = self.edProductName.text()
price = self._locale.toDouble(self.edPrice.text())[0]
quantity = self.edQuantity.value()
if txt != "":
data = [txt, price, quantity]
self.add_product(data)
self.update_total(price * quantity)
self.refresh_tableProducts()
# cleaning product related input
self.edProductName.clear()
self.edPrice.setText("0,00")
self.edQuantity.setValue(1)
self.edProductName.setFocus()
@QtCore.Slot()
def on_btnSelectAssociate_clicked(self):
associate_dialog = AssociateSelectDialog()
if associate_dialog.exec_() == QDialog.Accepted:
record = associate_dialog.get_record()
self._associate_id = record.value("id")
self.set_associate_info(record.value("fullname"), record.value("nickname"))
self.frameAssociate.setVisible(True)
self.btnCleanAssociate.setVisible(True)
# a registered associate can pay later
self.rdNotPaid.setEnabled(True)
self.edProductName.setFocus()
def set_associate_info(self, fullname, nickname):
self.lblName.setText(fullname)
self.lblNickname.setText(nickname)
@QtCore.Slot()
def on_btnCleanAssociate_clicked(self):
self.clear_associate()