[Urwid] EPICS in urwid

Ian Ward ian at excess.org
Mon Jul 26 09:38:17 EDT 2010


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. 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)

Ian

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



More information about the Urwid mailing list