class AttrAreaWidget(QWidget): checkboxStateChangedSignal = pyqtSignal(str, object) def setAnnotationScene(self, annotationScene): self._scene = annotationScene def enableAllGroups(self, enabled=True): for gn, gw in self.checkboxGroupWidgets.items(): gw.setEnabled(enabled) gw.enableAll(enabled) def enableCheckboxGroup(self, checkboxGroupName, enabled=True): groupWidget = self.checkboxGroupWidgets.get(checkboxGroupName, None) if groupWidget is not None: groupWidget.setEnabled(enabled) groupWidget.enableAll(enabled) def enableCheckbox(self, checkboxGroupName, checkboxName, enabled=True): groupWidget = self.checkboxGroupWidgets.get(checkboxGroupName, None) if groupWidget is not None: groupWidget.enable(checkboxName, enabled) # return (names_list, texts_list, displaycolors_list) def get_group_config(self, checkboxGroupName): names = [] texts = [] displaycolors = [] groupWidget = self.checkboxGroupWidgets.get(checkboxGroupName, None) if groupWidget is not None: names, texts, displaycolors = groupWidget.get_config() return names, texts, displaycolors # return names_list def get_group_names(self): groupNames = [] for groupName in self.checkboxGroupWidgets.keys(): groupNames.append(groupName) return groupNames def setCheckedAllGroups(self, checked=True): for groupName, groupWidget in self.checkboxGroupWidgets.items(): groupWidget.setCheckedAll(checked) def setCheckedGroup(self, checkboxGroupName, checked=True): groupWidget = self.checkboxGroupWidgets.get(checkboxGroupName, None) if groupWidget is not None: groupWidget.setCheckedAll(checked) def setCheckedCheckbox(self, checkboxGroupName, checkboxName, checked=True): # print "checkboxGroupName {} checkboxName {} checked {} ...".format(checkboxGroupName, checkboxName, checked) groupWidget = self.checkboxGroupWidgets.get(checkboxGroupName, None) # print "checkboxGroupWidgets = {}...".format(self.checkboxGroupWidgets) if groupWidget is not None: # LOG.info("AttrAreaWidget.setCheckedCheckbox for group {} checked {} ..".format(checkboxGroupName, checked)) # print ("AttrAreaWidget.setCheckedCheckbox for group {} checked {} ..".format(checkboxGroupName, checked)) groupWidget.setCheckedCheckbox(checkboxName, checked) def setCheckedCheckboxs(self, checkboxGroupName, checkboxNamesList, checked=True): if checkboxNamesList is None: return groupWidget = self.checkboxGroupWidgets.get(checkboxGroupName, None) if groupWidget is not None: # LOG.info(u"{} AttrAreaWidget.setCheckedCheckbox for group {} box {} checked {} ..".format(self.groupName, checkboxGroupName, checkboxNamesList, checked)) groupWidget.setCheckedCheckboxs(checkboxNamesList, checked) def sendCheckedSignal(self, checkboxGroupName): groupWidget = self.checkboxGroupWidgets.get(checkboxGroupName, None) if groupWidget is not None: groupWidget.sendCheckedSignal() def getCheckedWidgetsOptionInfo(self, checkboxGroupName): groupWidget = self.checkboxGroupWidgets.get(checkboxGroupName, None) if groupWidget is not None: return groupWidget.getCheckedWidgetsOptionInfo() return None, None def setOptionStateChangedSignalSlot(self, checkboxStateChangedSignalSlot): if checkboxStateChangedSignalSlot is not None: # print u"pannel {}: checkboxStateChangedSignal{} checkboxStateChangedSignalSlot {} is connected...".format(self.idName, self.checkboxStateChangedSignal, checkboxStateChangedSignalSlot) self.checkboxStateChangedSignal.connect( checkboxStateChangedSignalSlot) def hideGroup(self, checkboxGroupName): groupWidget = self.checkboxGroupWidgets.get(checkboxGroupName, None) if groupWidget is not None: return groupWidget.hide() def __init__(self, property=None, idName=None, displayName=None, parent=None): QWidget.__init__(self, parent) self.hotkeys = [] self.displayName = displayName self.idName = idName self.vlayout = MyVBoxLayout() #QVBoxLayout() self.vlayout.setAlignment(Qt.AlignTop) self.vlayout.setSpacing(4) self.vlayout.setMargin(4) #self.vlayout.setContentsMargins(0, 0, 0, 44) # LOG.info("AttrAreaWidget constructor : property {} ...".format(property)) self.numGroups = len(property) if property is not None else 0 self.checkboxGroupsDescDict = {} self.checkboxGroupWidgets = {} for i in xrange(self.numGroups): thisGroupProperty = property[i] # thisGroupProperty is a dict thisGroupName = thisGroupProperty.get( 'name') # thisGroupName is a string thisGroupOption = thisGroupProperty.get( 'option' ) # thisGroupOption is a tuple of dicts. each dict describes a checkbox thisGroupText = thisGroupProperty.get('displaytext') isExclusive = False if thisGroupName in config.NON_EXCLUSIVE_ATTRS_TAG_LIST else True if thisGroupName == config.ANNOTATION_PERSONBIKE_TYPE_GROUP_TOKEN: checkboxWidgetMinWidthInPixels = 52 else: checkboxWidgetMinWidthInPixels = 38 if thisGroupName == config.ANNOTATION_UPPER_COLOR_TOKEN: thisGroup_maxCheckedNum = config.MAX_UPPER_COLOR_NUMBER thisGroup_maxSeperateWidgetNum = config.GUI_MAX_SEPERATE_UPPER_COLOR_WIDGET_NUMBER elif thisGroupName == config.ANNOTATION_LOWER_COLOR_TOKEN: thisGroup_maxCheckedNum = config.MAX_LOWER_COLOR_NUMBER thisGroup_maxSeperateWidgetNum = config.GUI_MAX_SEPERATE_LOWER_COLOR_WIDGET_NUMBER elif thisGroupName == config.ANNOTATION_VEHICLE_COLOR_TOKEN: thisGroup_maxCheckedNum = config.MAX_VEHICLE_COLOR_NUMBER thisGroup_maxSeperateWidgetNum = config.GUI_MAX_SEPERATE_VEHICLE_COLOR_WIDGET_NUMBER else: thisGroup_maxCheckedNum = config.MAX_CHECKED_OPTIONS_NUMBER thisGroup_maxSeperateWidgetNum = config.MAX_OPTIONS_NUMBER thisGroupWidget = CheckboxListWidget( thisGroupName, thisGroupText, isExclusive, thisGroupOption, self.checkboxStateChangedSignal, thisGroup_maxCheckedNum, thisGroup_maxSeperateWidgetNum) # add checkbox record to this checkbox group record thisGroupCheckboxs = {} for checkboxOption in thisGroupOption: thisCheckboxName = checkboxOption[ config.METADATA_ATTR_VALUE_TOKEN] thisCheckboxProperty = checkboxOption.copy() thisGroupCheckboxs[thisCheckboxName] = thisCheckboxProperty self.vlayout.addWidget(thisGroupWidget) self.checkboxGroupsDescDict[ thisGroupName] = thisGroupCheckboxs # add this checkbox group record to checkbox groups recrod self.checkboxGroupWidgets[thisGroupName] = thisGroupWidget # LOG.info("checkboxGroupWidgets = {} checkboxGroupsDescDict = {}".format(self.checkboxGroupWidgets, self.checkboxGroupsDescDict) self.vlayout.addStretch(1) self.setLayout(self.vlayout) return def stateHasChanged(self, checkedWidgetsAttrDescDict): # LOG.info("call AttrAreaWidget.stateHasChanged({})".format(checkedWidgetsAttrDescDict)) return def get_checked_widgets_name(self, group_name): widget = self.checkboxGroupWidgets.get(str(group_name), None) # LOG.info("AttrAreaWidget.get_checked_widgets_name ... widget = {}".format(widget)) checkedWidgetsNameList = widget.get_checked_widgets_name( ) if widget is not None else None # LOG.info("AttrAreaWidget.get_checked_widgets_name ... checkedWidget = {}".format(checkedWidget)) return checkedWidgetsNameList def add_hotkey(self, choice, name, hotkey): self.hotkeys.append((choice, name, hotkey)) def get_checked_widgets_attrDesc(self): descsDict = {} for widgetName, widgetInfo in self.checkboxWidgetsInfo.items(): if widgetInfo[0].isChecked(): desc = [None, None, None, None, None] desc[ checkedWidgetsAttrDescList_checkedWidget_idx] = widgetInfo[ 0] desc[ checkedWidgetsAttrDescList_checkedWidgetText_idx] = widgetInfo[ 1] desc[ checkedWidgetsAttrDescList_checkedWidgetColor_idx] = widgetInfo[ 2] desc[ checkedWidgetsAttrDescList_checkedWidgetStyleSheet_idx] = widgetInfo[ 3] descsDict[widgetName] = desc for widgetInfo in self.popupWidgetsInfo.values(): for actionWidget in widgetInfo[ popupWidgetsInfo_actionsWidgetList_idx]: if actionWidget.isChecked(): idx = widgetInfo[ popupWidgetsInfo_actionsWidgetList_idx].index( actionWidget) desc = [None, None, None, None, None] desc[ checkedWidgetsAttrDescList_checkedWidget_idx] = actionWidget desc[ checkedWidgetsAttrDescList_checkedWidgetText_idx] = widgetInfo[ popupWidgetsInfo_actionsTextList_idx][idx] desc[ checkedWidgetsAttrDescList_checkedWidgetColor_idx] = widgetInfo[ popupWidgetsInfo_actionsColorList_idx][idx] desc[ checkedWidgetsAttrDescList_checkedWidgetStyleSheet_idx] = widgetInfo[ popupWidgetsInfo_actionsWidgetStyleSheet_idx] desc[ checkedWidgetsAttrDescList_checkedWidgetPopupParentWidget_idx] = widgetInfo[ popupWidgetsInfo_pushButtonWidget_idx] widgetName = widgetInfo[ popupWidgetsInfo_actionsNameList_idx][idx] descsDict[widgetName] = desc return descsDict def startEditMode(self, model_items): return
class buttonWithOptionsWidget(QWidget): def __init__(self, annotation_scene, stateChangedSignalSlot=None, buttonWithOptionsProperty=None, displayName=None, parent=None): QWidget.__init__(self, parent) # print "buttonWithOptionsProperty = {}".format(comboPannelProperty) self.buttonWithOptionsProperty = buttonWithOptionsProperty self.name = displayName self.vlayout = QVBoxLayout() self.vlayout.setAlignment(Qt.AlignTop) self.vlayout.setSpacing(4) self.vlayout.setMargin(4) #self.vlayout.setContentsMargins(0, 0, 0, 44) self.vlayout.addWidget(self.propertyEditorWidget) self.vlayout.addWidget(self.attrAreaWidget) self.vlayout.addStretch(1) self.setLayout(self.vlayout) return def enableCheckbox(self, checkboxGroupName, checkboxName, enabled=True): groupWidget = self.checkboxGroupWidgets.get(checkboxGroupName, None) if groupWidget is not None: groupWidget.enable(checkboxName, enabled) def setCheckedCheckbox(self, checkboxName, checked=True): self.checkboxGroupWidget.setCheckedCheckbox(checkboxName, checked) def setCheckedCheckboxs(self, checkboxNamesList, checked=True): if checkboxNamesList is None: return groupWidget = self.checkboxGroupWidget.get(checkboxGroupName, None) if groupWidget is not None: # LOG.info(u"{} AttrAreaWidget.setCheckedCheckbox for group {} box {} checked {} ..".format(self.name, checkboxGroupName, checkboxNamesList, checked)) groupWidget.setCheckedCheckboxs(checkboxNamesList, checked) def sendCheckedSignal(self, checkboxGroupName): groupWidget = self.checkboxGroupWidgets.get(checkboxGroupName, None) if groupWidget is not None: groupWidget.sendCheckedSignal() def getCheckedWidgetsOptionInfo(self, checkboxGroupName): groupWidget = self.checkboxGroupWidgets.get(checkboxGroupName, None) if groupWidget is not None: return groupWidget.getCheckedWidgetsOptionInfo() return None, None def __init__(self, stateChangedSignalSlot=None, property=None, displayName=None, parent=None): QWidget.__init__(self, parent) self.hotkeys = [] self.name = displayName self.vlayout = MyVBoxLayout() #QVBoxLayout() self.vlayout.setAlignment(Qt.AlignTop) self.vlayout.setSpacing(4) self.vlayout.setMargin(4) #self.vlayout.setContentsMargins(0, 0, 0, 44) if stateChangedSignalSlot is not None: self.stateChanged.connect(stateChangedSignalSlot) # LOG.info("AttrAreaWidget constructor : property {} ...".format(property)) self.numGroups = len(property) if property is not None else 0 self.buttonGroupsDescDict = {} self.buttonGroupWidgets = {} for i in xrange(self.numGroups): thisGroupProperty = property[i] # thisGroupProperty is a dict thisGroupName = thisGroupProperty.get( 'name') # thisGroupName is a string thisGroupOption = thisGroupProperty.get( 'option' ) # thisGroupOption is a tuple of dicts. each dict describes a checkbox thisGroupText = thisGroupProperty.get('displaytext') thisGroup isExclusive = False if thisGroupName in config.NON_EXCLUSIVE_ATTRS_TAG_LIST else True if thisGroupName == config.ANNOTATION_PERSONBIKE_TYPE_GROUP_TOKEN: checkboxWidgetMinWidthInPixels = 52 else: checkboxWidgetMinWidthInPixels = 38 thisGroupWidget = checkBoxListWidget(thisGroupName, thisGroupText, isExclusive, thisGroupOption, self.stateChanged) if thisGroupName == config.ANNOTATION_UPPER_COLOR_TOKEN: thisGroupWidget.setMaxCheckedNum(config.MAX_UPPER_COLOR_NUMBER) thisGroupWidget.setMaxSeperateWidgetNum( config.GUI_MAX_SEPERATE_UPPER_COLOR_WIDGET_NUMBER) elif thisGroupName == config.ANNOTATION_LOWER_COLOR_TOKEN: thisGroupWidget.setMaxCheckedNum(config.MAX_LOWER_COLOR_NUMBER) thisGroupWidget.setMaxSeperateWidgetNum( config.GUI_MAX_SEPERATE_LOWER_COLOR_WIDGET_NUMBER) elif thisGroupName == config.ANNOTATION_VEHICLE_COLOR_TOKEN: thisGroupWidget.setMaxCheckedNum( config.MAX_VEHICLE_COLOR_NUMBER) thisGroupWidget.setMaxSeperateWidgetNum( config.GUI_MAX_SEPERATE_VEHICLE_COLOR_WIDGET_NUMBER) else: thisGroupWidget.setMaxCheckedNum( config.MAX_CHECKED_OPTIONS_NUMBER) thisGroupWidget.setMaxSeperateWidgetNum( config.MAX_OPTIONS_NUMBER) thisGroupCheckboxs = {} optCnt = 0 for checkboxOption in thisGroupOption: thisCheckboxName = checkboxOption[ config.METADATA_ATTR_VALUE_TOKEN] thisCheckboxText = checkboxOption[ config.METADATA_DISPLAYTEXT_TOKEN] thisCheckboxProperty = checkboxOption.copy() # get widget display color if thisGroupName == config.ANNOTATION_UPPER_COLOR_TOKEN or thisGroupName == config.ANNOTATION_LOWER_COLOR_TOKEN or thisGroupName == config.ANNOTATION_VEHICLE_COLOR_TOKEN: thisCheckboxBkgColorChecked = thisCheckboxProperty[ config.COLOR_ATTR_RGB_VALUE_TOKEN] thisCheckboxBkgColor = thisCheckboxBkgColorChecked else: thisCheckboxBkgColorChecked = thisCheckboxProperty[ config.METADATA_DISPLAYCOLOR_TOKEN] thisCheckboxBkgColor = None # calc widget text color # thisCheckboxBkgColorChecked string pattern: #123456 txtColorChecked = None if thisCheckboxBkgColorChecked is not None: import math rgba = utils.hexColorStrToRGBA(thisCheckboxBkgColorChecked) distance = math.sqrt((rgba[0] - 255)**2 + (rgba[1] - 255)**2 + (rgba[2] - 255)**2) txtColorChecked = '#ffffff' if distance > config.GUI_COLOR_TAG_TEXT_BLACKWHITE_TOGGLE_THRESHOLD else '#000000' txtColor = txtColorChecked if thisGroupName == config.ANNOTATION_UPPER_COLOR_TOKEN or thisGroupName == config.ANNOTATION_LOWER_COLOR_TOKEN or thisGroupName == config.ANNOTATION_VEHICLE_COLOR_TOKEN else None thisGroupCheckboxs[ thisCheckboxName] = thisCheckboxProperty # add checkbox record to this checkbox group record # add widget to this group if optCnt < thisGroupWidget._maxSeperateWidgetNum: thisGroupWidget.add_checkbox( thisCheckboxName, thisCheckboxText, thisCheckboxBkgColor, txtColor, thisCheckboxBkgColorChecked, txtColorChecked, checkboxWidgetMinWidthInPixels) else: thisGroupWidget.add_popup_button( config.GUI_MORE_WIDGET_DISPLAYTEXT, thisCheckboxName, thisCheckboxText, popupbutton_background_color="#808080", popupbutton_text_color="#ffffff", checkbox_background_color=thisCheckboxBkgColor, checkbox_text_color=txtColor) optCnt += 1 # thisGroupWidget.add_checkbox("Unset", u"Unset") thisGroupWidget.setLayout(thisGroupWidget.flayout) self.vlayout.addWidget(thisGroupWidget) self.checkboxGroupsDescDict[ thisGroupName] = thisGroupCheckboxs # add this checkbox group record to checkbox groups recrod self.checkboxGroupWidgets[thisGroupName] = thisGroupWidget # LOG.info("checkboxGroupWidgets = {} checkboxGroupsDescDict = {}".format(self.checkboxGroupWidgets, self.checkboxGroupsDescDict) self.vlayout.addStretch(1) self.setLayout(self.vlayout) return def stateHasChanged(self, checkedWidgetsAttrDescDict): # LOG.info("AttrAreaWidget.stateChanged with {}".format(checkedWidgetsAttrDescDict)) return def get_checked_widgets_name(self, group_name): widget = self.checkboxGroupWidgets.get(str(group_name), None) # LOG.info("AttrAreaWidget.get_checked_widgets_name ... widget = {}".format(widget)) checkedWidgetsNameList = widget.get_checked_widgets_name( ) if widget is not None else None # LOG.info("AttrAreaWidget.get_checked_widgets_name ... checkedWidget = {}".format(checkedWidget)) return checkedWidgetsNameList def add_hotkey(self, choice, name, hotkey): self.hotkeys.append((choice, name, hotkey)) def get_checked_widgets_attrDesc(self): descsDict = {} for widgetName, widgetInfo in self.checkboxWidgetsInfo.items(): if widgetInfo[0].isChecked(): desc = [None, None, None, None] desc[ checkedWidgetsAttrDescList_checkedWidget_idx] = widgetInfo[ 0] desc[ checkedWidgetsAttrDescList_checkedWidgetText_idx] = widgetInfo[ 1] desc[ checkedWidgetsAttrDescList_checkedWidgetStyleSheet_idx] = widgetInfo[ 2] descsDict[widgetName] = desc for widgetInfo in self.popupWidgetsInfo.values(): for actionWidget in widgetInfo[ popupWidgetsInfo_actionsWidgetList_idx]: if actionWidget.isChecked(): idx = widgetInfo[ popupWidgetsInfo_actionsWidgetList_idx].index( actionWidget) desc = [None, None, None, None] desc[ checkedWidgetsAttrDescList_checkedWidget_idx] = actionWidget desc[ checkedWidgetsAttrDescList_checkedWidgetText_idx] = widgetInfo[ popupWidgetsInfo_actionsTextList_idx][idx] desc[ checkedWidgetsAttrDescList_checkedWidgetStyleSheet_idx] = widgetInfo[ popupWidgetsInfo_actionsWidgetStyleSheet_idx] desc[ checkedWidgetsAttrDescList_checkedWidgetPopupParentWidget_idx] = widgetInfo[ popupWidgetsInfo_pushButtonWidget_idx] widgetName = widgetInfo[ popupWidgetsInfo_actionsNameList_idx][idx] descsDict[widgetName] = desc return descsDict def startEditMode(self, model_items): return