wxTimer and the new dynamic event system... 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.
ouch67
Earned some good credits
Earned some good credits
Posts: 134
Joined: Sun Mar 23, 2008 12:09 am

wxTimer and the new dynamic event system...

Post by ouch67 » Wed Jul 13, 2011 8:03 pm

So I'm trying to get these 2 to work together.

I can't seem to find one example of using a wxtimer with the new bind event commands.

The wxTimerEvent also doesn't seem to have an event type assigned to it which is also throwing me off...

any help would be appreciated.

catalin
Moderator
Moderator
Posts: 1529
Joined: Wed Nov 12, 2008 7:23 am
Location: Romania

Re: wxTimer and the new dynamic event system...

Post by catalin » Wed Jul 13, 2011 8:10 pm

The event type is wxEVT_TIMER. The rest should be just like using Bind in any other situation (connect the timer's target to that event type).

ouch67
Earned some good credits
Earned some good credits
Posts: 134
Joined: Sun Mar 23, 2008 12:09 am

Re: wxTimer and the new dynamic event system...

Post by ouch67 » Wed Jul 13, 2011 8:36 pm

ok, I think I got it now except the bind command isn't working.

It's telling me it's out of scope. I'm calling it in OnInit, should I not use it there? Where do you set bindings up at?

my code so far is this:

Code: Select all

    wxTimer* m_timer;
    m_timer = new wxTimer();
    m_timer->SetOwner(this);

    Bind(wxEVT_TIMER, &slashanim, this);
    m_timer->Start(3000);

catalin
Moderator
Moderator
Posts: 1529
Joined: Wed Nov 12, 2008 7:23 am
Location: Romania

Re: wxTimer and the new dynamic event system...

Post by catalin » Wed Jul 13, 2011 8:59 pm

What exactly is out of scope?
Binding there is ok.
Is m_timer supposed to be a member variable? If yes then you probably don't want to do
wxTimer* m_timer;

ouch67
Earned some good credits
Earned some good credits
Posts: 134
Joined: Sun Mar 23, 2008 12:09 am

Re: wxTimer and the new dynamic event system...

Post by ouch67 » Wed Jul 13, 2011 9:01 pm

it specifically says the bind command itself is... which is a bit scary... heh...

I'm using the SVN branch of 2.9

The log says:

Code: Select all

|359|error: 'Bind' was not declared in this scope|
I've also tried to declare:

#include <wx/event.h>

I still get the same problem

User avatar
doublemax
Moderator
Moderator
Posts: 14511
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxTimer and the new dynamic event system...

Post by doublemax » Wed Jul 13, 2011 9:12 pm

Which platform/compiler? Bind is not available everywhere.

Code: Select all

/*
   If this is defined, wxEvtHandler::Bind<>() is available (not all compilers
   have the required template support for this and in particular under Windows
   where only g++ and MSVC >= 7 currently support it.
 */
#if wxCHECK_GCC_VERSION(3, 2) || wxCHECK_VISUALC_VERSION(7)
    #define wxHAS_EVENT_BIND
#endif
Use the source, Luke!

ouch67
Earned some good credits
Earned some good credits
Posts: 134
Joined: Sun Mar 23, 2008 12:09 am

Re: wxTimer and the new dynamic event system...

Post by ouch67 » Wed Jul 13, 2011 9:14 pm

I'm using TDM mingw 4.5.2 (32bit) on windows 7 64bit.

User avatar
doublemax
Moderator
Moderator
Posts: 14511
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxTimer and the new dynamic event system...

Post by doublemax » Wed Jul 13, 2011 9:21 pm

Can you check if the above check evaluates as true that wxHAS_EVENT_BIND gets defined?
Use the source, Luke!

ouch67
Earned some good credits
Earned some good credits
Posts: 134
Joined: Sun Mar 23, 2008 12:09 am

Re: wxTimer and the new dynamic event system...

Post by ouch67 » Wed Jul 13, 2011 9:34 pm

It's not defined, I wonder why?

also I did a search for:

#define wxHAS_EVENT_BIND
and it didn't come up with anything in the 2.9 trunk, where did you find that code snippet?

User avatar
doublemax
Moderator
Moderator
Posts: 14511
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxTimer and the new dynamic event system...

Post by doublemax » Wed Jul 13, 2011 10:22 pm

It's in include/wx/features.h

I hope you didn't get the SVN branch from wxWidgets/branches/WX_2_9_0_BRANCH
You want wxWidgets/trunk

Just making sure...
Use the source, Luke!

ouch67
Earned some good credits
Earned some good credits
Posts: 134
Joined: Sun Mar 23, 2008 12:09 am

Re: wxTimer and the new dynamic event system...

Post by ouch67 » Wed Jul 13, 2011 10:29 pm

and yes I have that branch of 2.9.

yeah that code is not there:

Code: Select all

/**
*  Name:        wx/features.h
*  Purpose:     test macros for the features which might be available in some
*               wxWidgets ports but not others
*  Author:      Vadim Zeitlin
*  Modified by: Ryan Norton (Converted to C)
*  Created:     18.03.02
*  RCS-ID:      $Id: features.h 60526 2009-05-06 11:42:16Z VZ $
*  Copyright:   (c) 2002 Vadim Zeitlin <[email protected]>
*  Licence:     wxWindows licence
*/

/* THIS IS A C FILE, DON'T USE C++ FEATURES (IN PARTICULAR COMMENTS) IN IT */

#ifndef _WX_FEATURES_H_
#define _WX_FEATURES_H_

/*  radio menu items are currently not implemented in wxMotif, use this
    symbol (kept for compatibility from the time when they were not implemented
    under other platforms as well) to test for this */
#if !defined(__WXMOTIF__)
    #define wxHAS_RADIO_MENU_ITEMS
#else
    #undef wxHAS_RADIO_MENU_ITEMS
#endif

/*  the raw keyboard codes are generated under wxGTK and wxMSW only */
#if defined(__WXGTK__) || defined(__WXMSW__) || defined(__WXMAC__) \
    || defined(__WXDFB__)
    #define wxHAS_RAW_KEY_CODES
#else
    #undef wxHAS_RAW_KEY_CODES
#endif

/*  taskbar is implemented in the major ports */
#if defined(__WXMSW__) || defined(__WXCOCOA__) \
    || defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXX11__) \
    || defined(__WXOSX_MAC__) || defined(__WXCOCOA__)
    #define wxHAS_TASK_BAR_ICON
#else
    #undef wxUSE_TASKBARICON
    #define wxUSE_TASKBARICON 0
    #undef wxHAS_TASK_BAR_ICON
#endif

/*  wxIconLocation appeared in the middle of 2.5.0 so it's handy to have a */
/*  separate define for it */
#define wxHAS_ICON_LOCATION

/*  same for wxCrashReport */
#ifdef __WXMSW__
    #define wxHAS_CRASH_REPORT
#else
    #undef wxHAS_CRASH_REPORT
#endif

/*  wxRE_ADVANCED is not always available, depending on regex library used
 *  (it's unavailable only if compiling via configure against system library) */
#ifndef WX_NO_REGEX_ADVANCED
    #define wxHAS_REGEX_ADVANCED
#else
    #undef wxHAS_REGEX_ADVANCED
#endif

/* Pango-based ports and wxDFB use UTF-8 for text and font encodings
 * internally and so their fonts can handle any encodings: */
#if wxUSE_PANGO || defined(__WXDFB__)
    #define wxHAS_UTF8_FONTS
#endif

/* This is defined when the underlying toolkit handles tab traversal natively.
   Otherwise we implement it ourselves in wxControlContainer. */
#ifdef __WXGTK20__
    #define wxHAS_NATIVE_TAB_TRAVERSAL
#endif

/* This is defined when the compiler provides some type of extended locale
   functions.  Otherwise, we implement them ourselves to only support the
   'C' locale */
#if defined(HAVE_LOCALE_T) || \
    (wxCHECK_VISUALC_VERSION(8) && !defined(__WXWINCE__))
    #define wxHAS_XLOCALE_SUPPORT
#else
    #undef wxHAS_XLOCALE_SUPPORT
#endif

/* Direct access to bitmap data is not implemented in all ports yet */
#if defined(__WXGTK20__) || defined(__WXMAC__) || defined(__WXDFB__) || \
        defined(__WXMSW__)

    /*
       These compilers can't deal with templates in wx/rawbmp.h:
        - HP aCC for PA-RISC
        - Watcom < 1.8
     */
    #if !wxONLY_WATCOM_EARLIER_THAN(1, 8) && \
        !(defined(__HP_aCC) && defined(__hppa))
        #define wxHAS_RAW_BITMAP
    #endif
#endif

/* also define deprecated synonym which exists for compatibility only */
#ifdef wxHAS_RAW_BITMAP
    #define wxHAVE_RAW_BITMAP
#endif

#endif /*  _WX_FEATURES_H_ */

what svn branch did you get that from?

User avatar
doublemax
Moderator
Moderator
Posts: 14511
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxTimer and the new dynamic event system...

Post by doublemax » Wed Jul 13, 2011 10:43 pm

Strange...

Code: Select all

/**
*  Name:        wx/features.h
*  Purpose:     test macros for the features which might be available in some
*               wxWidgets ports but not others
*  Author:      Vadim Zeitlin
*  Modified by: Ryan Norton (Converted to C)
*  Created:     18.03.02
*  RCS-ID:      $Id: features.h 60526 2009-05-06 11:42:16Z VZ $
*  Copyright:   (c) 2002 Vadim Zeitlin <[email protected]>
*  Licence:     wxWindows licence
*/

/* THIS IS A C FILE, DON'T USE C++ FEATURES (IN PARTICULAR COMMENTS) IN IT */

#ifndef _WX_FEATURES_H_
#define _WX_FEATURES_H_

/*  radio menu items are currently not implemented in wxMotif, use this
    symbol (kept for compatibility from the time when they were not implemented
    under other platforms as well) to test for this */
