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