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 16 Jul 2019, 19: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 98 of 98 [1462 Posts]   Goto page: Previous 1, 2, 3, ..., 96, 97, 98
Author Message
MochiMoppel


Joined: 26 Jan 2011
Posts: 1852
Location: Japan

PostPosted: Wed 12 Dec 2018, 09:16    Post subject:  

smokey01 wrote:
Ah this one is good too as it checks to see if a file exists rather than reading the contents of the file.
What do you mean by "good too"? It's what you tried to achieve with your example. Reading the contents is not what you asked for.
Back to top
View user's profile Send private message 
smokey01


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

PostPosted: Wed 12 Dec 2018, 17:12    Post subject:  

MochiMoppel wrote:
smokey01 wrote:
Ah this one is good too as it checks to see if a file exists rather than reading the contents of the file.
What do you mean by "good too"? It's what you tried to achieve with your example. Reading the contents is not what you asked for.

You are quite correct and thanks.

I'm trying to automate the process a little more. If I explain the full requirements it might make more sense.

Attached is a logic map for the buttons. Red means disabled and Green enabled. There is actually a stop button which should stop the server and client and enable client and server buttons but not affect Teacher and Student buttons. The Teacher and Student buttons need to be enabled after their apps are closed. It's actually the same app but with different configuration. Not sure how to do this. Currently I have these buttons being enabled with the stop button.

I'm sure the code could be a lot smarter and tidier but it mostly works.

Thanks
Code:

#!/bin/sh

[ -z $GTKDIALOG ] && GTKDIALOG=gtkdialog

MAIN_DIALOG='
<window>
   <vbox>
      <hbox>
         <button>
            <label>Server</label>
            <variable>SERVER</variable>
            <action>touch /tmp/server</action>
            <action>touch /tmp/client</action>
            <action>touch /tmp/teacher</action>
            <action>disable:CLIENT</action>
            <action>disable:TEACHER</action>
            <action>disable:SERVER</action>
         </button>
         
         <button>
            <label>Client</label>
            <variable>CLIENT</variable>
            <action>touch /tmp/client</action>
            <action>touch /tmp/server</action>
            <action>touch /tmp/student</action>
            <action>disable:SERVER</action>
            <action>disable:STUDENT</action>
            <action>disable:CLIENT</action>
         </button>

         <button>
            <label>Teacher</label>
            <variable>TEACHER</variable>
            <action>touch /tmp/teacher</action>
            <action>touch /tmp/student</action>
            <action>touch /tmp/server</action>
            <action>disable:STUDENT</action>
            <action>disable:SERVER</action>
            <action>disable:TEACHER</action>
         </button>
         
         <button>
            <label>Student</label>
            <variable>STUDENT</variable>
            <action>touch /tmp/student</action>
            <action>touch /tmp/teacher</action>
            <action>touch /tmp/client</action>
            <action>disable:TEACHER</action>
            <action>disable:CLIENT</action>
            <action>disable:STUDENT</action>
         </button>
         
         <button tooltip-text="Reset all the buttons">
            <label>Stop</label>
            <variable>STOP</variable>
            <action condition="command_is_true( [ -e /tmp/server ]&& echo true && rm /tmp/server)">enable:SERVER</action>
            <action condition="command_is_true( [ -e /tmp/client ]&& echo true && rm /tmp/client)">enable:CLIENT</action>
            <action condition="command_is_true( [ -e /tmp/teacher ]&& echo true && rm /tmp/teacher)">enable:TEACHER</action>
            <action condition="command_is_true( [ -e /tmp/student ]&& echo true && rm /tmp/student)">enable:STUDENT</action>
         </button>
         
         <button ok></button>
      </hbox>
      
   </vbox>
</window>
'
export MAIN_DIALOG

case $1 in
   -d | --dump) echo "$MAIN_DIALOG" ;;
   *) $GTKDIALOG --program=MAIN_DIALOG ;;
esac
button-map.png
 Description   
 Filesize   4.7 KB
 Viewed   333 Time(s)

button-map.png


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


Joined: 26 Jan 2011
Posts: 1852
Location: Japan

PostPosted: Thu 13 Dec 2018, 10:52    Post subject:  

zigbert wrote:
Smokey
You're missing the conditional option.
Code:
<action condition="file_is_false( /tmp/file )">disable:STATUS</action>

@zigbert: As smokey01 and I couldn't get this to work I would be keen to learn how this condition is supposed to work. The description in the manual makes no sense to me and I haven't found a single script or example where this condition has been used.
I suspected that "file" would relate to a monitored input file, but tests were negative.
Do you know more?

[Edit] OK, figured it out. file_is_false tests if a given file contains "false", "no" or zero. In smokey01's example the tmp files contain nothing, hence the condition is not met. At least I now understand why nobody uses this condition.
Back to top
View user's profile Send private message 
zigbert


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

PostPosted: Thu 13 Dec 2018, 17:03    Post subject:  