#if !defined(__WXMOTIF__)
    #define wxHAS_RADIO_MENU_ITEMS
#else
    #undef wxHAS_RADIO_MENU_ITEMS
#endif

/*  the raw keyboard codes are generated under wxGTK and wxMSW only */
#if defined(__WXGTK__) || defined(__WXMSW__) || defined(__WXMAC__) \
    || defined(__WXDFB__)
    #define wxHAS_RAW_KEY_CODES
#else
    #undef wxHAS_RAW_KEY_CODES
#endif

/*  taskbar is implemented in the major ports */
#if defined(__WXMSW__) || defined(__WXCOCOA__) \
    || defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXX11__) \
    || defined(__WXOSX_MAC__) || defined(__WXCOCOA__)
    #define wxHAS_TASK_BAR_ICON
#else
    #undef wxUSE_TASKBARICON
    #define wxUSE_TASKBARICON 0
    #undef wxHAS_TASK_BAR_ICON
#endif

/*  wxIconLocation appeared in the middle of 2.5.0 so it's handy to have a */
/*  separate define for it */
#define wxHAS_ICON_LOCATION

/*  same for wxCrashReport */
#ifdef __WXMSW__
    #define wxHAS_CRASH_REPORT
#else
    #undef wxHAS_CRASH_REPORT
#endif

/*  wxRE_ADVANCED is not always available, depending on regex library used
 *  (it's unavailable only if compiling via configure against system library) */
#ifndef WX_NO_REGEX_ADVANCED
    #define wxHAS_REGEX_ADVANCED
#else
    #undef wxHAS_REGEX_ADVANCED
#endif

/* Pango-based ports and wxDFB use UTF-8 for text and font encodings
 * internally and so their fonts can handle any encodings: */
#if wxUSE_PANGO || defined(__WXDFB__)
    #define wxHAS_UTF8_FONTS
#endif

/* This is defined when the underlying toolkit handles tab traversal natively.
   Otherwise we implement it ourselves in wxControlContainer. */
#ifdef __WXGTK20__
    #define wxHAS_NATIVE_TAB_TRAVERSAL
#endif

/* This is defined when the compiler provides some type of extended locale
   functions.  Otherwise, we implement them ourselves to only support the
   'C' locale */
#if defined(HAVE_LOCALE_T) || \
    (wxCHECK_VISUALC_VERSION(8) && !defined(__WXWINCE__))
    #define wxHAS_XLOCALE_SUPPORT
#else
    #undef wxHAS_XLOCALE_SUPPORT
#endif

/* Direct access to bitmap data is not implemented in all ports yet */
#if defined(__WXGTK20__) || defined(__WXMAC__) || defined(__WXDFB__) || \
        defined(__WXMSW__)

    /*
       These compilers can't deal with templates in wx/rawbmp.h:
        - HP aCC for PA-RISC
        - Watcom < 1.8
     */
    #if !wxONLY_WATCOM_EARLIER_THAN(1, 8) && \
        !(defined(__HP_aCC) && defined(__hppa))
        #define wxHAS_RAW_BITMAP
    #endif
#endif

/* also define deprecated synonym which exists for compatibility only */
#ifdef wxHAS_RAW_BITMAP
    #define wxHAVE_RAW_BITMAP
#endif

/*
   If this is defined, wxEvtHandler::Bind<>() is available (not all compilers
   have the required template support for this and in particular under Windows
   where only g++ and MSVC >= 7 currently support it.
 */
#if wxCHECK_GCC_VERSION(3, 2) || wxCHECK_VISUALC_VERSION(7)
    #define wxHAS_EVENT_BIND
#endif


#endif /*  _WX_FEATURES_H_ */
From http://svn.wxwidgets.org/svn/wx/wxWidgets/trunk
Use the source, Luke!

ouch67
Earned some good credits
Earned some good credits
Posts: 134
Joined: Sun Mar 23, 2008 12:09 am

Re: wxTimer and the new dynamic event system...

Post by ouch67 » Wed Jul 13, 2011 11:00 pm

when I compile and use the svn trunk version i get a no matching function call for Bind.

and it says I do have wxHAS_EVENT_BIND defined...

User avatar
doublemax
Moderator
Moderator
Posts: 14511
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxTimer and the new dynamic event system...

Post by doublemax » Wed Jul 13, 2011 11:08 pm

"no matching function call" is a different error. I guess just the parameter list is wrong.

http://docs.wxwidgets.org/trunk/classwx ... e03db66e5c
Use the source, Luke!

ouch67
Earned some good credits
Earned some good credits
Posts: 134
Joined: Sun Mar 23, 2008 12:09 am

Re: wxTimer and the new dynamic event system...

Post by ouch67 » Thu Jul 14, 2011 3:02 pm

I actually just had a typo in my function declaration... but it works great, thanks again.

But why doesn't WX_2_9_0_BRANCH have these dynamic events? it's a function introduced in 2.9 right?

Post Reply