Sign in to follow this  
Red Ant

Need a good strategy to handle GUI updates triggered by an external source

Recommended Posts

Red Ant    471
Hello, Imagine you have an application with a nice graphical user interface. The GUI is the means by which you display and alter the underlying data of your application. Part of the nature of your application is that it is connected to another application via TCP/IP (or any other means of communication ... doesn't really matter for our example). The other application may contact your GUI app and send it stuff at arbitrary times. Each time it does, you must read what it has sent you and update the data you're displaying in your GUI. However, updating the data is not enough ... the various components of your GUI may also need to be updated to reflect the changed data! And that's where I'm not quite sure how this is best done, because refreshing the entire GUI just because one aspect of the data has changed seems a bit inefficient. In principle, I can see 2 ways to do this more elegantly: A) Upon receiving something from the other app, you explicitely update only those components of your GUI which are affected by the change. This doesn't seem very flexible to me, as the application as a whole constantly must be aware of exactly which of its components must be updated when a message of type X, Y, etc. arrives. B) You define custom events for each type of message you may receive from the other application. When a message is incoming, you just update the data but do not explicitely update the GUI. Much rather you fire an appropriate event, depending on which type of message you've just received. If a GUI component has registered to receive the event, it can update itself by inspecting the updated data. Okay, now that I've formulated my question, things actually seem a bit clearer to me but I'm still a bit undecided, so if you have something useful to add, please feel free to! Also, and this a bit of a newby-ish question, is there a widely accepted strategy to prevent updates of GUI components which aren't currently visible? Do you just check if the component is visible and then just return without doing anything if it invisible? Or is there a way to ensure that a component doesn't even receive the event at all if it isn't visible in the first place? P.S. I'm using wxWindows, but this is really more of a general problem than tied to any particular GUI library.

Share this post


Link to post
Share on other sites
Basiror    241
id say that gui apps are event driven thus you should make use of the event system
every decent gui implementation offers

e.g.: messagemaps with MFC wxWidgets implemented message maps nearly the same way


so read your network packet and send a message
maybe you need to check to which window you need to send the message

Share this post


Link to post
Share on other sites
Red Ant    471
Yeah, I suppose events are the way to go. But when you think of it, using events really doesn't change much about my original problem because I still need to keep track of which windows / controls I must send the events to (as you already pointed out in your post). :(

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this