Learning gtkDialog (pmenu project)

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Message
Author
afishe2000
Posts: 37
Joined: Fri 29 Jan 2010, 16:09

Learning gtkDialog (pmenu project)

#1 Post by afishe2000 »

Continuing work on an updated pmenu...

pmenu-3.0.0.pet

The pet for 3.0.0 REQUIRES /usr/bin/switch2 from gtk-theme-switch-i386.pet.

Image

Using the image preview technique developed by zigbert you can now see the icons for each menu item.
(Page 28 of the Gtkdialog - tips thread)

To edit the .desktop files the program now calls "defaulttexteditor" instead of "geany" directly.

I've also included the "Exec" path information as suggested by big_bass.

Next update will include a confirmation dialog for the Full, Empty, and Delete Item buttons. I think these are drastic actions and should require a confirmation.

I am also still planning the ability to directly edit the .desktop files from the program in the future, as long as it doesn't slow it down too much.

Also playing around with the idea of sorting the items by category instead of alphabetically...

Jeff
Last edited by afishe2000 on Mon 20 Sep 2010, 08:08, edited 6 times in total.
seaside
Posts: 934
Joined: Thu 12 Apr 2007, 00:19

Re: Learning gtkDialog (pmenu project)

#2 Post by seaside »

afishe2000,

That looks quite nice. You may find that changing the occurrences of "EDITPATH = X" to "EDITPATH=X" (remove the spaces on either side of the "=" sign) would fix your problems.

Cheers,
s
User avatar
01micko
Posts: 8741
Joined: Sat 11 Oct 2008, 13:39
Location: qld
Contact:

#3 Post by 01micko »

Hi afishe2000

I agree with seaside.. when defining a variable don't put spaces either side of the "=". Different story when testing the condition of that variable of course. :wink:

What I normally do, for most actions (depends on complexity) inside the gtkdialog, is define a function before the gtkdialog.

Here is an extremely simple example I made some time ago:

Code: Select all

#!/bin/bash
#funtion to find and move clock skin
function INSTALL(){
	
	CLOCK_PATH=`grep '*.png' $CLOCKSKIN | cut -d '/' -f2`
	mv $CLOCKSKIN /usr/local/pwidgets/widgets/clock_skins/$CLOCK_PATH 2>/dev/null
}
export -f INSTALL

export CLOCK="
<window title=\"Clockskin Installer\">
 <vbox>
  <text><label>\"Drag a clockskin to the box\"</label></text>
   <entry>
    <variable>CLOCKSKIN</variable>
    <action>echo $CLOCKSKIN</action>
   </entry>
  <hbox>
   <button>
    <input file stock=\"gtk-ok\"></input>
    <label>\"OK\"</label>
    <action>INSTALL</action>
    <action>EXIT:ok</action>
   </button>
  </hbox>
 </vbox>
</window>
"
gtkdialog3 -p CLOCK
unset CLOCK
In this way, much more complex actions can be used.

Cheers
Puppy Linux Blog - contact me for access
User avatar
jemimah
Posts: 4307
Joined: Wed 26 Aug 2009, 19:56
Location: Tampa, FL
Contact:

#4 Post by jemimah »

Environment variables do not seem to work for some reason - at least I've never been able to get them to work.

Here is the lazy solution: disable the edit button for removed items.

Also, checkout LxShortcut for editing .desktop files. http://sourceforge.net/projects/lxde/files/

Image

Code: Select all

#!/bin/bash 
#created trapster March 2009 for Puppy 4.00, GPL 
#fix by Jemimah to not require GUI reloads april 2010 
#edited by afishe200 to format side by side and include simple editing jul 2010 

#finds all items currently listed in the menu... 
/usr/local/pmenu/current_list.sh #writes to /usr/local/pmenu/current_list.txt 

#finds all items removed from the menu 
/usr/local/pmenu/removed_list.sh #writes to /usr/local/pmenu/removed 

