[Mypaint-discuss] current git version stopped working? Issue with try-except-finally in WindowManager class.
Hi, I wonder if it's my setup or not, but as of 1704779f6bd2f973b095a5bbdbd7a413f58e8910 (windowing: Move code to new WindowManager class.) MyPaint stopped working on fresh config. It fails like this: Traceback (most recent call last): File ./mypaint, line 130, in module main.main(datapath, confpath) File /home/giniu/dev/mypaint/gui/main.py, line 68, in main run() File /home/giniu/dev/mypaint/gui/main.py, line 43, in run app = application.Application(datapath, confpath, args) File /home/giniu/dev/mypaint/gui/application.py, line 66, in __init__ self.windowmanager = windowing.WindowManager(self) File /home/giniu/dev/mypaint/gui/windowing.py, line 267, in __init__ self.main_window = self.get_window('drawWindow') File /home/giniu/dev/mypaint/gui/windowing.py, line 286, in get_window using_default = self.load_window_position(window_name, window) File /home/giniu/dev/mypaint/gui/windowing.py, line 319, in load_window_position f.close() UnboundLocalError: local variable 'f' referenced before assignment it happened when I removed ~/.mypaint and wanted to see how fresh setup behaves, thus file ~/.mypaint/windowpos.conf does not exists for me. I believe it should work as I look at it, at least it should according to PEP341 that was merged into Python 5 years ago? Unwinding the try-except-finally of PEP341 into try-try-except-finally works... funny, isn't it? That's with latest Python 2.7, they changed something and it worked with previous versions, or maybe there is mistake in code that I didn't noticed? Didn't had time to test it out so I'm not sure if it's bug or not so I'm not sending it to bugtracker but list. Anyway, I attached patch that made it work for me. Cheers, Andrzej. diff --git a/gui/windowing.py b/gui/windowing.py index a502d1a..42e938a 100644 --- a/gui/windowing.py +++ b/gui/windowing.py @@ -303,20 +303,24 @@ class WindowManager(object): def load_window_position(self, name, window): geometry, visible = WINDOW_DEFAULTS.get(name, (None, False)) using_default = True +f = None try: -f = open(self.config_file_path) -for line in f: -if line.startswith(name): -parts = line.split() -visible = parts[1] == 'True' -x, y, w, h = [int(i) for i in parts[2:2+4]] -geometry = '%dx%d+%d+%d' % (w, h, x, y) -using_default = False -break -except IOError: -pass +try: +print self.config_file_path +f = open(self.config_file_path) +for line in f: +if line.startswith(name): +parts = line.split() +visible = parts[1] == 'True' +x, y, w, h = [int(i) for i in parts[2:2+4]] +geometry = '%dx%d+%d+%d' % (w, h, x, y) +using_default = False +break +except IOError: +pass finally: -f.close() +if f: +f.close() # Initial gravities can be all over the place. Fix aberrant ones up # when the windows are safely on-screen so their position can be # saved sanely. Doing this only when the window's mapped means that the ___ Mypaint-discuss mailing list Mypaint-discuss@gna.org https://mail.gna.org/listinfo/mypaint-discuss
Re: [Mypaint-discuss] current git version stopped working? Issue with try-except-finally in WindowManager class.
On 28 December 2010 15:08, Andrzej Giniewicz ggi...@gmail.com wrote: Hi, I wonder if it's my setup or not, but as of 1704779f6bd2f973b095a5bbdbd7a413f58e8910 (windowing: Move code to new WindowManager class.) MyPaint stopped working on fresh config. It fails like this: Thanks a lot for quick testing and the patch! Since f only needs to be closed if it has succesfully opened and thus did not raise IOError, I pushed a fix which puts f.close() inside the try statement. -- Regards Jon Nordby - www.jonnor.com ___ Mypaint-discuss mailing list Mypaint-discuss@gna.org https://mail.gna.org/listinfo/mypaint-discuss
Re: [Mypaint-discuss] current git version stopped working? Issue with try-except-finally in WindowManager class.
On 28 December 2010 19:02, Andrzej Giniewicz ggi...@gmail.com wrote: Anyway, I noticed one more issue I had fixed on my copy for some time (it's setup thing again, Python3 is default on my OS), today I found out how to fix it in right way. Thanks, applied unchanged and pushed! I've actually seen this for a while (I'm running Arch as well) but I've been too lazy to fix it. -- Regards Jon Nordby - www.jonnor.com ___ Mypaint-discuss mailing list Mypaint-discuss@gna.org https://mail.gna.org/listinfo/mypaint-discuss
Re: [Mypaint-discuss] current git version stopped working? Issue with try-except-finally in WindowManager class.
On Tue, Dec 28, 2010 at 8:58 PM, Jon Nordby jono...@gmail.com wrote: Thanks, applied unchanged and pushed! I've actually seen this for a while (I'm running Arch as well) but I've been too lazy to fix it. Cool, now it builds, runs and all tests pass on fresh install on Arch, yay! (well, kind of - the test_*.py file have to be changed from python to python2 to run, but it is unrelated to mypaint itself). Anyway, I wondered if/when you will guess that it's on Arch, seems not many distros switched to Py3K yet, heh? Also I knew you use Arch, and I believe now you can also remove the python2.patch from the mypaint-git package you maintain there? I'd write it under mypaint-git AUR page, but I'm lazy too, and not logged in there at the moment :P Cheers, Andrzej. ___ Mypaint-discuss mailing list Mypaint-discuss@gna.org https://mail.gna.org/listinfo/mypaint-discuss
Re: [Mypaint-discuss] current git version stopped working? Issue with try-except-finally in WindowManager class.
On 28 December 2010 21:28, Andrzej Giniewicz ggi...@gmail.com wrote: On Tue, Dec 28, 2010 at 8:58 PM, Jon Nordby jono...@gmail.com wrote: Thanks, applied unchanged and pushed! I've actually seen this for a while (I'm running Arch as well) but I've been too lazy to fix it. Cool, now it builds, runs and all tests pass on fresh install on Arch, yay! (well, kind of - the test_*.py file have to be changed from python to python2 to run, but it is unrelated to mypaint itself). Anyway, I wondered if/when you will guess that it's on Arch, seems not many distros switched to Py3K yet, heh? No, and I don't expect anyone else will follow anytime soon. Probably not in 2011. Lonely are the brave ;) I believe now you can also remove the python2.patch from the mypaint-git package you maintain there? I'd write it under mypaint-git AUR page, but I'm lazy too, and not logged in there at the moment :P Thanks for the reminder, done now. This also reminds me that there is more stuff that should be fixed in our build system. We are running some stuff directly in the sconscript/sconstruct, instead of creating targets like we should: scons: Reading SConscript files ... Building for python2.7 swig -o mypaintlib_wrap.cpp -noproxydel -python -c++ mypaintlib.i python2.7 generate.py Writing brushsettings.hpp scons: done reading SConscript files. scons: Building targets ... The code that makes that output between the scons: ... lines should actually be executed after building targets. -- Regards Jon Nordby - www.jonnor.com ___ Mypaint-discuss mailing list Mypaint-discuss@gna.org https://mail.gna.org/listinfo/mypaint-discuss