Advertisement
Guest User

nitrofurano

a guest
Nov 8th, 2008
227
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #! /usr/bin/python
  2. #- alacarte2fluxmenu - 0611211515
  3. #- Paulo Silva (correasilva_at_tugamail_dot_com) - GPL licence
  4. #- converts the Gnome menu (/usr/share/applications/*.desktop) into a fluxbox menu
  5. #- usage: python gnome2fluxmenu.py > fluxmenu.txt
  6. #- or:    python gnome2fluxmenu.py > ~/.fluxbox/menu   (please backup 'menu' document before)
  7. #- note: results may need some small adjustments, like apps turned on/off with Alacarte
  8. import gconf,os,sys,random,mimetypes
  9. gnmp_st="/usr/share/applications"
  10. catacce_sl=[""]*512;catutil_sl=[""]*512;catgame_sl=[""]*512;catgrap_sl=[""]*512
  11. catnetw_sl=[""]*512;catoffi_sl=[""]*512;catothe_sl=[""]*512;catdeve_sl=[""]*512
  12. catauvd_sl=[""]*512;catsyst_sl=[""]*512;catsysp_sl=[""]*512;catsysa_sl=[""]*512
  13. cntacce=0;cntutil=0;cntgame=0;cntgrap=0;cntnetw=0;cntoffi=0
  14. cntothe=0;cntdeve=0;cntauvd=0;cntsyst=0;cntsysp=0;cntsysa=0
  15. diritems_sl=os.listdir(gnmp_st)
  16. for item in diritems_sl:
  17.   finp_st=os.path.join(gnmp_st,item)
  18.   if finp_st.endswith(".desktop"):
  19.     finp_fl=open(finp_st,"r")
  20.     cate_st="";name_st="";exec_st="";catswc=0
  21.     while True:
  22.  
  23.       text_st=finp_fl.readline()
  24.  
  25.       if len(text_st)==0:break
  26.       text_st=text_st.replace("\n","")
  27.       if text_st.startswith("Categories="):
  28.         cate_st=text_st
  29.         if cate_st.find("Accessibility")>0:catswc+=   1
  30.         if cate_st.find("Utility")>0:      catswc+=   2
  31.         if cate_st.find("Game")>0:         catswc+=   4
  32.         if cate_st.find("Graphics")>0:     catswc+=   8
  33.         if cate_st.find("Network")>0:      catswc+=  16
  34.         if cate_st.find("Office")>0:       catswc+=  32
  35.         if cate_st.find("Development")>0:  catswc+=  64
  36.         if cate_st.find("AudioVideo")>0:   catswc+= 128
  37.         if cate_st.find("System")>0:       catswc+= 256
  38.         if cate_st.find("Settings")>0:     catswc+= 512
  39.         if cate_st.find("Core")>0:         catswc+=1024
  40.       if text_st.startswith("Name="):
  41.         name_st=text_st[5:];name_st=name_st.replace(")","\\)")
  42.       if text_st.startswith("Exec="):
  43.         exec_st=text_st[5:]
  44.     fluxpr_st="[exec]("+name_st+"){"+exec_st+"}<>"
  45.     if (catswc&   1)==  1:
  46.       catacce_sl[cntacce]=fluxpr_st;cntacce+=1
  47.     if (catswc&   2)==  2:
  48.       catutil_sl[cntutil]=fluxpr_st;cntutil+=1
  49.     if (catswc&   4)==  4:
  50.       catgame_sl[cntgame]=fluxpr_st;cntgame+=1
  51.     if (catswc&   8)==  8:
  52.       catgrap_sl[cntgrap]=fluxpr_st;cntgrap+=1
  53.     if (catswc&  16)== 16:
  54.       catnetw_sl[cntnetw]=fluxpr_st;cntnetw+=1
  55.     if (catswc&  32)== 32:
  56.       catoffi_sl[cntoffi]=fluxpr_st;cntoffi+=1
  57.     if (catswc&1023)==  0:
  58.       catothe_sl[cntothe]=fluxpr_st;cntothe+=1
  59.     if (catswc&  64)== 64:
  60.       catdeve_sl[cntdeve]=fluxpr_st;cntdeve+=1
  61.     if (catswc& 128)==128:
  62.       catauvd_sl[cntauvd]=fluxpr_st;cntauvd+=1
  63.     if (catswc& 768)==256:
  64.       catsyst_sl[cntsyst]=fluxpr_st;cntsyst+=1
  65.     if (catswc& 768)==512:
  66.       catsysp_sl[cntsysp]=fluxpr_st;cntsysp+=1
  67.     if (catswc& 768)==768:
  68.       catsysa_sl[cntsysa]=fluxpr_st;cntsysa+=1
  69.     finp_fl.close()
  70. print"[begin](Fluxbox){}<>"
  71. print"  [submenu](Accessibility){}<>"
  72. for i in range(0,cntacce-1,1):print"    "+catacce_sl[i]
  73. print"  [end]";print"  [submenu](Accessories){}<>"
  74. for i in range(0,cntutil-1,1):print"    "+catutil_sl[i]
  75. print"  [end]";print"  [submenu](Games){}<>"
  76. for i in range(0,cntgame-1,1):print"    "+catgame_sl[i]
  77. print"  [end]";print"  [submenu](Graphics){}<>"
  78. for i in range(0,cntgrap-1,1):print"    "+catgrap_sl[i]
  79. print"  [end]";print"  [submenu](Internet){}<>"
  80. for i in range(0,cntnetw-1,1):print"    "+catnetw_sl[i]
  81. print"  [end]";print"  [submenu](Office){}<>"
  82. for i in range(0,cntoffi-1,1):print"    "+catoffi_sl[i]
  83. print"  [end]";print"  [submenu](Other){}<>"
  84. for i in range(0,cntothe-1,1):print"    "+catothe_sl[i]
  85. print"  [end]";print"  [submenu](Programming){}<>"
  86. for i in range(0,cntdeve-1,1):print"    "+catdeve_sl[i]
  87. print"  [end]";print"  [submenu](Sound & Video){}<>"
  88. for i in range(0,cntauvd-1,1):print"    "+catauvd_sl[i]
  89. print"  [end]";print"  [submenu](System Tools){}<>"
  90. for i in range(0,cntsyst-1,1):print"    "+catsyst_sl[i]
  91. print"  [end]"
  92. print"  [separator](){}<>"
  93. print"  [workspaces](Workspaces)"
  94. print"  [exec](Run...){fbrun}<>"
  95. print"  [exec](Add/Remove...){gnome-app-install}<>"
  96. print"  [submenu](Places){}<>"
  97. print"    [exec](Home Folder){nautilus --no-desktop}<>"
  98. print"    [exec](Documents){nautilus --no-desktop ~/Documents}<>"
  99. print"    [exec](Desktop){nautilus --no-desktop ~/Desktop}<>"
  100. print"    [submenu](Bookmarks){}<>"
  101. print"    [end]"
  102. print"    [exec](Computer){nautilus --no-desktop computer:}<>"
  103. print"    [exec](CD/DVD Creator){nautilus --no-desktop burn:///}<>"
  104. print"    [exec](Network Servers){nautilus --no-desktop network:}<>"
  105. print"    [exec](Connect to Server...){gdialog --msgbox \"not available:\nmissing menu item\"}<>"
  106. print"    [exec](Search for Files...){gnome-search-tool}<>"
  107. print"  [end]"
  108. print"  [submenu](System){}<>"
  109. print"    [submenu](Preferences){}<>"
  110. for i in range(0,cntsysp-1,1):print"      "+catsysp_sl[i]
  111. print"    [end]";print"    [submenu](Administration){}<>"
  112. for i in range(0,cntsysa-1,1):print"      "+catsysa_sl[i]
  113. print"    [end]"
  114. print"    [submenu](Fluxbox){}<>"
  115. print"      [submenu](Edit Fluxbox){}<>"
  116. print"        [exec](Edit Menu){gedit ~/.fluxbox/menu}<>"
  117. print"        [exec](Edit StartUp){gedit ~/.fluxbox/startup}<>"
  118. print"        [exec](Edit Keybinding){gedit ~/.fluxbox/keys}<>"
  119. print"      [end]"
  120. print"      [submenu](Fluxbox Tools){}<>"
  121. print"        [exec](Fluxconf){fluxconf}<>"
  122. print"        [exec](Fluxkeys){fluxkeys}<>"
  123. print"        [exec](Fluxmenu){fluxmenu}<>"
  124. print"      [end]"
  125. print"      [submenu](Style){Style}<>"
  126. print"        [stylesdir](~/.fluxbox/styles){}<>"
  127. print"        [stylesmenu](Fluxbox Styles){/usr/share/fluxbox/styles}<>"
  128. print"      [end]"
  129. print"      [config](Config){}<>"
  130. print"      [reconfig](Reconfigure){}<>"
  131. print"      [restart](Restart){}<>"
  132. print"      [submenu](WindowManagers){}<>"
  133. print"        [restart](Blackbox){/usr/bin/blackbox}<>"
  134. print"        [restart](Window Maker){/usr/bin/wmaker}<>"
  135. print"        [restart](Enlightenment){/usr/bin/enlightenment}<>"
  136. print"        [restart](IceWM){/usr/bin/icewm}<>"
  137. print"        [restart](Flwm){/usr/bin/flwm}<>"
  138. print"        [restart](Larswm){/usr/bin/larswm}<>"
  139. print"        [restart](lwm){/usr/bin/X11/lwm}<>"
  140. print"        [restart](Openbox){/usr/bin/openbox}<>"
  141. print"        [restart](PWM){/usr/bin/pwm}<>"
  142. print"        [restart](ratpoison){ratpoison}<>"
  143. print"        [restart](Sapphire){/usr/bin/sapphire}<>"
  144. print"        [restart](Oroborus){/usr/bin/oroborus}<>"
  145. print"        [restart](w9wm){/usr/X11R6/bin/w9wm}<>"
  146. print"        [restart](WindowLab){windowlab}<>"
  147. print"        [restart](wm2){/usr/bin/wm2}<>"
  148. print"      [end]"
  149. print"    [end]"
  150. print"    [submenu](Help){}<>"
  151. print"      [exec](System Documentation){gdialog --msgbox \"not available:\nmissing menu item\"}<>"
  152. print"      [exec](Online Documentation){firefox http://help.ubuntu.com}<>"
  153. print"      [exec](Community Support){firefox http://www.ubuntu.com/support/supportoptions/freesupport}<>"
  154. print"      [exec](Commercial Support){firefox http://www.ubuntu.com/support/marketplace}<>"
  155. print"      [exec](Ubuntu Book Excerpt){firefox file:///usr/share/example-content/book-toc.html}<>"
  156. print"    [end]"
  157. print"    [exec](About GNOME){gnome-about}<>"
  158. print"    [exec](About Ubuntu){yelp ghelp:about-ubuntu}<>"
  159. print"  [end]"
  160. print"  [submenu](Quit){}<>"
  161. print"    [exit](Logout){}<>"
  162. print"    [exec](Shutdown){gksu \"shutdown -h now\"}<>"
  163. print"    [exec](Restart){gksu \"shutdown -r now\"}<>"
  164. print"  [end]"
  165. print"[end]"
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement