~vorlon/ubuntu/saucy/gourmet/trunk

« back to all changes in this revision

Viewing changes to src/lib/exporters/winprinter.py

  • Committer: Bazaar Package Importer
  • Author(s): Jamie Strandboge
  • Date: 2009-12-29 09:12:49 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20091229091249-n45z95fou0yr2t1t
Tags: 0.15.2-0ubuntu1
* New upstream release (LP: #431806, Closes: #530841). Also fixes the
  following bugs:
  - LP: #315836
  - LP: #295982
  - LP: #316445 (the GUI has been changed so this no longer applies)
* Drop forcing of python2.5
* debian/control: Recommends python-gnome2-extras for printing
* drop debian/patches/05-add_manpage.patch, which is now included upstream
* Fix some lintian warnings:
  - add debian/README.source
  - debian/control: bump Standards-Version to 3.8.3
  - debian/compat: bump to 5
* debian/control: Depends on python-poppler (needed for printing)
* debian/patches/01_fix_raise_str.patch: don't raise str exception
  in src/lib/plugin_gui.py
* debian/patches/02_fix_nutrition_index_out_of_range.patch: don't
  add entries beyond the width of the field in databaseGrabber.py
* debian/patches/03_dont_remove_nonexistent_plugin.patch: don't
  remove an inactive plugin in plugin_loader.py and don't deactivate
  a plugin from a non-existent database

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
import tempfile, gtk
2
 
from pdf_exporter import PdfWriter, PdfExporterMultiDoc, get_pdf_prefs
3
 
 
4
 
from gettext import gettext as _
5
 
from gettext import ngettext
6
 
import gourmet.gtk_extras.dialog_extras as de
7
 
import gourmet.gglobals as gglobals
8
 
from gourmet.convert import FRACTIONS_NORMAL
9
 
import exporter
10
 
 
11
 
import win32api
12
 
 
13
 
 
14
 
def print_file_with_windows (filename):
15
 
    # Method from:
16
 
    # http://tgolden.sc.sabren.com/python/win32_how_do_i/print.html#shellexecute
17
 
    if de.getBoolean(label=_('Print'),
18
 
                  sublabel=_('Ready to print your recipe through the PDF file %s. Unfortunately, we have no print preview - shall we go ahead and print?')%filename):
19
 
        win32api.ShellExecute(
20
 
            0,
21
 
            "print",
22
 
            filename,
23
 
            None,
24
 
            ".",
25
 
            0
26
 
            )
27
 
        d = de.MessageDialog(label=_('Print job sent'),
28
 
                       sublabel=_("Print job has been sent. If something goes wrong, you can open the PDF file and try printing again."))
29
 
    else:
30
 
        d = de.MessageDialog(label=_('Print job cancelled'),
31
 
                       sublabel=_("If you'd like, you can open the PDF file.")
32
 
                              )
33
 
    b = gtk.Button(stock=gtk.STOCK_JUMP_TO)
34
 
    b.connect('clicked',lambda *args: gglobals.launch_url(filename))
35
 
    d.vbox.pack_end(b,expand=False); b.show()
36
 
    d.run()
37
 
        
38
 
 
39
 
class RecRenderer:
40
 
    def __init__ (self, rd, recs, mult=1, dialog_title=_("Print Recipes"),
41
 
                  dialog_parent=None, **kwargs):
42
 
        filename = tempfile.mktemp('.pdf')
43
 
        pdf_args = get_pdf_prefs()
44
 
        kwargs['pdf_args']=pdf_args
45
 
        e = PdfExporterMultiDoc(rd,recs,filename, **kwargs)
46
 
        e.run()
47
 
        print_file_with_windows(filename)
48
 
        #show_disappointing_message()
49
 
        #debug('printing not supported; showed dialog',0)
50
 
 
51
 
class SimpleWriter (PdfWriter):
52
 
 
53
 
    def __init__ (self, file=None, dialog_parent=None, show_dialog=True):
54
 
        self.filename = tempfile.mktemp('.pdf')
55
 
        self.outfile = open(self.filename,'wb')
56
 
        #PdfWriter.__init__(self)
57
 
        self.setup_document(self.outfile,
58
 
                            **get_pdf_prefs({
59
 
                'page_layout':(ngettext('%s Column','%s Columns',2)%2),
60
 
                })
61
 
                            )
62
 
                            
63
 
    def close (self):
64
 
        PdfWriter.close(self)
65
 
        self.outfile.close()
66
 
        print_file_with_windows(self.filename)
67
 
    
68
 
if __name__ == '__main__':
69
 
    sw = SimpleWriter()
70
 
    sw.write_header("This is a big heading")
71
 
    sw.write_paragraph("""This is a paragraph.
72
 
This is perhaps a silly sort of paragraph to write, but I'm in the mood for silly paragraphs.
73
 
In fact, I'm in the mood for extraordinarily silly paragraphs. Paragraphs so silly they go on and on and on and on and (not being tired continuing) on and so forth until (by now the reader tiring) they take a sudden left turn, careening around the bend (passing colorless, sleeping, furious green ideas), plummetting downward (toward what or whom I don't know, whether or not there is a netherworld being among the many things, such as the existence of fairies, which escape my knowledge), falling fast and furious until hitting that final (cliched) rock bottom and returning upward.
74
 
This is my final paragraph.""")
75
 
    sw.write_subheader("Foo")
76
 
    sw.write_paragraph("This is the section named foo.  "*12)
77
 
    sw.write_subheader("Final Section")
78
 
    sw.write_paragraph("And this is the final section." * 3)
79
 
    sw.close()