Page 1 of 8

jwm_tools-0.9 (was jwm_menu_create)

Posted: Tue 16 Aug 2011, 03:05
by technosaurus
Forget about deciding whether to yaf-splash or gtkdialog-splash while creating jwm menus when it happens in <0.2 seconds _AND_ supports subcategory menus using only basic shell commands (no other requirements)

Thanks to amigo for his readline trick (and others) posted here:
http://www.murga-linux.com/puppy/viewtopic.php?t=70238

usage:
#to get a menu without subcategories
jwm_menu_create && jwm -restart

#to get a menu with subcategories
SUBMENU=0 jwm_menu_create && jwm -restart

#to test with another language
LANG=de_JA SUBMENU=0 jwm_menu_create && jwm -restart

see the German translation for a localization template


Changelog:
v0.9
added support for keybindings - if upgrading add this to your JWMRC

Code: Select all

KEYBINDINGS=',Up,up ,Down,down ,Right,right ,Left,left ,h,left ,j,down ,k,up ,l,right ,Return,select ,Escape,escape A,Tab,next A,F4,close A,#,desktop# A,F1,root:3 A,F2,window'
fixed duplicate entries for menus/submenus (I think)
pinstall script is no longer required, now that all fixmenus items are supported
v0.8
fixed bug in menu entries that had desktop files without newline endings
added support for groups
v0.7
bugfixes (some typos and omissions - thanks maxerro)
reworked jwm_param_set to be able to unlimited values
included L18L's gui for wider testing
logical partitions and swap drives no longer show up in drive tray
media cards are now displayed in the drive tray
added the desktop related stuff including backgrounds and new jwm500 formatting
TODO - update jwm_image_view to change background now
v0.6
1. monolithic configuration file that can easily be used by any program to know what the jwm settings are, use them, change them etc... without having to hack at xml files with the shell
2. script to modify the configuration file (up to 9 parameters at a time)
3. jwm_menu_create now uses the config file (at ${HOME}/.jwm/JWMRC) to set almost all parameters (tray, keys and groups not yet implemented - see ${HOME}/.jwm/jwmrc-extra)
4. Submenus and drive icon tray are now enabled/disabled via JWMRC
5. drive tray is now part of the main .jwmrc if enabled
6 removable drives now display a usb icon (devicehandler doesn't however have an unmount option... or other frills )
7. jwm_notify and jwm_image_view now share a temporary jwmrc file (${HOME}/.jwm/jwmrc-tmp)
8. add jwm_param_set to modify jwm settings
usage:
jwm_param_set 'DRIVES="true"'
jwm_menu_create && jwm -restart
#will rebuild the jwmrc and include a drive tray at bottom center
jwm_param_set 'DRIVES=""'
jwm_menu_create && jwm -restart
#will rebuild the jwmrc and exclude the drive tray at bottom center
even with the extra

a gui wrapper can just do this

Code: Select all

. ${HOME}/.jwm/JWMRC 
#bunch of gui crud here
jwm_param_set 'PARAM1="'${VALUE}'"' ... 
jwm_menu_create && jwm -restart
note the double and single quotes in jwm_param_set --- I find it easier to use than backslashing quotes (which are needed becaus some params have spaces or begin with a #)
v 0.5
added jwm_image_view ... usage: jwm_image_view [images]
add drive tray ... usage jwm_create_drives
fixed a bug in jwm_notify -- used by the drive tray
removed static install menu - make it with jwm_install_menu_create
added TODOs
- split out localizations in separat files to be sources
- background setting - already have gtk2jwm for the colors
v 0.4
de,fr,ru,es translations
fixed bug in keybindings
v 0.3
added jwm_notify tools
german localization
install menu-blacklisted BuildingBlock, DEV, DOC and NLS (feel free to modify)
and some minor bugfixes
v 0.2
defaults to $HOME/.jwmrc ... make a backup - it doesn't
bugfixes
install menu (auto-hidden at upper left)
v 0.1
initial release

Todo:
4. Support other window managers - just need a template and basic menu entry layout <<< after v1.0
5. Add it to bashbox. <<<will maintain separately merged with no modifications required

Re: jwm_menu_create

Posted: Tue 16 Aug 2011, 08:36
by BarryK
technosaurus wrote: Todo:
1. What the heck is up the default*.desktop file stubs - do I need a work around or are they misplaced/malformed (they are missing most entries)
technosaurus,
Just tell your program to ignore those.

Xfce needs them. Thunor, I think, uses them, plus maybe other Xfce components.

I added those default*.desktop files when I was getting the Wary Thunor PET (and all other Thunor pkgs) to integrate nicely in Puppy, however I had a feeling that Xfce is abusing XDG (that is, how .desktop files are used) somewhat -- perhaps not, perhaps their understanding of it is more advanced than mine.

Stretching my memory a bit, they use .desktop files for mime handling, the files don't necessarily have to have a menu entry.

Posted: Tue 16 Aug 2011, 08:54
by technosaurus
good to know, I think PCManFM2 uses them too.
I just fixed it by resetting the variables for each file - they don't get processed now and the other missing values don't get copied from the previous- time on my 1.6ghz machine is still 0.15s

I don't know if localizing the desktop file processing will do much now that I have looked into the files more ... many of them have been stripped of localization ... removing it from TODO for now.

Posted: Tue 16 Aug 2011, 11:00
by aragon
technosaurus wrote:...

I don't know if localizing the desktop file processing will do much now that I have looked into the files more ... many of them have been stripped of localization ... removing it from TODO for now.
Please don't. There are much efforts to get puppy-own-apps (gtkdialog) NLS-compatible , so it would be a missed chance, to not include that feature (if you're able to, what you are...).

aragon

Posted: Tue 16 Aug 2011, 12:02
by maxerro
Thank you techno.
My biggest argument against JWM is finally solved as an even more customizable solution. Wow.

Hope this becomes part of the new fixmenus routine (at least for JWM), but even if not - I'll make it a standard in my fixmenus script.
p.s. One more <Separator/> in the Main menu between Setup and Utility to resemble the original.

Posted: Tue 16 Aug 2011, 13:13
by sc0ttman
GREAT stuff... Can't say how much I love having a much faster fixmenus script - particularly as when the locale is non-english, the fixmenus script must retain these settings and is often much slower to finish when non-english locales are being used.
aragon wrote:
technosaurus wrote:...

I don't know if localizing the desktop file processing will do much now that I have looked into the files more ... many of them have been stripped of localization ... removing it from TODO for now.
Please don't. There are much efforts to get puppy-own-apps (gtkdialog) NLS-compatible , so it would be a missed chance, to not include that feature (if you're able to, what you are...).

