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 23 Oct 2018, 12:32
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 95 of 96 [1429 Posts]   Goto page: Previous 1, 2, 3, ..., 93, 94, 95, 96 Next
Author Message
smokey01


Joined: 30 Dec 2006
Posts: 2770
Location: South Australia :-(

PostPosted: Sun 05 Aug 2018, 05:29    Post subject:  

I've been beaten again by this gtkdialog.

It's an entry widget with a checkbox widget. The entry widget is to enter a password. The checkbox widget should show the password when true and hide it when false.

Code:
#!/bin/sh

[ -z $GTKDIALOG ] && GTKDIALOG=gtkdialog

MAIN_DIALOG='
<window>
   <vbox>
      <frame Not Working>
         <entry visibility="$CHECKBOX">
            <default>Password</default>
            <variable>ENTRY</variable>
         </entry>
         <checkbox>
            <label>Show/Hide Password</label>
            <variable>CHECKBOX</variable>
            <action>echo $CHECKBOX</action>
            <action>if true enable:ENTRY</action>
            <action>if false disable:ENTRY</action>
            <action>refresh:ENTRY</action>
         </checkbox>
      </frame>
      <hbox>
         <button ok></button>
         <button cancel></button>
      </hbox>
   </vbox>
</window>
'
export MAIN_DIALOG

case $1 in
   -d | --dump) echo "$MAIN_DIALOG" ;;
   *) $GTKDIALOG --program=MAIN_DIALOG ;;
esac

I disable/enable the entry widget to make sure it is toggling properly.
I am also echoing the $CHECKBOX variable to make sure it's changing state which it is.

How do I make the tag attribute visibility="$CHECKBOX" update when the checkbox state is changed. I am refreshing the ENTRY widget but that's not doing it.

It's looks simple enough but it's got me stumped.

Thanks.
password.png
 Description   
 Filesize   7.35 KB
 Viewed   568 Time(s)

password.png


_________________
Software <-> Distros <-> Tips <-> Newsletters
Back to top
View user's profile Send private message Visit poster's website 
SFR


Joined: 26 Oct 2011
Posts: 1665

PostPosted: Sun 05 Aug 2018, 07:06    Post subject:  

That's how I did this once: you need 2 synced <entry> fields (I used <notebook> as a container for them), one with visibility="false" and the other one with visibility="true".
Then by using a checkbox you can simply switch between them, i.e. <notebook>'s tabs.

Also, having a <notebook> with tabs hidden somehow messes with the layout (empty space beneath buttons), so we need to to hide it initially and show on 'map-event' signal.

Code:
#!/bin/sh

[ -z $GTKDIALOG ] && GTKDIALOG=gtkdialog

MAIN_DIALOG='
<window>
   <vbox>

      <frame Working Now>

         <notebook show-tabs="false" show-border="false" visible="false">
         <entry visibility="false">
            <default>Password</default>
            <variable>ENTRY</variable>
            <input>echo "$ENTRY_PLAIN"</input>
            <action>refresh:ENTRY_PLAIN</action>
         </entry>

         <entry visibility="true">
            <default>Password</default>
            <variable>ENTRY_PLAIN</variable>
            <input>echo "$ENTRY"</input>
            <action>refresh:ENTRY</action>
         </entry>

            <variable>PASS_MODE</variable>
            <input>echo $(( (PASS_MODE + 1) & 1 ))</input>
      </notebook>

         <checkbox>
            <label>Show/Hide Password</label>
            <action>refresh:PASS_MODE</action>
         </checkbox>

      </frame>

      <hbox>
         <button ok></button>
         <button cancel></button>
      </hbox>
   </vbox>

   <action signal="map-event">show:PASS_MODE</action>
</window>
'
export MAIN_DIALOG

case $1 in
   -d | --dump) echo "$MAIN_DIALOG" ;;
   *) $GTKDIALOG --program=MAIN_DIALOG ;;
esac

Greetings!

