Page 1 of 1

a new spin on gtkdialog NOT using export

Posted: 26 Apr 2012, 14:09
by bigbass
After a lot of thinking about how gtkdialog exports an enormous string into global memory
and most of the time as MAIN_DIALOG= I decided to try another "local" way of handling strings instead
this is a modular approach in little blocks that you add

# a new spin on gtkdialog by Joe Arose bigbass

# 1.) We won't export a large string into global memory now this acts as "local" variables instead
# 2.) We will take input -s, --stdin Get the GUI description from standard input.

Code: Select all

TEXT='Hello'
echo '<text><label>Content of variable is: '"$TEXT"'</label></text>'  | gtkdialog -s 

Code: Select all

TEXT2='Hello again '
echo '<text><label>Content of variable is: '"$TEXT2"'</label></text>'  | gtkdialog -s 
#--------------------------
# original example of using gtkdialog
#--------------------------

#!/bin/bash

export MAIN_DIALOG='
<vbox>
<text>
<label>This is a static text.</label>
</text>
<hbox>
<button ok></button>
<button cancel></button>
</hbox>
</vbox>
'

gtkdialog --program=MAIN_DIALOG



# here is another example trying to maintain a readable XML format
#--------------------------
# a new way of using gtkdialog without export
#--------------------------

Code: Select all

echo ' <vbox>
           <text>
            <label>This is a static text.</label>
           </text>   
           <hbox>
            <button ok>
            </button>
            <button cancel>
            </button>
         </hbox>
        </vbox>'| gtkdialog -s

Re: a new spin on gtkdialog NOT using export

Posted: 27 Apr 2012, 03:19
by brokenman
A novel approach. It certainly brings up windows much quicker. Some of my larger apps can take up to 5-6 seconds to export all variables. This method does have its drawbacks though.

I've also been playing around with a similar format:

TEXT="Hello world"
gtkdialog -s <<< "<text><label>$TEXT</label></text>"

Was also looking at FIFO's but they can be processor hogs. The other method is to load the dialog directly from a file ... but i prefer to keep everything in the one script and this method requires having multiple files to handle multiple functions.

Re: a new spin on gtkdialog NOT using export

Posted: 27 Apr 2012, 14:58
by bigbass
Hey brokenman

The other method is to load the dialog directly from a file
thats the best way that was documented but I couldn't get a working example going to test it :%)


I am looking for a way to speed things up I hope ...

without the export a config file can be sourced also
makes adjusting code much easier lets say version updates
or other languages that could be added or optional messages and you can preset some values making
it a lot easier than reading through many of lines of code just to make a simple change

we make a config file that contains the variables
you could make an all in one like this


make the config file then source it :)

it wont meet all needs but the config file alone is still a good idea
and this may come in handy getting values into gtkdialog


Code: Select all

cat << 'EOF' >hello.conf
TEXT='Hello'   
TEXT2='Hello again '  
EOF

. hello.conf
echo ' <vbox>
           <text>
            <label>This is a static text.</label>
           </text>   
           <text>
            <label>These are variables that were sourced '"$TEXT"'  </label>
           </text>            
           <text>
            <label>These are variables that were sourced '"$TEXT2"'  </label>
           </text>         
           <hbox>
            <button ok>
            </button>
            <button cancel>
            </button>
         </hbox>
        </vbox>'| gtkdialog -s

Re: a new spin on gtkdialog NOT using export

Posted: 27 Apr 2012, 18:56
by brokenman
Yeah i like the conf file idea. PPM uses a similar idea ... there is a function in /usr/lib/ppm containing all variables that i may need to change, and of course there are user config files in /etc.

I am all for speeding things up ... and have even resorted to starting a quick little distraction window, perhaps asking a question while the real deal loads in the background. :oops:

Re: a new spin on gtkdialog NOT using export

Posted: 28 Apr 2012, 15:29
by bigbass
Hey brokenman

here is another odd way of doing this from a file
finally figured out how to use the --file= option :)
it took me more time than I want to confess :oops:

I didnt find an example using this the idea was "implied" though in the documentation
to speed things up

if we can get variables in without using export
we have the best of both worlds

now here is the way to call it from a script
maybe it could get added to the official examples

Code: Select all

#!/bin/sh
# call this launch-file2 make it executable 
gtkdialog --file=90.01-use_the_file_option
     
call this 90.01-use_the_file_option Note there is no #! /usr/local/bin/gtkdialog -f as a header

Code: Select all

<vbox>
  <button>
    <label>Xterm</label>
    <action>xterm&</action>
  </button>
  <button>
    <label>Exit</label>
  </button>
</vbox>

Re: a new spin on gtkdialog NOT using export

Posted: 29 Apr 2012, 14:21
by brokenman
Starting from a file is much quicker than exporting stuff too. I use the #!/bin/bash shebang without problems ... and interestingly you can write notes after the XML code with no adverse effect.

Code: Select all

#!/bin/bash
<vbox>
  <button>
    <label>They called me a button</label>
    <action>echo "and i believed them"</action>
  </button>
  <button>
    <label>Exit</label>
  </button>
</vbox>

This button has an identity crisis. This note will not harm any code.
From a console: gtkdialog -f testfile.sh

Re: a new spin on gtkdialog NOT using export

