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 Thu 29 Jun 2017, 05:22
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
GtkDialog - tips
Post new topic   Reply to topic View previous topic :: View next topic
Page 67 of 78 [1164 Posts]   Goto page: Previous 1, 2, 3, ..., 65, 66, 67, 68, 69, ..., 76, 77, 78 Next
Author Message
mister_electronico


Joined: 20 Jan 2008
Posts: 951
Location: Asturias_ España

PostPosted: Sun 29 Mar 2015, 12:29    Post subject: Explanation  

To make turning the knob and needed to create the following variables.

DEGRED = IF THE POSITION OF RED POINT.
DEGR= IF THE VARIABLE OF ANGLE ROTATION

This variable can be used later to tell the program where the control level is

X = position of your mouse axis X
Y = position of your mouse axis Y

Px = position of the red dot on axis X
Py = position of the red dot on axis Y

Px=cosine(DEGRED)
Py=sine(DEGRED)


Here I leave a picture to try to clarify how it works
explanation program.png
 Description   
 Filesize   9.04 KB
 Viewed   575 Time(s)

explanation program.png

Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger 
mister_electronico


Joined: 20 Jan 2008
Posts: 951
Location: Asturias_ España

PostPosted: Sun 29 Mar 2015, 12:31    Post subject: All program.  

All program:

Code:

#!/bin/bash

export TEMPDIR=/tmp/knob
mkdir $TEMPDIR
trap 'rm -rf $TEMPDIR' EXIT

export PIC=$TEMPDIR/pic.svg
export DEGREE=$TEMPDIR/degree
export CORDENATE=$TEMPDIR/cordenate

echo 0 > $DEGREE

# DEGREE is the angle you have to turn is not the actual angle in the red dot is
cp ./rotary1.svg $PIC
cp ./rotary1.png $TEMPDIR

export WIN_NAME="KNOB"
export YF=6
export PIC_X=300

# Get current, relative position of cursor
get_xy () {
  read MX MY WX WY WI <<< `getcurpos && xwininfo -name "$WIN_NAME" 2>/dev/null | awk 'NR>=4&&NR<=5 {print $4} NR==8 {print $2}'`
  X=$((($MX-$WX)-($WI-$PIC_X)/2))
  Y=$(($MY-$WY-$YF))
  echo "X: $X   Y: $Y"
 
  DEGR=$(<$DEGREE) 
 
  let DEGRED=240-DEGR # Get the value of the angle where it really is the red dot
 

 
  PI=$(echo "scale=10; 4*a(1)" | bc -l )
  RADIANS=$(echo "scale=5; $DEGRED*$PI/180" | bc -l )
  VAL=$(echo "scale=5; 120*s($RADIANS)" | bc -l )
  Py=$(echo "(-1)*$VAL/1+150" | bc )

  VAL=$(echo "scale=5; 135*c($RADIANS)" | bc -l )
  Px=$(echo "$VAL/1+150" | bc )
 
  echo "the value DEGRED es " $DEGRED
  echo "the value DEGR es " $DEGR
  echo "the value Px es " $Px
  echo "the value Py es " $Py 
 
  if  [ $DEGR -lt 154 ] && [ $Px -lt 151 ] && [ $X -lt 150 ] && [ $Py -lt $Y ] && [ $Y -lt 260 ]; then DEGR=$(($DEGR-5)); echo $DEGR > $DEGREE; fi   
  if  [ $DEGR -lt 154 ] && [ $Px -lt 151 ] && [ $X -lt 150 ] && [ $Py -gt $Y ] && [ $Y -lt 260 ]; then DEGR=$(($DEGR+5)); echo $DEGR > $DEGREE; fi
  if  [ $DEGR -lt 154 ] && [ $Px -lt 151 ] && [ $X -gt 150 ] && [ $Y -lt 260 ]; then DEGR=$(($DEGR+5)); echo $DEGR > $DEGREE; fi
 
  if  [ $DEGR -gt 154 ] && [ $Px -gt 150 ] && [ $X -gt 150 ] && [ $Py -lt $Y ] && [ $Y -lt 260 ]; then DEGR=$(($DEGR+5)); echo $DEGR > $DEGREE; fi   
  if  [ $DEGR -gt 154 ] && [ $Px -gt 150 ] && [ $X -gt 150 ] && [ $Y -lt $Py ] && [ $Y -lt 260 ]; then DEGR=$(($DEGR-5)); echo $DEGR > $DEGREE; fi   
  if  [ $DEGR -gt 154 ] && [ $Px -gt 150 ] && [ $X -lt 150 ] && [ $Y -lt 260 ]; then DEGR=$(($DEGR-5)); echo $DEGR > $DEGREE; fi   


echo '<svg width="35mm" height="35mm" transform="scale(1.0) rotate('$DEGR' 60 60)"
   id="svg1"
   sodipodi:version="0.32"
   inkscape:version="0.36"
   xmlns="http://www.w3.org/2000/svg"
   xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
   xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
   xmlns:xlink="http://www.w3.org/1999/xlink"
   sodipodi:docbase="/tmp/knob"
   sodipodi:docname="/tmp/knob/rotary1.svg">
  <defs
     id="defs3" />
  <sodipodi:namedview
     id="base" />
  <image
     xlink:href="rotary1.png"
     sodipodi:absref="/tmp/knob/rotary1.png"
    x="0" y="0"
     width="120.000000"
     height="120.000000"
     id="image562" />
</svg>' > $PIC
}

