Unicode error in wx_gdi ?
Hello All, I still shaking out my last few bugs in my tile matching game: I am now down to one stumper for me: 1) when I initialize wxPython 2) from an exe that I have created with py2exe 3) when the executable is located on the desktop as opposed to somewhere on C or D directly 4) when My Desktop is not written in ascii but instead Korean hangul I get this error: Traceback (most recent call last): File shanghai.py, line 13, in ? File wxPython\__init__.pyc, line 10, in ? File wxPython\_wx.pyc, line 3, in ? File wxPython\_core.pyc, line 15, in ? File wx\__init__.pyc, line 42, in ? File wx\_core.pyc, line 10994, in ? File wx\_gdi.pyc, line 2443, in ? File wx\_gdi.pyc, line 2340, in Locale_AddCatalogLookupPathPrefix UnicodeDecodeError: 'ascii' codec can't decode byte 0xbf in position 26: ordinal not in range(128) Granted this may seem like an obscure error, but the net effect is that I cannot use wxPython for my games and applications as many of my users will place the executable directly on their desktop and the path of the desktop contains non-ascii paths. What do i do from here? Do I go into wx_gdi.py and fix it so that it uses unicode instead of ascii? I have not yet made any changes to other people's libraries... Any help would be much appreciated, -Erik -- http://mail.python.org/mailman/listinfo/python-list
Detecting the change of screen resolution with SDL or PyGame
Hello All, I am trying to clean up some polish bugs with the Shanghai game I am working on and I am currently stuck on trying to get the right event for detecting when the user has changed the desktop resolution. I have tried trapping the following events: 1) SDL_ACTIVEEVENT 2) SDL_VIDEOEXPOSE 3) SDL_VIDEORESIZE These are the events that are passed through to pygame as pygame.ACTIVEEVENT and so on... #3 - SDL_VIDEORESIZE This is what I looked at first and I was wrong, this is only for the WINDOW being resized... not the desktop resoltion #2 - SDL_VIDEOEXPOSE After watching the events in a debugger when I change the desktop resolution I find out that this IS the event that is generated from changing the desktop resolution. Okay no problem right? Time to call: self.screen = self.pygame.display.set_mode( size ) and draw() again right? Well sure, now my game repaints properly when the desktop resolution changes. So What is the problem? Well now EVERY TIME another window draws on top of my game's window a SDL_VIDEOEXPOSE event is triggered. There does not appear to be any flags associated with this event. So I am having trouble distinguishing from an overlapping window and changing the desktop resolution. So I tried this: 1) call pygame.display.Info() at the startup of my game and save off this structure 2) call it again after getting a SDL_VIDEOEXPOSE event and comparing to see if it has changed at all. The problem with this is that apparantly the VidInfo structure DOES NOT change when changing desktop resolution... So then I tried using SDL_ACTIVEEVENT and simply leaving the display black and unpainted after the user changes the resolution until the user rolls the mouse over the game window and bringing it back to focus. This works. However, it gets annoying watching the screen repaint everytime the window gains focus Do you guys have any leads for me to try? This HAS to be a problem solved many times before... Thank you, -Erik -- http://mail.python.org/mailman/listinfo/python-list
Re: Trouble with the encoding of os.getcwd() in Korean Windows
Hello All, Well as usual, after I post I keep on digging and I found the answer... http://cjkpython.i18n.org/ Has the encodings for Chinese, Korean and Japanese... and I took the hint that I found from the foundationstore and tried cp949 and wa-la! it works... Now, the question remains, how do I write windows python code that will work on all flavors of windows languages? The wxPython demo works, because I have installed it on a path on my machine that does not have Hangul in the path. But if I distribute something to end users, they most certainly have Hangul in their path, or Japanese or Chinese, or some other encoding... so how do you get the correct encoding from the system? Thanks, -Erik -- http://mail.python.org/mailman/listinfo/python-list
Re: Trouble with the encoding of os.getcwd() in Korean Windows
Thank you Vincent, I will try this... I did get over my troubles with this new code snippet: encoding = locale.getpreferredencoding() htmlpath = os.getcwd() htmlpath = htmlpath.decode( encoding ) That seems to be working well too. I can write to these files and I can open them with the file dialog, but this is now failing with the famous aschii error: webbrowser.open( htmlpath, True, True ) -- http://mail.python.org/mailman/listinfo/python-list
Re: Trouble with the encoding of os.getcwd() in Korean Windows
Hello All, sorry for all the posts... I am *almost* there now... okay I have this code: import sys, os encoding = locale.getpreferredencoding() htmlpath = os.getcwd() htmlpath = htmlpath.decode( encoding ) . write to the file . . file is written fine, and can be opened by both FireFox and IE and displays fine ... webbrowser.open( htmlpath.encode ( encoding ), True, True ) the line above now works fine (fixed the ascii error) but *NOW* my problem is that FirefOX pops up a message box complaining that the file does not exist, but it certainly does, it just doesn't like what it is called... Any ideas now? Thanks, -Erik -- http://mail.python.org/mailman/listinfo/python-list
Re: Trouble with the encoding of os.getcwd() in Korean Windows
Ah and PS, again this is only for paths that are non-aschii or at least have Korean in them... The broswer bit launches successfully in other locations. -Erik -- http://mail.python.org/mailman/listinfo/python-list
Re: Trouble with the encoding of os.getcwd() in Korean Windows
Wow, even more information. When I set my default browser to IE, it launches fine... so it is something about FireFox being more picky than IE... Where would I hunt down this sort of problem? Sounds rare, should I contact Mozilla, or can you guys spot something silly I am doing? Thank you, -Erik -- http://mail.python.org/mailman/listinfo/python-list
in wxPython, how to minimize the window in absence of minimize button?
Hello All, I now have a wx.NO_BORDER frame that I have written dragging code for... I like my window this way as it looks sleeker and I am now installing some image buttons. Now I would like to create a new minimize button from an image, and then capture that mouse down and cause it to minimize the window... I can make buttons all day long, despite all of my googling I still cannot figure out what method I should call with my minimize button... Please help thank you, -Erik -- http://mail.python.org/mailman/listinfo/python-list
Re: in wxPython, how to minimize the window in absence of minimize button?
Damn, I am dumb... self.Iconize( True ) Sorry. But a helpful tip is that the demo code *surrounding* the wxPython demo is VERY useful, I never looked at that before! -- http://mail.python.org/mailman/listinfo/python-list
Effbot's SimpleXMLWriter fails when py2exe'd
Hello All, So I have been using Effbot's XML stuff a lot! And I have been using py2exe, pygame and wxPython all mixed together... I am getting this strange error log when writing XML files with his XML writer. It appears to be fouling up on the encoding, ONLY in the exe version. Runs fine and great as a python script. What this does is leave the file hanging open... I could write out the XML myself, but I would rather use his class... any ideas why it broke? Thank you, -Erik code snippet: def SaveVocabTree( self ): ElementTree( self.vocabXMLTree ).write(self.currentPath, encoding='utf-8') error log: Traceback (most recent call last): File vocab.py, line 457, in OnAdd File vocab.py, line 483, in AddWord File vocab.py, line 494, in SaveVocabTree File elementtree\ElementTree.pyc, line 666, in write File elementtree\ElementTree.pyc, line 684, in _write File elementtree\ElementTree.pyc, line 754, in _encode LookupError: unknown encoding: utf-8 -- http://mail.python.org/mailman/listinfo/python-list
Re: ElementTree cannot parse UTF-8 Unicode?
There is something wrong with the physical file... I d/l a trial version of XML Spy home edition and built an equivalent of the korean test file, and tried it and it got past the element tree error and now I am stuck with the wxEditCtrl error. To build the xml file in the first place I had code that looked like this: d=wxFileDialog( self, message=Choose a file, defaultDir=os.getcwd(), defaultFile=, wildcard=*.xml, style=wx.SAVE | wxOVERWRITE_PROMPT | wx.CHANGE_DIR) if d.ShowModal() == wx.ID_OK: # This returns a Python list of files that were selected. paths = d.GetPaths() layout = '?xml version=\1.0\ encoding=\UTF-8\?\n' L1Word = self.t1.GetValue() L2Word = 'undefined' layout += 'Vocab\n' layout += 'Word L1=\'' + L1Word + '\'/Word\n' layout += '/Vocab' open( paths[0], 'w' ).write(layout) d.Destroy() So apprantly there is something wrong with physically constructing the file in this manner? Thank you, -Erik -- http://mail.python.org/mailman/listinfo/python-list
Re: ElementTree cannot parse UTF-8 Unicode?
That was a great clue. I am an idiot and tapped on the wrong download link... now I can read and parse the xml file fine - as long as I create it in XML spy - if I create it by this method: d=wxFileDialog( self, message=Choose a file, defaultDir=os.getcwd(), defaultFile=, wildcard=*.xml, style=wx.SAVE | wxOVERWRITE_PROMPT | wx.CHANGE_DIR) if d.ShowModal() == wx.ID_OK: # This returns a Python list of files that were selected. paths = d.GetPaths() layout = '?xml version=\1.0\ encoding=\UTF-8\?\n' L1Word = self.t1.GetValue() L2Word = 'undefined' layout += 'Vocab\n' layout += 'Word L1=\'' + L1Word + '\'/Word\n' layout += '/Vocab' open( paths[0], 'w' ).write(layout) I get hung up on the write statement, I am off to look for a a Unicode capable file write I think... -Erik -- http://mail.python.org/mailman/listinfo/python-list
Re: ElementTree cannot parse UTF-8 Unicode?
Woo-hoo! Everything is working now! Thank you everyone! The TWO problems I had: 1) I needed to save my XML file in the first place with this code: f = codecs.open(paths[0], 'w', 'utf8') 2) I needed to download the UNICODE version of wxPython, duh. So why are there non-UNICODE versions of wxPython??? To save memory or something??? Thank you all! Best! -Erik -- http://mail.python.org/mailman/listinfo/python-list
ElementTree cannot parse UTF-8 Unicode?
Hello All, I am getting an error of not well-formed at the beginning of the Korean text in the second example. I am doing something wrong with how I am encoding my Korean? Do I need more of a wrapper about it than simple quotes? Is there some sort of XML syntax for indicating a Unicode string, or does the Elementree library just not support reading of Unicode? here is my test snippet: from elementtree import ElementTree vocabXML = ElementTree.parse('test2.xml').getroot() where I have two data files: this one works: ?xml version=1.0 encoding=UTF-8? Vocab Word L1='Hahha'/Word /Vocab this one fails: ?xml version=1.0 encoding=UTF-8? Vocab Word L1=!/Word /Vocab -- http://mail.python.org/mailman/listinfo/python-list
Re: ElementTree cannot parse UTF-8 Unicode?
Hello Fredrik, 1) The exact error is in line 1160 of self._parser.Parse(data, 0 ): xml.parsers.expat.ExpatError: not well-formed (invalid token): line 3, column 16 2) You are right in that the print of the file read works just fine. 3) You are also right in that the digitally encoded unicode also works fine. However, this solution has two new problems: 1) The xml file is now not human readable 2) After ElementTree gets done parsing it, I am feeding the text to a wx.TextCtrl via .SetValue() but that is now giving me an error message of being unable to convert that style of string So it seems to me, that ElementTree is just not expecting to run into the Korean characters for it is at column 16 that these begin. Am I formatting the XML properly? Thank you, -Erik -- http://mail.python.org/mailman/listinfo/python-list
Re: wxPython and PyGame - do they play well together?
Thank you, My apologies to all for insufficient googling -Erik -- http://mail.python.org/mailman/listinfo/python-list
wxPython and PyGame - do they play well together?
Hello All, I am having a great time with python and pygame, and last night I took a long look at the wxPython demo. I think that rocks as well. So now, my question is do wxPython and PyGame work together? How is the windows event loop managed? How is the display window managed? Is it possible to have some sort of master/slave relationship between the two? Is it possible that either could be dominant? Does this sound too weird? I appreciate any fingers pointing in any directions... Thank you, -Erik -- http://mail.python.org/mailman/listinfo/python-list
Re: pygame + py2exe = bad exe. why?
M.E.Farmer wrote: Erik glad to see you were able to track it down. Have you been succesful in making the changes they mentioned? M.E.Farmer Yes below is a simple script that works. The key was that pygame uses freesansbold.ttf as the default font and that is not copied over in the normal py2exe process. See the end of the setup script. #!/usr/bin/env python from distutils.core import setup import py2exe, pygame import glob, shutil setup(windows=[mahjong.py], name='GoPets Mahjong', version='0.3.1', description='Mahjong for GoPets Users', author='Erik Bethke', author_email='[EMAIL PROTECTED]', url='www.erikbethke.com', py_modules=['mahjong','background','board','tile','textBox'] ) shutil.copytree('data', 'dist/data') shutil.copyfile('freesansbold.ttf', 'dist/freesansbold.ttf') -- http://mail.python.org/mailman/listinfo/python-list
Python! Is! Truly! Amazing!
Hello Everyone, I have to say: Python! Is! Truly! Amazing! So I started with python about a month ago and put in 24 hours across three weekends. My first project was to recreate a simple maze-let thingie that I remember as my first program way back on the Vic-20. That was a quick snap and a pleasure. Since then I have settled down into working on a Mahjong game. I have uploaded a current version at my personal website: www.erikbethke.com/Python/mahjong.zip also note screenshots: www.erikbethke.com/Python/screenshot01.jpg www.erikbethke.com/Python/screenshot02.pg www.erikbethke.com/Python/screenshot03.pg www.erikbethke.com/Python/screenshot04.pg www.erikbethke.com/Python/screenshot05.pg So I have been using Python 2.3.4 as that is what was compatible with the excellent PyGame last month. After reading the posts here I am using wing IDE, and over all I like it... some minor issues and I am sure if I RTFM I would have these handled. I will be buying a bunch of licenses for us. I also used this project to learn a little about XML, so I used XML to fully describe the UI, the tilesets and the tile layouts and have it able to go back and forth between 3 different tilesets, and backgounds. The XML is crappy as you can see I am experimenting with putting some data in attributes and elsewhere in elements. So now I have it laying out the tiles, tile picking correctly, and I was even able to write many new little feature-ettes in wickedly fast single edit-run passes such as this to highlight the currently available matches: def findMatchingTiles(self): matchList = [] visibleTiles = [] for i, c in enumerate ( self.tiles ): if c.state != 'clear': visibleTiles.append( c ) for i, c in enumerate ( visibleTiles ): if self.testForClear( c ): for j, d in enumerate ( visibleTiles ): if d != c and d.tileNum == c.tileNum and self.testForClear( d ): matchList.append( [c, d] ) return matchList def showHint(self): matchList = self.findMatchingTiles() for i, c in enumerate( matchList ): c[0].state='clicked' c[1].state='clicked' self.draw() I have NEVER experienced this kind of programming joy. I am a 33 year-old professional game developer (www.gopetslive.com) and have been in the industry for 11 years, and have been programming since 4th grade like all the rest of you guys. And I am not saying all this to brag, no seriously I am delirious in joy right now. I have a bad cold and went to sleep at 1am last night and woke at 5am just to get back to playing with Python! I have been looking into Python to see if it is a good answer for getting a lot of new fresh mini-game and UI work done for our project GoPets, and clearly it is. I haven't yet explored the server-side but I will. The Mahjong game in the future will take its tile art dynamically from the portraits of the users that are your friends and the people your GoPet has visited recently. Anyways, I am now a super gushing fan-boy. I have worked my way up from a scripter working in crappy proprietary languages to a c++ programmer, to now biz guy. But when I walked away from programming I gave it a grim farewell, c++ work is good, but so much mind goes into it to make progree compared to other creative uses of the mind. But Python rocks, it makes programming very fun again and now I finding myself coming home earlier so I can get to work on Python and I have an entire heap of new projects I wanted to get done. Anyways, the Mahjong game code is quite crappy. No effort has been made to optimize it, nor have I handled any sorts of errors whatsoever. I know it sucks. But I posted the code there anyways in case any one else is just coming along and wants some more example code. I also have no real UI going on. Hit R to randomize the tiles, M to try to setup a solvable game (but my algorithm for this is not very effective yet), and H for hints on tiles that can be matched. Other than the tile art anyone can do what the feel with it. Thank you all for posting here, you have already solved dozens and dozens of questions for me with a little help of google groups. Truly thank you. -Erik -- http://mail.python.org/mailman/listinfo/python-list
Re: Python! Is! Truly! Amazing!
Oh yeah, and farmer, no I didn't yet get back to making an exe by fixing the problem with pygame2exe i just got disctracted getting other things done so fast! -Erik www.gopetslive.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Python! Is! Truly! Amazing!
somehow lost my j's: www.erikbethke.com/Python/screenshot02.jpg www.erikbethke.com/Python/screenshot03.jpg www.erikbethke.com/Python/screenshot04.jpg www.erikbethke.com/Python/screenshot05.jpg -- http://mail.python.org/mailman/listinfo/python-list