src/aoikhotkey/util/growl.py
def hotkey_tfunc(hotkey_manager, hotkey, hotkey_type, hotkey_info, event):
    """
    Hotkey trigger function that sends notification to Growl.

    :param hotkey_manager: Hotkey manager.

    :param hotkey: Hotkey's virtual key list.

    :param hotkey_type: Hotkey type.

    :param hotkey_info: Hotkey info.

    :param event: Event object.

    :return: None.
    """
    # Create task function
    def task_func():
        # Call default hotkey trigger function to print message to console
        hotkey_tfunc_default(
            hotkey_manager, hotkey, hotkey_type, hotkey_info, event
        )

        # Use global variable
        global _GROWL_NOTI

        # If the Growl notifier is False,
        # it means the initialization below failed.
        if _GROWL_NOTI is False:
            # Do not send message to Growl
            return

        # If the Growl notifier is not False.

        # If the Growl notifier is None,
        # it means the initialization is not done yet.
        if _GROWL_NOTI is None:
            try:
                # Import module
                import gntp.notifier

                # Create Growl notifier
                _GROWL_NOTI = gntp.notifier.GrowlNotifier(
                    applicationName='AoikHotkey',
                    notifications=['New Messages'],
                    defaultNotifications=['New Messages'],
                )

                # Register with Growl
                _GROWL_NOTI.register()

            # If have import error
            except ImportError:
                # Set the Growl notifier be False
                _GROWL_NOTI = False

                # Get error message
                msg = (
                    'Package `gntp` is not installed. Try:\n'
                    'pip install gntp\n'
                )

                # Print error message
                sys.stderr.write(msg)

                # Do not send message to Growl
                return

            # If have other error
            except Exception:
                # Set the Growl notifier be False
                _GROWL_NOTI = False

                # Get traceback message
                tb_msg = format_exc()

                # Get error message
                msg = (
                    '# Error: Failed initializing Growl notifier:\n'
                    '---\n{0}---\n'
                ).format(tb_msg)

                # Print error message
                sys.stderr.write(msg)

                # Do not send message to Growl
                return

        # Assert the Growl notifier is not False or None
        assert _GROWL_NOTI

        # If hotkey type is key-down
        if hotkey_type == HOTKEY_TYPE_V_DN:
            # Get text
            up_dn_text = ' down '

        # If hotkey type is key-up
        elif hotkey_type == HOTKEY_TYPE_V_UP:
            # Get text
            up_dn_text = ' up '

        # If hotkey type is not key-down or key-up
        else:
            # Get text
            up_dn_text = ' '

        # Get original hotkey spec
        orig_spec = hotkey_info[HOTKEY_INFO_K_HOTKEY_ORIG_SPEC]

        # Get notification title
        title = '{hotkey_type}{up_dn_text}triggered'.format(
            hotkey_type='Hotseq'
            if hotkey_type == HOTKEY_TYPE_V_KS else 'Hotkey',
            up_dn_text=up_dn_text,
        )

        # Get hotkey pattern
        hotkey_pattern = orig_spec[0]

        # Get notification description
        description = '{hotkey_pattern}\n{hotkey_vk_names}'.format(
            hotkey_pattern=hotkey_pattern,
            hotkey_vk_names=' '.join(
                hotkey_manager.vk_to_name(x) or str(x) for x in hotkey
            ),
        )

        # Create task function
        _GROWL_NOTI.notify(
            noteType='New Messages',
            title=title,
            description=description,
        )

    # Add task function to queue
    add_task(task_func)

    Hotkey trigger function that sends notification to Growl.

    :param hotkey_manager: Hotkey manager.

    :param hotkey: Hotkey's virtual key list.

    :param hotkey_type: Hotkey type.

    :param hotkey_info: Hotkey info.

    :param event: Event object.

    :return: None.
    
