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 Sun 24 Sep 2017, 03:14
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 78 of 81 [1213 Posts]   Goto page: Previous 1, 2, 3, ..., 76, 77, 78, 79, 80, 81 Next
Author Message
zigbert


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

PostPosted: Sun 11 Dec 2016, 05:50    Post subject:  

Howto set up dynamic tabs
_________________
Stardust resources
Back to top
View user's profile Send private message Visit poster's website 
mavrothal


Joined: 24 Aug 2009
Posts: 2872

PostPosted: Mon 16 Jan 2017, 01:47    Post subject:
Subject description: selection of tree entries
 

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:
          <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

_________________
Kids all over the world go around with an XO laptop. They deserve one puppy (or many) too Very Happy
Back to top
View user's profile Send private message 
step

Joined: 04 May 2012
Posts: 917

PostPosted: Mon 16 Jan 2017, 09:46    Post subject:  

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:

<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:

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.

_________________
Fatdog64-710|+Packages|Kodi|Findnrun|+forum|gtkmenuplus

Last edited by step on Tue 17 Jan 2017, 10:05; edited 1 time in total
Back to top
View user's profile Send private message 
MochiMoppel


Joined: 26 Jan 2011
Posts: 1351
Location: Japan

PostPosted: Mon 16 Jan 2017, 23:18    Post subject:  

step wrote:
Code:

echo "$TREE1" | tr -s "$bs" -f4  # will get <repository>
This won't work. I assume you mean something like
Code:
echo "$TREE1" | cut -d "$bs"  -f4
Back to top
View user's profile Send private message 
mavrothal


Joined: 24 Aug 2009
Posts: 2872

PostPosted: Tue 17 Jan 2017, 05:30    Post subject:  

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

_________________
Kids all over the world go around with an XO laptop. They deserve one puppy (or many) too Very Happy
Back to top
View user's profile Send private message 
step

Joined: 04 May 2012
Posts: 917

PostPosted: Tue 17 Jan 2017, 10:04    Post subject:  

@mavrothal, AFAIK, a widget can have only one associated variable. So a single tree with TREE1 and TREE2 variables isn't possible.

@MochiMoppel, thanks for catching my typo! Fixed.

_________________
Fatdog64-710|+Packages|Kodi|Findnrun|+forum|gtkmenuplus
Back to top
View user's profile Send private message 
seaside

Joined: 11 Apr 2007
Posts: 915

PostPosted: Wed 18 Jan 2017, 20:34    Post subject: selection of tree items  

step wrote:
@mavrothal, AFAIK, a widget can have only one associated variable. So a single tree with TREE1 and TREE2 variables isn't possible.

@MochiMoppel, thanks for catching my typo! Fixed.


Perhaps this also might be useful.

Code:
# get fields from a tree selection

# example file
echo 'name1 | cat1 | desc1 | repo1
name2 | cat2 | desc2 | repo2 ' >ppm.dat

# load variables, "items" for gui, "total" for all

while read line; do
total="$total
$line"
items="$items
<item>$line</item>"
done <ppm.dat

# Gui

GTKDIALOG=gtkdialog

export MAIN_DIALOG='
<window title="PPM_test" window_position="2" icon-name="gtk-dialog-warning">
<vbox>
  <frame Left-click Selection>
    <tree hover-expand="true" hover-selection="true">
      <variable>SELECT</variable>
      <width>460</width><height>260</height>
      <label>Name  | Cat | Desc |Repo</label>
      '"$items"'
      <action signal="button-press-event">exit:getitem</action>
    </tree>
  </frame>
  <hbox homogeneous="true">
   <button cancel></button>
  </hbox>
</vbox>
</window>
'
eval "$($GTKDIALOG --program=MAIN_DIALOG)"

[ "$EXIT" = "Cancel" ]  && exit

# getitem for repo and/or other items

IFSold="$IFS"
IFS='|'

# match selection in total

while read line;do
[[ ${line/$SELECT/} != ${line} ]]  &&   aline=($line) &&  break
done <<<"$total"

NAME=${aline[0]}
CAT=${aline[1]}
DESC=${aline[2]}
REPO=${aline[3]}

echo "$REPO"
IFS="$IFSold"


I've always liked the "hover-selection" mode ....... it just gives a nice speedy and controlled feeling when selecting. Very Happy

Cheers,
s
Back to top
View user's profile Send private message 
MochiMoppel


Joined: 26 Jan 2011
Posts: 1351
Location: Japan

PostPosted: Thu 19 Jan 2017, 23:43    Post subject:  

step wrote:
CAVEAT: The tree widget limits the total character count of each row to slightly over 510. I use 510.

Good point. I don't know how you manage to get "slightly over" 510. For me the limit is exactly 510, and that includes the separators.

This limitation alone can make it impossible to load data into the widget, let alone duplicate the data in an added <packed> column. Packing all data in an extra column is perfectly OK for short and few data. For large amounts of data, especially when their length is not known, we need a different approach.

Let's think big. The following demo puts names and descriptions of all packages into a tree widget, in total almost 6000 items. In Slacko this means retrieving data from these files:
    /root/.packages/Packages-puppy-2-official
    /root/.packages/Packages-puppy-3-official
    /root/.packages/Packages-puppy-4-official
    /root/.packages/Packages-puppy-5-official
    /root/.packages/Packages-puppy-common-official
    /root/.packages/Packages-puppy-noarch-official
    /root/.packages/Packages-puppy-quirky-official
    /root/.packages/Packages-puppy-slacko14-official
    /root/.packages/Packages-slackware-14.0-official
    /root/.packages/Packages-slackware-14.0-patches
    /root/.packages/Packages-slackware-14.0-salix
    /root/.packages/Packages-slackware-14.0-slacky

Some entries in these files are as long as 900 characters, way too much for a tree widget. The trick is to not load the data themselves into the tree but rather a small representation and a unique index. This will allow to return any of the 14 data columns, not just one tree column, as variable.
The second trick is to define "helper widgets" in the dialog. Their sole purpose is to hold the variables which we can not export from the tree or which exist only in the data source, but not in the tree. In the demo this is achieved with the 4 entry widgets at the top. Normally they would be hidden, so would be the (exported) "Source" column of the tree.

Code:
#!/bin/sh
TMPFILE=/tmp/treeinput

## Retrieve all Name and Description fields from all repositories, add path of and line number within Packages file, then write to file
awk -F"|" '{print $1"|"$10"|"FILENAME"#"FNR}' /root/.packages/Packages* > $TMPFILE

function print_field {
    [ "$vTREE" ] || return                                      # exit if vTREE empty (happens at startup when nothing selected yet)
    FIELD=$1                                                    # field number within record
    RECORD=${vTREE##*#}                                         # line number within source file
    SOURCE=${vTREE%#*}                                          # full path of source file
    awk -F"|" 'FNR == '$RECORD' {print $'$FIELD'}' $SOURCE      # fetch and print field content
    ## FNR is the line number within each source file
    ## print adds trailing newline (printf does not)
    ## This ensures that output of awk is never an empty string, even if the printed field is empty.
    ## Gtkdialog refresh function does nothing (=keeps previous value) if <input> results in an empty string. Bug?
    ## Feeding value to entry widget and not a text widget will make sure that trailing newline(s) are discarded
}; export -f print_field

echo -n '
<window>
    <vbox>
        <vbox visible="true">
            <entry>
                <input>print_field 1</input>
                <variable>vNAME</variable>
            </entry>
            <entry>
                <input>print_field 10</input>
                <variable>vDESCRIPTION</variable>
            </entry>
            <entry>
                <input>print_field 6</input>
                <variable>vSIZE</variable>
            </entry>
            <entry>
                <input>echo ${vTREE%#*}</input> 
                <variable>vSOURCE</variable>
            </entry>
        </vbox>
        <tree column-visible="1|1|1" exported-column="2" auto-sort="true">
            <variable>vTREE</variable>
            <label>"Name|Description|Source"</label>
            <input file>'$TMPFILE'</input>
            <action signal="changed">refresh:vNAME</action>
            <action signal="changed">refresh:vDESCRIPTION</action>
            <action signal="changed">refresh:vSIZE</action>
            <action signal="changed">refresh:vSOURCE</action>
        </tree>
        <button></button>
    </vbox>
</window>
' | gtkdialog -G 600x400 -s
returned_variables.png
 Description   
 Filesize   106.05 KB
 Viewed   421 Time(s)

returned_variables.png

Back to top
View user's profile Send private message 
mavrothal


Joined: 24 Aug 2009
Posts: 2872

PostPosted: Fri 20 Jan 2017, 07:31    Post subject:  

For the "history", since I was trying to keep changes to a minimum and consistent with the rest of the ppm infrastucture I formulated a solution based on step's suggestion.
But I think is time for someone (not me) to really take up on re-writing PPM from scratch and implementing all these nice ideas both in UI an underneath. Wink

_________________
Kids all over the world go around with an XO laptop. They deserve one puppy (or many) too Very Happy
Back to top
View user's profile Send private message 
torm


Joined: 07 Mar 2015
Posts: 118

PostPosted: Fri 07 Jul 2017, 20:29    Post subject:  

.

comboboxtext widget
-menuitem refuses to follow cursor up if any xy is set in the theme for "menu" ?
Appears 1st item up, while 2nd+ look ok. Cursor down is ok.
Is able to click it, while spoils the look...

Tested with "default" theme with only this xy added, so it will apply for any theme.
Is that a "bug" or should I know something?
Back to top
View user's profile Send private message 
recobayu


Joined: 15 Sep 2010
Posts: 274
Location: indonesia

PostPosted: Tue 11 Jul 2017, 23:34    Post subject:  

Hi All, how to make an entry with only one character and automatically change everytime we write it? I have do something like this:
Code:
#!/bin/sh
export a='
<hbox>
 <entry max-length="1">
  <variable>e1</variable>
  <action>echo e1: $e1</action>
  <action>grabfocus:e2</action>
 </entry>
 <entry>
  <variable>e2</variable>
  <action>echo e2: $e2</action>
  <action>grabfocus:e1</action>
 </entry>
</hbox>'

gtkdialog -p a

If I only use one entry (e1) and refresh e1, it also does not do.
My example output like this:
Code:
e1: d
e2: s
e1:
e1: d
e2:
e2: f
e1:
e1: g
e2:
e2: d
e1:
e1: s
Back to top
View user's profile Send private message 
MochiMoppel


Joined: 26 Jan 2011
Posts: 1351
Location: Japan

PostPosted: Wed 12 Jul 2017, 00:27    Post subject:  

Not clear what you are trying to achieve. To stop output of empty variable you could do something like this:
Code:
export a='
<hbox>
<entry max-length="1">
<variable>e1</variable>
<action>[[ $e1 ]] && echo e1: $e1</action>
<action>grabfocus:e2</action>
</entry>
<entry>
<variable>e2</variable>
<action>[[ $e2 ]] && echo e2: $e2</action>
<action>grabfocus:e1</action>
</entry>
</hbox>'
gtkdialog -p a

If additionally you want to prevent e1 from changing focus to e2 while e1 is empty (= prevent empty entry boxes) you will have to add a condition to the grabfocus function.
Back to top
View user's profile Send private message 
recobayu


Joined: 15 Sep 2010
Posts: 274
Location: indonesia

PostPosted: Wed 12 Jul 2017, 03:05    Post subject:  

Actually, I want to make release event of winkey shortcut work for menu and win+"other key" for another shortcut in jwm. So I call my gtkdialog script when win key being pressed. Then if i do not click any alphabet, my menu show. If I press "E" in my keyboard, then rox filer show. Something like that.

But I realize that, if I use this methode, i can not use F1, arrow, alt, ctrl, and so in entry.
:'(

So I let joewing to add release event in shortcut alone.
Back to top
View user's profile Send private message 
recobayu


Joined: 15 Sep 2010
Posts: 274
Location: indonesia

PostPosted: Tue 25 Jul 2017, 02:46    Post subject:  

How to move from entry to the button on left or right by arrow key (not tab key)?

Code:
#!/bin/sh
echo '
<hbox>
  <button>
    <label>left</label>
  </button>
 
  <entry has-focus="true">
  </entry>
 
  <button>
    <label>right</label>
  </button>
 
</hbox>'|gtkdialog -s


Thank you
Back to top
View user's profile Send private message 
MochiMoppel


Joined: 26 Jan 2011
Posts: 1351
Location: Japan

PostPosted: Tue 25 Jul 2017, 03:09    Post subject:  

Possible, but this would conflict with the built-in and expected behavior of the arrow keys, i.e. moving the text cursor within the entry box. Are you sure you want to do this?
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 78 of 81 [1213 Posts]   Goto page: Previous 1, 2, 3, ..., 76, 77, 78, 79, 80, 81 Next
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.0675s ][ Queries: 14 (0.0029s) ][ GZIP on ]