def set_items(self, items, parent = None): logger.debug('setting items for current navpane section') section_tree = self.findChild(QtGui.QWidget, 'SectionTree') if section_tree: if parent == None: # take a copy, so the copy can be extended self._items = list(i for i in items) section_tree.clear() section_tree.clear_model_items() parent = section_tree if not items: return for item in items: label = item.get_verbose_name() icon = item.get_icon() model_item = ModelItem( parent, [unicode(label)], item ) if icon: model_item.set_icon(icon.getQIcon()) section_tree.modelitems.append( model_item ) if isinstance( item, Section ): child_items = item.get_items() self.set_items( child_items, parent = model_item ) self._items.extend( child_items ) section_tree.resizeColumnToContents( 0 )
def set_items(self, items): logger.debug('setting items for current navpane section') section_tree = self.findChild(QtGui.QWidget, 'SectionTree') self._items = items if section_tree: section_tree.clear() section_tree.clear_model_items() if not items: return for item in items: label = item.get_verbose_name() icon = item.get_icon() model_item = ModelItem( section_tree, [unicode(label)], item ) if icon: model_item.set_icon(icon.getQIcon()) section_tree.modelitems.append( model_item ) section_tree.resizeColumnToContents( 0 )
def set_items(self, items): logger.debug('setting items for current navpane section') section_tree = self.findChild(QtGui.QWidget, 'SectionTree') self._items = items if section_tree: section_tree.clear() section_tree.clear_model_items() if not items: return for item in items: label = item.get_verbose_name() model_item = ModelItem(section_tree, [label]) section_tree.modelitems.append(model_item)
def __init__(self, parent, admin): ModelItem.__init__(self, parent, [admin.get_verbose_name()], None) self.admin = admin
class NavigationPane(QDockWidget): """NavigationPane made of PaneButtons and ModelTrees""" def __init__(self, app_admin, workspace, parent): super(QDockWidget, self).__init__(parent) self.workspace = workspace self.app_admin = app_admin self._sections = None self._animation = QtCore.QParallelAnimationGroup() self._animation.finished.connect( self.animation_finished ) self._title_widget = QWidget() self._dock_widget = self.get_dock_widget() self._dock_widget.setMouseTracking(True) self._current_tree_widget = None # hack for removing the dock title bar self.setTitleBarWidget(self._title_widget) self.setWidget(self._dock_widget) self.setFeatures(QDockWidget.NoDockWidgetFeatures) self.app_admin.sections_changed_signal.connect(self.update_sections) self.update_sections() @QtCore.pyqtSlot() def update_sections(self): post(self.app_admin.get_sections, self.set_sections) @QtCore.pyqtSlot() def animation_finished(self): """Once the animation is finished, hide all non active section trees""" layout = self._dock_widget.layout() for i in range( layout.count() ): if i%2 == 1: section_tree = layout.itemAt( i ).widget() if section_tree != self._current_tree_widget: section_tree.hide() def get_dock_widget(self): layout = QVBoxLayout() layout.setContentsMargins(0,0,0,0) layout.setSpacing(0) dw = QWidget() dw.setLayout(layout) return dw def get_tree_widget(self): tw = ModelTree(parent=self) tw.setObjectName('PaneTree') # i hate the sunken frame style tw.setFrameShape(QFrame.NoFrame) tw.setFrameShadow(QFrame.Plain) tw.contextmenu = QMenu(self) act = ActionFactory.new_tab(self, self.open_in_new_view) tw.contextmenu.addAction(act) tw.setContextMenuPolicy(Qt.CustomContextMenu) tw.customContextMenuRequested.connect(self.create_context_menu) return tw def get_sections(self): return self._sections def set_sections(self, sections): logger.debug('setting navpane sections') animation = QtCore.QPropertyAnimation(self._dock_widget, 'minimumWidth', self) animation.setDuration( 500 ) animation.setStartValue( 10 ) animation.setEndValue( 220 ) animation.start() self._sections = sections self._buttons = [( index, section.get_verbose_name(), section.get_icon().getQPixmap(), ) for index, section in enumerate(sections)] for index, name, pixmap in self._buttons: tree_widget = self.get_tree_widget() if index!=0: tree_widget.setMaximumHeight(0) pane_button = PaneButton(name, pixmap) pane_button.pressed.connect(self.change_current) self._dock_widget.layout().addWidget(pane_button) self._dock_widget.layout().addWidget(tree_widget) last_tree_index = self._dock_widget.layout().count() - 1 def get_models_for_tree(): return (last_tree_index, self._sections[index].get_items()) post(get_models_for_tree, self.set_models_for_tree) self.change_current(0) def set_models_for_tree(self, (tree_index, items)): tree_widget = self._dock_widget.layout().itemAt(tree_index).widget() for item in items: label = item.get_verbose_name() tree_widget.section_items.append(item) tree_widget.modelitems.append(ModelItem(tree_widget, [label])) tree_widget.itemClicked.connect(self.open_in_current_view)