I have two questions today, both of which are just verification checks
to make sure, for the most part, I'm doing things right.
1. to do with notifications:
As part of one of my projects I wanted to implement a way to send text
messages to your fellow gamer, even if its a quick, "you suck why did
you kill my level 500 beast."
the problem was, I'm not sure how to go about visually showing this. For
example, for blind users, I'd use something like:
speak("You have a new message from "+message.username+" that reads
Now, I was looking through the wx python demos and at first, I thought
NotificationMessage would be a good one, and it does seem useful for
other stuff I had in mind. I think Skype may use similar as a back end
if you call someone when they are offline, then they come back online.
That could get very annoying, very fast though I'd imagine. So my next
idea was to use a wx.listCtrl called chat_history.
Then to have it to where each chat message is appended to the list, and
coloured red. Once you focus the cursor into the list (read it), it
turns them the normal, I'm assuming white, colour.
Would this, along with a sound, be a suitable visual way of showing chat
Second off, this one is to do with panels. I'm a little stuck as to how
I should be showing my panels, and to be honest I think I'm overdoing it
Here's a commented version of a basic window I might use. Any help on
this would be appreciated.
Thanks again everyone for your patients.
panel = wx.Panel(self, wx.ID_ANY, style= wx.WANTS_CHARS) # create the
panel so it looks correct on all platforms and is easier to manage
self.mainpanel=panel # store the panel so that you can hide or show
it later on
panel.SetBackgroundColour("white") # because otherwise you can't see
vbox = wx.BoxSizer(wx.VERTICAL) # puts one sizer above the other I
think, in a vertical line. I should probably change this to grid, but
screen visualisation in my head is a bit of a knockout right now
hbox1 = wx.BoxSizer(wx.HORIZONTAL) # multiples of these would create
lines of horizontal widgets across the screen, I think.
self.info1 = wx.ListCtrl(panel, -1, style = wx.LC_REPORT)
hbox1.Add(self.info1, 1, wx.EXPAND|wx.ALIGN_LEFT|wx.ALL,5)
self.info1.SetName("Information.") # screen reader stuff
self.info1.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.send_enter) # adding
items to the list is handled in code not included as it's irrelevant
browse1 = wx.Button(panel, -1, "Exit!")
panel.Fit() # assuming it fits it to the screen
panel.Layout() # not sure entirely, but figure it draws everything on
panel.Update() # don't know if I actually need this, I'm a bit
confused between self.Refresh, and self.upadte
self.Show() # for the frame
# I realise some of these calls may be unnecessary, but I'm really unsure
Nathan smith wrote:
> Second off, this one is to do with panels. I'm a little stuck as to
> how I should be showing my panels, and to be honest I think I'm
> overdoing it a lot.
It is key that you understand that all of the windowing systems are
event based. With very few exceptions, when you make a call changing
the state of a window, the screen pixels will not have changed by the
time the call returns. Instead, the change will queue up a message.
The next time your app returns to its message loop, that message will be
popped off the queue and handled. That's where the pixels change.
You don't have to call Show on your individual panels and controls. You
just have to Show your frame. As long as a control isn't hidden, it
will get drawn when the frame refreshes.
Nothing gets drawn during your "create" call. This is just setting up
data structures. When you call self.Show() on the frame, that will
start the process of sending paint messages to all of the subwindows.
That's where the pixels actually get drawn When create_window returns,
nothing is yet visible. That happens later.
Refresh queues up a repaint message, asking the window to repaint itself
the next time it gets to its message loop. Update demands that the
window repaint itself immediately, but that's not meaningful during
initialization, because nothing has been painted. Basically, you never
need to call Update or Refresh during initialization. A refresh will
be done as soon as the window creation is finished.
The Layout/Fit stuff is mostly superstition. Layout gets called during
"size" message handling. Fit is useful for your Frame, so it can resize
itself to fit the panel, but you generally don't need it for lower
windows. Layout doesn't actually draw anything. It just forces all
of the sizers to recompute the size of their contained components. If
the sizes change, repaint requests will be queued up and the components
will redraw themselves later.
So, where you have this:
> panel.Fit() # assuming it fits it to the screen
> panel.Layout() # not sure entirely, but figure it draws everything
> on screen
> panel.Update() # don't know if I actually need this, I'm a bit
> confused between self.Refresh, and self.upadte
> self.Show() # for the frame