def __init__(self, *args, **kwargs): super(Widget_TypeAttributeList, self).__init__(*args, **kwargs) self.installEventFilter(self) mainLayout = QVBoxLayout(self) mainLayout.setContentsMargins(0, 0, 0, 5) groupBox = QGroupBox("Search Attribute Types") groupBoxLayout = QVBoxLayout() groupBox.setStyleSheet("font-size:12px") groupBox.setLayout(groupBoxLayout) groupBoxLayout.setContentsMargins(0, 0, 0, 0) scrollArea = QScrollArea() scrollArea.setStyleSheet("font-size:11px") scrollAreaWidget = QWidget() scrollAreaLayout = QVBoxLayout(scrollAreaWidget) scrollArea.setWidgetResizable(True) scrollArea.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Ignored) scrollArea.setWidget(scrollAreaWidget) scrollAreaLayout.setContentsMargins(5, 0, 5, 0) scrollArea.resize(scrollArea.sizeHint()) groupBoxLayout.addWidget(scrollArea) self.get_csv_form_google_spreadsheets(Widget_TypeAttributeList.url, Widget_TypeAttributeList.csv) dict_list = self.get_dictList_from_csvPath( Widget_TypeAttributeList.csv) self.w_typeAttrs = [] for dict_data in dict_list: w_typeAttr = Widget_TypeAttribute(attr_name=dict_data['attr_name'], type_node=dict_data['type_node']) scrollAreaLayout.addWidget(w_typeAttr) self.w_typeAttrs.append(w_typeAttr) empty = QLabel() empty.setMinimumHeight(0) scrollAreaLayout.addWidget(empty) mainLayout.addWidget(groupBox) self.resize(0, 100)
class MetadataView(QAbstractItemView): MESSAGE_NO_SELECTION = 'Metadata' MESSAGE_SINGLE_SELECTION = 'Metadata for 1 box' MESSAGE_MULTIPLE_SELECTION = 'Metadata for {0} boxes' def __init__(self, parent=None): # This view is never made visible super(MetadataView, self).__init__() # A container for the controls self._form_container = FormContainer() # A scrollable container for the form self._form_scroll = QScrollArea(parent) self._form_scroll.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) self._form_scroll.setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded) self._form_scroll.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) self._form_scroll.setWidget(self._form_container) # Make the controls fill the available horizontal space # http://qt-project.org/forums/viewthread/11012 self._form_scroll.setWidgetResizable(True) # Title self._title = QLabel() # Title is fixed at the top - form can be scrolled layout = QVBoxLayout() layout.addWidget(self._title) layout.addWidget(self._form_scroll) # Top-level container for the title and form self.widget = QWidget(parent) self.widget.setLayout(layout) def reset(self): """QAbstractItemView virtual """ debug_print('MetadataView.reset') super(MetadataView, self).reset() # Clear the controls self.selectionChanged([], []) def selectionChanged(self, selected, deselected): """QAbstractItemView slot """ debug_print('MetadataView.selectionChanged') selected = self.selectionModel().selectedIndexes() # Set title if 1 == len(selected): title = self.MESSAGE_SINGLE_SELECTION elif selected: title = self.MESSAGE_MULTIPLE_SELECTION.format(len(selected)) else: title = self.MESSAGE_NO_SELECTION self._title.setText(title) # TODO Combo should indicate multiple and unrecognised values # Put values into the controls metadata = [i.data(MetadataRole) for i in selected] for field, control in self._form_container.controls.iteritems(): values = {m.get(field, '') for m in metadata} control.selection_changed(selected, values)