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
thunor
Posts: 350
Joined: Thu 14 Oct 2010, 15:24
Location: Minas Tirith, in the Pelennor Fields fighting the Easterlings
Contact:

#481 Post by thunor »

8-bit wrote:I could not get the checkmark png images for yes and no found and as a result, the one example does not work for me.
I've attached them to my post on the previous page :)

They are from the Elementary icon set.

User avatar
8-bit
Posts: 3406
Joined: Wed 04 Apr 2007, 03:37
Location: Oregon

#482 Post by 8-bit »

thunor wrote:
8-bit wrote:I could not get the checkmark png images for yes and no found and as a result, the one example does not work for me.
I've attached them to my post on the previous page :)

They are from the Elementary icon set.
I had used some other png files to get it to work, but I downloaded the ones from your post and they work too.
I do have another question though.
I am running Lupu 520 and in doing a search for "yes", I came up empty handed.
So I assume those png files are not part of a standard puppy.
I had initially used ones from /usr/local/lib/X11/pixmaps.
I picked some that were close, copied them to the directory containing the toggle script, and renamed them to correspond with the names in the script.
One thing I did notice is that a toggle configuration file is written when toggle is run. But even if I have the no.png images displayed when I stop the script, they are not retained for the next time toggle is run.
It always starts with the yes.png images.
So what is that configuration file for?

User avatar
thunor
Posts: 350
Joined: Thu 14 Oct 2010, 15:24
Location: Minas Tirith, in the Pelennor Fields fighting the Easterlings
Contact:

#483 Post by thunor »

8-bit wrote:One thing I did notice is that a toggle configuration file is written when toggle is run. But even if I have the no.png images displayed when I stop the script, they are not retained for the next time toggle is run.
It always starts with the yes.png images.
So what is that configuration file for?
It's just an example for illustrative purposes which happens to default to yes.

The "configuration" file TOGGLE is necessary because if an exported shell variable were used instead, funcImageToggle would be able to change the exported variable but not the original variable resulting in the image not toggling. That's what you meant right? If so see this.

Replace

Code: Select all

echo 0 > TOGGLE; funcImageToggle
with

Code: Select all

if [ ! -f TOGGLE ]; then echo 0 > TOGGLE; funcImageToggle; fi
and you'll get the functionality you're expecting :)

Regards,
Thunor

User avatar
8-bit
Posts: 3406
Joined: Wed 04 Apr 2007, 03:37
Location: Oregon

#484 Post by 8-bit »

Thank you for making things clear.
I already knew of how to get the script to use the configuration file on startup.
But while I am here, I will ask that the modded gtkdialog file I uploaded be checked out to see if everything works as expected.
I still have the modified source code files, I used gtkdilaog3-0.7.20-pe-1 for my source and added the patches I found in this thread.

So if I missed something or you would like me to upload the modified source in a tar.gz file yell.

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

#485 Post by 01micko »

Ah thunor.. this is fun! I will write a revision of the clunky wallpaper setter soon.

8-bit.. your binary works just fine :) , I notice it's not stripped though, you can get it alot smaller with "strip --strip-unneeded"

Here is a spin on thunor's code that demos the pixmap refreshing capability: (notice how only one of the buttons refreshes the pixmap :wink:)

Code: Select all

#!/bin/bash

function funcImageToggle() {
   if [ $(< TOGGLE) = 1 ]; then
      ln -sf no.png toggle.png
      echo 0 > TOGGLE
   else
      ln -sf yes.png toggle.png
      echo 1 > TOGGLE
   fi
}
export -f funcImageToggle

echo 0 > TOGGLE; funcImageToggle

export MAIN_DIALOG='
<window title="btnImageToggle" resizable="false" width-request="300" height-request="100">
   <vbox homogeneous="true">
      <hbox homogeneous="true">
         <pixmap> 
			<variable>TOGGLEPIX</variable>
            <input file>toggle.png</input>
         </pixmap>
         <button>
            <variable>TOGGLEME</variable>
            <input file>toggle.png</input>
            <label>"Toggle Me!"</label>
            <action>funcImageToggle</action>
            <action type="refresh">TOGGLEME</action>
            <action type="refresh">TOGGLEMETOO</action>
            <action type="refresh">TOGGLEPIX</action>
         </button>
         <button tooltip-text="Toggle me too!">
            <variable>TOGGLEMETOO</variable>
            <input file>toggle.png</input>
            <action>funcImageToggle</action>
            <action type="refresh">TOGGLEMETOO</action>
            <action type="refresh">TOGGLEME</action>
         </button>
      </hbox>
   </vbox>
   <action signal="hide">exit:Exit</action>
