Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Tue 20 Nov 2018, 11:19
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
How to drag and drop image in pixmap?
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [12 Posts]  
Author Message
arivas_2005

Joined: 25 Feb 2007
Posts: 201

PostPosted: Sat 11 Aug 2018, 19:54    Post subject:  How to drag and drop image in pixmap?  

regards

I need to modify image on the fly

I do not know if <pixmap> accepts drag and drop image
(it's possible?)

I did this:
I added a text box by dragging the path of the image (dragdrop)
to modify the path of the image but I can not make it work

same, I want to clean the text box after the refresh of the image

I attach the code

Code:

#! /bin/bash
# name image reference gtk-change-fly-image.jpg
echo "gtk-change-fly-image.jpg">/tmp/image
export TMPDIR=`cat /tmp/image`

repix() {
export TMPDIR=`cat /tmp/image`
Xdialog --msg $TMPDIR x
   }

function repix2() {
   export TMPDIR=`cat /tmp/image`
 echo -e '<pixmap>
 <variable>IMAGE1</variable>
         <action>repix</action> 
       <input file>'"$TMPDIR"'</input>
       <action>refresh:IMAGEN1</action>
       </pixmap> '
}
   
export -f repix
export IMAGE="gtk-dialog-folgers.jpg"


export MAIN_DIALOG='
<vbox>
 
  <frame Changue image on fly-drag-drop path>     
  <eventbox>
    <vbox>
    '"$(repix2)"'
    <text label="Drop path image here.." wrap="false"></text>
     <entry file-monitor="true" auto-refresh="true">
      <variable>ENTRY</variable>
        <action when="selection-changed">echo -e "$ENTRY"</action>
        <action when="selection-changed">echo "$ENTRY">/tmp/image</action>
        <action when="selection-changed">refresh:IMAGE1</action>
        <action when="selection-changed">ENTRY=`echo ""` </action>
        <action when="selection-changed">refresh:ENTRY</action>
    </entry>   
     </vbox>
    </eventbox>
  </frame>
  <hbox>
    <button cancel></button>
    <button label="Refresh pix 2 & clear texbox">
    <action>repix</action>
     <action>ENTRY=`echo ""`</action>
      <action>repix2()</action>
      <action>refresh:ENTRY</action>
    </button>
    <button ok></button>
  </hbox>   
</vbox>
'

gtkdialog --program=MAIN_DIALOG

Back to top
View user's profile Send private message 
arivas_2005

Joined: 25 Feb 2007
Posts: 201

PostPosted: Sun 12 Aug 2018, 14:18    Post subject:  

regards
here again
now I drag the name of the image to the text box and it is shown in the pixmap

After several hours of trial and error, you can now refresh the new image, but ..
How can I make the image fit the frame?
large or small, suits the size of the <pixmap> box
this is the code:

Code:

#! /bin/bash
# name image reference gtk-change-fly-image.jpg
export DIR=`pwd`

if [ ! -e "$DIR""/gtk-change-fly-image.jpg" ];then
   Xdialog --msgbox "No existe imagen de referencia" x
   exit
fi
# image rererence
cp -rf  "$DIR""/gtk-Pimage_0.jpg" "$DIR""/gtk-change-fly-image.jpg"

hacecopia(){
largo=${#ENTRY}
if [ $largo -gt 0 ];then
  extension=$(echo $ENTRY | awk -F . '{if (NF>1) {print $NF}}')
  rutaimagen="$ENTRY"
  largoextension=${#extension}
  if [ "$largoextension" -gt 0 ];then
         if [ "$extension" = "jpg" ] || [ "$extension" = "jpeg" ] || [ "$extension" = "png" ] || [ "$extension" = "bmp" ] || [ "$extension" = "svg" ];then

            #Xdialog --msgbox "SI  es imagen "$extension"\n"$rutaimagen"\n""$DIR""/gtk-Pimage_tempo.jpg" x
            
            TMP=$IFS; IFS=
            #yes | cp -rf "$rutaimagen" "$DIR""/gtk-Pimage_tempo.jpg"
            cp -rf "$rutaimagen" "$DIR""/gtk-change-fly-image.jpg"
            IFS=$TMP
         else
             Xdialog --msgbox "NOO  es imagen " x
         fi
   else
       Xdialog --msgbox "Sin extension" x
   fi
else
a="A" 
fi

}

function repix2() {
echo '<pixmap resizable="false"  scrollable="f" height-request="170" width-request="250" >
      <variable>IMAGEN</variable>
       <input file>'$IMAGE'</input>
       </pixmap>'
}

export -f hacecopia   
export IMAGE="$DIR""/gtk-change-fly-image.jpg"

export MAIN_DIALOG='
<window scrollable="true" window-position="0" height-request="260" width-request="270">
<vbox>
 
  <frame Changue image on fly-drag-drop path scrollable="true" >     
  <eventbox>
    <vbox>
    '"$(repix2)"'
    <text label="Drop path image here.." wrap="false"></text>
     <entry file-monitor="true" auto-refresh="true">
      <variable>ENTRY</variable>
        <action when="selection-changed">echo -e "$ENTRY"</action>
        <action when="selection-changed">hacecopia</action>
        <action when="selection-changed">refresh:IMAGEN</action>
        <action when="selection-changed">clear:ENTRY</action>
        <action when="selection-changed">refresh:ENTRY</action>
          '$(rem "<action>repix2()</action>")'
    </entry>   
     </vbox>
    </eventbox>
  </frame>

</vbox>
</window>
'
gtkwialog  -p MAIN_DIALOG
Back to top
View user's profile Send private message 
musher0

Joined: 04 Jan 2009
Posts: 13000
Location: Gatineau (Qc), Canada

PostPosted: Sun 12 Aug 2018, 15:07    Post subject:  

Hello arivas.

For any image conversion, may I suggest that you install the full
netpbm package and study the over 200 possibilities it offers?

It is as powerful as imagemagick, but less complicated.

Recent Puppies do not offer the full netpbm.

Surely, you can pipe a couple of netpbm utilities one behind the other to get
the result you want.

Also, what is your definition of "pixmap", please ? The generally accepted
definition of pixmap is this.

I am not a specialist in graphics, far from it. But I do know that it is impossible
to put an entire jpg or png image in one single pixmap.

Perhaps edit the title of your thread? TIA.

Respectfully.

_________________
musher0
~~~~~~~~~~
Je suis né pour aimer et non pas pour haïr. (Sophocle) /
I was born to love and not to hate. (Sophocles)
Back to top
View user's profile Send private message 
vovchik


Joined: 23 Oct 2006
Posts: 1469
Location: Ukraine

PostPosted: Sun 12 Aug 2018, 18:49    Post subject:  

I don't mean to beat my own drum here, but for simple conversion, you could use my little picscale, which Barry has compiled for recent puppies:

Code:
picscale

picscale image resizer/converter - v.0.1b by vovchik, Puppy Linux Forum, July 2011

Input formats supported: pnm, pbm, pgm, ppm, tga, xpm, tiff, pcx, gif,
xbm, wmf, icns, bmp, png, jpg, svg and ico.

Output formats supported: png, jpg, bmp, tiff and ico.

Input parameters: -i oldfilename -o newfilename height width quality/compression/depth

Example: picscale -i old.png -o new.png 128 128 9

Quality/compression/depth settings:

   bmp (N/A):               0 - 100
   jpeg (quality):          0 - 100
   png (compression):       0 - 9
   tiff (compression type): 1 - 8
   ico (depth):             16, 24 or 32


Since it uses gdk_pixbuf_loader, there is nothing to install.

Cheers,
vovchik
Back to top
View user's profile Send private message 
wiak

Joined: 11 Dec 2007
Posts: 996
Location: not Bulgaria

PostPosted: Sun 12 Aug 2018, 19:05    Post subject:  

arivas_2005 wrote:

How can I make the image fit the frame?
large or small, suits the size of the <pixmap> box


Actually, this is a reasonable and good question but unfortunately as far as I know gtkdialog hasn't implemented support for scaling.

EDIT: As I said below, I know nothing about pixmap handling... Seems there is scaling support of some sort already in widget_pixmap.c, though I haven't studied how it works so no idea if relevant to your problem, arivas. (Did manage to rescale an image, but that was after a recompile after hard-coding a 'width' size, which rescaled accordingly - didn't yet try how to do it with own gtkwialog program). So sorry, no help for your question from me at this point of time. If I find something I'll come back on it of course, but I mean to stop programming for a while so maybe a long while.

Alas, I know nothing much about pixmap handling, but it seems to me that in GTK+2 it is usually done by GDK (in GTK+3, Cairo scaling function can be used) and in particular gdk_pixbuf_scale_simple, which isn't used in gtkdialog as far as a quick look tells me. For example see this link:

https://stackoverflow.com/questions/1269320/scale-an-image-in-gtk

https://developer.gnome.org/gdk-pixbuf/stable/gdk-pixbuf-Scaling.html

Perhaps vovchik uses such function in his app and or is familiar with it?

I'll experiment. From above links, I think using

Code:
gdk_pixbuf_scale_simple()

using a pointer to a GdkPixbuf

or maybe/more-likely:

Code:
gdk_pixbuf_new_from_file_at_scale()

using a pointer to an imagefile

with a bit of surrounding logic around line 144 of widget_pixmap.c in gtkdialog/gtkwialog might work, but won't know till I try it...

wiak

Last edited by wiak on Sun 12 Aug 2018, 23:25; edited 2 times in total
Back to top
View user's profile Send private message 
wiak

Joined: 11 Dec 2007
Posts: 996
Location: not Bulgaria

PostPosted: Sun 12 Aug 2018, 21:25    Post subject:  

I remember forum member SFR made a paint program using gtkdialog but I can't remember its name or where it is. Maybe that contains some relevant info about pixmap handling.

EDIT: Found here:

http://murga-linux.com/puppy/viewtopic.php?t=82333

Hmmm. not sure that helps in this case, sorry. I'm still looking into this issue though since, as I said, I have managed to quickly get loading file to scale via a hardcode addition to gtkwialog source. It's just a matter of getting the desired width parameter to the pixmap handling routine. Presumably the script syntax for doing that is already built in (like I say I have just never used pixmaps) but if not, seems to me it could be incorporated. I note you tried width-request but that doesn't alter pixmap width itself. As I said I'll report back once I've studied the code unless someone who just knows the answer just post that.

EDIT2: Okay, I've checked and, on running your script, note that internally width and height are both being reported as -1; that causes gtkwialog to avoid the scaling code, which, assuming I understand your issue, is the problem. I'll now look into how 'width' parameter currently gets passed into that part of the gtkwialog, which should answer how to do it (or indicate new code required in gtkdialog/gtkwialog in order to do it).

wiak

Last edited by wiak on Sun 12 Aug 2018, 22:34; edited 1 time in total
Back to top
View user's profile Send private message 
MochiMoppel


Joined: 26 Jan 2011
Posts: 1682
Location: Japan

PostPosted: Sun 12 Aug 2018, 22:34    Post subject:  

@arivas_2005:

Instead of
Code:
echo '<pixmap resizable="false"  scrollable="f" height-request="170" width-request="250" >
<variable>IMAGEN</variable>
<input file>'$IMAGE'</input>
</pixmap>'


use
Code:
echo '<pixmap>
<variable>IMAGEN</variable>
<width>250</width>
<height>170</height>
<input file>'$IMAGE'</input>
</pixmap>'

Note that images smaller than 250x170 will be enlarged!
Back to top
View user's profile Send private message 
wiak

Joined: 11 Dec 2007
Posts: 996
Location: not Bulgaria

PostPosted: Sun 12 Aug 2018, 22:36    Post subject:  

Okay, problems solved. So that's how width and height are passed to pixmap. Good to know, saves reading the source code.

I was just about to look here (or in docs with sources):

http://01micko.com/reference/pixmap.html

Should have done that first.

Note to myself anyway: that the function used internally in gtkdialog/gtkwialog preserves the aspect ratio. That could be supplemented/substitued with some new code (internally in gtkwialog) using my earlier mentioned:

Code:
gdk_pixbuf_new_from_file_at_scale()


which can either preserve aspect ratio or provide actual width and height pixmap requested. EDIT: Some advantages of the _at_scale method:

Quote:
When preserving the aspect ratio, a width of -1 will cause the image to be scaled to the exact given height, and a height of -1 will cause the image to be scaled to the exact given width. When not preserving aspect ratio, a width or height of -1 means to not scale the image at all in that dimension.


That would be instead of the currently used:

Code:
gdk_pixbuf_new_from_file_at_size()
, which scales but always preserves aspect ratio and does have the up-scaling issue mentioned.

wiak
Back to top
View user's profile Send private message 
musher0

Joined: 04 Jan 2009
Posts: 13000
Location: Gatineau (Qc), Canada

PostPosted: Sun 12 Aug 2018, 23:31    Post subject:  

Hi guys.

FWIW.
Code:
#!/bin/ash
# /root/my-applications/bin/scalejpg.sh # For PuppyLinux
#
# Usage: scalejpg.sh $1 $2
# scalejpg.sh < image > < proportion >
#
### Using picture at:
# http://www.dogbreedslist.info/free-dog-wallpapers/German-Shepherd-puppy-protruding-tongue.html
# Examples :
# /root/my-applications/bin/scalejpg.sh German-Shepherd-puppy-protruding-tongue-900x506.jpg 1.25
# (enlarge to 125 %)
# /root/my-applications/bin/scalejpg.sh German-Shepherd-puppy-protruding-tongue-900x506.jpg .5
# (reduce to 50 %)
#
# Requires: jpegtopnm, pamscale, pnmtojpeg from netpbm package.
# (c) musher0, Aug. 12 2018. GPL3
####
image="$1"
percent="$2"
cp $image $image.1 # Keeping the original.
defaultimageviewer $image.1 &
jpegtopnm $image.1 | pamscale -xscale=$percent -yscale=$percent | pnmtojpeg > $image.2
defaultimageviewer $image.2

You could play with the variables to get the defaultimageviewer to show the
same picture name, therefore giving the illusion of instant reduction or
enlargement.

With qiv it works. Other viewers? I don't know. I couldn't care less for the
gtk-message language, too. Tit for tat. Twisted Evil

BFN.
scalejpgExample.jpg
 Description   
 Filesize   105.27 KB
 Viewed   129 Time(s)

scalejpgExample.jpg


_________________
musher0
~~~~~~~~~~
Je suis né pour aimer et non pas pour haïr. (Sophocle) /
I was born to love and not to hate. (Sophocles)

Last edited by musher0 on Mon 13 Aug 2018, 12:23; edited 1 time in total
Back to top
View user's profile Send private message 
wiak

Joined: 11 Dec 2007
Posts: 996
Location: not Bulgaria

PostPosted: Mon 13 Aug 2018, 00:58    Post subject:  

musher0 wrote:
I couldn't care less for the
gtk-message language, too. Tit for tat. Twisted Evil

BFN.


There are many ways to crack a nut and plenty of superb little image utility apps, sxiv being my own favourite - few deps yet even does animated gifs (though underneath many, but not all, utilities access the same GTK+ functions). And as you may know, I much prefer IUP syntax (nested curly brackets rather than pseudo xml) when it comes to GTK function access simplification from a programming point of view.

Straight GTK+ programming from C isn't too bad either, though first you have to learn C and there are lots of GTK functions and steps in building the GTK (but not so terribly different really from gtkdialog or IUP for that matter, which tend to group/wrap steps for ease of use and to limit the number of functions available to the programmer).

Overall, I think the likes of yad and gtkdialog are good for creating quick frontends to commandline utils that don't come with a gui themselves. Not so good for creating bigger apps where you will probably find better alternatives written in C, C++, with GTK or QT, easily enough. IUP, however, is different, since it is designed for full-blown apps too, and nice that it can be driven via Lua (and several other language bindings).

I also feel that over-concentrating on gtkdialog type apps as a programmer is limiting in terms of advancing programming techniques and experience. But for a hobby makes no difference one way or the other.

One thing for sure, despite the countless thousand of apps already available, someone has to write the apps and keep doing so. User's perspective is understood but doesn't change that development necessity.

But, yes, of course, the commandline and simple shell scripts more generally are excellent for their ability to pipe commandlines together for a desired overall result.

wiak
Back to top
View user's profile Send private message 
musher0

Joined: 04 Jan 2009
Posts: 13000
Location: Gatineau (Qc), Canada

PostPosted: Mon 13 Aug 2018, 12:39    Post subject:  

Thanks for the intelligent answer, wiak.

Reading it, this old English proverb came to my mind, with so many computer
languages and dialects to try out: "Jack of all trades, master of none."

For a young hobbyist, it probably does not matter if he dabbles in this language
and juggles with that other language also: he has years left to decide which
computer language he prefers to use. An older hobbyist knows he does not have
many years left, so will tend to focus on trying to master only one language.
Just a thought.

BFN.

_________________
musher0
~~~~~~~~~~
Je suis né pour aimer et non pas pour haïr. (Sophocle) /
I was born to love and not to hate. (Sophocles)
Back to top
View user's profile Send private message 
wiak

Joined: 11 Dec 2007
Posts: 996
Location: not Bulgaria

PostPosted: Mon 13 Aug 2018, 17:21    Post subject:  

musher0 wrote:
"Jack of all trades, master of none."

...An older hobbyist knows he does not have
many years left, so will tend to focus on trying to master only one language.


Agreed and agreed. But modern systems are complex and very often one tool unfortunately cannot do the job. I wish there was one perfect programming language that did everything - would make education, and practice easy, but everything is tied together with different colours of string, weaving patterns, and types of knot. Most of us thus learn a subset of tools, but certainly not all (and whether we master any is a matter for conjecture. It is certainly very useful when some choose to concentrate on one language and hence have time to become encyclopedias of its intracacies.

As far as programming more generally is concerned, some who try to learn the 'art' end by giving up because they started at page 1 of the manual, reached page 100 and there were one thousand pages still to go. The person who just reads the introduction, about the basics, the syntax, and the structure, and then dives in to the deep end may actually prove able to use the language in practice. Bit like French to me maybe. Such programmers research and learn new tricks about any specific language only when they need them. They become specialists in certain areas only - which is why helpful collaboration, rather than arrogant put-downs, is what open source development it is all about.

Very off-topic this so I'll add that I'm glad to have stumbled across this thread because it has encouraged me to head into pixmap research mode - one of many areas of GTK+ programming I knew zilch about.

wiak
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 1 [12 Posts]  
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Off-Topic Area » Programming
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.2686s ][ Queries: 13 (0.0877s) ][ GZIP on ]