def __init__(self, value=None):
     super(MDSplusMethodWidget, self).__init__(rows=4,
                                               columns=2,
                                               homogeneous=False)
     self.device = Entry()
     self.method = Entry()
     self.args = list()
     self.argTable = Table(rows=8, columns=2, homogeneous=False)
     for i in range(8):
         self.args.append(Entry())
         self.argTable.attach(Label("Arg %d:       " % (i + 1, )), 0, 1, i,
                              i + 1, 0, 0)
         self.argTable.attach(self.args[i], 1, 2, i, i + 1, EXPAND | FILL,
                              0)
     self.scrolledWindow = ScrolledWindow()
     self.scrolledWindow.add_with_viewport(self.argTable)
     self.scrolledWindow.set_policy(POLICY_NEVER, POLICY_ALWAYS)
     adj = self.scrolledWindow.get_vadjustment()
     adj.connect("changed", adj_changed)
     self.timeout = Entry()
     self.attach(Label("Device:"), 0, 1, 0, 1, 0, 0)
     self.attach(self.device, 1, 2, 0, 1, EXPAND | FILL, 0)
     self.attach(Label("Method:"), 0, 1, 1, 2, 0, 0)
     self.attach(self.method, 1, 2, 1, 2, EXPAND | FILL, 0)
     self.attach(self.scrolledWindow, 0, 2, 2, 3)
     self.attach(Label("Timeout:"), 0, 1, 3, 4, 0, 0)
     self.attach(self.timeout, 1, 2, 3, 4, EXPAND | FILL, 0)
     self.set_row_spacings(5)
     self.value = value
Beispiel #2
0
	def __init__(self, editor):
		"""
		Initialize the bar object.
		@type editor: An Editor object.
		"""
		Table.__init__(self)
		self.__init_attributes(editor)
		self.__set_properties()
		self.connect("key-press-event", self.__key_press_event_cb)
Beispiel #3
0
 def __init__(self):
     ScrolledWindow.__init__(self)
     MDSplusWidget.__init__(self)
     self.numChannels = 4
     self.nodesPerChannel = 3
     self.dataNidOffset = 1
     self.startIdxNidOffset = 2
     self.endIdxNidOffset = 3
     self.incNidOffset = -1
     self.table = Table(homogeneous=False)
     self.table.set_row_spacings(0)
     self.add_with_viewport(self.table)
     self.set_policy(POLICY_NEVER, POLICY_ALWAYS)
     adj = self.get_vadjustment()
     if adj is not None:
         adj.connect("changed", self.adj_changed)
 def __init__(self,value=None):
     super(MDSplusRoutineWidget,self).__init__(rows=4,columns=2,homogeneous=False)
     self.image=Entry()
     self.routine=Entry()
     self.args=list()
     self.argTable=Table(rows=8,columns=2,homogeneous=False)
     for i in range(8):
         self.args.append(Entry())
         self.argTable.attach(Label("Arg %d:     " % (i+1,)),0,1,i,i+1,0,0)
         self.argTable.attach(self.args[i],1,2,i,i+1,EXPAND|FILL,0)
     self.scrolledWindow=ScrolledWindow()
     self.scrolledWindow.add_with_viewport(self.argTable)
     self.scrolledWindow.set_policy(POLICY_NEVER,POLICY_ALWAYS)
     adj=self.scrolledWindow.get_vadjustment()
     adj.connect("changed",adj_changed)
     self.timeout=Entry()
     self.attach(Label("Library:"),0,1,0,1,0,0)
     self.attach(self.image,1,2,0,1,EXPAND|FILL,0)
     self.attach(Label("Routine:"),0,1,1,2,0,0)
     self.attach(self.routine,1,2,1,2,EXPAND|FILL,0)
     self.attach(self.scrolledWindow,0,2,2,3)
     self.attach(Label("Timeout:"),0,1,3,4,0,0)
     self.attach(self.timeout,1,2,3,4,EXPAND|FILL,0)
     self.set_row_spacings(5)
     self.value=value
