]> git.lyx.org Git - lyx.git/blob - lib/lyx2lyx/lyxconvert_228.py
add bibtopic support (bug 870).
[lyx.git] / lib / lyx2lyx / lyxconvert_228.py
1 # This file is part of lyx2lyx
2 # -*- coding: iso-8859-1 -*-
3 # Copyright (C) 2003 José Matos <jamatos@fep.up.pt>
4 #
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License
7 # as published by the Free Software Foundation; either version 2
8 # of the License, or (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18
19
20
21 import sys
22 from parser_tools import find_token
23
24
25 def convert_minipage(lines):
26     """ Convert minipages to the box inset.
27     We try to use the same order of arguments as lyx does.
28     """
29     pos = ["t","c","b"]
30     inner_pos = ["c","t","b","s"]
31
32     i = 0
33     while 1:
34         i = find_token(lines, "\\begin_inset Minipage", i)
35         if i == -1:
36             return
37
38         lines[i] = "\\begin_inset Box Frameless"
39         i = i + 1
40
41         # convert old to new position using the pos list
42         if lines[i][:8] == "position":
43             lines[i] = 'position "%s"' % pos[int(lines[i][9])]
44         else:
45             lines.insert(i, 'position "%s"' % pos[0])
46         i = i + 1
47
48         lines.insert(i, 'hor_pos "c"')
49         i = i + 1
50         lines.insert(i, 'has_inner_box 1')
51         i = i + 1
52
53         # convert the inner_position
54         if lines[i][:14] == "inner_position":
55             lines[i] = 'inner_pos "%s"' %  inner_pos[int(lines[i][15])]
56         else:
57             lines.insert('inner_pos "%s"' % inner_pos[0])
58         i = i + 1
59
60         # We need this since the new file format has a height and width
61         # in a different order.
62         if lines[i][:6] == "height":
63             height = lines[i][6:]
64             # test for default value of 221 and convert it accordingly
65             if height == ' "0pt"':
66                 height = ' "1pt"'
67             del lines[i]
68         else:
69             height = ' "1pt"'
70
71         if lines[i][:5] == "width":
72             width = lines[i][5:]
73             del lines[i]
74         else:
75             width = ' "0"'
76
77         if lines[i][:9] == "collapsed":
78             if lines[i][9:] == "true":
79                 status = "collapsed"
80             else:
81                 status = "open"
82             del lines[i]
83         else:
84             status = "collapsed"
85
86         lines.insert(i, 'use_parbox 0')
87         i = i + 1
88         lines.insert(i, 'width' + width)
89         i = i + 1
90         lines.insert(i, 'special "none"')
91         i = i + 1
92         lines.insert(i, 'height' + height)
93         i = i + 1
94         lines.insert(i, 'height_special "totalheight"')
95         i = i + 1
96         lines.insert(i, 'status ' + status)
97         i = i + 1
98
99 def convert(header, body):
100     convert_minipage(body)
101
102 if __name__ == "__main__":
103     pass