HomePage > Software Index > Development > gtkdialog > Tips and Tricks

4.2 How to store window size/placement


This example shows how we can save settings for window size and placement for next startup. Be also aware that this solution makes it possible to let user rescale gui smaller than the default size. Normally you define the size of, for example, a <tree>, and the user can only resize the gui larger, but when using <window default_height="$HEIGHT" default_width="$WIDTH">, you don't need to define <height> and <width> for the tree widget.

save_geometry (){
  XWININFO=`xwininfo -stats -name SizeMe`
  HEIGHT=`echo "$XWININFO" | grep 'Height:' | awk '{print $2}'`
  WIDTH=`echo "$XWININFO" | grep 'Width:' | awk '{print $2}'`
  X1=`echo "$XWININFO" | grep 'Absolute upper-left X' | awk '{print $4}'`
  Y1=`echo "$XWININFO" | grep 'Absolute upper-left Y' | awk '{print $4}'`
  X2=`echo "$XWININFO" | grep 'Relative upper-left X' | awk '{print $4}'`
  Y2=`echo "$XWININFO" | grep 'Relative upper-left Y' | awk '{print $4}'`
  X=$(($X1-$X2))
  Y=$(($Y1-$Y2))
  echo "export HEIGHT=$HEIGHT" > /tmp/geometry
  echo "export WIDTH=$WIDTH" >> /tmp/geometry
  echo "export X=$X" >> /tmp/geometry
  echo "export Y=$Y" >> /tmp/geometry
  chmod 700 /tmp/geometry
}

export -f save_geometry
[ -f /tmp/geometry ] && . /tmp/geometry

export DIALOG="
<window title=\"SizeMe\" default_height=\"$HEIGHT\" default_width=\"$WIDTH\">
 <vbox>
  <frame>
   <text>
	<label>If you resize or move this window, it will be remembered for next time.</label>
   </text>
  </frame>
  <hbox>
   <button ok>
   </button>
  </hbox>
 </vbox>
 <action signal=\"hide\">save_geometry</action>
</window>"
gtkdialog --program=DIALOG --geometry +"$X"+"$Y"


Another approach for size/placement is to make a call of your app from the cli.

RIGHT=14; DOWN=36; WIDTH=80; HEIGHT=80 # define variables with defaults

GUI='
 <vbox>
  <button cancel></button>
 </vbox>'
gtkdialog -p GUI -G ${1-${WIDTH}x${HEIGHT}+${RIGHT}+${DOWN}}



Categories
CategoryGtkdialog
There are no comments on this page.
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki