This file is indexed.

/usr/share/pyshared/pycocumalib/LetterComposer.py is in pycocuma 0.4.5-6-7.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
"""
Letter Composer for TeX-Letters
"""
#  Copyright (C) 2004  Henning Jacobs <henning@srcco.de>
#
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.
#
#  $Id: LetterComposer.py 92 2004-11-28 15:34:44Z henning $

from Tkinter import *
import Pmw
import ToolTip
import os, sys, types
from InputWidgets import TextEdit, TextComboEdit, FilenameEdit, MemoEdit
import Preferences
import ConfigParser
import __version__

PADX = PADY = 2

class Letter:
    "Encapsulates Letter-Data"
    def __init__(self):
        self._metasect = "MetaInfo"
        self._datasect = "LetterData"
        self._dict = {
            'MySignature': "",
            'MyPlace': "",
            'MyAddress': "",
            'MyBackAddress': "",
            'MyBottomText': "",
            'Date': "",
            'Address': "",
            'YourMail': "",
            'Subject': "",
            'Opening': "",
            'Body': "",
            'Closing': "",
            'Enclosing': ""
            }
        
    def getDict(self):
        return self._dict

    def setDict(self, _dict):
        self._dict = _dict
        
    def saveToFile(self, filename):
        cp = ConfigParser.SafeConfigParser()
        # Make OptionNames case-sensitive:
        cp.optionxform = str
        # Add Meta-Info:
        sec = self._metasect
        if not cp.has_section(sec):
            cp.add_section(sec)
        import time
        cp.set(sec, "Creator", "PyCoCuMa-%s" % __version__.__version__)
        cp.set(sec, "CreationDate", time.strftime('%Y%m%dT%H%M%S'))
        # Add Data section:
        sec = self._datasect
        if not cp.has_section(sec):
            cp.add_section(sec)
        for key, val in zip(self._dict.keys(), self._dict.values()):
            cp.set(sec, key, val.encode('utf-8', 'replace'))
        cp.write(open(filename, 'wb'))
        
    def loadFromFile(self, filename):
        cp = ConfigParser.SafeConfigParser()
        # Make OptionNames case-sensitive:
        cp.optionxform = str
        cp.read([filename])
        for opt in cp.options(self._datasect):
            self._dict[opt] = unicode(cp.get(self._datasect, opt), 'utf-8', 'replace')
    

class LetterComposer(Pmw.MegaToplevel):
    def __init__(self, master):
        Pmw.MegaToplevel.__init__(self, master=master, title='Compose Letter')
        self.userdeletefunc(self.withdraw)
        self.master = master    
        self.letter = Letter()
        self.createWidgets()
        self.fillDefaultValues()
        self.withdraw()

    def fillDefaultValues(self):
        "Get initial values from Preferences"
        myaddress = Preferences.get('lettercomposer.myaddress')
        self.edtMyAddress.clear()
        if myaddress: self.edtMyAddress.set(myaddress)
        templatefname = Preferences.get('lettercomposer.template_filename')
        if not templatefname: templatefname = os.path.dirname(sys.argv[0])+'/templates/DinBrief.tex'
        self.edtTemplateFilename.set(templatefname)
        self.edtSubject.clear()
        opening = Preferences.get('lettercomposer.opening', types.ListType)
        if opening is not None: 
            self.edtOpening.setlist(opening)
            if len(opening)>0:
                self.edtOpening.set(opening[0])
        self.edtBody.clear()
        closing = Preferences.get('lettercomposer.closing', types.ListType)
        if closing is not None: 
            self.edtClosing.setlist(closing)
            if len(closing)>0:
                self.edtClosing.set(closing[0])
        # Now fill the combobox lists:
        import time
        self.edtDate.setlist([
            time.strftime('%d. %B %Y'),
            time.strftime('%x'),
            time.strftime('%Y-%m-%d')])
        
    def createWidgets(self):
        hull = self.component('hull')
        hull.rowconfigure(0, weight=1)
        hull.columnconfigure(0, weight=1)
        top = Frame(hull, borderwidth=1, relief=RAISED)
        top.grid(sticky=W+E+S+N)
        sidepanel = Frame(hull, borderwidth=1, relief=RAISED)
        sidepanel.grid(row=0, column=1, sticky=N+S)
        self.edtTemplateFilename = FilenameEdit(sidepanel, showbasenameonly=True,
            filetypes=[('LaTeX Templates','*.tex'),('All Files','*')])
        self.edtTemplateFilename.grid(sticky=W+E, padx=PADX, pady=PADY)
        self.edtTeXFilename = FilenameEdit(sidepanel, type='saveas',
            filetypes=[('LaTeX Files','*.tex'),('All Files','*')])
        ToolTip.ToolTip(self.edtTeXFilename, 'TeX Filename to save to')
        self.edtTeXFilename.grid(sticky=W+E, padx=PADX, pady=PADY)    
        btn = Button(sidepanel, text='Save Letter', command=self.saveLetterToFile)
        btn.grid(sticky=W+E, padx=PADX, pady=PADY)
        btn = Button(sidepanel, text='Load Letter', command=self.loadLetterFromFile)
        btn.grid(sticky=W+E, padx=PADX, pady=PADY)
        btn = Button(sidepanel, text='Save TeX', command=self.saveTeXToFile)
        btn.grid(sticky=W+E, padx=PADX, pady=PADY)
        btn = Button(sidepanel, text='Preview PDF', command=self.previewPdfFile)
        btn.grid(sticky=W+E, padx=PADX, pady=PADY)
        btn = Button(sidepanel, text='Close', command=self.close)
        btn.grid(sticky=W+E, padx=PADX, pady=PADY)
        self.use_signature = IntVar()
        self.use_signature.set(1)
        chk = Checkbutton(sidepanel, text='Use Signature',
            variable=self.use_signature)
        chk.grid(sticky=W+E, padx=PADX, pady=PADY)
        top.columnconfigure(0, weight=1)
        # Expand Body:
        top.rowconfigure(4, weight=1)
        self.edtAddress = MemoEdit(top, labelpos=N, label_text='Address to:')
        ToolTip.ToolTip(self.edtAddress, "recipient's address: exactly four lines are used")
        self.edtAddress.grid(sticky=W+E+S+N, padx=PADX, pady=PADY)
        self.edtMyAddress = MemoEdit(top, labelpos=N, label_text='My Address:')
        ToolTip.ToolTip(self.edtMyAddress, "sender's address: first line is also signature\n"+
            'first three lines are used as backaddress\n'+
            'you can specify as many lines as you need (e.g. for phone, email)')
        self.edtMyAddress.set(' ')
        self.edtMyAddress.tag_add('default', '0.0', END)
        self.edtMyAddress.tag_config('default', justify=RIGHT)
        self.edtMyAddress.grid(row=0, column=1, sticky=W+E+S+N, padx=PADX, pady=PADY)
        self.edtYourMail = TextEdit(top, labelpos=W, label_text='Your Mail:')
        ToolTip.ToolTip(self.edtYourMail, "refer to recipient's mail (usually by date)")
        self.edtYourMail.grid(sticky=W+E, padx=PADX, pady=PADY)
        self.edtDate = TextComboEdit(top, labelpos=W, label_text='Date:')
        ToolTip.ToolTip(self.edtDate, "leave empty to use today's date")
        self.edtDate.grid(row=1, column=1, sticky=W+E, padx=PADX, pady=PADY)
        self.edtSubject = TextEdit(top, labelpos=W, label_text='Subject:')
        self.edtSubject.grid(columnspan=2, sticky=W+E, padx=PADX, pady=PADY)
        self.edtOpening = TextComboEdit(top, labelpos=W, label_text='Opening:')
        self.edtOpening.grid(columnspan=2, sticky=W+E, padx=PADX, pady=PADY)
        self.edtBody = MemoEdit(top, text_height=8, file_extension='.tex')
        ToolTip.ToolTip(self.edtBody, 'text body: you can use LaTeX commands here\n' +
            '(Press CTRL-E to open external editor)')
        self.edtBody.grid(columnspan=2, sticky=W+E+S+N, padx=PADX, pady=PADY)
        self.edtClosing = TextComboEdit(top, labelpos=W, label_text='Closing:')
        self.edtClosing.grid(columnspan=2, sticky=W+E, padx=PADX, pady=PADY)
        self.edtEnclosing = TextEdit(top, labelpos=W, label_text='Enclosing:')
        ToolTip.ToolTip(self.edtEnclosing, 'list of attachments, separate by LaTeX linebreak (\\\\)')
        self.edtEnclosing.grid(columnspan=2, sticky=W+E, padx=PADX, pady=PADY)

    def createLetterFromWidgets(self):
        address_lines = self.edtAddress.get().splitlines()
        # We want exactly four lines:
        for i in range(4-len(address_lines)):
            address_lines.append('')
        myaddress_lines = self.edtMyAddress.get().splitlines()
        if self.use_signature.get() and len(myaddress_lines)>0:
            signature = myaddress_lines[0]
        else: signature = ''    
        letterdict = {
            'MySignature':signature,
            'MyPlace':'',
            'MyAddress':"\n".join(myaddress_lines),
            'MyBackAddress':"\n".join(myaddress_lines[:3]),
            'MyBottomText':'',
            'Date':self.edtDate.get(),
            'Address':"\n".join(address_lines),
            'YourMail':self.edtYourMail.get(),
            'Subject':self.edtSubject.get(),
            'Opening':self.edtOpening.get(),
            'Body':self.edtBody.get(),
            'Closing':self.edtClosing.get(),
            'Enclosing':self.edtEnclosing.get()
            }
        self.letter.setDict(letterdict)

    def saveLetterToFile(self):
        self.createLetterFromWidgets()
        import tkFileDialog
        dlg = tkFileDialog.SaveAs(self.master, filetypes=[("PyCoCuMa Letter Files", "*.letter")])
        letter_dir = Preferences.get('lettercomposer.letter_dir')
        letter_fname, file_ext = os.path.splitext(os.path.basename(self.edtTeXFilename.get()))
        letter_fname += '.letter'
        fname = dlg.show(initialdir=letter_dir, initialfile=letter_fname)
        if fname:
            self.letter.saveToFile(fname)

    def loadLetterFromFile(self):
        import tkFileDialog
        dlg = tkFileDialog.Open(self.master, filetypes=[("PyCoCuMa Letter Files", "*.letter"),
            ("All Files", "*")])
        letter_dir = Preferences.get('lettercomposer.letter_dir')
        fname = dlg.show(initialdir=letter_dir)
        if fname:
            self.letter.loadFromFile(fname)
            d = self.letter.getDict()
            self.edtMyAddress.set(d["MyAddress"])
            self.edtDate.set(d["Date"])
            self.edtAddress.set(d["Address"])
            self.edtYourMail.set(d["YourMail"])
            self.edtSubject.set(d["Subject"])
            self.edtOpening.set(d["Opening"])
            self.edtBody.set(d["Body"])
            self.edtClosing.set(d["Closing"])
            self.edtEnclosing.set(d["Enclosing"])
    
    def saveTeXToFile(self):
        self.createLetterFromWidgets()
        def enclatin1(str):
            return str.encode('latin-1', 'replace')
        from TemplateProcessor import TemplateProcessor
        proc = TemplateProcessor(postproc=enclatin1)
        outfile = file(self.edtTeXFilename.get(), 'wb')
        d = self.letter.getDict().copy()
        d["MyAddress"] = d["MyAddress"].splitlines()
        d["MyBackAddress"] = d["MyBackAddress"].splitlines()
        d["Address"] = d["Address"].splitlines()
        proc.process(file(self.edtTemplateFilename.get()).readlines(),
            outfile.write, d)
        outfile.close()    
        self.savePreferences()

    def savePreferences(self):    
        Preferences.set('lettercomposer.myaddress', self.edtMyAddress.get())
        opening = self.edtOpening.get()
        openings = list(self.edtOpening.getlist())
        if opening and not opening in openings: openings.insert(0, opening)
        Preferences.set('lettercomposer.opening', openings[:10])
        closing = self.edtClosing.get()
        closings = list(self.edtClosing.getlist())
        if closing and not closing in closings: closings.insert(0, closing)
        Preferences.set('lettercomposer.closing', closings[:10])
        Preferences.set('lettercomposer.template_filename', self.edtTemplateFilename.get())
        Preferences.set('lettercomposer.letter_dir', os.path.dirname(self.edtTeXFilename.get()))
        
    def previewPdfFile(self):
        import texwrapper
        texfilename = self.edtTeXFilename.get()
        if not os.access(texfilename, os.F_OK):
            import tkMessageBox
            tkMessageBox.showerror("Error", "File not found: '%s'\n You must save the TeX-file first!" % texfilename)
            return
        texwrapper.run_pdflatex(texfilename)
        texwrapper.view_pdf(texfilename)

    def close(self):
        self.withdraw()

    def composeTo(self, addressee, adr):
        self.fillDefaultValues()
        adrstreet = adr.street.get()
        adrcity = '%s %s' % (adr.postcode.get(), adr.city.get())
        address = '\n%s\n%s\n%s' % (addressee.fn.get(), adrstreet, adrcity)
        self.edtAddress.clear()
        self.edtAddress.set(address)
        texfname = addressee.uid.get()
        if not texfname: texfname = addressee.fn.get().replace(' ', '_')
        texdir = Preferences.get('lettercomposer.letter_dir')
        if not texdir: texdir = os.path.dirname(sys.argv[0])
        import time
        texfname = '%s/%s-%s.tex' % (texdir, texfname, time.strftime('%Y%m%d'))
        self.edtTeXFilename.set(texfname)
        self.show()

    _firstshow = 1
    def show(self):
        if self._firstshow:
            self.centerWindow()
        else:
            self.deiconify()
        self.lift()    
        self._firstshow = 0
            
    def centerWindow(self, relx=0.5, rely=0.3):
        "Center the Window on Screen"
        widget = self
        master = self.master
        widget.update_idletasks() # Actualize geometry information
        if master.winfo_ismapped():
            m_width = master.winfo_width()
            m_height = master.winfo_height()
            m_x = master.winfo_rootx()
            m_y = master.winfo_rooty()
        else:
            m_width = master.winfo_screenwidth()
            m_height = master.winfo_screenheight()
            m_x = m_y = 0
        w_width = widget.winfo_reqwidth()
        w_height = widget.winfo_reqheight()
        x = m_x + (m_width - w_width) * relx
        y = m_y + (m_height - w_height) * rely
        if x+w_width > master.winfo_screenwidth():
            x = master.winfo_screenwidth() - w_width
        elif x < 0:
            x = 0
        if y+w_height > master.winfo_screenheight():
            y = master.winfo_screenheight() - w_height
        elif y < 0:
            y = 0
        widget.geometry("+%d+%d" % (x, y))
        widget.deiconify() # Become visible at the desired location



if __name__ == "__main__":
    import vcard
    import testvcard
    tk = Tk()
    dlg = LetterComposer(tk)
    card = vcard.vCard()
    testvcard.fillDemoCard(card)
    dlg.composeTo(card, card.adr[0])
    tk.mainloop()