Exemplo n.º 1
0
class Title(QWidget):
    def __init__(self, foldable_data, parent=None):
        QWidget.__init__(self, parent)

        self.foldable = False

        #Contained widgets
        self.fold_button = FoldButton()
        self.noop_button = NoopButton()
        self.name = QLabel()
        self.abstract = foldable_data.abstract
        self.edit_button = EditButton()

        #Layout
        box = QHBoxLayout(self)
        box.setMargin(0)
        box.setAlignment(Qt.AlignLeft)
        box.addWidget(self.fold_button)
        box.addWidget(self.noop_button)
        box.addWidget(self.name)
        box.addWidget(self.abstract)
        box.addStretch()
        box.addWidget(self.edit_button)
        self.setFoldable(True)

        #SIGNALS to update content
        self.connect(foldable_data, SIGNAL('name changed'), self.setName)
        self.connect(foldable_data, SIGNAL('menu changed'), self.setMenu)

        #Initialize content
        self.setName(foldable_data.name)
        self.setMenu(foldable_data.menu)

    def setName(self, name):
        self.name.setText('<h2>%s</h2>' % name)

    def setMenu(self, menu):
        self.edit_button.setMenu(menu)

    def mouseDoubleClickEvent(self, event):
        """
        double clicking on elements' title bar has the same effect
        as clicking on expand/collapse button
        """
        if not self.foldable:
            return
        self.fold_button.emit(SIGNAL('clicked()'))

    def setFoldable(self, foldable):
        if foldable == self.foldable:
            return

        self.foldable = foldable

        if foldable:
            self.fold_button.show()
            self.noop_button.hide()
            return
        self.fold_button.hide()
        self.noop_button.show()
Exemplo n.º 2
0
    def __init__(self, foldable_data, parent=None):
        QWidget.__init__(self, parent)

        self.foldable = False

        #Contained widgets
        self.fold_button = FoldButton()
        self.noop_button = NoopButton()
        self.name = QLabel()
        self.abstract = foldable_data.abstract
        self.edit_button = EditButton()

        #Layout
        box = QHBoxLayout(self)
        box.setMargin(0)
        box.setAlignment(Qt.AlignLeft)
        box.addWidget(self.fold_button)
        box.addWidget(self.noop_button)
        box.addWidget(self.name)
        box.addWidget(self.abstract)
        box.addStretch()
        box.addWidget(self.edit_button)
        self.setFoldable(True)

        #SIGNALS to update content
        self.connect(foldable_data, SIGNAL('name changed'), self.setName)
        self.connect(foldable_data, SIGNAL('menu changed'), self.setMenu)

        #Initialize content
        self.setName(foldable_data.name)
        self.setMenu(foldable_data.menu)