当前位置: 首页>>代码示例>>Python>>正文


Python QMenu.setTitle方法代码示例

本文整理汇总了Python中spyderlib.qt.QtGui.QMenu.setTitle方法的典型用法代码示例。如果您正苦于以下问题:Python QMenu.setTitle方法的具体用法?Python QMenu.setTitle怎么用?Python QMenu.setTitle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在spyderlib.qt.QtGui.QMenu的用法示例。


在下文中一共展示了QMenu.setTitle方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: PreviewTable

# 需要导入模块: from spyderlib.qt.QtGui import QMenu [as 别名]
# 或者: from spyderlib.qt.QtGui.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()
开发者ID:gyenney,项目名称:Tools,代码行数:84,代码来源:importwizard.py

示例2: PreviewTable

# 需要导入模块: from spyderlib.qt.QtGui import QMenu [as 别名]
# 或者: from spyderlib.qt.QtGui.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 = map(None, text.split(rowsep))[skiprows:]
        for row in text_rows:
            stripped = unicode(row).strip()
            if len(stripped) == 0 or stripped.startswith(comments):
                continue
            line = unicode(row).split(colsep)
            line = map(lambda x: try_to_parse(unicode(x)), line)
            out.append(line)
        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)

    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()
开发者ID:jromang,项目名称:retina-old,代码行数:80,代码来源:importwizard.py


注:本文中的spyderlib.qt.QtGui.QMenu.setTitle方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。