aragon
At the very least, make sure your script does not BREAK localisation, as it can then be used inside 'fixmenus_on_locale' (by shinobar) to update the menu, AND to convert most of the english to the current language.

I strongly recommend looking at and running 'fixmenus_on_locale' (used by any 'Puppy Desktop-NLS' enabled system) to see that the shutdown entries and categories can still be localised when this script is run as a replacement for 'fixmenus', inside 'fixmenus_on_locale'. I am gonna test this now, and try to make sure it works, and will get back to you.

And perhaps, for portability, the echo -e can, instead of being hardcoded, contain $(cat ~/.jwmrc) or an equivolent... minus the $MENU stuff, of course... Just a thought - as is, this may break font settings and such.

jwm_menu_create

Posted: Tue 16 Aug 2011, 14:54
by L18L
Hi technosaurus,
thank you for this great script. :)
you wrote:...
I don't know if localizing the desktop file processing will do much now that I have looked into the files more ... many of them have been stripped of localization ... removing it from TODO for now.
I have put this on my TODO.

Code: Select all

#!/bin/ash
#SUBMENU=0 #because sometimes its a PITA to have too many in one menu, set to "" for no sub category menus
# i18n by L18L
export TEXTDOMAIN=jwm_menu
export OUTPUT_CHARSET=UTF-8
# that's it plus some $(gettext "bla") or `gettext "bla\`
#                in labels for Name, Comment (added !?) and Categories
It works, see screenshot for German translation (not yet finished).
Produced in drake01.
Just some translations required.

script attached.

Posted: Tue 16 Aug 2011, 15:24
by sc0ttman
I found that the following is required around line 18 or 19 (before the case "$CATS" line)

Code: Select all

	CATS="${CATS%;*}" # sc0ttman, keep just the first (or only) category.. everything before the semi-colon ;
Without this, I do not see .desktop files with have more than one category, for example deadbeef.desktop:

Code: Select all

Categories=AudioVideo;Player
I also fixed a typo that prevented "utility" apps from showing..
Look for a mis-spelled 'utility' word... Around line 30, the line starts like:

Code: Select all

Utility|Viewer|Development|Building|Debugger|IDE|
.....

