CustomTreeCtrl bug with multi-byte Unicode text

obdev <[email protected]>
Newsgroups gmane.comp.python.wxpython.devel
Message-ID <[email protected]>
Hi

This is my first bug report so please bear with me.

I have a filesystem navigator app that uses HyperTreeCtrl, based on the 
demo code for this control.

If I resize the column or the top-level frame, the 'ellipsizing' code seems 
to have intermittent problems with multi-byte Unicode char strings when 
calculating text widths. It also triggers some asserts on exit.

This happens on both Linux and Mac. Not tried on Windows.

I have a attached a small test case which reproduces the error(s).

Thanks.

----------

Environment:

wx.version(): '3.0.2.0 gtk2 (classic)'
uname: Linux mint 3.13.0-37-generic #64-Ubuntu SMP Mon Sep 22 21:28:38 UTC 
2014 x86_64 x86_64 x86_64 GNU/Linux
Python 2.7.6 (default, Oct 26 2016, 20:30:19) 
[GCC 4.8.4] on linux2

Output:

(1) Periodically when the bug is triggered

Traceback (most recent call last):
  File 
"/home/duncang/openbackup/wx/wxPython-src-3.0.2.0/wxPython/wx/lib/agw/hypertreelist.py", 
line 3288, in OnPaint
    y, x_maincol = self.PaintLevel(self._anchor, dc, 0, 0, x_maincol)
  File 
"/home/duncang/openbackup/wx/wxPython-src-3.0.2.0/wxPython/wx/lib/agw/hypertreelist.py", 
line 3195, in PaintLevel
    y, x_maincol = self.PaintLevel(child, dc, level+1, y, x_maincol)
  File 
"/home/duncang/openbackup/wx/wxPython-src-3.0.2.0/wxPython/wx/lib/agw/hypertreelist.py", 
line 3106, in PaintLevel
    self.PaintItem(item, dc)
  File 
"/home/duncang/openbackup/wx/wxPython-src-3.0.2.0/wxPython/wx/lib/agw/hypertreelist.py", 
line 3006, in PaintItem
    text = ChopText(dc, text, maxsize)
  File 
"/home/duncang/openbackup/wx/wxPython-src-3.0.2.0/wxPython/wx/lib/agw/customtreectrl.py", 
line 649, in ChopText
    x, y = dc.GetTextExtent(s)
  File 
"/home/duncang/openbackup/wx/wxPython-src-3.0.2.0/wxPython/wx/_gdi.py", 
line 4127, in GetTextExtent
    return _gdi_.DC_GetTextExtent(*args, **kwargs)
  File "/usr/lib/python2.7/encodings/utf_8.py", line 16, in decode
    return codecs.utf_8_decode(input, errors, True)
UnicodeDecodeError: 'utf8' codec can't decode byte 0xd8 in position 53: 
invalid continuation byte

(2) At interpreter exit

/home/duncang/openbackup/wx/wxPython-src-3.0.2.0/src/gtk/dcclient.cpp(250): 
assert "Assert failure" failed in wxFreePoolGC(): Wrong GC
/home/duncang/openbackup/wx/wxPython-src-3.0.2.0/src/gtk/dcclient.cpp(250): 
assert "Assert failure" failed in wxFreePoolGC(): Wrong GC
/home/duncang/openbackup/wx/wxPython-src-3.0.2.0/src/gtk/dcclient.cpp(250): 
assert "Assert failure" failed in wxFreePoolGC(): Wrong GC
/home/duncang/openbackup/wx/wxPython-src-3.0.2.0/src/gtk/dcclient.cpp(250): 
assert "Assert failure" failed in wxFreePoolGC(): Wrong GC

(3) Mac is very similar but I also get a backtrace on exit

