GtkDialog - tips

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Message
Author
seaside
Posts: 934
Joined: Thu 12 Apr 2007, 00:19

Re: Dynamic pixmaps

#376 Post by seaside »

afishe2000 wrote: Here is the test code I modified from the pixmap example and an screenshot of the results:

Code: Select all

#!/bin/bash

get_Pic() {
	echo foldger.jpg
}
export -f get_Pic

export MAIN_DIALOG="
<vbox>
  <frame Static File Name>
    <text>
			<label>foldger.jpg</label>
		</text> 
	</frame> 
  <frame Static Picture>
		<pixmap>
      <input file>"folgers.jpg"</input>
    </pixmap>
  </frame>
  <frame Dynamic File Name>
    <text>
			<input>get_Pic</input>
		</text> 
	</frame> 
  <frame Dynamic Picture>
    <pixmap>
      <input file>get_Pic</input>
    </pixmap>
  </frame>
  <hbox>
    <button cancel></button>
    <button ok></button>
  </hbox>
</vbox>
"
gtkdialog3 --program=MAIN_DIALOG
afishe2000,

If your question is "why doesn't the Dynamic Picture work?"

Two reasons-

Code: Select all

get_Pic() {
	echo foldger.jpg 
}
1. Should be "folgers.jpg"

2. This code -

Code: Select all

<frame Dynamic Picture>
    <pixmap>
      <input file>get_Pic</input>
    </pixmap>
  </frame>
Command "get_pic" needs to be resolved to the actual filename in place like this -

Code: Select all

 <input file>$(get_Pic)</input>
Great work - keep going :D

Regards,
s

afishe2000
Posts: 37
Joined: Fri 29 Jan 2010, 16:09

#377 Post by afishe2000 »

Thanks so much,

I'm surprised that <text> works with get_Pic ($(get_Pic) doesn't though) but <pixmap> needs $(get_Pic).

I thought the function was returning a string and both widgets just required a sting input.

Code: Select all

<text> 
  <input>get_Pic</input> 
</text> 

<pixmap> 
  <input file>$(get_Pic)</input> 
</pixmap>

seaside
Posts: 934
Joined: Thu 12 Apr 2007, 00:19

#378 Post by seaside »

afishe2000 wrote:Thanks so much,

I'm surprised that <text> works with get_Pic ($(get_Pic) doesn't though) but <pixmap> needs $(get_Pic).
afishe2000,

The pixmap <input file> does not accept a variable for a filename, so $(get_Pic) is used as a subshell command.

$(get_Pic) doesn't work in text and other inputs because it IS a subshell :D (Subshell process variables are not visible to parents)

This may be useful-

http://tldp.org/LDP/abs/html/subshells. ... BSHELLSREF

Cheers,
s

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

#379 Post by neurino »

I'm using Glade Interface Designer to build up a little gui using libglade.

My problem is using signal to open an internet page: it escapes "&" char in urls to &#.38 (remove the ".", otherwise the forum re-escapes "&#.38" to "&" :D ) breaking the url, for example the link

http://www.google.com/search?hl=en&q=glade

Code: Select all

...
<signal name=\"clicked\" handler=\"defaultbrowser "http://www.google.com/search?hl=en&q=glade"\"/>
...
executes on click:

Code: Select all

defaultbrowser "http://www.google.com/search?hl=en&#.38;q=glade"
which is incorrect, so we have
& => & => &#38 tha is "&" escaped!!!

Any tips?

User avatar
Aitch
Posts: 6518
Joined: Wed 04 Apr 2007, 15:57
Location: Chatham, Kent, UK

#380 Post by Aitch »

Try

http://htmlhelp.com/tools/validator/problems.html
To avoid problems with both validators and browsers, always use & in place of & when writing URLs in HTML:

<a href="foo.cgi?chapter=1&section=2&copy=3&lang=en">...</a>

Note that replacing & with & is only done when writing the URL in HTML, where "&" is a special character (along with "<" and ">"). When writing the same URL in a plain text email message or in the location bar of your browser, you would use "&" and not "&". With HTML, the browser translates "&" to "&" so the Web server would only see "&" and not "&" in the query string of the request.
Incorrect Nesting of Elements
HTH

Aitch :)

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].

Post Reply