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


Python QMenu.setToolTip方法代码示例

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


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

示例1: install_shortcuts

# 需要导入模块: from PyQt5.QtWidgets import QMenu [as 别名]
# 或者: from PyQt5.QtWidgets.QMenu import setToolTip [as 别名]
def install_shortcuts(obj, actions, ide):
    short = resources.get_shortcut
    for action in actions:
        short_key = action.get("shortcut", None)
        action_data = action.get("action", None)
        connect = action.get("connect", None)
        shortcut = None
        item_ui = None
        func = None
        if connect is not None:
            func = getattr(obj, connect, None)

        if short_key and not action_data:
            if isinstance(short_key, QKeySequence):
                shortcut = QShortcut(short_key, ide)
            else:
                if short(short_key) is None:
                    logger.warning("Not shorcut for %s" % short_key)
                    continue
                shortcut = QShortcut(short(short_key), ide)
            shortcut.setContext(Qt.ApplicationShortcut)
            if isinstance(func, collections.Callable):
                shortcut.activated.connect(func)
        if action_data:
            is_menu = action_data.get('is_menu', False)
            if is_menu:
                item_ui = QMenu(action_data['text'], ide)
            else:
                item_ui = QAction(action_data['text'], ide)
                object_name = "%s.%s" % (obj.__class__.__name__, connect)
                item_ui.setObjectName(object_name)
                # FIXME: Configurable
                item_ui.setIconVisibleInMenu(False)
            image_name = action_data.get('image', None)
            section = action_data.get('section', None)
            weight = action_data.get('weight', None)
            keysequence = action_data.get('keysequence', None)
            if image_name:
                if isinstance(image_name, int):
                    icon = ide.style().standardIcon(image_name)
                    item_ui.setIcon(icon)
                elif isinstance(image_name, str):
                    if image_name.startswith("/home"):
                        icon = QIcon(image_name)
                    else:
                        icon = QIcon(":img/" + image_name)
                    item_ui.setIcon(icon)
            if short_key and not is_menu:
                if short(short_key) is None:
                    logger.warning("Not shortcut for %s" % short_key)
                    continue
                item_ui.setShortcut(short(short_key))
                # Add tooltip with append shortcut
                item_ui.setToolTip(
                    tooltip_with_shortcut(item_ui.text(), short(short_key)))
                item_ui.setShortcutContext(Qt.ApplicationShortcut)
            elif keysequence and not is_menu:
                item_ui.setShortcut(short(keysequence))
                item_ui.setShortcutContext(Qt.ApplicationShortcut)
            if isinstance(func, collections.Callable) and not is_menu:
                item_ui.triggered.connect(lambda _, func=func: func())
            if section and section[0] is not None and weight:
                ide.register_menuitem(item_ui, section, weight)
                if image_name and not is_menu:
                    ide.register_toolbar(item_ui, section, weight)

        if short_key and shortcut:
            ide.register_shortcut(short_key, shortcut, item_ui)
开发者ID:ninja-ide,项目名称:ninja-ide,代码行数:70,代码来源:ui_tools.py

示例2: build_xlt_menu

# 需要导入模块: from PyQt5.QtWidgets import QMenu [as 别名]
# 或者: from PyQt5.QtWidgets.QMenu import setToolTip [as 别名]
def build_xlt_menu( mainwindow, slot ):

    # Create the submenu but assume it will be empty.
    submenu = QMenu(
        _TR( 'Name of Translators submenu', 'Translators...' ) )
    submenu.setToolTip(
        _TR( 'Translators submenu tooltip',
             'Available Translators in extras/Translators folder' ) )
    submenu.setEnabled( False )

    # Form the path to extras/Translators and try to get a list
    # of all files in it. If it doesn't exist or isn't a dir,
    # we get an error.
    xlt_dir = os.path.join( paths.get_extras_path(), 'Translators' )
    try :
        xlt_files = os.listdir( xlt_dir )
    except Exception as E:
        # this error is logged but not displayed to the user as its
        # only effect is an empty, disabled submenu.
        xlt_logger.error( 'Unable to load any Translator modules')
        xlt_logger.error( str(E) )
        xlt_files = []

    # Check every file in extras/Translators as a possible Translator
    for candidate in xlt_files :

        # Form the full path
        candidate_path = os.path.join( xlt_dir, candidate )

        # Is it readable?
        if not os.access( candidate_path, os.R_OK ) : continue

        # Is it a python source? (Not supporting .pyc just now)
        if not candidate.endswith('.py') : continue

        # Create a loader object - this throws no exceptions
        xlt_logger.info( 'Loading translator module '+candidate )
        xlt_loader = importlib.machinery.SourceFileLoader(
            os.path.splitext( candidate )[0], candidate_path )

        # Try the actual load, which executes the code and can throw
        # exceptions either directly from the loader, or uncaught exceptions
        # thrown by the loaded code. If any exceptions, skip it.
        xlt_logger.info( 'Executing translator into namespace '+candidate )
        try:
            xlt_namespace = xlt_loader.load_module()
        except Exception as E :
            # This error is only logged. It is of interest only to the
            # coder of a Translator wondering why it doesn't appear.
            xlt_logger.error( 'Error loading or executing Translator {}:'.format(candidate) )
            xlt_logger.error( str(E) )
            continue

        # The loaded module should have a MENU_NAME which is a string
        xlt_name = getattr( xlt_namespace, 'MENU_NAME', False )
        if not isinstance(xlt_name, str) :
            xlt_logger.error('Translator {} has no MENU_NAME string'.format(candidate) )
            continue

        # The MENU_NAME should be of reasonable length for a menu item
        if ( len( xlt_name ) > 16 ) or ( len( xlt_name ) < 3 ) :
            xlt_logger.error('Translator {} MENU_NAME too long or too short'.format(candidate) )
            continue

        # The loaded module should offer global functions initialize() and
        # translate(). If not, log an error.

        xlt_fun = getattr( xlt_namespace, 'initialize', False )
        if not isinstance( xlt_fun, types.FunctionType ):
            xlt_logger.error('Translator {} lacks initialize() member'.format(candidate) )
            continue
        xlt_fun = getattr( xlt_namespace, 'translate', False )
        if not isinstance( xlt_fun, types.FunctionType ) :
            xlt_logger.error('Translator {} lacks translate() member'.format(candidate) )
            continue
        xlt_fun = getattr( xlt_namespace, 'finalize', False )
        if not isinstance( xlt_fun, types.FunctionType ) :
            xlt_logger.error('Translator {} lacks finalize() member'.format(candidate) )
            continue
        # OK, we are going to trust it. Save the namespace for use later.
        xlt_index = len( _XLT_NAMESPACES )
        _XLT_NAMESPACES.append( xlt_namespace )

        # Build the menu action with the given name and an optional tooltip.
        action = submenu.addAction( xlt_namespace.MENU_NAME )
        action.setToolTip( getattr( xlt_namespace, 'TOOLTIP', '' ) )

        # Save the index to the namespace as the menu action's data()
        action.setData( xlt_index )

        # Connect the action to the slot provided
        action.triggered.connect( slot )

        # The menu is not going to be empty, so make it enabled
        submenu.setEnabled( True )

    # end for candidate in xlt_files
    return submenu
开发者ID:tallforasmurf,项目名称:PPQT2,代码行数:100,代码来源:translators.py


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