Re: Hotkey Toolbar Quick Program Launcher AGAIN!

new topic     » goto parent     » topic index » view thread      » older message » newer message

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 thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu