Skip to content

Commit 01ea042

Browse files
author
gsherman
committed
Added a Python script for generating unique context ids for creating context sensitive help.
The script requires Python 2.5. See comments at the head of the script for more information. git-svn-id: http://svn.osgeo.org/qgis/trunk@12156 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent e3b5681 commit 01ea042

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

scripts/context_help_id.py

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/usr/bin/python
2+
"""
3+
/***************************************************************************
4+
contxt_help_id.py
5+
-------------------
6+
begin : 2009-11-16
7+
copyright : (C) 2009 by Gary E.Sherman
8+
email : gsherman at mrcc.com
9+
***************************************************************************/
10+
11+
/***************************************************************************
12+
* *
13+
* This program is free software; you can redistribute it and/or modify *
14+
* it under the terms of the GNU General Public License as published by *
15+
* the Free Software Foundation; either version 2 of the License, or *
16+
* (at your option) any later version. *
17+
* *
18+
***************************************************************************/
19+
20+
This script generates a unique context id based for use in the QGIS
21+
context sensitive help system. It uses the SHA1 hash for the class name
22+
and converts the first 12 characters to a unique integer.
23+
24+
To create a context id, pass the name of the QGIS class on the command line.
25+
Example:
26+
./context_help_id.py QgsAbout
27+
28+
This script requires Python 2.5 or higher (hashlib was introduced at 2.5).
29+
30+
NOTE: Due to a change in the way context ids are generated, ids
31+
generated by the old method (Java hashCode function) will be different than
32+
the id generated by the new method for the same class.
33+
"""
34+
import hashlib
35+
import sys
36+
# check to see if a class name was specified and if so, craete the context id
37+
if len(sys.argv) > 1:
38+
hash = hashlib.sha1()
39+
# set the hash to the name passed on the command line
40+
hash.update(sys.argv[1])
41+
# generate the context id by converting the first 12 characters of the hash
42+
# to decimal
43+
context_id = int(hash.hexdigest()[:12],16)
44+
# print the result
45+
print context_id
46+
else:
47+
# if no class name was specified, give a bit of help
48+
print "To generate a context sensitive help id, specify the QGIS class name on the command line"

0 commit comments

Comments
 (0)