export PMENU=" 
<window title=\"Menu and Item Editor\" icon-name=\"gtk-about\"> 
      <hbox> 
         <frame Current Menu Items> 
            <table> 
		<height>300</height>
		<width>300</width>
               <variable>TREE1</variable> 
               <input>cat /usr/local/pmenu/current_list.txt</input> 
               <action type=\"enable\">REMOVE1</action> 
               <action type=\"disable\">ADD1</action> 
               <action type=\"enable\">EDIT1</action> 
               <action>Clear:TREE2</action> 
               <action>Refresh:TREE2</action> 

            </table> 
         </frame> 
         <vbox> 
            <button sensitive=\"false\"> 
               <label> Remove </label> 
               <variable>REMOVE1</variable> 
               <action>/usr/local/pmenu/remove_item.sh \$TREE1</action> 
               <action>/usr/local/pmenu/current_list.sh</action> 
               <action>/usr/local/pmenu/removed_list.sh</action> 
               <action>Clear:TREE1</action> 
               <action>Refresh:TREE1</action> 
               <action>Clear:TREE2</action> 
               <action>Refresh:TREE2</action> 
            </button> 
          
            <button sensitive=\"false\"> 
               <label> Add </label> 
               <variable>ADD1</variable> 
               <action>/usr/local/pmenu/add_item.sh \$TREE2</action> 
               <action>/usr/local/pmenu/current_list.sh</action> 
               <action>/usr/local/pmenu/removed_list.sh</action> 
               <action>Clear:TREE1</action> 
               <action>Refresh:TREE1</action> 
               <action>Clear:TREE2</action> 
               <action>Refresh:TREE2</action> 
            </button> 
            <button sensitive=\"false\"> 
               <label> Edit </label> 
               <variable>EDIT1</variable> 
               <action>lxshortcut -i /usr/share/applications/\$TREE1 -o /usr/share/applications/\$TREE1</action> 
            </button> 
            <button> 
               <label>Refresh Menu</label> 
               <action>fixmenus</action> 
            </button> 
         </vbox> 
         <frame Removed Menu Items> 
            <table> 
		<width>300</width>
               <variable>TREE2</variable> 
               <variable>EDIT0</variable> 
               <input>cat /usr/local/pmenu/removed_list.txt</input> 
               <action type=\"disable\">REMOVE1</action> 
               <action type=\"enable\">ADD1</action> 
               <action type=\"disable\">EDIT1</action> 
               <action>Clear:TREE1</action> 
               <action>Refresh:TREE1</action> 
            </table> 
         </frame> 
      </hbox> 

</window> 
" 

RETPARAMS="`gtkdialog3 --program=PMENU`" 

#echo "$RETPARAMS" 
exit 

eval "$RETPARAMS" 

###END### 
afishe2000
Posts: 37
Joined: Fri 29 Jan 2010, 16:09

#5 Post by afishe2000 »

Thanks to all,

That's exactly it. I've been beating my head against the wall trying to get environment variables to work, and they just don't...

Doing all this work on my EeePC 901 running puppeee, thanks for such a great distribution.

Jeff
User avatar
jemimah
Posts: 4307
Joined: Wed 26 Aug 2009, 19:56
Location: Tampa, FL
Contact:

#6 Post by jemimah »

Cool. If you make any further improvements let me know as I'm going to put the new version into Puppeee.

If you're looking for a second project, it would be good to combine the Xorg Scaling Wizard, and the Xorg Panning Wizard into one wizard as discussed here: http://pupweb.org/cgi-bin/yabb2/YaBB.pl?num=1276937129. There's a lot of potential for usability improvements.
afishe2000
Posts: 37
Joined: Fri 29 Jan 2010, 16:09

Creating global variables in gtkdialog (pass through a file)

#7 Post by afishe2000 »

In the middle of re-reading the gtkdialog-tips thread.

In gtkdialog global variables are really constants.

The only way to pass variables is through a file.

Example:

Code: Select all

#!/bin/sh 

add() { 
  N=$(cat /tmp/number) 
  let N=N+1 
  echo $N 
  echo $N >/tmp/number 
} 

export -f add 
echo 0>/tmp/number 

export MAIN_DIALOG=' 
<vbox width-request="160"> 
	<text visible="true"><variable>TEXT</variable>
		<input>add</input></text> 
	<button>
		<label>Reset</label>
   <	action>refresh:TEXT</action> 
	</button>
	<button>
		<label>Reset</label> 
		<action>echo -1>/tmp/number</action>
		<action>refresh:TEXT</action>
	</button>  
	<button cancel></button> 
</vbox> 
' 