Beispiel #5
0
    def __init__(self, title=TITLE, level=WINDOW_TOPLEVEL, on_exit=None):
        self.title = title
        self.grabbing = False
        self.events = []
        self.rgb = WHITE_RGB
        self.on_exit = on_exit

        self.window = Window(level)
        self.window.set_title(title)
        self.window.set_resizable(True)
        self.window.add_events(POINTER_MOTION_MASK)
        self.window.set_default_size(350, 150)
        self.colors = []

        grab_btn = Button('Grab')
        grab_btn.connect_object('clicked', self.toggle_grab, self.window)
        self.grab_btn = grab_btn

        exit_btn = Button('Exit')
        exit_btn.connect_object('clicked', self.destroy, self.window)

        drawing = DrawingArea()
        drawing.connect_object('expose_event', self.do_expose, self.window)
        self.drawing = drawing

        label = Label(rgb_to_string(WHITE_RGB))
        self.label = label

        table = Table(2, 2, True)
        table.attach(self.drawing, 0, 1, 0, 1)
        table.attach(label,   0, 1, 1, 2)
        table.attach(grab_btn, 1, 2, 0, 1)
        table.attach(exit_btn, 1, 2, 1, 2)
        self.window.add(table)
Beispiel #6
0
    def __init__(self):

        Table.__init__(self, 1, 5)

        self.entry1 = Entry()
        self.entry2 = Entry()

        self.button = Button("Search")

        self.attach(self.entry1, 0, 1, 0, 1)
        self.attach(self.entry2, 1, 2, 0, 1)
        self.attach(self.button, 2, 3, 0, 1)

        self.entry1.set_width_chars(12)
        self.entry2.set_width_chars(12)

        self.entry1.set_text("59.666042")
        self.entry2.set_text("16.481794")

        self.button.connect('clicked', self.clicked)
Beispiel #7
0
 def __init__(self):
     
     Table.__init__(self, 1, 5)
     
     self.entry1 = Entry()
     self.entry2 = Entry()
     
     self.button = Button("Search")
     
     self.attach(self.entry1, 0, 1, 0, 1) 
     self.attach(self.entry2, 1, 2, 0, 1) 
     self.attach(self.button, 2, 3, 0, 1)
     
     self.entry1.set_width_chars(12)
     self.entry2.set_width_chars(12)
     
     self.entry1.set_text("59.666042")
     self.entry2.set_text("16.481794")
     
     self.button.connect('clicked', self.clicked)
Beispiel #8
0
    def __init__(self):
        ScrolledWindow.__init__(self)

        self.set_policy(POLICY_ALWAYS, POLICY_ALWAYS)

        self.table = Table(3, 3)
        self.hRuler = HRuler()
        self.vRuler = VRuler()
        self.canvas = Canvas()

        self.canvas.connect('size-allocate', self.area_allocate, None)
        self.canvas.connect('motion-notify-event', self.area_motion, None)

        self.table.attach(self.hRuler, 1, 2, 0, 1, SHRINK | FILL,
                          SHRINK | FILL)
        self.table.attach(self.vRuler, 0, 1, 1, 2, SHRINK | FILL,
                          SHRINK | FILL)
        self.table.attach(self.canvas, 1, 2, 1, 2)

        self.add_with_viewport(self.table)
class MDSplusMethodWidget(Table):

    def __init__(self,value=None):
        super(MDSplusMethodWidget,self).__init__(rows=4,columns=2,homogeneous=False)
        self.device=Entry()
        self.method=Entry()
        self.args=list()
        self.argTable=Table(rows=8,columns=2,homogeneous=False)
        for i in range(8):
            self.args.append(Entry())
            self.argTable.attach(Label("Arg %d:       " % (i+1,)),0,1,i,i+1,0,0)
            self.argTable.attach(self.args[i],1,2,i,i+1,EXPAND|FILL,0)
        self.scrolledWindow=ScrolledWindow()
        self.scrolledWindow.add_with_viewport(self.argTable)
        self.scrolledWindow.set_policy(POLICY_NEVER,POLICY_ALWAYS)
        adj=self.scrolledWindow.get_vadjustment()
        adj.connect("changed",adj_changed)
        self.timeout=Entry()
        self.attach(Label("Device:"),0,1,0,1,0,0)
        self.attach(self.device,1,2,0,1,EXPAND|FILL,0)
        self.attach(Label("Method:"),0,1,1,2,0,0)
        self.attach(self.method,1,2,1,2,EXPAND|FILL,0)
        self.attach(self.scrolledWindow,0,2,2,3)
        self.attach(Label("Timeout:"),0,1,3,4,0,0)
        self.attach(self.timeout,1,2,3,4,EXPAND|FILL,0)
        self.set_row_spacings(5)
        self.value=value

    def getValue(self):
        ans=Method()
        ans.method=self.method.get_text()
        try:
            ans.method=Data.compile(ans.method)
        except Exception,e:
            pass
        try:
            ans.object=Data.compile(self.device.get_text())
        except Exception,e:
            msg="Invalid device specified.\n\n%s" % (e,)
            MDSplusErrorMsg('Invalid Device',msg)
            raise
Beispiel #10
0
class DrawArea(ScrolledWindow):
    def __init__(self):
        ScrolledWindow.__init__(self)

        self.set_policy(POLICY_ALWAYS, POLICY_ALWAYS)

        self.table = Table(3, 3)
        self.hRuler = HRuler()
        self.vRuler = VRuler()
        self.canvas = Canvas()

        self.canvas.connect('size-allocate', self.area_allocate, None)
        self.canvas.connect('motion-notify-event', self.area_motion, None)

        self.table.attach(self.hRuler, 1, 2, 0, 1, SHRINK | FILL,
                          SHRINK | FILL)
        self.table.attach(self.vRuler, 0, 1, 1, 2, SHRINK | FILL,
                          SHRINK | FILL)
        self.table.attach(self.canvas, 1, 2, 1, 2)

        self.add_with_viewport(self.table)

    def area_allocate(self, widget, allocation, data):
        self.hRuler.set_range(0, self.canvas.allocation[2], 10,
                              self.canvas.allocation[2])
        self.vRuler.set_range(0, self.canvas.allocation[3], 10,
                              self.canvas.allocation[3])

    def area_motion(self, widget, event, data):
        self.hRuler.set_range(0, self.canvas.allocation[2], event.x,
                              self.canvas.allocation[2])
        self.vRuler.set_range(0, self.canvas.allocation[3], event.y,
                              self.canvas.allocation[3])
Beispiel #11
0
 def __init__(self, info):
     
     Table.__init__(self, 4, 1)
     
     self.info = info
     
     self.objs = (
         image_new_from_file("img/found/%s.png" % (str(self.info['found']), )),
         image_new_from_file("img/wpt/%s.png" % (self.info['type'][0], )),
         Label(self.info['id']),
         Label("%s by %s" % (self.info['name'], self.info['creator']))
     )
     
     self.objs[0].set_tooltip_text("Found" if self.info['found'] else "Not found")
     self.objs[1].set_tooltip_text(self.info['type'][1])
     
     self.objs[2].set_size_request(80, 32)
     self.objs[3].set_justify(JUSTIFY_LEFT)
     self.objs[3].set_ellipsize(ELLIPSIZE_END)
     
     self.attach(self.objs[0], 0, 1, 0, 1, FILL, FILL)
     self.attach(self.objs[1], 1, 2, 0, 1, FILL, FILL)
     self.attach(self.objs[2], 2, 3, 0, 1, FILL, FILL, FILL, FILL)
     self.attach(self.objs[3], 3, 4, 0, 1)
