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
Geoffrey
Posts: 2355
Joined: Sun 30 May 2010, 08:42
Location: Queensland

#1141 Post by Geoffrey »

zigbert wrote:Geoffrey
Thanks for this one - interesting!

I have put your code in the new post about Text managing
Yes it is interesting, I was looking for another means to make strikethrough text other than doing it online,
this isn't perfect as there can be some small spaces in the line if you look carefully and when paste in to a text file the line shifts to the right by one character, but it's good enough.
I found the simplest code solutionhere

Code: Select all

echo text | sed $"s/./&\xCC\xB6/g"
I noted that the "$" in the code made no difference, so I removed it.

List of character codeshere

edit:
I compared both ways of doing it, their identical.

I see a space in the line on the "m"
w̶r̶i̶t̶e̶ ̶s̶o̶m̶e̶ ̶t̶e̶x̶t̶ ̶h̶e̶r̶e̶ online strikethrough
w̶r̶i̶t̶e̶ ̶s̶o̶m̶e̶ ̶t̶e̶x̶t̶ ̶h̶e̶r̶e̶ gtkdialog strikethrough
[b]Carolina:[/b] [url=http://smokey01.com/carolina/pages/recent-repo.html]Recent Repository Additions[/url]
[img]https://dl.dropboxusercontent.com/s/ahfade8q4def1lq/signbot.gif[/img]

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

#1142 Post by MochiMoppel »

Geoffrey wrote:this isn't perfect as there can be some small spaces in the line if you look carefully
As you already said: Good enough. Spaces occur when you put the line character, which as any other character has its own width, on top of another character with a different width. If this character (e.g. the relatively wide letter 'm') is wider than the line you will see gaps. These gaps disappear when you use a fixed width font. You may see line gaps here: m̶m̶m̶m̶m̶m̶m̶m̶m̶m̶m̶
Now copy the string into Geany, which can handle UTF-8 and by default uses a fixed width font. See the difference?
I found the simplest code solutionhere
I use almost the same simple code, but made me a GUI. I didn't even bother to put it into a script and entered it directly into a desktop icon, but for "normal" users here is the code:

Code: Select all

xclip -o | sed "s/./&\xCC\xB6/g" | gxmessage -c -file -
Usage: Select some text in any application, then run the script (e.g. via desktop icon or keyboard shortcut)

Since we are here in the gtkdialog thread it should be noted that gtkdialog can produce beautiful strkethrough text, even with colored strike. The only problem is that the text loses its formats when the text is copied to another application. UTF-8 makes the text usable in all aplications that understand Unicode. To see the difference between strikethrough formatting via Pango mark-up in gtkdialog and via UTF-8 you can try this demo:

Code: Select all

#!/bin/sh
function  mark_me_up { echo -n "<span strikethrough='true'  strikethrough_color='red' font='bold 14'>$@</span>" ;}
export -f mark_me_up

echo '
<window>
<vbox>
    <frame>
        <edit>
            <default>"Sample text"</default>
            <variable>vEDIT</variable>
        </edit>
    </frame>

    <frame Pango Markup>
        <text use-markup="true" xalign="left" selectable="true">
            <variable>vTEXT1</variable>
            <input>mark_me_up "$vEDIT"</input>
        </text>
    </frame>

    <frame UTF-8 U+0336>
        <text xalign="left" selectable="true">
            <variable>vTEXT2</variable>
            <input>echo "$vEDIT" | sed "s/./&\xCC\xB6/g"</input>
        </text>
    </frame>


    <button label="Create S̶T̶R̶I̶K̶E̶̶̶">
        <action>refresh:vTEXT1</action>
        <action>refresh:vTEXT2</action>
    </button>
</vbox>
</window>' | gtkdialog -s
Attachments
strikethrough.png
(7.45 KiB) Downloaded 904 times

User avatar
Geoffrey
Posts: 2355
Joined: Sun 30 May 2010, 08:42
Location: Queensland

#1143 Post by Geoffrey »

MochiMoppel wrote:I use almost the same simple code, but made me a GUI. I didn't even bother to put it into a script and entered it directly into a desktop icon, but for "normal" users here is the code:

Code: Select all

xclip -o | sed "s/./&\xCC\xB6/g" | gxmessage -c -file -
Usage: Select some text in any application, then run the script (e.g. via desktop icon or keyboard shortcut)
Nice, I had a play and opted for this with a hotkey

Code: Select all

#!/bin/sh
xclip -o | sed "s/./&\xCC\xB6/g" | xclip -selection "clipboard"
Select text - press hotkey - paste, result = S̶e̶l̶e̶c̶t̶ ̶t̶e̶x̶t̶
[b]Carolina:[/b] [url=http://smokey01.com/carolina/pages/recent-repo.html]Recent Repository Additions[/url]
[img]https://dl.dropboxusercontent.com/s/ahfade8q4def1lq/signbot.gif[/img]

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

#1144 Post by MochiMoppel »

Yes, that's probably the fastest solution and similar to what was discussed in this recent thread.
You only need to be careful not to use xclip from within gtkdialog, otherwise gtkdialog will acquaint you with its very nasty variable bug.

User avatar
torm
Posts: 186
Joined: Sat 07 Mar 2015, 19:56

#1145 Post by torm »

MochiMoppel wrote:
torm wrote:<action signal="type">activity</action>
if "button-release-event" is the event
does GtkStatusbar widget support that?
Needs an eventbox to work:

Code: Select all

#! /bin/sh
echo '
<window width-request="200">
    <eventbox>
        <statusbar>
            <input>echo "Click me!"</input>
        </statusbar>
        <action signal="button-press-event">beep</action> 
        <action signal="button-release-event">beep -f100</action> 
    </eventbox>
</window>'|gtkdialog -s

Thanks for reply
:)
I think I've already tested it, at some point.
And it is emitting at least some signals that can be used.
(to store the new location, etc.)

Tricked it to move around with middle-mouse-button.
However, the result is not as reliable as expected.
Will look into RoxFM and JWM to see if there's some built-in way..

Or, maybe there is some gtk-module to drag around the (not decorated) window?
Something small and simple, that could be used with Gtkdialog?

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

#1146 Post by MochiMoppel »

torm wrote:Or, maybe there is some gtk-module to drag around the (not decorated) window?
Something small and simple, that could be used with Gtkdialog?
What's wrong with the system wide default? You can move any window, decorated or not, by pressing Alt key + drag.

User avatar
torm
Posts: 186
Joined: Sat 07 Mar 2015, 19:56

#1147 Post by torm »

What's wrong with the system wide default? You can move any window, decorated or not, by pressing Alt key + drag.
:roll:
default user, maybe..
most people are not able to remember how to use kb+mb combinations.
So I'm trying to keep it simple.

Maybe I just bundle it with xdotool :?

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

#1148 Post by MochiMoppel »

"Tips and Tricks" section of the first post, chapter
Let entry accept (some) numbers only:

Code: Select all

<entry editable="true" allow-empty="false">
How does allow-empty work? Does it work at all for entry widgets?

BTW: Sorry to poke around in the code, but the main code doesn't seem right.

Code: Select all

<input>case $ENTRY in [0-9]*) echo $ENTRY;; *) echo 0;; esac</input>
Text will not default to 0 if the text starts with a number.

It works better when the logic is "reversed":

Code: Select all

<input>case $ENTRY in *[^0-9]*) echo 0;; *) echo $ENTRY ;; esac</input>
This will default to 0 if ENTRY contains any character other than characters 0 to 9.

If a completely empty field should also default to 0 then this should do it:

Code: Select all

<input>case $ENTRY in ""|*[^0-9]*) echo 0;; *) echo $ENTRY ;; esac</input>

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

#1149 Post by zigbert »

MochiMoppel wrote:BTW: Sorry to poke around in the code, but the main code doesn't seem right
:lol: :lol: :lol:

The code in this thread is a collection of many inputs, and all improvements are welcome.

I'll update the main post
Thank you

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

#1150 Post by MochiMoppel »

"Tips and Tricks" section of the first post, chapter
Let entry accept (some) numbers only:

Actually it's an interesting example and shows the dilemma when dealing with incorrect input. If an entry widget is supposed to accept only numbers and the user inputs letters, what should the checking routine do?
- Erase everything and replace with zero? That's probably the worst reaction
- Erase everything? Very common and not bad.
- Keep wrong entry and alert user? That's what I would prefer and what most web forms are doing.

This dilemma could be avoided if the entry would do what the headline promises and would accept numbers only - nothing else. Any input of non-numbers should be blocked. No more rubbish input to clean up later. Can it be done?

Of course it can. Here is the code:

Code: Select all

#!/bin/bash
TMP=/tmp/last_good  # file to hold last verified (=good) entry value
echo > $TMP         # create file
trap "rm $TMP" EXIT # delete tmp file before closing dialog

echo '
<vbox> 
  <text label="Strict number entry (non-numbers rejected)"></text> 
  <entry> 
    <variable>vENTRY</variable>
    <input file>'$TMP'</input> 
    <action condition="command_is_true([[ $vENTRY =~ ^[0-9]*$ ]] && echo $vENTRY > '$TMP' || { beep & echo true;})">refresh:vENTRY</action>
  </entry>
  <button></button>
</vbox>' |gtkdialog -cs
The code checks every new input. If it's good, i.e if the entry field still contains only numbers, the content is saved to the tmp file. If the user has entered a non-number, he is alerted with a beep and the entry field is refreshed with the content of the tmp file (holding the field content displayed before the non-number was added). Simply speaking it's an automatic undo function.

Important: The tmp file must not be completely empty. Apparently gtkdialog <input file> ignores empty files. That's the reason for the echo > $TMP command, which creates the file by sending a newline character.

This real-time checking method can be useful for many things, i.e it can be used to change capitalization on-the-fly and it can be used to support the final checking. I'm still exploring the possibilities.
Attachments
number_entry.png
(3.49 KiB) Downloaded 595 times

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

#1151 Post by zigbert »

Maybe the headline is wrong...

What about
Realtime check of <entry> input

mistfire
Posts: 1411
Joined: Wed 05 Nov 2008, 00:35
Location: PH

#1152 Post by mistfire »

To all developers here. I have a question, How to create a treeview with nodes on gtkdialog?

I want to show all files and subdirectories recursively in path and show them in a treeview.

Thank you

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

#1153 Post by recobayu »

step wrote:@recobayu , just a suggestion, why don't you move the text outside the button, so you can have all buttons left-aligned and same size, and text labels left-aligned and merged with background color?
Thank you Step.
Here is my code:

Code: Select all

#!/bin/sh
buattombol(){
ls /root/puppy-reference/midi-icons > ikon
for i in `cat ikon`;do
	echo '
<hbox spacing="0">
<button relief="2">
	<input file>/root/puppy-reference/midi-icons/'$i'</input>
	<width>24</width>
</button>
<button xalign="0" width-request="200" relief="2">
	<label>'$i'</label>
</button>
</hbox>'
done
}
#~ export -f buattombol 

export gui='
<window>
<vbox spacing="0" scrollable="true" width="260" height="600">
'"`buattombol`"'
<button>
	<label>okay</label>
</button>
</vbox>
</window>'
gtkdialog -p gui
Attachments
button left align.png
this is really left aligned :)
(26.76 KiB) Downloaded 516 times

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

#1154 Post by zigbert »

Underline / strikethrough text
>> Underline and strikethrough text is supported by the use-markup="true" option for text widgets.
<text use-markup="true"><label>"<u>underline</u>"</label></text>
<text use-markup="true"><label>"<s>strikethrough</s>"</label></text>
>> This example shows underline and strikethrough on request

Code: Select all