MochiMoppel wrote:
At least I now understand why nobody uses this condition.
I do Embarassed Laughing
_________________
Stardust resources
Back to top
View user's profile Send private message Visit poster's website 
smokey01


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

PostPosted: Thu 13 Dec 2018, 17:06    Post subject:  

MochiMoppel wrote:
zigbert wrote:
Smokey
You're missing the conditional option.
Code:
<action condition="file_is_false( /tmp/file )">disable:STATUS</action>

@zigbert: As smokey01 and I couldn't get this to work I would be keen to learn how this condition is supposed to work. The description in the manual makes no sense to me and I haven't found a single script or example where this condition has been used.
I suspected that "file" would relate to a monitored input file, but tests were negative.
Do you know more?

[Edit] OK, figured it out. file_is_false tests if a given file contains "false", "no" or zero. In smokey01's example the tmp files contain nothing, hence the condition is not met. At least I now understand why nobody uses this condition.


Once I created a file containing the word false it work as you've also discovered.

I'm still trying to find a way to enable/disable a button depending if a file exists or not in the following situation:

If I use a function that runs psip like this:

run_psip() {
touch /tmp/psip-file
psip
rm /tmp/psip-file
}
export -f run_psip

and call it from a button, the function only runs when the button is clicked.
When psip is terminated the "rm /tmp/psip-file" needs to be run after psip is closed, then a test to see if the file exists. The button in the GUI should be enabled when there is no /tmp/psip-file and disabled when there is.

I thought the <input file> option might work but apparently it only seems to display graphic files on the button widget, if they exist. I also tried it with tag attributes file-monitor and auto-refresh, no joy.

Is there are way to achieve this?

Thanks

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


Joined: 26 Jan 2011
Posts: 1852
Location: Japan

PostPosted: Fri 14 Dec 2018, 00:24    Post subject:  

smokey01 wrote:
I'm still trying to find a way to enable/disable a button depending if a file exists or not
Argolance asked the same question here in this forum about 2 months ago.
Basically 2 ways to achieve this: Either with a timer widget or with file-monitor attribute.

Quote:
I thought the <input file> option might work but apparently it only seems to display graphic files on the button widget, if they exist. I also tried it with tag attributes file-monitor and auto-refresh, no joy.
You were close. <input file> is supposed to display the button icon but even if the file is no image file file-monitor can still monitor it. In Argolance's thread I gave an example with 2 buttons, but it can be done with only 1 button. Hold your breath, this is going to be weird.

I thought that this would not work, but it does (I use leafpad since I don't have psip).
The script starts by creating an empty file (> /tmp/leafpad-file).
The function removes any tmp file that may exist, then runs the application. After the application finished, an empty string is written to the empty file. Apart from the filedate nothing changed, right?. Normally I would expect that this does not trigger a file-changed signal, but apparently it does.

Code:
#!/bin/bash
> /tmp/leafpad-file

run_leafpad() { 
   leafpad
   > /tmp/leafpad-file
}
export -f run_leafpad
 
echo -n '<window>
<vbox>
   <button label="run_leafpad" file-monitor="true">
      <variable>BUT</variable>
      <input file>/tmp/leafpad-file</input>
      <action signal="file-changed">enable:BUT</action>
      <action signal="file-changed">break:</action>
       <action>disable:BUT</action>
      <action>run_leafpad &</action>
   </button>
</vbox>
</window>' | gtkdialog -s
rm /tmp/leafpad-file
Note that in above code the button has no icon but it would be no problem to add one in the usual manner.

Using a timer would be more efficient as the timer monitors the file only as long as leafpad is running and not continuously as in above example:
Code:
#!/bin/bash
run_leafpad() {
   > /tmp/leafpad-file
   leafpad
   rm /tmp/leafpad-file
}
export -f run_leafpad
 
echo -n '<window>
<vbox>
   <button label="run_leafpad">
      <variable>BUT</variable>
      <action>disable:BUT</action>
      <action>enable:TIMER</action>
      <action>run_leafpad &</action>
   </button>
   <timer visible="false" sensitive="false">
      <variable>TIMER</variable>
      <action condition="command_is_true( [ -e /tmp/leafpad-file ] && echo true )">break:</action>
      <action>disable:TIMER</action>
      <action>enable:BUT</action>
   </timer>
</vbox>
</window>' | gtkdialog -s
Back to top
View user's profile Send private message 
smokey01


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

PostPosted: Sat 15 Dec 2018, 18:49    Post subject:  

@MochiMoppel,

Two excellent examples. I prefer the second as it only creates the test file when the external app is running instead of the parent GUI. I was very close but no cigar, as they say.

I was using a timer widget at one stage but was unaware of the break command. I pretty sure this code will do the job nicely.

Thanks again.

_________________
Software <-> Distros <-> Tips <-> Newsletters
Back to top
View user's profile Send private message Visit poster's website 
Display posts from previous:   Sort by:   
Page 98 of 98 [1462 Posts]   Goto page: Previous 1, 2, 3, ..., 96, 97, 98
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.1895s ][ Queries: 12 (0.1393s) ][ GZIP on ]