export -f get_xy

echo '
<window title="'${WIN_NAME}'">
  <vbox>
    <eventbox>
      <pixmap>
        <variable>PICTURE</variable>     
        <input file>'$PIC'</input>
        <width>'${PIC_X}'</width>
      </pixmap>
      <action signal="button-press-event">enable:varTIMER</action>
      <action signal="button-release-event">disable:varTIMER</action>
    </eventbox>

    <timer visible="false" milliseconds="true" interval="100" sensitive="false">
      <variable>varTIMER</variable>
      <action>get_xy</action>
      <action>refresh:PICTURE</action>
    </timer>
  </vbox>
</window>' | gtkdialog -s



I will continue working on.
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger 
mister_electronico


Joined: 20 Jan 2008
Posts: 951
Location: Asturias_ España

PostPosted: Sun 29 Mar 2015, 12:51    Post subject: Some considerations.  

Some considerations:

The knob rotates very slow for me, I think this is because the burning process SVG image files on the memory in the /tmp/knob is a slow process.

I think that any process of recording a file on memory or hard disk makes the process very slow independent that the file has a very small as is the case in this instance size.

So I'm thinking it could create all SVG images when begin the program.

Thinking that knob rotate in steps of 5 degrees this would

300º / 5 = 60 images

rotary1.svg=899bits so

60x899=53940 bits ---------so ------- 53942 / 1024 = about 53 K

This deal would make the program a little more memory, but

Then one would have to be loading picture as the angle, and in this case the program would have to read only pictures, no burn it.

I think it would be much faster.

Well I'm thinking out loud, so let you is burning my single neuron that I have.

see you

Regards
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger 
mister_electronico


Joined: 20 Jan 2008
Posts: 951
Location: Asturias_ España

PostPosted: Mon 30 Mar 2015, 09:42    Post subject: Question?  

Question? Is there any way to pass a variable to the input pixmap to change the name example:

function{

Here I want give diferent names to $PIC
PIC = img1.svg next time img2.svg............
}


<pixmap>
<input file>'$PIC'</input>
</pixmap>

Do not let me change it only gets the name I give to "export"


Thank you
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger 
don570


Joined: 10 Mar 2010
Posts: 4599
Location: Ontario

PostPosted: Tue 31 Mar 2015, 20:43    Post subject:  

When I tried your script it was too slow. Crying or Very sad
Retrovol uses C or Basic for a crude but effective slider

It's open source software

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


Joined: 20 Jan 2008
Posts: 951
Location: Asturias_ España

PostPosted: Wed 01 Apr 2015, 13:13    Post subject: yes.  

Yes don570 you are right every step 5 degrees rotation knob :
Make image svg file - write in memory - read in pixmap .

This makes the process very slow in gkdialog.

I'll try in C as you say to try to do it faster.

Thank for check the program and and give me an answer

See you.
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger 
zigbert


Joined: 29 Mar 2006
Posts: 6436
Location: Valåmoen, Norway

PostPosted: Wed 01 Apr 2015, 18:52    Post subject:  

Knob
A simpler and faster approach
NB! remove existing /tmp/knob

Code:

#!/bin/bash

export PIC_Y=300 #set height/width of knob
export COLOR='#444'
export COLOR_DOT='red'

export TEMPDIR=/tmp/knob
if [ ! -d $TEMPDIR ]; then
   mkdir $TEMPDIR
   echo 0 > $TEMPDIR/degree
fi

# Get current, relative position of cursor
get_xy () {
   DEGR="$(<$TEMPDIR/degree)"
   Y="`getcurpos | awk '{print $2}'`"
   Y2="$(<$TEMPDIR/cursor_y)"
   DEGR=$(($DEGR+($Y2-$Y)))
   [ $DEGR -lt 1 ] && DEGR=0; [ $DEGR -gt 250 ] && DEGR=250 #keep value in range
   echo $Y > $TEMPDIR/cursor_y
   echo $DEGR > $TEMPDIR/degree
   echo Y:$Y DEGR:$DEGR

   echo '
   <svg width="'${PIC_Y}'" height="'${PIC_Y}'" transform="scale(1.0) rotate('$DEGR' '$((${PIC_Y}/2))' '$((${PIC_Y}/2))')">
      <circle style="fill:'$COLOR';" cx="'$((${PIC_Y}/2))'" cy="'$((${PIC_Y}/2))'" r="'$((${PIC_Y}*45/100))'"/>
      <circle style="fill:'$COLOR_DOT';" cx="'$((${PIC_Y}*20/100))'" cy="'$((${PIC_Y}*75/100))'" r="'$((${PIC_Y}*3/100))'"/>
   </svg>' > $TEMPDIR/pic.svg
}

export -f get_xy

echo '
<window title="knob">
  <vbox>
    <eventbox>
      <pixmap>
        <variable>PICTURE</variable>     
        <input file>'$TEMPDIR/pic.svg'</input>
        <height>'${PIC_Y}'</height>
      </pixmap>
      <action signal="button-press-event">getcurpos | awk '"'"'{print $2}'"'"' > '$TEMPDIR'/cursor_y</action>
      <action signal="button-press-event">enable:varTIMER</action>
      <action signal="button-release-event">disable:varTIMER</action>
    </eventbox>

    <timer visible="false" milliseconds="true" interval="50" sensitive="false">
      <variable>varTIMER</variable>
      <action>get_xy</action>
      <action>refresh:PICTURE</action>
    </timer>
  </vbox>
</window>' | gtkdialog -s

_________________
Stardust resources
Back to top
View user's profile Send private message Visit poster's website 
mister_electronico


Joined: 20 Jan 2008
Posts: 951
Location: Asturias_ España

PostPosted: Thu 02 Apr 2015, 05:42    Post subject: hi  

Zigbert very smart , It is now much faster.

I always thinking in the SVG image and forgot the rotary1.png image of 15 Kbit.

I think the load this png file makes the process slower.

I'll try to make it more attractive rotary knob by SVG like bottons of don570, I hope not increase much in size and make the process slower.

The knob does not respond correctly to mouse in my system, I will try to study your code.

But now I'm five days off to my small town retake it when I return.

Thanks for everything

Greetings.
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger 
zigbert


Joined: 29 Mar 2006
Posts: 6436
Location: Valåmoen, Norway

PostPosted: Thu 02 Apr 2015, 14:51    Post subject:  

Not hard to improve the looks Smile
forum.jpg
 Description   
 Filesize   22.68 KB
 Viewed   433 Time(s)

forum.jpg


_________________
Stardust resources
Back to top
View user's profile Send private message Visit poster's website 
zigbert


Joined: 29 Mar 2006
Posts: 6436
Location: Valåmoen, Norway

PostPosted: Thu 02 Apr 2015, 14:53    Post subject:  

This snippet handles the 4 knobs separately
Code:
#!/bin/bash

export KNOB_Y=60 #set height/width of knob
export COLOR='#A4BEA9' #78837A
export COLOR_DOT='#eee' #999
export WORKDIR=/tmp/knob

