xml_info 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. #!/bin/bash
  2. #this generates xml code for a gtkdialog gui.
  3. #it is NOT a standalone window
  4. #
  5. #usage :
  6. # xml_info BOX-HEIGHT ICON ICON-HEIGHT "text-string1" "text-string2" ...
  7. # xml_info gtk
  8. #
  9. # GTK must be run before gtkdialog is executed to update GTK2_RC_FILES with the image used in background of msgbox
  10. # BOX-HEIGHT is the height of the field.
  11. # - integer : the height in pixels
  12. # - fixed : autoresize msgbox, but do NOT scale this area
  13. # - scale or 0 : autoresize msgbox, and scale this area
  14. # ICON can either be a gtk stock icon, a normal raster/vector file or no icon. if no path is set, /usr/share/pixmaps/puppy/ is used
  15. # ICON-HEIGHT is a integer - 0 uses default size of icon
  16. #
  17. #Sigmund Berglund, dec 2013
  18. #GPL
  19. case $1 in
  20. gtk)
  21. #. $HOME/.theme_nnnnn #this to allow some kind of theming in the future
  22. case $2 in
  23. green|yes|1)
  24. COLOR1='#BED1C1'
  25. COLOR2='#006F04'
  26. ;;
  27. red|no|0)
  28. COLOR1='#DFCECE'
  29. COLOR2='#8E0000'
  30. ;;
  31. esac
  32. #if no theme-values is defined - use the default
  33. #this theming don't work in combination with all gtk2 themes.
  34. [ ! "$OPACITY" ] && OPACITY=0.5 #background opacity to melt into different global gtk-themes. gradients does not support this.
  35. [ ! "$COLOR1" ] && COLOR1='#EDEAC6' #background color
  36. [ ! "$COLOR2" ] && COLOR2='#000000' #gradient spot color
  37. [ ! "$MODE" ] && MODE="flat" #drawing mode
  38. #build background svg for info-widget
  39. export FLAT='<svg version="1.0"><rect width="100" height="100" style="fill:'${COLOR1}';fill-opacity:'${OPACITY}';stroke:none"/></svg>'
  40. export GRADIENT='
  41. <svg version="1.1" width="2000" height="1000">
  42. <defs>
  43. <linearGradient id="LG_01" x1="30" y1="95" x2="-50" y2="-125" gradientUnits="userSpaceOnUse">
  44. <stop style="stop-color:'${COLOR1}';stop-opacity:1" offset="0" />
  45. <stop style="stop-color:'${COLOR2}';stop-opacity:1" offset="1" />
  46. </linearGradient>
  47. </defs>
  48. <rect width="2000" height="1000" style="fill:'${COLOR1}';stroke:none"/>
  49. <rect
  50. style="fill:url(#LG_01);fill-opacity:1;stroke-width:0"
  51. width="250" height="200"/>
  52. </svg>'
  53. case $MODE in gradient) BGSVG="$GRADIENT";; *) BGSVG="$FLAT";; esac
  54. echo "$BGSVG" > /tmp/xml_info.svg
  55. #redefine gtk-theme
  56. echo 'pixmap_path "/tmp/"
  57. style "Bgsvg" { bg_pixmap[NORMAL] = "xml_info.svg" }
  58. widget "*BgSVG" style "Bgsvg"' > /tmp/gtkrc_xml_info
  59. #combine theme stuff with system themes
  60. if [ ! "$GTK2_RC_FILES" ]; then
  61. export GTK2_RC_FILES=~/.gtkrc-2.0:/tmp/gtkrc_xml_info
  62. else
  63. export GTK2_RC_FILES="$GTK2_RC_FILES:/tmp/gtkrc_xml_info"
  64. fi
  65. ;;
  66. fixed)
  67. HEIGHT='space-expand="false" space-fill="false"'
  68. ;;
  69. 0|scale|' '|'')
  70. HEIGHT='space-expand="true" space-fill="true"'
  71. ;;
  72. *[0-9]*)
  73. [ $1 != 0 ] && HEIGHT="height-request=\"$1\" space-expand=\"false\" space-fill=\"false\""
  74. ;;
  75. *)
  76. HEIGHT='space-expand="true" space-fill="true"'
  77. ;;
  78. esac
  79. #define icon
  80. case $2 in
  81. /*)
  82. #icon from file
  83. ICON_INPUT="<input file>${2}</input>"
  84. case $3 in 0) ICON_HEIGHT="";; *) ICON_HEIGHT="<height>${3}</height>";; esac
  85. ICON="<vbox><pixmap>${ICON_INPUT}${ICON_HEIGHT}</pixmap></vbox>"
  86. ;;
  87. 0|none|' '|'')
  88. ICON=""
  89. ;;
  90. *)
  91. case $2 in
  92. *.svg)
  93. #icon from puppy stock
  94. ICON_INPUT="<input file>/usr/share/pixmaps/puppy/${2}</input>"
  95. case $3 in 0) ICON_HEIGHT="";; *) ICON_HEIGHT="<height>${3}</height>";; esac
  96. ICON="<vbox><pixmap>${ICON_INPUT}${ICON_HEIGHT}</pixmap></vbox>"
  97. ;;
  98. *)
  99. #icon from gtk stock
  100. ICON_INPUT="<input file stock=\"gtk-${2}\"></input>"
  101. case $3 in [1-6]) ICON_HEIGHT=" icon_size=\"${3}\"";; 0|*) ICON_HEIGHT="";; esac
  102. ICON="<vbox><pixmap${ICON_HEIGHT}>${ICON_INPUT}</pixmap></vbox>"
  103. ;;
  104. esac
  105. esac
  106. if [ "$3" ] || [ "$4" ] || [ "$5" ]; then #generate XML code
  107. echo '
  108. <notebook name="BgSVG" show-tabs="false" '${HEIGHT}'>
  109. <hbox '${HEIGHT}'>
  110. <vbox space-expand="false" space-fill="false">
  111. <hbox border-width="10">
  112. '${ICON}'
  113. <text width-request="5"><label>""</label></text>
  114. <vbox space-expand="false" space-fill="false">'
  115. [ "$4" ] && echo '<text xalign="0" use-markup="true"><label>"'$4'"</label></text>'
  116. [ "$5" ] && echo '<text xalign="0" use-markup="true"><label>"'$5'"</label></text>'
  117. [ "$6" ] && echo '<text xalign="0" use-markup="true"><label>"'$6'"</label></text>'
  118. [ "$7" ] && echo '<text xalign="0" use-markup="true"><label>"'$7'"</label></text>'
  119. [ "$8" ] && echo '<text xalign="0" use-markup="true"><label>"'$8'"</label></text>'
  120. [ "$9" ] && echo '<text xalign="0" use-markup="true"><label>"'$9'"</label></text>'
  121. echo '</vbox>
  122. </hbox>
  123. </vbox>
  124. <text space-expand="true" space-fill="true"><label>""</label></text>
  125. </hbox>
  126. </notebook>'
  127. fi