def _setupGUI(self): self._class_buttons = {} self._class_shortcuts = {} self._label_editor = None # Label class buttons self._classbox = QGroupBox("Labels", self) self._classbox_layout = FloatingLayout() self._classbox.setLayout(self._classbox_layout) # Global widget self._layout = MyVBoxLayout() self.setLayout(self._layout) self._layout.addWidget(self._classbox, 0) self._layout.addStretch(1)
def _setupGUI(self, _groupBoxName): self._widgets_dict = {} self._class_shortcuts = {} # Label class buttons qss = "QGroupBox::title {subcontrol-origin: margin; subcontrol-position: top left; padding: 0 3px; color : red; font-weight:bold; }" self._inserterButtonGroupbox = QGroupBox(_groupBoxName, self) self._inserterButtonGroupbox.setStyleSheet(qss) self._inserterButtonGroup_layout = FloatingLayout() self._inserterButtonGroupbox.setLayout( self._inserterButtonGroup_layout) # Global widget self._layout = MyVBoxLayout() self.setLayout(self._layout) self._layout.addWidget(self._inserterButtonGroupbox, 0) self._layout.addStretch(1)
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 _setupGUI(self): self._class_buttons = {} self.label_menu = {} self.label_action = {} self._label_editor = None # Label class buttons self._parea = QGroupBox("Labels") self._classbox = QScrollArea() self._classbox_layout = FloatingLayout() self._parea.setLayout(self._classbox_layout) self._parea.setGeometry(0, 0, 200, 200) self._classbox.setWidget(self._parea) self._classbox.setGeometry(0, 0, 100, 100) # 添加txt模块 self.combo_box = QComboBox() self._group_box_add_txt = QGroupBox('add_txt', self) self._group_box_add_txt_layout = QVBoxLayout() self._group_box_add_txt.setLayout(self._group_box_add_txt_layout) temp = cf.LABELS self.items = [] # 获取所有的标签 for i in temp: self.items.append(i['attributes']['class']) # 假如下拉框 self.combo_box.addItems(self.items) self.add_txt_btn = QPushButton('add txt') self.add_txt_btn.clicked.connect(self.add_txt) # 加入下拉框和按钮 self._group_box_add_txt_layout.addWidget(self.combo_box, 0) self._group_box_add_txt_layout.addWidget(self.add_txt_btn, 1) # 根据关键字搜索图片模块 self._group_box_add_files = QGroupBox('add files', self) # 文件名包含的 self._key_word = QLineEdit('') self._key_word.setPlaceholderText('Second') # 文件类型 self._extension = QLineEdit('') self._extension.setPlaceholderText('bmp') self._search_btn = QPushButton('search files') self._group_box_add_files_layout = QVBoxLayout() # 加入控件 self._group_box_add_files_layout.addWidget(self._key_word, 0) self._group_box_add_files_layout.addWidget(self._extension, 1) self._group_box_add_files_layout.addWidget(self._search_btn, 2) self._group_box_add_files.setLayout(self._group_box_add_files_layout) # 添加标签模块 self._group_box_add_label = QGroupBox("添加标签", self) self._add_label_group_layout = QVBoxLayout() self._group_box_add_label.setLayout(self._add_label_group_layout) # 标签的class self.attributes_LineEdit = QLineEdit('') self.attributes_LineEdit.setPlaceholderText('attributes') # 标签画出来的类型 self.attributes_type = QComboBox() self.attributes_type.addItems(self.get_attributes_type()) # 快捷键,目前设置了只允许一个键 self.hotkey = QLineEdit('') self.hotkey.setPlaceholderText('hotkey') self.regx = QRegExp("[a-z0-9]$") self.validator = QRegExpValidator(self.regx, self.hotkey) self.hotkey.setValidator(self.validator) # 标签显示 self.text_LineEdit = QLineEdit('') self.text_LineEdit.setPlaceholderText('text') # 颜色 color = QtGui.QColor(0, 0, 0) self.color_label = QtGui.QWidget() self.color_label.setStyleSheet("QWidget { background-color: %s }" % color.name()) self.color_info = [0, 0, 0] self.color_layout = QtGui.QHBoxLayout() self.color_btn = QPushButton('选择颜色') self.color_btn.clicked.connect(self.color_dialog) self.color_layout.addWidget(self.color_label) self.color_layout.addWidget(self.color_btn) # 笔刷 global brush2idx self.brush_combo_box = QComboBox() self.brush_combo_box.addItems(list(brush2idx.keys())) # 按钮 self.attributes_add_btn = QPushButton('添加标签') self.attributes_add_btn.clicked.connect(self.add_attributes) # 加入控件 self._add_label_group_layout.addWidget(self.attributes_LineEdit, 0) self._add_label_group_layout.addWidget(self.attributes_type, 1) self._add_label_group_layout.addWidget(self.hotkey, 2) self._add_label_group_layout.addWidget(self.text_LineEdit, 3) self._label_widget = QWidget() self._label_widget.setLayout(self.color_layout) self._add_label_group_layout.addWidget(self._label_widget, 4) self._add_label_group_layout.addWidget(self.brush_combo_box, 5) self._add_label_group_layout.addWidget(self.attributes_add_btn, 6) # 生成训练数据按钮 self._file_button = QPushButton('生成训练数据') self._file_button.clicked.connect(self.generate) # Global widget self._layout = MyVBoxLayout() self.setLayout(self._layout) self._layout.addWidget(self._classbox, 1) self._layout.insertWidget(-1, self._group_box_add_label, 1) self._layout.insertWidget(-1, self._group_box_add_txt, 1) self._layout.insertWidget(-1, self._group_box_add_files, 1) self._layout.insertWidget(-1, self._file_button, 1)
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