Apr 22 17:30:24  python[13200] <Error>: CGContextRestoreGState: invalid 
context 0x0. Backtrace:
 <_ZN14wxWindowDCImplD2Ev+54>
  <_ZN13wxPaintDCImplD0Ev+27>
   <_ZN9wxPaintDCD0Ev+44>
    <_wrap_delete_DC+107>
     <PySwigObject_dealloc+622>
      <_PyDict_Contains+162>
       <_PyObject_SlotCompare+23622>
        <PyFrame_GetLineNumber+142>
         <PySys_WriteStdout+3026>
          <PyDict_DelItemString+2315>
           <PyDict_Merge+715>
            <PyDict_SetItem+181>
             <PyDict_SetItemString+62>
              <PyImport_Cleanup+311>
               <Py_Finalize+297>
                <Py_Main+2455>

(4) Unicode strings, used for my testing

서울시
ວຽງຈັນ
กรุงเทพมหานคร
Hà Nội
London
أبو ظبي‎
اسلام‌اباد
دبي‎
دولة الإمارات العربية المتحدة
Αθήνα
Αθήναι
Москва
Тошкент
मुंबई
ঢাকা
နေပြည်တော်
ශ්‍රී ජයවර්ධනපුර කෝට්ටේ
北京
東京都


-- 
You received this message because you are subscribed to the Google Groups "wxPython-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
For more options, visit https://groups.google.com/d/optout.
tree_text_bug_test.py (text/x-python, 2.5 KB)
# coding=UTF-8

import wx
import wx.lib.agw.hypertreelist as htl
import wx.lib.agw as agw

class HyperTreeListDemo(wx.Frame):

    def __init__(self, parent):

        wx.Frame.__init__(self, parent)

        self.SetTitle("HyperTreeList Demo")
        self.panel = wx.Panel(self, -1, style=wx.WANTS_CHARS)
        sizer = wx.BoxSizer(wx.VERTICAL)
        self.tree = HyperTreeList(self.panel, -1)
        sizer.Add(self.tree, 1, wx.EXPAND)
        self.panel.SetSizer(sizer)
        sizer.Layout()

class HyperTreeList(htl.HyperTreeList):

    def __init__(self, parent, id=wx.ID_ANY, pos=wx.DefaultPosition,
                 size=wx.DefaultSize,
                 style=wx.SUNKEN_BORDER,
                 agwStyle=wx.TR_HAS_BUTTONS | htl.TR_ELLIPSIZE_LONG_ITEMS,
                 log=None):

        htl.HyperTreeList.__init__(self, parent, id, pos, size, style, agwStyle)

        self.AddColumn("Filename")
        self.AddColumn("Column 1")
        self.AddColumn("Column 2")
        self.SetMainColumn(0)
        self.SetColumnWidth(0, 175)

        self.root = self.AddRoot("/", ct_type=1)
        self.SetItem3State(self.root, False)
        self.root.SetHasPlus()

        # treeitems = [u"Hà Nội", u"London", u"北京", u"東京都", u"دبي", u"ঢাকা",   u"أبو ظبي?", u"دولة الإمارات العربية المتحد",
                        # u"मुंबई",  u"ශ්?රී ජයවර්ධනපුර කෝට්ටේ", u"Αθήνα", u"Москва", u"ວຽງຈັນ", u"Αθήναι", u"Тошкент", u"서울시", "اسلام?اباد", u"နေပ?ည?တော?", u"กรุงเทพมหานคร"]

        treeitems = ["Hà Nội", "London", "北京", "東京都", "دبي", "ঢাকা",   "أبو ظبي", "دولة الإمارات العربية المتحد",
                                                "मुंबई",  u"ශ්?රී ජයවර්ධනපුර කෝට්ටේ", "Αθήνα", "Москва", "ວຽງຈັນ", "Αθήναι", "Тошкент", "서울시", "اسلام?اباد", "နေပ?ည?တော?", "กรุงเทพมหานคร"]

        for t in treeitems:
            print("appending %s, len = %d" % (t, len(t)))
            child = self.AppendItem(self.root, t, ct_type=1)


class MyApp(wx.App):
	def OnInit(self):
		self.frame = HyperTreeListDemo(None)
		self.frame.Show()
		return True	

if __name__ == '__main__':
	app = MyApp(False)
	app.MainLoop()
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.