Hotkey trigger function that sends notification to Growl.
Hotkey trigger function that sends notification to Growl .
def hotkey_tfunc(hotkey_manager, hotkey, hotkey_type, hotkey_info, event):
    def task_func():
        hotkey_tfunc_default(
            hotkey_manager, hotkey, hotkey_type, hotkey_info, event
        )
        global _GROWL_NOTI
        if _GROWL_NOTI is False:
            return
        if _GROWL_NOTI is None:
            try:
                import gntp.notifier
                _GROWL_NOTI = gntp.notifier.GrowlNotifier(
                    applicationName='AoikHotkey',
                    notifications=['New Messages'],
                    defaultNotifications=['New Messages'],
                )
                _GROWL_NOTI.register()
            except ImportError:
                _GROWL_NOTI = False
                msg = (
                    'Package `gntp` is not installed. Try:\n'
                    'pip install gntp\n'
                )
                sys.stderr.write(msg)
                return
            except Exception:
                _GROWL_NOTI = False
                tb_msg = format_exc()
                msg = (
                    '# Error: Failed initializing Growl notifier:\n'
                    '---\n{0}---\n'
                ).format(tb_msg)
                sys.stderr.write(msg)
                return
        assert _GROWL_NOTI
        if hotkey_type == HOTKEY_TYPE_V_DN:
            up_dn_text = ' down '
        elif hotkey_type == HOTKEY_TYPE_V_UP:
            up_dn_text = ' up '
        else:
            up_dn_text = ' '
        orig_spec = hotkey_info[HOTKEY_INFO_K_HOTKEY_ORIG_SPEC]
        title = '{hotkey_type}{up_dn_text}triggered'.format(
            hotkey_type='Hotseq'
            if hotkey_type == HOTKEY_TYPE_V_KS else 'Hotkey',
            up_dn_text=up_dn_text,
        )
        hotkey_pattern = orig_spec[0]
        description = '{hotkey_pattern}\n{hotkey_vk_names}'.format(
            hotkey_pattern=hotkey_pattern,
            hotkey_vk_names=' '.join(
                hotkey_manager.vk_to_name(x) or str(x) for x in hotkey
            ),
        )
        _GROWL_NOTI.notify(
            noteType='New Messages',
            title=title,
            description=description,
        )
    add_task(task_func)
def hotkey_tfunc ( hotkey_manager , hotkey , hotkey_type , hotkey_info , event ) : def task_func ( ) : hotkey_tfunc_default ( hotkey_manager , hotkey , hotkey_type , hotkey_info , event ) global _GROWL_NOTI if _GROWL_NOTI is False : return if _GROWL_NOTI is None : try : import gntp . notifier _GROWL_NOTI = gntp . notifier . GrowlNotifier ( applicationName = 'AoikHotkey' , notifications = [ 'New Messages' ] , defaultNotifications = [ 'New Messages' ] , ) _GROWL_NOTI . register ( ) except ImportError : _GROWL_NOTI = False msg = ( 'Package `gntp` is not installed. Try:\n' 'pip install gntp\n' ) sys . stderr . write ( msg ) return except Exception : _GROWL_NOTI = False tb_msg = format_exc ( ) msg = ( '# Error: Failed initializing Growl notifier:\n' '---\n{0}---\n' ) . format ( tb_msg ) sys . stderr . write ( msg ) return assert _GROWL_NOTI if hotkey_type == HOTKEY_TYPE_V_DN : up_dn_text = ' down ' elif hotkey_type == HOTKEY_TYPE_V_UP : up_dn_text = ' up ' else : up_dn_text = ' ' orig_spec = hotkey_info [ HOTKEY_INFO_K_HOTKEY_ORIG_SPEC ] title = '{hotkey_type}{up_dn_text}triggered' . format ( hotkey_type = 'Hotseq' if hotkey_type == HOTKEY_TYPE_V_KS else 'Hotkey' , up_dn_text = up_dn_text , ) hotkey_pattern = orig_spec [ 0 ] description = '{hotkey_pattern}\n{hotkey_vk_names}' . format ( hotkey_pattern = hotkey_pattern , hotkey_vk_names = ' ' . join ( hotkey_manager . vk_to_name ( x ) or str ( x ) for x in hotkey ) , ) _GROWL_NOTI . notify ( noteType = 'New Messages' , title = title , description = description , ) add_task ( task_func )
Hotkey trigger function that sends notification to Growl.
Hotkey trigger function that sends notification to Growl .
"""
    Hotkey trigger function that sends notification to Growl.

    :param hotkey_manager: Hotkey manager.

    :param hotkey: Hotkey's virtual key list.

    :param hotkey_type: Hotkey type.

    :param hotkey_info: Hotkey info.

    :param event: Event object.

    :return: None.
    """ # Create task function # Call default hotkey trigger function to print message to console # Use global variable # If the Growl notifier is False, # it means the initialization below failed. # Do not send message to Growl # If the Growl notifier is not False. # If the Growl notifier is None, # it means the initialization is not done yet. # Import module # Create Growl notifier # Register with Growl # If have import error # Set the Growl notifier be False # Get error message # Print error message # Do not send message to Growl # If have other error # Set the Growl notifier be False # Get traceback message # Get error message # Print error message # Do not send message to Growl # Assert the Growl notifier is not False or None # If hotkey type is key-down # Get text # If hotkey type is key-up # Get text # If hotkey type is not key-down or key-up # Get text # Get original hotkey spec # Get notification title # Get hotkey pattern # Get notification description # Create task function # Add task function to queue
None
hotkey_manager
None
hotkey
Hotkey's virtual key list.
Hotkey ' s virtual key list .
hotkey_type
None
hotkey_info
None
event
None