def __init__(self, *args): """ Descript. : """ BlissWidget.__init__(self, *args) self.propertyBag = PropertyBag.PropertyBag()
def __init__(self, name, item_type=""): self.name = name self.type = item_type self.children = [] self.connections = [] self.properties = PropertyBag.PropertyBag() self.properties.addProperty( "alignment", "combo", ( "none", "top center", "top left", "top right", "bottom center", "bottom left", "bottom right", "center", "hcenter", "vcenter", "left", "right", ), "none", ) self.signals = {} self.slots = {}
def __init__(self, parent = None, widgetName = ''): Connectable.Connectable.__init__(self) QWidget.__init__(self, parent, widgetName) self.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.MinimumExpanding) self.propertyBag = PropertyBag.PropertyBag() self.__enabledState = True #saved enabled state self.__loadedHardwareObjects = [] self._signalSlotFilters = {} self._widgetEvents = [] # # add what's this help # QWhatsThis.add(self, "%s (%s)\n" % (widgetName, self.__class__.__name__)) # # add properties shared by all BlissWidgets # self.addProperty('fontSize', 'string', str(self.font().pointSize())) #self.addProperty("alignment", "combo", ("none", "top center", "top left", "top right", "bottom center", "bottom left", "bottom right", "center", "left", "right"), "none") self.addProperty('instanceAllowAlways', 'boolean', False)#, hidden=True) self.addProperty('instanceAllowConnected', 'boolean', False)#, hidden=True) # # connect signals / slots # dispatcher.connect(self.__hardwareObjectDiscarded, 'hardwareObjectDiscarded', HardwareRepository.HardwareRepository()) self.defineSlot('enable_widget', ())
def __init__(self, parent=None, widget_name=''): """ Descript. : """ Connectable.Connectable.__init__(self) QFrame.__init__(self, parent) self.setObjectName(widget_name) self.property_bag = PropertyBag.PropertyBag() self.__enabledState = True self.__loaded_hardware_objects = [] self.__failed_to_load_hwobj = False self.__use_progress_dialog = False self._signal_slot_filters = {} self._widget_events = [] self.setWhatsThis("%s (%s)\n" % (widget_name, self.__class__.__name__)) self.addProperty('fontSize', 'string', str(self.font().pointSize())) self.addProperty('frame', 'boolean', False, comment="Draw a frame around the widget") self.addProperty('instanceAllowAlways', 'boolean', False, comment="Allow to control brick in all modes") self.addProperty('instanceAllowConnected', 'boolean', False, comment="Allow to control brick in slave mode") self.addProperty('fixedWidth', 'integer', '-1', comment="Set fixed width in pixels") self.addProperty('fixedHeight', 'integer', '-1', comment="Set fixed height in pixels") self.addProperty('hide', 'boolean', False, comment="Hide widget") dispatcher.connect(self.__hardwareObjectDiscarded, 'hardwareObjectDiscarded', HardwareRepository.HardwareRepository()) self.defineSlot('enable_widget', ()) self.defineSlot('disable_widget', ()) #If PySide used then connect method was not overriden #This solution of redirecting methods works... self.connect = self.connect_hwobj self.diconnect = self.disconnect_hwobj
def load_children(children): """Loads children""" index = 0 for child in children: new_item = None if "brick" in child: brick = load_brick(child["type"], child["name"]) child["brick"] = brick new_item = Qt4_BaseLayoutItems.BrickCfg( child["name"], child["type"]) new_item["brick"] = brick self.bricks[child["name"]] = new_item else: if child["type"] == "window": new_item = Qt4_BaseLayoutItems.WindowCfg(child["name"]) self.windows[child["name"]] = new_item else: NewItemClass = Configuration.classes[child["type"]] new_item = NewItemClass(child["name"], child["type"]) self.items[child["name"]] = new_item if new_item is not None: if type(child["properties"]) == bytes: #if type(child["properties"]) == str: try: new_item.setProperties( pickle.loads(child["properties"])) #newItem.setProperties(pickle.loads(child["properties"].encode('utf8'))) except: logging.getLogger().exception(\ "Error: could not load properties " + \ "for %s", child["name"]) new_item.properties = PropertyBag.PropertyBag() else: new_item.setProperties(child["properties"]) child["properties"] = new_item.properties new_item.__dict__ = child #try: # new_item_signals = new_item["signals"] # new_item_slots = new_item["slots"] #except: # new_item.__dict__ = child #else: # new_item.__dict__ = child # new_item.slots = new_item_slots # new_item.signals = new_item_signals # children[index] = new_item children[index] = new_item load_children(child["children"]) index += 1
def loadChildren(children): i = 0 for child in children: newItem = None if "brick" in child: b = loadBrick(child["type"], child["name"]) child["brick"] = b newItem = BaseLayoutItems.BrickCfg(child["name"], child["type"]) newItem["brick"] = b self.bricks[child["name"]] = newItem else: if child["type"] == "window": newItem = BaseLayoutItems.WindowCfg(child["name"]) self.windows[child["name"]] = newItem else: newItemClass = Configuration.classes[child["type"]] newItem = newItemClass(child["name"], child["type"]) self.items[child["name"]] = newItem if newItem is not None: if type(child["properties"]) == bytes: try: #print "loading properties for %s" % child["name"] newItem.setProperties( pickle.loads(child["properties"])) except: logging.getLogger().exception( "Error: could not load properties for %s", child["name"]) newItem.properties = PropertyBag.PropertyBag() else: newItem.setProperties(child["properties"]) child["properties"] = newItem.properties try: newItemSignals = newItem["signals"] newItemSlots = newItem["slots"] except: newItem.__dict__ = child else: newItem.__dict__ = child newItem.slots = newItemSlots newItem.signals = newItemSignals children[i] = newItem loadChildren(child["children"]) i += 1
def loadChildren(children): i = 0 for child in children: newItem = None if "brick" in child: b = loadBrick(child["type"], child["name"]) child["brick"] = b newItem = BaseLayoutItems.BrickCfg(child["name"], child["type"]) newItem["brick"] = b self.bricks[child["name"]] = newItem else: if child["type"] == "window": newItem = BaseLayoutItems.WindowCfg(child["name"]) self.windows[child["name"]] = newItem else: newItemClass = Configuration.classes[child["type"]] newItem = newItemClass(child["name"], child["type"]) self.items[child["name"]] = newItem if newItem is not None: if isinstance(child["properties"], types.StringType): try: #print "loading properties for %s" % child["name"] newItem.setProperties( cPickle.loads(child["properties"])) except BaseException: logging.getLogger().exception( "Error: could not load properties for %s", child["name"]) newItem.properties = PropertyBag.PropertyBag() else: newItem.setProperties(child["properties"]) child["properties"] = newItem.properties newItem.__dict__ = child children[i] = newItem loadChildren(child["children"]) i += 1
def __init__(self, *args): """Constructor """ BlissWidget.__init__(self, *args) self.__stopIdle = _stopIdle() # addProperty adds a property for the brick : # - 1st argument is the name of the property ; # - 2d argument is the type (one of string, integer, float, file, combo) ; # - 3rd argument is the default value. # In some cases (e.g combo), the third argument is a tuple of choices # and the fourth argument is the default value. # When a property is changed, the propertyChanged() method is called. self.addProperty("mnemonic", "string", "") self.addProperty("title", "string", "") self.addProperty("formatString", "formatString", "###.##") self.addProperty("horizontalLayout", "boolean", True) self.__horizontalLayout = False self.addProperty("dynamicProperties", "", PropertyBag.PropertyBag(), hidden=True) # now we can "draw" the brick, i.e creating GUI widgets # and arranging them in a layout. It is the default appearance # for the brick (if no property is set for example) self.__lblTitle = qt.QLabel(self) self.__lblTitle.setAlignment(qt.Qt.AlignHCenter) self.__pads = [] self.__plugs = [] self.__padLayout = qt.QGridLayout(None, 1, 1) self.__padLayout.setSpacing(0) self.__padLayout.setMargin(0) layout = qt.QVBoxLayout(self, 0, 0) layout.addWidget(self.__lblTitle) layout.addLayout(self.__padLayout) self.__extPadid = re.compile(r"pad (\d+)")
def __init__(self, parent=None, widgetName=''): """ Descript. : """ Connectable.Connectable.__init__(self) QtGui.QFrame.__init__(self, parent) self.setObjectName(widgetName) self.propertyBag = PropertyBag.PropertyBag() self.__enabledState = True #saved enabled state self.__loadedHardwareObjects = [] self._signalSlotFilters = {} self._widgetEvents = [] # # add what's this help # self.setWhatsThis("%s (%s)\n" % (widgetName, self.__class__.__name__)) #WhatsThis.add(self, "%s (%s)\n" % (widgetName, self.__class__.__name__)) # # add properties shared by all BlissWidgets # self.addProperty('fontSize', 'string', str(self.font().pointSize())) self.addProperty('frame', 'boolean', False) self.addProperty('instanceAllowAlways', 'boolean', False) #, hidden=True) self.addProperty('instanceAllowConnected', 'boolean', False) #, hidden=True) self.addProperty('fixedWidth', 'integer', '-1') self.addProperty('fixedHeight', 'integer', '-1') # # connect signals / slots # dispatcher.connect(self.__hardwareObjectDiscarded, 'hardwareObjectDiscarded', HardwareRepository.HardwareRepository()) self.defineSlot('enable_widget', ())
def propertyChanged(self, property, oldValue, newValue): if property == "mnemonic": self.__plugs = [] for pad in self.__pads: self.__padLayout.remove(pad) self.__pads = [] equipment = self.getHardwareObject(newValue) if equipment is not None: if hasattr(equipment, "isSampleStage"): for pad in equipment.getAxisList(): self.__createOnePad(pad) elif hasattr(equipment, "move"): self.__createOneAxis(equipment) else: self.__createOnePad(equipment) # clean properties propNames = [] for propertyName, prop in self.propertyBag.properties.iteritems( ): if propertyName not in [ "fontSize", "mnemonic", "title", "formatString", ]: propNames.append(propertyName) if not self.isRunning() and oldValue is not None: for propertyName in propNames: self.delProperty(propertyName) self.addProperty( "dynamicProperties", "", PropertyBag.PropertyBag(), hidden=True, ) # Brick Property if hasattr(equipment, "isSampleStage"): for i, axis in enumerate(equipment.getAxisList()): self.__addNewProperty(axis, i, len(self.__pads) > 1) elif equipment.__class__.__name__ == "SpecMotor": self.__addNewAxisProperty() else: self.__addNewProperty(equipment) self.propertyBag.properties.update( self["dynamicProperties"].properties) self.propertyBag.updateEditor() for name, prop in self[ "dynamicProperties"].properties.iteritems(): self.__setDynamicProperty(name, prop.getValue()) # refresh labels self["formatString"] = self.getProperty( "formatString").getUserValue() elif property == "title": self.__lblTitle.setText(newValue) elif property == "formatString": for plug in self.__plugs: plug.setFormat(self["formatString"]) elif property == "horizontalLayout": for pad in self.__pads: self.__padLayout.remove(pad) self.__horizontalLayout = newValue if newValue: for i, pad in enumerate(self.__pads): self.__padLayout.addWidget(pad, 0, i) else: for i, pad in enumerate(self.__pads): self.__padLayout.addWidget(pad, i, 0) else: if self.__setDynamicProperty(property, newValue): self["dynamicProperties"].getProperty(property).setValue( newValue)
def __init__(self, *args): BlissWidget.__init__(self, *args) self.propertyBag = PropertyBag.PropertyBag()