Python

NAVIGATION
CATEGORIES
REFERRENCE
LINKS
  • wxPython + signals

    2 answers - 1484 bytes - related search similar search Add To My Delicious Add To My Stumble Upon Add To My Google Mark Add To My Facebook Add To My Digg Add To My Reddit

    Hi all,
    I am searching for something like SigSlot (the C++'s counterpart). The
    main idea is that I want to make a data model that pushes messages /
    signals to my wxPython application. This way the GUI will be a 'dumb'
    listener, and when e.g. a signal arrives that e.g. a project item is
    added to the DB, I can act upon it to list it in my combobox for
    example (don't mind the syntax I am real new to python):
    Something like;
    class MyComboBox(wx.ComboBox)
    def AddNewProjectItem(prjid, name):
    # append to combobox
    _projects.Append(name, prjid)
    Where I can subscribe my AddNewProjectItem method to a signal / slot
    library, which gets triggered once the user has added the project:
    Adding to a trigger:
    _addProjectSignal.connect(AddNewProjectItem)
    Firing it:
    def CreateNewProject:
    dlg = new MyPatientDialog()
    if dlg.ShowModal == K:
    _addProjectSignal.submit(dlg.prjname, dlg.prjid)
    The idea is that if more methods are connected to the one signal,
    various parts of the GUI are updated this way.
    Is there something like this in (wx)Python ? I saw that PyQT has it's
    signslot implementation but it should be more generic I guess
    Regards,
    - Jorgen
    To unsubscribe, e-mail: wxPython-users-unsubscribe (AT) lists (DOT) wxwidgets.org
    For additional commands, e-mail: wxPython-users-help (AT) lists (DOT) wxwidgets.org
  • No.1 | | 2136 bytes | |

    Thanks Jurgen!

    Regards
    - Jorgen ;-)

    10/25/06, J Kareta <python (AT) kareta (DOT) dewrote:
    Jorgen Bodde schrieb:

    Hi all,

    I am searching for something like SigSlot (the C++'s counterpart). The
    main idea is that I want to make a data model that pushes messages /
    signals to my wxPython application. This way the GUI will be a 'dumb'
    listener, and when e.g. a signal arrives that e.g. a project item is
    added to the DB, I can act upon it to list it in my combobox for
    example (don't mind the syntax I am real new to python):

    Something like;

    class MyComboBox(wx.ComboBox)

    def AddNewProjectItem(prjid, name):
    # append to combobox
    _projects.Append(name, prjid)

    Where I can subscribe my AddNewProjectItem method to a signal / slot
    library, which gets triggered once the user has added the project:

    Adding to a trigger:

    _addProjectSignal.connect(AddNewProjectItem)

    Firing it:

    def CreateNewProject:
    dlg = new MyPatientDialog()
    if dlg.ShowModal == K:
    _addProjectSignal.submit(dlg.prjname, dlg.prjid)

    The idea is that if more methods are connected to the one signal,
    various parts of the GUI are updated this way.

    Is there something like this in (wx)Python ? I saw that PyQT has it's
    signslot implementation but it should be more generic I guess

    Regards,
    - Jorgen

    To unsubscribe, e-mail: wxPython-users-unsubscribe (AT) lists (DOT) wxwidgets.org
    For additional commands, e-mail: wxPython-users-help (AT) lists (DOT) wxwidgets.org
    >
    >
    >

    Hi Jorgen,

    look up pydispatcher:
    *pydispatcher*.sourceforge.net

    Regards,
    J
    *
    *

    To unsubscribe, e-mail: wxPython-users-unsubscribe (AT) lists (DOT) wxwidgets.org
    For additional commands, e-mail: wxPython-users-help (AT) lists (DOT) wxwidgets.org
    --

    To unsubscribe, e-mail: wxPython-users-unsubscribe (AT) lists (DOT) wxwidgets.org
    For additional commands, e-mail: wxPython-users-help (AT) lists (DOT) wxwidgets.org
  • No.2 | | 2351 bytes | |

    Hi Jorgen,

    the main issue is that the QT's SigSlot is how Trolltech sees the event
    handling issue
    In wxPython the event handling is done by binging events tho event handlers
    as you can see in various tutorials in the wiki

    If you are keen on using something like SigSlot I guess you could
    implement it yourself, is not very hard you could either decorate or even
    ducktape the wxPython classes to provide this functionality.

    You could take a look at wax it uses something like a midway between
    wxpython and sigslot

    Here is a small example on how I see the SigSlot approach:

    import wx

    class Signal:
    _slots = []

    def connect(self, slot):
    self._slots.append(slot)

    def disconnect(self, slot):
    if slot in self._slots:
    self.slots.remove(slot)

    def submit(self, *args):
    for slot in self._slots:
    slot(*args)

    class EventSignal(Signal):
    def __init__(self, widget, event):
    widget.Bind(event, self.decode_submit)
    def decode_submit(self, evt):
    '''here, in theory, you could decode the event and call the slots
    with something more relevant
    '''
    self.submit(evt)

    class CustomFrame(wx.Frame):
    def __init__(self):
    wx.Frameinit__(self, None, title="TestFrame")
    button = wx.Button(self, label="Push Me")
    v = 1
    if v == 1:
    ''' binding 2 methods to a single event will cause only the last
    one to be called'''
    button.Bind(wx.EVT_BUTTN, Button1)
    button.Bind(wx.EVT_BUTTN, Button2)
    elif v == 2:
    ''' You can use custom Signal clasess '''
    self.pressButtonSignal = EventSignal(button, wx.EVT_BUTTN)
    self.pressButtonSignal.connect(Button1)
    self.pressButtonSignal.connect(Button2)
    elif v ==3:
    ''' or you can use Generic clasess '''
    self.pressButtonSignal = Signal()
    button.Bind(wx.EVT_BUTTN, self.pressButtonSignal.submit)
    self.pressButtonSignal.connect(Button1)
    self.pressButtonSignal.connect(Button2)

    def Button1(self, evt):
    print "Button1"

    def Button2(self, evt):
    print "Button2"

    if __name__ == "__main__":
    app = wx.App(0)
    frame = CustomFrame()
    frame.Show()
    app.MainLoop()

Re: wxPython + signals


max 4000 letters.
Your nickname that display:
In order to stop the spam: 8 + 8 =
QUESTION ON "Python"

EMSDN.COM