Exemple #1
0
 def test_ignore_non_custom(self):
     toolkit_data = wx.DataObjectComposite()
     html_data = wx.HTMLDataObject()
     html_data.SetHTML("hello world")
     toolkit_data.Add(html_data)
     text_data = wx.CustomDataObject(wx.DataFormat('text/plain'))
     text_data.SetData(b'hello world')
     toolkit_data.Add(text_data)
     data_wrapper = DataWrapper(toolkit_data=toolkit_data)
     self.assertTrue('text/plain' in data_wrapper.mimetypes())
     self.assertEqual(data_wrapper.get_mimedata('text/plain'),
                      b'hello world')
Exemple #2
0
def copy_html_to_clipboard(html):
    """
    Copy the html string into the clipboard as a HTML object.
    """
    if not wx.TheClipboard.IsOpened():
        do = wx.HTMLDataObject()
        do.SetHTML(html)
        wx.TheClipboard.Open()
        res = wx.TheClipboard.SetData(do)
        wx.TheClipboard.Close()
        return res
    return False
Exemple #3
0
 def test_HTMLDataObject(self):
     data = "<html><body>This is some data</body></html>"
     do = wx.HTMLDataObject(data)
     self.assertEqual(do.GetHTML(), data)
     self.assertEqual(do.HTML, data)
Exemple #4
0
	def onPaste( self, event ):
		success = False
		table = None
		
		# Try to get html format.
		html_data = wx.HTMLDataObject()
		if wx.TheClipboard.Open():
			success = wx.TheClipboard.GetData(html_data)
			wx.TheClipboard.Close()
		if success:
			table = listFromHtml( html_data.GetHTML() )
			if not table:
				success = False
				
		# If no success, try tab delimited.
		if not success:
			text_data = wx.TextDataObject()
			if wx.TheClipboard.Open():
				success = wx.TheClipboard.GetData(text_data)
				wx.TheClipboard.Close()
			if success:
				table = []
				for line in text_data.GetText().split('\n'):
					table.append( line.split('\t') )
				if not table:
					success = False
		if not success:
			return

		riderInfo = []
		fm = None
		for row in table:
			if fm:
				f = fm.finder( row )
				info = {
					'bib': 			f('bib',u''),
					'first_name':	u'{}'.format(f('first_name',u'')).strip(),
					'last_name':	u'{}'.format(f('last_name',u'')).strip(),
					'license':		u'{}'.format(f('license_code',u'')).strip(),
					'team':			u'{}'.format(f('team',u'')).strip(),
					'uci_id':		u'{}'.format(f('uci_id',u'')).strip(),
					'nation_code':		u'{}'.format(f('nation_code',u'')).strip(),
					'existing_points':	u'{}'.format(f('existing_points',u'0')).strip(),
				}
				
				info['bib'] = u'{}'.format(info['bib']).strip()
				if not info['bib']:	# If missing bib, assume end of input.
					continue
				
				# Check for comma-separated name.
				name = u'{}'.format(f('name', u'')).strip()
				if name and not info['first_name'] and not info['last_name']:
					try:
						info['last_name'], info['first_name'] = name.split(',',1)
					except:
						pass
				
				# If there is a bib it must be numeric.
				try:
					info['bib'] = int(u'{}'.format(info['bib']).strip())
				except ValueError:
					continue

				ri = Model.RiderInfo( **info )
				riderInfo.append( ri )
				
			elif any( u'{}'.format(h).strip().lower() in self.bibHeader for h in row ):
				fm = standard_field_map()
				fm.set_headers( row )
				
			Model.race.setRiderInfo( riderInfo )
			self.updateGrid()