Gtkwialog project

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Message
Author
disciple
Posts: 6984
Joined: Sun 21 May 2006, 01:46
Location: Auckland, New Zealand

#41 Post by disciple »

They are part of gtk, and you can't add more just by putting images somewhere.
Do you know a good gtkdialog program? Please post a link here

Classic Puppy quotes

ROOT FOREVER
GTK2 FOREVER

wiak
Posts: 2040
Joined: Tue 11 Dec 2007, 05:12
Location: not Bulgaria

#42 Post by wiak »

disciple wrote:They are part of gtk, and you can't add more just by putting images somewhere.
Yes.

https://developer.gnome.org/gtk2/stable ... Items.html

You can register your own icons though. This is pinstall from weX:

Code: Select all

#!/bin/sh

gtk-update-icon-cache -f -i /usr/share/icons/hicolor
weX icon is provided in the dotpet in directory /usr/share/icons/hicolor/48x48/apps/wex48.png

Code: Select all

<window title="weX" icon-name="wex48" resizable="false">
So if you wanted that icon on a button, you could use:

Code: Select all

<button>
 <input file icon="wex48"></input>
 <variable>WHATEVER</variable>
 <action>command_string</action>
</button>
https://developer.gnome.org/icon-theme-spec/

In wex, though, button icons are in /usr/local/share/pixmaps/wex
They are used directly via their filepath:

Code: Select all

   <button tooltip-text="$(gettext 'RECORD/CONTINUE RECORD')">
    <input file>/usr/local/share/pixmaps/wex/wex_record.png</input>

wiak
Posts: 2040
Joined: Tue 11 Dec 2007, 05:12
Location: not Bulgaria

#43 Post by wiak »

I mentioned that you cannot mix -a and -b modes of gtkwialog. That is not really an issue since most of the time -b (for blocking) would be the best mode to use. However -a (for asynchronous non-blocking) mode is super-efficient for starting up a program effectively in the background, without needing any shell process to also be called for job control purposes (though programmer always has the choice).

Whilst I thus intend the current commandline switch selectable operation 'modes' to remain stable in terms of future compatability, I am looking into adding an optional facility to start up a program in non-blocking background mode even when -b mode otherwise chosen. Then we will get benefit of both at same time - no shell process command required yet with ability to either block till a command finishes before returning control to the dialog or to return immediately (leaving command program fork/exec'd and running in its own process) like with overall -a mode.

I'll only try that alteration in a testing branch however, and it will not at all effect the current gtkwialog operation anyway. i.e. I will ensure the interface remains stable for any additions ensuring full backwards compatibility.
-------------------------

In short explanation:

Neither -a nor -b modes involve running any shell as part of processing an <action>command_string</action>. But one of the jobs of a shell is to provide job control (shell uses a symbol & in relation to that). So if you want to background a process when currently using the gtkwialog -b <action> mode, you would need to start up a shell (since the command_string you give is what you get...):

Code: Select all

<action>sh -c "command &"</action>
where, command, might for example be leafpad.

whereas, you can fork/exec a process in non-blocking -a mode simply with:

Code: Select all

<action>command</action>
No & symbol being required (and wouldn't mean anything anyway since no shell being used to run this command). In this -a mode once command is fork/exec'd in this way, control returns immediately to the dialog (i.e. non-blocking) so command effectively 'runs in the background' albeit without needing any controlling shell.

Wouldn't it be nice when using the -b mode to also be able to avoid the need for starting up a shell to run a process in its own space (by which I mean fork/exec'd and not blocking). A method for doing that is what I plan to implement, but again it won't upset any current behaviours in my plan (will be using & symbol or similar to simply say use -a mode on this particular <action>. When no shell process is being run the & symbol doesn't mean anything special anyway...).

Funny thing about legacy gtkdialog, if most people were like me, they probably didn't realise a /bin/sh -c process was being used with <action>command_strings</action>. Rather, as programmers, we just came to learn by word of mouth and trial and error, what worked and what didn't (to some extent). Big shock therefore was that bash -f export didn't work with <action>bash -c calls if underlying system shell dash or ash... There would be some other not well understood subtleties. In other words, as I've said before, with legacy gtkdialog, <action>bash -c function_name</action>, for example doesn't mean what it says (bash -c function_name). Rather it means:

