1. Hotkey Toolbar Quick Program Launcher AGAIN!

Hello All

They say third time lucky (or is this the fourth?)
My recent posts had no weird characters so I think I have solved that=20
problems.  If not I will have to hide under a rock for a while.  :(

If you want to try this, then read the help for quick at the beginning of=
=20
the listing below.

You can change quick.ini to have programs/documents what you want to=20
launch, and quick.exw will need to have the correct location of quick.ini=

in it (at present c:\euphoria\bin\).

Please let me know what you think and if you have any answers to
my questions in the previous post.

The problems are these:

1. Originally I had quick.exw and quick.ini in the same folder and the=20
program found the .ini file with just a "quick.ini" file name but after I=
=20
rebooted it couldn't find it and so I had to change to the full path whic=
h=20
is "C:\\EUPHORIA\\BIN\\quick.ini". I don't understand why a reboot did th=
is.

2. I want to put Icons on the buttons for the selected programs of type=20
=2Eexe so that they are easy to recognise.  However as someone said, the =

extractIcon( function does not appear to be compatible with the=20
create(PictureButton or the setIcon( function so I haven't managed to get=
=20
any icons on the buttons. I have commented out the part that doesn't work=
=20
near the bottom. Don't worry about the complex looking floor((ib-1)/13)*4=
0,=20
remainder(ib-1,13)*40 parameters as they work fine and just use the same =

code to set up all 39 buttons.

3. I haven't yet done the Enter key part which is to allow the reassignme=
nt=20
of the keys by the user. So at present you have to edit the .ini file=20
(carefully) to set up the programs you want to have a quick launch of.

4. I am not sure whether my program has a memory leak but something does.=
=20
How do I tell?

Thanks

Ray

----start quick.exw----
sequence qhelp
qhelp=3D"QUICK is a quick hotkey program launcher of your favourites\n" &=

   "\n" &
   "START *quick* application which will be in minimized mode.\n" &
   "At any time press F12 to bring quick up for use,\n" &
   "then either click on a button or type a single key \n" &
   "a-z (or A-Z) or 0-9 to run the chosen application.\n" &
   "To remember easily, I use E for Explorer, I for Irfanview,\n" &
   "W for WordPad, Z for WinZip etc.\n" &
   "Press Enter to alter any of the 36 chosen applications.\n" &
   "The application's icon will show on the button it is set to.\n" &
   "Press Esc and the application will be disabled and closed.\n" &
   "Press any other key and help information will be brought up.\n" &
   "Be Happy!\n" &
   "\n" &
   "=A9 Copyright 2003 Ray Tomes -- rtomes at ihug.co.nz\n" &
   "No warranty of any kind is given by the author\n" &
   "as it is my first Euphoria program, but I did test it lots  blink\n" &
   "May be freely used.  Please advise suggested changes to me.\n" &
   "Written in Euphoria language, see http://www.RapidEuphoria.com\n" &
   "and uses Win32Lib by David Cuny and friends and hotkey by Ting.\n" &
   "Thanks to Dan Moyer, Derek Parnell, C.K.Lester, aku saya,\n" &
   "Pete Lomax and others for help with Euphoria and Win32Lib.\n"

without warning
include Win32lib.ew
include hotkey.e
include msgbox.e

object bshow
bshow =3D "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" & {"Enter","Esc","?"}
atom bnum -- button number pressed or key typed: a-z=3D>1-26, 0-9=3D>27-3=
6,
--           Enter=3D>37, Esc=3D>38, other=3D>39
sequence assign, button
assign =3D repeat("",39)
button =3D repeat(0,39)
atom inifn, i
object linb, bsh, bhint
constant Window1=3Dcreate(Window,"Quick",0,Center,Center,128,547,0)

atom Window2

procedure gethelp()
   i =3D message_box(qhelp, "Quick HELP", MB_OK)
end procedure

procedure reassign()
   -- to be done yet
end procedure

procedure launch(integer butno)
   if butno=3D37 then reassign()
   elsif butno=3D38 then closeApp()
   elsif butno=3D39 then gethelp()
   else shellExecute("open", assign[butno], SW_SHOWNORMAL)
   end if
   openWindow(Window1, Minimize)
end procedure

procedure AnyKey(integer self, integer event, sequence params)
   integer keycode, shift
   keycode=3Dparams[1]
   shift=3Dparams[2]
   if keycode>=3D'a' and keycode<=3D'z' then bnum=3Dkeycode-96
   elsif keycode>=3D'A' and keycode<=3D'Z' then bnum=3Dkeycode-64
   elsif keycode>=3D'0' and keycode<=3D'9' then bnum=3Dkeycode-48+27
   elsif keycode=3D13 then bnum=3D37
   elsif keycode=3D27 then bnum=3D38
   else bnum=3D39 -- undefined keys also gives help
   end if
   launch(bnum)
end procedure

procedure WinHotKey(atom id) -- HotKey pressed =3D> show window
   openWindow( Window1, Normal)
end procedure

procedure ClickBut(integer id, integer event, sequence parms)
   for ib=3D1 to 39 do
     if id=3Dbutton[ib] then launch(ib) end if
   end for
end procedure

-- serious execution starts here with quick.ini file
-- originally I just had "quick.ini" but rebooting req'd change ???
inifn=3Dopen( "C:\\EUPHORIA\\BIN\\quick.ini", "r")
if inifn =3D -1 then
   i =3D message_box("quick.ini file not found", "Quick", MB_OKCANCEL)
else
   linb =3D gets(inifn)
   if equal(linb,"[buttons]\n") then
     for bn=3D1 to 36 do
       linb =3D gets(inifn)
       if atom(linb) then exit end if
       assign[bn]=3Dlinb[3..length(linb)-1]
     end for
   end if
end if
close(inifn)

for ib=3D1 to 39 do
   i=3D0
   bsh=3Dbshow[ib]
   if ib<37 then bhint=3Dbsh&" unassigned"
   elsif ib=3D37 then bhint=3D"Enter sets code assignment of applications=
"
   elsif ib=3D38 then bhint=3D"Esc shuts down *quick*"
   elsif ib=3D39 then bhint=3D"? or space for Help and About quick"
   end if
   if length(assign[ib])>2 then bhint=3Dbsh&" launches "&assign[ib] end i=
f
   if atom(bsh) then bsh=3D{bsh} end if
----- it seems that extractIcon is NOT compatible with PictureButton
--  if match(".exe",assign[ib]) then
--    i=3DextractIcon(assign[ib])
--    if i!=3D0 then button[ib]=3Dcreate(PictureButton,{bsh,bhint},
--      Window1,floor((ib-1)/13)*40, remainder(ib-1,13)*40, 40, 40, 0)
--      setIcon ( button[ib], {i} )
--    else
--    end if
--  end if
   if i=3D0 then
     button[ib]=3Dcreate(PushButton,{bsh,bhint},
       Window1,floor((ib-1)/13)*40,remainder(ib-1,13)*40,40,40,0)
   end if
   setHandler( button[ib], w32HClick, routine_id("ClickBut"))
end for

onHotKey =3D routine_id("WinHotKey")
setHotKey( Window1, 2, 0, VK_F12)
setHandler( Window1, w32HKeyPress, routine_id("AnyKey"))
WinMain( Window1, Minimize )

----end quick.exw----
----start quick.ini----
[buttons]
A=3D
B=3D
C=3D
D=3DC:\EUPHORIA\DOC\database.doc
E=3DC:\WINDOWS\EXPLORER.EXE
F=3D
G=3D
H=3DC:\EUPHORIA\DOC\ENCYEU.HLP
I=3D"C:\Program Files\IrfanView\i_view32.exe"
J=3D
K=3D
L=3D"C:\Program Files\NoteTab Light\NoteTab.exe"
M=3D
N=3D"C:\Program Files\Netscape\Netscape\Netscp.exe"
O=3D
P=3D
Q=3D
R=3DC:\EUPHORIA\DOC\REFMAN.DOC
S=3D
T=3D
U=3D
V=3D
W=3D"C:\Program Files\Accessories\WORDPAD.EXE"
X=3D
Y=3D
Z=3D"C:\Program Files\WinZip\WINZIP32.EXE"
0=3D
1=3D
2=3DC:\EUPHORIA\DL\IDE\IDE.exw
3=3DC:\EUPHORIA\DL\Win32Lib\Docs\index.htm
4=3D
5=3D
6=3D
7=3D
8=3D
9=3D


----end quick.ini----

new topic     » topic index » view message » categorize

2. Re: Hotkey Toolbar Quick Program Launcher AGAIN!

SUCCESS!

new topic     » goto parent     » topic index » view message » categorize

3. Re: Hotkey Toolbar Quick Program Launcher AGAIN!

Hello Ray,

I've add a few comments to you post, and your code, hopefully they point you
in the right direction.

>1. Originally I had quick.exw and quick.ini in the same folder and the
>program found the .ini file with just a "quick.ini" file name but after I
>rebooted it couldn't find it and so I had to change to the full path which
>is "C:\\EUPHORIA\\BIN\\quick.ini". I don't understand why a reboot did
this.

i would suggest getting the directory of the .exw file from command_line()
it will be the second element of the returned sequence:  { "path to
interpreter", "path to exw file", "additional command line options", ... }

>2. I want to put Icons on the buttons for the selected programs of type
>.exe so that they are easy to recognise.  However as someone said, the
>extractIcon( function does not appear to be compatible with the
>create(PictureButton or the setIcon( function so I haven't managed to get
>any icons on the buttons. I have commented out the part that doesn't work
>near the bottom. Don't worry about the complex looking floor((ib-1)/13)*40,
>remainder(ib-1,13)*40 parameters as they work fine and just use the same
>code to set up all 39 buttons.

i like the XPM library provided by Jonas Temple, it comes with a lot of nice
icons, you can use an xpm image from the library on a PictureButton by
calling  createDIB( xpmToEuBmp(name_of_xpm) )




--add this code:

function build_ascii()
sequence ascii
    ascii = repeat(0, 255)

    for i = 1 to 255 do
        ascii[i] = i
    end for

    return ascii
end function

sequence ascii_table
    ascii_table = build_ascii()

-- then use it here:

procedure AnyKey(integer self, integer event, sequence params)
   integer keycode, shift
   keycode=params[1]
   shift=params[2]
   if find( keycod, ascii_table['a'..'z'] ) then bnum=keycode-96
   elsif find( keycode, ascii_table['A'..'Z'] ) then bnum=keycode-64
   elsif find( keycode, ascii_table['0'..'9'] ) then bnum=keycode-48+27
   elsif keycode=13 then bnum=37
   elsif keycode=27 then bnum=38
   else bnum=39 -- undefined keys also gives help
   end if
   launch(bnum)
end procedure

-- not sure why, it looks like it should help

>procedure ClickBut(integer id, integer event, sequence parms)
>   for ib=1 to 39 do
>     if id=button[ib] then launch(ib) end if
>   end for
>end procedure

-- no need for a for loop, since ClickBut() will only be called
-- once per button press, rather do the following:

procedure ClickBut(integer id, integer event, sequence parms)
integer ib
    ib = find( id, button )        -- i like find(). find() is my friend.
match() and compare() are good, too.
    if ib then launch(ib) end if
end procedure


-- i just typed this out in outlook, forgive me if it needs editing (i doubt
it)

function startup_dir()
-- get the directory the program started in
sequence cmd
integer slash

    cmd = command_line()    -- get the command line
    cmd = cmd[2]                 -- get the path to the .exw file
    cmd = reverse( cmd )      -- reverse() it so the filename come before
the path

     -- find the first slash in the path
    if platform() = LINUX then    -- platform independant
        slash = find( '/', cmd )
    else
        slash = find( '\\', cmd )
    end if

    if slash then
        -- a slash was found, so strip the file name (remember, the path is
backwords!)
        cmd = cmd[slash..length(cmd)]
        cmd = reverse(cmd)    -- re-reverse() it

    else
        -- no slash found, must be the current directory
        cmd = current_dir()

        if cmd[length(cmd)] != '\\' then
        -- i don't recall if current_dir() returns a slash at
        --  the end of the path, so i put in a fail-safe

            if platform() = LINUX then    -- platform independant
                cmd &= '/'
            else
                cmd &= '\\'
            end if

        end if

    end if

    return cmd
end function


procedure init_ini()
-- notice this is now a procedure

inifn = open( startup_dir() & "quick.ini", "r" )

>if inifn = -1 then
>   i = message_box("quick.ini file not found", "Quick", MB_OKCANCEL)
>else
>   linb = gets(inifn)
>   if equal(linb,"[buttons]\n") then
>     for bn=1 to 36 do
>       linb = gets(inifn)
>       if atom(linb) then exit end if
>       assign[bn]=linb[3..length(linb)-1]
>     end for
>   end if
>end if
>close(inifn)

-- since we are now in a procedure, we can 'return' when needed

if inifn = -1 then
-- if open() returns -1, you do not need to close() the file, it was never
opened
    i = message_box("quick.ini file not found", "Quick", MB_OKCANCEL)
    return    -- stop initializing
end if


-- no real change needed here:
>   linb = gets(inifn)
>   if equal(linb,"[buttons]\n") then
>     for bn=1 to 36 do
>       linb = gets(inifn)
>       if atom(linb) then exit end if
>       assign[bn]=linb[3..length(linb)-1]
>     end for
>   end if

close(fn)

end procedure

procedure init_button()
-- another2 procedure

>
>for ib=1 to 39 do
>   i=0
>   bsh=bshow[ib]
>   if ib<37 then bhint=bsh&" unassigned"
>   elsif ib=37 then bhint="Enter sets code assignment of applications"
>   elsif ib=38 then bhint="Esc shuts down *quick*"
>   elsif ib=39 then bhint="? or space for Help and About quick"
>   end if
>   if length(assign[ib])>2 then bhint=bsh&" launches "&assign[ib] end if
>   if atom(bsh) then bsh={bsh} end if
>----- it seems that extractIcon is NOT compatible with PictureButton
>--  if match(".exe",assign[ib]) then
>--    i=extractIcon(assign[ib])
>--    if i!=0 then button[ib]=create(PictureButton,{bsh,bhint},
>--      Window1,floor((ib-1)/13)*40, remainder(ib-1,13)*40, 40, 40, 0)
>--      setIcon ( button[ib], {i} )
>--    else
>--    end if
>--  end if
>   if i=0 then
>     button[ib]=create(PushButton,{bsh,bhint},
>       Window1,floor((ib-1)/13)*40,remainder(ib-1,13)*40,40,40,0)
>   end if
>   setHandler( button[ib], w32HClick, routine_id("ClickBut"))
>end for

end procedure

i put all of the above into a procedures which should be called before
WinMain(), reason being your program will load faster if everthing is in a
routine, since the interpreter reads in code until it *has* to do something,
then it does it, and continues reading. if nothing *needs* to be executed
until the very end, everything will load first, then run. this may
contribute to what you think is a memory leak.

also, consider using kat's strtok.e library for your ini file. it may help
down the road if you decide to change anything, so you won't need to rely on
hard numbers. and users don't have to be 'careful' when editing the file,
with strtok.e, the possibilities are nearly endless <side note> see kat,
some of us us your stuff, i think strtok.e is great! </side note>

example:

-- old code
       assign[bn]=linb[3..length(linb)-1]

-- new code
        linb = split( linb, '=' )
        assign[bn] = linb[2]


~Greg
g.haberek at comcast.net

new topic     » goto parent     » topic index » view message » categorize

4. Re: Hotkey Toolbar Quick Program Launcher AGAIN!

Hi Greg

Many thanks for your lengthy reply. I will sit down and digest it.

But, as regards the icons, I am not sure if you realise what I am doing on 
this one. I am going to the program that is associated with a button (it 
gets the *.exe from the .ini file) and extracting the icon from the 
program itself and want to put that on the button. This is to work even 
when I add the dynamic reassignment of programs to buttons later. So I 
really want to use extractIcon() to have the correct icon for any program 
that someone else might have.

All the best

Ray Tomes

new topic     » goto parent     » topic index » view message » categorize

5. Re: Hotkey Toolbar Quick Program Launcher AGAIN!

Ray,

The Win32Lib demo "FlatToolBar.exw" extracts icons, & puts them on buttons,
with text also on the buttons, although it doesn't appear to use
"extractIcon" to get the icon from an exe, but rather, as far as I can
understand, it uses "iExw = w32Func(xLoadIcon,{instance(), "exw"} )".  But
from Win32Lib doc, it looks like "extractIcon" *should* work, for DLL, EXE
or ICO files.

Dan Moyer

----- Original Message -----
From: "Ray Tomes" <rtomes at ihug.co.nz>
To: "EUforum" <EUforum at topica.com>
Sent: Thursday, June 19, 2003 8:50 PM
Subject: Re: Hotkey Toolbar Quick Program Launcher AGAIN!


>
>
> Hi Greg
>
> Many thanks for your lengthy reply. I will sit down and digest it.
>
> But, as regards the icons, I am not sure if you realise what I am doing on
> this one. I am going to the program that is associated with a button (it
> gets the *.exe from the .ini file) and extracting the icon from the
> program itself and want to put that on the button. This is to work even
> when I add the dynamic reassignment of programs to buttons later. So I
> really want to use extractIcon() to have the correct icon for any program
> that someone else might have.
>
> All the best
>
> Ray Tomes
>
>
>
> TOPICA - Start your own email discussion group. FREE!
>
>

new topic     » goto parent     » topic index » view message » categorize

6. Re: Hotkey Toolbar Quick Program Launcher AGAIN!

Hi Greg

OOPS - just discovered I forgot to send this.

Greg Haberek wrote:
 > i would suggest getting the directory of the .exw file from command_line()
 > it will be the second element of the returned sequence:  { "path to
 > interpreter", "path to exw file", "additional command line options", ... }

OK, I have done this and it works. What confuses me is that it worked to
begin with with my file name just "quick.ini" so I assumed that the
default dir was the one where the quick.exw was double clicked. I got a
real surprise when the next time I booted it couldn't find it.

later you wrote:
  > function startup_dir()
  > -- get the directory the program started in
  > sequence cmd
  > integer slash
... and a lot of code.

I cheated on this, just knocking off the exw and putting the ini in place
as follows (it will even work if I change the program name)  smile

cmd=command_line()
inifn=open(cmd[2][1..length(cmd[2])-3]&"ini", "r")

Euphoria is the first language I have come across that is BETTER than
BASIC at manipulating strings, and I have come across a few (started
programming in the 60s). Hey while I am reminiscing, I also had a C64 and
an Amiga before getting a 286 then various Pentiums. But before the C64 I
had a Compucolor! The C64 and Amiga were great machines and some things
have never caught up with the Amiga yet. I have a C64 emulator on the PC
and it will run some of the old games; also a game "Jumpman lives!".

Not sure about your ascii table so I haven't done that. I am going by the
principle that if it isn't broke don't fix it.

 > -- no need for a for loop, since ClickBut() will only be called
 > -- once per button press, rather do the following:
...

Yes, good point, why loop if not needed - find is faster. I will change
this too.

Many thanks Greg

new topic     » goto parent     » topic index » view message » categorize

7. Re: Hotkey Toolbar Quick Program Launcher AGAIN!

> OK, I have done this and it works. What confuses me is that it worked to
> begin with with my file name just "quick.ini" so I assumed that the
> default dir was the one where the quick.exw was double clicked. I got a
> real surprise when the next time I booted it couldn't find it.

reason here is that the current directory may have been reset. what are you
using to edit (and run) your files? I use MEditor most of the time, and I've
noticed problems with it placing files I create in the wrong spot, so I
started using startup_dir(). If you use ed, i doubt you'd have a problem. if
you're using the IDE, you may run into the same problem as I run into with
MEditor.

> Euphoria is the first language I have come across that is BETTER than
> BASIC at manipulating strings, and I have come across a few (started
> programming in the 60s). Hey while I am reminiscing, I also had a C64 and
> an Amiga before getting a 286 then various Pentiums. But before the C64 I
> had a Compucolor! The C64 and Amiga were great machines and some things
> have never caught up with the Amiga yet. I have a C64 emulator on the PC
> and it will run some of the old games; also a game "Jumpman lives!".

**** JUMPMAN RULES! ****
Lately I've been working on the artwork and level layouts for a game called
'Jumpman X' (i skipped a few versions for time's sake) which I hope to
develop this summer. I used to have an old Apple II on which I learned
Apple-Basic, and made my own text-mode games. (that was when I was about 7
or 8) My uncle still has 3 Commodore 64's, one of which is wired up to an
electronic dart board, running (basic) software he wrote himself. I was a
QBasic programmer for a long time, maybe 6 or 7 years, just as a hobby. A
few years ago, I discovered Euphoria, and the first thing that drew me to it
was how easy it was to manipulate strings. (if you add up the ages I gave
here, it nearly my entire life's story! i'm only 19 smile

> Not sure about your ascii table so I haven't done that. I am going by the
> principle that if it isn't broke don't fix it.

Comparisons just look messy, and again, find() is faster. so if you slice a
sequence   x['A'..'Z'] and then look for a value in that, it is easier than
writing out a bunch of comparisons.

> Yes, good point, why loop if not needed - find is faster. I will change
> this too.

> Many thanks Greg

No problem, I'm always here to help.

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu