Ver Mensaje Individual
  #1 (permalink)  
Antiguo 09/04/2014, 01:59
Principe_Azul
Invitado
 
Mensajes: n/a
Puntos:
Duda con ListCtrl (se pierden algunas líneas de algunas filas)

Hola a todos!!

Tengo una duda con ListCtrl, les comento que hace unos días había terminado un programa que necesitaba, por suerte lo pude hacer bien y había algo que resolví gracias a razpeitia y a un usuario que respondió su mismo tema con la solución del problema.
El código es este:

Código Python:
Ver original
  1. import wx
  2. import wx.lib.mixins.listctrl  as  listmix
  3.  
  4. import sys
  5. import time
  6.        
  7. #----------------------------------------------------------------------
  8. class Log:
  9.     r"""\brief Needed by the wxdemos.
  10.    The log output is redirected to the status bar of the containing frame.
  11.    """
  12.  
  13.     def WriteText(self,text_string):
  14.         self.write(text_string)
  15.  
  16.     def write(self,text_string):
  17.         wx.GetApp().GetTopWindow().SetStatusText(text_string)
  18.  
  19. #----------------------------------------------------------------------
  20. # The panel you want to test (TestVirtualList)
  21. #----------------------------------------------------------------------
  22.  
  23. musicdata = {
  24. 1 : ("Bad English", "The Price Of Love", "Rock"),
  25. 2 : ("DNA featuring Suzanne Vega", "Tom's Diner", "Rock"),
  26. 3 : ("George Michael", "Praying For Time", "Rock"),
  27. 4 : ("Gloria Estefan", "Here We Are", "Rock"),
  28. 5 : ("Linda Ronstadt", "Don't Know Much", "Rock"),
  29. 6 : ("Michael Bolton", "How Am I Supposed To Live Without You", "Blues"),
  30. 7 : ("Paul Young", "Oh Girl", "Rock"),
  31. 8 : ("Paula Abdul", "Opposites Attract", "Rock"),
  32. 9 : ("Richard Marx", "Should've Known Better", "Rock"),
  33. 10: ("Rod Stewart", "Forever Young", "Rock"),
  34. 11: ("Roxette", "Dangerous", "Rock"),
  35. 12: ("Sheena Easton", "The Lover In Me", "Rock"),
  36. 13: ("Sinead O'Connor", "Nothing Compares 2 U", "Rock"),
  37. 14: ("Stevie B.", "Because I Love You", "Rock"),
  38. 15: ("Taylor Dayne", "Love Will Lead You Back", "Rock"),
  39. 16: ("The Bangles", "Eternal Flame", "Rock"),
  40. 17: ("Wilson Phillips", "Release Me", "Rock"),
  41. 18: ("Billy Joel", "Blonde Over Blue", "Rock"),
  42. 19: ("Billy Joel", "Famous Last Words", "Rock"),
  43. 20: ("Billy Joel", "Lullabye (Goodnight, My Angel)", "Rock"),
  44. 21: ("Billy Joel", "The River Of Dreams", "Rock"),
  45. 22: ("Billy Joel", "Two Thousand Years", "Rock"),
  46. 23: ("Janet Jackson", "Alright", "Rock"),
  47. 24: ("Janet Jackson", "Black Cat", "Rock"),
  48. 25: ("Janet Jackson", "Come Back To Me", "Rock"),
  49. 26: ("Janet Jackson", "Escapade", "Rock"),
  50. 27: ("Janet Jackson", "Love Will Never Do (Without You)", "Rock"),
  51. 28: ("Janet Jackson", "Miss You Much", "Rock"),
  52. 29: ("Janet Jackson", "Rhythm Nation", "Rock"),
  53. 30: ("Janet Jackson", "State Of The World", "Rock"),
  54. 31: ("Janet Jackson", "The Knowledge", "Rock"),
  55. 32: ("Spyro Gyra", "End of Romanticism", "Jazz"),
  56. 33: ("Spyro Gyra", "Heliopolis", "Jazz"),
  57. 34: ("Spyro Gyra", "Jubilee", "Jazz"),
  58. 35: ("Spyro Gyra", "Little Linda", "Jazz"),
  59. 36: ("Spyro Gyra", "Morning Dance", "Jazz"),
  60. 37: ("Spyro Gyra", "Song for Lorraine", "Jazz"),
  61. 38: ("Yes", "Owner Of A Lonely Heart", "Rock"),
  62. 39: ("Yes", "Rhythm Of Love", "Rock"),
  63. 40: ("Cusco", "Dream Catcher", "New Age"),
  64. 41: ("Cusco", "Geronimos Laughter", "New Age"),
  65. 42: ("Cusco", "Ghost Dance", "New Age"),
  66. 43: ("Blue Man Group", "Drumbone", "New Age"),
  67. 44: ("Blue Man Group", "Endless Column", "New Age"),
  68. 45: ("Blue Man Group", "Klein Mandelbrot", "New Age"),
  69. 46: ("Kenny G", "Silhouette", "Jazz"),
  70. 47: ("Sade", "Smooth Operator", "Jazz"),
  71. 48: ("David Arkenstone", "Papillon (On The Wings Of The Butterfly)", "New Age"),
  72. 49: ("David Arkenstone", "Stepping Stars", "New Age"),
  73. 50: ("David Arkenstone", "Carnation Lily Lily Rose", "New Age"),
  74. 51: ("David Lanz", "Behind The Waterfall", "New Age"),
  75. 52: ("David Lanz", "Cristofori's Dream", "New Age"),
  76. 53: ("David Lanz", "Heartsounds", "New Age"),
  77. 54: ("David Lanz", "Leaves on the Seine", "New Age"),
  78. }
  79.  
  80. n = 1000
  81. l = musicdata.values()
  82. L = {}
  83. for i in xrange(n):
  84.     L[i] = l[i % len(l)]
  85. musicdata = L
  86.  
  87. class TestVirtualList(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin, listmix.ColumnSorterMixin):
  88.     def __init__(self, parent,log):
  89.         wx.ListCtrl.__init__( self, parent, -1, style=wx.LC_REPORT|wx.LC_VIRTUAL|wx.LC_HRULES|wx.LC_VRULES)
  90.         self.log=log
  91.  
  92.         #adding some art
  93.         self.il = wx.ImageList(16, 16)
  94.         a={"sm_up":"GO_UP","sm_dn":"GO_DOWN","w_idx":"WARNING","e_idx":"ERROR","i_idx":"QUESTION"}
  95.         for k,v in a.items():
  96.             s="self.%s= self.il.Add(wx.ArtProvider_GetBitmap(wx.ART_%s,wx.ART_TOOLBAR,(16,16)))" % (k,v)
  97.             exec(s)
  98.         self.SetImageList(self.il, wx.IMAGE_LIST_SMALL)
  99.  
  100.         #adding some attributes (colourful background for each item rows)
  101.         self.attr1 = wx.ListItemAttr()
  102.         self.attr1.SetBackgroundColour("yellow")
  103.         self.attr2 = wx.ListItemAttr()
  104.         self.attr2.SetBackgroundColour("light blue")
  105.         self.attr3 = wx.ListItemAttr()
  106.         self.attr3.SetBackgroundColour("purple")
  107.  
  108.         #building the columns
  109.         self.InsertColumn(0, "Artist")
  110.         self.InsertColumn(1, "Title")
  111.         self.InsertColumn(2, "Genre")
  112.         self.SetColumnWidth(0, 150)
  113.         self.SetColumnWidth(1, 220)
  114.         self.SetColumnWidth(2, 100)
  115.  
  116.         #These two should probably be passed to init more cleanly
  117.         #setting the numbers of items = number of elements in the dictionary
  118.         self.itemDataMap = musicdata
  119.         self.itemIndexMap = musicdata.keys()
  120.         self.SetItemCount(len(musicdata))
  121.        
  122.         #mixins
  123.         listmix.ListCtrlAutoWidthMixin.__init__(self)
  124.         listmix.ColumnSorterMixin.__init__(self, 3)
  125.  
  126.         #sort by genre (column 2), A->Z ascending order (1)
  127.         self.SortListItems(2, 1)
  128.  
  129.         #events
  130.         self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnItemSelected)
  131.         self.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.OnItemActivated)
  132.         self.Bind(wx.EVT_LIST_ITEM_DESELECTED, self.OnItemDeselected)
  133.         self.Bind(wx.EVT_LIST_COL_CLICK, self.OnColClick)
  134.  
  135.     def OnColClick(self,event):
  136.         event.Skip()
  137.  
  138.     def OnItemSelected(self, event):
  139.         self.currentItem = event.m_itemIndex
  140.         self.log.WriteText('OnItemSelected: "%s", "%s", "%s", "%s"\n' %
  141.                            (self.currentItem,
  142.                             self.GetItemText(self.currentItem),
  143.                             self.getColumnText(self.currentItem, 1),
  144.                             self.getColumnText(self.currentItem, 2)))
  145.  
  146.     def OnItemActivated(self, event):
  147.         self.currentItem = event.m_itemIndex
  148.         self.log.WriteText("OnItemActivated: %s\nTopItem: %s\n" %
  149.                            (self.GetItemText(self.currentItem), self.GetTopItem()))
  150.  
  151.     def getColumnText(self, index, col):
  152.         item = self.GetItem(index, col)
  153.         return item.GetText()
  154.  
  155.     def OnItemDeselected(self, evt):
  156.         self.log.WriteText("OnItemDeselected: %s" % evt.m_itemIndex)

" Nota: Pueden ver código completo aquí: http://code.activestate.com/recipes/...al-wxlistctrl/ "


cuando abro el programa (luego de que el mismo se abre, lo redimensiono manualmente ya que la ventana es pequeña para todo el ListCtrl) se ve así:

http://subefotos.com/ver/?a3d898e047...3806a3625o.jpg

Pero mi duda es, ¿por qué aquí sucede esto?:

http://subefotos.com/ver/?3f9b2d2577...f3e9b57f5o.jpg

Pero cuando presiono el botón "Av Pág" del teclado, esto ya no ocurre, osea las filas se conservan en sus lugares, no hay problema cuando presiono Av Pág:

http://subefotos.com/ver/?959626fc4a...eb246f352o.jpg

Yo no sé porque pasa esto, ustedes son los expertos (En hora buena!!) y podrán seguramente explicarme porque ocurre esta acción inesperada!!!

También probé otro programa, igual a este pero sin imágenes y también pasa lo mismo.

Desde ya muchas gracias!!

PD: Tengo un escaner de puertos que trabaja exactamente igual que el programa que puse recién, osea el ListCtrl es el mismo y ese programa no tiene ese problema (No se en que lenguaje estará, probablemente C).

PD: Agradezco a razpeitia por dejar este código que me ha servido a reducir el tiempo en cargar gran cantidad de Items, lo probé y funcionó perfecto.

Cargué sin Virtual List 50.000 líneas: Demora 20 Segs.
Cargué con Virtual List 50.000 líneas: Demora 1 Seg.

Última edición por Principe_Azul; 09/04/2014 a las 02:26