Status bar extension

View: New views
12 Messages — Rating Filter:   Alert me  

Status bar extension

by Youness Alaoui-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi all,

Today I took on the task of writing an extension for Mac to allow Tcl/Tk applications to have a status icon in the status bar (the right part of the menu bar). It was quite interesting, I used some code from gtk's implementation, and it seems to work fine now! 
If anyone is interested, you can find it in amsn's latest SVN : http://amsn.svn.sourceforge.net/viewvc/amsn/trunk/amsn/utils/macosx/statusicon/
The API is quite simple :
- ::statusicon::create callback
creates a status icon (invisible) and will use the callback specified for notifying Tcl of click actions.
Returns an identifier for the status icon,
- ::statusicon::setImage statusicon imagePath
Sets the image to show in the status bar, takes a statusicon identifier (returned by ::statusicon::create) and the path to an image (not an actual Tk image, but the relative/absolute path to an image file). PNG files seem to work file, whatever works with NSImage should work here.
- ::statusicon::setTooltip statusicon tooltip
Sets the tooltip on the statusicon
- ::statusicon::setVisible statusicon visible
Takes a boolean and shows/hides the status icon
- ::statusicon::destroy statusicon
Destroy a previously created statusicon

The clicks are being reported to Tcl through the callback specified in the call to ::statusicon::create and it's format is :
proc callback { action } {
  if {$msg == "ACTION" } {
     # Single click
  } elseif {$msg == "DOUBLE_ACTION" } {
     # double click
  }
}

I hope this is useful to somebody else!

Take care,
KaKaRoTo

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Tcl-mac mailing list
tcl-mac@...
https://lists.sourceforge.net/lists/listinfo/tcl-mac

Re: Status bar extension

by Linus Nyberg-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.

Hi Youness!

 

This is really really cool stuff.

I tested it but got tempted to create some kind of popup when the user clicks on the status icon… See the attached screenshot.

It didn’t work all the way for me, and I was wondering if you have any tips? If you are launching some kind of popup menu and making it work?

 

Here’s the problem: When Tk launches the popup, it seems to lose focus or something (because the status bar takes focus?), so when I press any of the menu items, the commands behind them are still not run.

 

Maybe someone else knows how to force focus to the popup…? “focus –force .popup”, grab etc does not work since the Tk app itself doesn’t seem to have focus.

 

Here’s the example code:

 

#######################

cd [file dirname [info script]]

cd .. ;# => Resources

cd .. ;# => Contents

cd .. ;# => App folder

set ::MAC_APP_FOLDER [pwd]

 

proc mac_startup {} {

                      console show

                     

                      load [file join $::MAC_APP_FOLDER Contents Resources Scripts statusicon.dylib]

                     

                      wm geometry . 400x400

                     

                      frame .f -width 400 -height 400 -bg grey70

                      place .f -x 0 -y 0 -anchor nw

 

                      set si_id [::statusicon::create my_callback]

                     

                      ::statusicon::setImage $si_id [file join $::MAC_APP_FOLDER Contents Resources Scripts 6_contact_b.gif]

                      ::statusicon::setTooltip $si_id "Test tooltip"

                      ::statusicon::setVisible $si_id 1

}

 

proc my_callback {action} {

                      puts "action = $action"

                      if {$action == "ACTION"} {

                                            set m [menu .popup]

                                            $m add command -label "Do something" -command {puts "Do Something"}

                                            $m add command -label "Do something else" -command {puts "Do Something Else"}

                                           

                                            tk_popup .popup [winfo pointerx .] [winfo pointery .]

                                            destroy .popup

                      }

}

 

after 5 mac_startup

#######################

 


From: Youness Alaoui [mailto:kakaroto@...]
Sent: den 7 oktober 2009 11:49
To: tcl-mac@... List
Subject: [MACTCL] Status bar extension

 

Hi all,

 

Today I took on the task of writing an extension for Mac to allow Tcl/Tk applications to have a status icon in the status bar (the right part of the menu bar). It was quite interesting, I used some code from gtk's implementation, and it seems to work fine now! 

If anyone is interested, you can find it in amsn's latest SVN : http://amsn.svn.sourceforge.net/viewvc/amsn/trunk/amsn/utils/macosx/statusicon/

The API is quite simple :

- ::statusicon::create callback

creates a status icon (invisible) and will use the callback specified for notifying Tcl of click actions.

Returns an identifier for the status icon,

- ::statusicon::setImage statusicon imagePath

Sets the image to show in the status bar, takes a statusicon identifier (returned by ::statusicon::create) and the path to an image (not an actual Tk image, but the relative/absolute path to an image file). PNG files seem to work file, whatever works with NSImage should work here.

- ::statusicon::setTooltip statusicon tooltip

Sets the tooltip on the statusicon

- ::statusicon::setVisible statusicon visible

Takes a boolean and shows/hides the status icon

- ::statusicon::destroy statusicon

Destroy a previously created statusicon

 

