Toolbar button no response after disable/re-enable unless...

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
tt3
Earned a small fee
Earned a small fee
Posts: 10
Joined: Tue Jan 11, 2011 10:19 pm

Toolbar button no response after disable/re-enable unless...

Post by tt3 »

I have a toggle toolbar button. I'd like to achieve this:
Upon clicking on it, it will disable itself and start a 1-second timer. When the timer is called, it will re-enable that same button.

This only works if I click the button, move the mouse pointer outside of the button and back, then the button will respond.

If I click the button, leave the mouse pointer where it is, wait for that 1-second timer period, I can see that the button is enabled. But if I click (without moving the mouse pointer outside), there's no response. How to fix this? (For now, I'd prefer avoid using the update window UI method.)

Any help is appreciated. Here's the code (runs on wx2.8 Hardy):

Code: Select all

  EVT_TOOL(ID_GRAB, Frame::OnGrab)
  EVT_TIMER(ID_TIMER, Frame::OnTimer)

void Frame::OnGrab(class wxCommandEvent&) {
  toolbar_->EnableTool(ID_GRAB, false);
  timer_.Start(1000);
}
void Frame::OnTimer(wxTimerEvent& event) {
  timer_.Stop();
  toolbar_->EnableTool(ID_GRAB, true);
}
User avatar
doublemax
Moderator
Moderator
Posts: 19118
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Toolbar button no response after disable/re-enable unles

Post by doublemax »

Try calling Realize() and/or Refresh() on the toolbar after changing the tool status.
Use the source, Luke!
tt3
Earned a small fee
Earned a small fee
Posts: 10
Joined: Tue Jan 11, 2011 10:19 pm

Re: Toolbar button no response after disable/re-enable unles

Post by tt3 »

Tried Realize(), Refresh(), and combination, none worked.
User avatar
doublemax
Moderator
Moderator
Posts: 19118
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Toolbar button no response after disable/re-enable unles

Post by doublemax »

Which platform and wx version?

I just tested this on Windows with wx 2.8.12 and it worked fine.
Use the source, Luke!
tt3
Earned a small fee
Earned a small fee
Posts: 10
Joined: Tue Jan 11, 2011 10:19 pm

Re: Toolbar button no response after disable/re-enable unles

Post by tt3 »

It's wx2.8.11 on Ubuntu 8.04.
tt3
Earned a small fee
Earned a small fee
Posts: 10
Joined: Tue Jan 11, 2011 10:19 pm

Re: Toolbar button no response after disable/re-enable unles

Post by tt3 »

I just did a quick test, and Yes, it works on Windows. But not on my version of linux (Ubuntu Hardy).
Here's the complete code of the quick test, if anyone can give it a try on their ubuntu box. Thanks.

Code: Select all

#include <wx/wx.h>
#include <wx/artprov.h>
#include <wx/timer.h>

class App : public wxApp {
 public:
  bool OnInit();
};

class Frame : public wxFrame {
 public:
  enum {
    ID_ABOUT = wxID_HIGHEST + 1,
    ID_TIMER,
    ID_GRAB,
  };
  Frame();

 private:
  void OnTimer(class wxTimerEvent&);
  void OnGrab(class wxCommandEvent&);
  DECLARE_EVENT_TABLE()
  wxToolBar* toolbar_;
  wxTimer timer_;
};

IMPLEMENT_APP(App)

bool App::OnInit() {
  Frame* frame = new Frame;
  frame->Show();
  return true;
}

BEGIN_EVENT_TABLE(Frame, wxFrame)
  EVT_TIMER(ID_TIMER, Frame::OnTimer)
  EVT_TOOL(ID_GRAB, Frame::OnGrab)
END_EVENT_TABLE()

Frame::Frame()
    : wxFrame(NULL, wxID_ANY, wxT("test toolbar")),
      timer_(this, ID_TIMER) {
  toolbar_ = CreateToolBar(wxTB_DOCKABLE|wxTB_TEXT|wxTB_NO_TOOLTIPS);
  toolbar_->AddTool(ID_GRAB, _T("Grab"), wxArtProvider::GetBitmap(wxART_FIND),
                   _T("Grab?"), wxITEM_CHECK);
  toolbar_->Realize();
}

void Frame::OnTimer(wxTimerEvent& event) {
  timer_.Stop();
  toolbar_->EnableTool(ID_GRAB, true);
  //toolbar_->SetFocus();
  //toolbar_->Realize();
  //toolbar_->Refresh();
}

void Frame::OnGrab(class wxCommandEvent&) {
  toolbar_->EnableTool(ID_GRAB, false);
  timer_.Start(1000);
}
Edit: compilation fix for unicode builds
User avatar
doublemax
Moderator
Moderator
Posts: 19118
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Toolbar button no response after disable/re-enable unles

Post by doublemax »

Just to make sure: Did you use the wxGTK port? (and not GTK1, X11 or Universal)
Use the source, Luke!
tt3
Earned a small fee
Earned a small fee
Posts: 10
Joined: Tue Jan 11, 2011 10:19 pm

Re: Toolbar button no response after disable/re-enable unles

Post by tt3 »

I think it is wxGTK. The wxWidgets directory has name "wxGTK-2.8.11". Other than that I don't know where to check for sure.
User avatar
evstevemd
Part Of The Furniture
Part Of The Furniture
Posts: 2409
Joined: Wed Jan 28, 2009 11:57 am
Location: United Republic of Tanzania

Re: Toolbar button no response after disable/re-enable unles

Post by evstevemd »

try using wx-config --query-toolkit
In my machine it displays gtk2
Chief Justice: We have trouble dear citizens!
Citizens: What it is his honor?
Chief Justice:Our president is an atheist, who will he swear to?
DavidHart
Site Admin
Site Admin
Posts: 4253
Joined: Thu Jan 12, 2006 6:23 pm
Location: IoW, UK

Re: Toolbar button no response after disable/re-enable unles

Post by DavidHart »

Hi,
If I click the button, leave the mouse pointer where it is, wait for that 1-second timer period, I can see that the button is enabled. But if I click (without moving the mouse pointer outside), there's no response.
That's a bit ambiguous. I presume you mean "then move outside the button and leave the mouse pointer where it is".

If so, it works for me, on a rather more recent Linux (are you really still using Hardy? ;) ) and wxGTK-2.8.12.

Regards,

David
Post Reply