Subclassing with XRCed

I am trying to subclass wx.html.HtmlWindow. I created a subclass
HTMLChat(wx.html.HtmlWindow) and added the subclass=”HTMLChat” as
well as tried subclass=”chat_client.HTMLChat” and when I load my
app, it says:

“subclass HTMLChat not found for resource htmChat, not
subclassing!”

class HTMLChat(wx.html.HtmlWindow):

def __init__(self, parent, ID, frame):

    #wxHTML.HtmlWindow.__init__(self, parent, ID)

    pre = wx.PreHtmlWindow()

    self.PostCreate(pre)

def OnLinkClicked(self, link):

    print link.Href

class MyApp(wx.App):

def OnInit(self):

    self.res = xrc.XmlResource(GUI_FILE)

    self.frame = self.res.LoadFrame(None, GUI_FRAME)

    self.panel = xrc.XRCCTRL(self.frame, GUI_PANEL)

    self.message = xrc.XRCCTRL(self.panel, GUI_MESSAGE)

    self.html = xrc.XRCCTRL(self.panel, GUI_HTML)

    self.send = xrc.XRCCTRL(self.panel, GUI_BTN_SEND)

    self.frame.Show(1)

    self.InitMenu()

    return True
<?xml version="1.0" encoding="cp1255"?>

<title>Forem Chat Client (alpha)</title>

<object class="wxPanel"

name=“pnlMain”>

  <object class="wxBoxSizer">

    <orient>wxVERTICAL</orient>

    <object class="sizeritem">

      <object class="wxHtmlWindow"

name=“htmChat” subclass=“HTMLChat”>

<- snip ->

···

No virus found in this outgoing message.

Checked by AVG Free Edition.

Version: 7.5.441 / Virus Database: 268.17.33/678 - Release Date: 2/9/2007 4:06 PM

Hi,

your __init__ method should have no extra arguments in this case:

class HTMLChat(wx.html.HtmlWindow):
    def __init__(self):
    ...

You should have looked to the terminal output, it normally prints the
exception traceback, the message you included is from C++ XRC API so
does not know about problems related to python.

Maybe there is a way to turn on graphical error reporting similar to
wxWidgets new assertion dialog.

Roman

···

On Sat, 2007-02-10 at 10:20 -0500, Lee Connell wrote:

I am trying to subclass wx.html.HtmlWindow. I created a subclass
HTMLChat(wx.html.HtmlWindow) and added the subclass=”HTMLChat” as well
as tried subclass=”chat_client.HTMLChat” and when I load my app, it
says:

“subclass HTMLChat not found for resource htmChat, not subclassing!”

class HTMLChat(wx.html.HtmlWindow):

    def __init__(self, parent, ID, frame):

        #wxHTML.HtmlWindow.__init__(self, parent, ID)

        pre = wx.PreHtmlWindow()

        self.PostCreate(pre)

    def OnLinkClicked(self, link):

        print link.Href

class MyApp(wx.App):

    def OnInit(self):

        self.res = xrc.XmlResource(GUI_FILE)

        self.frame = self.res.LoadFrame(None, GUI_FRAME)

        self.panel = xrc.XRCCTRL(self.frame, GUI_PANEL)

        self.message = xrc.XRCCTRL(self.panel, GUI_MESSAGE)

        self.html = xrc.XRCCTRL(self.panel, GUI_HTML)

        self.send = xrc.XRCCTRL(self.panel, GUI_BTN_SEND)

        self.frame.Show(1)

        self.InitMenu()

        return True

<?xml version="1.0" encoding="cp1255"?>

<resource>

  <object class="wxFrame" name="frmMain">

    <title>Forem Chat Client (alpha)</title>

    <object class="wxPanel" name="pnlMain">

      <object class="wxBoxSizer">

        <orient>wxVERTICAL</orient>

        <object class="sizeritem">

          <object class="wxHtmlWindow" name="htmChat"
subclass="HTMLChat">

<- snip ->

--
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.5.441 / Virus Database: 268.17.33/678 - Release Date:
2/9/2007 4:06 PM

Roman,

Thanks for reply. I just had it working and all a sudden it's not working
again. I've attached the code if you have time to look at it. I am not
getting any info related to XRC in the output. I just get a dialog box that
says "subclass for "ChatClient.HTMLChat" not found for resource "htmChat".

-Lee

Hi,

your __init__ method should have no extra arguments in this case:

class HTMLChat(wx.html.HtmlWindow):
    def __init__(self):
    ...

You should have looked to the terminal output, it normally prints the
exception traceback, the message you included is from C++ XRC API so
does not know about problems related to python.

Maybe there is a way to turn on graphical error reporting similar to
wxWidgets new assertion dialog.

Roman

gui.xrc (2.11 KB)

ChatClient.py (3.31 KB)

···

-----Original Message-----

On Sat, 2007-02-10 at 10:20 -0500, Lee Connell wrote:

I am trying to subclass wx.html.HtmlWindow. I created a subclass
HTMLChat(wx.html.HtmlWindow) and added the subclass=”HTMLChat” as well
as tried subclass=”chat_client.HTMLChat” and when I load my app, it
says:

“subclass HTMLChat not found for resource htmChat, not subclassing!”

class HTMLChat(wx.html.HtmlWindow):

    def __init__(self, parent, ID, frame):

        #wxHTML.HtmlWindow.__init__(self, parent, ID)

        pre = wx.PreHtmlWindow()

        self.PostCreate(pre)

    def OnLinkClicked(self, link):

        print link.Href

class MyApp(wx.App):

    def OnInit(self):

        self.res = xrc.XmlResource(GUI_FILE)

        self.frame = self.res.LoadFrame(None, GUI_FRAME)

        self.panel = xrc.XRCCTRL(self.frame, GUI_PANEL)

        self.message = xrc.XRCCTRL(self.panel, GUI_MESSAGE)

        self.html = xrc.XRCCTRL(self.panel, GUI_HTML)

        self.send = xrc.XRCCTRL(self.panel, GUI_BTN_SEND)

        self.frame.Show(1)

        self.InitMenu()

        return True

<?xml version="1.0" encoding="cp1255"?>

<resource>

  <object class="wxFrame" name="frmMain">

    <title>Forem Chat Client (alpha)</title>

    <object class="wxPanel" name="pnlMain">

      <object class="wxBoxSizer">

        <orient>wxVERTICAL</orient>

        <object class="sizeritem">

          <object class="wxHtmlWindow" name="htmChat"
subclass="HTMLChat">

<- snip ->

--
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.5.441 / Virus Database: 268.17.33/678 - Release Date:
2/9/2007 4:06 PM

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org

--
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.5.441 / Virus Database: 268.17.33/678 - Release Date: 2/9/2007
4:06 PM

--
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.5.441 / Virus Database: 268.17.33/678 - Release Date: 2/9/2007
4:06 PM

The problem is when I use wxReactor from Twisted. When I use this it does
not work, as soon as I take this out of imports and stop the
wxreactor.install() method, it works fine. Anyone have examples of using
wxReactor or even wxPython with Twisted?

···

-----Original Message-----
From: Roman Rolinsky [mailto:rolinsky@femagsoft.com]
Sent: Saturday, February 10, 2007 1:33 PM
To: wxPython-users@lists.wxwidgets.org
Subject: Re: [wxPython-users] Subclassing with XRCed

Hi,

your __init__ method should have no extra arguments in this case:

class HTMLChat(wx.html.HtmlWindow):
    def __init__(self):
    ...

You should have looked to the terminal output, it normally prints the
exception traceback, the message you included is from C++ XRC API so
does not know about problems related to python.

Maybe there is a way to turn on graphical error reporting similar to
wxWidgets new assertion dialog.

Roman

--
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.5.441 / Virus Database: 268.17.33/678 - Release Date: 2/9/2007
4:06 PM

Lee Connell wrote:

The problem is when I use wxReactor from Twisted. When I use this it does
not work, as soon as I take this out of imports and stop the
wxreactor.install() method, it works fine.

Does twisted do anything that changes the Python import semantics? The Python XRC subclass factory is pretty simple, but it needs to be able to dynamically import modules. Here is the code:

def _my_import(name):
     try:
         mod = __import__(name)
     except ImportError:
         import traceback
         print traceback.format_exc()
         raise
     components = name.split('.')
     for comp in components[1:]:
         mod = getattr(mod, comp)
     return mod

class XmlSubclassFactory_Python(XmlSubclassFactory):
     def __init__(self):
         XmlSubclassFactory.__init__(self)

     def Create(self, className):
         assert className.find('.') != -1, "Module name must be specified!"
         mname = className[:className.rfind('.')]
         cname = className[className.rfind('.')+1:]
         module = _my_import(mname)
         klass = getattr(module, cname)
         inst = klass()
         return inst

XmlResource_AddSubclassFactory(XmlSubclassFactory_Python())

Anyone have examples of using
wxReactor or even wxPython with Twisted?

There are several around. Several folks here use both and make sure that it continues to work. But perhaps nobody has used a xrc subclass in the same app as twisted...

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

