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
Exemple #2
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)
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,e:
            pass
        ans.routine=self.routine.get_text()
        try:
            ans.routine=Data.compile(ans.routine)
        except Exception,e:
            pass
Exemple #4
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])
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)