gtkdialog3 -c -p MAIN_DIALOG 
unset -f add 
unset MAIN_DIALOG 

Lots to learn...

Jeff
afishe2000
Posts: 37
Joined: Fri 29 Jan 2010, 16:09

#8 Post by afishe2000 »

Basic problem solved, you can now edit from either table.

I'll continue to work with it. I'd like to have a integrated editor.

I would also like the right table deselected if the left is selected and vice versa.

Odd thing with the IF statement:
- Tried \$switch_Position instead of \$(cat /tmp/switch) - didn't work
- Tried [ \$(cat /tmp/switch) ] instead of [ \$(cat /tmp/switch) = true ] - didn't work

Still lots to learn...

Code: Select all

#!/bin/bash 
#created trapster March 2009 for Puppy 4.00, GPL 
#fix by Jemimah to not require GUI reloads april 2010 
#edited by afishe200 to format side by side and include simple editing jul 2010 

#finds all items currently listed in the menu... 
/usr/local/pmenu/current_list.sh #writes to /usr/local/pmenu/current_list.txt 

#finds all items removed from the menu 
/usr/local/pmenu/removed_list.sh #writes to /usr/local/pmenu/removed 

switch_Position() { 
  N=$(cat /tmp/switch)  
  echo $N 
} 
switch_On() {
	echo true >/tmp/switch
}
switch_Off() {
	echo false >/tmp/switch
}
export -f switch_Position
export -f switch_On
export -f switch_Off

export PMENU="
<window title=\"Puppy Menu and Item Editor\" icon-name=\"gtk-about\"> 
      <hbox height-request=\"450\"> 
         <frame Current Menu Items                                             > 
            <table> 
               <variable>TREE_0</variable>
               <input>cat /usr/local/pmenu/current_list.txt</input>
               <action>switch_On</action>               
               <action type=\"enable\">REMOVE_BUTTON</action> 
               <action type=\"disable\">ADD_BUTTON</action> 
               <action type=\"enable\">EDIT_BUTTON</action>
            </table>
         </frame>
         <vbox>
            <hbox height-request=\"20\">
              <text visible = \"false\">
              </text>
            </hbox> 
            <button sensitive=\"false\"> 
               <label> Remove </label> 
               <variable>REMOVE_BUTTON</variable> 
               <action>/usr/local/pmenu/remove_item.sh \$TREE_0</action> 
               <action>/usr/local/pmenu/current_list.sh</action> 
               <action>/usr/local/pmenu/removed_list.sh</action> 
               <action>Clear:TREE_0</action> 
               <action>Refresh:TREE_0</action> 
               <action>Clear:TREE_1</action> 
               <action>Refresh:TREE_1</action> 
            </button> 
          
            <button sensitive=\"false\"> 
               <label> Add </label> 
               <variable>ADD_BUTTON</variable> 
               <action>/usr/local/pmenu/add_item.sh \$TREE_1</action> 
               <action>/usr/local/pmenu/current_list.sh</action> 
               <action>/usr/local/pmenu/removed_list.sh</action> 
               <action>Clear:TREE_0</action> 
               <action>Refresh:TREE_0</action> 
               <action>Clear:TREE_1</action> 
               <action>Refresh:TREE_1</action> 
            </button> 
            <hbox height-request=\"20\">
              <text visible = \"false\">
              </text>
            </hbox> 
            <button sensitive=\"false\"> 
               <label> Edit </label> 
               <variable>EDIT_BUTTON</variable> 
               <action>if [ \$(cat /tmp/switch) = true ];	then geany /usr/share/applications/\$TREE_0; else geany /usr/local/pmenu/removed/\$TREE_1; fi</action>
            </button>
            <hbox height-request=\"20\">
              <text visible = \"false\">
              </text>
            </hbox>  
            <button> 
               <label>Refresh Menu</label> 
               <action>fixmenus</action> 
            </button>   
         </vbox> 
         <frame Removed Menu Items                                             > 
            <table> 
               <variable>TREE_1</variable> 
               <input>cat /usr/local/pmenu/removed_list.txt</input>
               <action>switch_Off</action>             
               <action type=\"disable\">REMOVE_BUTTON</action> 
               <action type=\"enable\">ADD_BUTTON</action> 
               <action type=\"enable\">EDIT_BUTTON</action> 
            </table> 
         </frame> 
      </hbox> 
