 |
Puppy Linux Discussion Forum Puppy home page: puppylinux.com
|
The time now is Fri 20 Nov 2009, 19:53
All times are UTC - 4 |
| Author |
Message |
zigbert

Joined: 29 Mar 2006 Posts: 2504 Location: Valåmoen, Norway
|
Posted: Thu 05 Nov 2009, 15:57 Post subject:
|
|
Patriot
Invisible checkboxes.....mmmmm.....
What do you mean by flip-flops?
I think we need to include more info in the main post to explain what your fixed gtkdialog can do. I have here simplified a script to show open/close feature..... Do you think it is enough to explain....
| Code: | #!/bin/sh
# Requires the fixed gtkdialog3-pe1
export LAUNCHED_DIALOG='
<variable>LAUNCHED_DIALOG</variable>
<vbox>
<text><label>This is a launched window</label></text>
<button><label>increase number</label>
<action>A=$(cat /tmp/tmp); echo $(($A+1)) > /tmp/tmp</action>
<action>refresh:TEXT</action>
</button>
</vbox>'
export MAIN_DIALOG='
<vbox>
<frame>
<text width-chars="20" height-request="120"><variable>TEXT</variable><input>cat /tmp/tmp</input></text>
</frame>
<checkbox visible="false">
<label>"OPENCLOSE"</label>
<variable>OPENCLOSE</variable>
<input>if [ "$OPENCLOSE" = "false" ]; then echo "true"; else echo "false"; fi</input>
<action>if true launch:LAUNCHED_DIALOG</action>
<action>if false closewindow:LAUNCHED_DIALOG</action>
</checkbox>
<button><label>"Open/Close"</label><action>refresh:OPENCLOSE</action></button>
<button><label>Exit</label></button>
</vbox>'
echo 1 > /tmp/tmp
gtkdialog3 -p MAIN_DIALOG |
Sigmund
_________________ Stardust resources
|
|
Back to top
|
|
 |
big_bass

Joined: 13 Aug 2007 Posts: 807
|
Posted: Thu 05 Nov 2009, 16:20 Post subject:
|
|
zigbert
| Quote: | | What do you mean by flip-flops? |
Hey zigbert
in electronics " flip flop" changes from one logic level to another
a changeable state
high to low or low to high
or 1 to 0 or 0 to 1
or yes to no or no to yes in a human readable format
thanks for the shortened code snippet
Joe
_________________
The slackware 12.2 hardware detecting SMP kernel with a puppy 412 body http://puppy2.org/slaxer/
|
|
Back to top
|
|
 |
zigbert

Joined: 29 Mar 2006 Posts: 2504 Location: Valåmoen, Norway
|
Posted: Thu 05 Nov 2009, 16:57 Post subject:
|
|
Joe
Ok, I see. I will write more tips for flip-flops. Both buttons and menus sound logical to me. Pmusic wants this..... Thanks for the explanation.
Here is the previous script even more simplified. Since checkbox is a flip-flop itself, we don't need to make make a flip-flop button.
| Code: | #!/bin/sh
# Requires the fixed gtkdialog3-pe1
export LAUNCHED_DIALOG='
<variable>LAUNCHED_DIALOG</variable>
<vbox>
<text><label>This is a launched window</label></text>
<button><label>increase number</label>
<action>A=$(cat /tmp/tmp); echo $(($A+1)) > /tmp/tmp</action>
<action>refresh:TEXT</action>
</button>
</vbox>'
export MAIN_DIALOG='
<vbox>
<frame>
<text width-chars="20" height-request="120"><variable>TEXT</variable><input>cat /tmp/tmp</input></text>
</frame>
<checkbox draw_indicator="false">
<label>"Open/Close"</label>
<variable>OPENCLOSE</variable>
<action>if true launch:LAUNCHED_DIALOG</action>
<action>if false closewindow:LAUNCHED_DIALOG</action>
</checkbox>
<button><label>Exit</label></button>
</vbox>'
echo 1 > /tmp/tmp
gtkdialog3 -p MAIN_DIALOG |
Sigmund
_________________ Stardust resources
|
|
Back to top
|
|
 |
Patriot

Joined: 15 Jan 2009 Posts: 526
|
Posted: Fri 06 Nov 2009, 06:13 Post subject:
|
|
Hmmm .....
zigbert,
It's up to you which script to use for your examples. A shortened script is fine ...
Well, Joe's spot-on about the flip-flops ... Think of it like a light switch (on/off). I used the hidden checkboxes as flip-flops and link it to a button as per your original question. As I mentioned earlier, I didn't think of using checkboxes like this before ... I think that it's a nicer cosmetics using a button though (depending on the requirements) ...
Rgds
|
|
Back to top
|
|
 |
zigbert

Joined: 29 Mar 2006 Posts: 2504 Location: Valåmoen, Norway
|
Posted: Fri 06 Nov 2009, 13:59 Post subject:
|
|
I have updated the main post
All credits go to Patriot !!!
#####################################
Flip-flops - make buttons/menus work like checkboxes
>> Flip-flops are swithes (variables) that are turned ON/OFF. - Just like a checkboxes. If you want to manage ON/OFF statements with buttons or menuitems, read on....
You might already have thought that it is possible to echo ON/OFF to a file, and then read content of file to determine if a button/menu should activate ON or OFF. Well, that will work, but not if you want to use the builtin gtkdialog commands enable/disable, launch/closewindow, refresh...
Gtkdialog does only support checkboxes as flip-flops, but the wonder is that they can be invisible. If we link a menu or button to the invisible checkbox, it all feels comfortable. Check the following example:
| Code: | #!/bin/sh
export MAIN_DIALOG='
<window title="Flip-Flop">
<vbox>
<menubar>
<menu>
<menuitem icon="gtk-dialog-question">
<label>Start/Stop clock</label>
<action>refresh:STARTSTOP</action>
</menuitem>
<label>Clock</label>
</menu>
</menubar>
<frame>
<text><input>cat /tmp/text</input><variable>TEXT</variable></text>
<entry>
<variable>ENTRY</variable>
<input>date +%H:%M:%S</input>
</entry>
</frame>
<checkbox visible="false">
<variable>STARTSTOP</variable>
<default>true</default>
<input>if [ "$STARTSTOP" = "false" ]; then echo "true"; else echo "false"; fi</input>
<action>if true enable:ENTRY</action>
<action>if true enable:TEXT</action>
<action>if true echo 100 > /tmp/progress</action>
<action>if true echo "I am ON" > /tmp/text</action>
<action>if false disable:ENTRY</action>
<action>if false disable:TEXT</action>
<action>if false echo 0 > /tmp/progress</action>
<action>if false echo "I am OFF" > /tmp/text</action>
<action>refresh:TEXT</action>
</checkbox>
<progressbar>
<variable>PROGRESS</variable>
<input>while [ A = A ]; do sleep 0.5; P=`cat /tmp/percent`; echo $P; cat /tmp/progress > /tmp/percent; done</input>
<action>refresh:ENTRY</action>
<action>echo 0 > /tmp/percent</action>
</progressbar>
</vbox>
</window>'
echo 100 > /tmp/progress
echo 'I am OFF' > /tmp/text
gtkdialog3 -p MAIN_DIALOG |
###################################################################################
7.) Gtkdialog - Patriot edition - More fun
###################################################################################
Download gtkdialog3-0.7.20-pe1-i486.pet (48kb)
Patriot has shipped a gtkdialog version that makes it possible to close launched dialog from main dialog. <action type="closewindow">LAUNCHED_DIALOG</action>
Example of use:
| Code: | #!/bin/sh
# Requires the fixed gtkdialog3-pe1
export LAUNCHED_DIALOG='
<variable>LAUNCHED_DIALOG</variable>
<vbox>
<text><label>This is a launched window</label></text>
<button><label>increase number</label>
<action>A=$(cat /tmp/tmp); echo $(($A+1)) > /tmp/tmp</action>
<action>refresh:TEXT</action>
</button>
</vbox>'
export MAIN_DIALOG='
<vbox>
<frame>
<text width-chars="20" height-request="120"><variable>TEXT</variable><input>cat /tmp/tmp</input></text>
</frame>
<checkbox draw_indicator="false">
<label>"Open/Close"</label>
<variable>OPENCLOSE</variable>
<action>if true launch:LAUNCHED_DIALOG</action>
<action>if false closewindow:LAUNCHED_DIALOG</action>
</checkbox>
<button><label>Exit</label></button>
</vbox>'
echo 1 > /tmp/tmp
gtkdialog3 -p MAIN_DIALOG |
_________________ Stardust resources
|
|
Back to top
|
|
 |
potong
Joined: 06 Mar 2009 Posts: 10
|
Posted: Sat 07 Nov 2009, 04:04 Post subject:
Some Undocumented Stuff |
|
Some stuff that may be useful.
| Code: | #!/bin/bash
# Written on a rainy day
# catch all at exit
trap 'echo "deleting $tempfile"; rm -f $tempfile /tmp/gtkrc' EXIT
# resource file stuff
cat <<EOF >/tmp/gtkrc
binding "MoveCursorPages" {
bind "<Control>D" {
"move-cursor" (pages, 1, 0)
}
bind "<Control>U" {
"move-cursor" (pages, -1, 0)
}
}
binding "MoveCursorToEnd" {
bind "<Control>Down" {
"move-cursor" (buffer-ends, 1, 0)
}
bind "<Control>Up" {
"move-cursor" (buffer-ends, -1, 0)
}
}
binding "MoveCursorWord" {
bind "<Control>Right" {
"move-cursor" (words, 1, 0)
}
bind "<Control>Left" {
"move-cursor" (words, -1, 0)
}
}
# bindings can be attached to signals (might be more to this?)
class "GtkEntry" binding "MoveCursorWord"
class "GtkEntry" binding "MoveCursorToEnd"
class "GtkTextView" binding "MoveCursorToEnd"
widget "*sourcecode" binding "MoveCursorPages"
style "mono50"
{ font_name="Mono bold 50" base[NORMAL]="black" text[NORMAL]="yellow" }
style "courier14"
{ font_name="courier normal 14" base[NORMAL]="beige" text[NORMAL]="brown" }
style "postie"
{
bg[NORMAL] = "beige"
fg[NORMAL] = "blue"
}
widget "gtk-tooltip*" style "postie"
# widgets can be selected by "name" attribute N.B. wildcards "*" in widget
widget "*timer" style "mono50"
widget "*sourcecode" style "courier14"
gtk-cursor-blink-time=50000
EOF
# include adhoc theme stuff with system themes
export GTK2_RC_FILES=/tmp/gtkrc:/root/.gtkrc-2.0
# functions
progress(){ # called as input for the progressbar
while : # loop forever
do
sleep 0.1 # wait a while
echo $(ticker) # this shows up on the progressbar
echo 100 # this activates the progressbar action
done & # background it
}
ticker(){ # stream a ticker n.b. use base 10 to avoid octal (leading 0's)
local msg="$ticker_msg >>><<<" # add a divider
local time=$(date +%S%N) # seconds and nanosecs
local num=${time:0:3} # strip to secs and tenths
local count=$(((10#$num)%${#msg})) # calculate letter shift
local temp=${msg:$count} # cut up the message
echo "${temp}${msg%%$temp}" # and stick it back together
}
seconds(){ # called as input for the entry
[ ! -f $tempfile ] && echo $TIMER && return # use tempfile as a switch
local start=$(<$tempfile) # get start time from file
local time="$(($(date '+%s')-start))" # seconds from start
printf "%02d:%02d:%02d" $((time/3600)) $((time%3600/60)) $((time%60))
}
refresh(){ # called when the refresh button is clicked
rm_tempfile # belt and braces
echo $(date '+%s') >$tempfile # save new start time
}
rm_tempfile(){ # called when a key-press is activated in the entry widget
rm -f $tempfile # delete tempfile (see trap)
}
# export functions and variables (once exported cannot be altered)
export -f progress ticker seconds refresh rm_tempfile
export tempfile=$(mktemp) ticker_msg="Press any key to stop the timer"
# save the time in seconds from 1970 in tempfile
echo $(date '+%s') >$tempfile
edit_tooltip_text="Use Control Up and Control Down to go to start and end of buffer.
Use Control Right and Control Left to jump foreward and backwards by a word.
Use Control U and Control D to up and down a page at a time.
See bindings in the resource file."
# GUI layout N.B. use a here-document and cat to avoid most(?) backslashes
export stopwatch=$(cat <<EOV
<window title="Simple Timer">
<vbox>
<notebook enable-popup="true" page="0" tab-pos="3" labels="Timer|Source">
<vbox width-request="275">
<progressbar visible="true" text-xalign="0.5">
<input>progress</input>
<action>refresh:TIMER</action>
</progressbar>
<entry name="timer" xalign="0.5" tooltip-text="Press any key to stop the clock">
<variable>TIMER</variable>
<input>seconds</input>
<action signal="key-press-event">rm_tempfile</action>
</entry>
<button use-stock="true" label="gtk-refresh" tooltip-text="Click to zero the clock">
<action>refresh</action>
</button>
</vbox>
<vbox height-request="400" width-request="800">
<frame Source Code for $0>
<edit name="sourcecode" editable="false" tooltip-text="$edit_tooltip_text">
<input file>$0</input>
</edit>
</frame>
</vbox>
</notebook>
<hbox tooltip-text="Try right clicking on a notebook tab">
<button use-stock="true" label="gtk-cancel" image-position="3" relief="2" xalign="1" tooltip-text="Press Alt C"></button>
</hbox>
</vbox>
</window>
EOV)
gtkdialog3 -p stopwatch |
Potong
|
|
Back to top
|
|
 |
zigbert

Joined: 29 Mar 2006 Posts: 2504 Location: Valåmoen, Norway
|
Posted: Sat 07 Nov 2009, 05:15 Post subject:
|
|
Potong
I am amazed (and shocked)
This is so much heavy stuff, I need the weekend to play
Absolutely WONDERFUL
I will rewrite main post
Sigmund
_________________ Stardust resources
|
|
Back to top
|
|
 |
Patriot

Joined: 15 Jan 2009 Posts: 526
|
Posted: Sat 07 Nov 2009, 08:50 Post subject:
|
|
Hmmm .....
zigbert,
Oh yes ... that's it ! Thanks to potong for the backgrounding thingy ...
That's precisely the embedded timer event method I'm looking for ... How could have I missed the backgrounding ...
Ok, zigbert, the short and condensed timer event illustration ...
| Code: | #!/bin/sh
# Scrolling text & embedded timer event illustration
function scrolltext() {
thestr="${1}"
echo "${thestr:2}${thestr:0:2}"
}
function timer() {
# 100% value bypass: Explanation is in the same thread ahead
# Input must be str+int or int+str sequence
while : ; do echo -e "x\n 100; sleep 0.5; done
}
export -f scrolltext timer
export GTKBOX='
<window title="Embedded Timer Event">
<vbox>
<text width-request="240"><label>""</label></text>
<progressbar visible="false">
<input>timer</input>
<action>refresh:SCROLLMSG</action>
</progressbar>
<entry text="Keep scrolling scrolling scrolling ... ">
<variable>SCROLLMSG</variable>
<input>scrolltext "$SCROLLMSG"</input>
</entry>
<hbox>
<button use-stock="true" label="gtk-quit" has-focus="true">
<action>EXIT:Exit</action>
</button>
</hbox>
</vbox>
</window>'
gtkdialog3 -p GTKBOX -c
unset GTKBOX
|
Time to update some of my codes .....
Rgds
[Edit] Minor correction to progressbar timer function
.
Last edited by Patriot on Sat 07 Nov 2009, 11:18; edited 1 time in total
|
|
Back to top
|
|
 |
zigbert

Joined: 29 Mar 2006 Posts: 2504 Location: Valåmoen, Norway
|
Posted: Sat 07 Nov 2009, 09:26 Post subject:
|
|
Patriot and potong
Why background the while-loop. If I remove the &, everything works as normal...???
Ok, so it's echo that does the scrolling part. Is it possible to scroll a long text in a short field? Now we scroll for fun, but I would like to scroll if gui isn't wide enough.
I have already updated the clock-script in the main post with a invisible progressbar. Are there other widgets than checkboxes (flip-flops) and progressbars (event-handling) that could benefit of being hidden?
Yes, we are pushing the limits...
Sigmund
_________________ Stardust resources
|
|
Back to top
|
|
 |
Patriot

Joined: 15 Jan 2009 Posts: 526
|
Posted: Sat 07 Nov 2009, 11:30 Post subject:
|
|
Hmmm .....
| zigbert wrote: | | ..... If I remove the &, everything works as normal...??? |
You're right. I did that just now and the chi energy flows through the codes .....
So, in order to understand why, I unzapped the sources and this is what I think is happening:
1. Creation of a progressbar <input> command will start a new separate thread with an input pipe.
2. As long as the pipe is opened, the separate thread runs ...
3. For reasons that I cannot yet comprehend, the input values are to be in the sequence of string + integer or integer + string ... or the timer cycle doesn't work ...
4. Each time the input value 100 is received, it performs all in action list and then repeat waiting for more piped input cycle.
5. Once the thread quits, the pipe is closed,
6. When the widget is destroyed, the piped reader thread quits.
7. It is the programmer's responsibility to ensure that the separate thread does not cause a cpu usage runaway (ie. use of sleep recess).
Now, I took a peek at my old test scripts and found that I was missing the text + integer input sequence (ie. I was only sending the int update) ... That's why my earlier scripts borks with progressbar as timer events ... It's not the backgrounding after all ... oh well, can't win 'em all ... but I'm sure glad to have the timer event working .....
| zigbert wrote: | | Ok, so it's echo that does the scrolling part. Is it possible to scroll a long text in a short field? ..... |
Yes, of course.
| zigbert wrote: | | Are there other widgets than checkboxes (flip-flops) and progressbars (event-handling) that could benefit of being hidden? |
I believe there's more waiting to be discovered ...
Rgds
|
|
Back to top
|
|
 |
zigbert

Joined: 29 Mar 2006 Posts: 2504 Location: Valåmoen, Norway
|
Posted: Sat 07 Nov 2009, 15:19 Post subject:
|
|
I need help.
The attached script is just a simple launch/close script. I works fine, but I try to let the checkbox <input> check if a file exist .... If it does, - true. If it doesn't, - false.
I was hoping to change
<input>if [ "$CHKBOX" = "false" ]; then echo "true"; else echo "false"; fi</input>
with
<input>if [ -f /tmp/tmp ]; then echo "true"; else echo "false"; fi</input>
| Code: | #!/bin/sh
export LAUNCHED_DIALOG='<vbox><text><label>This is a launched window</label></text></vbox>'
export MAIN_DIALOG='
<vbox>
<button>
<label>"Launch/Close"</label>
<action>refresh:CHKBOX</action>
</button>
<checkbox visible="false">
<variable>CHKBOX</variable>
<input>if [ "$CHKBOX" = "false" ]; then echo "true"; else echo "false"; fi</input>
<action>if true launch:LAUNCHED_DIALOG</action>
</checkbox>
</vbox>'
gtkdialog3 -p MAIN_DIALOG |
_________________ Stardust resources
|
|
Back to top
|
|
 |
zigbert

Joined: 29 Mar 2006 Posts: 2504 Location: Valåmoen, Norway
|
Posted: Sat 07 Nov 2009, 17:52 Post subject:
|
|
Main post updated
#########################################
Gtk-theme
...
By giving the text-widget a name (see example), it is possible to have a gtk-theme for only this uniqe text string. This will work for all kinds of widget types.
| 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>"
gtkdialog3 --program=test_app |
##########################################
Scroll text
>> This example shows scrolling text in a <entry> widget. This will work for other widgets as well.
| Code: | #!/bin/sh
# Scrolling text & embedded timer event illustration
function scrolltext() {
thestr="${1}"
echo "${thestr:2}${thestr:0:2}"
}
function timer() {
# 100% value bypass: Explanation is in the same thread ahead
# Input must be str+int or int+str sequence
while : ; do echo -e "x\n 100; sleep 0.5; done
}
export -f scrolltext timer
export GTKBOX='
<window title="Embedded Timer Event">
<vbox>
<text width-request="240"><label>""</label></text>
<progressbar visible="false">
<input>timer</input>
<action>refresh:SCROLLMSG</action>
</progressbar>
<entry text="Keep scrolling scrolling scrolling ... ">
<variable>SCROLLMSG</variable>
<input>scrolltext "$SCROLLMSG"</input>
</entry>
<hbox>
<button use-stock="true" label="gtk-quit" has-focus="true">
<action>EXIT:Exit</action>
</button>
</hbox>
</vbox>
</window>'
gtkdialog3 -p GTKBOX -c
unset GTKBOX |
###################################################################################
7.) Extended use of widgets - Undocumented features
###################################################################################
<text>
>> For more advanced text layout, here is a good catch.
<button>
>> As many other widgets buttons support tooltips.
<button tooltip-text=" This is the text ">...</button>
>> You can skip the button decoration.
<button relief="2">...</button>
>> The image doesn't need to be left of label. It can be left/right/above/below. Values 0-3
<button image-position="3">...</button>
>> Size of button can be defined.
<button width-request="100" height-request="200">...</button>
>> Label alignment can be justified.
<button xalign="1" yalign="1">...</button>
>> Hotkey is set in 2 ways
<button use-stock="true" label="gtk-cancel">...</button>
<button use-underline="true"><label>Cancel</label>...</button>
<notebook>
>> You can define which tab should be active by default. "0" represent tab1, "1" represent tab2 ...
<notebook page="1">...</notebook>
>> Tabs can be shown at Top/Bottom/Left/Right. Values from 0-3
<notebook tab-pos="3">...</notebook>
>> Tabs can chosen in right-click menu
<notebook enable-popup="true">...</notebook>
_________________ Stardust resources
|
|
Back to top
|
|
 |
Patriot

Joined: 15 Jan 2009 Posts: 526
|
Posted: Mon 09 Nov 2009, 03:15 Post subject:
|
|
Hmmm .....
| zigbert wrote: | I need help.
........
I was hoping to change
<input>if [ "$CHKBOX" = "false" ]; then echo "true"; else echo "false"; fi</input>
with
<input>if [ -f /tmp/tmp ]; then echo "true"; else echo "false"; fi</input>
........ |
I believe the gtkdialog input command parsing is kinda borked if you do "if [ -f ... statement" ... I suggest placing the "if statement" into an exported function like so:
| Code: | function checkfile() {
if [ -e /tmp/tmp ]; then echo "true"; else echo "false"; fi</input>
}
export -f checkfile
... <input>checkfile</input> |
... but it does seem counter-productive to use hidden checkbox this way ... I suggest to just use simple button action for it ...
Rgds
|
|
Back to top
|
|
 |
zigbert

Joined: 29 Mar 2006 Posts: 2504 Location: Valåmoen, Norway
|
Posted: Mon 09 Nov 2009, 13:58 Post subject:
|
|
| Patriot wrote: | | I believe the gtkdialog input command parsing is kinda borked if you do "if [ -f ... statement" ... I suggest placing the "if statement" into an exported function like so: | Naaaah, I've tried with no luck....
| Patriot wrote: | | ... but it does seem counter-productive to use hidden checkbox this way ... I suggest to just use simple button action for it ... | Thought so too, but I don't know how to launch a new dialog using an <action> of a invisible button in combination with an 'if' statement.
BTW, here is a draft for a right-click-menu. Does not follow the main gtk-theme, but works ok. Note that the <window> attribute skip_taskbar_hint="true" doesn't work.
| Code: | #!/bin/sh
menu_right_click(){
#this builds a fake menu using the <tree> widget
if [ $BUTTON = 3 ]; then
#set gtk-theme
echo 'style "menu-right" {
font_name = "DejaVu Sans 12"
bg[NORMAL] = "#ADADAD"
base[NORMAL] = "#ADADAD"
base[SELECTED] = "#878787"
text[NORMAL] = "#222222"
text[SELECTED] = "#ffffff"
engine "pixmap" {
image {
function = FOCUS
file = "<none>"}}}
class "*" style "menu-right"' > /tmp/gtkrc
export GTK2_RC_FILES=/tmp/gtkrc
#show menu
export menu="
<window title=\"menu\" decorated=\"false\" skip_taskbar_hint=\"true\" window_position=\"2\">
<vbox>
<tree hover-selection=\"true\" headers-visible=\"false\">
<label>a</label>
<variable>MENU</variable>
<height>75</height><width>200</width>
<item>Rename</item>
<item>Copy</item>
<item>Delete</item>
<action>echo</action>
</tree>
</vbox>
<action signal=\"leave-notify-event\">EXIT:exit</action>
</window>"
gtkdialog3 -p menu > /tmp/menu 2> /dev/null
OUTPUT="`grep 'MENU=' /tmp/menu | cut -d '"' -f 2`" #'
case $OUTPUT in
Rename) gxmessage Rename;;
Copy) gxmessage Copy;;
Delete) gxmessage Delete;;
esac
fi
}
export -f menu_right_click
export MAIN='
<vbox>
<tree hover-selection="true">
<label>files</label>
<input>ls -1</input>
<variable>TREE</variable>
<height>400</height><width>300</width>
<action signal="button-press-event">menu_right_click</action>
</tree>
</vbox>'
gtkdialog3 -p MAIN |
Sigmund
_________________ Stardust resources
|
|
Back to top
|
|
 |
potong
Joined: 06 Mar 2009 Posts: 10
|
Posted: Yesterday, at 13:53 Post subject:
Date Entry |
|
Using mouse clicks to update a date entry (poor mans calendar)
| Code: | #!/bin/bash
trap 'echo deleting $tempfile; rm -f $tempfile' EXIT
# use combination of radio buttons and mouse clicks to manipulate date entry
set_date(){ # see tooltip
local period d=${DATE:0:2} m=${DATE:3:2} Y=${DATE:6:4} # split DATE
[[ $RB_DAY = true ]] && period="day" # use radio buttons to
[[ $RB_MONTH = true ]] && period="month" # adjust time period
[[ $RB_YEAR = true ]] && period="year"
case $BUTTON in # BUTTON is exported by gtkdialog
1) date -d "$Y-$m-$d +1 $period" +"%d/%m/%Y";; # left (+)
3) date -d "$Y-$m-$d -1 $period" +"%d/%m/%Y";; # right(-)
*) date +"%d/%m/%Y";; # everything else set todays date
esac
}
export -f set_date
tt="left/middle/right click to add/refresh/subtract date"
l1="Select the function below and save
it in your .bashrc:"
tempfile=$(mktemp)
echo "tempfile=$tempfile"
cat <<'EOV' >$tempfile
runs(){
local p="Overwrite $1 y/n? "
[[ -f $1 ]] && {
read -p "$p" yn
[[ ! $yn = y ]] && return
}
xclip -o >$1; chmod +x $1; $1;
}
EOV
l2="Select code snippets from forum and
then in a terminal type: runs <filename>
N.B. Beware Puppy runs as root!
Always check all code first!"
export GUI=$(cat <<EOV | sed -e 's/#.*//' # allow comments in gui
<window title="+/- Date"> # also useful when building
<vbox> # the gui (alignment etc)
<notebook labels="+/- Date|Source|Useful Function">
<vbox>
<frame Date Manipulation>
<entry xalign="0.5" editable="false"> # centre date
<variable>DATE</variable>
<input>set_date</input> # call exported function
</entry>
<hbox homogeneous="true">
<vbox>
<radiobutton active="true" label="Day"> # set day as default step
<variable>RB_DAY</variable>
</radiobutton>
<radiobutton label="Month">
<variable>RB_MONTH</variable>
</radiobutton>
<radiobutton label="Year">
<variable>RB_YEAR</variable>
</radiobutton>
</vbox>
<button tooltip-text="$tt" label="+/- Date">
<action signal="button-press-event" type="refresh">DATE</action>
</button>
</hbox>
</frame>
</vbox>
<vbox height-request="400" width-request="600">
<frame Source Code for $0>
<edit editable="false">
<input file>$0</input>
</edit>
</frame>
</vbox>
<vbox>
<frame Forum Code Copy Function>
<text label="$l1" xalign="0"></text>
<text selectable="true" xalign="0">
<label>xxx</label>
<input file>$tempfile</input>
</text>
<text label="$l2" xalign="0"></text>
</frame>
</vbox>
</notebook>
<hbox>
<button cancel></button>
</hbox>
</vbox>
</window>
EOV)
gtkdialog3 -p GUI
|
potong
|
|
Back to top
|
|
 |
|
|
|
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
|