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
mister_electronico
Posts: 969
Joined: Sun 20 Jan 2008, 20:20
Location: Asturias_ España
Contact:

Close to slit my wrists

#1006 Post by mister_electronico »

Sorry to present a code in C on a forum gtkdialog
But it's the only way I've found to increase slightly speed knob.
I think the refresh process images in gtkdialog is a slow process.

A slightly increased considering doing more things anyway as it
was not fast enough steps to increase knob 10 degrees.

Anyway not know how many more will these steps in commercial programs.

I copied the rotary knob Zigbert but only one because all code of him is crazy for me.

Just as I left the code SFR for the coordinates of the mouse.

The program still needs tweaking but it could be a start for me.

I hope the C program can run on other computers, but if not it is very easy to compile.

gcc -o knob knob.c -lm

To run the program first unzip the file and run within the directory KNOB:

# ./knob1

If someone prove it I very grateful to tell your impressions.

All codes are in the compressed archive.

Greating
Attachments
knob.tar.gz
(17.17 KiB) Downloaded 261 times

User avatar
mister_electronico
Posts: 969
Joined: Sun 20 Jan 2008, 20:20
Location: Asturias_ España
Contact:

Thinking of many things forgotten in the simplest

#1007 Post by mister_electronico »

Thinking of many things forgotten in the simplest, thought the refresh time it marked the click of the mouse, but forget the most obvious.

Code: Select all

    <timer visible="false" milliseconds="true" interval="100" sensitive="false">
      <variable>varTIMER</variable>
      <action>get_xy</action>
      <action>refresh:PICTURE</action>
    </timer>
If we change the timer 100 ms to 50 ms is obviously faster.


However this can produce jumps in the knob I do not like it.
What imply that this timer setting depends of the speed of our CPU.


Greetings.

User avatar
mister_electronico
Posts: 969
Joined: Sun 20 Jan 2008, 20:20
Location: Asturias_ España
Contact:

improving knob

#1008 Post by mister_electronico »

This a new version knob, No rebounds in the pointer and softer in slip.

Checking the speed of the program in C from the terminal is found to have enough speed.

Code: Select all

# cd /mnt/home/KNOBC2
# ls
imgini.svg  img.svg  knob  knob1  knob.c
# mkdir /tmp/knob
# cp imgini.svg  /tmp/knob
# cp img.svg  /tmp/knob
# echo "0" > /tmp/knob/DEGR.dat
# 
# time ./knob 78 98

real	0m0.003s
user	0m0.000s
sys	0m0.000s

If it does not work or is jerky at best is convenient in some computers speed up timer in the "knob1" program at the line of code.

Code: Select all

<timer visible="false" milliseconds="true" interval="80" sensitive="false">
Doing more than 80

I hope to be useful and my thanks to all the great people of this forum Puppy.
Attachments
knob2.tar.gz
(6.94 KiB) Downloaded 339 times
Last edited by mister_electronico on Wed 15 Apr 2015, 19:23, edited 1 time in total.

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

#1009 Post by don570 »

I modified a Thunor example to show how to use SVG image buttons
in a toggle button example. A menu heading is disabled in this example.
I'm sure lots of other useful things could be done as well.

You can change the size of the button by fiddling with the height and width tags.

Explanation: I generate two SVG images, then change their names to
true.svg and false.svg .
Note the importance of the variable tgb1. I am using Thunor's notation.

Image

Code: Select all

#!/bin/sh
#example to toggle menu by don570

rm -rf /tmp/TOGGLE_EXAMPLE # start fresh
TMPDIR=/tmp/TOGGLE_EXAMPLE
mkdir -p $TMPDIR
cd $TMPDIR  # create and load images from this folder


for LABEL in 1 2 ;do
[  $LABEL -eq 1 ] && TEXT="Enable Menu"
[  $LABEL -eq 2 ] && TEXT="Disable Menu"



X1=$(echo "$TEXT"|wc -c)  # number of letters
W=$((${X1}*6*95/31))
DISPLACE=$(($W/7))
FILL=white


echo '<svg version="1.1"> 
      <rect
      style="fill:'$FILL';fill-opacity:.7;stroke-width:2;stroke:black;stroke-opacity:1;"
     width='\"$W\"' height="36" rx="10" ry="10" x="1" y="1"/>
           <text style="font-family:DejaVu;font-size:24;fill-opacity:1"
      x='\"$DISPLACE\"'  y="26" >
'$TEXT'
     </text>

</svg>
'> "$TEXT".svg

done

ln -sf "Disable Menu".svg tgb0.svg
ln -sf "Enable Menu".svg tgb1.svg
# create true and false images
cp "Disable Menu".svg true.svg 
cp  "Enable Menu".svg false.svg 

MAIN_DIALOG='
<window title="ToggleButton Advanced" resizable="false" border-width="0">
	<vbox>
		<menubar>
			<menu use-underline="true">
				<menuitem stock-id="gtk-quit" accel-key="0x51" accel-mods="4">
					<action>exit:Quit</action>
				</menuitem>
				<label>"_File"</label>
				<variable>mnuFile</variable>
				<sensitive>false</sensitive>
			</menu>
		</menubar>
		<vbox border-width="20" spacing="20">
			<hbox homogeneous="true">
				<text><label>My Example</label></text>
				<entry>
					<default>true</default>
					<variable>entry</variable>
					<input>echo $tgb1</input>
				</entry>
				
			</hbox>
			<hseparator></hseparator>
			<hbox homogeneous="true">
				<togglebutton>
					<variable>tgb1</variable>					
					<input file>tgb1.svg</input>
					<action>ln -sf $tgb1.svg tgb1.svg</action>
					<action>refresh:tgb1</action>
					<action>refresh:entry</action>					
					<action>if true enable:mnuFile</action>
					<action>if false disable:mnuFile</action>
				</togglebutton>
			</hbox>
		</vbox>
	</vbox>
</window>
'
export MAIN_DIALOG
gtkdialog --program=MAIN_DIALOG



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

design gui

#1010 Post by recobayu »

Hi All,
I want to make a gui about encryption and decription of image. I have wrote my code in python 2.7.6. In puppy linux, we just load our devx.sfs. We also must install Image library from PIL, and I had done. My code has so many def.
Is there possible to implement it into gtkdialog? Could someone give me an example gui of that please (button, image, frame, etc.)?
Thanks.
Recobayu

Edited:
Finally, i know something like gtkdialog. There is Tkinter. I'm sorry for my out of topic here. :oops:
Last edited by recobayu on Fri 24 Apr 2015, 10:03, edited 1 time in total.

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

#1011 Post by don570 »

I would read the code in pupmd5sum for a start

http://www.murga-linux.com/puppy/viewtopic.php?t=84019

______________________________________________________

User avatar
BarryK
Puppy Master
Posts: 9392
Joined: Mon 09 May 2005, 09:23
Location: Perth, Western Australia
Contact:

#1012 Post by BarryK »

I have been playing with these flags in QuickSetup, at first bootup, click on one of them and immediately the QuickSetup window redraws in that language.
It is a friendly start for non-English users.

The first image is how I want it to look. The images packed closely. I used the 'pixmap' tag.
The problem is, I don't know how to associate an action on a mouse-click over one of those images.

The second image shows it done with buttons. Yes, I can get actions, but the rendering is not as densely packed as I want.

Does anyone know how I can pack the icons closely, and associate an action with each one?

Note, I am not sure how well this idea scales. There can be a third column, beyond that it is not practical. But, the translations are only intended to be "gross", for example Spanish for everywhere in the world Spanish or derivative is used.
Attachments
quicksetup-button.png
(85.94 KiB) Downloaded 441 times
quicksetup-pixmap.png
(75.13 KiB) Downloaded 459 times
[url]https://bkhome.org/news/[/url]

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

