[openbox] Menu conversion script
Adam Stephens
adam.c.stephens at ohiou.edu
Wed Jul 30 02:14:13 EDT 2003
Hmm...sorry about the line wrapping, hopefully you can figure it out. :)
also, i forgot to say, don't use anything related to themes or visual
styles. it will cause problems.
-atom
On Wed, 2003-07-30 at 02:01, Adam Stephens wrote:
> Hi,
>
> I just updated to version 3 today, and already I liked it better than
> version 2.
>
> I don't claim to be a master programmer, but I wrote a script to convert
> version 2 (blackbox) style menus to the new version 3 xml format. The
> script prolly will break in some situations, but it worked just fine for
> me. I used python, as I am trying to become more familiar with it, but
> feel free to convert it, change it, lick it and make it more friendly.
> Hopefully this will benefit others.
>
> Enjoy,
> -atom
>
> ------begin convertmenu.py ------
>
> #!/usr/bin/python
> #
> # written by/for atom.
> # it may not work for you.
> #
> #
>
> import os, sys, re, string
> from string import find, replace, upper, lower, strip
>
> linenumber = 0
> indent = ''
> menuheader0 = '<menu id=\"'
> menuheader1 = '\" label=\"'
> menuheader2 = '\">'
> menuend = '</menu>'
> execute0 = '<item label=\"'
> execute1 = '\">\n'
> execute2 = '<action name=\"execute\"><execute>'
> execute3 = '</execute></action>\n'
> execute4 = '</item>'
>
> try:
> file = open(sys.argv[1], 'r')
> except IndexError:
> print 'usage: convertmenu.py <oldmenufile>'
> sys.exit()
>
>
>
> for line in file.readlines():
>
> if find(line, '(') > -1:
> object = strip(re.search('\(.*\)', line).group(), '()')
> if find(line, '{') > -1:
> runthis = strip(re.search('\{.*\}', line).group(), '{}')
>
> if (find(line, '[begin]') > -1) or (find(line, '[submenu]') > -1) :
> line =
> indent+menuheader0+upper(object)+menuheader1+lower(object)\
> +menuheader2
> indent = indent+' '
> elif find(line, '[end]') > -1:
> indent = indent[:-1]
> line = indent+menuend
> elif find(line, '[exec]') > -1:
> line = indent+execute0+lower(object)+execute1+indent+'
> '+execute2\
> +runthis+execute3+indent+execute4
> else:
> line = ''
>
> if len(line) == 0:
> continue
>
> print line
> linenumber += 1
>
> file.close()
>
> ------end------
>
More information about the openbox
mailing list