This is a read-only mirror of pymolwiki.org

Difference between revisions of "Check Key"

From PyMOL Wiki
Jump to navigation Jump to search
(Created page with '===DESCRIPTION=== A simple script used to check if a given key is valid for for the set_key command. This is useful when the user would like to use a keyboard key as short…')
 
m (7 revisions)
 
(6 intermediate revisions by one other user not shown)
Line 1: Line 1:
 +
{{Infobox script-repo
 +
|type      = script
 +
|filename  = check_key.py
 +
|author    = [[User:Slaw|Sean M. Law]]
 +
|license  = -
 +
}}
 +
 
===DESCRIPTION===  
 
===DESCRIPTION===  
  
A simple script used to check if a given key is valid for for the [[set_key]] command.  This is useful when the user would like to use a keyboard key as shortcut/hotkey in their script but need to check if the key is a valid one.
+
A simple script used to check if a given key is valid for for the [[Set Key]] command.  This is useful when the user would like to use a keyboard key as shortcut/hotkey in their script but need to check if the key is a valid one.
  
 
===USAGE===
 
===USAGE===
Line 11: Line 18:
 
</source>
 
</source>
  
If the key specified is a valid one as defined in [[set_key]] then it returns the value of the keystroke.  Otherwise, it returns None.
+
If the key specified is a valid one as defined in [[Set Key]] then it returns the value of the keystroke.  Otherwise, it returns None.
  
For an example that calls this script, see [[jump]].
+
For an example that calls this script, see [[Jump]].
  
 
===PyMOL API===
 
===PyMOL API===
Line 24: Line 31:
  
 
def check_key (keystroke):
 
def check_key (keystroke):
 +
 +
    """
 +
    Author Sean M. Law
 +
    University of Michigan
 +
    seanlaw_(at)_umich_dot_edu
 +
    """
 +
 
     keystroke=keystroke.strip('\"\'')
 
     keystroke=keystroke.strip('\"\'')
 
     out=allowed_keys.search(keystroke)
 
     out=allowed_keys.search(keystroke)
Line 40: Line 54:
 
===SEE ALSO===
 
===SEE ALSO===
 
[[Button]] [[Set Key]]
 
[[Button]] [[Set Key]]
 +
 +
[[Category:Script_Library]]

Latest revision as of 01:49, 28 March 2014

Type Python Script
Download check_key.py
Author(s) Sean M. Law
License -
This code has been put under version control in the project Pymol-script-repo

DESCRIPTION

A simple script used to check if a given key is valid for for the Set Key command. This is useful when the user would like to use a keyboard key as shortcut/hotkey in their script but need to check if the key is a valid one.

USAGE

load the script using the run command

check_key (keystroke)

If the key specified is a valid one as defined in Set Key then it returns the value of the keystroke. Otherwise, it returns None.

For an example that calls this script, see Jump.

PyMOL API

from pymol import cmd
import re

allowed_keys=re.compile('(F1|F2|left|right|pgup|pgdn|home|insert|(CTRL-[A-Z])|ALT-[A-Z0-9])')

def check_key (keystroke):

    """
    Author Sean M. Law
    University of Michigan
    seanlaw_(at)_umich_dot_edu
    """

    keystroke=keystroke.strip('\"\'')
    out=allowed_keys.search(keystroke)

    if (out != None):
        return keystroke         
    else:
        print "Error: Invalid key \""+keystroke+"\""
        print "Valid Keys: F1, F2, left, right, pdup, pgdn, home, insert"
        print "            CTRL-A to CTRL-Z"
        print "            ALT-0 to ALT-9, ALT-A to ALT-Z"
        return
cmd.extend("check_key", check_key)

SEE ALSO

Button Set Key