bcp2pekwm.py 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. #!/usr/bin/python
  2. #- bcp2xmmsskin (060622a, Python version (Linux only (afaik)))
  3. #- (converted from bcp2gnome060508g.wxb)
  4. import os
  5. import sys
  6. #- Bug: i can't run it from /usr/bin/ just like a command (...?)
  7. finp_st=sys.argv[1]
  8. chbcp_st=finp_st
  9. debug=0
  10. #- i want to put a '--help' option as argv option, but i don't know about it
  11. varghlp=0;basepal=1;txttmpl=1
  12. if finp_st=="--help":
  13. varghlp=1
  14. if varghlp==0:
  15. #- './' as opcional to '/usr/bin/' (last prioritary)
  16. flg=0;tm_st="./Base.BaseColorPalette"
  17. if os.path.isfile(tm_st):fbase_st=tm_st;flg=1
  18. if debug==1:print"base: ./"
  19. tm_st="/usr/bin/Base.BaseColorPalette"
  20. if os.path.isfile(tm_st):fbase_st=tm_st;flg=1
  21. if debug==1:print"base: /usr/bin/"
  22. if flg==0:
  23. basepal=0
  24. #- './' as opcional to '/usr/bin/' (last prioritary)
  25. flg=0;tm_st="./sqc_pekwm_template.txt"
  26. if os.path.isfile(tm_st):finp_st=tm_st;flg=1
  27. if debug==1:print"template: ./"
  28. tm_st="/usr/bin/sqc_pekwm_template.txt"
  29. if os.path.isfile(tm_st):finp_st=tm_st;flg=1
  30. if debug==1:print"template: /usr/bin/"
  31. if flg==0:
  32. txttmpl=0
  33. #- this reader is assuming only one gamma value is set - only the last #define value will be considered
  34. #- this reader reads 2 files, first the Base one, and later the Custom one
  35. #----------------------------------------------------------------------------------------
  36. #- functions ----------------------------------------------------------------------------
  37. def suffixreplacer(a_st,b_st):
  38. lct1=a_st.rfind(".");lct2=a_st.rfind("/")
  39. if lct1>-1 and lct1>lct2:a_st=a_st[:lct1]
  40. a_st=a_st+b_st
  41. return a_st
  42. def locstrinfo(a_st,b_st,c_st):
  43. adra=0;adrb=0;d_st=""
  44. while adrb<=len(a_st) and adrb<len(b_st):
  45. if debug==1:print adra,adrb
  46. if a_st[adra]==b_st[adrb]:
  47. adrb=adrb+1
  48. adra=adra+1
  49. while a_st[adra]!=c_st[0]:
  50. d_st=d_st+a_st[adra]
  51. adra=adra+1
  52. return d_st
  53. def hexvl(a_st):
  54. a_st=a_st.lower();tmpr=0;hx_st="0123456789abcdef";hx_st=hx_st.lower()
  55. for i in range(0,len(a_st),1):tmpr=(tmpr*16)+hx_st.find(a_st[i])
  56. return tmpr
  57. def fixhxc(va):
  58. tm_st="000000"+hex(va).lstrip("0x");tm_st="#"+tm_st[len(tm_st)-6:]
  59. return tm_st.upper()
  60. def fixhex(va,sz):
  61. tml_st=""
  62. for i in range (0,sz,1):tml_st=tml_st+"0"
  63. tml_st=tml_st+hex(va).lstrip("0x");tml_st=tml_st[len(tml_st)-sz:]
  64. return tml_st.upper()
  65. def shade(a_st,kw_st,shd):
  66. a_st="000000"+a_st;a_st=a_st[len(a_st)-6:]
  67. a_st=a_st.lower();tmpr=0;hx_st="0123456789abcdef";hx_st=hx_st.lower()
  68. rv=(hx_st.find(a_st[0])*16)+hx_st.find(a_st[1])
  69. gv=(hx_st.find(a_st[2])*16)+hx_st.find(a_st[3])
  70. bv=(hx_st.find(a_st[4])*16)+hx_st.find(a_st[5])
  71. if kw_st.lower()=="k":
  72. rv=int(rv*shd);gv=int(gv*shd);bv=int(bv*shd)
  73. else:
  74. rv=int(255-((255-rv)*shd));gv=int(255-((255-gv)*shd));bv=int(255-((255-bv)*shd))
  75. hc_st="000000"+hex(rv*65536+gv*256+bv).lstrip("0x")
  76. return hc_st[len(hc_st)-6:]
  77. #----------------------------------------------------------------------------------------
  78. #- defining theme name ------------------------------------------------------------------
  79. if varghlp==0:
  80. themename_st=suffixreplacer(chbcp_st,"")
  81. #----------------------------------------------------------------------------------------
  82. #- converter code start -----------------------------------------------------------------
  83. if varghlp==0 and (txttmpl==1 and basepal==1):
  84. #----------------------------------------------------------------------------------------
  85. #- reads #define values from Base and Custom --------------------------------------------
  86. fovl_stl=[""]*2 #- dim fovl_stl(2)
  87. fovl_stl[0]=fbase_st;fovl_stl[1]=chbcp_st
  88. for foid in range(0,2,1):
  89. inpfile=open(fovl_stl[foid],"r")
  90. print "loading",str(fovl_stl[foid])
  91. lcntr=0
  92. while True:
  93. text_st=inpfile.readline();lcntr=lcntr+1
  94. #- print "readed line lenght:"+str(len(text_st)),str(lcntr)
  95. if len(text_st)==0:break
  96. text_st=" "+text_st.strip()+" "
  97. cm01_st=locstrinfo(text_st," "," ")
  98. cm02_st=locstrinfo(text_st," # "," ")
  99. cm03_st=locstrinfo(text_st," # #"," ")
  100. if cm02_st.lower()=="linkforegroundcolor" :LinkForegroundColor =hexvl(cm03_st)
  101. if cm02_st.lower()=="activelinkforegroundcolor" :ActiveLinkForegroundColor =hexvl(cm03_st)
  102. if cm02_st.lower()=="visitedlinkforegroundcolor" :VisitedLinkForegroundColor =hexvl(cm03_st)
  103. if cm02_st.lower()=="basicbackground" :BasicBackground =hexvl(cm03_st)
  104. if cm02_st.lower()=="referencetext" :ReferenceText =hexvl(cm03_st)
  105. if cm02_st.lower()=="textforeground" :TextForeground =hexvl(cm03_st)
  106. if cm02_st.lower()=="textfieldbackground" :TextFieldBackground =hexvl(cm03_st)
  107. if cm02_st.lower()=="readonlybackground" :ReadOnlyBackground =hexvl(cm03_st)
  108. if cm02_st.lower()=="buttonbackground" :ButtonBackground =hexvl(cm03_st)
  109. if cm02_st.lower()=="scrollbartroughcolor" :ScrollBarTroughColor =hexvl(cm03_st)
  110. if cm02_st.lower()=="scrollbarcontrolbackground" :ScrollBarControlBackground =hexvl(cm03_st)
  111. if cm02_st.lower()=="indicatorbackground" :IndicatorBackground =hexvl(cm03_st)
  112. if cm02_st.lower()=="radiocolor" :RadioColor =hexvl(cm03_st)
  113. if cm02_st.lower()=="checkcolor" :CheckColor =hexvl(cm03_st)
  114. if cm02_st.lower()=="drawingareabackground" :DrawingAreaBackground =hexvl(cm03_st)
  115. if cm02_st.lower()=="drawingareacontrastcolor1" :DrawingAreaContrastColor1 =hexvl(cm03_st)
  116. if cm02_st.lower()=="drawingareacontrastcolor2" :DrawingAreaContrastColor2 =hexvl(cm03_st)
  117. if cm02_st.lower()=="drawingareacontrastcolor3" :DrawingAreaContrastColor3 =hexvl(cm03_st)
  118. if cm02_st.lower()=="drawingareacontrastcolor4" :DrawingAreaContrastColor4 =hexvl(cm03_st)
  119. if cm02_st.lower()=="scrolledlistbackground" :ScrolledListBackground =hexvl(cm03_st)
  120. if cm02_st.lower()=="textbackground" :TextBackground =hexvl(cm03_st)
  121. if cm02_st.lower()=="highlightcolor1" :HighlightColor1 =hexvl(cm03_st)
  122. if cm02_st.lower()=="highlightcolor2" :HighlightColor2 =hexvl(cm03_st)
  123. if cm02_st.lower()=="highlightcolor3" :HighlightColor3 =hexvl(cm03_st)
  124. if cm02_st.lower()=="highlightcolor4" :HighlightColor4 =hexvl(cm03_st)
  125. if cm02_st.lower()=="highlightcolor5" :HighlightColor5 =hexvl(cm03_st)
  126. if cm02_st.lower()=="highlightcolor6" :HighlightColor6 =hexvl(cm03_st)
  127. if cm02_st.lower()=="highlightcolor7" :HighlightColor7 =hexvl(cm03_st)
  128. if cm02_st.lower()=="highlightcolor8" :HighlightColor8 =hexvl(cm03_st)
  129. if cm02_st.lower()=="wmbackground" :WMBackground =hexvl(cm03_st)
  130. if cm02_st.lower()=="wmforeground" :WMForeground =hexvl(cm03_st)
  131. if cm02_st.lower()=="wmactivebackground" :WMActiveBackground =hexvl(cm03_st)
  132. if cm02_st.lower()=="wmactiveforeground" :WMActiveForeground =hexvl(cm03_st)
  133. if cm02_st.lower()=="textselectedbackground" :TextSelectedBackground =hexvl(cm03_st)
  134. if cm02_st.lower()=="textselectedforeground" :TextSelectedForeground =hexvl(cm03_st)
  135. if cm02_st.lower()=="indicatorlightcolor" :IndicatorLightColor =hexvl(cm03_st)
  136. if cm02_st.lower()=="progressindicatorcolor" :ProgressIndicatorColor =hexvl(cm03_st)
  137. if cm02_st.lower()=="selectfillcolor" :SelectFillColor =hexvl(cm03_st)
  138. if cm02_st.lower()=="redColor" :RedColor =hexvl(cm03_st)
  139. if cm02_st.lower()=="orangecolor" :OrangeColor =hexvl(cm03_st)
  140. if cm02_st.lower()=="yellowcolor" :YellowColor =hexvl(cm03_st)
  141. if cm02_st.lower()=="greencolor" :GreenColor =hexvl(cm03_st)
  142. if cm02_st.lower()=="bluecolor" :BlueColor =hexvl(cm03_st)
  143. if cm02_st.lower()=="browncolor" :BrownColor =hexvl(cm03_st)
  144. if cm02_st.lower()=="purplecolor" :PurpleColor =hexvl(cm03_st)
  145. if cm02_st.lower()=="errorcolor" :ErrorColor =hexvl(cm03_st)
  146. if cm02_st.lower()=="warningcolor" :WarningColor =hexvl(cm03_st)
  147. if cm02_st.lower()=="informationcolor" :InformationColor =hexvl(cm03_st)
  148. if cm02_st.lower()=="alternatebackground1" :AlternateBackground1 =hexvl(cm03_st)
  149. if cm02_st.lower()=="alternatebackground2" :AlternateBackground2 =hexvl(cm03_st)
  150. if cm02_st.lower()=="alternatebackground3" :AlternateBackground3 =hexvl(cm03_st)
  151. if cm02_st.lower()=="alternatebackground4" :AlternateBackground4 =hexvl(cm03_st)
  152. if cm02_st.lower()=="alternatebackground5" :AlternateBackground5 =hexvl(cm03_st)
  153. if cm02_st.lower()=="alternatebackground6" :AlternateBackground6 =hexvl(cm03_st)
  154. if cm02_st.lower()=="disabledtextforeground" :DisabledTextForeground =hexvl(cm03_st)
  155. if cm02_st.lower()=="lightradiofillcolor" :LightRadioFillColor =hexvl(cm03_st)
  156. if cm02_st.lower()=="disabledcheckcolor" :DisabledCheckColor =hexvl(cm03_st)
  157. if cm02_st.lower()=="pixmapbuttonfillcolor" :PixmapButtonFillColor =hexvl(cm03_st)
  158. if cm02_st.lower()=="pixmapbuttonbottomshadowcolor":PixmapButtonBottomShadowColor=hexvl(cm03_st)
  159. if cm02_st.lower()=="pixmapbuttontopshadowcolor" :PixmapButtonTopShadowColor =hexvl(cm03_st)
  160. if debug==1:print "palette file "+fovl_stl[foid]+" readed. Lines readed:"+str(lcntr)
  161. inpfile.close()
  162. #- testing
  163. if debug==1:print fixhxc(WMBackground)
  164. #----------------------------------------------------------------------------------------
  165. #- next step ----------------------------------------------------------------------------
  166. clq_stl=[""]*9 #- dim clq_stl[9]
  167. idx_stl=[""]*9 #- dim idx_stl[9]
  168. cctn_stl=[""]*15 #- dim cctn_stl[15]
  169. #--------------------- brighter <--X--> darker -------------------------------------------
  170. #- substituir depois textfieldbackground para listbackground
  171. clq_stl[1]="252120";idx_stl[1]="2345678" #- BasicBackground (background)
  172. clq_stl[2]="48485B";idx_stl[2]="GHIJKLM" #- ButtonBackground (button)
  173. clq_stl[3]="252120";idx_stl[3]="NOPQRST" #- ScrollBarTroughColor (scroll)
  174. clq_stl[4]="DCAC81";idx_stl[4]="UVWXYZ#" #- TextFieldBackground (entry)
  175. clq_stl[5]="DCAC81";idx_stl[5]="ghijklm" #- ProgressIndicatorColor (progressbar)
  176. clq_stl[6]="DCAC81";idx_stl[6]="nopqrst" #- WMActiveBackground (window border active)
  177. clq_stl[7]="DCAC81";idx_stl[7]="uvwxyz>" #- WMBackground (window border inactive)
  178. clq_stl[1]=fixhex(BasicBackground,6)
  179. clq_stl[2]=fixhex(ButtonBackground,6)
  180. clq_stl[3]=fixhex(ScrollBarTroughColor,6)
  181. clq_stl[4]=fixhex(TextFieldBackground,6)
  182. clq_stl[5]=fixhex(ProgressIndicatorColor,6)
  183. clq_stl[6]=fixhex(WMActiveBackground,6)
  184. clq_stl[7]=fixhex(WMBackground ,6)
  185. #cctn_stl[0]=" 38 1\","
  186. cctn_stl[0]=cctn_stl[0]+"\". c None\",\n\"* c "
  187. cctn_stl[0]=cctn_stl[0]+fixhxc(CheckColor)
  188. cctn_stl[0]=cctn_stl[0]+"\",\n\"+ c "
  189. cctn_stl[0]=cctn_stl[0]+fixhxc(RadioColor)
  190. cctn_stl[0]=cctn_stl[0]+"\","
  191. for pqt in range(1,8,1):
  192. cctn_stl[pqt]=""
  193. z_st="\""+idx_stl[pqt][0]+" c #"+shade(clq_stl[pqt],"w",.25)+"\",\n"
  194. cctn_stl[pqt]=cctn_stl[pqt]+z_st
  195. z_st="\""+idx_stl[pqt][1]+" c #"+shade(clq_stl[pqt],"w",.5) +"\",\n"
  196. cctn_stl[pqt]=cctn_stl[pqt]+z_st
  197. z_st="\""+idx_stl[pqt][2]+" c #"+shade(clq_stl[pqt],"w",.75)+"\",\n"
  198. cctn_stl[pqt]=cctn_stl[pqt]+z_st
  199. z_st="\""+idx_stl[pqt][3]+" c #"+shade(clq_stl[pqt],"w",1) +"\",\n"
  200. cctn_stl[pqt]=cctn_stl[pqt]+z_st
  201. z_st="\""+idx_stl[pqt][4]+" c #"+shade(clq_stl[pqt],"k",.75)+"\",\n"
  202. cctn_stl[pqt]=cctn_stl[pqt]+z_st
  203. z_st="\""+idx_stl[pqt][5]+" c #"+shade(clq_stl[pqt],"k",.5) +"\",\n"
  204. cctn_stl[pqt]=cctn_stl[pqt]+z_st
  205. z_st="\""+idx_stl[pqt][6]+" c #"+shade(clq_stl[pqt],"k",.25)+"\","
  206. cctn_stl[pqt]=cctn_stl[pqt]+z_st
  207. #----------------------------------------------------------------------------------------
  208. #- splitting sqc_pekwm_template.txt to all that files and replacing their string to colours ----
  209. print "splitting txttemplate into files..."
  210. tm_st="./sqc_pekwm_template.txt"
  211. firstcrop=0
  212. inpfile=open(finp_st,"r")
  213. #while eof(1)==0:
  214. while True:
  215. text_st=inpfile.readline()
  216. if len(text_st)==0:break
  217. text_st=" "+text_st+" "
  218. text_st=text_st.replace("##TextForeground",fixhxc(TextForeground))
  219. text_st=text_st.replace("##TextSelectedBackground",fixhxc(TextSelectedBackground))
  220. text_st=text_st.replace("##BasicBackground",fixhxc(BasicBackground))
  221. text_st=text_st.replace("##ScrolledListBackground",fixhxc(ScrolledListBackground))
  222. text_st=text_st.replace("##WMBackground",fixhxc(WMBackground))
  223. text_st=text_st.replace("##WMActiveBackground",fixhxc(WMActiveBackground))
  224. text_st=text_st.replace("##WMForeground",fixhxc(WMForeground))
  225. text_st=text_st.replace("##WMActiveForeground",fixhxc(WMActiveForeground))
  226. text_st=text_st.replace("##--pbdep","52 1\",")
  227. text_st=text_st.replace("##--bkln","\n")
  228. if debug==1:print text_st
  229. readeddef=0
  230. cm01_st=locstrinfo(text_st," "," ");cm02_st=locstrinfo(text_st," "," ")
  231. if cm01_st.lower()=="--X--".lower():
  232. readeddef=1
  233. if firstcrop<>0:
  234. outfile.close()
  235. firstcrop=1
  236. outfile=open("./"+cm02_st,"w")
  237. if cm01_st[:16].lower()=="##--wholepalette".lower():
  238. readeddef=1
  239. for pqt in range (0,8,1):
  240. outfile.write(cctn_stl[pqt]+"\n")
  241. if debug==1:print "writing?"
  242. if readeddef==0 and firstcrop<>0:
  243. text_st=text_st.strip()
  244. outfile.write(text_st+"\n")
  245. inpfile.close()
  246. #----------------------------------------------------------------------------------------
  247. #- running shell commands ---------------------------------------------------------------
  248. print "running shell commands..."
  249. os.system("mkdirhier \"./sqc_"+themename_st+"\"")
  250. os.system("mv *.xpm ./sqc_"+themename_st)
  251. os.system("mv theme ./sqc_"+themename_st)
  252. os.system("cp "+chbcp_st+" ./sqc_"+themename_st)
  253. print "all conversion done!"
  254. #----------------------------------------------------------------------------------------
  255. #- end of converter code ----------------------------------------------------------------
  256. if varghlp==1:
  257. print
  258. print"usage: python bcp2gnome.py [yourfile].BaseColorPalette"
  259. print"the theme folder result will appear neighbour to source file"
  260. print"(bcp2gnome [yourfile].BaseColorPalette (bcp2gnome in /usr/bin/) is not working yet)"
  261. print
  262. if basepal==0:
  263. print
  264. print "Base.BaseColorPalette is missing"
  265. print "please check at current directory or at /usr/bin/"
  266. print
  267. if txttmpl==0:
  268. print
  269. print "sqc_pekwm_template.txt is missing"
  270. print "please check at current directory or at /usr/bin/"
  271. print
  272. print "ok"
  273. #----------------------------------------------------------------------------------------
  274. #- that's all !!! -----------------------------------------------------------------------