Beispiel #12
0
 def __init__(self):
     ScrolledWindow.__init__(self)
     MDSplusWidget.__init__(self)
     self.numChannels=4
     self.nodesPerChannel=3
     self.dataNidOffset=1
     self.startIdxNidOffset=2
     self.endIdxNidOffset=3
     self.incNidOffset=-1
     self.table=Table(homogeneous=False)
     self.table.set_row_spacings(0)
     self.add_with_viewport(self.table)
     self.set_policy(POLICY_NEVER,POLICY_ALWAYS)
     adj=self.get_vadjustment()
     if adj is not None:
         adj.connect("changed",self.adj_changed)
Beispiel #13
0
class MDSplusDigChansWidget(props,MDSplusWidget,ScrolledWindow):

    __gtype_name__ = 'MDSplusDigChansWidget'

    __gproperties__= props.__gproperties__


    def resetPart(self,channel,field):
        try:
            channel[field].set_text(str(channel[field+'Node'].record.decompile()))
        except Exception:
            channel[field].set_text('')
        

    def reset(self):
        if not hasattr(self,'channels'):
            self.setupChannels()
        if hasattr(self,'channels'):
            for channel in self.channels:
                try:
                    channel['on'].set_active(channel['dataNode'].on)
                except Exception:
                    channel['on'].set_active(True)
                self.resetPart(channel,'startIdx')
                self.resetPart(channel,'endIdx')
                if self.incNidOffset > -1:
                    self.resetPart(channel,'inc')
                try:
                    channel['path'].set_label(str(channel['dataNode'].minpath))
                except Exception:
                    channel['path'].set_label('')

    def applyPart(self,channel,field,idx):
        value=channel[field].get_text()
        if value == '':
            value=None
        else:
            try:
                value=Data.compile(value)
            except Exception:
                MDSplusErrorMsg('Invalid value','Error compiling %s for channel %d\n\n%s\n\n%s' % (field,idx,value,sys.exc_info()))
                raise
        try:
            if channel[field+'Node'].compare(value) != 1:
                channel[field+'Node'].record=value
        except Exception:
            MDSplusErrorMsg('Error storing value','Error storing value %s for channel %d\n\n\%s' % (field,idx,sys.exc_info()))
        
    def apply(self):
        if self.putOnApply:
            idx=0
            for channel in self.channels:
                idx=idx+1
                if channel['dataNode'].on != channel['on'].get_active():
                    try:
                        channel['dataNode'].on=channel['on'].get_active()
                    except Exception:
                        if channel['on'].get_active():
                            state='on'
                        else:
                            state='off'
                        MDSplusErrorMsg('Error setting node on/off state','Error turning node %s %s\n\n%s' % (channel['dataNode'].minpath,state,sys.exc_info()))
                        raise
                self.applyPart(channel,'startIdx',idx)
                self.applyPart(channel,'endIdx',idx)
                if self.incNidOffset > -1:
                    self.applyPart(channel,'inc',idx)

    def adj_changed(self,adj):
        newstep=adj.upper/self.numChannels
        if adj.step_increment != newstep:
            adj.step_increment = newstep
    
    def setupChannels(self):
        for child in self.table.get_children():
            child.destroy()
        if self.incNidOffset > -1:
            columns=6
        else:
            columns=5
        self.table.resize(self.numChannels+1,columns)
        self.table.attach(Label(""),0,1,0,1,0,0,10,0)
        self.table.attach(Label("On"),1,2,0,1,0,0,10,0)
        self.table.attach(Label("StartIdx"),2,3,0,1,EXPAND|FILL,0,10,0)
        self.table.attach(Label("EndIdx"),3,4,0,1,EXPAND|FILL,0,10,0)
        if self.incNidOffset > -1:
            self.table.attach(Label("Increment"),4,5,0,1,EXPAND|FILL,0,10,0)
        self.table.attach(Label("Path"),columns-1,columns,0,1,0,0,10,0)
        self.channels=list()
        for chan in range(self.numChannels):
            channel=dict()
            self.channels.append(channel)
            channel['number']=Label("%d"% (chan+1,))
            self.table.attach(channel['number'],0,1,chan+1,chan+2,0,0,10,0)
            channel['on']=CheckButton('')
            self.table.attach(channel['on'],1,2,chan+1,chan+2,0,0,10,0)
            channel['startIdx']=Entry()
            self.table.attach(channel['startIdx'],2,3,chan+1,chan+2,EXPAND|FILL,0,10,0)
            channel['endIdx']=Entry()
            self.table.attach(channel['endIdx'],3,4,chan+1,chan+2,EXPAND|FILL,0,10,0)
            if self.incNidOffset > -1:
                channel['inc']=Entry()
                self.table.attach(channel['inc'],4,5,chan+1,chan+2,EXPAND|FILL,0,10,0)
            channel['path']=Label('                   ')
            self.table.attach(channel['path'],columns-1,columns,chan+1,chan+2,0,0,10,0)
        self.show_all()
        if not guibuilder:
            for chan in range(self.numChannels):
                chanNidOffset=self.node.nid+chan*self.nodesPerChannel
                channel=self.channels[chan]
                channel['dataNode']=TreeNode(chanNidOffset+self.dataNidOffset,self.node.tree)
                channel['startIdxNode']=TreeNode(chanNidOffset+self.startIdxNidOffset,self.node.tree)
                channel['endIdxNode']=TreeNode(chanNidOffset+self.endIdxNidOffset,self.node.tree)
                if self.incNidOffset > -1:
                    channel['incNode']=TreeNode(chanNidOffset+self.incNidOffset,self.node.tree)

    def __init__(self):
        ScrolledWindow.__init__(self)
        MDSplusWidget.__init__(self)
        self.numChannels=4
        self.nodesPerChannel=3
        self.dataNidOffset=1
        self.startIdxNidOffset=2
        self.endIdxNidOffset=3
        self.incNidOffset=-1
        self.table=Table(homogeneous=False)
        self.table.set_row_spacings(0)
        self.add_with_viewport(self.table)
        self.set_policy(POLICY_NEVER,POLICY_ALWAYS)
        adj=self.get_vadjustment()
        if adj is not None:
            adj.connect("changed",self.adj_changed)

    def show(self):
        self.show_all()
