Hi Dan,

I've analyzed your rewritten fvwm-menu-desktop.in and there are couple of things.

- under Debian systems it doesn't work out of the box, because there's no applications.menu. Therefore the program ends in some python errors:
pydev debugger: starting
Traceback (most recent call last):
File "/opt/eclipse/eclipse/plugins/org.python.pydev.debug_2.5.0.2012040618/pysrc/pydevd.py", line 1346, in <module>
    debugger.run(setup['file'], None, None)
File "/opt/eclipse/eclipse/plugins/org.python.pydev.debug_2.5.0.2012040618/pysrc/pydevd.py", line 1060, in run
    pydev_imports.execfile(file, globals, locals) #execute the script
File "/media/daten/shared/sourcen/Fvwm-xdg-menu/fvwm-menu-desktop.py", line 273, in <module>
    main()
File "/media/daten/shared/sourcen/Fvwm-xdg-menu/fvwm-menu-desktop.py", line 153, in main
    parsemenu(xdg.Menu.parse(menu), top)
  File "/usr/lib/pymodules/python2.7/xdg/Menu.py", line 523, in parse
    doc = xml.dom.minidom.parse(filename)
  File "/usr/lib/python2.7/xml/dom/minidom.py", line 1920, in parse
    return expatbuilder.parse(file)
  File "/usr/lib/python2.7/xml/dom/expatbuilder.py", line 922, in parse
    fp = open(file, 'rb')
IOError: [Errno 2] No such file or directory: '/etc/xdg/menus/applications.menu'

It must be checked if it exist *before* it will be parsed because the parse routine in xdg.Menu doesn't do that.
Fix in main():
    if os.path.exists(menu):
        parsemenu(xdg.Menu.parse(menu), top)
    else:
        print menu + " not available on this system. Exiting..."

- some menu entries doesn't work because of these trailing %U, %f, etc. Therefore these parts must be eliminated:
Fix in parsemenu():
    m = re.compile('%[A-Z]?', re.I)
    :
            execProgram = m.sub('', desktop.getExec())
            printmenu(desktop.getName(), desktop.getIcon(),
                  "Exec exec " + " " + execProgram)

- if you want to use icons with "--enable-mini-icons" no icons can be saved because no "icons" dir exist. Therefore it has to be explicit created:
    if not os.path.isdir(os.path.expanduser(icon_dir)):
        os.system("mkdir " + os.path.expanduser(icon_dir))

some icons defined in the desktop files won't be created because they are svgs. But convert can't convert to .svg
Fix in geticonfile() to convert also svgs:
    if not iconpath == None:
        extension = os.path.splitext(iconpath)[1]
    :
    if extension == '.svg':
        iconfile = iconfile.replace('.svg', '.png')

These fixes let the tool run in eclipse smoothless. But not on the command line.
#!@PYTHON@
doesn't work there. Switched back to
#!/usr/bin/python

The
    print 'DestroyMenu "%s"' % name
throws errors
Traceback (most recent call last):
  File "./fvwm-menu-desktop.py", line 289, in <module>
    main()
  File "./fvwm-menu-desktop.py", line 154, in main
    parsemenu(xdg.Menu.parse(menu), top)
  File "./fvwm-menu-desktop.py", line 226, in parsemenu
    parsemenu(entry)
  File "./fvwm-menu-desktop.py", line 209, in parsemenu
    print 'DestroyMenu "%s"' % name
UnicodeEncodeError: 'ascii' codec can't encode character u'\xfc' in position 14: ordinal not in range(128)

changed it to
    printtext('DestroyMenu "%s"' % name)

Btw about your comment
# themes not working: "hicolor" is a required theme I see lots of themes but none seem to affect much - it works, but the icons for popups doesn't exist in the hicolor theme because they are hardcoded in getdefaulticonfile(). I will look into it later.

Hope these fixes are ok for you.

Thomas

--- ../cvs/fvwm/bin/fvwm-menu-desktop.in	2012-06-22 20:28:55.671420675 +0200
+++ fvwm-menu-desktop.py	2012-06-23 12:41:42.633766537 +0200
@@ -1,4 +1,4 @@
-#!@PYTHON@
+#!/usr/bin/python
  
 # Modification History
 
@@ -107,7 +107,7 @@
     global verbose, force, size, theme, icon_dir, top, install_prefix
     verbose = False
     force = False
-    desktop='applications'
+    desktop='gnome-applications'
     size=24
     theme='gnome'
     icon_dir="~/.fvwm/icons"
@@ -150,8 +150,11 @@
     if (desktop[0] == '/'):
         menu=desktop
     
-    parsemenu(xdg.Menu.parse(menu), top)
-
+    if os.path.exists(menu):
+        parsemenu(xdg.Menu.parse(menu), top)
+    else:
+        print menu + " not available on this system. Exiting..."
+        
 
 def printtext(text):
     print text.encode("utf-8")
@@ -159,6 +162,9 @@
 def geticonfile(icon):
     iconpath = xdg.IconTheme.getIconPath(icon, size, theme, ["png", "xpm"])
 
+    if not iconpath == None:
+        extension = os.path.splitext(iconpath)[1]
+
     if not iconpath:
         return None
 
@@ -168,9 +174,16 @@
     if iconpath.find("%ix%i" % (size, size)) >= 0: # ugly hack!!!
         return iconpath
 
+    if not os.path.isdir(os.path.expanduser(icon_dir)):
+        os.system("mkdir " + os.path.expanduser(icon_dir))
+
     iconfile = os.path.join(os.path.expanduser(icon_dir),
                             "%ix%i-" % (size, size) + 
                             os.path.basename(iconpath))
+
+    if extension == '.svg':
+        iconfile = iconfile.replace('.svg', '.png')
+
     os.system("if test \\( ! -f '%s' \\) -o \\( '%s' -nt '%s' \\) ; then convert '%s' -resize %i '%s' ; fi"% 
               (iconfile, iconpath, iconfile, iconpath, size, iconfile))
     return iconfile
@@ -190,27 +203,30 @@
     printtext('+ "%s%s" %s' % (name, iconfile, command))
 
 def parsemenu(menu, name=""):
+    m = re.compile('%[A-Z]?', re.I)
     if not name:
-      name = menu.getPath()
-    print 'DestroyMenu "%s"' % name
+        name = menu.getPath()
+    printtext('DestroyMenu "%s"' % name)
     printtext('AddToMenu "%s"' % name)
     for entry in menu.getEntries():
-	if isinstance(entry, xdg.Menu.Menu):
-	    printmenu(entry.getName(), entry.getIcon(),
-		      'Popup "%s"' % entry.getPath())
-	elif isinstance(entry, xdg.Menu.MenuEntry):
-	    desktop = DesktopEntry(entry.DesktopEntry.getFileName())
-	    printmenu(desktop.getName(), desktop.getIcon(),
-                      "Exec exec " + desktop.getExec() )
-	else:
-	    printtext('# not supported: ' + str(entry))
+    	if isinstance(entry, xdg.Menu.Menu):
+    	    printmenu(entry.getName(), entry.getIcon(),
+    		      'Popup "%s"' % entry.getPath())
+    	elif isinstance(entry, xdg.Menu.MenuEntry):
+    	    desktop = DesktopEntry(entry.DesktopEntry.getFileName())
+            # eliminate '%U' etc behind execute string
+            execProgram = m.sub('', desktop.getExec())
+            printmenu(desktop.getName(), desktop.getIcon(),
+                  "Exec exec " + " " + execProgram)
+    	else:
+    	    printtext('# not supported: ' + str(entry))
 
     for entry in menu.getEntries():
-	if isinstance(entry, xdg.Menu.Menu):
-	    parsemenu(entry)
-
-    if (re.search('.*System Tools$',name)) : # fixme, find a better way to do this?
-        printmenu("Regenerate Applications Menu", "", "FvwmForm " "FvwmForm-Desktop" )
+    	if isinstance(entry, xdg.Menu.Menu):
+    	    parsemenu(entry)
+    
+        if (re.search('.*System Tools$',name)) : # fixme, find a better way to do this?
+            printmenu("Regenerate Applications Menu", "", "FvwmForm " "FvwmForm-Desktop" )
 
 
 usage="""

Reply via email to