Please help! Info –
Program: A pop up frame representing an email message, generated after clicking on a listctrl item (“the inbox”).
Situation: The message of one of the emails was long and part of it disappeared. Would need a vertical scrollbar to read it all! But…
Problem: As soon I changed wx.Panel to wx.ScrolledWindow or ScrolledPanel (tried both = same), the text of the message suddenly started to go all on one line…I no longer needed a vertical scrollbar, I needed + had a horizontal scrollbar to read it all.
If I change back to wx.Panel, the text wraps itself again (without being told to). It looks neat and lovely…except that I still can’t scroll down to read the rest. If I put back ScrolledWindow, suddenly all the text goes one one line. I DON’T UNDERSTAND. 🙁 Why is it doing this to me?
It’s so unpractical to read a message by scrolling horizontally back and forth, so I really really need to get the StaticText wrapped as it was before, with a vertical scrollbar to scroll through the emails that are longer. I have tried putting in a main_message.Wrap(main_message.GetSize().width) command, but it does nothing.
I want it to work so that there is a vertical scroller when needed…but no need for a horizontal scroller, i.e. no crazy text suddenly deciding it wants to be on one line. Anyone know what is doing this?
Have shrunk the code as best as can manage:
class Message(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__init__(self, parent, id, title, pos = (500, 100), size=(500, 500), style = wx.STAY_ON_TOP | wx.MAXIMIZE_BOX | wx.RESIZE_BORDER | wx.SYSTEM_MENU | wx.CAPTION)
self.basicpanel = wx.ScrolledWindow(self, -1)
self.basicpanel.SetScrollbars(1, 1, 1, 1)
self.basicpanel.SetBackgroundColour("medium goldenrod")
parent = self.GetParent()
message = parent.email
# email details e.g. sender, date, urgency, subject
sender_st = wx.StaticText(self.basicpanel, -1, "Sender:")
status_st = wx.StaticText(self.basicpanel, -1, "Status:")
date_st = wx.StaticText(self.basicpanel, -1, "Date:")
priority_st = wx.StaticText(self.basicpanel, -1, "Priority:")
subject_st = wx.StaticText(self.basicpanel, -1, "Subject:")
answer_sender = wx.StaticText(self.basicpanel, -1, message.sender)
answer_status = wx.StaticText(self.basicpanel, -1, message.status)
answer_date = wx.StaticText(self.basicpanel, -1, message.date)
answer_priority = wx.StaticText(self.basicpanel, -1, message.priority)
answer_subject = wx.StaticText(self.basicpanel, -1, message.subject)
# main body of email
main_message = wx.StaticText(self.basicpanel, -1, message.txt)
# create a box sizer to put in the email details like sender, date, et
self.messagebox = wx.StaticBox(self.basicpanel, -1, '', (5,5))
self.fgs_message = wx.FlexGridSizer(3, 4, 5, 15)
self.fgs_message.AddMany([(sender_st, 1, wx.EXPAND), (answer_sender, 1, wx.EXPAND), (status_st, 1, wx.EXPAND), (answer_status, 1, wx.EXPAND), (date_st, 1, wx.EXPAND), (answer_date, 1, wx.EXPAND), (priority_st, 1, wx.EXPAND), (answer_priority, 1, wx.EXPAND), (subject_st, 1, wx.EXPAND), (answer_subject, 1, wx.EXPAND)])
self.boxmessagesizer = wx.StaticBoxSizer(self.messagebox, wx.VERTICAL)
self.boxmessagesizer.Add(self.fgs_message, 1, wx.ALL, 5)
# create a sizer to include the above details and the main message or body of email
self.messagebasicsizer = wx.BoxSizer(wx.VERTICAL)
self.messagebasicsizer.Add(self.boxmessagesizer, 0, wx.EXPAND | wx.ALL, 10)
self.messagebasicsizer.Add(main_message, 1, wx.EXPAND | wx.ALL, 10)
# create buttons at the bottom and a horizontal sizer to put them on same line
self.buttonreply = wx.Button(self.basicpanel, 1, 'Reply', (20,10))
self.buttondelete = wx.Button(self.basicpanel, 1, 'Close + Delete', (40, 10))
self.buttonsave = wx.Button(self.basicpanel, 1, 'Close + Save', (40,10))
self.horisizer = wx.BoxSizer(wx.HORIZONTAL)
self.horisizer.AddMany([(self.buttonreply, 0, wx.EXPAND | wx.ALL, 10), (self.buttondelete, 0, wx.EXPAND | wx.ALL, 10), (self.buttonsave, 0, wx.EXPAND | wx.ALL, 10)])
# add buttons to sizer with message details and message
self.messagebasicsizer.Add(self.horisizer, 0, wx.EXPAND | wx.ALIGN_CENTRE | wx.ALL, 10)
self.basicpanel.SetSizer(self.messagebasicsizer)
self.Bind(wx.EVT_BUTTON, self.OnDestroy)
self.Show(True)
You should use the wordwrap module: http://www.wxpython.org/docs/api/wx.lib.wordwrap-module.html. I have an example here: http://www.blog.pythonlibrary.org/2008/06/11/wxpython-creating-an-about-box/
Or put the text into a read-only multiline TextCtrl instead. Then you’ll have scrolling automagically. The latter is probably easier and will look better aesthetically.