home *** CD-ROM | disk | FTP | other *** search
/ Windows News 2005 November / WNnov2005.iso / Windows / Equipement / Blender / blender-2.37a-windows.exe / $_5_ / .blender / scripts / save_theme.py < prev    next >
Text File  |  2005-06-13  |  4KB  |  120 lines

  1. #!BPY
  2.  
  3. """
  4. Name: 'Save Current Theme...'
  5. Blender: 237
  6. Group: 'Export'
  7. Tooltip: 'Save current theme as a bpython script'
  8. """
  9.  
  10. __author__ = "Willian P. Germano"
  11. __url__ = ("blender", "elysiun")
  12. __version__ = "2.37 2005/06/06"
  13.  
  14. __bpydoc__ = """\
  15. This script saves the current Theme in Blender as a Blender Python script.
  16.  
  17. Usage:
  18.  
  19. Use Blender's Theme tab in the User Preferences window to create and name your
  20. theme, then run this script from the File->Export menu to save it.
  21.  
  22. It is saved as a bpython script, meaning that you can simply run it to change
  23. the current theme.  By default it is currently saved under the
  24. "Misc" group, available only from the Scripts window "Scripts->Misc" menu.
  25.  
  26. To appear in the menu, a theme saved with this script must be put in your
  27. Blender's scripts dir, that's what happens by default when you save one by
  28. yourself.  If you don't know where this dir is, running
  29.  
  30. import Blender<br>print Blender.Get("scriptsdir")
  31.  
  32. on the Text Editor window (use menu or ALT+P to run it) will write the path on
  33. the console.
  34.  
  35. Remember to edit your exported theme's source file to put your name and
  36. some information on it before sharing it with others.
  37. """
  38.  
  39. # $Id: save_theme.py,v 1.6 2005/06/11 05:30:13 ianwill Exp $
  40. #
  41. # --------------------------------------------------------------------------
  42. # Copyright (C) 2004: Willian P. Germano, wgermano _at_ ig.com.br
  43. # --------------------------------------------------------------------------
  44. # Released under the Blender Artistic License (BAL):
  45. #   http://download.blender.org/documentation/html/x21254.html
  46. #
  47. # The scripts generated by this script are put under Public Domain by
  48. # default, but you are free to edit the ones you generate with this script
  49. # and change their license to another one of your choice.
  50. # --------------------------------------------------------------------------
  51.  
  52. import Blender
  53. from Blender.Window import Theme, FileSelector
  54.  
  55. theme = Theme.Get()[0] # get current theme
  56.  
  57. # default filename: theme's name + '_theme.py' in user's scripts dir:
  58. default_fname = Blender.Get("scriptsdir")
  59. default_fname = Blender.sys.join(default_fname, theme.name + '_theme.py')
  60. default_fname = default_fname.replace(' ','_')
  61.  
  62. def write_theme(filename):
  63.     "Write the current theme as a bpython script"
  64.  
  65.     if not filename.endswith('.py'): filename += '.py'
  66.  
  67.     fout = file(filename, "w")
  68.  
  69.     fout.write("""#!BPY
  70.  
  71. # \"\"\"
  72. # Name: '%s'
  73. # Blender: 237
  74. # Group: 'Themes'
  75. # Tooltip: 'Change current theme'
  76. # \"\"\"
  77.  
  78. __%s__ = "????"
  79. __%s__ = "2.37"
  80. __%s__ = ["blender"]
  81. __%s__ = \"\"\"\\
  82. You can edit this section to write something about your script that can
  83. be read then with the Scripts Help Browser script in Blender.
  84.  
  85. Remember to also set author, version and possibly url(s) above.  You can also
  86. define an __email__ tag, check some bundled script's source for examples.
  87. \"\"\"
  88.  
  89. # This script was automatically generated by the save_theme.py bpython script.
  90. # By default, these generated scripts are released as Public Domain, but you
  91. # are free to change the license of the scripts you generate with
  92. # save_theme.py before releasing them.
  93.  
  94. import Blender
  95. from Blender.Window import Theme
  96.  
  97. theme = Theme.New('%s')
  98. """ % (theme.name, "author", "version", "url", "bpydoc", theme.name))
  99.  
  100.     for tsp in theme.get(): # 
  101.         command = "\n%s = theme.get('%s')" % (tsp, tsp)
  102.         fout.write(command + "\n")
  103.         exec(command)
  104.         exec("vars = dir(%s)" % tsp)
  105.         vars.remove('theme')
  106.  
  107.         for var in vars:
  108.             v = "%s.%s" % (tsp, var)
  109.             exec("value = %s" % v)
  110.             fout.write("%s = %s\n" % (v, value))
  111.  
  112.     fout.write('\nBlender.Redraw(-1)')
  113.     fout.close()
  114.     try:
  115.         Blender.UpdateMenus()
  116.     except:
  117.         Blender.Draw.PupMenu("Warning - check console!%t|Menus could not be automatically updated")
  118.  
  119. FileSelector(write_theme, "Save Current Theme", default_fname)
  120.