bugfix drpython165, wxpython 2.8.6.1 (winxp)

coldway
2007-11-14
2013-04-26
  • coldway
    coldway
    2007-11-14

    When opening a file, I get (in windows) the error message:

    Traceback (most recent call last):
      File "F:\nj2007\python\drpython\drpython.py", line 2186, in OnOpen
        self.OpenFile(filenames[0], False, encoding=theencoding)
      File "F:\nj2007\python\drpython\drpython.py", line 2985, in OpenFile
        self.reloaddocumentsmenu()
      File "F:\nj2007\python\drpython\drpython.py", line 3034, in reloaddocumentsmenu
        self.documentsmenu.Remove(mnuitems[x].GetId())
      File "E:\Python25\lib\site-packages\wx-2.8-msw-unicode\wx\_core.py", line 10821, in __getitem__
        return _core_.MenuItemList___getitem__(*args, **kwargs)
    IndexError: sequence index out of range

    (windows)

    I have solved it by the next fix:
    in file 'drpython.py'

    the lines with the numbers 3030 and so on are replaced by the next lines:

    #        x = 0
    #        while x < num:
            x = num-1
            while x >= 0:
                self.documentsmenu.Remove(mnuitems[x].GetId())
                #mnuitems[x].Destroy()
    #            x = x + 1
                x -= 1            

     
    • I suspect, this happens only with this new wxPython Version on Windows.

      That Bug was already reported:
      https://sourceforge.net/tracker/index.php?func=detail&aid=1815108&group_id=83074&atid=568238

      I think, it resembles your fix. You could get also the last version (from svn), there should be also the fix in there. But nevertheless, cool that you find (your) fix yourself too.

       
      • Yes, apparently this is the same bug fixed in r267. Indexing seems not to work correctly in newer wx versions.

        The problem is that this is a common pattern in drPython:

                num = len(mnuitems)
                x = 0
                while x < num:
                    self.documentsmenu.Remove(mnuitems[x].GetId())
                    #mnuitems[x].Destroy()
                    x = x + 1

        I think it should be replaced for a more pythonic loop (as in r267):

                for mnuitem in mnuitems:
                    self.documentsmenu.Remove(mnuitem.GetId())

        There is some reason to do the first unpithonic loop?
        Sometimes removing or adding items inside a for loop causes undefined behaviour, but this doesn't seem to be the case.

         
        • I don't think, theres a reason for that. Of course, your pythonic way is far more better. Maybe it was a coding style in the first phases of Drpython, who knows. ;) Would you like to check in this?
          this loop is also in def setupdocumentsmenu.

          BTW: If I update DrPython, I have still r261.

           
          • Sorry, I mean r257
            I hadn't so much time last weeks, but I hope I could review that in this weekend.
            Regards

             
    • coldway
      coldway
      2007-11-17

      Thank you for the reponses.

      The solution:

         for mnuitem in mnuitems:
            self.documentsmenu.Remove(mnuitem.GetId())

      has the folowing complication:

      the statement "self.documentsmenu.Remove(mnuitem.GetId())" change "mnuitems"
      So the codition in the for-statement is changed.

      My advice is: don't use such tricky constructions.

      "You could get also the last version (from svn)"

      I don't no how to get the last version.
      Please explain me in more detail.

       
      • About for condition, yes, as I stated in previous post, changing a list inside a loop is not a good practice, but  it doesn't seems to be a problem here:

        menuitems (id): [810,-2,1098,-2,6061,6062,-2,8001,8000]
        removing: 810
        removing: -2
        removing: 1098
        removing: -2
        removing: 6061
        removing: 6062
        removing: -2
        removing: 8001
        removing: 8000

        Here, mnuitems is not just a list, is a <class 'wx._core.MenuItemList'>, that may be handling this things correctly.

        Anyway, I prefer a pythonic solution (if it doesn't cause any troubles, of course), but if you prefer another, less-pythonic solution, that's fine for me :-)

         
    • You need an svn client and then checkout. rapidsvn, esvn (both for linux and windows). I personally use on windows tortoise svn, (a context menu in filemanager (explorer or total commander), and I find it very comfortable.

      The first time, you do a checkout and type in:
      https://drpython.svn.sourceforge.net/svnroot/drpython and specify a target directory.

      If you are more interested, I could add you as member and give you a write access to svn.

      BTW: As I said, the code is very old and not from me. ;)