Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7127811
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T11:04:17+00:00 2026-05-28T11:04:17+00:00

In my application I use a function to show GtkInfoBars with a timeout (as

  • 0

In my application I use a function to show GtkInfoBars with a timeout (as described https://stackoverflow.com/a/1309257/406281) thanks to glib.timeout_add_seconds().

I understand that glib.timeout_add_seconds() is supposed to set a function to be called at regular intervals until said function returns False.

I’m not doing that, but everything works as expected. It’s perfectly simple. Here’s my code:

def infobar(self, message, msgtype=gtk.MESSAGE_INFO, timeout=5):
    bar = gtk.InfoBar()
    bar.set_message_type(msgtype)
    bar.add_button(gtk.STOCK_OK, gtk.RESPONSE_OK)
    bar.connect("response", lambda *args: bar.hide())
    self.vb2.pack_end(bar, False, False)
    label = gtk.Label()
    label.set_markup(message)
    content = bar.get_content_area()
    content.add(label)
    label.show()
    bar.show()
    if timeout:
        glib.timeout_add_seconds(timeout, bar.hide)

SO. Question time. Look at what I did in the last line. Simply put, is this okay? Will the timeout destroy itself after the second call to bar.hide() fails? Or am I accumulating extra neutered timeouts that will wake up every 5 seconds [technically] using up resources?


As an addendum:

If, as I suspect, this is bad, and I really do need to return False to destroy the timeouts, I need some help — I can’t figure out how to play around with the code in order to satisfy these conditions: I need to allow multiple InfoBars at the same time, with each still staying connected to their own timer and button-response signal (as the code is now) OR I need each new InfoBar to replace any previous one (I can’t figure out how to do this without inheriting the timer from the previous InfoBar–it gets messy).

Thanks for reading!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T11:04:18+00:00Added an answer on May 28, 2026 at 11:04 am

    Widget.hide always returns None, which glib.timeout_add_seconds treats identically to False. Thus, your timer will always terminate after running once. There is a possibility that hide will be called twice (when the user clicks OK and at the 5 s timeout) but that’s alright. So yes, your code is fine.

    Edit: Just realised something. You’re creating a new info bar every time the function runs, then only hiding it. Instead of using hide, use destroy so it gets properly cleaned up.

    … OR I need each new InfoBar to replace any previous one (I can’t figure out how to do this without inheriting the timer from the previous InfoBar–it gets messy).

    It’s not too complicated; just reuse the same info bar. Record the return value of glib.timeout_add_seconds, then while replacing the content of the info bar, kill the previous timer with glib.source_remove.

    There are usability trade-offs between the two choices you present (clean UI vs. making sure the user doesn’t miss important info) but that’s another topic and perhaps not that important.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to use show function inside application didFinishLaunchingWithOptions -(void)show { NSLog(@AAA); } -
I have a MFC dialog based application in which I use ::system() function to
Within my application, I use the MiniDumpWriteDump function (see dbghelp.dll) to write a crash
I use std::tr1::shared_ptr extensively throughout my application. This includes passing objects in as function
In my ExtJS application I use EditorGridPanel to show data from server. var applicationsGrid
In my application I use JQGrid for listing some contacts. I need to show
I want to create a global function to use throughout my application. Let say
I want to use AntiXss library function in my web application. I have a
I have a C++ library and a C++ application trying to use functions and
How do you make your application multithreaded ? Do you use asynch functions ?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.