The clicks are being reported to Tcl through the callback specified in the call to ::statusicon::create and it's format is :

proc callback { action } {

  if {$msg == "ACTION" } {

     # Single click

  } elseif {$msg == "DOUBLE_ACTION" } {

     # double click

  }

}

 

I hope this is useful to somebody else!

 

Take care,

KaKaRoTo



------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Tcl-mac mailing list
tcl-mac@...
https://lists.sourceforge.net/lists/listinfo/tcl-mac

statusicon.png (46K) Download Attachment

Re: Status bar extension

by Kevin Walzer-5 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On 10/7/09 5:48 AM, Youness Alaoui wrote:

> Hi all,
>
> Today I took on the task of writing an extension for Mac to allow Tcl/Tk
> applications to have a status icon in the status bar (the right part of
> the menu bar). It was quite interesting, I used some code from gtk's
> implementation, and it seems to work fine now!
> If anyone is interested, you can find it in amsn's latest SVN :
> http://amsn.svn.sourceforge.net/viewvc/amsn/trunk/amsn/utils/macosx/statusicon/
> The API is quite simple :
> - ::statusicon::create callback
> creates a status icon (invisible) and will use the callback specified
> for notifying Tcl of click actions.
> Returns an identifier for the status icon,
> - ::statusicon::setImage statusicon imagePath
> Sets the image to show in the status bar, takes a statusicon identifier
> (returned by ::statusicon::create) and the path to an image (not an
> actual Tk image, but the relative/absolute path to an image file). PNG
> files seem to work file, whatever works with NSImage should work here.
> - ::statusicon::setTooltip statusicon tooltip
> Sets the tooltip on the statusicon
> - ::statusicon::setVisible statusicon visible
> Takes a boolean and shows/hides the status icon
> - ::statusicon::destroy statusicon
> Destroy a previously created statusicon
>
> The clicks are being reported to Tcl through the callback specified in
> the call to ::statusicon::create and it's format is :
> proc callback { action } {
>    if {$msg == "ACTION" } {
>       # Single click
>    } elseif {$msg == "DOUBLE_ACTION" } {
>       # double click
>    }
> }
>
> I hope this is useful to somebody else!
>
> Take care,
> KaKaRoTo

Hi KaKaRoTo,

Wow! This is really cool. I did an svn update of aMSN and took a look at
it--very nice.

Something like this was on my "I need to learn more Objective-C so I can
write a Tk extension that does this" list--I had been wanting to add
this functionality to my applications. Thank you so much for doing this!

I will be doing some heavy lifting on some other Tk/Objective-C project
in the near future, so I'll post some news to the list when it's done.

Am I correct that the license is LGPL? I noticed that in the source code.

Also, I may modify the package a bit to allow one to build it separately
from aMSN--looks like that's the only way to do it right now, yes?

Thanks again,
Kevin

--
Kevin Walzer
Code by Kevin
http://www.codebykevin.com

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Tcl-mac mailing list
tcl-mac@...
https://lists.sourceforge.net/lists/listinfo/tcl-mac

Re: Status bar extension

by Youness Alaoui-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message



On Wed, Oct 7, 2009 at 7:13 AM, Linus Nyberg <linus@...> wrote:

Hi Youness!

Hi Linus! (great name btw :p) 

 

This is really really cool stuff.

Glad you find it useful!
 

I tested it but got tempted to create some kind of popup when the user clicks on the status icon… See the attached screenshot.

It didn’t work all the way for me, and I was wondering if you have any tips? If you are launching some kind of popup menu and making it work?

Yes, it works for me, in aMSN, I do launch a popup menu and it works correctly. 

 

Here’s the problem: When Tk launches the popup, it seems to lose focus or something (because the status bar takes focus?), so when I press any of the menu items, the commands behind them are still not run.

 

Maybe someone else knows how to force focus to the popup…? “focus –force .popup”, grab etc does not work since the Tk app itself doesn’t seem to have focus.

Ok, so I've tried your example code, and I had the same problem as you.. but I managed to fix it.. it wasn't a problem with the focus or anything like that.. it's jus that for some reason, when you destroy the popup menu, it screws up the callbacks for some reason.. so what I did to fix it is to remove the 'destroy .menu' after the tk_popup, and I moved it to the top of the function, right before you create the menu... it worked!
 By the way, I saw you used ::statusicon::setVisible, I wouldn't recommend it.. (I've now also removed it from amsn's code), the reason is because it's not needed.. the StatusItem Cocoa object doesn't support a 'setVisible' method, so what the extension does in that case is to destroy the status item or recreate it.. so basically, if you call setVisible false, it will destroy the icon (but keep a local reference to the previous tooltip and image used), and when calling setVisible true, it wil recreate it and call setImage and setTooltip on it... so basically, when you do a setImage or setTooltip, it will make the icon visible, and if you call setVisible after that, it's like calling setImage and setTooltip twice...