class MDSplusMethodWidget(Table):
    def __init__(self, value=None):
        super(MDSplusMethodWidget, self).__init__(rows=4,
                                                  columns=2,
                                                  homogeneous=False)
        self.device = Entry()
        self.method = Entry()
        self.args = list()
        self.argTable = Table(rows=8, columns=2, homogeneous=False)
        for i in range(8):
            self.args.append(Entry())
            self.argTable.attach(Label("Arg %d:       " % (i + 1, )), 0, 1, i,
                                 i + 1, 0, 0)
            self.argTable.attach(self.args[i], 1, 2, i, i + 1, EXPAND | FILL,
                                 0)
        self.scrolledWindow = ScrolledWindow()
        self.scrolledWindow.add_with_viewport(self.argTable)
        self.scrolledWindow.set_policy(POLICY_NEVER, POLICY_ALWAYS)
        adj = self.scrolledWindow.get_vadjustment()
        adj.connect("changed", adj_changed)
        self.timeout = Entry()
        self.attach(Label("Device:"), 0, 1, 0, 1, 0, 0)
        self.attach(self.device, 1, 2, 0, 1, EXPAND | FILL, 0)
        self.attach(Label("Method:"), 0, 1, 1, 2, 0, 0)
        self.attach(self.method, 1, 2, 1, 2, EXPAND | FILL, 0)
        self.attach(self.scrolledWindow, 0, 2, 2, 3)
        self.attach(Label("Timeout:"), 0, 1, 3, 4, 0, 0)
        self.attach(self.timeout, 1, 2, 3, 4, EXPAND | FILL, 0)
        self.set_row_spacings(5)
        self.value = value

    def getValue(self):
        ans = Method()
        ans.method = self.method.get_text()
        try:
            ans.method = Data.compile(ans.method)
        except Exception:
            pass
        try:
            ans.object = Data.compile(self.device.get_text())
        except Exception:
            msg = "Invalid device specified.\n\n%s" % (sys.exc_info()[1], )
            MDSplusErrorMsg('Invalid Device', msg)
            raise
        if self.timeout.get_text() == '' or self.timeout.get_text() == '*':
            ans.timeout = None
        else:
            try:
                ans.timeout = Data.compile(self.timeout.get_text())
            except Exception:
                msg = "Invalid timeout specified.\n\n%s" % (
                    sys.exc_info()[1], )
                MDSplusErrorMsg('Invalid Timeout', msg)
                raise
        idx = len(self.args) - 1
        found = False
        while idx >= 0:
            t = self.args[idx].get_text()
            if t == '':
                if found:
                    ans.setArgumentAt(idx, None)
            else:
                try:
                    a = Data.compile(t)
                except Exception:
                    msg = "Invalid argument (%d) specified.\n\n%s" % (
                        idx + 1,
                        sys.exc_info()[1],
                    )
                    MDSplusErrorMsg('Invalid Argument', msg)
                    raise
                ans.setArgumentAt(idx, a)
                found = True
            idx = idx - 1
        return ans

    def setValue(self, d):
        self._value = d
        self.reset()

    def reset(self):
        if isinstance(self._value, Method):
            self.method.set_text(self._value.method.decompile())
            self.device.set_text(self._value.object.decompile())
            if self._value.timeout is None:
                self.timeout.set_text('')
            else:
                self.timeout.set_text(self._value.timeout.decompile())
            idx = 0
            for arg in self.args:
                if self._value.getArgumentAt(idx) is None:
                    arg.set_text('')
                else:
                    arg.set_text(self._value.getArgumentAt(idx).decompile())
                idx = idx + 1
        else:
            self.method.set_text('')
            self.device.set_text('')
            self.timeout.set_text('')
            for arg in self.args:
                arg.set_text('')

    value = property(getValue, setValue)

    def show(self):
        old = self.get_no_show_all()
        self.set_no_show_all(False)
        self.show_all()
        self.set_no_show_all(old)
class MDSplusRoutineWidget(Table):

    def __init__(self,value=None):
        super(MDSplusRoutineWidget,self).__init__(rows=4,columns=2,homogeneous=False)
        self.image=Entry()
        self.routine=Entry()
        self.args=list()
        self.argTable=Table(rows=8,columns=2,homogeneous=False)
        for i in range(8):
            self.args.append(Entry())
            self.argTable.attach(Label("Arg %d:     " % (i+1,)),0,1,i,i+1,0,0)
            self.argTable.attach(self.args[i],1,2,i,i+1,EXPAND|FILL,0)
        self.scrolledWindow=ScrolledWindow()
        self.scrolledWindow.add_with_viewport(self.argTable)
        self.scrolledWindow.set_policy(POLICY_NEVER,POLICY_ALWAYS)
        adj=self.scrolledWindow.get_vadjustment()
        adj.connect("changed",adj_changed)
        self.timeout=Entry()
        self.attach(Label("Library:"),0,1,0,1,0,0)
        self.attach(self.image,1,2,0,1,EXPAND|FILL,0)
        self.attach(Label("Routine:"),0,1,1,2,0,0)
        self.attach(self.routine,1,2,1,2,EXPAND|FILL,0)
        self.attach(self.scrolledWindow,0,2,2,3)
        self.attach(Label("Timeout:"),0,1,3,4,0,0)
        self.attach(self.timeout,1,2,3,4,EXPAND|FILL,0)
        self.set_row_spacings(5)
        self.value=value

    def getValue(self):
        ans=Routine()
        ans.image=self.image.get_text()
        try:
            ans.image=Data.compile(ans.image)
        except Exception:
            pass
        ans.routine=self.routine.get_text()
        try:
            ans.routine=Data.compile(ans.routine)
        except Exception:
            pass
        if self.timeout.get_text() == '' or self.timeout.get_text() == '*':
            ans.timeout=None
        else:
            try:
                ans.timeout=Data.compile(self.timeout.get_text())
            except Exception:
                msg="Invalid timeout specified.\n\n%s" % (sys.exc_info(),)
                MDSplusErrorMsg('Invalid Timeout',msg)
                raise
        idx=len(self.args)-1
        found=False
        while idx >= 0:
            t = self.args[idx].get_text()
            if t == '':
                if found:
                    ans.setArgumentAt(idx,None)
            else:
                try:
                    a=Data.compile(t)
                except Exception:
                    msg="Invalid argument specified.\n\n%s" % (sys.exc_info(),)
                    MDSplusErrorMsg('Invalid Argument',msg)
                    raise
                ans.setArgumentAt(idx,a)
                found=True
            idx=idx-1
        return ans
        
    def setValue(self,d):
        self._value=d
        self.reset()


    def reset(self):
        if isinstance(self._value,Routine):
            self.image.set_text(self._value.image.decompile())
            self.routine.set_text(self._value.routine.decompile())
            if self._value.timeout is None or self._value.timeout.decompile() == '*':
                self.timeout.set_text('')
            else:
                self.timeout.set_text(self._value.timeout.decompile())
            idx=0
            for arg in self.args:
                if self._value.getArgumentAt(idx) is None:
                    arg.set_text('')
                else:
                    arg.set_text(self._value.getArgumentAt(idx).decompile())
                idx=idx+1
        else:
            self.image.set_text('')
            self.routine.set_text('')
            self.timeout.set_text('')
            for arg in self.args:
                arg.set_text('')

    value=property(getValue,setValue)

    def show(self):
        old=self.get_no_show_all()
        self.set_no_show_all(False)
        self.show_all()
        self.set_no_show_all(old)
