]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/samples/wxPIA_book/Chapter-18/clipboard.py
4 The whole contents of this control
5 will be placed in the system's
6 clipboard when you click the copy
11 If the clipboard contains a text
12 data object then it will be placed
13 in this control when you click
14 the paste button below. Try
15 copying to and pasting from
16 other applications too!
19 class MyFrame(wx
.Frame
):
21 wx
.Frame
.__init
__(self
, None, title
="Clipboard",
26 self
.t1
= wx
.TextCtrl(p
, -1, t1_text
,
27 style
=wx
.TE_MULTILINE|wx
.HSCROLL
)
28 self
.t2
= wx
.TextCtrl(p
, -1, t2_text
,
29 style
=wx
.TE_MULTILINE|wx
.HSCROLL
)
30 copy
= wx
.Button(p
, -1, "Copy")
31 paste
= wx
.Button(p
, -1, "Paste")
33 # setup the layout with sizers
34 fgs
= wx
.FlexGridSizer(2, 2, 5, 5)
38 fgs
.Add(self
.t1
, 0, wx
.EXPAND
)
39 fgs
.Add(self
.t2
, 0, wx
.EXPAND
)
40 fgs
.Add(copy
, 0, wx
.EXPAND
)
41 fgs
.Add(paste
, 0, wx
.EXPAND
)
42 border
= wx
.BoxSizer()
43 border
.Add(fgs
, 1, wx
.EXPAND|wx
.ALL
, 5)
47 self
.Bind(wx
.EVT_BUTTON
, self
.OnDoCopy
, copy
)
48 self
.Bind(wx
.EVT_BUTTON
, self
.OnDoPaste
, paste
)
50 def OnDoCopy(self
, evt
):
51 data
= wx
.TextDataObject()
52 data
.SetText(self
.t1
.GetValue())
53 if wx
.TheClipboard
.Open():
54 wx
.TheClipboard
.SetData(data
)
55 wx
.TheClipboard
.Close()
57 wx
.MessageBox("Unable to open the clipboard", "Error")
59 def OnDoPaste(self
, evt
):
61 data
= wx
.TextDataObject()
62 if wx
.TheClipboard
.Open():
63 success
= wx
.TheClipboard
.GetData(data
)
64 wx
.TheClipboard
.Close()
67 self
.t2
.SetValue(data
.GetText())
70 "There is no data in the clipboard in the required format",
74 app
= wx
.PySimpleApp()