mirror of
https://github.com/wxWidgets/Phoenix.git
synced 2026-01-04 19:10:09 +01:00
Fix context manager support for wx.TheClipboard.
Add some more clipboard tests. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxPython/Phoenix/trunk@76572 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -37,9 +37,6 @@ def run():
|
||||
c.find('AddData.data').transfer = True
|
||||
c.find('SetData.data').transfer = True
|
||||
|
||||
# context manager methods
|
||||
c.addPyMethod('__enter__', '(self)', 'return self')
|
||||
c.addPyMethod('__exit__', '(self, exc_type, exc_val, exc_tb)', 'self.Close()')
|
||||
|
||||
# TODO: This init wrapper class may be useful elsewhere...
|
||||
module.addPyCode("""\
|
||||
@@ -66,6 +63,15 @@ def run():
|
||||
self._checkInstance()
|
||||
return repr(self._instance)
|
||||
|
||||
# context manager methods
|
||||
def __enter__(self):
|
||||
self._checkInstance()
|
||||
if not self.Open():
|
||||
raise RuntimeError('Unable to open clipboard.')
|
||||
return self
|
||||
def __exit__(self, exc_type, exc_val, exc_tb):
|
||||
self.Close()
|
||||
|
||||
TheClipboard = _wxPyDelayedInitWrapper(Clipboard.Get)
|
||||
""")
|
||||
|
||||
|
||||
@@ -20,6 +20,24 @@ class clipbrd_Tests(wtc.WidgetTestCase):
|
||||
wx.TheClipboard.Close()
|
||||
|
||||
self.assertEqual(data2.GetText(), 'This is some data.')
|
||||
self.assertEqual(data2.Text, 'This is some data.')
|
||||
|
||||
|
||||
def test_clpbrd2(self):
|
||||
# same, but with the context manager
|
||||
|
||||
# copy
|
||||
data1 = wx.TextDataObject('This is some data.')
|
||||
with wx.TheClipboard as cb:
|
||||
cb.SetData(data1)
|
||||
|
||||
# paste
|
||||
data2 = wx.TextDataObject()
|
||||
with wx.TheClipboard as cb:
|
||||
wx.TheClipboard.GetData(data2)
|
||||
|
||||
self.assertEqual(data2.GetText(), 'This is some data.')
|
||||
self.assertEqual(data2.Text, 'This is some data.')
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
|
||||
@@ -63,7 +63,7 @@ class DataObjTests(wtc.WidgetTestCase):
|
||||
data._testGetAllFormats()
|
||||
|
||||
# TODO: Get this fixed! See https://groups.google.com/d/topic/wx-dev/wFxevpvbhvQ/discussion
|
||||
@unittest.skipIf(sys.platform == 'darwin', 'Using wx.DF_TEXT currently fails on Mac')
|
||||
#@unittest.skipIf(sys.platform == 'darwin', 'Using wx.DF_TEXT currently fails on Mac')
|
||||
def test_DataObject(self):
|
||||
class MyDataObject(wx.DataObject):
|
||||
def __init__(self, value=''):
|
||||
@@ -159,7 +159,7 @@ class DataObjTests(wtc.WidgetTestCase):
|
||||
|
||||
|
||||
# TODO: Get this fixed! See https://groups.google.com/d/topic/wx-dev/wFxevpvbhvQ/discussion
|
||||
@unittest.skipIf(sys.platform == 'darwin', 'Using wx.DF_TEXT currently fails on Mac')
|
||||
#@unittest.skipIf(sys.platform == 'darwin', 'Using wx.DF_TEXT currently fails on Mac')
|
||||
def test_DataObjectSimple2(self):
|
||||
class MyDataObject(wx.DataObjectSimple):
|
||||
def __init__(self, value=''):
|
||||
@@ -275,6 +275,23 @@ class DataObjTests(wtc.WidgetTestCase):
|
||||
self.assertAlmostEqual(do.TextLength, len(data), delta=1)
|
||||
|
||||
|
||||
def test_TextDataObjectClipboard(self):
|
||||
# copy
|
||||
text = 'This is some MORE data.'
|
||||
data1 = wx.TextDataObject(text)
|
||||
if wx.TheClipboard.Open():
|
||||
wx.TheClipboard.SetData(data1)
|
||||
wx.TheClipboard.Close()
|
||||
|
||||
# paste
|
||||
data2 = wx.TextDataObject()
|
||||
if wx.TheClipboard.Open():
|
||||
wx.TheClipboard.GetData(data2)
|
||||
wx.TheClipboard.Close()
|
||||
|
||||
self.assertEqual(text, data2.Text)
|
||||
|
||||
|
||||
def test_URLDataObject(self):
|
||||
url = 'http://wxPython.org/'
|
||||
do = wx.URLDataObject()
|
||||
@@ -302,6 +319,7 @@ class DataObjTests(wtc.WidgetTestCase):
|
||||
self.assertEqual(do.HTML, data)
|
||||
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user