</window>
'

gtkdialog4 --center --program=MAIN_DIALOG 
I took the liberty to make a combined patch of moose's and thunor's patches, (see attached), gunzip it and place it in the dir with the source dir and (patriot's source) and run:

Code: Select all

patch -p0 <  gtkdialog_moose_thunor_pixmap.patch
Have fun!
Attachments
gtkdialog_moose_thunor_pixmap.patch.gz
(1.19 KiB) Downloaded 414 times
Puppy Linux Blog - contact me for access

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

#486 Post by 01micko »

Ok, this is the not so clunky SWS (simple-wallpaper-setter) :D

Thanks to thunor's patches to gtkdialog.

note, this depends on the gtkdialog4 executable posted by 8-bit, or roll your own with the patch above, name it "gtkdialog4" and pop it in /usr/sbin or /usr/bin
Attachments
sws-exp.jpg
(37.27 KiB) Downloaded 1180 times
sws-0.3exp.pet
(4.14 KiB) Downloaded 432 times
Puppy Linux Blog - contact me for access

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

#487 Post by technosaurus »

As long as it doesn't _remove_ or change existing functionality when compared to gtkdialog3, there is no need to bump the version number. ... perhaps a symlink or version file etc... (btw there is an operational difference between 2 & 3 that required a version bump)
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
8-bit
Posts: 3406
Joined: Wed 04 Apr 2007, 03:37
Location: Oregon

#488 Post by 8-bit »

For all concerned about my calling the patched gtkdialog 4, I was not actually bumping the version number.
Or at least I did not mean to.
It was a case of calling it what I did for testing purposes so as not to interfere with the gtkdialog3 file that was already on my PC.
As a matter of fact, I compiled it as gtkdialog3 and just renamed the executable for co-existence while testing it.
If you do not like it being called gtkdialog4, just rename it to gtkdialog3.

I hope I made myself clear as mud on that.

Also, since I have never used the strip option in compiling, and have no idea where or how to implement it, my compile was not stripped.

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

#489 Post by 01micko »

Understood 8-bit and I was thinking along those lines too.

I'm going to put the exec in the next spup (as gtkdialog3) just to see if anything breaks, I don't think it will but you never know.

As a note, my patch does not include this from thunor (return ""; [in src/stringman.c]) .. as I understood his edit on the previous page took care of that. Please correct me if I'm wrong and I'll do another patch. Gtkdialog is not segfaulting for me if it doesn't find the image without that line.

BTW strip --strip-unneeded <name-of-exec> is all that's needed to strip in most cases. (learnt that from disciple a few years ago now :) )
Puppy Linux Blog - contact me for access

User avatar
8-bit
Posts: 3406
Joined: Wed 04 Apr 2007, 03:37
Location: Oregon

#490 Post by 8-bit »

01micko,
Thank you for the strip command usage.
I tried it and it brought the gtkdialog4 executable from 371K to 123K.

And also, I did modify the source for the "return;" in my compile.

Also, nice work on the Simple Wallpaper Switcher!

And lastly, I lied! The name originally compiled to was just "gtkdialog".

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

#491 Post by disciple »

Note that .so and .a files would normally be stripped before packaging too. If you strip these without the --strip-unneeded flag then it breaks them, but you can strip executables without --strip-unneeded... and they might even end up smaller.
Do you know a good gtkdialog program? Please post a link here

Classic Puppy quotes

ROOT FOREVER
GTK2 FOREVER

User avatar
8-bit
Posts: 3406
Joined: Wed 04 Apr 2007, 03:37
Location: Oregon

#492 Post by 8-bit »

thunor opens the door!

With the changes made to gtkdialog3, and after seeing 01micko's Simple Wallpaper Switcher, one could design a package/application and call it something like "Picture This".
Feed it the name of a picture directory and display each picture in that directory.
For trying to find a specific picture that had some name given by a camera
it would come in handy.

User avatar
thunor
Posts: 350
Joined: Thu 14 Oct 2010, 15:24
Location: Minas Tirith, in the Pelennor Fields fighting the Easterlings
Contact:

#493 Post by thunor »

Here's some code to enable <pixmap> to be scaled (no need to use external command-line scalers anymore):

[EDIT] 20110618-22:01 Gtkdialog is now in a repository (see this post).

This is how it works:

By default the image will be loaded without constraint as per the norm (width will default to -1 and height -1).
If either <width> or <height> (or both) is set then "the image will be scaled to fit in the requested size, preserving the image's aspect ratio."

e.g.
<width>100</width><height>100</height>
<width>100</width> (equivalent to <width>100</width><height>-1</height>)
<height>100</height> (equivalent to <width>-1</width><height>100</height>)

I achieved this by replacing gtk_image_new/set_from_file() with gdk_pixbuf_new_from_file_at_size() and I recommend reading the link.
Last edited by thunor on Sat 18 Jun 2011, 20:58, edited 4 times in total.

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

#494 Post by 01micko »

thunor,

re my earlier post..

is the return ""; still needed in stringman.c?

TIA
Puppy Linux Blog - contact me for access

User avatar
thunor
Posts: 350
Joined: Thu 14 Oct 2010, 15:24
Location: Minas Tirith, in the Pelennor Fields fighting the Easterlings
Contact:

#495 Post by thunor »

01micko wrote:thunor,

re my earlier post..

is the return ""; still needed in stringman.c?

TIA
Yes. It is missing and a bug.

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

#496 Post by 01micko »

Thanks again thunor

Well it's working well for me. This time I have compiled a gtkdialog executable with all patches and made a new patch with the new functionality to scale images and including the return ""; line in src/stringman.c. I have also adjusted the SWS to ditch the scale2pics dependency. Result is a 2K wallpaper setter! (and it's much faster without the loop to scale all the wallpapers, potentially very slow if you have many wallpapers in your collection). I have tested some (but far from all) legacy gtkdialog3 apps and they all still work so far.

