GtkDialog - tips

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Message
Author
User avatar
neurino
Posts: 362
Joined: Thu 15 Oct 2009, 13:08

#381 Post by neurino »

Ehm... :roll:

ampersands are already escaped (instead of "&" I put & in links) but when & entity is restored it is re-escaped, by some process, which one I'd like to know, to &#.38 The last one is the same as &

I'm a webmaster and I'm used to special chars in XML, the problem comes when gtkdialog calls the command in XML <signal>

potong
Posts: 88
Joined: Fri 06 Mar 2009, 04:01

#382 Post by potong »

neurino:

It's easy to fall foul of gtkdialog parsing code within it's xml and doubly so when using glade!

I have found it far easier to keep the code out of the gtkdialog/glade xml and just refer to an exported function.
This function can be in the main bash script i.e. the script calling gtkdialog or in an included function library file (see /usr/share/doc/gtkdialog3/examples/glade-01.00-entries_functions.sh)
If using the first method don't forget to export the function!

Code: Select all

say(){ echo hello; }
export -f say

Or you can play safe and export all functions and variables by coding

Code: Select all

#!/bin/bash -a
as the first line of your script.

In the glade file the xml for the signal handler could look like this

Code: Select all

<signal name="clicked" handler="getpage &"/>
and the include file like this:

Code: Select all

getpage(){ defaultbrowser "http://www.google.com/search?hl=en&q=glade"; }
HTH

potong

N.B. In glade you would type

Code: Select all

getpage &
in the Signal Handler entry
Last edited by potong on Wed 04 Aug 2010, 22:19, edited 1 time in total.

potong
Posts: 88
Joined: Fri 06 Mar 2009, 04:01

#383 Post by potong »

Double post

User avatar
neurino
Posts: 362
Joined: Thu 15 Oct 2009, 13:08

#384 Post by neurino »

potong wrote:neurino:

It's easy to fall foul of gtkdialog parsing code within it's xml and doubly so when using glade!

I have found it far easier to keep the code out of the gtkdialog/glade xml and just refer to an exported function.
Thanks potong, your advice is always helpful.

I'm building a little GUI for the gmail checker in the other post you answered me.

Inserting directly links in xml interface along with other data as subject, author and summary was the easiest logical way and, in fact, it all works except the link part with escaped ampersands.

Not a big trouble writing dynamically separate functions, one for each link and this is what I'm going to do.

Of course, if I'd ever distribute a little pet of this work (would be nice to stay as neat and light as possible) I'd put most of credits to you :D

User avatar
zigbert
Posts: 6621
Joined: Wed 29 Mar 2006, 18:13
Location: Valåmoen, Norway
Contact:

#385 Post by zigbert »

Could anyone give us newbies an easy guide: 'howto use gtkdialog with glade'?


Pleeeease
Sigmund

User avatar
neurino
Posts: 362
Joined: Thu 15 Oct 2009, 13:08

#386 Post by neurino »

zigbert wrote:Could anyone give us newbies an easy guide: 'howto use gtkdialog with glade'?

Pleeeease
Sigmund
You newbiee with gtkdialog? Is it a joke? :D :D

Anyway I made all by tentatives until it worked somehow.

In few steps:

open glade, in prefs choose to use libglade, build and save your gui to file, call

Code: Select all

gtkdialog3 -g your_glade_file.glade -p name_of_the_window_to_show -i your_shell_script_with_functions_called_by_signals_in_glade_file_no_need_to_export
Easy, but poorly documented.

disciple
Posts: 6984
Joined: Sun 21 May 2006, 01:46
Location: Auckland, New Zealand

#387 Post by disciple »

So what's the advantage of using glade, given that gtkdialog uses a similar xml syntax anyway? Is it just that you can create the gui in the glade interface designer?
Glade is an extra dependency which is going extinct as programs are rewritten to use gtkbuilder...
Do you know a good gtkdialog program? Please post a link here

Classic Puppy quotes

ROOT FOREVER
GTK2 FOREVER

User avatar
neurino
Posts: 362
Joined: Thu 15 Oct 2009, 13:08

#388 Post by neurino »

The full name of Glade in my menu is Glade Interface Designer so what to expect more?

I'm not taking care of depenecies as long I don't need extra libs that the ones already present in Puppy distributions I'm using (Wary 030 and Puppeee at the moment).

I find building with glade is extra fast then I can fine-tune xml in a text editor if I have the need.

For a simple settings dialog I think it's the fastest option (even if glade xml is more verbose than the one explained in this topic... but you don't have to handwrite it so...)

disciple
Posts: 6984
Joined: Sun 21 May 2006, 01:46
Location: Auckland, New Zealand

#389 Post by disciple »

so what to expect more?
Maybe. For all I know gtkdialog might be able to do more things when used with libglade. BTW, did Glade even start off as a GUI tool, or did that come later?

Zigbert, there's a thread I think on the forum of another distro, where a couple of guys were posting quite a lot of gtkdialog+glade examples. I thought I posted a link to it here, but I can't see the link... maybe it was the thread where I first reported hacking glade support out out of gtkdialog.
Do you know a good gtkdialog program? Please post a link here

Classic Puppy quotes

ROOT FOREVER
GTK2 FOREVER

disciple
Posts: 6984
Joined: Sun 21 May 2006, 01:46
Location: Auckland, New Zealand

#390 Post by disciple »

maybe it was the thread where I first reported hacking glade support out out of gtkdialog
No, it doesn't look like that was it. Surely I wasn't negligent enough not to post it at all...
Do you know a good gtkdialog program? Please post a link here

Classic Puppy quotes

ROOT FOREVER
GTK2 FOREVER

disciple
Posts: 6984
Joined: Sun 21 May 2006, 01:46
Location: Auckland, New Zealand

#391 Post by disciple »

There's this page that was linked to earlier in the thread http://tadeboro.blogspot.com/2009/04/gt ... art-2.html

And I was directed to this thread a while back http://www.pclinuxos.com/forum/index.ph ... 050.0.html
But IIRC the goblinx thread linked to there was actually better... but its gone now :(

----
No. From what I can see the goblinx page was a series of tutorials not using glade.
http://gigablast.com/get?q=gtkdialog+si ... 655&cnsp=0
http://gigablast.com/get?q=gtkdialog+si ... 281&cnsp=0
I'm sure I saw another page somewhere with glade examples...

But I guess what neurino posted might be all you want.
Do you know a good gtkdialog program? Please post a link here

Classic Puppy quotes

ROOT FOREVER
GTK2 FOREVER

User avatar
zigbert
Posts: 6621
Joined: Wed 29 Mar 2006, 18:13
Location: Valåmoen, Norway
Contact:

#392 Post by zigbert »

An interesting question is; Will gtkdialog allow use of more widgets (like slider, knobs, dynamic image rendering...)?

Another question is about the use of the glade-builder (the user-interface to build guis); Is this so powerful that it can build complex guis, or is it meant for less complex windows/boxes as shown in examples?

A working (tiny) example would be preferable.

What exactly will be the extra dependencies?


Sigmund

User avatar
neurino
Posts: 362
Joined: Thu 15 Oct 2009, 13:08

#393 Post by neurino »

zigbert wrote:is about the use of the glade-builder (the user-interface to build guis); Is this so powerful that it can build complex guis, or is it meant for less complex windows/boxes as shown in examples?
the second option

if you select liblade you'll see a lot of widget / options not available. Morover in my Wary's Glade crashes while using some widgets like the spin button.

It's quick, no more I guess.

About an example I'm not at home now to get some to post.
Anyway it's easier for you to build one by yourself in a minute and make it run like I posted before, I didn't go much more further.

I learned commands to put in signals by your tutorial, like EXIT:sure and others.

disciple
Posts: 6984
Joined: Sun 21 May 2006, 01:46
Location: Auckland, New Zealand

#394 Post by disciple »

What exactly will be the extra dependencies?
Sorry, no, I'm talking nonsense. At the moment there are no extra dependencies as gtkdialog normally depends on libglade.
But it is extremely easy to hack gtkdialog so that it doesn't depend on libglade, which we were discussing because libglade is becoming obsolete. IIRC someone said that gtkdialog is the only program in Puppy that still depends on it... or was there one other program?
So if we start writing gtkdialog+glade programs we just won't have the option of removing glade support.
If glade makes development easier, or allows gtkdialog to do more tricks, go ahead and use it :)
Another question is about the use of the glade-builder (the user-interface to build guis); Is this so powerful that it can build complex guis
Yes, it should be... although I guess I guess maybe you should define what you mean by complex guis :)
An interesting question is; Will gtkdialog allow use of more widgets (like slider, knobs, dynamic image rendering...)?
I guess we either need to experiment and see, or have another look at the gtkdialog source. I think the answer is no, but I'm not certain.
Do you know a good gtkdialog program? Please post a link here

Classic Puppy quotes

ROOT FOREVER
GTK2 FOREVER

User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

#395 Post by technosaurus »