draw_knob (){
   echo '
   <svg width="'${KNOB_Y}'" height="'${KNOB_Y}'">
     <defs>
       <radialGradient
         id="RG1" cx="'$((${KNOB_Y}*30/100))'" cy="'$((${KNOB_Y}*30/100))'" fx="'$((${KNOB_Y}*30/100))'" fy="'$((${KNOB_Y}*30/100))'" r="'$((${KNOB_Y}*45/100))'"
         gradientUnits="userSpaceOnUse">
         <stop style="stop-color:#393939;stop-opacity:1;" offset="1"/>
         <stop style="stop-color:#888;stop-opacity:1;" offset="0"/>
       </radialGradient>
     </defs>
      <circle style="fill:#111;" cx="'$(((${KNOB_Y}/2)+(${KNOB_Y}*3/100)))'" cy="'$(((${KNOB_Y}/2)+(${KNOB_Y}*3/100)))'" r="'$((${KNOB_Y}*46/100))'"/>
      <circle style="fill:#585858" cx="'$((${KNOB_Y}/2))'" cy="'$((${KNOB_Y}/2))'" r="'$((${KNOB_Y}*46/100))'"/>
      <circle style="fill:url(#RG1);stroke:'$COLOR';stroke-width:'$((${KNOB_Y}*2/100))'" cx="'$((${KNOB_Y}/2))'" cy="'$((${KNOB_Y}/2))'" r="'$((${KNOB_Y}*40/100))'"/>
      <circle style="fill:'$COLOR_DOT';" cx="'$((${KNOB_Y}*27/100))'" cy="'$((${KNOB_Y}*75/100))'" r="'$((${KNOB_Y}*4/100))'" transform="rotate('$1' '$((${KNOB_Y}/2))' '$((${KNOB_Y}/2))')"/>
   </svg>' > $2
}

# Get current, relative position of cursor
get_y (){
   NR="$(<$WORKDIR/knob_nr)"
   DEGR="$(<$WORKDIR/knob_${NR}_value)"
   Y="`getcurpos | awk '{print $2}'`"
   Y2="$(<$WORKDIR/cursor_y)"
   DEGR=$(($DEGR+($Y2-$Y))) #The knob's value range is equal to moving mouse 250 px.
   [ $DEGR -lt 1 ] && DEGR=0; [ $DEGR -gt 250 ] && DEGR=250 #keep value inside range
   echo $Y > $WORKDIR/cursor_y
   echo $DEGR > $WORKDIR/knob_${NR}_value
   echo Knob_${NR}: Y:$Y DEGR:$DEGR
   draw_knob $DEGR $WORKDIR/knob_${NR}.svg
}

export -f draw_knob get_y

if [ ! -d $WORKDIR ]; then
   mkdir $WORKDIR
   for I in 1 2 3 4; do
      echo 0 > $WORKDIR/knob_${I}_value
      draw_knob 0 $WORKDIR/knob_${I}.svg
   done
fi

echo '
<window title="knob">
<vbox>
  <hbox>
    <timer visible="false" milliseconds="true" interval="100" sensitive="false">
      <variable>TIMER</variable>
      <action>get_y</action>
      <action>refresh:KNOB_1</action>
      <action>refresh:KNOB_2</action>
      <action>refresh:KNOB_3</action>
      <action>refresh:KNOB_4</action>
    </timer>' > $WORKDIR/xml_knob
for I in 1 2 3 4; do
   echo '
   <eventbox>
     <pixmap>
       <variable>KNOB_'$I'</variable>     
       <input file>'$WORKDIR/knob_${I}.svg'</input>
       <height>'${KNOB_Y}'</height>
     </pixmap>
     <action signal="button-press-event">getcurpos | awk '"'"'{print $2}'"'"' > '$WORKDIR'/cursor_y</action>
     <action signal="button-press-event">echo '$I' > '$WORKDIR'/knob_nr</action>
     <action signal="button-press-event">enable:TIMER</action>
     <action signal="button-release-event">disable:TIMER</action>
   </eventbox>' >> $WORKDIR/xml_knob
done
echo '
  </hbox>
</vbox>
</window>' >> $WORKDIR/xml_knob
gtkdialog -f $WORKDIR/xml_knob

_________________
Stardust resources
Back to top
View user's profile Send private message Visit poster's website 
don570


Joined: 10 Mar 2010
Posts: 4599
Location: Ontario

PostPosted: Thu 02 Apr 2015, 20:33    Post subject:  

Quote:
I'll try to make it more attractive rotary knob by SVG like bottons of don570,


I made fancy candy colored text label buttons that were two different sizes
One for normal buttons 'OK' 'Cancel'
and another size for longer phrases.
Back to top
View user's profile Send private message 
technosaurus


Joined: 18 May 2008
Posts: 4718

PostPosted: Thu 02 Apr 2015, 22:09    Post subject:  

You can do this in svg with paths and a transform="rotate(...)":
https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/transform#Types_of_transform_definition

I like to hand write my SVGs for better control, but existing editors either mangle the code or don't have good access to the source, so I wrote a simple editor here:
http://murga-linux.com/puppy/viewtopic.php?p=836250#836250
I've found it to be extremely useful to play with paths and transforms until I understand them

