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 Mon 20 Nov 2017, 02:22
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
gtk: how to put state enable/disable a entry with function?
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [13 Posts]  
Author Message
arivas_2005

Joined: 25 Feb 2007
Posts: 191

PostPosted: Wed 04 Oct 2017, 18:08    Post subject:  gtk: how to put state enable/disable a entry with function?
Subject description: SOLVED
 

Hi
I want to use enable and disable property using function.
in the following example, I can not do it
I can only clean the boxes but not set it to disable B entry

Code:
#!/bin/sh

RIGHT=550 DOWN=36 WIDTH=600 HEIGHT=150   # define variables with defaults

function Onlyfile() {
   length_A=${#ORIGINALFILE}
   echo ${ORIGINALFILE##*"/"} | awk -F"." '{print $1}'>/tmp/pdffile
}
function init_2() {   
   length_A=${#ORIGINALFILE}
   #Xdialog --msgbox $ORIGINALFILE" \n"$length_A x
   if [ "$length_A" -eq 0 ]; then
   Xdialog --msgbox "$ORIGINALFILE "" empty" x;
   echo '<action>refresh:ARCHIVO_T</action>
     <action>disable:PDFFILE</action>
    <action>refresh:PDFFILE</action>' ;
   else           
      Xdialog --msgbox "$ORIGINALFILE"" -->"  x;
         echo '<action>refresh:PDFFILE</action>
       <action>enable:PDFFILE</action>   
       <action>refresh:PDFFILE</action>';
   fi
}

export -f init_2
export -f Onlyfile

export MAIN_DIALOG='
<window title="Learning gtk: modify boxs enable disable and comments ">
   <vbox>
       <text use-markup="true">
         <label>"<span color='"'blue'"' font-family='"'mono'"' weight='"'bold'"' size='"'x-large'"'><big>Learning kgt I</big></span>"
         </label>
        </text>   
       <text use-markup="true">
          <label>"<span color='"'brown'"' weight='"'bold'"' size='"'large'"' >drag ando drop a file to box A</span>"
         </label>
    </text>
   
      <hbox>
         <text label="A" xalign="0"></text>
         <entry>
            <variable>ORIGINALFILE</variable>
            <input>cat /tmp/original</input>
            <action>refresh:PDFFILE</action>
            <action signal="changed">Onlyfile</action>
            <action signal="changed">init_2</action>
            <action>eval ORIGINALFILE</action>
            <action>refresh:PDFFILE</action>
         </entry>
      </hbox>
     
      <hbox>
         <text label="B" xalign="0"></text>     
         <entry>
            <variable>PDFFILE</variable>
            <input>cat /tmp/pdffile</input>         
         </entry>
      </hbox>
     
      <hbox>
         <button>
            <label>Clear A and B</label>
            <action>echo "" /tmp/original</action>
            <action>echo "" /tmp/pdffile</action>
            <action signal="changed">init_2</action>
             <action>refresh:ORIGINALFILE</action>
         </button>
         <button>
            <label>Refresh B</label>
            <action>Onlyfile</action>
            <action>refresh:PDFFILE</action>
         </button>
         <button>
            <label>Exit</label>
             <action>exit:Exit</action>
         </button>         
     </hbox>
   
   </vbox>

</window>
'
I=$IFS; IFS=""
for STATEMENTS in $(gtkdialog -p MAIN_DIALOG -G ${1-${WIDTH}x${HEIGHT}+${RIGHT}+${DOWN}}); do
   eval $STATEMENTS
done
IFS=$I

help in:
1) I need to convert to disable box entry B when the script starts
2) I need to convert to disable entry B when clicking on button 'Clear A and B'
3) How do I include comments in the code?
Iuse:
<!-- comment here -->
'$(rem comment here)'
# comment here,
but Not Works
Thank you!

Last edited by arivas_2005 on Fri 06 Oct 2017, 23:19; edited 2 times in total
Back to top
View user's profile Send private message 
MochiMoppel


Joined: 26 Jan 2011
Posts: 1390
Location: Japan