someone might be able to remove even the libglade dependency and use gtk-builder-convert to convert the .glade files into .ui files that can be used internally by gtk+-2.12 and later. The same options and more should be available through gtkbuilder. There is a vala .ui example here:
http://live.gnome.org/Vala/GTKSample#Lo ... m_XML_File

there are examples in the devx in /usr/share/doc/gtkdialog3/examples/ (don't forget to edit the script to change gtkdialog to gtkdialog3 or make a symlink from gtkdialog3 for gtkdialog in /usr/sbin)

(Note: you only have to delete /usr/lib/pkgconfig/libglade-2.0.pc to compile without glade)
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].

User avatar
Patriot
Posts: 733
Joined: Thu 15 Jan 2009, 19:04

#396 Post by Patriot »

Hmmm .....
zigbert wrote:An interesting question is; Will gtkdialog allow use of more widgets (like slider, knobs, dynamic image rendering...)?
Widgets creation/usage is limited to only what is defined/supported internally to gtkdialog. If a widget is not defined, no amount of coaxing will either ...
zigbert wrote:Another question is about the use of the glade-builder (the user-interface to build guis); Is this so powerful that it can build complex guis, or is it meant for less complex windows/boxes as shown in examples?
Glade-builder is quite powerful and useful. However, IMHO, there are two good enuff reasons to stick with gtkdialog XML constructs:

1. Since gtkdialog widgets set is fixed,you will end up with a much bigger UI script to do exactly the same thing in glade when compared to standard gtkdialog definitions.

2. glade does gives you finer controls over the widgets but unless you are familiar with gtk+ glade constructs then these finer points can be confusing to use. Example, assigning a simple and meaningful exit action is enough to drive first time users to the wall.


Rgds

User avatar
neurino
Posts: 362
Joined: Thu 15 Oct 2009, 13:08

#397 Post by neurino »

As I already wrote also libglade-related files are plain XML, just a little more verbose but always easy to read.

What I do is, in the case of a Gmail notifier GUI, create with glade the XML mockup then cut and paste glade code in bash like you normally do with your xml, only I can get a working xml faster...

You guys also say the Glade-builder is powerful but I assert again that using libglade a lot of widgets and options are disabled while are active using, in preferences, the other lib.

So maybe it would be nice to understand how to use Glade-builder without libglade and having all the things enabled.

I tried something but had no luck except with the actions I wrote above using libglade. Maybe you can have better luck.

Last thing the "simple and meaningful exit action" is the only way, at the moment, I got the control over user action so no difference with it...
___________________

A little example attached, don't know if you can view the settings.glade file in Glade since on my Wary 030 spin button widget makes the app crash so I had to add it by hand, after founding one (and only one) sample online.

If someone knows where to find all glade XML tags and attributes...
Attachments
settings.tar.gz
little example using libglade
(2 KiB) Downloaded 476 times

User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

#398 Post by technosaurus »

This is more of a bash trick, but it could be expanded into a full blown menu if other parts of the .desktop files are parsed. Right now it just pulls out all of the executables from the .desktop files so that I don't have to try to figure out where it is in the menu.

Code: Select all

#!/bin/sh
for x in `ls /usr/share/applications/*.desktop`; do I=$I"<item>""`grep "^Exec=" $x |cut -d = -f 2`""</item>"; done
export D="<vbox><combobox><variable>C</variable>"$I"</combobox><button ok></button></vbox>" && eval `gtkdialog3 --program=D` && $C
Here it is with an entry box in case you want to enter it manually

Code: Select all

#!/bin/sh
for x in `ls /usr/share/applications/*.desktop`; do I=$I"<item>""`grep "^Exec=" $x |cut -d = -f 2`""</item>"; done
export D="<vbox><entry editable=\"true\"><variable>E</variable></entry>
<combobox><variable>C</variable>"$I"</combobox><button ok></button></vbox>"
eval `gtkdialog3 --program=D` && [ "$E" == "" ] && $C || $E
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].

User avatar
01micko
Posts: 8741
Joined: Sat 11 Oct 2008, 13:39
Location: qld
Contact:

#399 Post by 01micko »

techno 8) 8) 8)

Do you mind if I add this to my 'tools' page? Full credit to you of course.

I should have made something like this, I use a similar loop to detect browsers and choose the default in Lupu. I don't know how many times I have open either the /root/.jwmrc or /root/icewm/menu file just to look up an executable (and path if needed) :lol: Thanks

Cheers
Puppy Linux Blog - contact me for access

User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

#400 Post by technosaurus »

By all means.

I was initially planning to build a menu program that could be used with any light weight window manager... lost interest after this part though.

p.s. - it runs a bit faster if the top line has /bin/ash instead of /bin/sh
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].

Post Reply