KaKaRoTo

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Tcl-mac mailing list
tcl-mac@...
https://lists.sourceforge.net/lists/listinfo/tcl-mac

Re: Status bar extension

by Linus Nyberg-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.

Brilliant! It works! Thank you!!

 

Is the license LGPL or GPL?

 

Linus

 


From: snifikino@... [mailto:snifikino@...] On Behalf Of Youness Alaoui
Sent: den 8 oktober 2009 00:37
To: Linus Nyberg
Cc: tcl-mac@...
Subject: Re: [MACTCL] Status bar extension

 

 

On Wed, Oct 7, 2009 at 7:13 AM, Linus Nyberg <linus@...> wrote:

Hi Youness!

Hi Linus! (great name btw :p) 

 

This is really really cool stuff.

Glad you find it useful!

 

I tested it but got tempted to create some kind of popup when the user clicks on the status icon… See the attached screenshot.

It didn’t work all the way for me, and I was wondering if you have any tips? If you are launching some kind of popup menu and making it work?

Yes, it works for me, in aMSN, I do launch a popup menu and it works correctly. 

 

Here’s the problem: When Tk launches the popup, it seems to lose focus or something (because the status bar takes focus?), so when I press any of the menu items, the commands behind them are still not run.

 

Maybe someone else knows how to force focus to the popup…? “focus –force .popup”, grab etc does not work since the Tk app itself doesn’t seem to have focus.

Ok, so I've tried your example code, and I had the same problem as you.. but I managed to fix it.. it wasn't a problem with the focus or anything like that.. it's jus that for some reason, when you destroy the popup menu, it screws up the callbacks for some reason.. so what I did to fix it is to remove the 'destroy .menu' after the tk_popup, and I moved it to the top of the function, right before you create the menu... it worked!

 By the way, I saw you used ::statusicon::setVisible, I wouldn't recommend it.. (I've now also removed it from amsn's code), the reason is because it's not needed.. the StatusItem Cocoa object doesn't support a 'setVisible' method, so what the extension does in that case is to destroy the status item or recreate it.. so basically, if you call setVisible false, it will destroy the icon (but keep a local reference to the previous tooltip and image used), and when calling setVisible true, it wil recreate it and call setImage and setTooltip on it... so basically, when you do a setImage or setTooltip, it will make the icon visible, and if you call setVisible after that, it's like calling setImage and setTooltip twice...

KaKaRoTo


------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Tcl-mac mailing list
tcl-mac@...
https://lists.sourceforge.net/lists/listinfo/tcl-mac

Re: Status bar extension

by Kevin Walzer-5 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi KaKaRoTo,

I've done some additional playing with the statusbar extension and have
a few questions:

1. The status icon itself doesn't get the blue border around it when
it's clicked. Is this by design? I don't think it's a big deal, I didn't
notice it right away until I saw someone else mention in the aMSN
forums. If setting that border causes huge difficulties, I can
understand the choice to leave it out. But I thought I'd ask...

2. I don't see any mention of menus in the C code. Is the menu
implemented elsewhere, as a normal Tk popup for instance? I'm just
trying to understand this so I can implement the logic in my own
applications. I also, at some point, might add some Tcl-level code to
simplify this.

All in all, this seems to be a great implementation of this concept. I
had done some research into writing this kind of extension myself, and
one of the reasons I shied away from it was that it seemed I'd have to
do everything in C/Objective-C--the menu, for instance, so that it
wouldn't be a Tk menu but a Cocoa menu. Your approach is much simpler
and works quite well, so congratulations!

--Kevin

--
Kevin Walzer
Code by Kevin
http://www.codebykevin.com

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Tcl-mac mailing list
tcl-mac@...
https://lists.sourceforge.net/lists/listinfo/tcl-mac

Parent Message unknown Fwd: Status bar extension

by Youness Alaoui-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

ahh.. forwarding since I seem to always forget to use the 'reply all' feature..

---------- Forwarded message ----------
From: Youness Alaoui <kakaroto@...>
Date: Wed, Oct 7, 2009 at 6:44 PM
Subject: Re: [MACTCL] Status bar extension
To: kw@...