#1013 Post by SFR »

BarryK wrote:The first image is how I want it to look. The images packed closely. I used the 'pixmap' tag.
The problem is, I don't know how to associate an action on a mouse-click over one of those images.
You need to wrap every pixmap with <eventbox> tags, see this example:
http://www.murga-linux.com/puppy/viewto ... 007#836007

And if you want to pack the images even more closely, you can use <hbox>/<vbox>'s spacing attribute, e.g.: <vbox spacing="0">.

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
BarryK
Puppy Master
Posts: 9392
Joined: Mon 09 May 2005, 09:23
Location: Perth, Western Australia
Contact:

#1014 Post by BarryK »

SFR wrote:
BarryK wrote:The first image is how I want it to look. The images packed closely. I used the 'pixmap' tag.
The problem is, I don't know how to associate an action on a mouse-click over one of those images.
You need to wrap every pixmap with <eventbox> tags, see this example:
http://www.murga-linux.com/puppy/viewto ... 007#836007

And if you want to pack the images even more closely, you can use <hbox>/<vbox>'s spacing attribute, e.g.: <vbox spacing="0">.

Greetings!
SFR,
Thanks very much, yes that works! And thanks to MochiMoppel for figuring out some peculiarities.
[url]https://bkhome.org/news/[/url]

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

#1015 Post by recobayu »

Hi All,
Can we clear everything in vbox and then fill some button inside that (vbox)?
Thanks.
Recobayu

User avatar
Bert
Posts: 1103
Joined: Fri 30 Jun 2006, 20:09

#1016 Post by Bert »

Hi recobayu,

I hope I understood you correctly...is this what you're looking for:

Code: Select all

#!/bin/sh
 export MAIN_DIALOG=' 
<vbox  width-request="200"  height-request="100">
	<button  space-fill="true" space-expand="true">
		<input file stock="gtk-ok"></input>
		<label>LIMUKS</label>
	</button>