PostPosted: Wed 04 Oct 2017, 22:32    Post subject:  

1) Please respond to your old thread before you start a new one
2) Do not put the same question into 2 different threads
3) Do not put multiple questions into 1 thread
4) Keep your sample code as simple as possible, just enough to demonstrate your problem.
5) Once again: Pay attention to error messages! A "command not found" message should tell you that something is seriously wrong with your code.
6) Avoid
    for STATEMENTS in $(gtkdialog -p MAIN_DIALOG ); do
    eval $STATEMENTS
    done
constructs when you don't need them. In your case prevents you from seeing that many of your echo commands do not work as you might have expected.
7) Use something like I=$IFS; IFS="" only if you know what you are doing.
8) Study the examples that come with the Gtkdialog documentation.
9) Study zigbert's GtkDialog - tips thread. Already the first post will answer your question re. comments.
Back to top
View user's profile Send private message 
arivas_2005

Joined: 25 Feb 2007
Posts: 191

PostPosted: Fri 06 Oct 2017, 16:23    Post subject:  

regards
I will take into account the suggestions
and thank you for your contributions
-- I also modified the heading, more specific --
Excuse my insistence Embarassed
I have already simplified my sample, so
(I explain with image what I am looking for)
Code:
#!/bin/sh
echo "">/tmp/original
echo "" >/tmp/pdffile
function init_2() {   
   length_A=${#ORIGINALFILE}
   if [ "$length_A" -eq 0 ]; then   
    echo '<action>disable:PDFFILE</action>
          <action>refresh:PDFFILE</action>';
          echo "empty"
   else           
       echo '<action>enable:PDFFILE</action>
          <action>refresh:PDFFILE</action>';
      echo "$ORIGINALFILE"
   fi
}
export -f init_2
export MAIN_DIALOG='
<window>
   <vbox>   
         <entry>
            <variable>ORIGINALFILE</variable>
            <input>cat /tmp/original</input>
            <action signal="changed">init_2</action>
            <action>refresh:PDFFILE</action>
         </entry>
         <entry>
            <variable>PDFFILE</variable>
            <sensitive>false</sensitive>
            <input>cat /tmp/pdffile</input>     
         </entry>     
         <button>
            <label>Clear A and B</label>
            <action>echo "">/tmp/original</action>
         <action>echo "" /tmp/pdffile</action>
         <action>refresh:ORIGINALFILE</action>
         </button>   
   </vbox>
</window>
'
gtkdialog --program=MAIN_DIALOG

exit

Or it is impossible, as happens with alignment (previous case)
Thanks you
boxs-text.png
 Description   
 Filesize   6 KB
 Viewed   201 Time(s)

boxs-text.png

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


Joined: 26 Jan 2011
Posts: 1390
Location: Japan

PostPosted: Fri 06 Oct 2017, 22:40    Post subject:  

Aaah, that's much better...I mean, the code is better digestible now. I'm still not sure if I understand what you are trying to do.
arivas_2005 wrote:
Excuse my insistence Embarassed
Your admirable insistence is what keeps me going Laughing
Quote:
Or it is impossible, as happens with alignment (previous case)
What is "it"? If you mean "enable/disable a entry with function" as indicated in your title and your code, then yes, it's not possible. You can't execute a gtkdialog function (e.g. enable:PDFFILE) from an external function and you can't change the gtkdialog code after starting gtkdialog, so this will not work:
function init_2() {
echo '<action>disable:PDFFILE</action>
<action>refresh:PDFFILE</action>';


The good news is that en/disabling or clearing an <entry> widget is much easier than you probably think. I figure that the only reason for your reading and writing (almost) empty temp files is your attempt to clear the widgets.

Try this. No function or temp file required:
Code:
#!/bin/sh
export MAIN_DIALOG='
<window>
<vbox>   
     <entry>
       <variable>ORIGINALFILE</variable>
       <action condition="command_is_true( [[ -z $ORIGINALFILE ]] && echo true )">disable:PDFFILE</action> 
       <action condition="command_is_true( [[ -n $ORIGINALFILE ]] && echo true )">enable:PDFFILE</action> 
       <action>refresh:PDFFILE</action>
     </entry>
     <entry>
       <variable>PDFFILE</variable>
       <sensitive>false</sensitive>
       <input>basename "$ORIGINALFILE"</input>     
     </entry>     
     <button>
       <label>Clear A and B</label>
       <action>clear:ORIGINALFILE</action>
       <action>clear:PDFFILE</action>
     </button>   
</vbox>
</window>
'
gtkdialog --program=MAIN_DIALOG
Back to top
View user's profile Send private message 
arivas_2005

Joined: 25 Feb 2007
Posts: 191

PostPosted: Fri 06 Oct 2017, 23:17    Post subject:  

ja! that is power. Great ---
(how easy it seems .... that is enable/disable for me)
Code:
<action condition="command_is_true( [[ -z $ORIGINALFILE ]] && echo true )">disable:PDFFILE</action>
       <action condition="command_is_true( [[ -n $ORIGINALFILE ]] && echo true )">enable:PDFFILE</action>

a small explanation: what they do [[ -z $ORIGINALFILE ]] and [[ -n $ORIGINALFILE ]]
--------------------------------
my litle history:
I need to correct many names
drag the original name to the first entry
I correct it in the second (entry), and so the cycle.

is disable the second, to not drop the name there by mistake
and save time
thanks! .. MochiMoppel

in my work there is a lot of information to review and correct, to file, etc.
and I'm not a professional programmer
but I create script to help me in my work
use any example as a base and modify it
(I think there are many who do the same)
...
use google translate to compose questions
(I will learn English someday Embarassed )
You have supported me a lot
Thank you again Very Happy[/code]
Back to top
View user's profile Send private message 
MochiMoppel


Joined: 26 Jan 2011
Posts: 1390
Location: Japan

PostPosted: Fri 06 Oct 2017, 23:41    Post subject:  

arivas_2005 wrote:
I need to correct many names
drag the original name to the first entry
I correct it in the second (entry)

Why don't you correct in the first entry? Why 2 entries?
And since you have to do this with many names: Why drag&drop and clear button? That makes the process slow. If you could paste the original name into the entry field with middle mouse button you wouldn't even need to clear the field first. This could be done automatically before pasting.
Back to top
View user's profile Send private message 
arivas_2005

Joined: 25 Feb 2007
Posts: 191

PostPosted: Sat 07 Oct 2017, 00:22    Post subject:  

Hi
I use the second (entry B) because when I'm wrong to correct,
then, I use refreshment of the first one (entry A). (use the refresh button of the code above)
I avoid dragging the same name twice.
Back to top
View user's profile Send private message 
MochiMoppel


Joined: 26 Jan 2011
Posts: 1390
Location: Japan

PostPosted: Sat 07 Oct 2017, 01:06    Post subject:  

So you are using an additional entry as a kind of clipboard? Why not use the real clipboard?

With a single entry box:
1) Select a name (from a list?)
2) Press Ctrl+C to put it into the clipboard
3a) Move your mouse pointer over the entry field and click middle mouse button. This will paste the selected name.
3b) Alternatively use drag&drop or Ctrl+V to fill the entry field (IMO less comfortable and slower)
4) Make changes to the entry
5) If you make a mistake, e.g. delete a portion that you wanted to keep, dblclick the entry to select it and press Ctrl+V. This will revert it to the original name.
6) When everyting is OK, press Enter to start whatever action needs to be done. One of the actions could be to clear the entry field, to make it ready for the next name.
Back to top
View user's profile Send private message 
arivas_2005

