|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
|
|
#1
|
|||
|
|||
|
Py2exe and WxPython XRC issues
Hello. First poster here, so please be gentle.
I'm writing a WxPython-based program using XRC resource files for the UI design. The prog works magnificently when run as regular pyw. However, I want to compile it, and py2exe seemed like the most reasonable choice (pyinstaller unpacks stuff to temporary locations, and I'm kind of allergic to that kind of behavior). Problem is, py2exe seems to think it shouldn't include the XRC file in the resource.zip, but then the exe tries to find the damn thing there anyways. OK, some code for you to try: fiff.py Code:
import os
import wx
from wx import xrc
import sys
# Graphical stuff
class TempestApp(wx.App):
def OnInit(self): ## When the application class is instanced...
self.res = ""
self.res = wx.xrc.XmlResource(sys.path[0] + "\\noname.xrc") ## load the xrc file into self.res
self.init_frame() ## Initialize main frame and its bindings
return True
## Initializing
def init_frame(self):
self.frame = self.res.LoadFrame(None, 'FrameMain')
self.frame = wx.Frame(None, -1, "Hello World")
Tempest = TempestApp()
Tempest.frame.Show()
Tempest.MainLoop()
setup.py Code:
# setup.py import sys, os from distutils.core import setup import py2exe import glob setup(console=["fiff.py"]) ...and the noname.xrc: Code:
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?> <resource xmlns="http://www.wxwindows.org/wxxrc" version="2.3.0.1"> <object class="wxFrame" name="FrameMain"> <style>wxDEFAULT_FRAME_STYLE|wxTAB_TRAVERSAL</style> <size>480,400</size> <title>Tempest</title> <object class="wxPanel" name="m_panel11"> <style>wxTAB_TRAVERSAL</style> <object class="wxBoxSizer"> <orient>wxHORIZONTAL</orient> <object class="sizeritem"> <option>0</option> <flag>wxALL</flag> <border>5</border> <object class="wxStaticText" name="m_staticText1"> <label>Project:</label> </object> </object> <object class="sizeritem"> <option>1</option> <flag>wxALL</flag> <border>5</border> <object class="wxTextCtrl" name="TxtProjectName"> <value></value> <maxlength>0</maxlength> </object> </object> </object> </object> </object> </resource> What I want: I want the generated fiff.exe to see noname.xrc as an external resource. The point here is to be able to edit the interface without recompiling the exe. What I've tried: * I've tried adding data_files=[ ("",["noname.xrc",])] to the setup.py. That just copied the noname.xrc to the dist dir. * To even get the error message, I had to add the <i>self.frame = wx.Frame(None, -1, "Hello World")</i> row. If commented, the fiff.exe doesn't even give me an error, it just flashes an error window and closes down. * I've tried adding noname.xrc to the library.zip, but that didn't change anything. There. I don't think I've forgotten anything. Please, any comment or help is deeply appreciated. |
|
#2
|
|||
|
|||
|
Here's what (I think) you need to do.
First change Code:
self.res = wx.xrc.XmlResource(sys.path[0] + "\\noname.xrc") to simply read Code:
self.res = wx.xrc.XmlResource("noname.xrc")
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Python Programming > Py2exe and WxPython XRC issues |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|