3 # Test various print setting combinations
4 # To run this successfully you need to make some preparations. First of all,
5 # you need to open evince and make sure that:
6 # * the printer is set to "Print to File"
7 # (I think) we are unable to select the "Print to File" line from the table
10 # i'm note sure why this is required but it seems to break i18n if it is not commented out
11 # os.environ['LANG']='C'
12 homedir = os.environ["HOME"] + "/";
14 from dogtail.procedural import *
16 import dogtail.predicate
18 #~ uncommenting the import and load below should enable you to run this on any language
19 #~ If you are testing a different language than English run the test like so:
20 #~ LANG=xx_XX.YYY ./test-print-combinations.py
23 # dogtail.i18n.loadTranslationsFromPackageMoFiles('evince')
25 #~ test setting lists: customize these to your liking, the comment above each
26 #~ displays possible AND/OR default values
28 #~ copies = [1,2,3,4,....,n] # does not need to be sequential
37 #~ pages_per_sheet = [1,2,4,6,9,16]
38 pages_per_sheet = [1,4,9]
40 #~ only_print = ["All sheets","Even sheets","Odd sheets"]
41 only_print = ["All sheets","Even sheets","Odd sheets"]
43 #~ output_type = ["pdf","ps"]
46 #~ if you prepare more test documents with different numbers of pages,
47 #~ you can add them here, the test documents must be saved as n-page.pdf
48 #~ where n stands for the number of pages
50 #~ pages_in_document = [3,4]
51 pages_in_document = [3,4]
53 # all pages in a document, an even range, an odd range
54 #~ ranges = ["all","1-3,2-3,1","1-2,2-3,1-3"]
55 ranges = ["all","1-3,2-3,1","1-2,2-3,1-3"]
58 # estimate number of iterations the test will require, this will be lower because we don't run (col == 1 && cop == 1)
59 n_tests = len(copies) * len(collate) * len(reverse) * len(pages_per_sheet) * len(only_print) * len(output_type) * len(pages_in_document) * len(ranges)
61 #~ function: build_filename
62 def build_filename( pages, cop, pps, col, rev, rng, op, ot ):
63 result = "pid_" + str(pages) + "_cop_" + str(cop) + "_pps_" + str(pps) + "_col_" + str(col) + "_rev_" + str(rev)
66 if op == "All sheets":
68 elif op == "Even sheets":
76 elif rng == "1-3,2-3,1":
84 #~ ///function: build_filename
89 def run_test( pages, cop, pps, col, rev, rng, op, ot ):
90 filename = build_filename( pages, cop, pps, col, rev, rng, op, ot )
92 #~ we don't want the "file exists" dialog to pop up:
93 #~ delete the file if it already exists, potentially dangerous if filename
94 #~ is zero so we check for nonzero length at least
95 if ( os.path.exists(homedir + filename) and (len(filename) != 0) ):
96 os.unlink(homedir + filename)
98 evince = tree.root.application('evince')
100 click('File', roleName='menu')
101 click('Print...', roleName='menu item')
103 dlg = evince.dialog('Print')
105 #~ This doesn't work, even if rewritten as in test6.py or test7.py
106 #~ click(name='Print to File', roleName='table cell', raw=True)
108 focus.widget(roleName='page tab', name='General')
109 focus.widget.node.select()
111 dlg.child( roleName='text' ).text = filename
114 click('PDF', roleName='radio button')
116 click('Postscript', roleName='radio button')
120 click('All Pages', roleName='radio button')
122 click('Pages:', roleName='radio button')
123 dlg.child('Pages', roleName='text').text = rng
126 sb_copies = dlg.child( roleName='spin button' )
127 sb_copies.text = str(cop)
128 # activate must be called to actualize the new setting
129 sb_copies.doAction("activate")
132 cb_reverse = dlg.child('Reverse', roleName='check box')
133 if (rev == 1 and cb_reverse.checked == False):
135 elif (rev == 0 and cb_reverse.checked == True):
138 cb_collate = dlg.child('Collate', roleName='check box')
139 if (col == 1 and cb_collate.checked == False):
141 elif (col == 0 and cb_collate.checked == True):
144 focus.widget(roleName='page tab', name='Page Setup')
145 focus.widget.node.select()
147 #~ Set pages per sheet:
148 #~ This will break at some point if there is more than one numeric combo box
149 #~ it will also not work for languages with other numerals
150 #~ The for loops here are necessary because the name of these combo boxes
151 #~ is based on their current value and they have no 'label' attribute
153 # Redefining this here so that changing pages_per_sheet above does not affect our search
154 local_pages_per_sheet = [1,2,4,6,9,16]
155 for x in local_pages_per_sheet:
156 pred = dogtail.predicate.GenericPredicate( name = str(x), roleName='combo box' )
157 if dlg.findChild( pred, retry=False, requireResult=False):
158 # dlg.child( str(x), roleName='combo box').combovalue = str(pps)
159 # we've found what we're looking for, no need to continue the loop
162 # Redefining this here so that changing only_print above does not affect our search
163 local_only_print = ["All sheets","Even sheets","Odd sheets"]
164 for x in local_only_print:
165 pred = dogtail.predicate.GenericPredicate( name = str(x), roleName='combo box' )
166 if dlg.findChild( pred, retry=False, requireResult=False):
167 dlg.child( str(x), roleName='combo box').combovalue = str(op)
168 # we've found what we're looking for, no need to continue the loop
171 #~ We're done setting up, start the print job
172 click('Print', roleName='push button')
173 #~ ///function: run_test
179 for ot in output_type:
180 for pages in pages_in_document:
181 # the filename which is opened depends on 'pages'
182 app = run('evince', arguments=' ' + str(pages) + "-page.pdf")
186 #no sense in testing collate with 1 copy! it is equivalent to 1 uncollated
187 if (cop == 1 and col == 1):
190 for pps in pages_per_sheet:
191 for op in only_print:
193 print str(counter) + " of " + str(n_tests)
194 run_test( pages, cop, pps, col, rev, rng, op, ot )
195 click('File',roleName='menu')
196 click('Close',roleName='menu item')
198 #~ we should be done now.