Search code examples
pythonlinuxwxpython

How get string selection in wx.html.htmlwindow


I can not get a method to manage clipboard with the context menu I'm trying with version 2.8 of wxpython

import wx
import wx.lib.iewin

class main (wx.Frame):
    def __init__(self, parent):
        wx.Frame.__init__ (self, parent, id, title, pos, size, style)

        self.html_field = HTMLWINDOW(self.p_html, -1)

class HTMLWINDOW(wx.html.HtmlWindow):
    def __init__(self, parent, id):
        self.ie = wx.lib.iewin.IEHtmlWindow(self, -1, style)

        self.Bind(wx.EVT_CONTEXT_MENU, self.menu)

    def menu(self, event):
        self.copied = self.ie.GetStringSelection()

alternative method. but only I can get words, not a whole selection

def OnCellClicked(self, cell, x, y, evt):
    if isinstance(cell, wx.html.HtmlWordCell):
        sel = wx.html.HtmlSelection()
        word = cell.ConvertToText(sel)
    super(MyHtmlWindow, self).OnCellClicked(cell, x, y, evt)

importing wx.lib.iewin I get this error

Traceback (most recent call last):

ValueError: _type_ 'v' not supported
  File "main.py", line 3959, in <module>
import wx.lib.iewin as iewin
File "/usr/lib/python2.7/dist-packages/wx-2.8-gtk2-unicode/wx/lib/iewin.py", line 15, in <module>
import wx.lib.activex
 File "/usr/lib/python2.7/dist-packages/wx-2.8-gtk2-unicode/wx/lib/activex.py", line 35, in <module>
import ctypes.wintypes as wt
File "/usr/lib/python2.7/ctypes/wintypes.py", line 23, in <module>
class VARIANT_BOOL(_SimpleCData):
ValueError: _type_ 'v' not supported

Solution

  • As Werner already pointed out, you are attempting to import wx.lib.iewin in Linux. The iewin module is Windows only. I think it should give an import error that tells you it's Windows only, but the name itself implies that. You could put in a bug ticket so that it does raise an appropriate error though.

    If you need a browser-like widget, then you should check out WebView. It was added in wxPython 2.9, I believe and works cross-platform. You can read more about that widget here: