GtkDialog - tips

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Message
Author
User avatar
SFR
Posts: 1800
Joined: Wed 26 Oct 2011, 21:52

#916 Post by SFR »

Can8v, <combobox> is rather deprecated - how about <comboboxentry> or <comboboxtext> instead, which have <input file> tag, what makes importing data much easier?

Here's a sample:

Code: Select all

DEVICE_FILE="/root/my-applications/bin/activeMTPdevices.txt" 

export DEVICE_DIALOG_LIST='
<window title="The list">
  <vbox>

    <comboboxtext active="0"> 
      <variable>RESULT</variable>
      <input file>'${DEVICE_FILE}'</input>
    </comboboxtext>

    <hbox>
      <button ok>
        <action>exit:PROCEED</action>
      </button>
      <button cancel>
        <action>exit:CANCEL</action>
      </button>
    </hbox>
  
  </vbox>
</window>'


# In order to access returned variables, we have to evaluate them first
eval `gtkdialog --program DEVICE_DIALOG_LIST`


# EXIT states "PROCEED" and "CANCEL" are defined above, but "abort" is internal
if [ "$EXIT" = "PROCEED" ]; then
  xmessage "$RESULT"	#show the result
elif [ "$EXIT" = "CANCEL" ]; then
  xmessage "Cancelled"
elif [ "$EXIT" = "abort" ]; then
  xmessage "Window closed via X"
fi
Greetings!
[color=red][size=75][O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource[/size][/color]
[b][color=green]Omnia mea mecum porto.[/color][/b]

can8v
Posts: 586
Joined: Sat 15 Jul 2006, 08:20
Location: Yuba City, CA
Contact:

#917 Post by can8v »

@SFR
Thanks so much for this.

Puma
Posts: 7
Joined: Tue 09 Oct 2012, 15:59

Gtkdialog -get notebook tabnumber

#918 Post by Puma »

could one explain why this code works

Code: Select all

export MAIN='
<notebook>
  <frame><text><label>first tab</label></text></frame>
  <frame><text><label>second tab</label></text></frame>
  <frame><text><label>third tab</label></text></frame>
 
  <variable>VAR</variable>
  <action signal="button-release-event">[ $VAR -eq 0 ] && xmessage "first tab"</action>
  <action signal="key-release-event">[ $VAR -eq 0 ] && xmessage "first tab"</action>
  <action signal="button-release-event">[ $VAR -eq 1 ] && xmessage "second tab"</action>
  <action signal="key-release-event">[ $VAR -eq 1 ] && xmessage "second tab"</action>
  <action signal="button-release-event">[ $VAR -eq 2 ] && xmessage "third tab"</action>
  <action signal="key-release-event">[ $VAR -eq 2 ] && xmessage "third tab"</action>
 
</notebook>'

gtkdialog -cp MAIN
and this not

Code: Select all

export MAIN="
<notebook>

  <frame><text><label>\"first tab\"</label></text></frame>
  <frame><text><label>\"second tab\"</label></text></frame>
  <frame><text><label>\"third tab\"</label></text></frame>
 
  <variable>nTabPage</variable> 
   
  <action signal=\"button-release-event\">[ $nTabPage -eq 0 ] && xmessage \"first tab\"</action>
  <action signal=\"button-release-event\">[ $nTabPage -eq 1 ]  && xmessage \"second tab\"</action>    

</notebook>"

gtkdialog -cp MAIN
also i tried

Code: Select all

I=$IFS; IFS=""
for STATEMENTS in  $(PumaGui.pmx -cp MAIN); do
  eval $STATEMENTS
done
IFS=$I 
the only different is the double qoute sign.

thanks in advance

[/quote]

Puma
Posts: 7
Joined: Tue 09 Oct 2012, 15:59

sorry last code should read

#919 Post by Puma »

I=$IFS; IFS=""
for STATEMENTS in $(gtkdialog -cp MAIN); do
eval $STATEMENTS
done
IFS=$I

User avatar
SFR
Posts: 1800
Joined: Wed 26 Oct 2011, 21:52

#920 Post by SFR »

Puma wrote:the only different is the double qoute sign.
When you're using double quotes instead of single ones, the variables between <action>...</action> tags get evaluated instead of being exported literally as strings, so in result (since nTabPage var is null at this stage) MAIN contains:
<action signal="button-release-event">[ -eq 0 ] && xmessage "first tab"</action>
That's why I prefer s. quotes - much less hassle with escaping, etc.
Anyway, this will work:

Code: Select all

[ "'$nTabPage'" -eq 0 ]
Greetings!
[color=red][size=75][O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource[/size][/color]
[b][color=green]Omnia mea mecum porto.[/color][/b]

User avatar
zigbert
Posts: 6621
Joined: Wed 29 Mar 2006, 18:13
Location: Valåmoen, Norway
Contact:

#921 Post by zigbert »

Try a slash in front of $

Code: Select all

<action signal=\"button-release-event\">[ \$nTabPage -eq 0 ] && xmessage \"first tab\"</action> 

User avatar
don570
Posts: 5528
Joined: Wed 10 Mar 2010, 19:58
Location: Ontario

#922 Post by don570 »

I found that it is possible to force a button to bottom of list by a simple
trick. ---> text widget gets space-expand="true"

Code: Select all

<vbox>
<button>....</button>
...
...
<text space-expand="true"><label>""</label></text>

<button>...</button>
</vbox>
Note the button in right bottom corner. The button doesn't go
all the way to bottom, but close enough.
Image

Puma
Posts: 7
Joined: Tue 09 Oct 2012, 15:59

notebook tab refresh

#923 Post by Puma »

Thanks all for the quick reply. Code example of SFR works perfect but a new
problem arised. First some explanation.

At the moment i developed a Wary Distribution with special attention to server administration of VNC, PureFtp, Hiawatha (WebServer), PHP, and MySql.

Name of the distribution is Pumalix (Pu for Puppy, Ma for Part of my Name and Lix for Linux). Distribution is based on Wary becauce of old Bios support.

Included are Firefox (latest Version), PlayOnLinux, Gimp, Virtual Box and many more. Also i adapted all GtkDialog code to support multilingual appearance.

All is controlled by a GUI shown in attachement. Each Tab of the GUI is represented by a string variable which is allocated by a Function.

Because there is some code behind each Tab (especially ther Server Tab)
i would like to avoid running this code if only Tab one is shown. In this
case only code for Tab one should run and for the other tabs there is a simple dummy function running.

But if you click Tab two then the content of the represented string should change by calling the appropriate function.

Do do this i miss a event or something i can refresh after click.

below a simple code example.

Code: Select all

#! /bin/bash


########################  EXPORT Variablen  ##############################

export cTabBlank
export cTabPage1
export cTabPage2
export cTabPage3

#typeset -i nTabPage=0
#declare -i nTabPage=1

########################  EXPORT Functions  ##############################

function GetTabPage1()
{
  cTabPage1="<frame>
    <text>
      <label>\"first tab\"</label>
    </text>
  </frame>"
  
  echo $cTabPage1 
}
export -f GetTabPage1


#########################################################################

function GetTabPage2()
{
  cTabPage2="<frame>
    <text>
      <label>\"second tab\"</label>
    </text>
  </frame>"
  
  echo $cTabPage2 
}
export -f GetTabPage2


#########################################################################

function GetTabPage3()
{
  cTabPage3="<frame>
    <text>
      <label>\"third tab\"</label>
    </text>
  </frame>"
  
  echo $cTabPage3 
}
export -f GetTabPage3

#########################################################################

function GetTabBlank()
{
  cTabBlank="<frame>
    <text>
      <label>\"blank tab\"</label>
    </text>
  </frame>"
  
  echo $cTabBlank 
}
export -f GetTabBlank

#########################################################################

function OnTabPageChanged()
{
  declare -i local nActPage

  nActPage=$1

  if [ $nActPage -eq 0 ]; then
    xmessage "content of tab one is allways the same, no changes needed"
    #cTabPage1=$(GetTabPage1) 
  elif [ $nActPage -eq 1 ]; then
    xmessage "content of tab two should change by changing variable cTabPage2"
    cTabPage2=$(GetTabPage2)   
  elif [ $nActPage -eq 2 ]; then
	xmessage "content of tab three should change by changing variable cTabPage3"
	cTabPage3=$(GetTabPage3)
  fi  
  
}
export -f OnTabPageChanged


####################  INIT Notebook Tabs ################################

cTabPage1=$(GetTabPage1)
cTabPage2=$(GetTabBlank)
cTabPage3=$(GetTabBlank)

#############################  M A I N ##################################

export MAIN="
<notebook>

  $cTabPage1
  $cTabPage2
  $cTabPage3
  
  <variable>nTabPage</variable> 
  <action signal=\"button-release-event\">[ "'$nTabPage'" -eq 0 ] && OnTabPageChanged "'$nTabPage'" && refresh:nTabPage</action>
  <action signal=\"button-release-event\">[ "'$nTabPage'" -eq 1 ] && OnTabPageChanged "'$nTabPage'" && refresh:nTabPage</action>
  <action signal=\"button-release-event\">[ "'$nTabPage'" -eq 2 ] && OnTabPageChanged "'$nTabPage'" && refresh:nTabPage</action>      

</notebook>"

#############################  T E S T ##################################

#I=$IFS; IFS=""
#for STATEMENTS in  $(gtkdialog -cp MAIN	); do
#  eval $STATEMENTS
#done
#IFS=$I 

gtkdialog -cp MAIN	

##################### UNSET Functions ################################

unset GetTabBlank
unset GetTabPage1
unset GetTabPage2
unset GetTabPage3
unset OnTabPageChanged

##################### UNSET Variablen ################################

unset cTabBlank
unset cTabPage1
unset cTabPage2
unset cTabPage3

Puma
Posts: 7
Joined: Tue 09 Oct 2012, 15:59

screenshoot of control gui

#924 Post by Puma »

see attachment
Last edited by Puma on Tue 25 Feb 2014, 19:26, edited 7 times in total.

Puma
Posts: 7
Joined: Tue 09 Oct 2012, 15:59

next try image upload

#925 Post by Puma »

as embedded image

[img]/home/puma/Desktop/ServerControl.png[/img]
Last edited by Puma on Sun 23 Feb 2014, 18:56, edited 1 time in total.

Puma
Posts: 7
Joined: Tue 09 Oct 2012, 15:59

s o r r y

#926 Post by Puma »

cant upload any image neither as embedded image nor attachment

User avatar
don570
Posts: 5528
Joined: Wed 10 Mar 2010, 19:58
Location: Ontario

#927 Post by don570 »

When I post an image I use photobucket.com as a server,
then I can use <IMG>.....</IMG> tags
_________________________________________________

thanius
Posts: 10
Joined: Tue 04 Feb 2014, 17:19

Regarding updating pixmaps

#928 Post by thanius »

I just wrote an ad cycler and thought I'd share some on the pixmap updater. I saw the example here but I found it more clean to make symbolic links instead of copying the files. Here's my ad cycler:

Code: Select all

#!/bin/bash 

ln -fs ad1.png ad.png
echo 2 > /tmp/count

function cycle_ad {

# Because gtkdialog won't handle global vars for some retarded reason!
i=`cat /tmp/count`

if [ -e "ad$i.png" ]; then
  ln -fs ad$i.png ad.png
  echo $i+1|bc > /tmp/count
else
  ln -fs ad1.png ad.png
  echo 2 > /tmp/count
fi

}

export MAIN=' 
<window width-request="600" height-request="400"> 

<vbox homogeneous="true">
 <pixmap> 
  <variable>IMAGE</variable>
  <input file>ad.png</input> 
 </pixmap>
 
 <timer milliseconds="false" interval="13" visible="false"> 
   <action>exec $SHELL -c cycle_ad</action> 
   <action>sleep 2</action>
   <action type="refresh">IMAGE</action> 
 </timer>

</vbox> 
</window>' 

export -f cycle_ad

gtkdialog --center --program=MAIN

brokenman
Posts: 25
Joined: Thu 20 Oct 2011, 23:00

Always on top

#929 Post by brokenman »

Keeping a gtkdialog app 'always on top'

I've just read that this is possible in jwm using the .jwmrc file and launching the gtkdialog as a --class=APPLET. Is there an inbuilt way to do the same in openbox?

This could probably be achieved with other methods inside the openbox rc.xml file but I am wondering if something similar to the JWM solution si viable.

disciple
Posts: 6984
Joined: Sun 21 May 2006, 01:46
Location: Auckland, New Zealand

#930 Post by disciple »

"other methods inside the openbox rc.xml file" sounds similar to "using the .jwmrc file" to me...
Do you know a good gtkdialog program? Please post a link here

Classic Puppy quotes

ROOT FOREVER
GTK2 FOREVER

seaside
Posts: 934
Joined: Thu 12 Apr 2007, 00:19

#931 Post by seaside »

JWM can be set by placing this in /root/.jwm/jwmrc-personal-

Code: Select all

<Group>
<Name>on-top</Name>
<Class>on-top</Class>
<Option>layer:12</Option>
</Group>
Openbox set by openbox rc.xml "layer" property.
http://openbox.org/wiki/Help:Applicatio ... n_settings

Cheers,
s

User avatar
neerajkolte
Posts: 516
Joined: Mon 10 Feb 2014, 07:05
Location: Pune, India.

#932 Post by neerajkolte »

Nice thread. Just bookmarking for reference.
"One of my most productive days was throwing away 1000 lines of code."
- Ken Thompson

“We tend to overestimate the effect of a technology in the short run and underestimate the effect in the long run.â€￾
- Amara’s Law.

User avatar
Argolance
Posts: 3767
Joined: Sun 06 Jan 2008, 22:57
Location: PORT-BRILLET (Mayenne - France)
Contact:

#933 Post by Argolance »

Bonjour,
JWM Configuration web page wrote:layer
The layer of the tray. The default is above. Valid values are below, normal, and above.
So, depending on the JWM version you are running:

Code: Select all

<Group>
<Name>on-top</Name>
<Class>on-top</Class>
<Option>layer:12</Option>
</Group>
... is now deprecated and doesn't work properly.
It should be:

Code: Select all

<Group>
<Name>on-top</Name>
<Class>on-top</Class>
<Option>layer:above</Option>
</Group>
Cordialement.

User avatar
puppy_apprentice
Posts: 299
Joined: Tue 07 Feb 2012, 20:32

#934 Post by puppy_apprentice »

I want to make buttons UP and DOWN to move item on the list/tree gadget one place up or down. Is there built-in function for this task or i will have make own bash function for this? Maybe someone has code snippet for this?

User avatar
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

#935 Post by MochiMoppel »

puppy_apprentice wrote:I want to make buttons UP and DOWN to move item on the list/tree gadget one place up or down. Is there built-in function for this task or i will have make own bash function for this? Maybe someone has code snippet for this?
Zigbert provides a code snippet on the first page of this thread ("The next script shows how to move items in list by drag'n drop"). Not really buttons and I haven't tested, but maybe a start.

Post Reply