Example #1
0
 def __init__(self, widget, icon, title, description=None):
     super(Topbar, self).__init__()
     self.setupUi(widget)
     self.icon.setPixmap(QtGui.QPixmap(_fromUtf8(icon)))
     self.title.setText(title)
     if description is None:
         self.description.hide()
     else:
         self.description.setText(description)
Example #2
0
    def create_item(self, config, callback):
        """createItem adds a new item to the toolbar, the allowed items are:

            - *link*: a clicable element formed with an image,
                text and uri or path
            - *spacer*: a QSpacer to separete/pull the others items
            - *line*: a vertical line for a visual separation.

        The parameters are config and callback. Callback is the funcition
         called when a toolbar item has been activated, the config parameter
         is a dict and defines the kind of item to add to the toolbar and for
         the link items its params:
            - path: is the value that will be passed to the callback function.
            - name: the text that will appear under the image
            - image: image that will be used for the toolbar item.

        .. note::
            The items spacer/line doesn't have any parameter
        """
        widget = self.widget

        # Link
        if config['class'] == 'link':
            content = self.template % {
                'path': config['path'],
                'title': config['name'],
                'image': config['image']
            }
            item = QtGui.QLabel(widget)
            item.setText(content)
            item.setToolTip(config['name'])
            item.connect(
                item,
                QtCore.SIGNAL(_fromUtf8("linkActivated(QString)")),
                lambda s: callback(s))
        # Spacer
        elif config['class'] == 'spacer':
            item = QtGui.QSpacerItem(
                40,
                20,
                QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum
            )
        # Line
        elif config['class'] == 'line':
            item = QtGui.QFrame(widget)
            item.setFrameShape(QtGui.QFrame.VLine)
            item.setFrameShadow(QtGui.QFrame.Sunken)

        # Store a ref of the item inside the toolbar
        self.links.append(item)

        # Add the item to the container
        if isinstance(item, QtGui.QWidget):
            self.toolbarLinks.addWidget(item)
        else:
            self.toolbarLinks.addItem(item)