/bin/sh -c "bash -c function_name", which is really quite different (i.e. with old gtkdialog you don't really get what you put in... And similarly, other actions don't really do what the visible action command_string syntax alone suggests (you have to always remember that hidden /bin/sh -c with legacy gtkdialog (and some of its negative consequencies).

wiak
Last edited by wiak on Fri 01 Jun 2018, 05:20, edited 1 time in total.

wiak
Posts: 2040
Joined: Tue 11 Dec 2007, 05:12
Location: not Bulgaria

#44 Post by wiak »

Aside from the above post idea, my plan is to now create, possibly slightly improved, versions of cast2chrome, precord, and wex, (in that order since I am using cast2chrome on a daily basis myself) that use gtkwialog -b mode such that these will be able to be run in Debian with dash, or Slitaz with ash. Not a big job. Then I'll take a look at some of the Dog utils and tackle some of them if necessary (for my own use at least) in case no-one else finds time for that or chooses not to.

wiak

wiak
Posts: 2040
Joined: Tue 11 Dec 2007, 05:12
Location: not Bulgaria

detaching stdout of <action> commands

#45 Post by wiak »

Detaching stdout of <action> commands (issue when gtkdialog or gtkwialog output is being assigned to a variable via command-substitution):

An interesting practical and illustrative example discussed on Gtkdialog Tips thread; I've posted gtkwialog related info about it there:

http://www.murga-linux.com/puppy/viewto ... 141#994141

wiak
Posts: 2040
Joined: Tue 11 Dec 2007, 05:12
Location: not Bulgaria

#46 Post by wiak »

I've translated quite a few of the gtkdialog examples from zigbert's Gtkdialog Tips thread to use gtkwialog -b mode.

I did it in a hurry so haven't checked if my converted versions will also all run on systems with dash as system shell - but most will; I think a couple might need a few more tweeks. Find them in post 4 of this thread here. Hopefully they will help you convert your own programs should you want to try running them on distributions that have dash or ash or bash as their system shell:

http://www.murga-linux.com/puppy/viewto ... 443#993443

I'm going to make a start converting some of my own programs now.

wiak

User avatar
fredx181
Posts: 4448
Joined: Wed 11 Dec 2013, 12:37
Location: holland

#47 Post by fredx181 »

Hi wiak, Just want to say (again) that you've done a great job, not only your discovery resulting in creating gtkwialog, but also the excellent documentation, examples, technical background, etc... etc... Hats Off !

One thing I wonder about, looking at your DebianDog/gtkwialog repository:
I see 7 commits from you containing change of Readme and some more, but are the differences for gtkwialog compared to original gtkdialog there ?

Fred

wiak
Posts: 2040
Joined: Tue 11 Dec 2007, 05:12
Location: not Bulgaria

#48 Post by wiak »

fredx181 wrote: One thing I wonder about, looking at your DebianDog/gtkwialog repository:
I see 7 commits from you containing change of Readme and some more, but are the differences for gtkwialog compared to original gtkdialog there ?
pu
Fred
Not yet, Fred, been too busy and since considering minor code tweeks and not actually using github during my developments I'm not quite ready to push the source code there yet. But will happen soon enough. There is one particular area of code in gtkdialog I want to double-check how it works, just in case I've missed something, and also I want to convert a couple of my apps just as a double check. I've been converting precord, which has quite a lot of bash-related export code so a good test - haven't quite finished it yet. After that I'll push up the source code since it will be ready for proper testing and recompiling and pull requests and so on.

wiak

wiak
Posts: 2040
Joined: Tue 11 Dec 2007, 05:12
Location: not Bulgaria

#49 Post by wiak »

What an amazing job Thunor did of re-factoring the original gtkdialog code. I've been reading through some of it and the amount of work he did is far more enormous than any non-C programmer would imagine. It was far from just better implementing the Widgets to more closely match their inherent GtkDialog system capabilities. It would take a near obsession to learn the whole inner-workings of gtkdialog that Thunor obviously did.

My addition is simple, but is hopefully very useful for the very small effort I needed to expend implementing it. Most of my effort was simply background research to try find out why bash -f export didn't work well with gtkdialog - and looking at YAD code gave me the simple solution to that - just a small number of changes needed to gtkdialog itself over a very few files and thus with predictable results since nothing else needed to be touched (so far anyway... luckily).

Just a pity, I feel, that gtkdialog hadn't been written to use vbox and hbox constructions with simple curly bracket groupings (instead of pseudo xml tags) as used in IUP (with Lua and the other languages it supports), which is much nicer to program in (simpler, easier to read, supports comments, and harder to make mistakes in).

wiak

wiak
Posts: 2040
Joined: Tue 11 Dec 2007, 05:12
Location: not Bulgaria

#50 Post by wiak »

One, apparently rare, limitation found using gtkwialog on systems that do not use bash as the underlying system shell /bin/sh
(and legacy gtkdialog has that limitation anyway)

I spent one hour tonight converting Precord to use gtkwialog -b. That went fine and worked perfectly when underlying system shell was bash (which is no big deal since old version worked under legacy gtkdialog too with bash as system shell...).

But when I changed /bin/sh to be dash, the legacy gtkdialog version simply couldn't work at all because Precord is written in bash and uses a great many bash export -f functions. That being of course known and expected... But:

Though all the <action> contructs in the gtkwialog -b version of Precord can all find these functions, there is one other construct that happens to be used in current Precord that also calls up one of the bash functions and that is the <input> tag in one of the entry widgets (which calls bash function DateFile1). Unfortunately, none of the code I have added helps with that <input> tag situation, so that is a current limitation. Indeed, despite studying the code, I frankly do not yet know how <input> calls up exported functions - it is certainly not via the system() call.

I can only surmise, from the complex code involved, that it directly reads the function code from the shell environment, via perhaps a gtk library call, and then sends that function code to be processed via the mechanisms I have optionally modified. If so, legacy gtkdialog <input> command processing may expect a shell to interpret the function via system(), which does of course only work if underlying system shell is bash. So calling bash functions from <input> constructs certainly won't work with legacy gtkdialog.

Unfortunately, if my surmise turns out to be correct, then because the execution of that bash exported function requires an instance of bash to be running, which isn't the case with the gtkwialog -a or -b mod glib async or sync calls either (which don't call up any shell process) then that construct simply cannot work whichever mode is used when bash is not the underlying system shell. It is a small limitation, but one that has to be borne in mind.

In summary:

Though gtkwialog -b (or -a) mode can be used to convert many or even most legacy gtkdialog apps to work with dash, it does currently have at least this one newly found limitation:

you cannot call bash functions from <input> tags, only from <action> tags if underlying system shell is dash. There may be similar limitation; just remember -a and -b modes are specifically mainly related to <action>tag commandline_string opertion
I will have to therefore make a slight modification to Precord to workaround that remaining dash-related issue.

The easiest way around this for new programs is to never use exported bash functions in <input> tags.

Example of code that will not work when dash is the system shell:

Here is a simple exemplar program that will work using /bin/sh as bash but not when /bin/sh is dash, despite gtkwialog -b being used. Doesn't work with legacy gtkdialog either of course, when /bin/sh is dash:

Code: Select all

#! /bin/bash

hello (){
 echo "hello world"
}
export -f hello

export MAIN_DIALOG='
<vbox>
 <entry>
  <variable>ANYTHING</variable>
  <input>hello</input>
 </entry>
</vbox>
'

gtkwialog -b --program=MAIN_DIALOG
I'll write more on this limitation if I find more or any solution in code, but truthfully I think it probably has to be accepted as a limitation of both gtkdialog and gtkwialog. Fortunately, it is a limitation that can easy be avoided in the case of gtkwialog; not gtkdialog which cannot work at all with dash as system shell when bash exported functions being used anywhere.

Hopefully you understand what I'm talking about, but if not, just accept that as one limitation that has to be avoided if writing dash compatible apps in this manner.

I'm now looking through some other familiar bash/gtkdialog to see which will suffer from this limitation. I'll list any I've looked at here:

1. peasywifi, does not use <input> tags in the above manner so should convert nicely with gtkwialog -b for use with underneath dash shell (though its shebang would also need changed to #!/bin/bash for the exported functions to work.

2. My program cast2chrome should also convert nicely.

3. As fredx181 has I believe already proved, debdog-install (and xenialdog-install) should convert nicely (don't think these call exported functions anyway)

4. My program domyfile should convert nicely.

5. Despite being derived from Precord (albeit a long chain of ancestry) it looks like weX will convert nicely.

6. peasypdf should convert nicely (and probably most peasy apps).

7. ffconvert looks like it will convert okay.

Hmmm... I can't find any other problematic ones... only Precord... trust me to try to convert that first! ;-)

Quite a number of old Puppy util/apps don't use bash export -f at all, so they shouldn't generally need to be converted at all - just use gtkwialog in legacy mode (needs no switch for that).

Oh well, time will tell - I'll try converting cast2chrome next and come back to finish Precord later. If there is any particular app you'd like me to check (and maybe even convert), just let me know.

All going well with a couple of conversions in the next few days, I'll upload the source code to the DD organization github repository thereafter since I'm not planning any non-compatible changes if most basically converting fine.

wiak

anikin
Posts: 994
Joined: Thu 10 May 2012, 06:16

#51 Post by anikin »

wiak,

1. Can you, please have a look at the original mount-wizard script (see attachment). It is fred's mod of iguleder's script, that I brought to old DD. Will it work under dash? Unfortunately, It's been removed from the repos.

2. Please, also have a look at peasyglue - will it work with dash?

Thank you in advance,
Attachments
mount-wizard.gz
(1.96 KiB) Downloaded 146 times

wiak
Posts: 2040
Joined: Tue 11 Dec 2007, 05:12
Location: not Bulgaria

#52 Post by wiak »

I'll have a try tomorrow anikin cos its late night/morning here. I'm pretty sure peasyglue will work. Have to check out mount wizard.

Just got Precord running with dash as system shell underneath - first time I've had that on dash system, though did need slight tweak I mentioned in earlier post.

wiak

User avatar
fredx181
Posts: 4448
Joined: Wed 11 Dec 2013, 12:37
Location: holland

#53 Post by fredx181 »

Hi wiak, I had a look at pburn and it seems the only exported function is in /usr/local/pburn/box_tail and it has "tailing" exported to a <input>.... line
If you have time, can you have a look ?

Fred

wiak
Posts: 2040
Joined: Tue 11 Dec 2007, 05:12
Location: not Bulgaria

#54 Post by wiak »

@anikin: what is the issue with that mount-wizard with dash anyway. I can't see what existing problem would be at a glance. There are no export -f functions in it, which is main problem gtkwialog solves (allows bash exported functions). If its some kind of permission problem that would be a different matter altogether; please let me know.

peasyglue, on the other hand, needs gtkwialog -b, and I'll try that out - it should work then.

wiak

wiak
Posts: 2040
Joined: Tue 11 Dec 2007, 05:12
Location: not Bulgaria

#55 Post by wiak »

fredx181 wrote:Hi wiak, I had a look at pburn and it seems the only exported function is in /usr/local/pburn/box_tail and it has "tailing" exported to a <input>.... line
If you have time, can you have a look ?

Fred
Yep, I'll add that to tomorrows list. If there is an <input> issue it can always be worked around as I managed with Precord.

EDIT: I see what you mean, in the while construct... tailing. Yes, that'll need a workaround I think. I'll try tomorrow later - can be done that's for sure.

wiak

anikin
Posts: 994
Joined: Thu 10 May 2012, 06:16

#56 Post by anikin »

@wiak

My bad, I must have panicked and confused myself and you. Mount-wizard does work with both dash and bash. Thank you for setting this straight!

wiak
Posts: 2040
Joined: Tue 11 Dec 2007, 05:12
Location: not Bulgaria

#57 Post by wiak »

Code: Select all

#! /bin/bash 
printf '
 #!/bin/bash
 echo "hello world"
' >/tmp/hello
chmod +x /tmp/hello


export MAIN_DIALOG=" 
<vbox> 
 <entry> 
  <variable>ANYTHING</variable> 
  <input>/tmp/hello</input> 
 </entry> 
</vbox> 
"

gtkwialog -b --program=MAIN_DIALOG
Or better maybe sometimes to use a HERE document instead of printf:

Code: Select all

cat >/tmp/hello <<'here_hello_function'
#! /bin/bash 
echo "hello world"
here_hello_function
chmod +x /tmp/hello
Single quoting the <<'here_hello_function' to turn off parameter substitution in the HERE document body.

The above is a workaround to the <input> bash exported function issue I posted a few posts back. There may be better ways, but above method worked well even with a big function.
It's the same methodology I employed with that one problem exported bash function in Precord. This is just a simple example but really the same method. In Precord the /tmp/file I created actually had two functions in it. Pretty simple when only one <input> with that issue. Pburn should work likewise I'd say.

wiak
Last edited by wiak on Tue 05 Jun 2018, 11:07, edited 3 times in total.

User avatar
fredx181
Posts: 4448
Joined: Wed 11 Dec 2013, 12:37
Location: holland

#58 Post by fredx181 »

Hi wiak, I took on pfind to convert (I thought it should be less complicated than pburn)
It turned out to be a real challenge (for me anyway cos I'm a gtkdialog noob), replaced every instance of gtkdialog with "gtkwialog -b" in all related scripts (and sh symlinked to dash of course), but just doesn't work, the Search button does nothing.
I suspect at least some <action> or <input> lines are containing other bashism's than exported functions, but not sure.
I tried with this pfind:
https://fredx181.github.io/StretchDog/i ... .3_all.deb
(newer version than included in e.g. Xenialdog)

EDIT: I think I suspected right, e.g. this (in /usr/local/pfind/pfind):

Code: Select all

 <action>. '$PROGPATH'/func -search</action>
Should probably become something like this:

Code: Select all

 <action>bash -c ". '$PROGPATH'/func -search"</action>
EDIT2: There's checkbashisms (part of package "devscripts"), but unfortunately it doesn't work to check for bashisms inside <action>..</action>
https://linux.die.net/man/1/checkbashisms

Fred

wiak
Posts: 2040
Joined: Tue 11 Dec 2007, 05:12
Location: not Bulgaria

#59 Post by wiak »

fredx181 wrote: I suspect at least some <action> or <input> lines are containing other bashism's than exported functions, but not sure.
Yes, that could be the issue you've come across. Of course if '<action>commandstrings' contain bashisms they are going to need bash -c (with gtkwialog -b mode) to interpret them), so not just for export -f cases, that's true.

But it's also the case that if an '<action>commandstring' requires a shell to do file expansion or job control, for example, either sh -c or bash -c will be required by gtkwialog in the -b mode (since that mode does not itself exec any shell automatically). The command mode -b glib mechanism does do UNIX style parsing, but:
Parses a command line into an argument vector, in much the same way the shell would, but without many of the expansions the shell would perform (variable expansion, globs, operators, filename expansion, etc. are not supported).
Hence '<action>commandstring' entries that need filename expansion or such need to include an appropriate (sh -c or bash -c) shell command at the front.

I'll add pfind to my list ;-) But this list may take a while to look at...

My own bash/gtkdialog programs (and most of rcrsn51's peasy scripts) do not contain that external file function method so will generally be easy to convert (since mainly just the export -f situation to deal with). Problem with the split file function method is that there are so many of them(!) so you have to grep the whole folder looking for suspects...

Then I generally load suspect files up in geany and use search/replace with search term <action> and replace term <action>bash -c " and 'carefully' use the Find button to take a look before I commit anything (and finish off by putting a " symbol at the end - though I sometimes adjust replace term with sh -c if bash -c not required) but hopefully I'll work out a more automatic convert method eventually... I also thereafter do a quick search through the <input> lines, though usually not many of these. Have you any quicker technique?

wiak

wiak
Posts: 2040
Joined: Tue 11 Dec 2007, 05:12
Location: not Bulgaria

#60 Post by wiak »

Are you sure that line you mention in pfind is actually a bashism. It does contain '.' (source in bash) so does need a shell. I'd think this is what is required for that line (including the double/single start/end quote syntax shown:

"'<action>sh -c ". '$PROGPATH'/func -search"</action>'"

If it's a bashism should be bash -c. Either way the shell command is needed at the front here to interpret the '.'

I note there are a few other <action> lines in pfind that contain that '.' at the beginning.

wiak

Post Reply