Quantcast

in demo ComboCtrl.py how to Bind in MakeLCCombo(style=wx.CB_READONLY)

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

in demo ComboCtrl.py how to Bind in MakeLCCombo(style=wx.CB_READONLY)

yam850
Hi,

I use the ComboCtrl.py from the demo to make a List Control Combo
using cc=MakeLCCombo(style=wx.CB_READONLY).
I cannot Bind successfully an event to this control to get the
selected item.
I tried a lot cc.Bind(<event>, <method>)
cc.GetTextCtrl() returns None. (which I do not understand)

It works without style=wx.CB_READONLY using the focus event (which for
me is strange).
cc.Bind(wx.EVT_KILL_FOCUS, <method>)
cc.GetTextCtrl() returns a wxTextCtrl.

Thanks for any help or hint.


Here is the modified ComboCtrl.py
#!/usr/bin/env python
# vim: set fileencoding=utf-8 :

import wx
import wx.combo
import os

#----------------------------------------------------------------------

class NullLog:
    def write(*args):
        pass

# This class is used to provide an interface between a ComboCtrl and a
# ListCtrl that is used as the popoup for the combo widget.  In this
# case we use multiple inheritance to derive from both wx.ListCtrl and
# wx.ComboPopup, but it also works well when deriving from just
# ComboPopup and using a has-a relationship with the popup control,
# you just need to be sure to return the control itself from the
# GetControl method.

class ListCtrlComboPopup(wx.ListCtrl, wx.combo.ComboPopup):

    def __init__(self, log=None):
        if log:
            self.log = log
        else:
            self.log = NullLog()


        # Since we are using multiple inheritance, and don't know yet
        # which window is to be the parent, we'll do 2-phase create of
        # the ListCtrl instead, and call its Create method later in
        # our Create method.  (See Create below.)
        self.PostCreate(wx.PreListCtrl())

        # Also init the ComboPopup base class.
        wx.combo.ComboPopup.__init__(self)


    def AddItem(self, txt):
        self.InsertStringItem(self.GetItemCount(), txt)

    def OnMotion(self, evt):
        item, flags = self.HitTest(evt.GetPosition())
        if item >= 0:
            self.Select(item)
            self.curitem = item

    def OnLeftDown(self, evt):
        self.value = self.curitem
        self.Dismiss()

    # The following methods are those that are overridable from the
    # ComboPopup base class.  Most of them are not required, but all
    # are shown here for demonstration purposes.

    # This is called immediately after construction finishes.  You can
    # use self.GetCombo if needed to get to the ComboCtrl instance.
    def Init(self):
        self.log.write("ListCtrlComboPopup.Init")
        self.value = -1
        self.curitem = -1

    # Create the popup child control.  Return true for success.
    def Create(self, parent):
        self.log.write("ListCtrlComboPopup.Create")
        wx.ListCtrl.Create(self, parent,
                           style=wx.LC_LIST|wx.LC_SINGLE_SEL|
wx.SIMPLE_BORDER)
        self.Bind(wx.EVT_MOTION, self.OnMotion)
        self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown)
        return True

    # Return the widget that is to be used for the popup
    def GetControl(self):
        #self.log.write("ListCtrlComboPopup.GetControl")
        return self

    # Called just prior to displaying the popup, you can use it to
    # 'select' the current item.
    def SetStringValue(self, val):
        self.log.write("ListCtrlComboPopup.SetStringValue")
        idx = self.FindItem(-1, val)
        if idx != wx.NOT_FOUND:
            self.Select(idx)

    # Return a string representation of the current item.
    def GetStringValue(self):
        self.log.write("ListCtrlComboPopup.GetStringValue")
        if self.value >= 0:
            return self.GetItemText(self.value)
        return ""

    # Called immediately after the popup is shown
    def OnPopup(self):
        self.log.write("ListCtrlComboPopup.OnPopup")
        wx.combo.ComboPopup.OnPopup(self)

    # Called when popup is dismissed
    def OnDismiss(self):
        self.log.write("ListCtrlComboPopup.OnDismiss")
        wx.combo.ComboPopup.OnDismiss(self)

    # This is called to custom paint in the combo control itself
    # (ie. not the popup).  Default implementation draws value as
    # string.
    def PaintComboControl(self, dc, rect):
        self.log.write("ListCtrlComboPopup.PaintComboControl")
        wx.combo.ComboPopup.PaintComboControl(self, dc, rect)

    # Receives key events from the parent ComboCtrl.  Events not
    # handled should be skipped, as usual.
    def OnComboKeyEvent(self, event):
        self.log.write("ListCtrlComboPopup.OnComboKeyEvent")
        wx.combo.ComboPopup.OnComboKeyEvent(self, event)

    # Implement if you need to support special action when user
    # double-clicks on the parent wxComboCtrl.
    def OnComboDoubleClick(self):
        self.log.write("ListCtrlComboPopup.OnComboDoubleClick")
        wx.combo.ComboPopup.OnComboDoubleClick(self)

    # Return final size of popup. Called on every popup, just prior to
