LB_MULTIPLE on wxVListBox

Cool!
Thanks Robin. :smiley:

I didnt know about the abilities of wxMouseEvents. Now i know.

But there is one still missing thing, and it is that, in the frame where i use MyVListBox y have binded the event wx.EVT_LISTBOX
, and with it i do some task in another VListBox but when i deselect the last selected item (so no items keep selected) no event is fired (a bug?).

How can i force it to fire wx.EVT_LISTBOX?

Also, on the other hand, i have maked a switch-color feature between rows, and to use the system defined colors i choose to use the same color as the scrollbar.

def OnDrawBackground(self, dc, rect, n):
    #Draw the background and maybe a border if desired.
    if self.IsSelected(n):
        bg = wx.SystemSettings.GetColour(wx.SYS_COLOUR_HIGHLIGHT

)
else:
if n % 2:
bg = wx.SystemSettings.GetColour(wx.SYS_COLOUR_SCROLLBAR)
else:
bg = self.GetBackgroundColour()
dc.SetBrush(wx.Brush
(bg, wx.SOLID))
dc.DrawRectangle(rect[0],rect[1],rect[2],rect[3])

I couldn’t find a system color for that use. Is there any? Should i keep using scrollbars color?
It is very goodlooking to have 2 colors for use alternatively in each row.

PD:
In my opinion VListBox is a great ctrl. There could be a better example in the demo showing some magics with it. Like showing icons per item, showing some other ctrl when selected and maybe an expand effect.

Also it seems a little forgeted. As there are common methods in ListBoxes not present in VListBox, like toggle.

···

2007/9/1, Robin Dunn < robin@alldunn.com>:

Diego Jacobi wrote:

Hallo, i am making a little program with the use of wxVListBox becouse i

need to put in a good looking way multiple information. This part is
done. The problem is that i need it to be multi selectable. Partially
done with LB_MULTIPLE becouse it requires to press CTRL key to select

multiple and to have the ability to deselect.

I need exactly the same functionality as on with the CTRL key pressed.
But without the needing to press it. Do i explain my self?
It is a filter box, the user should just click to select and click to

deselect.

I have tried to do it manually with LISTBOX_SELECT event and using
Select(selecteditem,False) to deselect. But it seems like Select fires a
SELECT event.

I have tried to avoid it with no success.

Have anyone any idea?

Maybe forcing internally to be the CTRL key always pressed up only for
this Widget. Is there a way to do it?

Here is a bit of black magic for you, shown in a modification of the

sample in the demo. It works because wx.VListBox is a generic control
so modifying the mouse event has an effect when it gets to the default
event handler.

class MyVListBox(wx.VListBox):
def init(self, *args, **kw):

     wx.VListBox.__init__(self, *args, **kw)
     self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown)

 def OnLeftDown(self, evt):
     evt.Skip()
     if 'wxMac' in wx.PlatformInfo

:
evt.m_metaDown = True
else:
evt.m_controlDown = True

 # This method must be overridden.  When called it should draw the
 # n'th item on the dc within the rect.  How it is drawn, and what

 # is drawn is entirely up to you.
 def OnDrawItem(self, dc, rect, n):
     if self.IsSelected(n):
         c = wx.SystemSettings.GetColour(wx.SYS_COLOUR_HIGHLIGHTTEXT)
     else:
         c = self.GetForegroundColour()
     dc.SetFont(self.GetFont())
     dc.SetTextForeground(c)
     dc.DrawLabel(self._getItemText(n), rect,
                  wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL)


 # This method must be overridden.  It should return the height
 # required to draw the n'th item.
 def OnMeasureItem(self, n):
     height = 0
     for line in self._getItemText(n).split('\n'):

         w, h = self.GetTextExtent(line)
         height += h
     return height + 5

 def _getItemText(self, item):
     if item % 2 == 0:
         return "This is item# %d" % item

     else:
         return "This is item# %d\n with an extra line" % item

–
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!


To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org

For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org