Revision history for gtkdialogDocTips4.2


Revision [33322]

Last edited on 2023-02-24 06:48:17 by zigbert
Additions:
[[HomePage]] > [[SoftwareIndex|Software Index]] > [[SoftwareDevelopment|Development]] > [[gtkdialog|gtkdialog]] > [[gtkdialogDocTips|Tips and Tricks]]
===@@**#%[[gtkdialogDocTips4.1|❰❰❰ Previous]]#% #%[[gtkdialogDocTips|Index]]#% #%[[gtkdialogDocTips5|Next ❱❱❱]]#%**@@===
Deletions:
[[HomePage]] > [[SoftwareIndex Software Index]] > [[SoftwareDevelopment Development]] > [[gtkdialog gtkdialog]] > [[gtkdialogDocTips Tips and Tricks]]
@@**#%[[gtkdialogDocTips4.1|❰❰❰ Previous]]#% #%[[gtkdialogDocTips|Index]]#% #%[[gtkdialogDocTips5|Next ❱❱❱]]#%**@@


Revision [32891]

Edited on 2020-07-28 05:15:45 by zigbert
Additions:
====4.2 How to store window size/placement====
Deletions:
====4. How to store window size/placement====


Revision [32888]

Edited on 2020-07-28 05:11:48 by zigbert
Additions:
====4. How to store window size/placement====
@@**#%[[gtkdialogDocTips4.1|❰❰❰ Previous]]#% #%[[gtkdialogDocTips|Index]]#% #%[[gtkdialogDocTips5|Next ❱❱❱]]#%**@@
Deletions:
====4. The benefits of a config file====
A config file is a nice way to store the settings in your program. At next startup, it will show the settings like you left them last time.
==**Set default status of radiobuttons, Comboboxes...**==
By default, gtkdialog always activates the first ##[[http://01micko.com/reference/radiobutton.html <radiobutton>]]## and the first list-item for ##[[http://01micko.com/reference/combobox.html <combobox>]]##.
An easy way to use a config file is to run it like an ordinary bash-script, and include variable definitions in it. It is most common to keep config files in home directory as a hidden file ($HOME/.testrc). The file might look like this:
COMBOBOX="item 3"
ENTRY="default text"
RADIOBUTTON1="false"
RADIOBUTTON2="true"

Now let's go to the main script. For the ##[[http://01micko.com/reference/radiobutton.html <radiobutton>]]## and the ##[[http://01micko.com/reference/entry.html <entry>]]##, we set the ##<default>## tag to the corresponding variable in the config file. Since the ##[[http://01micko.com/reference/combobox.html <combobox>]]## doesn't support the ##<default>## tag, we need a workaround. We simply build the ##[[http://01micko.com/reference/combobox.html <combobox>]]## item-list so show our saved variable first.
#in case no testc file (first run), build the file
[ ! -s $HOME/.testrc ] && echo -e -n 'COMBOBOX="item 3"\nENTRY="default text"\nRADIOBUTTON1="false"\nRADIOBUTTON2="true"\n' > $HOME/.testrc
. $HOME/.testrc
#define combobox list items
COMBOBOX_ITEMS="<item>$COMBOBOX</item>" #stored value should be first in list
for I in 1 2 3 4; do COMBOBOX_ITEMS=`echo "$COMBOBOX_ITEMS<item>item $I</item>"`; done
export main="
<window title=\"The benefits of a config file\">
<frame The first item of list is the default choice in a Combobox>
<combobox>
<variable>COMBOBOX</variable>
$COMBOBOX_ITEMS
</combobox>
<frame If nothing else is set, the first radiobutton is the active one>
<radiobutton>
<variable>RADIOBUTTON1</variable>
<label>Yes I am</label>
<default>$RADIOBUTTON1</default>
</radiobutton>
<radiobutton>
<variable>RADIOBUTTON2</variable>
<label>No I'm not</label>
<default>$RADIOBUTTON2</default>
</radiobutton>
<frame Fetch entry-value from config file>
<entry>
<variable>ENTRY</variable>
<default>$ENTRY</default>
</entry>
<button ok></button>
gtkdialog -p main > $HOME/.testrc
The last codeline redirects output (variable values) to our config file instead of to the terminal.
Note that line 2 starts with a dot. It makes a huge difference if you skip it.
. $HOME/.config - run script as a childprocess as the main process. The variable values in the config file are reachable for the main script.
$HOME/.config - run script as a new process as the main process. The variable values in the config file will NOT be reachable for the main script.
==**How to store window size/placement**==


Revision [32887]

The oldest known version of this page was created on 2020-07-28 05:10:34 by zigbert
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki