Here it it recognized as a bash script and executed when clicked. Check your mime settings and your svg question 1 week ago.smokey01 wrote: the file displays as a glade file in Rox instead of a script
GtkDialog - tips
- MochiMoppel
- Posts: 2084
- Joined: Wed 26 Jan 2011, 09:06
- Location: Japan
Is there a script or program that will convert a glade file, saved as libglade or gtkbuilder, to regular gtkdialog code as discussed throughout this thread?
From something like this:
To something thik this:
I would like to create GUI's in glade then run them inside normal bash scripts. It's possible using gtkdialog providing it's been built with glade support and glade is saved as libglade. Unfortunately libglade is deprecated.
The results are not identical but it provides an example of what I'm trying to achieve.
From something like this:
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<requires lib="gtk+" version="2.24"/>
<!-- interface-naming-policy project-wide -->
<object class="GtkWindow" id="window1">
<property name="can_focus">False</property>
<child>
<placeholder/>
</child>
</object>
</interface>
Code: Select all
#!/bin/sh
[ -z $GTKDIALOG ] && GTKDIALOG=gtkdialog
MAIN_DIALOG='
<window>
<vbox>
<frame Description>
<text>
<label>This is an example window.</label>
</text>
</frame>
<hbox>
<button ok></button>
<button cancel></button>
</hbox>
</vbox>
</window>
'
export MAIN_DIALOG
case $1 in
-d | --dump) echo "$MAIN_DIALOG" ;;
*) $GTKDIALOG --program=MAIN_DIALOG ;;
esac
The results are not identical but it provides an example of what I'm trying to achieve.
- Moose On The Loose
- Posts: 965
- Joined: Thu 24 Feb 2011, 14:54
Perhaps this is a better way:MochiMoppel wrote:@smokey01. Not really a Gtkdialog issue. See here.
The long # string is there to prevent the file to be mistakenly recognized as a svg image.
Code: Select all
THING="SVG"
echo "<$THING" '.... more stuff ....
- MochiMoppel
- Posts: 2084
- Joined: Wed 26 Jan 2011, 09:06
- Location: Japan
Moose On The Loose wrote:Perhaps this is a better way:It is based on something commonly done for making html tags in javascriptCode: Select all
THING="SVG" echo "<$THING" '.... more stuff ....
Moose On The Loose wrote:Perhaps this is a better way:MochiMoppel wrote:@smokey01. Not really a Gtkdialog issue. See here.
The long # string is there to prevent the file to be mistakenly recognized as a svg image.
It is based on something commonly done for making html tags in javascriptCode: Select all
THING="SVG" echo "<$THING" '.... more stuff ....
Yea that worked
Code: Select all
#!/bin/sh
SVG=svg
svg_buttons () {
echo '<'$SVG' width="100%" height="100%" viewBox="0 0 60 20">
<defs>
<linearGradient id="button_surface" gradientUnits="objectBoundingBox"
x1="1" x2="1" y1="0" y2="1">
<stop stop-color="#D26F6F" offset="0"/>
<stop stop-color="#FF0000" offset="0.67"/>
</linearGradient>
<linearGradient id="virtual_light" gradientUnits="objectBoundingBox"
x1="0" x2="0" y1="0" y2="1">
<stop stop-color="#EEEEEE" offset="0" stop-opacity="0.8"/>
<stop stop-color="#EEEEEE" offset="0.4" stop-opacity="0"/>
</linearGradient>
</defs>
<!-- button content -->
<rect x="0" y="0" width="60" height="20" fill="url(#button_surface)" stroke="#570B0B"/>
<text x="17" y="15" fill="white"
font-family="Tahoma" font-size="14" font-weight="bold">
Kill
</text>
<!-- vitual lighting effect -->
<rect x="2" y="2" width="56" height="16" fill="url(#virtual_light)" stroke="#FFFFFF" stroke-opacity="0.4"/>
</svg>
'>/tmp/killk.svg
}
export -f svg_buttons
svg_buttons
defaultimageviewer /tmp/killk.svg
[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]
[img]https://dl.dropboxusercontent.com/s/ahfade8q4def1lq/signbot.gif[/img]
- MochiMoppel
- Posts: 2084
- Joined: Wed 26 Jan 2011, 09:06
- Location: Japan
Sure it works, but there is no need for a variable:Geoffrey wrote:Yea that worked
Code: Select all
echo '<''svg width="100%" ....
The main post is updated with this new knowledge about manual sorting of a list. The solution is provided by MochiMoppel.
My question is if my explanation is understandable? (and did I get it right, Mochi?)
I have uploaded a development release of pMusic using this new approach to move tracks in the playqueue. The code is seen in /usr/local/pmusic/gui_playlist
_______________________________________________________
Drag'n drop
Gtkdialog has limited support for drag'n drop. This is what we've learnt by now:
>> Drag from file browser (rox) to <entry> widget.
>> Move items in list by drag'n drop.
Using the reorderable option in the <tree> has some strange behavior. For example will items get swallowed when moving them onto another item. The workaround restores the list if the user moves item onto, instead of in between 2 other items... This code by MochiMoppel is a result of 2 cracked nuts:
- When moving an item in the list the $PTR_Y variable returns 0. This gives us the info that the user is moving rather than clicking.
- When a signal is defined in the <tree>, user defined actions are processed before the built-in actions. The trick is to activate the invisible button, and run the user-defined actions there - after the builtin save-command
For the record, we keep the old solution for this task...
My question is if my explanation is understandable? (and did I get it right, Mochi?)
I have uploaded a development release of pMusic using this new approach to move tracks in the playqueue. The code is seen in /usr/local/pmusic/gui_playlist
_______________________________________________________
Drag'n drop
Gtkdialog has limited support for drag'n drop. This is what we've learnt by now:
>> Drag from file browser (rox) to <entry> widget.
Code: Select all
export test="
<entry accept=\"directory\" width-request=\"300\">
<default>Drag a directory from Rox</default>
</entry>"
gtkdialog -p test
>> Move items in list by drag'n drop.
Using the reorderable option in the <tree> has some strange behavior. For example will items get swallowed when moving them onto another item. The workaround restores the list if the user moves item onto, instead of in between 2 other items... This code by MochiMoppel is a result of 2 cracked nuts:
- When moving an item in the list the $PTR_Y variable returns 0. This gives us the info that the user is moving rather than clicking.
- When a signal is defined in the <tree>, user defined actions are processed before the built-in actions. The trick is to activate the invisible button, and run the user-defined actions there - after the builtin save-command
Code: Select all
#!/bin/bash
#Code below line 15 (break:) is activated when user move item in list
ls -1 /usr/share/backgrounds > /tmp/test
do_something () { Xdialog -info "Do something with\n$TREE" x 2000 ;} ; export -f do_something
echo '
<vbox>
<tree headers-clickable="false" reorderable="true">
<label>Backgrounds</label>
<input>cat /tmp/test</input>
<output file>/tmp/test</output>
<variable>TREE</variable>
<height>300</height><width>200</width>
<action>do_something &</action>
<action signal="button-release-event" condition="command_is_true( echo $PTR_Y )">break:</action>
<action signal="button-release-event">save:TREE</action>
<action signal="button-release-event">activate:BTN_SAVE</action>
</tree>
<button visible="false">
<variable>BTN_SAVE</variable>
<action>cp /tmp/test /tmp/testbackup</action>
<action>save:TREE</action>
<action condition="command_is_true([[ $(wc </tmp/test) != $(wc </tmp/testbackup) ]] && sed \"s/^|*//\" /tmp/testbackup > /tmp/test && echo true )">refresh:TREE</action>
</button>
</vbox>' | gtkdialog -s
Code: Select all
#!/bin/sh
move (){
PRESS_EVENT=$(cat /tmp/PRESS_EVENT)
[[ $PRESS_EVENT && $TREE ]] || exit #exit if at least one of the 2 values is empty
[[ $PRESS_EVENT == $TREE ]] && exit #exit if both are equal (=single or double click)
sed -i "/$PRESS_EVENT/d; /$TREE/ i\\$PRESS_EVENT" /tmp/list #remove PRESS_EVENT, then insert item PRESS_EVENT before item $TREE
}
export -f move
ls -1 /usr/share/backgrounds > /tmp/list
export test="
<tree rules_hint=\"true\" hover-selection=\"true\" tooltip-text=\"Drag'n drop items to move them in list\">
<label>Backgrounds</label>
<input>cat /tmp/list</input>
<variable>TREE</variable>
<height>300</height><width>200</width>
<action signal=\"button-press-event\">echo \$TREE > /tmp/PRESS_EVENT</action>
<action signal=\"button-release-event\">move</action>
<action signal=\"button-release-event\">refresh:TREE</action>
</tree>"
gtkdialog -p test
- MochiMoppel
- Posts: 2084
- Joined: Wed 26 Jan 2011, 09:06
- Location: Japan
No answers - is that good or bad?zigbert wrote:My question is if my explanation is understandable?
Well....almostdid I get it right, Mochi?
Before I explain allow me one comment on the above "Drag from file browser" example: The accept="directory" attribute makes no sense without a corresponding (and deprecated) "fileselect" function. Might give the false impression that the example accepts only directories.
Return value of 0 is possible with clicking, so a value of 0 is not 100% proof for moving. For the code I use the opposite. I check if return value is not 0, and that MUST be a click, can't be a move.- When moving an item in the list the $PTR_Y variable returns 0. This gives us the info that the user is moving rather than clicking.
I propose:
"A return value >0 gives us the info that the user is clicking rather than moving."
We probably mean the same thing but I wouldn't understand your explanation if I wouldn't have written the code myself. Very difficult to put this complex process into 2 sentences and I recommend that you add a link to the drag&drop&go thread, just to keep Tips & Tricks short and provide a place for follow-up questions/explanations.- When a signal is defined in the <tree>, user defined actions are processed before the built-in actions. The trick is to activate the invisible button, and run the user-defined actions there - after the builtin save-command
Terminology is also a problem. AFAIK there are no established terms.
I'll give it a try and list the actions in the order of execution:
- custom actions (actions within <action> tags for non-default signals)
- default actions (actions within <action> tags for the default signal - if defined)
- built-in actions (actions performed automatically, no <action> tags required)
In this sense the reordering when releasing the mouse button is a built-in action, but the save action is not.
The whole process is interesting and full of surprises. Fascinating that the trick works when activating an invisible button but not when activating an invisible menuitem (which I prefer and use a lot in MMview). If it's not too boring I can post a mock-up of the tree reordering code which will show step-by-step what gtkdialog does. You would see immediately why the first save command saves the old item order and not the new one.
Back to the description. My draft proposal:
"- Normally all <action>s defined for a widget are processed before built-in actions (actions that don't require an <action> tag). The trick is to process a user defined <action> after a built-in action. An invisible button allows the code to run a user defined save action after a built-in reorder action."
Of course - fixedMochiMoppel wrote:Before I explain allow me one comment on the above "Drag from file browser" example: The accept="directory" attribute makes no sense without a corresponding (and deprecated) "fileselect" function. Might give the false impression that the example accepts only directories.
MochiMoppel wrote:I propose:
"A return value >0 gives us the info that the user is clicking rather than moving."
Thank you, I have updated...MochiMoppel wrote:Back to the description. My draft proposal:
"- Normally all <action>s defined for a widget are processed before built-in actions (actions that don't require an <action> tag). The trick is to process a user defined <action> after a built-in action. An invisible button allows the code to run a user defined save action after a built-in reorder action."
But, I removed (actions that don't require an <action> tag), as it didn't gave me any meaning without the deeper explanation. I think built-in actions is understandable just as is...
A added a link to the drag an drop thread
Sigmund
- BarryK
- Puppy Master
- Posts: 9392
- Joined: Mon 09 May 2005, 09:23
- Location: Perth, Western Australia
- Contact:
Guys,
Someone gave me the answer to this question sometime ago, but I can't recall the answer, nor who gave it
When a horizontal row of buttons is created, they default to pack together on the right side.
But, if you want the left-most one or more buttons to move over to the extreme left of the window (leaving the others on the right side), how to do that?
My old way was to pack spaces between, but there is a more exact method.
Someone gave me the answer to this question sometime ago, but I can't recall the answer, nor who gave it
When a horizontal row of buttons is created, they default to pack together on the right side.
But, if you want the left-most one or more buttons to move over to the extreme left of the window (leaving the others on the right side), how to do that?
My old way was to pack spaces between, but there is a more exact method.
[url]https://bkhome.org/news/[/url]
- MochiMoppel
- Posts: 2084
- Joined: Wed 26 Jan 2011, 09:06
- Location: Japan
What do you mean by "more exact". Zigbert describes a solution on page 1 of this thread. Not exact enough ?BarryK wrote:My old way was to pack spaces between, but there is a more exact method.
Personally I find zigbert's example a bit "over-engineered". This should give a similar result, with evenly proportioned buttons when resizing the window:zigbert wrote:Dynamic: (align one button to the left, another to the right)Code: Select all
<hbox space-expand="false" space-fill="false"> <button yes></button> <hbox space-expand="true" space-fill="true"><text><label>""</label></text></hbox> <button no></button> </hbox>
Code: Select all
<hbox space-expand="true" space-fill="true">
<button yes></button>
<text label=""></text>
<button no></button>
</hbox>
- BarryK
- Puppy Master
- Posts: 9392
- Joined: Mon 09 May 2005, 09:23
- Location: Perth, Western Australia
- Contact:
MochiMoppel,
Thanks for that!
Trying exactly as per zigbert's example, there is a problem. I placed the text label after the first three items, but those first three do not pack together at the left side.
They are spread out, as shown in attached photo:
Thanks for that!
Trying exactly as per zigbert's example, there is a problem. I placed the text label after the first three items, but those first three do not pack together at the left side.
They are spread out, as shown in attached photo:
- Attachments
-
- sns.png
- (14.76 KiB) Downloaded 279 times
Last edited by BarryK on Wed 23 Aug 2017, 23:53, edited 1 time in total.
[url]https://bkhome.org/news/[/url]
Let's give credit to Thunor who was first
Code: Select all
A text widget that has space-expand and space-fill set to true can be used as a spacer to push neighbouring widgets in certain directions.
Here the spacer text is "[]" so you can see it -- drag the window out and watch the button.
#!/bin/sh
GTKDIALOG=gtkdialog
Spacer="[]"
MAIN_DIALOG='
<window title="Spacer Test" window-position="1">
<vbox>
<hbox>
<button space-expand="false" space-fill="false">
<label>This button will stay put</label>
<input file stock="gtk-about"></input>
</button>
<text space-expand="true" space-fill="true">
<label>"'$Spacer'"</label>
</text>
</hbox>
</vbox>
</window>
'
export MAIN_DIALOG
case $1 in
-d | --dump) echo "$MAIN_DIALOG" ;;
*) $GTKDIALOG --program=MAIN_DIALOG ;;
esac
Regards,
Thunor
__________________________________________
- BarryK
- Puppy Master
- Posts: 9392
- Joined: Mon 09 May 2005, 09:23
- Location: Perth, Western Australia
- Contact:
Fixed it. Zigbert's example needed a change:
The first two buttons pack to the left.
But then, why have that nested hbox? No need:
Code: Select all
<hbox>
<button space-expand="false" space-fill="false">...</button>
<button space-expand="false" space-fill="false">...</button>
<hbox space-expand="true" space-fill="true"><text><label>""</label></text></hbox>
<button no></button>
</hbox>
But then, why have that nested hbox? No need:
Code: Select all
<hbox>
<button space-expand="false" space-fill="false">...</button>
<button space-expand="false" space-fill="false">...</button>
<text space-expand="true" space-fill="true"><label>""</label></text>
<button no></button>
</hbox>
[url]https://bkhome.org/news/[/url]
- MochiMoppel
- Posts: 2084
- Joined: Wed 26 Jan 2011, 09:06
- Location: Japan
They do.BarryK wrote:Trying exactly as per zigbert's example, there is a problem. I placed the text label after the first three items, but those first three do not pack together at the left side.
You are mixing up 2 different things. The screenshot indicates that they are glued to the left. That's the purpose of zigbert's example. If you also want the code to prevent their (default) stretching then you would need different code.They are spread out, as shown in attached photo:
And when you get rid of the hbox then there's probably no need for all these space-fills either:But then, why have that nested hbox? No need
Code: Select all
<hbox>
<button space-expand="false"></button>
<button space-expand="false"></button>
<text space-expand="true" label=""></text>
<button no></button>
</hbox>
Is it possible to give the <chooser> a predefined name. The path is defined with the <default> option, but I can't find a way to set the default saving filename.
Code: Select all
<chooser action="1" create-folders="true">
<variable>SAVEFILE</variable>
<default>'$(dirname "$MYFILE")'</default>
</chooser>
- Attachments
-
- Screenshot.jpg
- (24.61 KiB) Downloaded 194 times
- MochiMoppel
- Posts: 2084
- Joined: Wed 26 Jan 2011, 09:06
- Location: Japan