I've literally spent 20+ hours working on 2 or 3 lines of code and it's makin' me NuTzoid...
I'm the first to admit that shell programming is not my forte (although I've been using 3GLs and perl, etc for 40+ years... and Pupyy hisself for 15+ years)... but I just can't get my head around gtkdialog and how it does what it does when I try to use functions defined in the same shell script...
In short, the attached code works as expected if a button <action> item calls a defined function that manipulates a global variable... but if the function wants to use a parameter/argument, the parameter doesn't make it into the function.
I've made the code 'commentable' using one of Zigbert's hint post entries so the problem area is findable using '##'.
I've found the documentation for gtkdialog well organized but ultimately unhelpful as most of the syntax shown doesn't match any of the code I've looked at in Puppy's collection of scripts/tools - I've mainly been looking at the wallpaper setter, the quicksetup script and one of the examples for '5 minute front-end's shown elsewhere in this forum... but other than some help systems in the tools (which use 'case' statements, which is not relevant here), I can't find anything that uses functions with parameters in the same script (not running an external script file).. nor anything other than functions that just manipulate global variables.
I would greatly appreciate any pointers to how a function with parameters can be made to work when a button is pressed (and the parameter value is unknown, hence a case statement within the function is not relevant).
Using gtkdialog3 under Slacko 6.3.2...
Thanks a lot...
gtkdialog: Problems with 'actions' & functions... [SOLVED]
gtkdialog: Problems with 'actions' & functions... [SOLVED]
- Attachments
-
- funcerr.zip
- Example shell script that illustrates problems with gtkdialog that includes button actions that reference same-file user-defined functions that require parameters
- (985 Bytes) Downloaded 56 times
Last edited by ozboomer on Sun 28 Jun 2020, 02:46, edited 1 time in total.
[i]"I'm as free from money as a frog is from feathers"[/i]
-
- Posts: 159
- Joined: Sun 01 Mar 2020, 16:17
Hi.
I don't use e.g. XML=" gtkdialog code here "
I do use e.g. XML=' gtkdialog here '
So, if DIR2 is global then I write <action>open_filer '$DIR2'</action> and
if DIR2 is set by the gtkdialog gui I write <action>open_filer "$DIR2"</action>.
Works all the time.
I don't use e.g. XML=" gtkdialog code here "
I do use e.g. XML=' gtkdialog here '
Edit:
If using e.g. XML=' gtkdialog here ' you don't need to use this: stock=\"gtk-harddisk\".
Just this: stock="gtk-harddisk"
I don't use e.g. XML=" gtkdialog code here "
I do use e.g. XML=' gtkdialog here '
So, if DIR2 is global then I write <action>open_filer '$DIR2'</action> and
if DIR2 is set by the gtkdialog gui I write <action>open_filer "$DIR2"</action>.
Works all the time.
I don't use e.g. XML=" gtkdialog code here "
I do use e.g. XML=' gtkdialog here '
Edit:
If using e.g. XML=' gtkdialog here ' you don't need to use this: stock=\"gtk-harddisk\".
Just this: stock="gtk-harddisk"
Our Future Is Not Set In Stone
[url]https://www.youtube.com/channel/UCyfyaxCNMduwyXlQFRQKhhQ[/url]
[url]https://soundcloud.com/user-633698367[/url]
[b]My own build of Bionic64[/b]
[url]https://www.youtube.com/channel/UCyfyaxCNMduwyXlQFRQKhhQ[/url]
[url]https://soundcloud.com/user-633698367[/url]
[b]My own build of Bionic64[/b]
I understand that using double quotes is sometimes problematic in 'the shells' and they often need escaping... but so many of the Puppy tools use double quotes in their gtkdialog 'programs' (variable), I thought I'd just follow the 'standard'...
...but as i say, if I use a function (or the gtkdialog 'program') to manipulate a global, there's no trouble... and I might just wuss out and go that route... but it's still annoying that the <action> with a function + parameter(s) doesn't appear to work.. and the docs don't actually show how to structure such a usage (I find the 'explanation' about "type" and calls of most anything particularly confusing -- but then, maybe my brain is getting kinda slow )
...but as i say, if I use a function (or the gtkdialog 'program') to manipulate a global, there's no trouble... and I might just wuss out and go that route... but it's still annoying that the <action> with a function + parameter(s) doesn't appear to work.. and the docs don't actually show how to structure such a usage (I find the 'explanation' about "type" and calls of most anything particularly confusing -- but then, maybe my brain is getting kinda slow )
[i]"I'm as free from money as a frog is from feathers"[/i]
I had a quick look at your code. I think that you want to "escape" the $ sign.
That will prevent the $DIR2 variable from being evaluated at the time the XML string is created, which is before the gtkdialog program actually runs.
Instead the variable name and its current value will be passed to the subshell created by <action> during execution. So it can become an argument for
Your other method works because gtkdialog passes all its internal variables like DIR2 into the subshell.
Code: Select all
<action>open_filer \$DIR2</action>
Instead the variable name and its current value will be passed to the subshell created by <action> during execution. So it can become an argument for
Code: Select all
exec defaultfilemanager "$1" &
Code: Select all
exec defaultfilemanager "$DIR2"
gtkdialog: Problems with 'actions' & functions... [SOLVED]
rcrsn51, you *star*...
Simple. Effective. ..and sortof as expected, the escaping did the trick.
Many, many thanks for your help... and more blue ribbons to you
...as I scramble around on the floor, retrieving my hair that recently went a'wandering...
Simple. Effective. ..and sortof as expected, the escaping did the trick.
Many, many thanks for your help... and more blue ribbons to you
...as I scramble around on the floor, retrieving my hair that recently went a'wandering...
[i]"I'm as free from money as a frog is from feathers"[/i]
-
- Posts: 159
- Joined: Sun 01 Mar 2020, 16:17
In the beginning, when I started coding in shell script, I also used the double quotes. But I found it annoying to "escape" anything inside of the gtkdialog code. Then there was a discussion in programming section about using double or single quotes. And from that discussion I concluded using single quotes would fit my needs to code much better. So, I switched to use single quotes.
@rcrsn51
Thanks for mentioning the "escape". I forgot this the term. It just didn't came to mind.
@rcrsn51
Thanks for mentioning the "escape". I forgot this the term. It just didn't came to mind.
Our Future Is Not Set In Stone
[url]https://www.youtube.com/channel/UCyfyaxCNMduwyXlQFRQKhhQ[/url]
[url]https://soundcloud.com/user-633698367[/url]
[b]My own build of Bionic64[/b]
[url]https://www.youtube.com/channel/UCyfyaxCNMduwyXlQFRQKhhQ[/url]
[url]https://soundcloud.com/user-633698367[/url]
[b]My own build of Bionic64[/b]