Beispiel #16
0
class MDSplusDigChansWidget(props, MDSplusWidget, ScrolledWindow):

    __gtype_name__ = 'MDSplusDigChansWidget'

    __gproperties__ = props.__gproperties__

    def resetPart(self, channel, field):
        try:
            channel[field].set_text(
                str(channel[field + 'Node'].record.decompile()))
        except Exception:
            channel[field].set_text('')

    def reset(self):
        if not hasattr(self, 'channels'):
            self.setupChannels()
        if hasattr(self, 'channels'):
            for channel in self.channels:
                try:
                    channel['on'].set_active(channel['dataNode'].on)
                except Exception:
                    channel['on'].set_active(True)
                self.resetPart(channel, 'startIdx')
                self.resetPart(channel, 'endIdx')
                if self.incNidOffset > -1:
                    self.resetPart(channel, 'inc')
                try:
                    channel['path'].set_label(str(channel['dataNode'].minpath))
                except Exception:
                    channel['path'].set_label('')

    def applyPart(self, channel, field, idx):
        value = channel[field].get_text()
        if value == '':
            value = None
        else:
            try:
                value = Data.compile(value)
            except Exception:
                MDSplusErrorMsg(
                    'Invalid value',
                    'Error compiling %s for channel %d\n\n%s\n\n%s' %
                    (field, idx, value, sys.exc_info()))
                raise
        try:
            if channel[field + 'Node'].compare(value) != 1:
                channel[field + 'Node'].record = value
        except Exception:
            MDSplusErrorMsg(
                'Error storing value',
                'Error storing value %s for channel %d\n\n\%s' %
                (field, idx, sys.exc_info()))

    def apply(self):
        if self.putOnApply:
            idx = 0
            for channel in self.channels:
                idx = idx + 1
                if channel['dataNode'].on != channel['on'].get_active():
                    try:
                        channel['dataNode'].on = channel['on'].get_active()
                    except Exception:
                        if channel['on'].get_active():
                            state = 'on'
                        else:
                            state = 'off'
                        MDSplusErrorMsg(
                            'Error setting node on/off state',
                            'Error turning node %s %s\n\n%s' %
                            (channel['dataNode'].minpath, state,
                             sys.exc_info()))
                        raise
                self.applyPart(channel, 'startIdx', idx)
                self.applyPart(channel, 'endIdx', idx)
                if self.incNidOffset > -1:
                    self.applyPart(channel, 'inc', idx)

    def adj_changed(self, adj):
        newstep = adj.upper / self.numChannels
        if adj.step_increment != newstep:
            adj.step_increment = newstep

    def setupChannels(self):
        for child in self.table.get_children():
            child.destroy()
        if self.incNidOffset > -1:
            columns = 6
        else:
            columns = 5
        self.table.resize(self.numChannels + 1, columns)
        self.table.attach(Label(""), 0, 1, 0, 1, 0, 0, 10, 0)
        self.table.attach(Label("On"), 1, 2, 0, 1, 0, 0, 10, 0)
        self.table.attach(Label("StartIdx"), 2, 3, 0, 1, EXPAND | FILL, 0, 10,
                          0)
        self.table.attach(Label("EndIdx"), 3, 4, 0, 1, EXPAND | FILL, 0, 10, 0)
        if self.incNidOffset > -1:
            self.table.attach(Label("Increment"), 4, 5, 0, 1, EXPAND | FILL, 0,
                              10, 0)
        self.table.attach(Label("Path"), columns - 1, columns, 0, 1, 0, 0, 10,
                          0)
        self.channels = list()
        for chan in range(self.numChannels):
            channel = dict()
            self.channels.append(channel)
            channel['number'] = Label("%d" % (chan + 1, ))
            self.table.attach(channel['number'], 0, 1, chan + 1, chan + 2, 0,
                              0, 10, 0)
            channel['on'] = CheckButton('')
            self.table.attach(channel['on'], 1, 2, chan + 1, chan + 2, 0, 0,
                              10, 0)
            channel['startIdx'] = Entry()
            self.table.attach(channel['startIdx'], 2, 3, chan + 1, chan + 2,
                              EXPAND | FILL, 0, 10, 0)
            channel['endIdx'] = Entry()
            self.table.attach(channel['endIdx'], 3, 4, chan + 1, chan + 2,
                              EXPAND | FILL, 0, 10, 0)
            if self.incNidOffset > -1:
                channel['inc'] = Entry()
                self.table.attach(channel['inc'], 4, 5, chan + 1, chan + 2,
                                  EXPAND | FILL, 0, 10, 0)
            channel['path'] = Label('                   ')
            self.table.attach(channel['path'], columns - 1, columns, chan + 1,
                              chan + 2, 0, 0, 10, 0)
        self.show_all()
        if not guibuilder:
            for chan in range(self.numChannels):
                chanNidOffset = self.node.nid + chan * self.nodesPerChannel
                channel = self.channels[chan]
                channel['dataNode'] = TreeNode(
                    chanNidOffset + self.dataNidOffset, self.node.tree)
                channel['startIdxNode'] = TreeNode(
                    chanNidOffset + self.startIdxNidOffset, self.node.tree)
                channel['endIdxNode'] = TreeNode(
                    chanNidOffset + self.endIdxNidOffset, self.node.tree)
                if self.incNidOffset > -1:
                    channel['incNode'] = TreeNode(
                        chanNidOffset + self.incNidOffset, self.node.tree)

    def __init__(self):
        ScrolledWindow.__init__(self)
        MDSplusWidget.__init__(self)
        self.numChannels = 4
        self.nodesPerChannel = 3
        self.dataNidOffset = 1
        self.startIdxNidOffset = 2
        self.endIdxNidOffset = 3
        self.incNidOffset = -1
        self.table = Table(homogeneous=False)
        self.table.set_row_spacings(0)
        self.add_with_viewport(self.table)
        self.set_policy(POLICY_NEVER, POLICY_ALWAYS)
        adj = self.get_vadjustment()
        if adj is not None:
            adj.connect("changed", self.adj_changed)

    def show(self):
        self.show_all()