_________________
[O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource
Omnia mea mecum porto.
Back to top
View user's profile Send private message 
01micko


Joined: 11 Oct 2008
Posts: 8680
Location: qld

PostPosted: Sun 05 Aug 2018, 07:16    Post subject:  

While doing a tiny bit of research on Smokey's problem I stumbled upon Michael Czapski's work. (Sorry Grant but at least SFR came up with the goods Razz )

This guy is a serious programmer and scratched an itch with gtkdialog.

There might be some useful examples on his blog.

Check it out!

_________________
Puppy Linux Blog - contact me for access
Back to top
View user's profile Send private message Visit poster's website 
smokey01


Joined: 30 Dec 2006
Posts: 2770
Location: South Australia :-(

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

@SFR that does the job nicely but there must be an easier and shorter method.

Thanks.

SFR wrote:
That's how I did this once: you need 2 synced <entry> fields (I used <notebook> as a container for them), one with visibility="false" and the other one with visibility="true".
Then by using a checkbox you can simply switch between them, i.e. <notebook>'s tabs.

Also, having a <notebook> with tabs hidden somehow messes with the layout (empty space beneath buttons), so we need to to hide it initially and show on 'map-event' signal.

Code:
#!/bin/sh

[ -z $GTKDIALOG ] && GTKDIALOG=gtkdialog

MAIN_DIALOG='
<window>
   <vbox>

      <frame Working Now>

         <notebook show-tabs="false" show-border="false" visible="false">
         <entry visibility="false">
            <default>Password</default>
            <variable>ENTRY</variable>
            <input>echo "$ENTRY_PLAIN"</input>
            <action>refresh:ENTRY_PLAIN</action>
         </entry>

         <entry visibility="true">
            <default>Password</default>
            <variable>ENTRY_PLAIN</variable>
            <input>echo "$ENTRY"</input>
            <action>refresh:ENTRY</action>
         </entry>

            <variable>PASS_MODE</variable>
            <input>echo $(( (PASS_MODE + 1) & 1 ))</input>
      </notebook>

         <checkbox>
            <label>Show/Hide Password</label>
            <action>refresh:PASS_MODE</action>
         </checkbox>

      </frame>

      <hbox>
         <button ok></button>
         <button cancel></button>
      </hbox>
   </vbox>

   <action signal="map-event">show:PASS_MODE</action>
</window>
'
export MAIN_DIALOG

case $1 in
   -d | --dump) echo "$MAIN_DIALOG" ;;
   *) $GTKDIALOG --program=MAIN_DIALOG ;;
esac

Greetings!

_________________
Software <-> Distros <-> Tips <-> Newsletters
Back to top
View user's profile Send private message Visit poster's website 
smokey01


Joined: 30 Dec 2006
Posts: 2770
Location: South Australia :-(

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

01micko wrote:
While doing a tiny bit of research on Smokey's problem I stumbled upon Michael Czapski's work. (Sorry Grant but at least SFR came up with the goods Razz )

This guy is a serious programmer and scratched an itch with gtkdialog.

There might be some useful examples on his blog.

Check it out!


Thanks Mick. A very interesting blog.

_________________
Software <-> Distros <-> Tips <-> Newsletters
Back to top
View user's profile Send private message Visit poster's website 
MochiMoppel


Joined: 26 Jan 2011
Posts: 1664
Location: Japan

PostPosted: Sun 05 Aug 2018, 22:45    Post subject:  

SFR wrote:
Also, having a <notebook> with tabs hidden somehow messes with the layout (empty space beneath buttons), so we need to to hide it initially and show on 'map-event' signal.

You can avoid this empty space with
Code:
<window resizable="false">
Back to top
View user's profile Send private message 
MochiMoppel


Joined: 26 Jan 2011
Posts: 1664
Location: Japan

PostPosted: Sun 05 Aug 2018, 23:27    Post subject:  

Slightly shorter:
Code:
#!/bin/bash
[ -z $GTKDIALOG ] && GTKDIALOG=gtkdialog

MAIN_DIALOG='
<window>
<vbox>
   <frame Also working>

      <entry visibility="false">
       <default>Password</default>
       <variable>ENTRY</variable>
       <input>echo "$ENTRY_PLAIN"</input>
       <action>refresh:ENTRY_PLAIN</action>
     </entry>

     <entry visible="false">
       <default>Password</default>
       <variable>ENTRY_PLAIN</variable>
       <input>echo "$ENTRY"</input>
       <action>refresh:ENTRY</action>
     </entry>

     <checkbox>
       <label>Show/Hide Password</label>
       <action>if true hide:ENTRY</action>
       <action>if true show:ENTRY_PLAIN</action>
       <action>if false show:ENTRY</action>
       <action>if false hide:ENTRY_PLAIN</action>
     </checkbox>

   </frame>

   <hbox>
     <button ok></button>
     <button cancel></button>
   </hbox>
</vbox>

</window>
'
export MAIN_DIALOG
case $1 in
   -d | --dump) echo "$MAIN_DIALOG" ;;
   *) $GTKDIALOG --program=MAIN_DIALOG ;;
esac
Back to top
View user's profile Send private message 
SFR


Joined: 26 Oct 2011
Posts: 1665

PostPosted: Mon 06 Aug 2018, 10:20    Post subject:  

