RenderingStyles.py 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. """
  2. ***************************************************************************
  3. RenderingStyles.py
  4. ---------------------
  5. Date : August 2012
  6. Copyright : (C) 2012 by Victor Olaya
  7. Email : volayaf at gmail dot com
  8. ***************************************************************************
  9. * *
  10. * This program is free software; you can redistribute it and/or modify *
  11. * it under the terms of the GNU General Public License as published by *
  12. * the Free Software Foundation; either version 2 of the License, or *
  13. * (at your option) any later version. *
  14. * *
  15. ***************************************************************************
  16. """
  17. __author__ = 'Victor Olaya'
  18. __date__ = 'August 2012'
  19. __copyright__ = '(C) 2012, Victor Olaya'
  20. import os
  21. from processing.tools.system import userFolder
  22. class RenderingStyles:
  23. styles = {}
  24. @staticmethod
  25. def addAlgStylesAndSave(algname, styles):
  26. RenderingStyles.styles[algname] = styles
  27. RenderingStyles.saveSettings()
  28. @staticmethod
  29. def configFile():
  30. return os.path.join(userFolder(), 'processing_qgis_styles.conf')
  31. @staticmethod
  32. def loadStyles():
  33. if not os.path.isfile(RenderingStyles.configFile()):
  34. return
  35. with open(RenderingStyles.configFile()) as lines:
  36. line = lines.readline().strip('\n')
  37. while line != '':
  38. tokens = line.split('|')
  39. if tokens[0] in list(RenderingStyles.styles.keys()):
  40. RenderingStyles.styles[tokens[0]][tokens[1]] = tokens[2]
  41. else:
  42. alg = {}
  43. alg[tokens[1]] = tokens[2]
  44. RenderingStyles.styles[tokens[0]] = alg
  45. line = lines.readline().strip('\n')
  46. @staticmethod
  47. def saveSettings():
  48. with open(RenderingStyles.configFile(), 'w') as fout:
  49. for alg in list(RenderingStyles.styles.keys()):
  50. for out in list(RenderingStyles.styles[alg].keys()):
  51. fout.write(alg + '|' + out + '|' +
  52. RenderingStyles.styles[alg][out] + '\n')
  53. @staticmethod
  54. def getStyle(algname, outputname):
  55. if algname in RenderingStyles.styles:
  56. if outputname in RenderingStyles.styles[algname]:
  57. return RenderingStyles.styles[algname][outputname]
  58. return None