Package Pyblio :: Package Format :: Module OpenOffice
[hide private]
[frames] | no frames]

Source Code for Module Pyblio.Format.OpenOffice

 1  # This file is part of pybliographer 
 2  #  
 3  # Copyright (C) 1998-2006 Frederic GOBRY 
 4  # Email : gobry@pybliographer.org 
 5  #           
 6  # This program is free software; you can redistribute it and/or 
 7  # modify it under the terms of the GNU General Public License 
 8  # as published by the Free Software Foundation; either version 2  
 9  # of the License, or (at your option) any later version. 
10  #    
11  # This program is distributed in the hope that it will be useful, 
12  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
13  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
14  # GNU General Public License for more details.  
15  #  
16  # You should have received a copy of the GNU General Public License 
17  # along with this program; if not, write to the Free Software 
18  # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. 
19  # 
20   
21  from Pyblio.Format.Generator import Generator as Base 
22   
23  import uno 
24   
25  _gc = uno.getConstantByName 
26   
27  ITALIC = (_gc("com.sun.star.awt.FontSlant.ITALIC"), 
28            _gc("com.sun.star.awt.FontSlant.NONE")) 
29   
30  BOLD = (_gc("com.sun.star.awt.FontWeight.BOLD"), 
31          _gc("com.sun.star.awt.FontWeight.NORMAL")) 
32   
33   
34 -class Generator(Base):
35 """ Returns an object capable of transforming an abstract 36 representation of text into actual text in OpenOffice.""" 37
38 - def __init__(self, text, cursor):
39 self.t = text 40 self.c = cursor 41 self.first = False 42 return
43
44 - def do_string(self, t):
45 self.t.insertString(self.c, t, False)
46
47 - def do_i(self, t):
48 self.c.CharPosture = ITALIC[0] 49 for s in t.children: self(s) 50 self.c.CharPosture = ITALIC[1]
51
52 - def do_b(self, t):
53 self.c.CharWeight = BOLD[0] 54 for s in t.children: self(s) 55 self.c.CharWeight = BOLD[1]
56
57 - def do_br(self, t):
58 self.t.insertString(self.c, u'\x0a', False)
59
60 - def begin_biblio(self):
61 self.first = True
62
63 - def begin_reference(self, key):
64 if self.first: 65 self.first = False 66 else: 67 self.t.insertString(self.c, u'\x0d', False) 68 self.t.insertString(self.c, u'[%s]\xa0' % key, False)
69