Posted: 29 Apr 2012, 21:28
by bigbass
Hey brokenman thanks for the code snippet for calling from the command line


brokenman
I use the #!/bin/bash shebang without problems ... and interestingly you can write notes after the XML code with no adverse effect.
I was curious to why so I poked around in the sources
line 326 gtkdialog.c
/* FIXME: We read the first line of file and drop it. It is
* required because the #! is not included in the language.
*/
so anything on the first line gets dropped
I looked at the lexer.c and its a monster CASE
(was much easier in BaCon I have no idea how to do that in C )
looking for the preset keywords as numbers then returns
the XML tag so... it probably falls through and is cut out of the acceptable code
the bad part is that you cant use any good code after that gets cut too
it would be cool if we could trick it to add comments in the main code though

try adding this to the first line :)

Code: Select all

#!/bin/bash This line is ignored watch lets break some rules  > ><<< ><<> <><>>>> that all folks 
well you could date it and add the author and a brief one line description if you wanted to


I found something interesting in the sources that I havent seen these tags used
"output", "if", "then", "endif", "do" 0

hmm ..there is no tag endif though <if></if>works
no tags set for "do" or "then" also

this allowed me to see all of thunors added tags in one place the ones he added
in gtkdialog_lexer.c so it was a good discovery will save a lot of time now
would come in handy to see if you have a new tag in use

/**************************************************************
* Thunor: Newly supported widgets.
**************************************************************/

<hseparator></hseparator>
<vseparator></vseparator>
<comboboxtext></comboboxtext>
<comboboxentry></comboboxentry>
<hscale></hscale>
<vscale></vscale>
<spinbutton></spinbutton>
<timer></timer>
<togglebutton></togglebutton>
<statusbar></statusbar>
<colorbutton></colorbutton>

Re: a new spin on gtkdialog NOT using export

Posted: 30 Apr 2012, 13:41
by brokenman
Ah thats right! Now i remember thunor talking about the first line getting dropped when called through gtkdialog.

Thanks for the location tip. I wasn't aware of these ones and was using gtk styles to get colors. Cool!
<togglebutton></togglebutton>
<colorbutton></colorbutton>

"output", "if", "then", "endif", "do" 0
Wow ... sudden flashbacks ... just missing 'goto' lol.

I often comment my gtkdialog scripts as i go using double hash (##) and then use a launcher script to remove all lines with double hash.
something like:
cat myscript.sh|sed '@##@d' > /tmp/myscript && sh /tmp/myscript

I'd love to find a way to trick it into ignoring (or removing) these comment as it does with the first line. Must be possible ... will play around later.

Re: a new spin on gtkdialog NOT using export

Posted: 30 Apr 2012, 14:22
by bigbass
Hey brokenman
I often comment my gtkdialog scripts as i go using double hash (##) and then use a launcher script to remove all lines with double hash.
something like:
cat myscript.sh|sed '@##@d' > /tmp/myscript && sh /tmp/myscript
great! no hacking sources needed and its easy to remember the syntax
'@##@d' that looks to me like the car on the flintstones :lol:
you see the big wheel in the front and back no roof so its a convertible

brokenman
I'd love to find a way to trick it into ignoring (or removing) these comment as it does with the first line. Must be possible ... will play around later.
Yes! I found a post from a friend that has the solution
I worked with him many times before so it will be easy
to get it added

He (Gilbert Ashley aka amigo ) did this for a gtk1 backport of gtkdialog
so the patch would be manually added
Posted: Wed Mar 21, 2012 2:50 pm Post_subject:

amigo

Meanwhile, I've had an idea for awhile and implemented it.
Have you noticed that you can't embed comments inside
the xml-ish code for gtkdialog? There was even a posting about
it in zigberts gtkdialog tips thread. At the time I thought:
How difficult could that be to implement -a tag which does nothing?
Of course, our flex/bison skills are null, but still...
Anyway, today I started having a look.
At first the syntax wasn't be accepted and
I thought I needed some kind of dummy widget or to have some code
in several places. Turned out to need only a one-line patch -in fact it
only takes 14 chars of code to implement:

Code: Select all

--- ./src/lexer.l.00   2012-03-19 12:40:28.000000000 +0000
+++ ./src/lexer.l   2012-03-21 20:23:05.000000000 +0000
@@ -33,6 +33,7 @@
        return TAG_ATTR_NAME;
                }
 
+\<!-.*-!\> { ; }
 
 \<title\>    { Token="<title>"; return(BEGINTITLE); }
 \<\/title\>  { Token="</title>"; return(ENDTITLE);   }


Re: a new spin on gtkdialog NOT using export

Posted: 30 Apr 2012, 16:35
by brokenman
Aaah ... thats the stuff i was looking for! Yaba daba doooo!

Re: a new spin on gtkdialog NOT using export

Posted: 30 Apr 2012, 21:42
by bigbass
Hey brokenman
after thinking about this more this is the best solution

Code: Select all

cat myscript.sh|sed '@##@d' > /tmp/myscript && sh /tmp/myscript
1. because you don't have to recompile sources and remember a new comment tag
2. you maintain backward compatibility
3 . I have a hard time remembering syntax and I wont forget this one :good:

We know it could be done though...and how but

Reminds me of a quote
Knowledge is knowing the tomato is a fruit, wisdom is not putting in your fruit salad.


Joe