views:

77

answers:

2

Hi All,

In my application i have text control. I want my text ctrl should be read only but when some one right click on this he is able to copy the value from that ctrl and he can paste that value in other text control.

If i made my text control read only with wx.TE_READONLY then copy/paste is not working.

Is there any requirement to handle other type of wx event or i have to set more type of wx style flags while creating the text control object.

Thanks in advance.

A: 

Hmm Im on windows 7 and don't have any problem copying from a textCtrl that has the wx.READ_ONLY style flag set.

You said you wanted to paste into another textCtrl -obviously you can't have the wx.READ_ONLY style flag set in the textCtrl you want to be able to paste into.

Try out the demo below, you should be able to copy from the textCtrl on the left(which is read only) to the one on the right(which doesn't have the read only style set).

import wx

class MainWindow(wx.Frame):
    def __init__(self, parent, id=-1):
        wx.Frame.__init__(self,parent,id, size=(200,200))

        self.panel = wx.Panel(self,wx.ID_ANY)     
        bsizer = wx.BoxSizer()       
        read_only_txtCtrl = wx.TextCtrl(self,-1,
                        "This textCtrl is read only",
                        style=wx.TE_MULTILINE|wx.TE_READONLY)

        editable_txtCtrl = wx.TextCtrl(self,-1,
                        "This textCtrl is editable",
                        style=wx.TE_MULTILINE)

        bsizer.Add(read_only_txtCtrl, 1, wx.EXPAND)
        bsizer.Add(editable_txtCtrl, 1, wx.EXPAND)

        self.SetSizerAndFit(bsizer)


if __name__ == "__main__":

    app = wx.PySimpleApp()
    frame = MainWindow(None)
    frame.SetSize((200,200))
    frame.Show()
    app.MainLoop()
volting
A: 

We should bind wx.EVT_TEXT_COPY and wx.EVT_TEXT_PASTE with text control. one can copy and paste data from text ctrl although text ctrl is read only mode.

mukul sharma
@mukul: What, have you read my answer at all? Why do do you need to bind to `wx.EVT_TEXT_COPY` and `wx.EVT_TEXT_PASTE`? Have you run the runnable sample I provided with my answer?
volting
@volting i got your point, even i run that one. But here in u r running sample one text ctrl you cannot copy the value from other.I need both the text ctrl should be readonly and support copy and paste. Sorry for if i was not put the requirement clearly. Anyway thank you very much for your help.
mukul sharma
@mukul: Seems like a catch 22 you want your textBox to be read only yet you want to edit it i.e paste into it.
volting
@volting: Its no sort of catch 22. actually i just want to avoid error input in text ctrl, because i am writing right input first, so some one want to copy that value in other text ctrl can only copy that value and paste but cannot edit in text ctrl. Its possbile if you discard EVT_TEXT and use EVT_TEXT_COPY and EVT_TEXT_PASTE.
mukul sharma