#!/bin/sh
> /tmp/text
export DIALOG='
<window title="unicode text formating" icon-name="gtk-strikethrough">
  <vbox>
    <edit wrap-mode="3">
      <variable>EDIT</variable>
      <default>write some text here</default>
      <height>50</height>
    </edit>
    <edit file-monitor="true" auto-refresh="true" wrap-mode="3" editable="false">
      <height>50</height>
      <input file>/tmp/text</input>
    </edit>
    <hbox homogeneous="true">
      <button>
        <label>Underline text</label>
        <input file stock="gtk-ok"></input>
        <action>`echo "$EDIT" | sed "s/./&\xCD\x9F/g" > /tmp/text`</action>
      </button>
      <button>
        <label>Strikethrough text</label>
        <input file stock="gtk-ok"></input>
        <action>`echo "$EDIT" | sed "s/./&\xCC\xB6/g" > /tmp/text`</action>
      </button>
    </hbox>
  </vbox>
</window>'
gtkdialog -p DIALOG

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

#1155 Post by zigbert »

MochiMoppel has enlightened us with more <chooser> knowledge.
read this post: http://www.murga-linux.com/puppy/viewtopic.php?t=107675


<chooser>
>> Type of chooser-widget
0 - Open file
1 - Save file
2 - Select folder
3 - Create folder
<chooser action="1">
>> Hide/Show 'create folders' button
<chooser create-folders="false">

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

#1156 Post by zigbert »


User avatar
mavrothal
Posts: 3096
Joined: Mon 24 Aug 2009, 18:23

#1157 Post by mavrothal »

I was wondering if there is a way in a tree widget with entires with multiple columns (see for example PPM), when you select an entry to pass the information of all the columns and not just the first one
In the PPM case the relevant code is

Code: Select all

          <hbox space-expand=\"true\" space-fill=\"true\">
            <tree hover-selection="true" selection-mode="1" column-resizeable="true|false" space-expand="true" space-fill="true">
              <label>'$(gettext 'Package')'|'$(gettext 'Description')'</label>
              <variable>TREE1</variable>
              <width>300</width>
              <input file icon-column="1">/tmp/petget/filterpkgs.results.post</input>
              <action signal="button-release-event">add_item</action>
              <action signal="button-release-event">refresh:TREE_INSTALL</action>
              <action signal="button-release-event">enable:BUTTON_INSTALL</action>
            </tree>
          </hbox>
and the input filterpkgs.results.post file is in the format:
<name>|<category>|<description>|<repository>
The <name> and <description> fields are showing in the widget but only <name> is passed in the $TREE1 variable.
Is there a way to pass both <name> and <description> (or ideally <name> and <repository> ?
Thanks
== [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] ==

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

#1158 Post by step »

I would add an extra column at the end, which packs together all the fields you want to export. They need to be separated by a character that isn't '|' and doesn't appear in the data. Backspace is usually a good choice.
So now your tree receives these data:

Code: Select all

<name>|<category>|<description>|<repository>|<packed>
   where
<packed> = <name>bs<category>bs<description>bs<repository>
Now tell <tree> to hide the <packed> column. Use attribute column-visible="1|1|1|1|0". And you want to export the last column. Use attribute exported-column="5".
If <tree> is showing the icon column you might need to shift those numbers +/- 1, I don't recall the details. Experiment till you get the correct indexes.
Finally, the process that receives gtkdialog output is responsible for unpacking <packed> and extracting the fields you're interested in.

Code: Select all

bs=`printf  '\b'`
echo "$TREE1" | cut -d "$bs" -f4  # will get <repository>
CAVEAT: The tree widget limits the total character count of each row to slightly over 510. I use 510.
Last edited by step on Tue 17 Jan 2017, 14:05, edited 1 time in total.
[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
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

#1159 Post by MochiMoppel »

step wrote:

Code: Select all

echo "$TREE1" | tr -s "$bs" -f4  # will get <repository>
This won't work. I assume you mean something like

Code: Select all

echo "$TREE1" | cut -d "$bs"  -f4

User avatar
mavrothal
Posts: 3096
Joined: Mon 24 Aug 2009, 18:23

#1160 Post by mavrothal »

Thank you both for the help.

I guess we cannot export 2 columns in $TREE1 (with something like exported-column="1|2"?). Would it be possible to export 2 variables out of the same tree widget? ie column 1 for TREE1 and Column 2 for TREE2
== [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] ==

Post Reply