</window> 
"

gtkdialog3 -c --program=PMENU

unset PMENU
unset -f switch_On
unset -f switch_Off
unset -f switch_Position
rm /tmp/switch
afishe2000
Posts: 37
Joined: Fri 29 Jan 2010, 16:09

#9 Post by afishe2000 »

Continuing work and adding extra capabilities.

I've edited the first post to include a current screen shot and a download to the current program.

Jeff
User avatar
jemimah
Posts: 4307
Joined: Wed 26 Aug 2009, 19:56
Location: Tampa, FL
Contact:

#10 Post by jemimah »

Personally, I think the startup item editor should be a separate program from pmenu. Otherwise I'm confused what to call it on the menu.

Looking good though. It would be great to be able to use the program to add new startup items.
afishe2000
Posts: 37
Joined: Fri 29 Jan 2010, 16:09

#11 Post by afishe2000 »

jemimah,

Easy to do, was brainstorming but separating makes much more sense.

I have a list of things that I modify to make puppeee look and work like I want it to. I'm just programming to make it easier to make all those modifications.

I'm always looking for hints and FAQs to make my computers work better for me.

Thanks again,

Jeff
Modifications.txt

- You can edit /usr/share/icewm/toolbar to remove programs from the toolbar
//
prog "Eee-Control" netbook-pc eee-control
prog "Rover SpeedLaunch (Alt-Space)" emblem-system rover_run
//

- You can delete programs from /root/Startup that you don't want in the notification area
//
delete freememapplet_tray
delete network_tray
delete traytemp
delete zbluetooth-applet (NO BLUETOOTH ON MY 901)
//

- You can modify /etc/xdg/templates/_root_.icewm_menu to create a new menu system
- See /root/.icewm/menu for examples on how to add programs
//
prog "Chrome" "/opt/google/chrome/product_logo_48.png" /opt/google/chrome/google-chrome %U

separator

menu "Programs" x24 {

(OLD MENU GOES IN HERE...)

}
separator

prog "Lock" "lock48.png" /usr/local/apps/Xlock/AppRun
prog "Shutdown" "shutdown24.png" shutdown-gui
//

- You can modify /root/.icewm/preferences
--To remove Settings Menu change from 1 to 0
//
ShowSettingsMenu=0 # 0/1
//

