[wxPython-users] LB_MULTIPLE on wxVListBox

Diego Jacobi jacobidiego at gmail.com
Sat Sep 1 09:56:23 PDT 2007


Cool!
Thanks Robin. :-D

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 =3D wx.SystemSettings.GetColour(wx.SYS_COLOUR_HIGHLIGHT)
        else:
            if n % 2:
                bg =3D wx.SystemSettings.GetColour(wx.SYS_COLOUR_SCROLLBAR)
            else:
                bg =3D 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 at 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 =3D True
>          else:
>              evt.m_controlDown =3D 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 =3D wx.SystemSettings.GetColour(wx.SYS_COLOUR_HIGHLIGHTTEX=
T)
>          else:
>              c =3D 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 =3D 0
>          for line in self._getItemText(n).split('\n'):
>              w, h =3D self.GetTextExtent(line)
>              height +=3D h
>          return height + 5
>
>      def _getItemText(self, item):
>          if item % 2 =3D=3D 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 at lists.wxwidgets.org
> For additional commands, e-mail: wxPython-users-help at lists.wxwidgets.org
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.wxwidgets.org/pipermail/wxpython-users/attachments/200709=
01/17747ea9/attachment.htm


More information about the wxpython-users mailing list