本文整理汇总了Python中PySide.QtCore.QLocale.toString方法的典型用法代码示例。如果您正苦于以下问题:Python QLocale.toString方法的具体用法?Python QLocale.toString怎么用?Python QLocale.toString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PySide.QtCore.QLocale
的用法示例。
在下文中一共展示了QLocale.toString方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: BookOrderTableModel
# 需要导入模块: from PySide.QtCore import QLocale [as 别名]
# 或者: from PySide.QtCore.QLocale import toString [as 别名]
class BookOrderTableModel(BaseTableModel):
""" Model for listing book orders """
ID, DATE, TOTAL, ASSOCIATE, OBS = range(5)
def __init__(self, parent=None):
super(BookOrderTableModel, self).__init__(parent)
self._sql_statement = "SELECT b_o.id, b_o.date, b_o.total, a.fullname as associate, SUBSTR(b_o.obs,0,50) as obs " \
"FROM order_request b_o " \
"LEFT JOIN associate a ON b_o.associate_id = a.id " \
"WHERE b_o.type = 1"
self._name = "populate_obook"
self._locale = QLocale()
def load(self):
self.set_query_info(self._name, self._sql_statement)
super(BookOrderTableModel, self).load()
def data(self, index, role=Qt.DisplayRole):
if not index.isValid() or not (0<=index.row()<self.rowCount()):
# invalid index
return None
record = self.get_record(index.row())
column = index.column()
if role == Qt.DisplayRole:
if column == self.ID:
return record.value("id")
elif column == self.DATE:
return record.value("date").toString("dd/MMM - HH:mm")
elif column == self.TOTAL:
return self._locale.toString(record.value("total"), 'f', 2).replace('.','')
elif column == self.ASSOCIATE:
return record.value("associate")
elif column == self.OBS:
return record.value("obs")
return None
def headerData(self, section, orientation, role=Qt.DisplayRole):
if role == Qt.TextAlignmentRole:
if orientation == Qt.Horizontal:
return int(Qt.AlignLeft|Qt.AlignVCenter)
return int(Qt.AlignRight|Qt.AlignVCenter)
if role != Qt.DisplayRole:
return None
if orientation == Qt.Horizontal:
if section == self.ID:
return "Reg."
elif section == self.DATE:
return "Data e Hora"
elif section == self.TOTAL:
return "Total (R$)"
elif section == self.ASSOCIATE:
return "Associado"
elif section == self.OBS:
return unicode("Observações".decode('utf-8'))
return section + 1
示例2: formatUptime
# 需要导入模块: from PySide.QtCore import QLocale [as 别名]
# 或者: from PySide.QtCore.QLocale import toString [as 别名]
def formatUptime(time):
s = ''
loc = QLocale()
if time.days > 0:
d = QCoreApplication.translate('ifmon', 'days') if time.days > 1 \
else QCoreApplication.translate('ifmon', 'day')
s = '%s %s, ' % (loc.toString(time.days), d)
mm, ss = divmod(time.seconds, 60)
hh, mm = divmod(mm, 60)
def padded(d):
if d < 10:
return loc.toString(0) + loc.toString(d)
else:
return loc.toString(d)
s += '%s:%s:%s' % (padded(hh), padded(mm), padded(ss))
return s
示例3: DefaulterTableModel
# 需要导入模块: from PySide.QtCore import QLocale [as 别名]
# 或者: from PySide.QtCore.QLocale import toString [as 别名]
class DefaulterTableModel(AssociateTableModel):
""" Model for defaulter (at fault, associates with debt) objects """
DEBT = 8
def __init__(self, parent=None):
super(DefaulterTableModel, self).__init__(parent)
self._sql_statement = "SELECT id, fullname, nickname, email, resphone, comphone, privphone, " \
"streetaddress, debt FROM associate WHERE debt > 0.0"
self._name = "populate_defaulter"
self._locale = QLocale()
def data(self, index, role=Qt.DisplayRole):
if not index.isValid() or not (0<=index.row()<self.rowCount()):
# invalid index
return None
record = self.get_record(index.row())
column = index.column()
if role == Qt.DisplayRole:
if column == self.DEBT:
return self._locale.toString(record.value("debt"), 'f', 2).replace('.','')
else:
return super(DefaulterTableModel, self).data(index, role)
def headerData(self, section, orientation, role=Qt.DisplayRole):
if role == Qt.TextAlignmentRole:
if orientation == Qt.Horizontal:
return int(Qt.AlignLeft|Qt.AlignVCenter)
return int(Qt.AlignRight|Qt.AlignVCenter)
if role != Qt.DisplayRole:
return None
if orientation == Qt.Horizontal:
if section == self.DEBT:
return unicode("Pendência (R$)".decode('utf-8'))
else:
return super(DefaulterTableModel, self).headerData(section, orientation, role)
return section + 1
示例4: BookOrderForm
# 需要导入模块: from PySide.QtCore import QLocale [as 别名]
# 或者: from PySide.QtCore.QLocale import toString [as 别名]
#.........这里部分代码省略.........
self.edBarcode.setFocus()
return False
data = self.extract_input()
# filling a book order
self._model.insertRow(0)
for key,val in data.items():
self._model.setData(self._model.index(0, self.column[key]), val)
order_id = submit_and_get_id(self, self._model, self.log)
if order_id:
# order creation success, placing items
error = False
for item in self._book_list:
book_id = item[0]
book_quantity = item[3]
self._items_model.insertRow(0)
self._items_model.setData(self._items_model.index(0,1), order_id)
self._items_model.setData(self._items_model.index(0,2), book_id)
self._items_model.setData(self._items_model.index(0,3), book_quantity)
ok = self._items_model.submitAll()
if not ok:
error = True
break
if error:
self.log.error(self._items_model.lastError().text())
message = unicode("Erro\n\n""Venda registrada e contabilizada, porém ocorreu um problema e"
" não será possível visualizar seus itens.".decode('utf-8'))
QMessageBox.warning(self, "Seareiros - Livraria", message)
return False
else:
# all went fine
# retrieving some brief info of the order to display at the main window
if 'associate' in data:
desc = "Venda da livraria no valor de R$ %s para %s" % \
(self._locale.toString(data['total'], 'f', 2).replace('.',''), self.lblNickname.text())
else:
desc = "Venda da livraria no valor de R$ %s" % self._locale.toString(data['total'], 'f', 2).replace('.','')
if not log_to_history(self._model.database(), "venda_livraria", order_id, desc):
self.log.error(self._model.lastError().text())
message = unicode("Sucesso!\n\n""Venda concluída.".decode('utf-8'))
QMessageBox.information(self, "Seareiros - Livraria", message)
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()
# book
self.clear_table()
self.lblTotal.setText("0,00")
# associate
self.clear_associate()
self.edBarcode.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)
示例5: BookEditForm
# 需要导入模块: from PySide.QtCore import QLocale [as 别名]
# 或者: from PySide.QtCore.QLocale import toString [as 别名]
#.........这里部分代码省略.........
# had some problem with C++ originated objects
if lineEdit.objectName() not in ['qt_spinbox_lineedit', 'edSubject']:
lineEdit.returnPressed.connect(lineEdit.focusNextChild)
# detect changes on line edits
lineEdit.textChanged.connect(self.check_changes)
# different behaviour for these
self.edBarcode.textChanged.connect(self.check_barcode)
self.edSubject.returnPressed.connect(self.on_btnAddSubject_clicked)
# completers
config_completer(self.edSubject, self._subject_model, "name")
config_completer(self.edAuthor, self._author_model, "name")
config_completer(self.edSAuthor, self._s_author_model, "name")
config_completer(self.edPublisher, self._publisher_model, "name")
# making image clickable
clickable(self.edImage).connect(self.handle_image)
def fill_form(self):
# retrieving book info
self.edBarcode.setText(self._record.value("barcode"))
self.edTitle.setText(self._record.value("title"))
self.edYear.setValue(self._record.value("year"))
self.edDescription.setPlainText(self._record.value("description"))
self.radioAvailability.button(self._record.value("availability")).setChecked(True)
# retrieving image
ba = QByteArray(self._record.value("image"))
if ba:
self._image_set = True
img = qbytearray_to_qimage(ba)
self.set_image(img, clean_visible=True)
# currency
# TODO: ARRUMAR
self.edPrice.setText(self._locale.toString(self._record.value("price"), 'f', 2).replace('.',''))
# qcompleter fields
self.edAuthor.setText(self._get_name_from_id("author", self._record.value("author_id")))
self.edSAuthor.setText(self._get_name_from_id("s_author", self._record.value("s_author_id")))
self.edPublisher.setText(self._get_name_from_id("publisher", self._record.value("publisher_id")))
# retrieving subjects
for subj_record in self._subj_records:
self.add_subject([subj_record.value("id"),subj_record.value("name")])
# clearing changes
self._added_subjects[:] = []
self.refresh_tableSubjects()
def clear_image(self):
img = QImage(":icons/no_image.png")
self.set_image(img, clean_visible=False)
if self._image_set:
self._image_set = False
self._image_changed = True
def handle_image(self):
image_path = QFileDialog.getOpenFileName(self, "Escolha uma imagem", os.getenv("HOME"), "Imagens (*.png, *.jpg *.bmp)")[0]
if os.path.exists(image_path):
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)
示例6: BookTableModel
# 需要导入模块: from PySide.QtCore import QLocale [as 别名]
# 或者: from PySide.QtCore.QLocale import toString [as 别名]
class BookTableModel(BaseTableModel):
""" Model for book objects """
ID, TITLE, AUTHOR, S_AUTHOR, PRICE, STOCK, AVAILABILITY = range(7)
def __init__(self, parent=None, display_mode=constants.BOOK_ALL):
super(BookTableModel, self).__init__(parent)
self._sql_statement = "SELECT b.id, b.title, a.name as author, s_a.name as s_author, b.price, b.stock, b.availability " \
"FROM book b " \
"LEFT JOIN author a ON b.author_id = a.id " \
"LEFT JOIN s_author s_a ON b.s_author_id = s_a.id"
if display_mode == constants.BOOK_SELL:
self._sql_statement += " WHERE b.availability = 0 AND b.stock > 0"
elif display_mode == constants.BOOK_RENT:
self._sql_statement += " WHERE b.availability = 1"
self._name = "populate_book"
self._locale = QLocale()
def load(self):
self.set_query_info(self._name, self._sql_statement)
super(BookTableModel, self).load()
def data(self, index, role=Qt.DisplayRole):
if not index.isValid() or not (0<=index.row()<self.rowCount()):
# invalid index
return None
record = self.get_record(index.row())
column = index.column()
if role == Qt.DisplayRole:
if column == self.ID:
return record.value("id")
elif column == self.TITLE:
return record.value("title")
elif column == self.AUTHOR:
return record.value("author")
elif column == self.S_AUTHOR:
return record.value("s_author")
elif column == self.PRICE:
return self._locale.toString(record.value("price"), 'f', 2).replace('.','')
elif column == self.STOCK:
return record.value("stock")
elif column == self.AVAILABILITY:
return self.extend_availability(record.value("availability"))
return None
def headerData(self, section, orientation, role=Qt.DisplayRole):
if role == Qt.TextAlignmentRole:
if orientation == Qt.Horizontal:
return int(Qt.AlignLeft|Qt.AlignVCenter)
return int(Qt.AlignRight|Qt.AlignVCenter)
if role != Qt.DisplayRole:
return None
if orientation == Qt.Horizontal:
if section == self.ID:
return "Reg."
elif section == self.TITLE:
return unicode("Título".decode('utf-8'))
elif section == self.AUTHOR:
return "Autor"
elif section == self.S_AUTHOR:
return "Autor (Esp.)"
elif section == self.PRICE:
return unicode("Preço (R$)".decode('utf-8'))
elif section == self.STOCK:
return "Estoque"
elif section == self.AVAILABILITY:
return "Disponibilidade"
return section + 1
def extend_availability(self, availability):
avail_list = ['Venda', unicode('Locação'.decode('utf-8')), 'Inativo']
return avail_list[availability]
示例7: ProductOrderForm
# 需要导入模块: from PySide.QtCore import QLocale [as 别名]
# 或者: from PySide.QtCore.QLocale import toString [as 别名]
#.........这里部分代码省略.........
for key, val in data.items():
self._model.setData(self._model.index(0, self.column[key]), val)
order_id = submit_and_get_id(self, self._model, self.log)
if order_id:
# order creation success, placing items
error = False
for item in self._product_list:
product_name = item[0]
product_price = item[1]
product_quantity = item[2]
self._items_model.insertRow(0)
self._items_model.setData(self._items_model.index(0, 1), order_id)
self._items_model.setData(self._items_model.index(0, 2), product_name)
self._items_model.setData(self._items_model.index(0, 3), product_price)
self._items_model.setData(self._items_model.index(0, 4), product_quantity)
ok = self._items_model.submitAll()
if not ok:
error = True
break
if error:
self.log.error(self._items_model.lastError().text())
message = unicode(
"Erro\n\n"
"Venda registrada e contabilizada, porém ocorreu um problema e"
" não será possível visualizar seus itens.".decode("utf-8")
)
QMessageBox.warning(self, "Seareiros - Vendas do Bazar", message)
return False
else:
# all went fine
# retrieving some brief info of the order to display at the main window
if "associate" in data:
desc = "Venda do bazar no valor de R$ %s para %s" % (
self._locale.toString(data["total"], "f", 2).replace(".", ""),
self.lblNickname.text(),
)
else:
desc = "Venda do bazar no valor de R$ %s" % self._locale.toString(data["total"], "f", 2).replace(
".", ""
)
if not log_to_history(self._model.database(), "venda_bazar", order_id, desc):
self.log.error(self._model.lastError().text())
message = unicode("Sucesso!\n\n" "Venda concluída.".decode("utf-8"))
QMessageBox.information(self, "Seareiros - Vendas do Bazar", message)
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()