So test the exec if you dare. It's gzipped so you will have to gunzip it and make it executable. This time I named it 'gtkdialog3' to be compatible with all current gtkdialog 3 progs. Backup the older gtkdialog3 and place the new gtkdialog3 exec in /usr/sbin of course at your own risk. SWS is attached too, just as a demo. Note I had to set the width of the vbox container so the gui wouldn't keep switching size due to different aspect ratios of the images in my backgrounds directory. I set the height of the pixmap only.

Have fun!

EDIT: removed attachments, get gtkdialog from svn
see my post down page for patch at the time
Attachments
sws-0.4exp.pet
(1.96 KiB) Downloaded 407 times
Last edited by 01micko on Thu 23 Jun 2011, 20:49, edited 3 times in total.
Puppy Linux Blog - contact me for access

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

#497 Post by zigbert »

Mick
I am running your gtkdialog now, and everything seems to run fine. I hope I can check out thunors patch today :D


Sigmund

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

#498 Post by zigbert »

Works very well. I like the scaling.....
Could this technique be used for buttons as well? If so, we can make an image clickable (ie. to show the full sized image).

Scaling works perfectly

Code: Select all

<pixmap>
  <variable>ARTWORK</variable>
  <input file>$HOME/.pmusic/nowplaying_albumart.jpg</input>
  <width>100</width>
</pixmap>
Image gets cropped

Code: Select all

<button relief="2" width-request="100">
  <variable>ARTWORK</variable>
  <input file>$HOME/.pmusic/nowplaying_albumart.jpg</input>
</button>

User avatar
thunor
Posts: 350
Joined: Thu 14 Oct 2010, 15:24
Location: Minas Tirith, in the Pelennor Fields fighting the Easterlings
Contact:

#499 Post by thunor »

Additionally, in src/stringman.c replace function find_pixmap with this:

[EDIT] 20110618-22:01 Gtkdialog is now in a repository (see this post).

So, now if an image file doesn't physically exist then you will see gtk's stock broken image icon instead of blankness.

find_pixmap is still being used but as can be seen above, I've disabled all of the original developer's personal code that is of little use to anyone else.
Last edited by thunor on Sat 18 Jun 2011, 21:00, edited 2 times in total.

User avatar
8-bit
Posts: 3406
Joined: Wed 04 Apr 2007, 03:37
Location: Oregon

#500 Post by 8-bit »

thunor,

Would it be possible for you to compress the full source directory in a tar.gz file and attach it here?
Also, if you compiled using patches maybe include them?

Also, does your current version include the patches by Moose on The Loose?

My copy of source appears to include your latest patch as well as the others.
That is to say, I did the return""; change and even got it in the same place as you have shown.
So other than the comments, all matches.

Post Reply