OnPopup.
    # minWidth = preferred minimum width for window
    # prefHeight = preferred height. Only applies if > 0,
    # maxHeight = max height for window, as limited by screen size
    #   and should only be rounded down, if necessary.
    def GetAdjustedSize(self, minWidth, prefHeight, maxHeight):
        self.log.write("ListCtrlComboPopup.GetAdjustedSize: %d, %d,
%d" % (minWidth, prefHeight, maxHeight))
        return wx.combo.ComboPopup.GetAdjustedSize(self, minWidth,
prefHeight, maxHeight)

    # Return true if you want delay the call to Create until the popup
    # is shown for the first time. It is more efficient, but note that
    # it is often more convenient to have the control created
    # immediately.
    # Default returns false.
    def LazyCreate(self):
        self.log.write("ListCtrlComboPopup.LazyCreate")
        return wx.combo.ComboPopup.LazyCreate(self)


#----------------------------------------------------------------------
# This class is a popup containing a TreeCtrl.  This time we'll use a
# has-a style (instead of is-a like above.)

class TreeCtrlComboPopup(wx.combo.ComboPopup):

    # overridden ComboPopup methods

    def Init(self):
        self.value = None
        self.curitem = None


    def Create(self, parent):
        self.tree = wx.TreeCtrl(parent, style=wx.TR_HIDE_ROOT
                                |wx.TR_HAS_BUTTONS
                                |wx.TR_SINGLE
                                |wx.TR_LINES_AT_ROOT
                                |wx.SIMPLE_BORDER)
        self.tree.Bind(wx.EVT_MOTION, self.OnMotion)
        self.tree.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown)


    def GetControl(self):
        return self.tree

    def GetStringValue(self):
        if self.value:
            return self.tree.GetItemText(self.value)
        return ""

    def OnPopup(self):
        if self.value:
            self.tree.EnsureVisible(self.value)
            self.tree.SelectItem(self.value)

    def SetStringValue(self, value):
        # this assumes that item strings are unique...
        root = self.tree.GetRootItem()
        if not root:
            return
        found = self.FindItem(root, value)
        if found:
            self.value = found
            self.tree.SelectItem(found)

    def GetAdjustedSize(self, minWidth, prefHeight, maxHeight):
        return wx.Size(minWidth, min(200, maxHeight))


    # helpers

    def FindItem(self, parentItem, text):
        item, cookie = self.tree.GetFirstChild(parentItem)
        while item:
            if self.tree.GetItemText(item) == text:
                return item
            if self.tree.ItemHasChildren(item):
                item = self.FindItem(item, text)
            item, cookie = self.tree.GetNextChild(parentItem, cookie)
        return wx.TreeItemId();

    def AddItem(self, value, parent=None):
        if not parent:
            root = self.tree.GetRootItem()
            if not root:
                root = self.tree.AddRoot("<hidden root>")
            parent = root

        item = self.tree.AppendItem(parent, value)
        return item


    def OnMotion(self, evt):
        # have the selection follow the mouse, like in a real combobox
        item, flags = self.tree.HitTest(evt.GetPosition())
        if item and flags & wx.TREE_HITTEST_ONITEMLABEL:
            self.tree.SelectItem(item)
            self.curitem = item
        evt.Skip()

    def OnLeftDown(self, evt):
        # do the combobox selection
        item, flags = self.tree.HitTest(evt.GetPosition())
        if item and flags & wx.TREE_HITTEST_ONITEMLABEL:
            self.curitem = item
            self.value = item
            self.Dismiss()
        evt.Skip()