On Wed, Oct 7, 2009 at 7:54 AM, Kevin Walzer <kw@...> wrote:
On 10/7/09 5:48 AM, Youness Alaoui wrote:
> Hi all,
>
> Today I took on the task of writing an extension for Mac to allow Tcl/Tk
> applications to have a status icon in the status bar (the right part of
> the menu bar). It was quite interesting, I used some code from gtk's
> implementation, and it seems to work fine now!
> If anyone is interested, you can find it in amsn's latest SVN :
> http://amsn.svn.sourceforge.net/viewvc/amsn/trunk/amsn/utils/macosx/statusicon/
> The API is quite simple :
> - ::statusicon::create callback
> creates a status icon (invisible) and will use the callback specified
> for notifying Tcl of click actions.
> Returns an identifier for the status icon,
> - ::statusicon::setImage statusicon imagePath
> Sets the image to show in the status bar, takes a statusicon identifier
> (returned by ::statusicon::create) and the path to an image (not an
> actual Tk image, but the relative/absolute path to an image file). PNG
> files seem to work file, whatever works with NSImage should work here.
> - ::statusicon::setTooltip statusicon tooltip
> Sets the tooltip on the statusicon
> - ::statusicon::setVisible statusicon visible
> Takes a boolean and shows/hides the status icon
> - ::statusicon::destroy statusicon
> Destroy a previously created statusicon
>
> The clicks are being reported to Tcl through the callback specified in
> the call to ::statusicon::create and it's format is :
> proc callback { action } {
>    if {$msg == "ACTION" } {
>       # Single click
>    } elseif {$msg == "DOUBLE_ACTION" } {
>       # double click
>    }
> }
>
> I hope this is useful to somebody else!
>
> Take care,
> KaKaRoTo

Hi KaKaRoTo,
Hi Kevin!
 

Wow! This is really cool. I did an svn update of aMSN and took a look at
it--very nice.
Thanks :)
 

Something like this was on my "I need to learn more Objective-C so I can
write a Tk extension that does this" list--I had been wanting to add
this functionality to my applications. Thank you so much for doing this!
hehe, I never thought I'd do it, and it wasn't in my TODO list at all.. actually, I wanted to fix a bug in the libtray extension for *linux* that aMSN uses, and for reference I decided to look at gtk's code on how it handles a specific use case... when looking at their code, I saw they had a gtkstatusicon-quartz.c file, I looked at it, and it was so small and simple, and the API was so easy, that I thought, damn, I guess I could port this to Tcl/Tk in a few hours.. so I copied their code, then started removing the gtk specific stuff, then wrote the Tcl wrapper around it, and it worked!
I spent a lot of time struggling with the ObjC though, like how to create an NSString from (char *), and how to get an NSImage, etc.. forgetting to do the [Class alloc] calls, etc.. so a lot of incremental debugging until it worked!
However, I realized that the gtk implementation has quite a few bugs (crash if you destroy the statusicon, then recreate it for example), so I had to read the docs, figure out the garbage collection stuff and fix it all.
The issue I have is that :
1 - you have to give a file path, can't give a Tk image (unless I add some code to ask Tk to give me the data of the image as GIF, then create the NSImage with that data)
2 - The menu looks aweful, it's not very well integrated when you compare it with the other status icons
3 - I still need to add stuff like setTitle, setAlternateImage, etc.. maybe someone else can contribute all that! :)
 

I will be doing some heavy lifting on some other Tk/Objective-C project
in the near future, so I'll post some news to the list when it's done.
cool!
 

Am I correct that the license is LGPL? I noticed that in the source code.
I guess so, aMSN is GPL, but I guess the libs we develop for it can be LGPL (like TkCximage that I made LGPL)
 

Also, I may modify the package a bit to allow one to build it separately
from aMSN--looks like that's the only way to do it right now, yes?
yes.. it probably will need to be put as a separate package so others can enjoy it more easily.. add a LICENSE file, and give credit to the Gtk (Imendio) folks who wrote the initial implementation.
 

Thanks again,
Kevin
You're welcome and thanks for the feedback! :)
KaKaRoTo
 

--

Kevin Walzer
Code by Kevin
http://www.codebykevin.com

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Tcl-mac mailing list
https://lists.sourceforge.net/lists/listinfo/tcl-mac



------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Tcl-mac mailing list
tcl-mac@...
https://lists.sourceforge.net/lists/listinfo/tcl-mac

Re: Status bar extension

by Youness Alaoui-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message



On Thu, Oct 8, 2009 at 9:40 AM, Kevin Walzer <kw@...> wrote:
Hi KaKaRoTo,

I've done some additional playing with the statusbar extension and have
a few questions:
cool.. I prefer "and I have a few question" rather than "and I had a few crashes" :D

1. The status icon itself doesn't get the blue border around it when
it's clicked. Is this by design? I don't think it's a big deal, I didn't
notice it right away until I saw someone else mention in the aMSN
forums. If setting that border causes huge difficulties, I can
understand the choice to leave it out. But I thought I'd ask...
Well, I tested with and without the blue highlighting, and it felt better without it.. the reason is that the highlight is only when you click, so when you click, it becomes blue, but then returns to normal, and the Tk menu pops on top of it (not even aligned correctly, so doesn't look very native), so it just felt weird.. 
My plan though is to add a few API calls to allow access to everything the real cocoa object gives, like :
setHighlightMode, setAlternateImage, setTitle, setAttributeTitle, and possibly in the very far future : setMenu.
I could probably do that right now withing a few minutes (copy paste a function, replace the call to setSomething into a call to setWhatever...).. I'll tell you when I update it in SVN.
 

2. I don't see any mention of menus in the C code. Is the menu
implemented elsewhere, as a normal Tk popup for instance? I'm just
trying to understand this so I can implement the logic in my own
applications. I also, at some point, might add some Tcl-level code to
simplify this.
Nope, no menus.. the reason is simple.. a Tk menu is .. a Tk menu (not sure if it's custom toplevel window with overrideredirect or if it's an actual menu window).. most probably, it's a Carbon menu, which definitely won't work into a Cocoa widget which probably expects a Cocoa menu.. that's why all you do, is get your callback and when the 'ACTION' message is sent, do a :
tk_popup $menu [winfo pointerx] [winfo pointery]
Have a look at the code posted by Linus, it does the job..
Other interesting info is that if you double click on the status icon, you will most probably get a ACTION followed by a DOUBLE_ACTION event.. so in the case of amsn, since ACTION shows a popup menu, and DOUBLE_ACTION iconfies/deiconifies the main window, I had put a timer that delays the action 250ms and cancels the ACTION if DOUBLE_ACTION is received in that 250ms time interval.. it's hacky, but I don't know what to do more...
 

All in all, this seems to be a great implementation of this concept. I
had done some research into writing this kind of extension myself, and
one of the reasons I shied away from it was that it seemed I'd have to
do everything in C/Objective-C--the menu, for instance, so that it
wouldn't be a Tk menu but a Cocoa menu. Your approach is much simpler
and works quite well, so congratulations!
Thanks a lot :)
I didn't even thought of implementing the menu in ObjC (otherwise, I wouldn't have done anything), I just though I'd get the event and do the tk_popup.. simply because for both windows and for linux, we get an event and we call tk_popup, so I thought the same would be done for Mac...
It would be nice to do a setMenu and the code would read the Tk menu and its content/options and regenerate a new one with Cocoa, the problem is that it would fail if we modify the menu.. for example, initially all status items are disabled, then once we login, we enable the status items in the menu.. change the 'offline' menu into 'email@domain', and append custom states for that user's profile... the Cocoa menu would need to be updated, and I don't know if we can ask Tk to notify us of modifications to a menu so we can regenerate it...
The best thing would be to wait until Tk-Cocoa is released and try to use the cocoa menu from Tk directly..
by the way, do you know if there's any way (in tcl and in the C API) to see whether we're running Tk-Cocoa or Tk-Carbon ? I don't see it in tcl_platform or any other similar global variable...
KaKaRoTo
 

--Kevin

--
Kevin Walzer
Code by Kevin
http://www.codebykevin.com

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Tcl-mac mailing list


------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Tcl-mac mailing list
tcl-mac@...
https://lists.sourceforge.net/lists/listinfo/tcl-mac

Re: Status bar extension

by Kevin Walzer-5 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

   Hi KaKaRoTo,

>
> cool.. I prefer "and I have a few question" rather than "and I had a few
> crashes" :D

:-)

>
> Well, I tested with and without the blue highlighting, and it felt
> better without it.. the reason is that the highlight is only when you
> click, so when you click, it becomes blue, but then returns to normal,
> and the Tk menu pops on top of it (not even aligned correctly, so
> doesn't look very native), so it just felt weird..

Fair enough. I think the menu popping up above the blue highlight and
grabbing focus would be strange....the current approach is reasonable.

> My plan though is to add a few API calls to allow access to everything
> the real cocoa object gives, like :
> setHighlightMode, setAlternateImage, setTitle, setAttributeTitle, and
> possibly in the very far future : setMenu.
> You can see the whole API here :
> http://developer.apple.com/mac/library/DOCUMENTATION/Cocoa/Reference/ApplicationKit/Classes/NSStatusItem_Class/Reference/Reference.html
> I could probably do that right now withing a few minutes (copy paste a
> function, replace the call to setSomething into a call to
> setWhatever...).. I'll tell you when I update it in SVN.

Thanks! Looking forward to it.
>
> Nope, no menus.. the reason is simple.. a Tk menu is .. a Tk menu (not
> sure if it's custom toplevel window with overrideredirect or if it's an
> actual menu window).. most probably, it's a Carbon menu, which
> definitely won't work into a Cocoa widget which probably expects a Cocoa
> menu.. that's why all you do, is get your callback and when the 'ACTION'
> message is sent, do a :
> tk_popup $menu [winfo pointerx] [winfo pointery]
> Have a look at the code posted by Linus, it does the job..

I didn't actually see any code from Linus...I saw you replied to him,
but I don't think his e-mail went to the list...

Generating the event at the C level and then handling the menu popup in
Tk is definitely the way to go. That's how I implement the "toolbar
hiding" mechanism in my apps--use the <<toolbutton>> event and then use
pack forget/pack to toggle the toolbar's visibility...

>
> Thanks a lot :)
> I didn't even thought of implementing the menu in ObjC (otherwise, I
> wouldn't have done anything), I just though I'd get the event and do the
> tk_popup.. simply because for both windows and for linux, we get an
> event and we call tk_popup, so I thought the same would be done for Mac...
> It would be nice to do a setMenu and the code would read the Tk menu and
> its content/options and regenerate a new one with Cocoa, the problem is
> that it would fail if we modify the menu.. for example, initially all
> status items are disabled, then once we login, we enable the status
> items in the menu.. change the 'offline' menu into 'email@domain', and
> append custom states for that user's profile... the Cocoa menu would
> need to be updated, and I don't know if we can ask Tk to notify us of
> modifications to a menu so we can regenerate it...
> The best thing would be to wait until Tk-Cocoa is released and try to
> use the cocoa menu from Tk directly..

I think just using a Tk menu is the way to go. The Tk-Cocoa code in
support of menus is shorter and less cumbersome than Carbon, but I think
it's just simpler to stick to the Tk level wherever possible.


> by the way, do you know if there's any way (in tcl and in the C API) to
> see whether we're running Tk-Cocoa or Tk-Carbon ? I don't see it in
> tcl_platform or any other similar global variable...


Yes, from the Tk-Cocoa README:

"The Cocoa-based TkAqua can be distinguished from the older Carbon-based
version via the [winfo server .] command, example output on Mac OS X 10.5.7:
     Cocoa-based: CG409.3 Apple AppKit GC 949.46 Mac OS X 1057
     Carbon-based: QD10R30 Apple 1057"

In my apps I look for the "AppKit" string--if there it's Tk-Cocoa,
otherwise it's Carbon.

--Kevin

--
Kevin Walzer
Code by Kevin
http://www.codebykevin.com

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Tcl-mac mailing list
tcl-mac@...
https://lists.sourceforge.net/lists/listinfo/tcl-mac

Re: Status bar extension

by Youness Alaoui-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message



On Thu, Oct 8, 2009 at 6:44 PM, Kevin Walzer <kw@...> wrote:
 Hi KaKaRoTo,



cool.. I prefer "and I have a few question" rather than "and I had a few
crashes" :D

:-)



Well, I tested with and without the blue highlighting, and it felt
better without it.. the reason is that the highlight is only when you
click, so when you click, it becomes blue, but then returns to normal,
and the Tk menu pops on top of it (not even aligned correctly, so
doesn't look very native), so it just felt weird..

Fair enough. I think the menu popping up above the blue highlight and grabbing focus would be strange....the current approach is reasonable.


My plan though is to add a few API calls to allow access to everything
the real cocoa object gives, like :
setHighlightMode, setAlternateImage, setTitle, setAttributeTitle, and
possibly in the very far future : setMenu.
You can see the whole API here :
http://developer.apple.com/mac/library/DOCUMENTATION/Cocoa/Reference/ApplicationKit/Classes/NSStatusItem_Class/Reference/Reference.html
I could probably do that right now withing a few minutes (copy paste a
function, replace the call to setSomething into a call to
setWhatever...).. I'll tell you when I update it in SVN.

Thanks! Looking forward to it.
Ok... it might have taken a few hours instead (testing, bugfixing) but I got it to work! The latest SVN of aMSN has these new APIs :
::statusicon::setTitle
::statusicon::setAlternateImage
::statusicon::setHighlightMode
It's awesome to see a title + icon with an alternate image :)
You can now test the highlight mode and see how it feels.. not so great imho.. but at least now you have a choice!
(command-shift-C in aMSN, then type : [::statusicon::setHighlightMode $::statusicon true] if you need a quick example to try it on)
By the way, I had also done setAttributedTitle, and then realized it's the same as Title.. then later realized that an AttributedTitle is an NSAttributedString where you can have attributes (fonts, size, color..) on your string.. since I didn't know exactly how I could give those attributes to the extension, I decided to remove that API for now since it's useless... if anyone has more knowledge of AttributedStrings and how we could use them from a Tcl extension, then feel free to help :)
 


Nope, no menus.. the reason is simple.. a Tk menu is .. a Tk menu (not
sure if it's custom toplevel window with overrideredirect or if it's an
actual menu window).. most probably, it's a Carbon menu, which
definitely won't work into a Cocoa widget which probably expects a Cocoa
menu.. that's why all you do, is get your callback and when the 'ACTION'
message is sent, do a :
tk_popup $menu [winfo pointerx] [winfo pointery]
Have a look at the code posted by Linus, it does the job..

I didn't actually see any code from Linus...I saw you replied to him, but I don't think his e-mail went to the list...
I checked, he did CC the mailing list, but looking at public archives, it looks like it didn't get through, maybe he's not registered or something and it awaits moderation, or  sourceforge's spam filter caught it...

Generating the event at the C level and then handling the menu popup in Tk is definitely the way to go. That's how I implement the "toolbar hiding" mechanism in my apps--use the <<toolbutton>> event and then use pack forget/pack to toggle the toolbar's visibility...



Thanks a lot :)
I didn't even thought of implementing the menu in ObjC (otherwise, I
wouldn't have done anything), I just though I'd get the event and do the
tk_popup.. simply because for both windows and for linux, we get an
event and we call tk_popup, so I thought the same would be done for Mac...
It would be nice to do a setMenu and the code would read the Tk menu and
its content/options and regenerate a new one with Cocoa, the problem is
that it would fail if we modify the menu.. for example, initially all
status items are disabled, then once we login, we enable the status
items in the menu.. change the 'offline' menu into 'email@domain', and
append custom states for that user's profile... the Cocoa menu would
need to be updated, and I don't know if we can ask Tk to notify us of
modifications to a menu so we can regenerate it...
The best thing would be to wait until Tk-Cocoa is released and try to
use the cocoa menu from Tk directly..