</vbox>
'
gtkdialog --program=MAIN_DIALOG
Attachments
vbox-button.png
(4.93 KiB) Downloaded 394 times
[url=http://pupsearch.weebly.com/][img]http://pupsearch.weebly.com/uploads/7/4/6/4/7464374/125791.gif[/img][/url]
[url=https://startpage.com/do/search?q=host%3Awww.murga-linux.com%2F][img]http://i.imgur.com/XJ9Tqc7.png[/img][/url]

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

#1017 Post by recobayu »

:D
Thank you Bert, but my question is something like this:

Code: Select all

#!/bin/sh
export MAIN_DIALOG='
<window>
<hbox>
   <button  space-fill="true" space-expand="true">
      <input file stock="gtk-ok"></input>
      <label>LIMUKS</label>
      <action>echo "delete all inside vbox\nthen change to new \<button\>\nso the label and action of new button change\nto be our new parameter"</action>
   </button>
<vbox  width-request="200"  height-request="100">
   <button  space-fill="true" space-expand="true">
      <input file stock="gtk-ok"></input>
      <label>LIMUKS1</label>
      <variable>l1</variable>
   </button>
   <button  space-fill="true" space-expand="true">
      <input file stock="gtk-ok"></input>
      <label>LIMUKS2</label>
      <variable>l2</variable>
   </button>
   <button  space-fill="true" space-expand="true">
      <input file stock="gtk-ok"></input>
      <label>LIMUKS3</label>
      <variable>l3</variable>
   </button>
</vbox>
</hbox>
</window>
'
gtkdialog --program=MAIN_DIALOG
can we do that?

Edit:
I try this code:

Code: Select all

#!/bin/sh
export main='
<window>
<hbox>
	<vbox>
		<button>
			<label>hide</label>
			<action>hide:vku</action>
		</button>
		<button>
			<label>show</label>
			<action>show:vku</action>
		</button>
		<button>
			<label>delete</label>
			<action function="clear">frameku</action>
		</button>
	</vbox>
	<frame>
	<vbox>
		<button relief="2">
			<label>jwm settings</label>
			<action>echo myscript</action>
		</button>
		<button relief="2">
			<label>gtk change theme</label>
			<action>echo myscript2</action>
		</button>
		<button relief="2">
			<label>font viewer</label>
			<action>echo myscript3</action>
		</button>
		<button relief="2">
			<label>pcur selector</label>
			<action>echo myscript4</action>
		</button>
		<button relief="2">
			<label>LIMUKSku</label>
			<action>show:fku</action>
		</button>
		<variable>vku</variable>
	</vbox>
	<variable>frameku</variable>
	</frame>
</hbox>
</window>
'
gtkdialog -p main
It still just hide and show, but "clear" action still dont want run. :(

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

#1018 Post by MochiMoppel »

I'm also not quite sure what your question is. You can't "clear" a vbox and change the contents on-the-fly, but you can prepare 2 vboxes ant show them alternatively:

Code: Select all

#!/bin/bash
export MAIN_DIALOG=' 
<window> 
<hbox> 
<togglebutton  space-fill="true" space-expand="true"> 
   <input file stock="gtk-ok"></input> 
   <label>LIMUKS</label> 
   <action>echo -e "delete all inside vbox\nthen change to new \<button\>"</action> 
   <action>if true show:vBOX2</action>
   <action>if true hide:vBOX1</action>
   <action>if false hide:vBOX2</action>
   <action>if false show:vBOX1</action>
</togglebutton> 
<vbox  width-request="200"  height-request="100"> 
	<button  space-fill="true" space-expand="true"> 
	   <input file stock="gtk-ok"></input> 
	   <label>LIMUKS1</label> 
	</button> 
	<button  space-fill="true" space-expand="true"> 
	   <input file stock="gtk-ok"></input> 
	   <label>LIMUKS2</label> 
	</button> 
	<button  space-fill="true" space-expand="true"> 
	   <input file stock="gtk-ok"></input> 
	   <label>LIMUKS3</label> 
	</button> 
	<variable>vBOX1</variable>
</vbox>
<vbox  visible="false" width-request="200"  height-request="100"> 
	<button  space-fill="true" space-expand="true"> 
	   <input file stock="gtk-save"></input> 
	   <label>LIMUKS100</label> 
	</button> 
	<button  space-fill="true" space-expand="true"> 
	   <input file stock="gtk-save"></input> 
	   <label>LIMUKS200</label> 
	</button> 
	<variable>vBOX2</variable>
</vbox> 
</hbox> 
</window> 
' 
 gtkdialog --program=MAIN_DIALOG

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

#1019 Post by recobayu »

Thank you Mochi, it's work. But that is just 2 kind of change.
*I'm sorry of my bad english :oops:

My final purpose is I have an Entry, then I change the contain of vbox or frame based on string value of my entry. Like from my post (mukstart) here: http://www.murga-linux.com/puppy/viewtopic.php?p=859024. That use <tree>. I want to change that tobe button.

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

#1020 Post by MochiMoppel »

Using tree looks like a perfect solution. What would you gain from buttons?

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

#1021 Post by recobayu »

With <button relief="2">, the startmenu is like cinnamon's start menu.
This is the screenshoot:
Image

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

#1022 Post by MochiMoppel »

Tree items are "unreliefed" by design and with <tree hover-selection="true"> you get a button-like hover effect.

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

#1023 Post by recobayu »

Yap. It's very great :D
39 mochi.

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

#1024 Post by recobayu »

Alhamdulillah.. Finally, I did it. :D
Here is my code:

Code: Select all

#!/bin/sh
#rm nbMain

cek(){
	if [[ $E == "" ]];then
		echo 0 > nbsubMain
	else
		echo 1 > nbsubMain
	fi
}
export -f cek



export main='
<window>
  <vbox>
	<entry>
		<action>cek</action>
		<action>refresh:nbCari</action>
		<variable>E</variable>
	</entry>
	<notebook show-tabs="false" show-border="false" tab-pos="1">
	<hbox>
	  <vbox>
		<button relief="2">
			<label>All</label>
			<action signal="enter-notify-event">echo "0" >nbMain</action>
			<action signal="focus-in-event">echo "0" >nbMain</action>
			<action signal="focus-in-event">refresh:nbGanti</action>
			<action signal="enter-notify-event">refresh:nbGanti</action>
		</button>
		<button relief="2">
			<label>Destop</label>
			<action signal="enter-notify-event">echo "1" >nbMain</action>
			<action signal="focus-in-event">echo "1" >nbMain</action>
			<action signal="focus-in-event">refresh:nbGanti</action>
			<action signal="enter-notify-event">refresh:nbGanti</action>
		</button>
		<button relief="2">
			<label>System</label>
			<action signal="enter-notify-event">echo "2" >nbMain</action>
			<action signal="focus-in-event">echo "2" >nbMain</action>
			<action signal="focus-in-event">refresh:nbGanti</action>
			<action signal="enter-notify-event">refresh:nbGanti</action>
		</button>
		<button relief="2">
			<label>Setup</label>
			<action signal="enter-notify-event">echo "3" >nbMain</action>
			<action signal="focus-in-event">echo "3" >nbMain</action>
			<action signal="focus-in-event">refresh:nbGanti</action>
			<action signal="enter-notify-event">refresh:nbGanti</action>
		</button>
	  </vbox>
	<notebook show-tabs="false" show-border="false">
		<vbox>
			<button relief="2">
				<label>bersama</label>
			</button>
			<button relief="2">
				<label>ke sini</label>
			</button>
			<button relief="2">
				<label>dan juga</label>
			</button>
			<button relief="2">
				<label>sekarang</label>
			</button>
			<button relief="2">
				<label>lanjut</label>
			</button>
		</vbox>
		<vbox>
			<button relief="2">
				<label>next</label>
			</button>
			<button relief="2">
				<label>okay</label>
			</button>
			<button relief="2">
				<label>ini</label>
			</button>
			<button relief="2">
				<label>juga</label>
			</button>
			<button relief="2">
				<label>next</label>
			</button>
		</vbox>
		<vbox>
			<button relief="2">
				<label>ini</label>
			</button>
			<button relief="2">
				<label>ada satu</label>
			</button>
			<button relief="2">
				<label>lagi</label>
			</button>
			<button relief="2">
				<label>yang nambah</label>
			</button>
			<button relief="2">
				<label>di framenya</label>
			</button>
		</vbox>
		<vbox>
			<button relief="2">
				<label>dan</label>
			</button>
			<button relief="2">
				<label>lagi</label>
			</button>
			<button relief="2">
				<label>orang</label>
			</button>
			<button relief="2">
				<label>beriman</label>
			</button>
			<button relief="2">
				<label>amal salih</label>
			</button>
		</vbox>
		<variable>nbGanti</variable> 
        <input file>nbMain</input> 
	</notebook>
	</hbox>
	<hbox>
		<tree rules-hint="true" headers-visible="false">
			<item>first</item>
			<item>second</item>
			<item>third</item>
			<item>fourth</item>
		</tree>
	</hbox>
	<variable>nbCari</variable> 
	<input file>nbsubMain</input> 
	</notebook>
  </vbox>
</window>'
gtkdialog -p main
We can change on right side by hover button or by keyboard arrow, also we can find something by search on entry. All of that done by "notebook"

Now, how to write a function that can automatically write code <vbox> or <Button> so we are not write every button. But we just call that function. I still learn that. 8)

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

#1025 Post by recobayu »

Hi guys,
I want to ask a question.
If I have a file text.txt that contain a text,
and I have a file icon.txt that contain a path/to/icon.

How to make a tree that column one based on icon.txt and column two based on text.txt?

Post Reply