And I am gonna apply your work L18L, after I have tried putting jwm_menu_create into fixmenus_on_locale ... If can be made to work OK when called from shinobars script, there may be no need to gettext this one.. Is that right?

** EDIT: No, that's not right, it would be best to move the gettext stuff into create_jwm_menu, I guess.

Posted: Tue 16 Aug 2011, 16:07
by sc0ttman
OK, I attached an updated one...

- I have added the i18n stuff, except for $NAME .. see the comments for reasons why..
- I also fixed .desktop files with multiple categories
- I also changed 'export VAR=***' .. cos being strict, that is a bashism.

I attached my updated file...

Please search for #sc0ttman ... All changes marked #sc0ttman, plus there are suggestions in places where things can be done, thoughts from others are needed

One more thought, is gettext slower here, than the 'simple' way of just including a text localised file?

** EDIT: If you have Puppy-desktop installed, you will have the puppy-desktop.mo files for de, ru, nl, fr, es, jp and some others.

If installed, you can use the translations already available in the puppy-desktop.mo files, by simply changing L18Ls code at the top, to the following:

Code: Select all

# i18n by L18L #sc0ttman, stricly no bashisms, using puppy-desktop translations
TEXTDOMAIN=puppy-desktop; export TEXTDOMAIN
OUTPUT_CHARSET=UTF-8; export OUTPUT_CHARSET
I now have all categories localised in the menu, built using this very fast little script :D

The next step is to get the translated .desktop 'Name' fields, if they exist...
So we need to make this work:

Code: Select all

for myLOCALE in C $(echo $LANGUAGE|cut -d':' -f1) $LC_ALL $LANG;do :;done	# ex. 	ja_JP.UTF-8
myLOCALE2=${myLOCALE%_*}	# ex.	ja

.... 

case $LINE in
   Name[${myLOCALE2}]=*) NAME="${LINE#*=}"'' ;; # should use "Name[$LANG]=" if found

Posted: Tue 16 Aug 2011, 18:46
by technosaurus

Code: Select all

for myLOCALE in C $(echo $LANGUAGE|cut -d':' -f1) $LC_ALL $LANG;do :;done   # ex.    ja_JP.UTF-8
could be

Code: Select all

for myLOCALE in C ${LANGUAGE%:*} $LC_ALL $LANG;do :;done   # ex.    ja_JP.UTF-8 
prevents using cut unnecessarily - trying to keep it shell only

also rather than using gettext, we can just use variable names and export the variables from functions

ex:

Code: Select all

<Menu label="'`gettext "Fun"`'" icon="games24.png" height="16">
would be:

Code: Select all

<Menu label="'${Fun}'" icon="games24.png" height="16">
declare variables in the header

Desktop=Desktop ... Fun=Fun

then run
localize_$myLOCALE

the localize functions (must come before its call... probably right after the header)

Code: Select all

localize_ja{
export Desktop=Desktop ... Fun=Fun #except _actually_ translated
}
for languages that have a close relative, a stub could look like

Code: Select all

localize_es(){
localize_${some_close_language}
}
if a translation is not provided for some of the variables, it will just fall back to the defaults

I did this with the pprocess that is in bashbox and it worked ~5x faster

Posted: Tue 16 Aug 2011, 19:30
by Dougal
There are a couple of suboptimal things in the inner loop:
- You only seem to be interested in four of the categories (judging by the case structure), yet test if ${EXEC} is nonzero for every line...
- If you got your MenuEntry, you might as well break.

Anyway, the problem with this script is that you're hardwiring the structure into the script, which is even worse than the current solution... I don't see the problem with waiting one second every now and then for the menu regeneration (you can also use a dynamic menu, if you have a reasonably fast machine).

Posted: Tue 16 Aug 2011, 20:42
by technosaurus
moved it outside the loop, couldn't break because the entry order can vary, so I would need to check all 4 variables ... its faster to just parse the whole file and then do one

can someone tell me the preferred order of LANG, LC_ALL, and LANGUAGE as well as the typical formats.

I think something like this will work:
myLANG=${myLANG:-${LANG%_}}

a wrapper could then set myLANG and call it with

SUBMENUS=0 myLANG=ja jwm_menu_create > ${HOME}/.jwmrc

Edit - here is a template for localization:

