Exemplo n.º 1
0
    def _refresh(self, full=False):
        """
        refreshes the gui, if full, sets also the color of the address field
        """

        pic = PyInstrumentsConfig()
        self.tree_widget.blockSignals(True)
        self.tree_widget.remove_all_items()
        for tag, instr in pic.iteritems():
            widgetItem = self.tree_widget.add_item("", "", "", "", "", "")
            try:
                widgetItem.set_values(tag, \
                                  instr["address"],
                                  instr["model"],
                                  instr["simulate"],
                                  instr["code"])
            except KeyError as e:
                print "error"
                print e
            if (instr["model"] in Driver.supported_models()):
                widgetItem.set_color(2, "green")
            else:
                widgetItem.set_color(2, "red")

            if (instr["address"] in con.existing_addresses(full)):
                widgetItem.set_color(1, "green")
            else:
                widgetItem.set_color(1, "red")

        self.tree_widget.blockSignals(False)
 def remove_all(self):
     """
     removes all instruments
     """
     
     pic = PyInstrumentsConfig()
     pic.clear()
     pic.save()
     self.refresh()
 def get_from_gui(self):
     """updates values from the gui"""
     
     pic = PyInstrumentsConfig()
     pic.clear()
     for itm in self.tree_widget:
         pic[itm.val("logical_name")] = {"address" : itm.val("address"),
                                         "model" : itm.val("model"),
                                         "simulate" : itm.val("simulate"),
                                         "code": itm.val("code")}
     pic.save()
Exemplo n.º 4
0
    def item_changed(self):
        """an item changed in the gui"""

        self.get_from_gui()
        pic = PyInstrumentsConfig()
        self.fast_refresh()
        self.get_from_gui()
Exemplo n.º 5
0
def add_all_new_instruments():
    """Looks at all surrounding instruments as listed by 
    visa.get_instrument_list() and queries the model
    """

    dictionnary = get_surrounding_instruments()
    pic = PyInstrumentsConfig()
    existing_addresses = [instr["address"] for instr in pic.values()]
    for address, model in dictionnary.iteritems():
        if address not in existing_addresses:
            if model == "no device":
                model = None
            if len(address) < 10:
                tag = address
            else:
                tag = "DEV"
            tag = pic.add_instrument(tag, address=address, model=model)
def add_all_new_instruments():
    """Looks at all surrounding instruments as listed by 
    visa.get_instrument_list() and queries the model
    """
    
    dictionnary = get_surrounding_instruments()
    pic = PyInstrumentsConfig()
    existing_addresses = [instr["address"] for instr in pic.values()]
    for address, model in dictionnary.iteritems():
        if address not in existing_addresses:
            if model == "no device":
                model = None
            if len(address) < 10:
                tag = address
            else:
                tag = "DEV"
            tag = pic.add_instrument(tag, address = address, model = model)
Exemplo n.º 7
0
    def remove_all(self):
        """
        removes all instruments
        """

        pic = PyInstrumentsConfig()
        pic.clear()
        pic.save()
        self.refresh()
 def _refresh(self, full = False):
     """
     refreshes the gui, if full, sets also the color of the address field
     """
     
     pic = PyInstrumentsConfig()
     self.tree_widget.blockSignals(True)
     self.tree_widget.remove_all_items()
     for tag, instr in pic.iteritems():
         widgetItem = self.tree_widget.add_item("",
                                               "",
                                               "",
                                               "",
                                               "",
                                               "")
         try:
             widgetItem.set_values(tag, \
                               instr["address"],
                               instr["model"],
                               instr["simulate"],
                               instr["code"])
         except KeyError as e:
             print "error"
             print e
         if(instr["model"] in Driver.supported_models()):
             widgetItem.set_color(2, "green")
         else:
             widgetItem.set_color(2, "red")
         
         
         if(instr["address"] in con.existing_addresses(full)):
             widgetItem.set_color(1, "green")
         else:
             widgetItem.set_color(1, "red")
                 
     self.tree_widget.blockSignals(False) 
Exemplo n.º 9
0
    def get_from_gui(self):
        """updates values from the gui"""

        pic = PyInstrumentsConfig()
        pic.clear()
        for itm in self.tree_widget:
            pic[itm.val("logical_name")] = {
                "address": itm.val("address"),
                "model": itm.val("model"),
                "simulate": itm.val("simulate"),
                "code": itm.val("code")
            }
        pic.save()
Exemplo n.º 10
0
def query_models():
    """Physically queries all instruments models"""
    pic = PyInstrumentsConfig()
    for item in pic.values():
        item["model"] = get_model_name(item["address"])
    pic.save()
Exemplo n.º 11
0
    def contextMenu(self, point):
        """
        Context Menu (right click on the tree_widget)
        """

        if self.tree_widget.itemAt(point) != None:
            if self.tree_widget.columnAt(point.x()) == 1:
                return self.contextMenuAdresses(point)
            if self.tree_widget.columnAt(point.x()) == 2:
                return self.contextMenuModels(point)
        pic = PyInstrumentsConfig()

        def remove():
            """
            removes an item
            """

            pic.remove(logical_name)
            self.refresh()

        def add():
            """
            adds an item
            """

            tag = pic.add_instrument()
            self.refresh()

        menu = QtGui.QMenu(self)
        actionAddDevice = QtGui.QAction("add device", self)
        actionAddDevice.triggered.connect(add)
        menu.addAction(actionAddDevice)
        items = self.tree_widget.selectedItems()
        if len(items) > 0:
            obj = items[0]
            logical_name = str(obj.text(0))
            address = str(obj.text(1))
            actionRemoveDevice = QtGui.QAction("remove " + \
                                               logical_name + \
                                               "?", \
                                            self)
            actionRemoveDevice.triggered.connect(remove)
            menu.addAction(actionRemoveDevice)

            def query_model():
                """
                physically queries model from the device
                """

                pic[logical_name]["model"] = con.get_model_name(address)
                pic.save()
                self.refresh()


            actionQueryModel = QtGui.QAction( \
                                              "query model at address " + \
                                              address, \
                                            self)
            actionQueryModel.triggered.connect(query_model)
            menu.addAction(actionQueryModel)
            menu.addSeparator()

            #### if some specific menu_items have to be added,
            ## they will be added here

        self.exec_menu_at_right_place(menu, point)
Exemplo n.º 12
0
 def change_model(new_model):
     pic = PyInstrumentsConfig()
     itm = self.tree_widget.itemAt(point)
     pic[itm.val("logical_name")]["model"] = new_model
     pic.save()
     self.refresh()
Exemplo n.º 13
0
 def change_address(new_address):
     pic = PyInstrumentsConfig()
     itm = self.tree_widget.itemAt(point)
     pic[itm.val("logical_name")]["address"] = new_address
     pic.save()
     self.refresh()
 def change_model(new_model):
     pic = PyInstrumentsConfig()
     itm = self.tree_widget.itemAt(point)
     pic[itm.val("logical_name")]["model"] =  new_model
     pic.save()
     self.refresh()
 def change_address(new_address):
     pic = PyInstrumentsConfig()
     itm = self.tree_widget.itemAt(point)
     pic[itm.val("logical_name")]["address"] =  new_address
     pic.save()
     self.refresh()
def query_models():
    """Physically queries all instruments models"""
    pic = PyInstrumentsConfig()
    for item in pic.values():
        item["model"] = get_model_name(item["address"])
    pic.save()