Joined: 25 Feb 2007
Posts: 191

PostPosted: Sat 07 Oct 2017, 19:14    Post subject:  

Thanks for the suggestions. I will practice it.
regards.
Back to top
View user's profile Send private message 
arivas_2005

Joined: 25 Feb 2007
Posts: 191

PostPosted: Sat 07 Oct 2017, 23:59    Post subject:  

Hello
I have doubts. I will ask one by one according to the rule
in the line:
Code:
<input>basename $ORIGINALFILE | awk -F"." '{print $1}'</input>

how it is processed ' (single quote) to avoid errors in '{print $1}', or is not possible.
'"{print $1}"' "'{print $1}'" "'"{print $1}"'" not works or produce error
Thanks!
Back to top
View user's profile Send private message 
MochiMoppel


Joined: 26 Jan 2011
Posts: 1390
Location: Japan

PostPosted: Sun 08 Oct 2017, 01:34    Post subject:  

Welcome to quotation hell Twisted Evil
Code:
<input>basename "$ORIGINALFILE" | awk -F"." '\''{print $1}'\''</input>
Beware that you also need to quote $ORIGINALFILE unless you are dead sure that $ORIGINALFILE contains no space character.

Alternatively you could use bash substring expansion, which requires no quotes at all:
Code:
<input>F=${ORIGINALFILE##*/}; echo ${F%%.*}</input>

Example:
export ORIGINALFILE='/some/sample dir/foo bar.tar.gz'
${ORIGINALFILE##*/} # Strips every character, starting from left, up to last '/' ; Result: foo bar.tar.gz
${F%%.*} # Strips every character, starting from right, up to the last '.' ; Result foo bar
Back to top
View user's profile Send private message 
arivas_2005

Joined: 25 Feb 2007
Posts: 191

PostPosted: Sun 08 Oct 2017, 13:53    Post subject:  

Hello.
here again! Embarassed
Quote:
Welcome to quotation hell

for me, breaking head .. it's an impossible!!
quotation ....it is more than a discipline! .. it's a science!

and, continuing with the questions
-- I need to put the cursor directly in the B box(second entry).
I already did this:
-modified window title
Code:
<window title="Modified_Names"  width-request="400">

-I defined a function with xdotool:
Code:
Wactive () {
   xdotool windowactivate $(xdotool search --name "Modified_Names")
   xdotool click --delay 2 1
   xdotool key Tab Right
}
export -f Wactive

-add the following line in ORIGINALFILE entry:
Code:
<action condition="command_is_true( [[ -n $ORIGINALFILE ]] && Wactive )">refresh:PDFFILE</action>

its works!
information source: your support: MochiMoppel, forum programmer puppylinux and google google...

but, it's possible to do it in gtk action commands?
thanks again for your help!
Back to top
View user's profile Send private message 
MochiMoppel


Joined: 26 Jan 2011
Posts: 1390
Location: Japan

PostPosted: Mon 09 Oct 2017, 00:34    Post subject:  

Code:
<entry>
   <variable>ORIGINALFILE</variable>
   <action condition="command_is_true( [[ -z $ORIGINALFILE ]] && echo true )">disable:PDFFILE</action> 
   <action condition="command_is_true( [[ -n $ORIGINALFILE ]] && echo true )">enable:PDFFILE</action> 
   <action condition="command_is_true( [[ -n $ORIGINALFILE ]] && echo true )">grabfocus:PDFFILE</action> 
   <action condition="command_is_true( [[ -n $ORIGINALFILE ]] && echo true )">refresh:PDFFILE</action> 
</entry>

The gtkdialog grabfocus function always puts the text cursor in front.
If you need the cursor at the end you could use xdotool like this:
Code:
<entry>
   <variable>ORIGINALFILE</variable>
   <action condition="command_is_true( [[ -z $ORIGINALFILE ]] && echo true )">disable:PDFFILE</action> 
   <action condition="command_is_true( [[ -n $ORIGINALFILE ]] && echo true )">enable:PDFFILE</action> 
   <action condition="command_is_true( [[ -n $ORIGINALFILE ]] && echo true )">refresh:PDFFILE</action> 
   <action condition="command_is_true( [[ -n $ORIGINALFILE ]] && echo true )">xdotool key Tab Right</action> 
</entry>
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 1 [13 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.1393s ][ Queries: 13 (0.0115s) ][ GZIP on ]