#----------------------------------------------------------------------
# Here we subclass wx.combo.ComboCtrl to do some custom popup
animation

CUSTOM_COMBOBOX_ANIMATION_DURATION = 200

class ComboCtrlWithCustomPopupAnim(wx.combo.ComboCtrl):
    def __init__(self, *args, **kw):
        wx.combo.ComboCtrl.__init__(self, *args, **kw)
        self.Bind(wx.EVT_TIMER, self.OnTimer)
        self.aniTimer = wx.Timer(self)

    def AnimateShow(self, rect, flags):
        self.aniStart = wx.GetLocalTimeMillis()
        self.aniRect = wx.Rect(*rect)
        self.aniFlags = flags

        dc = wx.ScreenDC()
        bmp = wx.EmptyBitmap(rect.width, rect.height)
        mdc = wx.MemoryDC(bmp)
        if "wxMac" in wx.PlatformInfo:
            pass
        else:
            mdc.Blit(0, 0, rect.width, rect.height, dc, rect.x,
rect.y)
        del mdc
        self.aniBackBitmap = bmp

        self.aniTimer.Start(10, wx.TIMER_CONTINUOUS)
        self.OnTimer(None)
        return False


    def OnTimer(self, evt):
        stopTimer = False
        popup = self.GetPopupControl().GetControl()
        rect = self.aniRect
        dc = wx.ScreenDC()

        if self.IsPopupWindowState(self.Hidden):
            stopTimer = True
        else:
            pos = wx.GetLocalTimeMillis() - self.aniStart
            if pos < CUSTOM_COMBOBOX_ANIMATION_DURATION:
                # Actual animation happens here
                width = rect.width
                height = rect.height

                center_x = rect.x + (width/2)
                center_y = rect.y + (height/2)

                dc.SetPen( wx.BLACK_PEN )
                dc.SetBrush( wx.TRANSPARENT_BRUSH )

                w = (((pos*256)/
CUSTOM_COMBOBOX_ANIMATION_DURATION)*width)/256
                ratio = float(w) / float(width)
                h = int(height * ratio)

                dc.DrawBitmap( self.aniBackBitmap, rect.x, rect.y )
                dc.DrawRectangle( center_x - w/2, center_y - h/2, w,
h )
            else:
                stopTimer = True

        if stopTimer:
            dc.DrawBitmap( self.aniBackBitmap, rect.x, rect.y )
            popup.Move( (0, 0) )
            self.aniTimer.Stop()
            self.DoShowPopup( rect, self.aniFlags )


#----------------------------------------------------------------------
# FileSelectorCombo displays a dialog instead of a popup control, it
# also uses a custom bitmap on the combo button.

class FileSelectorCombo(wx.combo.ComboCtrl):
    def __init__(self, *args, **kw):
        wx.combo.ComboCtrl.__init__(self, *args, **kw)

        # make a custom bitmap showing "..."
        bw, bh = 14, 16
        bmp = wx.EmptyBitmap(bw,bh)
        dc = wx.MemoryDC(bmp)

        # clear to a specific background colour
        bgcolor = wx.Colour(255,254,255)
        dc.SetBackground(wx.Brush(bgcolor))
        dc.Clear()

        # draw the label onto the bitmap
        label = ".X."
        font = wx.SystemSettings.GetFont(wx.SYS_DEFAULT_GUI_FONT)
        font.SetWeight(wx.FONTWEIGHT_BOLD)
        dc.SetFont(font)
        tw,th = dc.GetTextExtent(label)
        dc.DrawText(label, (bw-tw)/2, (bw-tw)/2)
        del dc

        # now apply a mask using the bgcolor
        bmp.SetMaskColour(bgcolor)

        # and tell the ComboCtrl to use it
        self.SetButtonBitmaps(bmp, True)


    # Overridden from ComboCtrl, called when the combo button is
clicked
    def OnButtonClick(self):
        path = ""
        name = ""
        if self.GetValue():
            path, name = os.path.split(self.GetValue())

        dlg = wx.FileDialog(self, "Choose File", path, name,
                            "All files (*.*)|*.*", wx.FD_OPEN)
        if dlg.ShowModal() == wx.ID_OK:
            self.SetValue(dlg.GetPath())
        dlg.Destroy()
        self.SetFocus()

    # Overridden from ComboCtrl to avoid assert since there is no
ComboPopup
    def DoSetPopupControl(self, popup):
        pass


#----------------------------------------------------------------------

class TestPanel(wx.Panel):
    def __init__(self, parent, log):
        self.log = log
        wx.Panel.__init__(self, parent, -1)

        fgs = wx.FlexGridSizer(cols=3, hgap=10, vgap=10)

        ### modified
        # self.cc = self.MakeLCCombo(log=self.log,
style=wx.CB_READONLY)
        self.cc = self.MakeLCCombo(log=self.log)
        fgs.Add(self.cc)
        fgs.Add((10,10))
        fgs.Add(wx.StaticText(self, -1, "wx.ComboCtrl with a ListCtrl
popup"))
        self.cc.Bind(wx.EVT_KILL_FOCUS, self.on_event)

        cc = self.MakeLCCombo(style=wx.CB_READONLY)
        fgs.Add(cc)
        fgs.Add((10,10))
        fgs.Add(wx.StaticText(self, -1, "        Read-only"))

        cc = self.MakeLCCombo()
        cc.SetButtonPosition(side=wx.LEFT)
        fgs.Add(cc)
        fgs.Add((10,10))
        fgs.Add(wx.StaticText(self, -1, "        Button on the left"))

        cc = self.MakeLCCombo()
        cc.SetPopupMaxHeight(250)
        fgs.Add(cc)
        fgs.Add((10,10))
        fgs.Add(wx.StaticText(self, -1, "        Max height of popup
set"))

        cc = wx.combo.ComboCtrl(self, size=(250,-1))
        tcp = TreeCtrlComboPopup()
        cc.SetPopupControl(tcp)
        fgs.Add(cc)
        fgs.Add((10,10))
        fgs.Add(wx.StaticText(self, -1, "TreeCtrl popup"))
        # add some items to the tree
        for i in range(5):
            item = tcp.AddItem('Item %d' % (i+1))
            for j in range(15):
                tcp.AddItem('Subitem %d-%d' % (i+1, j+1), parent=item)

        cc = ComboCtrlWithCustomPopupAnim(self, size=(250, -1))
        popup = ListCtrlComboPopup()
        cc.SetPopupMaxHeight(150)
        cc.SetPopupControl(popup)
        fgs.Add(cc)
        fgs.Add((10,10))
        fgs.Add(wx.StaticText(self, -1, "Custom popup animation"))
        for word in "How cool was that!?  Way COOL!".split():
            popup.AddItem(word)
        if "wxMac" in wx.PlatformInfo:
            cc.SetValue("Sorry, animation not working yet on Mac")

        cc = FileSelectorCombo(self, size=(250, -1))
        fgs.Add(cc)
        fgs.Add((10,10))
        fgs.Add(wx.StaticText(self, -1, "Custom popup action, and
custom button bitmap"))

        box = wx.BoxSizer()
        box.Add(fgs, 1, wx.EXPAND|wx.ALL, 20)
        self.SetSizer(box)

    def on_event(self, event):  #### added
        self.log.write("on_event: GetValue=%s" %
(repr(self.cc.GetValue())))

    def MakeLCCombo(self, log=None, style=0):
        # Create a ComboCtrl
        cc = wx.combo.ComboCtrl(self, style=style, size=(250,-1))

        # Create a Popup
        popup = ListCtrlComboPopup(log)

        # Associate them with each other.  This also triggers the
        # creation of the ListCtrl.
        cc.SetPopupControl(popup)

        # Add some items to the listctrl.
        for x in range(75):
            popup.AddItem("Item-%02d" % x)

        return cc


#----------------------------------------------------------------------

def runTest(frame, nb, log):
    win = TestPanel(nb, log)
    return win

#----------------------------------------------------------------------

overview = """<html><body>
<h2><center>wx.combo.ComboCtrl</center></h2>

A combo control is a generic combobox that allows a totally custom
popup. In addition it has other customization features. For instance,
position and size of the dropdown button can be changed.

</body></html>
"""

if __name__ == '__main__':
    import sys,os
    import run
    run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])

--
To unsubscribe, send email to [hidden email]
or visit http://groups.google.com/group/wxPython-users?hl=en
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: in demo ComboCtrl.py how to Bind in MakeLCCombo(style=wx.CB_READONLY)

Tim Roberts
yam850 wrote:

> I use the ComboCtrl.py from the demo to make a List Control Combo
> using cc=MakeLCCombo(style=wx.CB_READONLY).
> I cannot Bind successfully an event to this control to get the
> selected item.
> I tried a lot cc.Bind(<event>, <method>)
> cc.GetTextCtrl() returns None. (which I do not understand)
>
> It works without style=wx.CB_READONLY using the focus event (which for
> me is strange).
> cc.Bind(wx.EVT_KILL_FOCUS, <method>)
> cc.GetTextCtrl() returns a wxTextCtrl.
>
> Thanks for any help or hint.

It's nearly impossible for us to help you, because you haven't told us
which events you tried to bind, or exactly where you tried to bind
them.  your code, as written, works OK both with and without "read
only".  At least, the GetValue() call is printing out the right value.

A read-only combo box doesn't need a text control.

Note that you are only binding to the first ComboCtrl.  If you expect to
handle the others, you need to use event.EventObject inside your event
handler, instead of hard coding to self.cc.  Example:
    self.log.write("on_event: GetValue %s" % event.EventObject.GetValue() )

--
Tim Roberts, [hidden email]
Providenza & Boekelheide, Inc.

--
To unsubscribe, send email to [hidden email]
or visit http://groups.google.com/group/wxPython-users?hl=en
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: in demo ComboCtrl.py how to Bind in MakeLCCombo(style=wx.CB_READONLY)

yam850
On 29 Mrz., 21:41, Tim Roberts <[hidden email]> wrote:
> It's nearly impossible for us to help you, because you haven't told us
> which events you tried to bind, or exactly where you tried to bind
> them.

A method (event handler) should be called, when the user selects an
item in this specific list.
In a TextCtrl this is EVT_TEXT_ENTER.
But this event does not work for the MakeLCCombo in the demo.
I tried almost every EVT_*.


>  your code, as written, works OK both with and without "read
> only".  At least, the GetValue() call is printing out the right value.

Not for me in the readonly version.
Linux mcp20 2.6.34.7-0.5-default #1 SMP 2010-10-25 08:40:12 +0200 i686
i686 i386 GNU/Linux
Python 2.6.5
wx-2.8-gtk2-unicode, 2.8.10.1
Do you test the upper most control?

> A read-only combo box doesn't need a text control.

Yes.

> Note that you are only binding to the first ComboCtrl.  If you expect to
> handle the others, you need to use event.EventObject inside your event
> handler, instead of hard coding to self.cc.  Example:
>     self.log.write("on_event: GetValue %s" % event.EventObject.GetValue() )

Yes.

How should I Bind to get a method called (event handler),
when the user selects an item in a specific
cc=MakeLCCombo(style=wx.CB_READONLY)?


Thanks for any help or hint

--
To unsubscribe, send email to [hidden email]
or visit http://groups.google.com/group/wxPython-users?hl=en
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: in demo ComboCtrl.py how to Bind in MakeLCCombo(style=wx.CB_READONLY)

Tim Roberts
yam850 wrote:
> On 29 Mrz., 21:41, Tim Roberts <[hidden email]> wrote:
>> It's nearly impossible for us to help you, because you haven't told us
>> which events you tried to bind, or exactly where you tried to bind
>> them.
> A method (event handler) should be called, when the user selects an
> item in this specific list.
> In a TextCtrl this is EVT_TEXT_ENTER.
> But this event does not work for the MakeLCCombo in the demo.
> I tried almost every EVT_*.

You have complete control here.  Your code contains the complete source
for the list control that gets displayed when you click the down arrow.
If you want an event returned when the list is dismissed, just fire the
event yourself:


class ListCtrlComboPopup(wx.ListCtrl, wx.combo.ComboPopup):
    ...
    # Called when popup is dismissed
    def OnDismiss(self):
        self.log.write("ListCtrlComboPopup.OnDismiss")
        evt = wx.PyCommandEvent(wx.EVT_TEXT.typeId, self.GetId())
        evt.SetEventObject(self.GetParent())
        wx.PostEvent(self,evt)
        wx.combo.ComboPopup.OnDismiss(self)



class TestPanel(wx.Panel):
    def __init__(self, parent, log):
        ...
        self.cc.Bind(wx.EVT_TEXT, self.on_text)

    def on_text(self,evt):
        self.log.write( "on_text: %s" % evt.EventObject.GetStringValue() )

--
Tim Roberts, [hidden email]
Providenza & Boekelheide, Inc.

--
To unsubscribe, send email to [hidden email]
or visit http://groups.google.com/group/wxPython-users?hl=en
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: in demo ComboCtrl.py how to Bind in MakeLCCombo(style=wx.CB_READONLY)

yam850
Am 30.03.2011 19:02, schrieb Tim Roberts:
You have complete control here. Your code contains the complete source
for the list control that gets displayed when you click the down arrow.
If you want an event returned when the list is dismissed, just fire the
event yourself:


class ListCtrlComboPopup(wx.ListCtrl, wx.combo.ComboPopup):
...
# Called when popup is dismissed
def OnDismiss(self):
self.log.write("ListCtrlComboPopup.OnDismiss")
evt = wx.PyCommandEvent(wx.EVT_TEXT.typeId, self.GetId())
evt.SetEventObject(self.GetParent())
wx.PostEvent(self,evt)
wx.combo.ComboPopup.OnDismiss(self)

class TestPanel(wx.Panel):
def __init__(self, parent, log):
...
self.cc.Bind(wx.EVT_TEXT, self.on_text)

def on_text(self,evt):
self.log.write( "on_text: %s" % evt.EventObject.GetStringValue() )

Sorry, it does not work now on both READONLY or not.
I have:
class ListCtrlComboPopup(wx.ListCtrl, wx.combo.ComboPopup):
...
   # Called when popup is dismissed
    def OnDismiss(self): # from Tim Roberts, wxPython-users
        self.log.write("ListCtrlComboPopup.OnDismiss  in")
        evt = wx.PyCommandEvent(wx.EVT_TEXT.typeId, self.GetId())
        evt.SetEventObject(self.GetParent())
        wx.PostEvent(self,evt)
        wx.combo.ComboPopup.OnDismiss(self)
        self.log.write("ListCtrlComboPopup.OnDismiss out")

class TestPanel(wx.Panel):
...
        cc = self.MakeLCCombo(log=self.log)
        # cc = self.MakeLCCombo(log=self.log, style=wx.CB_READONLY)
        cc.Bind(wx.EVT_TEXT, self.on_text)
...
   def on_text(self, evt):
        self.log.write( "on_text: %s" % evt.EventObject.GetStringValue() )

on stdout:
muk@mcp20:~/Test/python/wxPython/demo> python ./MyComboCtrl.py
wx.version: 2.8.10.1 (gtk2-unicode)
pid: 4056
20:23:33: ListCtrlComboPopup.Init
20:23:33: ListCtrlComboPopup.LazyCreate
20:23:33: ListCtrlComboPopup.Create
20:23:34: ListCtrlComboPopup.PaintComboControl
20:23:35: ListCtrlComboPopup.PaintComboControl
20:23:35: ListCtrlComboPopup.GetAdjustedSize: 250, 400, 883
20:23:35: ListCtrlComboPopup.OnPopup
20:23:35: ListCtrlComboPopup.PaintComboControl
20:23:36: ListCtrlComboPopup.GetStringValue
20:23:36: ListCtrlComboPopup.SetStringValue
20:23:36: ListCtrlComboPopup.OnDismiss  in
20:23:36: ListCtrlComboPopup.OnDismiss out
20:23:36: ListCtrlComboPopup.PaintComboControl

So it goes through the
ListCtrlComboPopup.OnDismiss but
it does not fire an event.



Thanks for helping me!
--
Kurt Mueller

--
To unsubscribe, send email to [hidden email]
or visit http://groups.google.com/group/wxPython-users?hl=en
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: in demo ComboCtrl.py how to Bind in MakeLCCombo(style=wx.CB_READONLY)

yam850
In reply to this post by Tim Roberts
 Am 30.03.2011 19:02, schrieb Tim Roberts:

> You have complete control here. Your code contains the complete source
> for the list control that gets displayed when you click the down arrow.
> If you want an event returned when the list is dismissed, just fire the
> event yourself:
>
>
> class ListCtrlComboPopup(wx.ListCtrl, wx.combo.ComboPopup):
> ...
> # Called when popup is dismissed
> def OnDismiss(self):
> self.log.write("ListCtrlComboPopup.OnDismiss")
> evt = wx.PyCommandEvent(wx.EVT_TEXT.typeId, self.GetId())
> evt.SetEventObject(self.GetParent())
> wx.PostEvent(self,evt)
> wx.combo.ComboPopup.OnDismiss(self)
>
> class TestPanel(wx.Panel):
> def __init__(self, parent, log):
> ...
> self.cc.Bind(wx.EVT_TEXT, self.on_text)
>
> def on_text(self,evt):
> self.log.write( "on_text: %s" % evt.EventObject.GetStringValue() )

Sorry, it does not work now on both READONLY or not.
I have:
class ListCtrlComboPopup(wx.ListCtrl, wx.combo.ComboPopup):
...
   # Called when popup is dismissed
    def OnDismiss(self): # from Tim Roberts, wxPython-users
        self.log.write("ListCtrlComboPopup.OnDismiss  in")
        evt = wx.PyCommandEvent(wx.EVT_TEXT.typeId, self.GetId())
        evt.SetEventObject(self.GetParent())
        wx.PostEvent(self,evt)
        wx.combo.ComboPopup.OnDismiss(self)
        self.log.write("ListCtrlComboPopup.OnDismiss out")

class TestPanel(wx.Panel):
...
        cc = self.MakeLCCombo(log=self.log)
        # cc = self.MakeLCCombo(log=self.log, style=wx.CB_READONLY)
        cc.Bind(wx.EVT_TEXT, self.on_text)
...
   def on_text(self, evt):
        self.log.write( "on_text: %s" %
evt.EventObject.GetStringValue() )

on stdout:
muk@mcp20:~/Test/python/wxPython/demo> python ./MyComboCtrl.py
wx.version: 2.8.10.1 (gtk2-unicode)
pid: 4056
20:23:33: ListCtrlComboPopup.Init
20:23:33: ListCtrlComboPopup.LazyCreate
20:23:33: ListCtrlComboPopup.Create
20:23:34: ListCtrlComboPopup.PaintComboControl
20:23:35: ListCtrlComboPopup.PaintComboControl
20:23:35: ListCtrlComboPopup.GetAdjustedSize: 250, 400, 883
20:23:35: ListCtrlComboPopup.OnPopup
20:23:35: ListCtrlComboPopup.PaintComboControl
20:23:36: ListCtrlComboPopup.GetStringValue
20:23:36: ListCtrlComboPopup.SetStringValue
20:23:36: ListCtrlComboPopup.OnDismiss  in
20:23:36: ListCtrlComboPopup.OnDismiss out
20:23:36: ListCtrlComboPopup.PaintComboControl

So it goes through the ListCtrlComboPopup.OnDismiss but
it does not fire an event.



Thanks for helping me!
--
Kurt Mueller

--
To unsubscribe, send email to [hidden email]
or visit http://groups.google.com/group/wxPython-users?hl=en
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: in demo ComboCtrl.py how to Bind in MakeLCCombo(style=wx.CB_READONLY)

Tim Roberts
yam850 wrote:
>  
> Sorry, it does not work now on both READONLY or not.

Are you running this from a command line, so that you can see Python
errors as they occur?  Or are you running this in some way that all of
the errors are hidden?

> class ListCtrlComboPopup(wx.ListCtrl, wx.combo.ComboPopup):
> ...
>    # Called when popup is dismissed
>     def OnDismiss(self): # from Tim Roberts, wxPython-users
>         self.log.write("ListCtrlComboPopup.OnDismiss  in")
>         evt = wx.PyCommandEvent(wx.EVT_TEXT.typeId, self.GetId())
>         evt.SetEventObject(self.GetParent())

Take out the "GetParent" call here.  Just evt.SetEventObject(self).

--
Tim Roberts, [hidden email]
Providenza & Boekelheide, Inc.

--
To unsubscribe, send email to [hidden email]
or visit http://groups.google.com/group/wxPython-users?hl=en
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: in demo ComboCtrl.py how to Bind in MakeLCCombo(style=wx.CB_READONLY)

yam850
On 30 Mrz., 21:59, Tim Roberts <[hidden email]> wrote:
> yam850 wrote:
> > Sorry, it does not work now on both READONLY or not.
> Are you running this from a command line, so that you can see Python
> errors as they occur?  Or are you running this in some way that all of
> the errors are hidden?

I run it from the commandline.
There is no Traceback if I use
evt.SetEventObject(self.GetParent())

There is a strange effect:
If I enter this line:
class TestPanel(wx.Panel):
...
        print >>sys.stderr, "print to stderr from TestPanel"
the output is on the stderr, but no events occur.


> > class ListCtrlComboPopup(wx.ListCtrl, wx.combo.ComboPopup):
> > ...
> >    # Called when popup is dismissed
> >     def OnDismiss(self): # from Tim Roberts, wxPython-users
> >         self.log.write("ListCtrlComboPopup.OnDismiss  in")
> >         evt = wx.PyCommandEvent(wx.EVT_TEXT.typeId, self.GetId())
> >         evt.SetEventObject(self.GetParent())
>
> Take out the "GetParent" call here.  Just evt.SetEventObject(self).

I did that. This way it works.


I misunderstood the meaning of this demo.
I thought it would be kind of a direct replacement for the
wx.ComboBox.
So to be such a replacement, there will be still some work to be done,
isn't it?


Thanks for your help!

--
Kurt Alfred Müller

--
To unsubscribe, send email to [hidden email]
or visit http://groups.google.com/group/wxPython-users?hl=en
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: in demo ComboCtrl.py how to Bind in MakeLCCombo(style=wx.CB_READONLY)

yam850
On 31 Mrz., 14:34, yam850 <[hidden email]> wrote:
> On 30 Mrz., 21:59, Tim Roberts <[hidden email]> wrote:
> > yam850 wrote:
> There is a strange effect:
> If I enter this line:
> class TestPanel(wx.Panel):
> ...
>         print >>sys.stderr, "print to stderr from TestPanel"
> the output is on the stderr, but no events occur.

This effect comes from the 'log' which comes from the run.py in the
demo.
I made my own log.

This problem solved.


The last lines of the program are as follows:
#----------------------------------------------------------------------

class NullLog:
    def write(*args):
        pass

class MyLog:
    def write(self, strg):
        sys.stderr.write("%s\n" % strg)

def main():
    app   = wx.App()
    frame = wx.Frame(None, title='ComboCtrl', size=(600,300))
    panl = TestPanel(frame, log=MyLog())
    frame.Show()
    app.MainLoop()

if __name__ == '__main__' :
    main()


--
Kurt Alfred Müller

--
To unsubscribe, send email to [hidden email]
or visit http://groups.google.com/group/wxPython-users?hl=en
Loading...