I sent an email to the maintainer of wxreactor.py. See if he replies on it.
Wxreactor.py isn't a whole lot either, it just puts twisted into a thread.

-Lee

···

-----Original Message-----
From: Robin Dunn [mailto:robin@alldunn.com]
Sent: Monday, February 12, 2007 2:48 PM
To: wxPython-users@lists.wxwidgets.org
Subject: Re: [wxPython-users] Subclassing with XRCed

Lee Connell wrote:

The problem is when I use wxReactor from Twisted. When I use this it does
not work, as soon as I take this out of imports and stop the
wxreactor.install() method, it works fine.

Does twisted do anything that changes the Python import semantics? The
Python XRC subclass factory is pretty simple, but it needs to be able to
dynamically import modules. Here is the code:

def _my_import(name):
     try:
         mod = __import__(name)
     except ImportError:
         import traceback
         print traceback.format_exc()
         raise
     components = name.split('.')
     for comp in components[1:]:
         mod = getattr(mod, comp)
     return mod

class XmlSubclassFactory_Python(XmlSubclassFactory):
     def __init__(self):
         XmlSubclassFactory.__init__(self)

     def Create(self, className):
         assert className.find('.') != -1, "Module name must be specified!"
         mname = className[:className.rfind('.')]
         cname = className[className.rfind('.')+1:]
         module = _my_import(mname)
         klass = getattr(module, cname)
         inst = klass()
         return inst

XmlResource_AddSubclassFactory(XmlSubclassFactory_Python())

Anyone have examples of using
wxReactor or even wxPython with Twisted?

There are several around. Several folks here use both and make sure
that it continues to work. But perhaps nobody has used a xrc subclass
in the same app as twisted...

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org

--
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.5.441 / Virus Database: 268.17.37/682 - Release Date: 2/12/2007
1:23 PM

--
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.5.441 / Virus Database: 268.17.37/682 - Release Date: 2/12/2007
1:23 PM

Robin,

Itamar replied to an email I sent him and this was his reply after running
the demo application I sent him.

------Original Message From Itamar------
I think the issue is that the way xrc import code is broken, or something;
it seems to re-execute the module, so the reactor is installed twice or
something, not sure exactly. If the module the xrc imports doesn't install
the reactor itself you should be fine.

···

-----Original Message-----
From: Robin Dunn [mailto:robin@alldunn.com]
Sent: Monday, February 12, 2007 2:48 PM
To: wxPython-users@lists.wxwidgets.org
Subject: Re: [wxPython-users] Subclassing with XRCed

Lee Connell wrote:

The problem is when I use wxReactor from Twisted. When I use this it does
not work, as soon as I take this out of imports and stop the
wxreactor.install() method, it works fine.

Does twisted do anything that changes the Python import semantics? The
Python XRC subclass factory is pretty simple, but it needs to be able to
dynamically import modules. Here is the code:

--
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.5.441 / Virus Database: 268.17.37/682 - Release Date: 2/12/2007
1:23 PM

Lee Connell wrote:

Robin,

Itamar replied to an email I sent him and this was his reply after running
the demo application I sent him.

------Original Message From Itamar------
I think the issue is that the way xrc import code is broken, or something;
it seems to re-execute the module, so the reactor is installed twice or
something, not sure exactly. If the module the xrc imports doesn't install
the reactor itself you should be fine.

Ah, yes. I should have remembered this. He is correct, when you put your subclassable class in the same module that is run as __main__ then it will get imported twice because XRC will also import it using the module name you specify in the subclass attribute. If you move that class to it's own module then it should work for you. Or you can move the call to wxreactor.install into a "if __name__ == '__main__':..." block.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Excellent!

Thank you very much Robin.

···

On 2/13/07, Robin Dunn robin@alldunn.com wrote:

Lee Connell wrote:

Robin,

Itamar replied to an email I sent him and this was his reply after running
the demo application I sent him.

------Original Message From Itamar------

I think the issue is that the way xrc import code is broken, or something;
it seems to re-execute the module, so the reactor is installed twice or
something, not sure exactly. If the module the xrc imports doesn’t install

the reactor itself you should be fine.

Ah, yes. I should have remembered this. He is correct, when you put
your subclassable class in the same module that is run as main then
it will get imported twice because XRC will also import it using the

module name you specify in the subclass attribute. If you move that
class to it’s own module then it should work for you. Or you can move
the call to wxreactor.install into a “if name == ‘main’:…” block.


Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!


To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail:
wxPython-users-help@lists.wxwidgets.org