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
mavrothal
Posts: 3096
Joined: Mon 24 Aug 2009, 18:23

Re: click'able progressbar

#1081 Post by mavrothal »

Geoffrey wrote:
mavrothal wrote:I was wondering if there is a way to make a progress bar clickable.
Try wrapping the progressbar with an eventbox, that should work.
Thank you!
That did it. :D
== [url=http://www.catb.org/esr/faqs/smart-questions.html]Here is how to solve your[/url] [url=https://www.chiark.greenend.org.uk/~sgtatham/bugs.html]Linux problems fast[/url] ==

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

#1082 Post by don570 »

Quick tip to avoid bad entries :

If entry widget accepts a positive integer, then check it
with a test...

Code: Select all

ENTRY=8;[ $ENTRY -gt 0 ] && xmessage true

If the time of day is entered then here is a quick check
by eliminating colon with the sed command
and then testing...

Code: Select all

ENTRY=`echo "9:00:09" | sed 's/://g'`;[ $ENTRY -ge 0 ] && xmessage true
Note that an error is passed to shell if variable is ordinary text

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

#1083 Post by MochiMoppel »

don570 wrote:Note that an error is passed to shell if variable is ordinary text
Wouldn't it be easier to eliminate everything that is not a digit?

Anyway, time entry can be tricky. You would need more tests to catch invalid times like 25:11:22 or 22:1:122.
I think I once wrote me a pretty bullet proof time entry widget. I'll post it - provided I can find it :lol:

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

#1084 Post by seaside »

MochiMoppel wrote:
don570 wrote:
Anyway, time entry can be tricky. You would need more tests to catch invalid times like 25:11:22 or 22:1:122.
Perhaps adapting this approach-

Code: Select all

 [[ $time_entry =~ ^[0-2]?[0-9]:[0-5][0-9]:[0-5][0-9]$ ]] && echo yes 
Cheers,
s

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

#1085 Post by MochiMoppel »

seaside wrote:Perhaps adapting this approach-

Code: Select all

 [[ $time_entry =~ ^[0-2]?[0-9]:[0-5][0-9]:[0-5][0-9]$ ]] && echo yes 
Would still allow 25:11:22 :cry:

Maybe this way:

Code: Select all

[[ $time_entry =~ ^([0-1]?[0-9]|2[0-3])(:[0-5]?[0-9]){0,2}$ ]] && echo true
This would allow entries like 5 and 9:30 and 9:9:9, all perfectly legal time formats.

If you want to make sure that these values are written as 05:00:00 and 09:30:00 and 09:09:09 try

Code: Select all

[[ $time_entry =~ ^([0-1][0-9]|2[0-3])(:[0-5][0-9]){2}$ ]] && echo true

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

#1086 Post by don570 »

Thanks to MochiMoppel 8)
I'll put the code inbaconrecorder entry widget.

By the way if first digit is zero I eliminate it before I test
if current time is greater than entered time.

___________________________________________

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

#1087 Post by MochiMoppel »

don570 wrote:By the way if first digit is zero I eliminate it before I test
if current time is greater than entered time.
I must have read your sentence more that 10 times now... I still don't understand it :cry:

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

#1088 Post by don570 »

to MochiMoppel...

Example 08:59:13


I checked if 8 characters were entered ---> if there is 8 characters then
I check if leading character is a zero.

If it is a zero then I drop it from the string. Then I delete the
colons using something I had read in Bash manual.
Substring Replacement

${string/substring/replacement}

Replace first match of $substring with $replacement. [2]
${string//substring/replacement}

Replace all matches of $substring with $replacement.

I should have used sed command to eliminate the colons.
I was just learning to program when I wrote baconrecorder.

______________________________________

A problem with MochiMoppel's suggestion is I don't know if
the user has entered seven or eight characters, so I need to check
first.

___________________________________________________

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

#1089 Post by MochiMoppel »

don570 wrote:A problem with MochiMoppel's suggestion is I don't know if
the user has entered seven or eight characters, so I need to check
first.
??? Both suggestions are only examples. Feel free to adjust them to meet your requirements. I don't understand why say you don't know if the user entered 7 or 8 characters. The second example makes the input of 8 characters mandatory. No ambiguities whatsoever.
I should have used sed command to eliminate the colons.
Why? Bash substring replacement is the ideal tool for this job. Sed could do it as well but would be much slower.

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

#1090 Post by don570 »

I've looked at my code in baconrecorder
and I actually added a leading zero
if only 7 characters were entered.

Code: Select all

 
# Add a zero at beginning if user left this out
if  [ "${#TIME_FUTURE}" = 7 ] ;then 
TIME_FUTURE=`echo "0""$TIME_FUTURE"`	
fi

Note that I don't think that an echo command was needed :oops:
TIME_FUTURE="0""$TIME_FUTURE"
would be okay

I probably did this because the leading zero is ignored anyway,
as shown by this example....

Code: Select all

 [  09 -gt 7 ] && echo true

User avatar
recobayu
Posts: 387
Joined: Wed 15 Sep 2010, 22:48
Location: indonesia

#1091 Post by recobayu »

Hi All,
how to close gtkdialog by "Esc" key?
Thank you

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

#1092 Post by SFR »

recobayu wrote:Hi All,
how to close gtkdialog by "Esc" key?
Thank you

Code: Select all

<window>

  (your code)

  <action signal="key-press-event" condition="command_is_true([ $KEY_SYM = Escape ] && echo true )">exit:EXIT</action>
</window>
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]

step
Posts: 1349
Joined: Fri 04 May 2012, 11:20

#1093 Post by step »

I read that several widget can take custom tag block-function-signals. What does it do? The docs just say "block signals from actions". Which means what? Does it mean, for example, that if widget A performs <action>save:B</action> and widget B set block-function-signals=true then the save action isn't executed at all? What are practical cases when enabling block-function-signals can be useful? Is there a dynamic way to change the value of block-function-signals, or is it just a dialog compile flag?
[url=http://murga-linux.com/puppy/viewtopic.php?t=117546]Fatdog64-810[/url]|[url=http://goo.gl/hqZtiB]+Packages[/url]|[url=http://goo.gl/6dbEzT]Kodi[/url]|[url=http://goo.gl/JQC4Vz]gtkmenuplus[/url]

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

#1094 Post by SFR »

I don't fully understand this attribute, but from what I see, it won't block actions initiated from within a given widget (by direct user action), but it will block them, if another widget is the initiator.

In this example when you type something in any of the entry boxes, a corresponding action gets executed, but pressing 'Refresh' button triggers action only in the first one, with 'block-function-signals=false':

Code: Select all

#!/bin/sh

export MAIN='
<hbox>

  <vbox>
    <text><label>block-false</label></text>
    <entry block-function-signals="false">
      <variable>BLOCK_FALSE</variable>
      <input>date +%s</input>
      <action signal="changed">echo BLOCK_FALSE</action>
    </entry>
    <button>
      <label>Refresh</label>
      <action>refresh:BLOCK_FALSE</action>
    </button>
  </vbox>
  
  <vbox>
    <text><label>block-true</label></text>
    <entry block-function-signals="true">
      <variable>BLOCK_TRUE</variable>
      <input>date +%s</input>
      <action signal="changed">echo BLOCK_TRUE</action>
    </entry>
    <button>
      <label>Refresh</label>
      <action>refresh:BLOCK_TRUE</action>
    </button>
  </vbox>

</hbox>'

gtkdialog -p MAIN
Perhaps someone else has a better explanation...

I have used that flag (by trial and error) in Multirename, what has improved <tree>'s reload time significantly.
I added it also to my legacy FNR recently, but I can't tell any difference in this case...

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:

#1095 Post by zigbert »

block-function-signals was introduced after my request. See
http://www.murga-linux.com/puppy/viewto ... 704#544704

step
Posts: 1349
Joined: Fri 04 May 2012, 11:20

#1096 Post by step »

zigbert wrote:block-function-signals was introduced after my request. See
http://www.murga-linux.com/puppy/viewto ... 704#544704
So, based on this, my understanding is that the motivation for using block-function-signals is function and not performance. Set it true to fence off actions that do not correspond to manual user changes. For example set it true if you want to trigger the skip forward/backward action only when a user changes the slider value (by dragging it) and for no other reason. Hopefully I'm getting it right.
[url=http://murga-linux.com/puppy/viewtopic.php?t=117546]Fatdog64-810[/url]|[url=http://goo.gl/hqZtiB]+Packages[/url]|[url=http://goo.gl/6dbEzT]Kodi[/url]|[url=http://goo.gl/JQC4Vz]gtkmenuplus[/url]

User avatar
recobayu
Posts: 387
Joined: Wed 15 Sep 2010, 22:48
Location: indonesia

#1097 Post by recobayu »

Can we cange label based on entry? I mean when we change text on entry, the label change directly live perform.

User avatar
trio
Posts: 2076
Joined: Sun 21 Dec 2008, 15:50
Location: अनà¥￾मोदना

#1098 Post by trio »

recobayu wrote:Can we cange label based on entry? I mean when we change text on entry, the label change directly live perform.
edit: ini mgkn yg anda mau

Code: Select all

#!/bin/bash -a

function echotext ()
{
echo "$NEWTEXT" > /tmp/text.txt
}
echo "OLD TEXT" > /tmp/text.txt 
export GUI="
<window title="Auto" icon-name="gtk-edit">
<vbox>
	<timer milliseconds="true" interval="200" visible="false">
      <action type="refresh">TEXT</action>
      <action type="refresh">NEWTEXT</action>
      </timer>
	<text>
	<input>cat /tmp/text.txt</input><variable>TEXT</variable>
	</text>
		<entry>
		<variable>"NEWTEXT"</variable>
		<action>echotext &</action>
		</entry>
</vbox>
</window>"		
gtkdialog --program=GUI
lihat widget timer nya ... selamat mencoba

User avatar
recobayu
Posts: 387
Joined: Wed 15 Sep 2010, 22:48
Location: indonesia

#1099 Post by recobayu »

Terima kasih mas Trio..
Saya nyoba sendiri bisa ternyata. Alhamdulillah..

Code: Select all

#!/bin/sh
echo > labelku
export a='<window>
<vbox>
 <entry>
  <action signal="changed">echo $e > labelku</action>
  <action signal="changed">refresh:t</action>
  <variable>e</variable>
 </entry>
 
  <text>
   <input file>labelku</input>
   <variable>t</variable>
  </text>
</vbox> 
</window>'
gtkdialog -p a
Lebih cepet malahan.. :D

User avatar
trio
Posts: 2076
Joined: Sun 21 Dec 2008, 15:50
Location: अनà¥￾मोदना

#1100 Post by trio »

Mantap

Code: Select all

<action signal="changed">

Post Reply