<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def genkey(key_name=None):
 """Creates a new standard GPG key Parameters ui: Bool \tIf True, then a new key is created when required without user interaction """


    if gnupg is None:
        return

    gpg_key_param_list = [
        ('key_type', 'DSA'),
        ('key_length', '2048'),
        ('subkey_type', 'ELG-E'),
        ('subkey_length', '2048'),
        ('expire_date', '0'),
    ]

    gpg = gnupg.GPG()

    gpg.encoding = 'utf-8'

    # Check if standard key is already present

    pyspread_key_fingerprint = config["gpg_key_fingerprint"]
    gpg_private_keys = [key for key in gpg.list_keys(secret=True)
                        if has_no_password(key["keyid"])]
    gpg_private_fingerprints = \
        [key['fingerprint'] for key in gpg.list_keys(secret=True)
         if has_no_password(key["keyid"])]

    pyspread_key = None

    for private_key, fingerprint in zip(gpg_private_keys,
                                        gpg_private_fingerprints):
        if str(pyspread_key_fingerprint) == fingerprint:
            pyspread_key = private_key

    if gpg_private_keys:
        # If GPG are available, choose one
        pyspread_key = choose_key(gpg_private_keys)

    if pyspread_key:
        # A key has been chosen
        config["gpg_key_fingerprint"] = repr(pyspread_key['fingerprint'])

    else:
        # No key has been chosen --> Create new one
        if key_name is None:
            gpg_key_parameters = get_key_params_from_user(gpg_key_param_list)
            if gpg_key_parameters is None:
                # No name entered
                return
        else:
            gpg_key_param_list.append(
                ('name_real', '{key_name}'.format(key_name=key_name)))
            gpg_key_parameters = dict(gpg_key_param_list)

        input_data = gpg.gen_key_input(**gpg_key_parameters)

        # Generate key
        # ------------

        if key_name is None:
            # Show information dialog

            style = wx.ICON_INFORMATION | wx.DIALOG_NO_PARENT | wx.OK | \
                wx.CANCEL
            pyspread_key_uid = gpg_key_parameters["name_real"]
            short_message = _("New GPG key").format(pyspread_key_uid)
            message = _("After confirming this dialog, a new GPG key ") + \
                _("'{key}' will be generated.").format(key=pyspread_key_uid) +\
                _(" \n \nThis may take some time.\nPlease wait.")
            dlg = wx.MessageDialog(None, message, short_message, style)
            dlg.Centre()

            if dlg.ShowModal() == wx.ID_OK:
                dlg.Destroy()
                gpg_key = gpg.gen_key(input_data)
                _register_key(gpg_key, gpg)
                fingerprint = gpg_key.fingerprint
            else:
                dlg.Destroy()
                return

        else:
            gpg_key = gpg.gen_key(input_data)
            _register_key(gpg_key, gpg)
            fingerprint = gpg_key.fingerprint

    return fingerprint