本文整理汇总了Python中qtpy.QtWidgets.QMenu.setTitle方法的典型用法代码示例。如果您正苦于以下问题:Python QMenu.setTitle方法的具体用法?Python QMenu.setTitle怎么用?Python QMenu.setTitle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类qtpy.QtWidgets.QMenu
的用法示例。
在下文中一共展示了QMenu.setTitle方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: PreviewTable
# 需要导入模块: from qtpy.QtWidgets import QMenu [as 别名]
# 或者: from qtpy.QtWidgets.QMenu import setTitle [as 别名]
class PreviewTable(QTableView):
"""Import wizard preview widget"""
def __init__(self, parent):
QTableView.__init__(self, parent)
self._model = None
# Setting up actions
self.date_dayfirst_action = create_action(self, "dayfirst",
triggered=ft_partial(self.parse_to_type, atype="date", dayfirst=True))
self.date_monthfirst_action = create_action(self, "monthfirst",
triggered=ft_partial(self.parse_to_type, atype="date", dayfirst=False))
self.perc_action = create_action(self, "perc",
triggered=ft_partial(self.parse_to_type, atype="perc"))
self.acc_action = create_action(self, "account",
triggered=ft_partial(self.parse_to_type, atype="account"))
self.str_action = create_action(self, "unicode",
triggered=ft_partial(self.parse_to_type, atype="unicode"))
self.int_action = create_action(self, "int",
triggered=ft_partial(self.parse_to_type, atype="int"))
self.float_action = create_action(self, "float",
triggered=ft_partial(self.parse_to_type, atype="float"))
# Setting up menus
self.date_menu = QMenu()
self.date_menu.setTitle("Date")
add_actions( self.date_menu, (self.date_dayfirst_action,
self.date_monthfirst_action))
self.parse_menu = QMenu(self)
self.parse_menu.addMenu(self.date_menu)
add_actions( self.parse_menu, (self.perc_action, self.acc_action))
self.parse_menu.setTitle("String to")
self.opt_menu = QMenu(self)
self.opt_menu.addMenu(self.parse_menu)
add_actions( self.opt_menu, (self.str_action, self.int_action,
self.float_action))
def _shape_text(self, text, colsep=u"\t", rowsep=u"\n",
transpose=False, skiprows=0, comments='#'):
"""Decode the shape of the given text"""
assert colsep != rowsep
out = []
text_rows = text.split(rowsep)[skiprows:]
for row in text_rows:
stripped = to_text_string(row).strip()
if len(stripped) == 0 or stripped.startswith(comments):
continue
line = to_text_string(row).split(colsep)
line = [try_to_parse(to_text_string(x)) for x in line]
out.append(line)
# Replace missing elements with np.nan's or None's
if programs.is_module_installed('numpy'):
from numpy import nan
out = list(zip_longest(*out, fillvalue=nan))
else:
out = list(zip_longest(*out, fillvalue=None))
# Tranpose the last result to get the expected one
out = [[r[col] for r in out] for col in range(len(out[0]))]
if transpose:
return [[r[col] for r in out] for col in range(len(out[0]))]
return out
def get_data(self):
"""Return model data"""
if self._model is None:
return None
return self._model.get_data()
def process_data(self, text, colsep=u"\t", rowsep=u"\n",
transpose=False, skiprows=0, comments='#'):
"""Put data into table model"""
data = self._shape_text(text, colsep, rowsep, transpose, skiprows,
comments)
self._model = PreviewTableModel(data)
self.setModel(self._model)
@Slot()
def parse_to_type(self,**kwargs):
"""Parse to a given type"""
indexes = self.selectedIndexes()
if not indexes: return
for index in indexes:
self.model().parse_data_type(index, **kwargs)
def contextMenuEvent(self, event):
"""Reimplement Qt method"""
self.opt_menu.popup(event.globalPos())
event.accept()