Revision [32922]
This is an old revision of gtkdialogDocTips9.3 made by zigbert on 2020-07-31 02:45:25.
9. Tips and Tricks
1.
How to change the gui without restarting the appRecent Gtkdialog allows to hide/show widgets, To hide many widgets at once, you can hide a <hbox> or <vbox>. This will hide all widgets inside the box.
Another approach is to use the notebook attributes <notebook show-tabs="false" show-border="false">. Using several tabs in a notebook with hidden header, we can simulate a gui re-render. The only thing that is happening is that we switch tab, but since the user can't see those, he will be fooled...
More info at http://www.murga-linux.com/puppy/viewtopic.php?p=553833#553833.
2.
Control the icon/label of menuitemsIf you have met problems to show a certain icon and at the same time give it an unique label, this will illustrate how it is recommended to be implemented for the benefit of anyone and everyone.
<menuitem stock="gtk-undo" label="'$LOC118'" accel-key="0x07a" accel-mods="4"> <action>. '$APPDIR'/func -undo</action> <action>refresh:PLAYLIST</action> </menuitem>'
Doing it this way makes GTK+ deal with the left-to-right and right-to-left internationalisation of the icons if applicable. You might think this won't work because GTK+ will make a stock label "Undo", and it will. But, straight afterwards it will update the label with $LOC118. Because it initially was a stock label, use-underline is automatically set to true, and you can use underscores in your custom text.
3.
Understand the alignmentGtkdialog tends to align objects to the right side of the window. Exceptions are radiobuttons and checkboxes which are aligned to the left. It is easy to center whatever object in your gui. Here's some alignment explanation:
- <hbox><button>...</button></hbox> will place button to the right.
- <button>...</button> and button will fill whole line.
- <hbox homogeneous=true><button>...</button></hbox> will place button in horizontal center.
- <hbox homogeneous=true><vbox homogeneous=true><button>...</button></vbox></hbox> will place button in center both vertical and horizontal.
- <hbox><text xalign="0">...</text></hbox> will place text at left. xalign/yalign may hold 0, 1 or 2 for left, right or center. xalign/yalign works for other widgets as well. For buttons they describe placement of label rather than button itself.
Using vertical rows can be troublesome, because often, the label defines the width of the objects. This leads to different width and it all looks crappy. You can override this by the attribute <vbox width-request="x">...</vbox>, where x represent the number of pixels for the width of the row. There is also a height-request attribute.
4.
Insert empty gapStatic:
<text width-chars="40" height-request="120"><label>" "</label></text>
Dynamic:
(align one button to the left, another to the right)
<hbox space-expand="false" space-fill="false"> <button yes></button> <hbox space-expand="true" space-fill="true"><text><label>" "</label></text></hbox> <button no></button> </hbox>
5.
Window header iconYou can add your own icon (symlinks also work) if you place it in a gtk-theme directory structure as /usr/share/icons/hicolor/. ie. /usr/share/icons/hicolor/48x48/apps/games48.png
Now, run this command in the terminal to refresh the icon cache;
gtk-update-icon-cache -f -i /usr/share/icons/hicolor
Your gtkdialog code would look like this;
<window title="A GTKDialog" icon-name="games48" resizable="false" decorated="true">