Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select and copy text from dialog in wxPython

I have a wxPython app, and in this app, I can select and copy text from various frames, but I can't do so from dialogs. Is there a way to do this?

I understand I could probably do this by putting some kind of TextCtrl in the dialog, but I'd like to be able to do this from a standard looking dialog.

EDIT:

Sorry, I should have been more specific. I can't select text from a wx.MessageBox under Windows Vista or Mac (don't have access to Linux to try that). Here is one example of the call to create the message box:

wx.MessageBox(str(msg), "Could not load ballots", wx.OK|wx.ICON_ERROR)

I am unable to select the text of the message box.

like image 942
gaefan Avatar asked Jul 05 '10 16:07

gaefan


1 Answers

If you make a custom MessageBox like so, it will appear to be static text until you click on the text:

class MessageBox(wx.Dialog):
    def __init__(self, parent, title):
        wx.Dialog.__init__(self, parent, title=title)
        text = wx.TextCtrl(self, style=wx.TE_READONLY|wx.BORDER_NONE)
        text.SetValue("Hi hi hi")
        text.SetBackgroundColour(wx.SystemSettings.GetColour(4))
        self.ShowModal()
        self.Destroy()

I've only tested this on windows, you might have to adjust the color for your OS.

like image 138
Jake Avatar answered Oct 08 '22 11:10

Jake