本文整理汇总了Python中UI.widgets.Tabla.horizontalHeaderItem方法的典型用法代码示例。如果您正苦于以下问题:Python Tabla.horizontalHeaderItem方法的具体用法?Python Tabla.horizontalHeaderItem怎么用?Python Tabla.horizontalHeaderItem使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UI.widgets.Tabla
的用法示例。
在下文中一共展示了Tabla.horizontalHeaderItem方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: InputTableWidget
# 需要导入模块: from UI.widgets import Tabla [as 别名]
# 或者: from UI.widgets.Tabla import horizontalHeaderItem [as 别名]
#.........这里部分代码省略.........
def showTc(self, value):
"""Show/hide Tc widget"""
self.labelTc.setVisible(value in (7, 9))
self.tc.setVisible(value in (7, 9))
def open(self):
"""Load data from a test file"""
fname, ext = QtWidgets.QFileDialog.getOpenFileName(
self,
QtWidgets.QApplication.translate("pychemqt", "Open text file"),
"./")
if fname:
try:
# Numpy raise error if use the fname directly and find a
# non-latin1 character, inclusive in comment lines
with open(fname, "rb") as file:
data = loadtxt(file)
self.delete()
self.tabla.setData(data)
except ValueError as er:
# Raise a error msg if the file can load by loadtxt, the user
# can select any type of file and the input error is possible
title = QtWidgets.QApplication.translate(
"pychemqt", "Failed to load file")
msg = fname + "\n" + er.args[0]
QtWidgets.QMessageBox.critical(self, title, msg)
def save(self):
"""Save currend data of table to a file"""
fname, ext = QtWidgets.QFileDialog.getSaveFileName(
self,
QtWidgets.QApplication.translate("pychemqt", "Save data to file"),
"./")
if fname:
with open(fname, 'w') as file:
file.write("#"+self.title+"\n")
file.write("#")
for i in range(self.tabla.columnCount()):
item = self.tabla.horizontalHeaderItem(i)
file.write(item.text()+"\t")
file.write("\n")
data = self.data
for fila in range(len(data)):
for columna in range(self.tabla.columnCount()):
file.write(str(data[fila][columna])+"\t")
file.write("\n")
def delete(self):
"""Clear table"""
self.tabla.setRowCount(0)
self.tabla.clearContents()
self.tabla.addRow()
@property
def data(self):
return self.tabla.getData()
def column(self, column, magnitud=None, unit="conf"):
"""
column: column to get
magnitud: magnitud to get the values
unit: unit of the values in table"""
data = self.tabla.getColumn(column)
if self.unit:
magnitud = self.unit[column]
tx = self.tabla.horizontalHeaderItem(column).text().split(", ")[-1]
unit = magnitud.__units__[magnitud.__text__.index(tx)]
if magnitud is not None:
data = [magnitud(x, unit) for x in data]
return data
def editUnit(self, col):
"""Show dialog to config input unit"""
unit = self.unit[col]
widget = QtWidgets.QComboBox(self.tabla)
for txt in unit.__text__:
widget.addItem(txt)
txt = self.tabla.horizontalHeaderItem(col).text().split(", ")[-1]
widget.setCurrentText(txt)
# Define Unit combobox geometry
size = self.tabla.horizontalHeader().sectionSize(col)
pos = self.tabla.horizontalHeader().sectionPosition(col)
h = self.tabla.horizontalHeader().height()
geometry = QtCore.QRect(pos, 0, size, h)
widget.setGeometry(geometry)
widget.currentIndexChanged["int"].connect(
partial(self.updateHeader, col))
widget.show()
widget.showPopup()
def updateHeader(self, col, index):
"""Change the text in header"""
widget = self.sender()
txt = self.tabla.horizontalHeaderItem(col).text()
newtxt = "%s, %s" % (txt.split(",")[0], widget.currentText())
self.tabla.setHorizontalHeaderItem(
col, QtWidgets.QTableWidgetItem(newtxt))
widget.close()