~ubuntu-branches/ubuntu/utopic/dogtail/utopic

« back to all changes in this revision

Viewing changes to examples/no-help-at-all.py

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Holbach
  • Date: 2006-12-21 13:33:47 UTC
  • mfrom: (1.2.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 5.
  • Revision ID: james.westby@ubuntu.com-20061221133347-xo9jg11afp5plcka
Tags: upstream-0.6.1
ImportĀ upstreamĀ versionĀ 0.6.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
"""
3
3
Dogtail script for generating unhelpful help file.
4
4
 
5
 
Scours the UI of a program, and generates a parody of a help file for that 
 
5
Scours the UI of a program, and generates a parody of a help file for that
6
6
program.
7
7
 
8
8
The resulting DocBook file is simply a reading back of the program's UI to you.
9
9
 
10
 
The idea is to highlight a gripe of mine (and many other people): 
 
10
The idea is to highlight a gripe of mine (and many other people):
11
11
documentation should be more than this!
12
12
 
13
13
This script is licensed under the GPL.
15
15
__author__ = 'David Malcolm <dmalcolm@redhat.com>'
16
16
 
17
17
from dogtail.tree import *
 
18
from dogtail.utils import *
18
19
import sys
19
20
 
20
21
def writePCDataElement(name, content):
21
 
        print '\t\t<%s>%s</%s>'%(name, content, name) # FIXME: escape the content
22
 
        
 
22
    print '\t\t<%s>%s</%s>'%(name, content, name) # FIXME: escape the content
 
23
 
23
24
 
24
25
def generateUnhelpfulHelp(appName):
25
 
        app = root.application(appName)
26
 
        print '<?xml version="1.0"?>'
27
 
        print '<!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN" "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd">'
28
 
        print '<article>'
29
 
 
30
 
        taggedAppName = '<application>%s</application>'%appName
31
 
 
32
 
        # Artile info:
33
 
        print '\t<articleinfo>'
34
 
        writePCDataElement("title", "The Totally Definitive No-Nonsense Unhelpful Complete Guide to %s for Mannequins in 40 Days - Unleashed!"%taggedAppName)
35
 
        print '\t</articleinfo>'
36
 
 
37
 
        # Guts of the article:
38
 
        print '\t<sect1>'
39
 
        writePCDataElement("title", "Introduction")
40
 
        writePCDataElement("caution", "<para>Do not take these instructions seriously.  They are a parody of unhelpful help files found on many computer systems, and were autogenerated by <application>no-help-at-all</application></para>")
41
 
        writePCDataElement("para", "You can start %s by opening a terminal and typing the <command>%s</command> command."%(taggedAppName, appName))
42
 
        print '\t</sect1>'
43
 
 
44
 
        menus = app.findChildren(predicate.GenericPredicate(roleName="menu"))
45
 
        for menu in menus:
46
 
                print '\t<sect1>'
47
 
                writePCDataElement("title", "The <guimenu>%s</guimenu> menu"%menu.name)
48
 
                writePCDataElement("para", "Use the <guimenu>%s</guimenu> menu to work with %ss"%(menu.name, menu.name.lower()))
49
 
                items = menu.findChildren(predicate.GenericPredicate(roleName="menu item"), recursive=False)
50
 
                if items!=None:
51
 
                        for item in items:
52
 
                                verb = item.name
53
 
                                noun = menu.name
54
 
                                print '\t\t<sect2>'
55
 
                                writePCDataElement("title", "%sing a %s"%(verb.title(), noun.lower()))
56
 
                                writePCDataElement("para", "To %s a %s, choose <guimenu>%s</guimenu> &gt; <guimenuitem>%s</guimenuitem>"%(verb.lower(), noun.lower(), menu.name, item.name))
57
 
                                print '\t\t</sect2>'
58
 
                print '\t</sect1>'
59
 
 
60
 
        print '</article>'
 
26
    try:
 
27
        app = root.application(appName)
 
28
    except SearchError:
 
29
        run(appName)
 
30
    print '<?xml version="1.0"?>'
 
31
    print '<!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN" "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd">'
 
32
    print '<article>'
 
33
 
 
34
    taggedAppName = '<application>%s</application>'%appName
 
35
 
 
36
    # Artile info:
 
37
    print '\t<articleinfo>'
 
38
    writePCDataElement("title", "The Totally Definitive No-Nonsense Unhelpful Complete Guide to %s for Mannequins in 40 Days - Unleashed!"%taggedAppName)
 
39
    print '\t</articleinfo>'
 
40
 
 
41
    # Guts of the article:
 
42
    print '\t<sect1>'
 
43
    writePCDataElement("title", "Introduction")
 
44
    writePCDataElement("caution", "<para>Do not take these instructions seriously.  They are a parody of unhelpful help files found on many computer systems, and were autogenerated by <application>no-help-at-all</application></para>")
 
45
    writePCDataElement("para", "You can start %s by opening a terminal and typing the <command>%s</command> command."%(taggedAppName, appName))
 
46
    print '\t</sect1>'
 
47
 
 
48
    menus = app.findChildren(predicate.GenericPredicate(roleName="menu"))
 
49
    for menu in menus:
 
50
        print '\t<sect1>'
 
51
        writePCDataElement("title", "The <guimenu>%s</guimenu> menu"%menu.name)
 
52
        writePCDataElement("para", "Use the <guimenu>%s</guimenu> menu to work with %ss"%(menu.name, menu.name.lower()))
 
53
        items = menu.findChildren(predicate.GenericPredicate(roleName="menu item"), recursive=False)
 
54
        if items!=None:
 
55
            for item in items:
 
56
                verb = item.name
 
57
                noun = menu.name
 
58
                print '\t\t<sect2>'
 
59
                writePCDataElement("title", "%sing a %s"%(verb.title(), noun.lower()))
 
60
                writePCDataElement("para", "To %s a %s, choose <guimenu>%s</guimenu> &gt; <guimenuitem>%s</guimenuitem>"%(verb.lower(), noun.lower(), menu.name, item.name))
 
61
                print '\t\t</sect2>'
 
62
        print '\t</sect1>'
 
63
 
 
64
    print '</article>'
61
65
 
62
66
if __name__=='__main__':
63
 
        generateUnhelpfulHelp(sys.argv[1])
64
 
        
 
67
    try:
 
68
        generateUnhelpfulHelp(sys.argv[1])
 
69
    except IndexError:
 
70
        print "####################################"
 
71
        print "please supply an application name on the cmdline"
 
72
        print "####################################"