View Full Version : PyGtk: Skip print dialog

October 12th, 2009, 11:52 PM
Scenario: I've written a bash script that logs into the NY times website and pulls down the daily puzzle. Once I've got the puzzle, I'd like to be able to print it without any user input. I've looked at the code from XWord, and I'm able to essentially borrow that code to print it, but I'm unable to skip the print dialog box.

Below is the relevant code from xword.

def do_print(self, dialog, res, job):
config = job.get_config()

if res == gnomeprint.ui.DIALOG_RESPONSE_CANCEL:
elif res == gnomeprint.ui.DIALOG_RESPONSE_PREVIEW:
self.do_preview(config, dialog)
elif res == gnomeprint.ui.DIALOG_RESPONSE_PRINT:
self.gpc = job.get_context()

def print_puzzle(self, win):
job = gnomeprint.Job(gnomeprint.config_default())
dialog = gnomeprint.ui.Dialog(job, "Print...", 0)
dialog.connect('response', self.do_print, job)

def print_puzzle_now(self, win):
job = gnomeprint.Job(gnomeprint.config_default())

I added in print_puzzle_now() so as not to disturb the other functionality.

Calling print_() brings up the print dialog box, and based on the pyGTK reference for gnomeprint (http://www.pygtk.org/pygnomeprint/class-gnomeprintjob.html), it's not clear to me how to avoid the dialog box.

Anyone know how to accomplish this?

October 12th, 2009, 11:57 PM
In a shell script you can use the lp command to print.

October 13th, 2009, 12:00 AM
In a shell script you can use the lp command to print.
That'd be all well and good if the file I was trying to print was text, and not binary. I need the functionality of xword to properly parse and layout the file before printing. Sorry for not making that clear.

January 29th, 2010, 09:53 PM
Did you ever figure this out?

January 29th, 2010, 10:48 PM
Did you ever figure this out?

Maybe use the "lp" command?

April 17th, 2010, 10:53 PM
In case anyone finds this thread via google (like me):
I find that in this case the command

lpr <document to print>
works nicely for me