Here is a simplified knob using only paths and rotate() ... just change height and width to XXpx
<svg id="svg" width="100%" height="100%" viewBox="0 0 96 96"><path d="M47 1A47 47 0 1 0 49 1z"/>
<path fill="red" transform="rotate(270, 48, 4Cool" d="M48 1A4 4 0 1 0 50 1z"/>
</svg>

_________________
Web Programming - Pet Packaging 100 & 101
Back to top
View user's profile Send private message 
01micko


Joined: 11 Oct 2008
Posts: 8652
Location: qld

PostPosted: Fri 03 Apr 2015, 03:04    Post subject:  

technosaurus wrote:
You can do this in svg with paths and a transform="rotate(...)":
https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/transform#Types_of_transform_definition

I like to hand write my SVGs for better control, but existing editors either mangle the code or don't have good access to the source, so I wrote a simple editor here:
http://murga-linux.com/puppy/viewtopic.php?p=836250#836250
I've found it to be extremely useful to play with paths and transforms until I understand them

Here is a simplified knob using only paths and rotate() ... just change height and width to XXpx
Code:
<svg id="svg" width="100%" height="100%" viewBox="0 0 96 96"><path d="M47 1A47 47 0 1 0 49 1z"/>
<path fill="red" transform="rotate(270, 48, 48)" d="M48 1A4 4 0 1 0 50 1z"/>
</svg>
That darn droid and that darn Cool Smile
_________________
Puppy Linux Blog - contact me for access
Back to top
View user's profile Send private message Visit poster's website 
mister_electronico


Joined: 20 Jan 2008
Posts: 951
Location: Asturias_ España

PostPosted: Mon 06 Apr 2015, 18:13    Post subject: trying again.  

Just back from my little vacation, hi zigbert I was watching you watching your penultimate code:

http://murga-linux.com/puppy/viewtopic.php?p=837718#837718

It's fast but for me has a problem that does not obey either the mouse.

I think that in the code must be taken into account also the X axis to rotate knob in the appropriate direction depending on the position in which it find.

I was freaking out that even a slight modification I make of your code causes it to become very slow.

The buttons on your last code are very nice, but not if it will be only in my system but I have to hold down the mouse outside the window and turn it so that the knob can fully rotate.

In the code of SFR the mouse only works over knob window I like it but this it is that makes the program more slower.

I think that is right don570 perhaps be better to try piece of code in C.

I am currently developing this program ligth panel:

https://www.youtube.com/watch?v=-B6hQdiPCaM

As soon as I finish I'll put it here, I think part of the code is faster that is in C.

Very interesting Technosaurus the path and rotate () I'll try to have if the speed improves.

Thanks gentlemen for all the information I will continue studying and making progress here

Greetings
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger 
cusco-travel-services

Joined: 02 Mar 2015
Posts: 8

PostPosted: Fri 10 Apr 2015, 20:55    Post subject:  Re: GtkDialog - tips  

zigbert wrote:

Code:
#!/bin/bash
echo 'style "specialmono"
{
  font_name="Mono 12"
}
widget "*mono" style "specialmono"
class "GtkText*" style "specialmono"' > /tmp/gtkrc_mono

export GTK2_RC_FILES=/tmp/gtkrc_mono:/root/.gtkrc-2.0

export test_app="
<vbox>
  <text name=\"mono\"><label>This text-widget uses monospace font....</label></text>
  <text><label>...while this text-widget don't.</label></text>
  <edit><default>All edit-widgets gets monospace.</default></edit>
</vbox>"
gtkdialog --program=test_app


Hi zigbert et al,

What is the following line, in the code above, supposed to do exactly?

Code:
export GTK2_RC_FILES=/tmp/gtkrc_mono:/root/.gtkrc-2.0

Is the colon (:) a Field separator in this context or is it serving some other purpose?

When I use the following, for example, ...

Code:
export GTK2_RC_FILES=/tmp/gtkrc_title:~/.gtkrc-2.0

... echo "$GTK2_RC_FILES" gives /home/mtbvfr/.gtkrc-2.0 but no such directory nor file exists.

Thanks, Michael.
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 67 of 78 [1164 Posts]   Goto page: Previous 1, 2, 3, ..., 65, 66, 67, 68, 69, ..., 76, 77, 78 Next
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.1373s ][ Queries: 13 (0.0149s) ][ GZIP on ]