wxPython interface conflict

Hi

I am a beginner of wxPython. I am trying to write a GUI plug-in in another freeware called TexGen (

http://texgen.sourceforge.net/index.php/Main_Page). TexGen has a Python interface to run Python script within the application. So I wrote a trial wxPython script. It was to run in TexGen to create a frame. Afterwards, some functions in TexGen became problematic, i.e. “file->save TexGen file” raising an error message - TexGenGUI.exe has encountered a problem and needs to close. I wonder anything can be done within wxpython script or I need to change TexGen setting. Really appreciate your time to help look at this issue.
I use Windows XP and WxPython2.8 installed for Python2.5. The script is below:

#################################################################################"

import wx

import sys

class MyFrame(wx.Frame):

def init(

self, parent, ID, title, pos=wx.DefaultPosition,

size=wx.DefaultSize, style=wx.DEFAULT_FRAME_STYLE

):

global data

wx.Frame.init(self, parent, ID, title, pos, size, style)

panel = wx.Panel(self)

c = wx.Button(panel, -1, “Close”, (95,100))

self.Bind(wx.EVT_BUTTON, self.OnCloseMe, c)

self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)

def OnCloseMe(self, event):

self.Close(True)

def OnCloseWindow(self, event):

self.Destroy()

class App(wx.App):

def OnInit(self):

self.frame = MyFrame(None, -1, ‘Trial’, size = (300, 300))

self.frame.Show()

return True

···

#---------------------------------------------------------------------------

app = App()

try:

app.MainLoop()

finally:

del app

####################################################################################"

Many thanks

Xuesen

x. zeng wrote:

Hi

I am a beginner of wxPython. I am trying to write a GUI plug-in in another freeware called TexGen (

_- TexGen). TexGen has a Python interface to run Python script within the application. So I wrote a trial wxPython script. It was to run in TexGen to create a frame. Afterwards, some functions in TexGen became problematic, i.e. "file->save TexGen file" raising an error message - TexGenGUI.exe has encountered a problem and needs to close. I wonder anything can be done within wxpython script or I need to change TexGen setting. Really appreciate your time to help look at this issue.

I use Windows XP and WxPython2.8 installed for Python2.5. The script is below:

Is TexGen designed to allow GUI plugins or just non-GUI scripts that it runs in the background? If the former then does it have some API for integrating your plugin with their GUI and event loop? Have you asked the TexGen people if running wxPython applications as a plugin is supported or expected to work?

My guess is that the cleanup that is done when the wx.App object is destroyed is stomping on something in TexGen's UI code, open handles, or etc., so there are a couple things you could try to workaround this.

1. Don't let the app object be destroyed. Only create one of them and reuse it each time the wx scripts are run.

2. Run the wx code in another thread.

3. Both #1 and #2.

···

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

Robin,

Your suggestions sound very sensible.
TexGen was originally designed to allow just non-GUI scripts to run in the background. It works well with wxPython to a certain level. To my experience, the conflict of WxPython and TexGen is that Wx takes full control of system output while malfunctioning TexGen output. I did try setting redirect output behaviour. It did not help. So I wonder that may not be the point.

TexGen UI is written using wxWidgets and all functions are wrapped to python using SWIG. TexGen C++ code will create an instance of wxApp, while my wxpython script also creates a wx.App object. Your first suggestion is implying there should only be a single instance of this class. If I can somehow get a reference to TexGen’s wxApp instance from python then I can reuse that instead (maybe). I don’t know exactly how to do that. Would you please enlighten me on this?

Many thanks

Xuesen

···

On Fri, Feb 13, 2009 at 6:29 PM, Robin Dunn robin@alldunn.com wrote:

x. zeng wrote:

Hi

I am a beginner of wxPython. I am trying to write a GUI plug-in in another freeware called TexGen (

_http://texgen.sourceforge.net/index.php/Main_Page_). TexGen has a Python interface to run Python script within the application. So I wrote a trial wxPython script. It was to run in TexGen to create a frame. Afterwards, some functions in TexGen became problematic, i.e. “file->save TexGen file” raising an error message - TexGenGUI.exe has encountered a problem and needs to close. I wonder anything can be done within wxpython script or I need to change TexGen setting. Really appreciate your time to help look at this issue.

I use Windows XP and WxPython2.8 installed for Python2.5. The script is below:

Is TexGen designed to allow GUI plugins or just non-GUI scripts that it runs in the background? If the former then does it have some API for integrating your plugin with their GUI and event loop? Have you asked the TexGen people if running wxPython applications as a plugin is supported or expected to work?

My guess is that the cleanup that is done when the wx.App object is destroyed is stomping on something in TexGen’s UI code, open handles, or etc., so there are a couple things you could try to workaround this.

  1. Don’t let the app object be destroyed. Only create one of them and reuse it each time the wx scripts are run.

  2. Run the wx code in another thread.

  3. Both #1 and #2.


Robin Dunn

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


wxpython-users mailing list

wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

x. zeng wrote:

Robin,
Your suggestions sound very sensible.

TexGen was originally designed to allow just non-GUI scripts to run in the background. It works well with wxPython to a certain level. To my experience, the conflict of WxPython and TexGen is that Wx takes full control of system output while malfunctioning TexGen output. I did try setting redirect output behaviour. It did not help. So I wonder that may not be the point.

TexGen UI is written using wxWidgets and all functions are wrapped to python using SWIG. TexGen C++ code will create an instance of wxApp, while my wxpython script also creates a wx.App object. Your first suggestion is implying there should only be a single instance of this class. If I can somehow get a reference to TexGen's wxApp instance from python then I can reuse that instead (maybe). I don't know exactly how to do that. Would you please enlighten me on this?

If it's already a wx app then you should not create a wx.App object at all. Just create and show your frame and let the app deliver events to it. You will probably need to ensure that the application and wxPython are both using the same wx DLLs.

···

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