[Urwid] EPICS in urwid

Krempasky Juraj juraj.krempasky at psi.ch
Wed Jul 28 11:12:38 EDT 2010

Hello Ian,

This is my widgetwrap supposed to just display an EPICS channel called
pvName. The EPICS part (pv_value) is working properly, the urwid part in
the valueCB callback does not work. The class is tested in Ipython only.
Any idea why the callback does not update the text?

Kindest personal regards.

Juraj Krempasky


class epicsUw(CaChannel.CaChannel, urwid.WidgetWrap):
    def __init__(self, pvName=None):
        self.inited = False
        if pvName!=None:
            self.search_and_connect(pvName, self.connectCB, pvName)
        self.display_w = urwid.Text(('', " Hello Epics "),
        urwid.WidgetWrap.__init__(self, self.display_w)

    # Callback functions

    def controlCB(self,epicsArgs,userArgs):
        for key in epicsArgs.keys():
            setattr(self, key, epicsArgs[key])
        self.inited = True

    def valueCB(self, epicsArgs, userArgs):
        for key in epicsArgs.keys():
            setattr(self, key, epicsArgs[key])
        #self.display_w.set_text(self.pv_value+' '+self.pv_units)
        self.AttrMap(self.pv_value+' '+self.pv_units)

    def connectCB(self, epicsArgs, userArgs):
        # setup valueCB only in the first time
        if state==2 and self.never_conn:
type()), None,
                CaChannel.ca.DBE_VALUE | CaChannel.ca.DBE_ALARM,
                None, self.controlCB)

-----Original Message-----
From: urwid-bounces at lists.excess.org
[mailto:urwid-bounces at lists.excess.org] On Behalf Of Ian Ward
Sent: Montag, 26. Juli 2010 15:38
To: urwid at lists.excess.org
Subject: Re: [Urwid] EPICS in urwid

Hello, sorry for the slow reply

Krempasky Juraj wrote on 2010-07-14 10:08:
> Hello,
> I am newbie to urwid and I am looking for a solution to integrate 
> urwid ui into EPICS large scale instrumentation control.
> In the simplest case the point is to make
> urwid.AttrMap(urwid.Text(value)) update from EPICS callback mechanisms

> that understand the alarm state and value to be changed in ui. First 
> question I have is that one could access the text and its color 
> attributes via AttrMap base_widget. Is there some other solution?

If you are creating many of these you might want to create a custom
widget.  Subclass from WidgetWrap and use the AttrMap(Text) as the
display widget.  This lets you hide the implementation, and lets you
define your own interface without potential conflicts with AttrMap.

> Second question: building up the ui as
> Frame->ListBox->(Columns,Pile,Text) is pretty straightforward. 
> Frame->ListBox->However,
> is there some way to insert into the
> Frame->ListBox->(Columns,Pile,Text) ui configuration also the EPICS
> callback mechanism such that the urwid.MainLoop will not complain?
> In principle I need to create an object like
> class epicsText(epics, urwid.Text):
>     def __init__(self, epicsChannel):
>            epics.__init__(self)
>            self.search_and_connect(epicsChannel, self.connectCB)
>            urwid.AttrMap(urwid.Text(epicsChannel))
>            ...
>     def connectCB(self,...)
>            .....
>     def valueCB(self,...):
>            ...set text attributes
> directly in Frame->ListBox->(Columns,Pile,EpicsText) such that the 
> listbox would initialize the EPICS part correctly and urwid.MainLoop 
> will stay happy.

MainLoop staying happy is the tricky part at the moment.  You need to
call loop.draw_screen() when the screen needs to be updated.  Either
call it as part of the callback (not appropriate for a widget method) or
have set up a timer to update the screen (if redrawing on every callback
would be too costly)


> Looking forward for suggestions, best regards.
> Juraj Krempasky

Urwid mailing list
Urwid at lists.excess.org

More information about the Urwid mailing list