Code: Select all

	xx*)	#this is a template, just remove any unnecessary translations
		jwm_Desktop="" 
		jwm_DesktopSettings="" 
		jwm_DesktopCountry="" 
		jwm_DesktopApplets="" 
		jwm_System="" 
		jwm_SystemConfig="" 
		jwm_SystemMemory="" 
		jwm_SystemSchedule="" 
		jwm_Setup="" 
		jwm_SetupEntry="" 
		jwm_SetupWizard="" 
		jwm_SetupUtility="" 
		jwm_Utility="" 
		jwm_UtilityUtilities="" 
		jwm_UtilityArchiving="" 
		jwm_UtilityConsole="" 
		jwm_Filesystem="" 
		jwm_FilesystemManager="" 
		jwm_FilesystemMount="" 
		jwm_FilesystemUtilities="" 
		jwm_FilesystemFind="" 
		jwm_Graphic="" 
		jwm_GraphicGraphics="" 
		jwm_GraphicEdit="" 
		jwm_GraphicUtility="" 
		jwm_Document="" 
		jwm_DocumentCompose="" 
		jwm_DocumentText="" 
		jwm_DocumentUtilities="" 
		jwm_Business="" 
		jwm_BusinessSheets="" 
		jwm_BusinessCalculator="" 
		jwm_BusinessUtilities="" 
		jwm_Personal="" 
		jwm_PersonalPlan="" 
		jwm_PersonalUtilities="" 
		jwm_Network="" 
		jwm_NetworkDialup="" 
		jwm_NetworkRemote="" 
		jwm_Internet="" 
		jwm_InternetWWW="" 
		jwm_Multimedia="" 
		jwm_MultimediaMedia="" 
		jwm_MultimediaBurn="" 
		jwm_Fun="" 
		jwm_Help="" 
		jwm_Shutdown="" 
		jwm_Exit="" 
		jwm_Reboot="" 
		jwm_Poweroff="" 
		jwm_RestartX="" 
		jwm_RestartJWM=""
		;;

Posted: Tue 16 Aug 2011, 23:59
by technosaurus
I have made a conscious decision to omit the localized keymaps, I will shift all of the additional template items to their own files ... in ${HOME}/.jwm/
groups keymaps desktop ... etc...
The menu is auto generated, but the rest is user (or developer) defined

Edit.
Ok, I have the menu localized, Names as well - if jwm ever gets tooltip support for menu items it is already ready there is a template in the script (/usr/bin/jwm_menu_create) for adding new localizations

moved the non-menu stuff to ${HOME}/.jwm/jwm-extra ... will split this apart as new tools develop (I know scottman and goingnuts have already done some work in this area)

also "multi-userized" the include paths and the pinstall.sh install script

a couple of other mods/bugfixes too

added more typos ... probably

see original post for 0.1 version pet

jwm_menu_create v0.1 uploaded

Posted: Wed 17 Aug 2011, 05:05
by technosaurus
I have uploaded the first alpha pet package

possible issues from moving the non-menu stuff to a separate file if any P-apps modify the etc/xdg/template or jwmrc directly ... this will eventually make it much easier to change themes (I think zigbert's jwm theming and ptray may need to be looked at)
I may eventually put some pieces/parts back in if it can be auto-generated from a configuration file ... for example a parse-able file(s) with all of the shortcut key definitions, list of groups and definitions, etc... but since they are currently static, there is no real point in regenerating them every time (AFAICT)

Anyone using one of zigbert, scottman, goingnuts or many other jwm related apps/scripts that this doesn't play nice with let me know.

btw, does anyone (other than myself) prefer the submenus

Edit:
I started going through jwm-config which is spread out in several different files... so I just picked one (gtk2jwm) and went through it ... long story short ... now it is totally rewritten, but AFAICT not directly used

Code: Select all

#!/bin/sh
. /root/.jwm/jwm_colors
while read LINE ; do #go through trayfile line by line
	case $LINE in
		include*/usr/share/themes*)GTKRC=${LINE#include };GTKRC=${GTKRC//\"/};break;;
	esac
done < ${HOME}/.gtkrc-2.0

while read LINE ; do #go through gtkrc file line by line
	case $LINE in
		*bg?NORMAL*)MENU_BG=${LINE##* };;
		*bg?SELECTED*)ACTIVE_BG=${LINE##* };;
		*fg?NORMAL*)FOREGROUND=${LINE##* };;
		*bg?ACTIVE*)PAGER_BG=${LINE##* };;
		*fg?SELECTED*)FG_SELECTED=${LINE##* };;
	esac
done < $GTKRC

 #save them...
echo '#This is written to by /usr/local/jwmconfig2/gtk2jwm script
MENU_BG='${MENU_BG}'
ACTIVE_BG='${ACTIVE_BG}'
FOREGROUND='${FOREGROUND}'
PAGER_BG='${PAGER_BG}'
FG_SELECTED='${FG_SELECTED} > ${HOME}/.jwm/jwm_colors

mv -f ${HOME}/.jwmrc-tray ${HOME}/.jwmrc-tray.bak

while read LINE ; do #go through trayfile line by line, fix blinky and xload, pass the rest through
	case $LINE in
		*blinkydelayed*)echo '		blinkydelayed -bg "'"$MENU_BG"'"' >> ${HOME}/.jwmrc-tray;;
		*xload??nolabel*)echo '		xload -nolabel -fg red -hl white -bg "'"$MENU_BG"'"' >> ${HOME}/.jwmrc-tray;;
		*)echo $LINE >> ${HOME}/.jwmrc-tray;;
		esac
