def add_item(self, data_dict, index=None): """Add a item""" button = MToolButton() button.setText(data_dict.get('text')) if data_dict.get('svg'): button.svg(data_dict.get('svg')) if data_dict.get('tooltip'): button.setProperty('toolTip', data_dict.get('tooltip')) if data_dict.get('clicked'): button.clicked.connect(data_dict.get('clicked')) if data_dict.get('text'): if data_dict.get('svg') or data_dict.get('icon'): button.text_beside_icon() else: button.text_only() else: button.icon_only() if self._button_group.buttons(): separator = MLabel(self._separator).secondary() self._label_list.append(separator) self._main_layout.insertWidget(self._main_layout.count() - 1, separator) self._main_layout.insertWidget(self._main_layout.count() - 1, button) if index is None: self._button_group.addButton(button) else: self._button_group.addButton(button, index)
def create_button(self, data_dict): button = MToolButton() if data_dict.get('svg'): button.svg(data_dict.get('svg')) if data_dict.get('text'): if data_dict.get('svg') or data_dict.get('icon'): button.text_beside_icon() else: button.text_only() else: button.icon_only() return button