--To change time format, reference (http://linux.die.net/man/3/strftime)
//
# Clock Time format (strftime format string)
TimeFormat="%e %b %y - %H:%M:%S"
//

--To change the MENU font
//
MenuFontNameXft="sans-serif:size=14"
//

--To change the clock font
//
ClockFontNameXft="sans-serif:size=12"
//

- You can modify application names and icons by editing .desktop files in /usr/share/applications/

- Applications that have been removed from the menu can be found in /usr/local/pmenu/removed/
afishe2000
Posts: 37
Joined: Fri 29 Jan 2010, 16:09

#12 Post by afishe2000 »

Program is moving along nicely...

I updated the first post with a new screen shot and a .pet file of the work done so far.

Currently when you click on a Menu Item it brings up the data from the .desktop file.

I've read just about every google return for gtkdialog pixmap, the gtkdialog-tips like 10 times, and tried everything under the sun but just can't get the icons file to dynamically load into a pixmap with the rest of the .desktop data...

Any help or suggestions would be very much appreciated.

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

#13 Post by seaside »

afishe2000 wrote:Program is moving along nicely...

I've read just about every google return for gtkdialog pixmap, the gtkdialog-tips like 10 times, and tried everything under the sun but just can't get the icons file to dynamically load into a pixmap with the rest of the .desktop data...

Any help or suggestions would be very much appreciated.

Thanks,
afishe2000,

Are you using "table"? Somewhere in the back of my mind is the idea that "tree" is necessary for pixmaps.

Hope that's it.

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

#14 Post by seaside »

afishe2000,

I now see that you were not trying to put icons in the table, but next to the "Icon:" entry.

Check here
http://murga-linux.com/puppy/viewtopic. ... 928#437928

Cheers,
s
afishe2000
Posts: 37
Joined: Fri 29 Jan 2010, 16:09

#15 Post by afishe2000 »

Updated the first post to pmenu-2.0.1.

Importing the icons into the edit area is killing me so integrated editing is still not complete.

You can view the .desktop properties and still edit the file using geany.

I've added the ability to run the selected program from within pmenu so you can get a better idea about the program then just the properties.

I also added the ability to delete the .desktop file if you find broken or duplicate links.

Still working on this project slowly...
afishe2000
Posts: 37
Joined: Fri 29 Jan 2010, 16:09

#16 Post by afishe2000 »

Oops,

Updated the first post to pmenu-2.0.2.

Had some of the button icons backwards.
afishe2000
Posts: 37
Joined: Fri 29 Jan 2010, 16:09

Refreshing a pixmap image using a button.

#17 Post by afishe2000 »

As I mentioned, the more I learn the less I seem to know.

I'm using to following code to try to have the pixmap change from speaker on image to the speaker off image by pushing the corresponding button.

The popup button then would open a new dialog and show that same image.

Obviously it isn't working as I'd envisioned.

Everyone has been so helpful, I feel like I just keep running into the wall every time I turn the corner...

Code: Select all


#!/bin/bash

echo 1 >/tmp/file_name

get_Pic() {
	path="/usr/local/lib/X11/mini-icons/"	
	if [ $(cat /tmp/file_name) = 1 ]; then
		file="mini-speaker.xpm";
	else
		file="mini-speaker-off.xpm";
	fi
	echo $path$file
}
export -f get_Pic

export NEW_DIALOG="
  <vbox>
  <pixmap>
   <input file>$(get_Pic)</input>
 </pixmap>
  <text>
		<input>get_Pic</input>
	</text>
	</vbox> 
"

export MAIN_DIALOG="
<vbox>
    <pixmap>
      <variable>PIC</variable>
      <input file>$(get_Pic)</input>
    </pixmap> 
    <text>
      <variable>NAME</variable>
			<input>get_Pic</input>
		</text>     
  <hbox>
    <button>
      <label>Pop-up</label>
      <action type=\"launch\">NEW_DIALOG</action>
    </button>
 		<button>
			<input file>\"/usr/local/lib/X11/mini-icons/mini-speaker.xpm\"</input>
			<action>\"echo 1 >/tmp/file_name\"</action>
			<action>Refresh:NAME</action>
			<action>Refresh:PIC</action>
		</button> 
		<button>
			<input file>\"/usr/local/lib/X11/mini-icons/mini-speaker-off.xpm\"</input>
			<action>\"echo 2 >/tmp/file_name\"</action>
			<action>Refresh:NAME</action>
			<action>Refresh:PIC</action>
		</button>
    <button ok></button>
  </hbox>
</vbox>
"
gtkdialog3 --program=MAIN_DIALOG

unset MAIN_DIALOG
unset NEW_DIALOG
unset get_Pic

rm /tmp/file_name

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

Re: Refreshing a pixmap image using a button.

#18 Post by seaside »

afishe2000 wrote: I'm using to following code to try to have the pixmap change from speaker on image to the speaker off image by pushing the corresponding button.
afishe2000,

You might be able to do something with "flip-flops" (see section 10 of the Gtkdialog Tips below)
http://murga-linux.com/puppy/viewtopic.php?t=38608

Perhaps something where the image is made invisible -
<button visible="false"> and is toggled on and off.

Cheers,
s
big_bass
Posts: 1740
Joined: Mon 13 Aug 2007, 12:21

#19 Post by big_bass »

jemimah
Personally, I think the startup item editor should be a separate program from pmenu. Otherwise I'm confused what to call it on the menu.


well I did a chainsaw hack of afishe2000's pmenu2
I removed only the desktop editor and made it a stand alone app called
desktop_view_edit

so nothing gets touched in pmenu


*I didnt "package" it since I use TXZ format and this way anyone could test it
add the icon and desktop of your choice



@Hey afishe2000 great coding !

Joe
Attachments
desktop_view_edit.tar.gz
(1.75 KiB) Downloaded 542 times
desktop_edit.png
(40.55 KiB) Downloaded 1798 times
User avatar
vovchik
Posts: 1507
Joined: Tue 24 Oct 2006, 00:02
Location: Ukraine

nice job

#20 Post by vovchik »

Dear afishe2000 and big_bass,

Both your little apps are useful. Thanks.

With kind regards,
vovchik
Post Reply