done < ${HOME}/.jwmrc-tray.bak

jwm_menu_create

Posted: Wed 17 Aug 2011, 11:06
by L18L
technosaurus wrote:...
can someone tell me the preferred order of LANG, LC_ALL, and LANGUAGE as well as the typical formats.
...
http://www.gnu.org/software/gettext/man ... E-variable
Though you might not use gettext I kindly suggest to use LANGUAGE in the way defined by GNU.

I am using LANGUAGE (my locale is de_DE) for example

Code: Select all

LANGUAGE=en geany
If I had an error message from geany to reproduce the error message in English and searching for help from an international audience.

This is working with all GNU software
but NOT with rox and abiword, they seem to use "SIMPLE" localization.

LANGUAGE is a list of languages and can be used independently of having locales for all languages.
See my example
ymount

Technosaurus, did I get you right?
You support more then just the language set in locale but faster than gettext?
If that is true, CONGRATULATIONS
:)
(And sc0ttman can use his slovio then :wink: )

------------------------
Edited some hours later

Yes, it is true
Thank you :D

Edited some minutes later
Changed first line of script from

Code: Select all

myLANG=${LANG%_*}
to

Code: Select all

 [ -z $LANGUAGE ] && myLANG=${LANG%_*} || myLANG=$LANGUAGE
And changed back to English:

Code: Select all

 LANGUAGE=en ./jwm_menu_create > ${HOME}/.jwmrc && jwm -restart
:D

Posted: Thu 18 Aug 2011, 10:35
by technosaurus
I haven't added any translations yet, but the infrastructure is now there and will automatically fall back to en_TEchnosaurus

... but I did add a new item for 0.2 (see the teaser pic)

I got sick of waiting & waiting .... every time I wanted to change categories or distro repo .... so just added the whole damn thing to a jwm rootmenu
amazingly it runs (only once) in ~2.5s and after that it is as instant as navigating the regular menu
it does ALL repos, whereas PPM takes over 30s for just one distro and ~5s just to switch categories
... sorry it doesn't increase your download speed though

jwm_menu_create

Posted: Thu 18 Aug 2011, 14:41
by L18L
Thanks for having added the LANGUAGE thing :)

line 179 of jwm_menu_create should be now:
Name=*|Name?${myLANG}?=*) NAME="${LINE#*=}"'' ;;
until a better storage for translations is created.

TPM (TechnosaurusPackageManager) is looking very interesting :D

That is how the translations of NAME are stored in lang_pack's now

[Desktop Entry]
Encoding=UTF-8
Name=Abiword wordprocessor
Name[ru]=Abiword тек

Re: jwm_menu_create

Posted: Thu 18 Aug 2011, 15:00
by sc0ttman
L18L wrote:TPM (TechnosaurusPackageManager) is looking very interesting :D
I was gonna call it the JW(PP)M ;)

Posted: Thu 18 Aug 2011, 16:11
by maxerro
:D Borderline-genius-showoff... TS, while you're under the influence of cosmical wisdom-dust activity, you might try making a 15x faster JWM-menu-shaped Pmount replacement.

People who don't like multiple (or any) trays can play with the attached jwm_install_menu_create. Then run TS's jwm_menu_create v0.2 and activate the menu with middle mouse button (or change the script to respond to left button if you prefer).

pmount replacement

Posted: Thu 18 Aug 2011, 16:25
by L18L
maxerro wrote:Pmount replacement.
Try this one
ymount
:D