smokey01 wrote:
@SFR that does the job nicely but there must be an easier and shorter method.

Surely it would be nice if there was an easier way, but there isn't, to my knowledge.
You can do it The Right Way™ in pure GTK+ (e.g. via C, Python, etc.) using gtk-entry-set-visibility, but AFAIK Gtkdialog does not implement a mechanism to change widget's specific properties on the fly, except for a couple of them that are common to all widgets (sentitive, visible).

@Mochi: thanks for simplifying it!

Greetings!

_________________
[O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource
Omnia mea mecum porto.
Back to top
View user's profile Send private message 
don570


Joined: 10 Mar 2010
Posts: 5161
Location: Ontario

PostPosted: Mon 27 Aug 2018, 19:48    Post subject:  

Tip:

Xdialog has a limit to the number of characters in a message box

but 'backtitle' option allows more lines to shown in window

Example:

Quote:

Xdialog --left --backtitle "\n$(gettext 'Conversion factor\nUnit A to Unit B')" --msgbox "$MSG1\n\n $MSG2\n\n $MSG3\n\n $MSG4\n\n $MSG5\n\n $MSG6" 0 0


Reference:
http://murga-linux.com/puppy/viewtopic.php?t=114156
_________________________________________________
Back to top
View user's profile Send private message 
wiak

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

PostPosted: Mon 17 Sep 2018, 09:10    Post subject:  

SFR wrote:

Surely it would be nice if there was an easier way, but there isn't, to my knowledge.
You can do it The Right Way™ in pure GTK+ (e.g. via C, Python, etc.) using gtk-entry-set-visibility, but AFAIK Gtkdialog does not implement a mechanism to change widget's specific properties on the fly, except for a couple of them that are common to all widgets (sentitive, visible).


Gtkdialog does use gtk-entry-set-visibility function but only during first initialisation.

Current gtkdialog (since ver 0.7.21) recognises the sensitive states: true, false, or password during that initialisation. That additional 'password' state really refers to gtk-entry-set-visibility, rather than actual GTK GtkWidget sensitive state, which only includes true or false (grayed out or not).

Adding additional sensitive states and associated logic (as was done for 'password' itself), it is possible to toggle at least some widget states 'on-the-fly' via a checkbox refresh action. For example, I am currently trying out an experimental gtkwialog compile that includes extra sensitive state 'toggle_password' (each time the entry is refreshed via a checkbox). I'm still however considering whether the approach is good and what additional 'sensitive' state name(s) to actually use in practice, before any possible gtkwialog release with that extra functionality. The resultant sh/gtkwialog code is certainly a bit simpler than the hide/show password entry-box workarounds described earlier. The following straightforward code, for example, works with my experimental gtkwialog compile:

Code:
#!/bin/bash
[ -z $GTKDIALOG ] && GTKDIALOG=gtkwialog

MAIN_DIALOG='
<window>
<vbox>
 <frame Also working>

  <entry>
   <sensitive>toggle_password</sensitive>
   <variable>ENTRY</variable>
   <default>Password</default>
  </entry>

  <checkbox>
   <variable>CHKBOX</variable>
   <label>Show/Hide Password</label>
   <action>refresh:ENTRY</action>
  </checkbox>

 </frame>

 <hbox>
  <button ok></button>
  <button cancel></button>
 </hbox>   

</vbox>
</window>
'
export MAIN_DIALOG
case $1 in
   -d | --dump) echo "$MAIN_DIALOG" ;;
   *) $GTKDIALOG --program=MAIN_DIALOG ;;
esac


I'll post further about it if I decide to proceed with/publish that addition; just hesitant to adopt a new strategy (since once formalised hard to take it back...) in case a better approach is found. I'm hesitant because I'm not sure if overloading sensitive with additional states is best mechanism (despite that already being done for 'password' state itself) - it is certainly easy to apply. Might instead be better to have a new 'Directive' for such on-the-fly refresh additions, which I have yet to think of a suitable name for... However, I'm inclined towards these additional 'sensitive' states to toggle between since it involves only a little bit extra code to implement. If you feel you have any use for this facility, let me know since it is not worth further consideration if not likely to be used anyway.

wiak

Note: gif created using weX screencapture along with its utility button to fredx181's gifenc-yad utility. On looking at it, according to checkbox label, I should of course make password show on clicking check box, rather than hide on click...
toggle_password.gif
 Description   
 Filesize   209.5 KB
 Viewed   258 Time(s)

toggle_password.gif

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


Joined: 28 Apr 2014
Posts: 506
Location: Bretagne / France

PostPosted: Mon 01 Oct 2018, 13:03    Post subject:  

Hi,

I think it's not possible, but question in case of

About button label

Code:

<button>
<variable>okbutton</variable>
<label>"'`date`'"</label>
<action>refresh:okbutton</action>
</button>


The button take value only after load ? Update is not possible ?

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


Joined: 26 Jan 2011
Posts: 1664
Location: Japan

PostPosted: Tue 02 Oct 2018, 05:59    Post subject:  

fabrice_035 wrote:
The button take value only after load ? Update is not possible ?
Labels are fixed even before gtkdialog starts.

You could try a work around with an updated button icon:
Code:
#!/bin/bash
update_icon () {
echo '<''svg width="100" height="20"><text x="50%" y="70%" text-anchor="middle">'"$(date +%T)"'</text></svg>' > /tmp/buticon.svg
}; export -f update_icon

update_icon
echo '
<button>
   <variable>BUT</variable>
   <input file>/tmp/buticon.svg</input>
   <action>echo do something useful here</action>
   <action>update_icon</action>
   <action>refresh:BUT</action>
</button>
'|gtkdialog -s
rm /tmp/buticon.svg
button_with_svg_icon.png
 Description   
 Filesize   1.48 KB
 Viewed   118 Time(s)

button_with_svg_icon.png

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


Joined: 28 Apr 2014
Posts: 506
Location: Bretagne / France

PostPosted: Tue 02 Oct 2018, 10:07    Post subject:  

@MochiMoppel : whaouu, very nice! Respect Shocked
Back to top
View user's profile Send private message 
vovchik


Joined: 23 Oct 2006
Posts: 1469
Location: Ukraine

PostPosted: Tue 02 Oct 2018, 10:19    Post subject:  

Dear Mochi,

Brilliant. And thanks for the example. We can also make it pretty without much effort:

Code:
#!/bin/bash

function update_icon()
{
echo '<''svg width="300" height="60">' \
      '<rect x="1%" y="1%" rx="5%" ry="10%" width="98%" ' \
      'height="98%" fill="darkorange" stroke="darkred" ' \
      'stroke-width="3.5"/> <text x="50%" ' \
      'stroke="darkred" stroke-opacity="1.0" stroke-width="2.4" ' \
      'fill="white" fill-opacity="1.0" font-weight="800" ' \
      'font-size="50" font-family="Sans" ' \
      'y="78%" text-anchor="middle">'"$(date +%T)"'' \
      '</text></svg>' > /tmp/buticon.svg
}

export -f update_icon
update_icon

echo '
<button>
   <variable>BUT</variable>
   <input file>/tmp/buticon.svg</input>
   <action>echo "Do something useful here..."</action>
   <action>update_icon</action>
   <action>refresh:BUT</action>
</button>
'|gtkdialog -s

rm /tmp/buticon.svg


With kind regards,
vovchik
screenshot1.png
 Description   
 Filesize   16.19 KB
 Viewed   85 Time(s)

screenshot1.png

update-button-pup.tar.gz
Description 
gz

 Download 
Filename  update-button-pup.tar.gz 
Filesize  1.51 KB 
Downloaded  12 Time(s) 
screenshot.png
 Description   
 Filesize   12.98 KB
 Viewed   93 Time(s)

screenshot.png

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


Joined: 28 Apr 2014
Posts: 506
Location: Bretagne / France

PostPosted: Tue 02 Oct 2018, 12:38    Post subject:  

@vovchik : terrrrrible Cool

I not understand functions on timer widget
http://01micko.com/reference/timer.html

Code:

<timer tag_attr="value"...>
   <variable>varname</variable>
   <input>command</input>
   <input file>filename</input>
   <sensitive>state</sensitive>
   <action>activity</action>...
   <action signal="type">activity</action>...
   <action function="type">parameter</action>...
</timer>


I try the "input file" activity, never working
I imagine when the input file change then action signal receive a signal ?

example

Code:

#!/bin/bash

touch /tmp/myfile

echo '
<button>
   <variable>BUT</variable>
   <label>press me</label>
   <action>echo "button down"</action>
   </button>
   
   <timer visible="true" milliseconds="true" file-monitor="true">
   <input file>/tmp/myfile</input>
   <action>echo "working signal"</action>
   </timer>

'| gtkdialog -s


So, if i change /tmp/myfile with echo "xxx" > /tmp/myfile
There is no signal transmitted

Explain me please.
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 95 of 96 [1429 Posts]   Goto page: Previous 1, 2, 3, ..., 93, 94, 95, 96 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.3174s ][ Queries: 13 (0.2060s) ][ GZIP on ]