wxTaskBarIcon using a TFF Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
ChronoGraff
Knows some wx things
Knows some wx things
Posts: 42
Joined: Wed Apr 22, 2015 5:42 pm

wxTaskBarIcon using a TFF

Post by ChronoGraff »

Hi guys, my first post. **edit** not my first post... hmm... :shock:

This is driving me crazy, I have looked at the Resources of other apps and notice tiff's being used.

My basic code is:

Code: Select all

// .xpm format
if (!_systemTray->SetIcon(wxICON(tray_icon), "Today's tasks."))
{
    // Deal with error
}

// .tiff format
wxIcon icon(_("tray_icon"), wxBITMAP_TYPE_TIFF);
if (!_systemTray->SetIcon(icon, "Today's tasks."))
{
    // Deal with error
}
And the trace:

Code: Select all

Exception Type:        EXC_BAD_ACCESS (SIGSEGV)
Exception Codes:       KERN_INVALID_ADDRESS at 0x0000000000000058
Exception Note:        EXC_CORPSE_NOTIFY

VM Regions Near 0x58:
--> 
    __TEXT                 00000001091da000-000000010925d000 [  524K] r-x/rwx SM=COW  /Volumes/VOLUME/*/ChronoGraff.app/Contents/MacOS/ChronoGraff

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0   libwx_osx_cocoau_core-3.1.dylib	0x0000000109578bb3[b] wxBitmap::GetNSImage() const + 51[/b]
1   libwx_osx_cocoau_adv-3.1.dylib	0x0000000109a87ead wxTaskBarIconCustomStatusItemImpl::SetIcon(wxIcon const&, wxString const&) + 429
I am assuming that line 0 (bolded) is where the issue lies.

I have NO idea how to use a tiff instead of xpm, or in fact load a taskbaricon of another format other than xpm. It's a real pain at the moment, this is a kind of last resort posting here as I have spent a few days trying all manner of solutions to no avail.

Can anyone help? Thanks in advance
User avatar
doublemax
Moderator
Moderator
Posts: 19114
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxTaskBarIcon using a TFF

Post by doublemax »

Code: Select all

wxIcon icon(_("tray_icon"), wxBITMAP_TYPE_TIFF);
After this you should check if the icon is ok before using it ( icon.IsOk() ). Most likely it's not.

Make sure the file is found. Is the filename really "tray_icon", without extension?

Another possibility is that the TIFF image handler is not loaded. Did you call wxInitAllImageHandlers() ?
Use the source, Luke!
ChronoGraff
Knows some wx things
Knows some wx things
Posts: 42
Joined: Wed Apr 22, 2015 5:42 pm

Re: wxTaskBarIcon using a TFF

Post by ChronoGraff »

doublemax wrote:

Code: Select all

wxIcon icon(_("tray_icon"), wxBITMAP_TYPE_TIFF);
After this you should check if the icon is ok before using it ( icon.IsOk() ). Most likely it's not.

Make sure the file is found. Is the filename really "tray_icon", without extension?

Another possibility is that the TIFF image handler is not loaded. Did you call wxInitAllImageHandlers() ?
Hi thanks for the reply, and I get this;

I also changed "tray_icon" to "tray_icon.tiff"

Code: Select all

16:06:28: can't open file 'tray_icon.tiff' (error 2: No such file or directory)
16:06:28: Failed to load image from file "tray_icon.tiff".
I also have wxInitAllImageHandlers() called in constructer.

One thing, the path? Should the path be relative, or? Is there something I'm missing. It's not finding the file. IsOk() was perfect to figure out what was wrong. Thanks for that! I should have noticed that, just been working hard and a bit tired.

Making headway now at least I know it can't find the file!
User avatar
doublemax
Moderator
Moderator
Posts: 19114
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxTaskBarIcon using a TFF

Post by doublemax »

Using relative paths is often unreliable, better use wxStandardPaths to build an absolute path.

E.g.

Code: Select all

#include <wx/stdpaths.h>
...
wxString filepath = wxStandardPaths::Get().GetDataDir() + "/tray_icon.tiff";
wxLogMessage("trying to load: %s", filepath );
Use the source, Luke!
ChronoGraff
Knows some wx things
Knows some wx things
Posts: 42
Joined: Wed Apr 22, 2015 5:42 pm

Re: wxTaskBarIcon using a TFF

Post by ChronoGraff »

Thanks for the help! Appreciated!
ChronoGraff
Knows some wx things
Knows some wx things
Posts: 42
Joined: Wed Apr 22, 2015 5:42 pm

Re: wxTaskBarIcon using a TFF

Post by ChronoGraff »

Flip me... spoke too soon... the TIFF is loading, everything is fine BUT

Code: Select all

17:25:16: Unknown field with tag 37724 (0x935c) encountered (in module "TIFFReadDirectory")
17:25:16: Unknown field with tag 37724 (0x935c) encountered (in module "TIFFReadDirectory")
I'm using latest version of libtiff.

Sorted, on OS X use

Code: Select all

tiffutil -cathidpicheck <files> -out <name>.tiff
Taken from https://developer.apple.com/library/con ... 02-CH7-SW4
User avatar
doublemax
Moderator
Moderator
Posts: 19114
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxTaskBarIcon using a TFF

Post by doublemax »

In wxWidgets you can suppress these kind of warning messages by creating an instance of wxLogNull on the stack.

http://docs.wxwidgets.org/trunk/classwx_log_null.html
Use the source, Luke!
Post Reply