I think just using a Tk menu is the way to go. The Tk-Cocoa code in support of menus is shorter and less cumbersome than Carbon, but I think it's just simpler to stick to the Tk level wherever possible.
yeah, I wouldn't want to implement that, hehe.. but in the future, we could have a "setMenu" call that would only work if you use Tk-Cocoa and it would just feed it the NSMenu used internally by Cocoa.. although there might be complications in case the menu is destroyed... anyways, we'll see when the time comes, for now it's good enough I think!



by the way, do you know if there's any way (in tcl and in the C API) to
see whether we're running Tk-Cocoa or Tk-Carbon ? I don't see it in
tcl_platform or any other similar global variable...


Yes, from the Tk-Cocoa README:

"The Cocoa-based TkAqua can be distinguished from the older Carbon-based
version via the [winfo server .] command, example output on Mac OS X 10.5.7:
   Cocoa-based:        CG409.3 Apple AppKit GC 949.46 Mac OS X 1057
   Carbon-based:       QD10R30 Apple 1057"

In my apps I look for the "AppKit" string--if there it's Tk-Cocoa, otherwise it's Carbon.
cool.. thanks, I checked the README but it's not there.. 
ah.. finally found it.. checked the README, then tk/README, but didn't check tk/macosx/README.. hehe
but it doesn't givea solution for the "and in the C API".. if I am to add a setMenu command to the statusicon extension when we use Cocoa, I'd need to get that info from the C level..
by the way, I can't seem to get my statusicon.dylib to load into Tk-Cocoa, any idea on how to fix that (I seem to remember finding the solution a while ago, but I just can't find it again :-( )
Thanks!
KaKaRoTo
 


--Kevin

--
Kevin Walzer
Code by Kevin
http://www.codebykevin.com


------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Tcl-mac mailing list
tcl-mac@...
https://lists.sourceforge.net/lists/listinfo/tcl-mac

Re: Status bar extension

by Linus Nyberg-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.

Sorry, this email should have come earlier in the conversation, but my mails keep getting caught by the spam filter on this list… No idea why – any tips appreciated. L

The problem was, like KaKaRoTo wrote, to not destroy the popup. Here is the working “my_callback”:

 

proc my_callback {action} {

                      puts "action = $action"

                      if {$action == "ACTION"} {

                                            if {[winfo exists .popup]} {

                                                                 destroy .popup

                                            }

                                            set m [menu .popup]

                                            $m add command -label "Do something" -command {puts "Do Something"}

                                            $m add command -label "Do something else" -command {puts "Do Something Else"}

                                           

                                            tk_popup .popup [winfo pointerx .] [winfo pointery .]

                      }

}

 

Cheers,

 

Linus

 


From: Linus Nyberg [mailto:linus@...]
Sent: den 7 oktober 2009 13:13
To: 'Youness Alaoui'; tcl-mac@...
Subject: Re: [MACTCL] Status bar extension

 

Hi Youness!

 

This is really really cool stuff.

I tested it but got tempted to create some kind of popup when the user clicks on the status icon… See the attached screenshot.

It didn’t work all the way for me, and I was wondering if you have any tips? If you are launching some kind of popup menu and making it work?

 

Here’s the problem: When Tk launches the popup, it seems to lose focus or something (because the status bar takes focus?), so when I press any of the menu items, the commands behind them are still not run.

 

Maybe someone else knows how to force focus to the popup…? “focus –force .popup”, grab etc does not work since the Tk app itself doesn’t seem to have focus.

 

Here’s the example code:

 

#######################

cd [file dirname [info script]]

cd .. ;# => Resources

cd .. ;# => Contents

cd .. ;# => App folder

set ::MAC_APP_FOLDER [pwd]

 

proc mac_startup {} {

                      console show

                     

                      load [file join $::MAC_APP_FOLDER Contents Resources Scripts statusicon.dylib]

                     

                      wm geometry . 400x400

                     

                      frame .f -width 400 -height 400 -bg grey70

                      place .f -x 0 -y 0 -anchor nw

 

                      set si_id [::statusicon::create my_callback]

                     

                      ::statusicon::setImage $si_id [file join $::MAC_APP_FOLDER Contents Resources Scripts 6_contact_b.gif]

                      ::statusicon::setTooltip $si_id "Test tooltip"

                      ::statusicon::setVisible $si_id 1

}

 

