xml_info 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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 doesn't work in combination with all gtk2 themes.
  34. #read config if exist
  35. [ -s $HOME/.config/ptheme/gtkdialog_active ] && . $HOME/.config/ptheme/gtkdialog_active
  36. [ ! "$XML_INFO_OPACITY" ] && XML_INFO_OPACITY=0.5 #background opacity to melt into different global gtk-themes. gradients does not support this.
  37. [ ! "$XML_INFO_COLOR1" ] && XML_INFO_COLOR1='#EDEAC6' #background color
  38. [ ! "$XML_INFO_COLOR2" ] && XML_INFO_COLOR2='#000000' #gradient spot color
  39. [ ! "$XML_INFO_MODE" ] && XML_INFO_MODE="flat" #drawing mode
  40. #build background svg for info-widget
  41. export FLAT='<svg version="1.0"><rect width="100" height="100" style="fill:'${XML_INFO_COLOR1}';fill-opacity:'${XML_INFO_OPACITY}';stroke:none"/></svg>'
  42. export GRADIENT='
  43. <svg version="1.1" width="2000" height="1000">
  44. <defs>
  45. <linearGradient id="LG_01" x1="30" y1="95" x2="-50" y2="-125" gradientUnits="userSpaceOnUse">
  46. <stop style="stop-color:'${XML_INFO_COLOR1}';stop-opacity:1" offset="0" />
  47. <stop style="stop-color:'${XML_INFO_COLOR2}';stop-opacity:1" offset="1" />
  48. </linearGradient>
  49. </defs>
  50. <rect width="2000" height="1000" style="fill:'${XML_INFO_COLOR1}';stroke:none"/>
  51. <rect
  52. style="fill:url(#LG_01);fill-opacity:1;stroke-width:0"
  53. width="250" height="200"/>
  54. </svg>'
  55. case $XML_INFO_MODE in gradient) BGSVG="$GRADIENT";; *) BGSVG="$FLAT";; esac
  56. echo "$BGSVG" > /tmp/xml_info.svg
  57. #redefine gtk-theme
  58. echo 'pixmap_path "/tmp/"
  59. style "Bgsvg" { bg_pixmap[NORMAL] = "xml_info.svg" }
  60. widget "*BgSVG" style "Bgsvg"
  61. style "ScaleGrip" { GtkStatusbar::shadow_type = GTK_SHADOW_NONE }
  62. widget "*ScaleGrip" style "ScaleGrip"' > /tmp/gtkrc_xml_info
  63. #combine theme stuff with system themes
  64. if [ ! "$GTK2_RC_FILES" ]; then
  65. export GTK2_RC_FILES=~/.gtkrc-2.0:/tmp/gtkrc_xml_info
  66. else
  67. export GTK2_RC_FILES="$GTK2_RC_FILES:/tmp/gtkrc_xml_info"
  68. fi
  69. ;;
  70. fixed)
  71. HEIGHT='space-expand="false" space-fill="false"'
  72. ;;
  73. 0|scale|' '|'')
  74. HEIGHT='space-expand="true" space-fill="true"'
  75. ;;
  76. *[0-9]*)
  77. [ $1 != 0 ] && HEIGHT="height-request=\"$1\" space-expand=\"false\" space-fill=\"false\""
  78. ;;
  79. *)
  80. HEIGHT='space-expand="true" space-fill="true"'
  81. ;;
  82. esac
  83. #define icon
  84. case $2 in
  85. /*)
  86. #icon from file
  87. ICON_INPUT="<input file>${2}</input>"
  88. case $3 in 0) ICON_HEIGHT="";; *) ICON_HEIGHT="<height>${3}</height>";; esac
  89. ICON="<vbox><pixmap>${ICON_INPUT}${ICON_HEIGHT}</pixmap></vbox>"
  90. ;;
  91. 0|none|' '|'')
  92. ICON=""
  93. ;;
  94. *)
  95. case $2 in
  96. *.svg)
  97. #icon from puppy stock
  98. ICON_INPUT="<input file>/usr/share/pixmaps/puppy/${2}</input>"
  99. case $3 in 0) ICON_HEIGHT="";; *) ICON_HEIGHT="<height>${3}</height>";; esac
  100. ICON="<vbox><pixmap>${ICON_INPUT}${ICON_HEIGHT}</pixmap></vbox>"
  101. ;;
  102. *)
  103. #icon from gtk stock
  104. ICON_INPUT="<input file stock=\"gtk-${2}\"></input>"
  105. case $3 in [1-6]) ICON_HEIGHT=" icon_size=\"${3}\"";; 0|*) ICON_HEIGHT="";; esac
  106. ICON="<vbox><pixmap${ICON_HEIGHT}>${ICON_INPUT}</pixmap></vbox>"
  107. ;;
  108. esac
  109. esac
  110. if [ "$3" ] || [ "$4" ] || [ "$5" ]; then #generate XML code
  111. echo '
  112. <notebook name="BgSVG" show-tabs="false" '${HEIGHT}'>
  113. <hbox '${HEIGHT}'>
  114. <vbox space-expand="false" space-fill="false">
  115. <hbox border-width="10">
  116. '${ICON}'
  117. <text width-request="5"><label>""</label></text>
  118. <vbox space-expand="false" space-fill="false">'
  119. [ "$4" ] && echo '<text xalign="0" use-markup="true"><label>"'$4'"</label></text>'
  120. [ "$5" ] && echo '<text xalign="0" use-markup="true"><label>"'$5'"</label></text>'
  121. [ "$6" ] && echo '<text xalign="0" use-markup="true"><label>"'$6'"</label></text>'
  122. [ "$7" ] && echo '<text xalign="0" use-markup="true"><label>"'$7'"</label></text>'
  123. [ "$8" ] && echo '<text xalign="0" use-markup="true"><label>"'$8'"</label></text>'
  124. [ "$9" ] && echo '<text xalign="0" use-markup="true"><label>"'$9'"</label></text>'
  125. echo '</vbox>
  126. </hbox>
  127. </vbox>
  128. <text space-expand="true" space-fill="true"><label>""</label></text>
  129. </hbox>
  130. </notebook>'
  131. fi