proc my_callback {action} {

                      puts "action = $action"

                      if {$action == "ACTION"} {

                                            set m [menu .popup]

                                            $m add command -label "Do something" -command {puts "Do Something"}

                                            $m add command -label "Do something else" -command {puts "Do Something Else"}

                                           

                                            tk_popup .popup [winfo pointerx .] [winfo pointery .]

                                            destroy .popup

                      }

}

 

after 5 mac_startup

#######################

 


From: Youness Alaoui [mailto:kakaroto@...]
Sent: den 7 oktober 2009 11:49
To: tcl-mac@... List
Subject: [MACTCL] Status bar extension

 

Hi all,

 

Today I took on the task of writing an extension for Mac to allow Tcl/Tk applications to have a status icon in the status bar (the right part of the menu bar). It was quite interesting, I used some code from gtk's implementation, and it seems to work fine now! 

If anyone is interested, you can find it in amsn's latest SVN : http://amsn.svn.sourceforge.net/viewvc/amsn/trunk/amsn/utils/macosx/statusicon/

The API is quite simple :

- ::statusicon::create callback

creates a status icon (invisible) and will use the callback specified for notifying Tcl of click actions.

Returns an identifier for the status icon,

- ::statusicon::setImage statusicon imagePath

Sets the image to show in the status bar, takes a statusicon identifier (returned by ::statusicon::create) and the path to an image (not an actual Tk image, but the relative/absolute path to an image file). PNG files seem to work file, whatever works with NSImage should work here.

- ::statusicon::setTooltip statusicon tooltip

Sets the tooltip on the statusicon

- ::statusicon::setVisible statusicon visible

Takes a boolean and shows/hides the status icon

- ::statusicon::destroy statusicon

Destroy a previously created statusicon

 

The clicks are being reported to Tcl through the callback specified in the call to ::statusicon::create and it's format is :

proc callback { action } {

  if {$msg == "ACTION" } {

     # Single click

  } elseif {$msg == "DOUBLE_ACTION" } {

     # double click

  }

}

 

I hope this is useful to somebody else!

 

Take care,

KaKaRoTo


------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Tcl-mac mailing list
tcl-mac@...
https://lists.sourceforge.net/lists/listinfo/tcl-mac

Re: Status bar extension

by Kevin Walzer-5 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


> Ok... it might have taken a few hours instead (testing, bugfixing) but I
> got it to work! The latest SVN of aMSN has these new APIs :
> ::statusicon::setTitle
> ::statusicon::setAlternateImage
> ::statusicon::setHighlightMode

Good, looking forward to trying these.

> It's awesome to see a title + icon with an alternate image :)
> You can now test the highlight mode and see how it feels.. not so great
> imho.. but at least now you have a choice!
> (command-shift-C in aMSN, then type : [::statusicon::setHighlightMode
> $::statusicon true] if you need a quick example to try it on)

I tried the blue and I agree it's better without it, especially if
there's no way to preserve the blue highlight while the menu is visible.
Seeing the blue disappear when the menu pops up looks wieird.

> By the way, I had also done setAttributedTitle, and then realized it's
> the same as Title.. then later realized that an AttributedTitle is an
> NSAttributedString where you can have attributes (fonts, size, color..)
> on your string.. since I didn't know exactly how I could give those
> attributes to the extension, I decided to remove that API for now since
> it's useless... if anyone has more knowledge of AttributedStrings and
> how we could use them from a Tcl extension, then feel free to help :)

AttributedStrings are similar in concept to Tk's text tags, as far as I
can tell. I doubt we'd gain much by using attributedstings in Tk.

>
>
> yeah, I wouldn't want to implement that, hehe.. but in the future, we
> could have a "setMenu" call that would only work if you use Tk-Cocoa and
> it would just feed it the NSMenu used internally by Cocoa.. although
> there might be complications in case the menu is destroyed... anyways,
> we'll see when the time comes, for now it's good enough I think!

Agreed.

>
>
> but it doesn't givea solution for the "and in the C API".. if I am to
> add a setMenu command to the statusicon extension when we use Cocoa, I'd
> need to get that info from the C level..

Once 8.6 is out, you'll be able to tell by looking at the patchlevel of
Tcl/Tk that you're compiling against. 8.5 Tk-Cocoa is a fork, but
Tk-Cocoa 8.6 will the mainline of development.


> by the way, I can't seem to get my statusicon.dylib to load into
> Tk-Cocoa, any idea on how to fix that (I seem to remember finding the
> solution a while ago, but I just can't find it again :-( )
>

Are you using stubs to build the extension? If your build of Tk-Cocoa is
based on 8.6 and you're hard-building the dylib against 8.5, I don't
think it would work with 8.6. That's the only thing I can think of.

Kevin


--
Kevin Walzer
Code by Kevin
http://www.codebykevin.com

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Tcl-mac mailing list
tcl-mac@...
https://lists.sourceforge.net/lists/listinfo/tcl-mac