Ejemplo n.º 1
0
    def __init__(self, vm):
        super(VmTemplateItem, self).__init__()
        self.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled)
        self.vm = vm

        if vm.template is not None:
            self.setText(vm.template.name)
        else:
            font = QFont()
            font.setStyle(QFont.StyleItalic)
            self.setFont(font)
            self.setTextColor(QColor("gray"))

            if vm.is_appvm():  # and vm.template is None
                self.setText("StandaloneVM")
            elif vm.is_template():
                self.setText("TemplateVM")
            elif vm.qid == 0:
                self.setText("AdminVM")
            elif vm.is_netvm():
                self.setText("NetVM")
            else:
                self.setText("---")

        self.setTextAlignment(Qt.AlignVCenter)
Ejemplo n.º 2
0
    def update_items(self):
        self.item = QGraphicsRectItem(
            0, 0, self.width, self.row_h * self.coeff_h)
        seq_width = 0
        nopen = QPen(Qt.NoPen)
        self.item.setPen(nopen)
        font = QFont(self.ftype, self.fsize)
        if self.fstyle == "italic":
            font.setStyle(QFont.StyleItalic)
        elif self.fstyle == "oblique":
            font.setStyle(QFont.StyleOblique)
        rect_cls = QGraphicsRectItem
        for i, val in enumerate(self.liste):
            width = self.col_w
            height = self.row_h * len(str(val)) + 1
            rectitem = rect_cls(0, 0, width, height, parent=self.item)
            rectitem.setX(seq_width)  # to give correct X to children item
            rectitem.setBrush(QBrush(QColor(self.bgcolor)))
            rectitem.setPen(nopen)

            # write letter if enough space in height
            if height >= self.fsize:
                text = QGraphicsSimpleTextItem(str(val), parent=rectitem)
                text.setFont(font)
                text.setBrush(QBrush(QColor(self.fgcolor)))
                # Center text according to rectitem size
                # txtw = text.boundingRect().width()
                txth = text.boundingRect().height()
                text.setRotation(self.rot)
                text.setX(txth)
            seq_width += width
        self.width = seq_width
Ejemplo n.º 3
0
    def __init__(self, vm):
        super(VmTemplateItem, self).__init__()
        self.setFlags(Qt.ItemIsSelectable|Qt.ItemIsEnabled)
        self.vm = vm

        if vm.template is not None:
            self.setText(vm.template.name)
        else:
            font = QFont()
            font.setStyle(QFont.StyleItalic)
            self.setFont(font)
            self.setTextColor(QColor("gray"))

            if vm.is_appvm(): # and vm.template is None
                self.setText("StandaloneVM")
            elif vm.is_template():
                self.setText("TemplateVM")
            elif vm.qid == 0:
                self.setText("AdminVM")
            elif vm.is_netvm():
                self.setText("NetVM")
            else:
                self.setText("---")

        self.setTextAlignment(Qt.AlignVCenter)
Ejemplo n.º 4
0
 def popup_activer_module(self):
     u"""Affiche un menu permettant d'activer des modules."""
     menu = PopUpMenu(u"Module à activer", self, 'crayon')
     deja_charges = [onglet.__module__.split('.')[-1] for onglet in self]
     exercices = None
     for nom in param.modules:
         if nom not in deja_charges:
             titre = param.descriptions_modules[nom]['titre']
             if titre.startswith('Exercices - '):
                 if exercices is None:
                     exercices = menu.addMenu(u'Exercices')
                 action = exercices.addAction(titre[12:])
             else:
                 action = menu.addAction(titre)
             action.triggered.connect(partial(self.activer_module, nom, selectionner=True))
     menu.addSeparator()
     print png_pth('reload')
     action = menu.addAction(QIcon(png_pth('reload')), u"Restaurer la session précédente")
     action.setIconVisibleInMenu(True)
     action.triggered.connect(self.ChargerSessionPrecedente)
     font = QFont()
     ##font.setBold(True)
     font.setStyle(QFont.StyleItalic)
     action.setFont(font)
     menu.exec_(self.newTabButton.mapToGlobal(QPoint(0, self.newTabButton.height())))
Ejemplo n.º 5
0
 def get_font(self, key):
         font = QFont()
         try:
                 font = QFont(self.get(key + "_family"), int(self.get(key + '_size')))
                 font.setStyle(int(self.get(key + '_style')))
         except Exception as inst:                        
                 print inst
         return font
Ejemplo n.º 6
0
 def __init__(self, title, parent, icon=None):
     QMenu.__init__(self, title, parent)
     if icon is None:
         title = u'\u2022 ' + title
         self._title = self.addAction(title)
     else:
         if isinstance(icon, basestring):
             ##icon = QIcon(png(icon))
             icon = QIcon(png_pth(icon))
         self._title = self.addAction(icon, title)
     self._title.setEnabled(False)
     self._title.setIconVisibleInMenu(True)
     font = QFont()
     font.setBold(True)
     font.setStyle(QFont.StyleItalic)
     self._title.setFont(font)
     self.addSeparator()
Ejemplo n.º 7
0
def QFont_from_Font(font):
    """ Convert the given Enaml Font into a QFont.

    Parameters
    ----------
    font : Font
        The Enaml Font object.

    Returns
    -------
    result : QFont
        The QFont instance for the given Enaml font.

    """
    qfont = QFont(font.family, font.pointsize, font.weight)
    qfont.setStyle(font.style)
    qfont.setCapitalization(font.caps)
    return qfont
Ejemplo n.º 8
0
def QFont_from_Font(font):
    """ Convert the given Enaml Font into a QFont.

    Parameters
    ----------
    font : Font
        The Enaml Font object.

    Returns
    -------
    result : QFont
        The QFont instance for the given Enaml font.

    """
    qfont = QFont(font.family, font.pointsize, font.weight)
    qfont.setStyle(font.style)
    qfont.setCapitalization(font.caps)
    return qfont
Ejemplo n.º 9
0
def trinomial_face(binom,
                   spp,
                   ftype="Verdana",
                   fsize=10,
                   fgcolor="black",
                   fstyle="normal",
                   bold=False):
    """
    Stolen from:
    https://connorskennerton.wordpress.com/2016/11/16/python-ete3-formatting-organism-names-the-way-i-want/
    """

    font = QFont(ftype, fsize)
    font.setBold(bold)
    if fstyle == "italic":
        font.setStyle(QFont.StyleItalic)
    elif fstyle == "oblique":
        font.setStyle(QFont.StyleOblique)

    text = QGraphicsTextItem()
    text.setFont(font)
    if spp is None:
        text.setHtml("<i>{}</i>".format(binom))
    else:
        text.setHtml("<i>{}</i> {}".format(binom, spp))

    rect = QGraphicsRectItem(0, 0,
                             text.boundingRect().width(),
                             text.boundingRect().height() - 10)
    text.setParentItem(rect)
    center = rect.boundingRect().center()
    text.setPos(rect.boundingRect().x(),
                center.y() - text.boundingRect().height() / 2)

    # no border
    rect.setPen(QPen(QtCore.Qt.NoPen))

    return ete3.faces.StaticItemFace(rect)
Ejemplo n.º 10
0
    class NumberBar(QWidget):
        '''class that deifnes textEditor numberBar'''
        def __init__(self, editor):
            QWidget.__init__(self, editor)

            self.editor = editor
            self.editor.blockCountChanged.connect(self.updateWidth)
            self.editor.updateRequest.connect(self.updateContents)
            self.font = QFont()
            self.numberBarColor = QColor("#e8e8e8")

        def paintEvent(self, event):

            painter = QPainter(self)
            painter.fillRect(event.rect(), self.numberBarColor)

            block = self.editor.firstVisibleBlock()

            # Iterate over all visible text blocks in the document.
            while block.isValid():
                blockNumber = block.blockNumber()
                block_top = self.editor.blockBoundingGeometry(
                    block).translated(self.editor.contentOffset()).top()

                # Check if the position of the block is out side of the visible area.
                if not block.isVisible() or block_top >= event.rect().bottom():
                    break

                # We want the line number for the selected line to be bold.
                if blockNumber == self.editor.textCursor().blockNumber():
                    self.font.setBold(True)
                    painter.setPen(QColor("#000000"))
                else:
                    self.font.setBold(False)
                    painter.setPen(QColor("#717171"))
                painter.setFont(self.font)

                # Draw the line number right justified at the position of the line.
                paint_rect = QRect(0, block_top, self.width(),
                                   self.editor.fontMetrics().height())
                painter.drawText(paint_rect, Qt.AlignRight,
                                 str(blockNumber + 1))

                block = block.next()

            painter.end()

            QWidget.paintEvent(self, event)

        def getWidth(self):
            count = self.editor.blockCount()
            width = self.fontMetrics().width(str(count)) + 10
            return width

        def updateWidth(self):
            width = self.getWidth()
            if self.width() != width:
                self.setFixedWidth(width)
                self.editor.setViewportMargins(width, 0, 0, 0)

        def updateContents(self, rect, scroll):
            if scroll:
                self.scroll(0, scroll)
            else:
                self.update(0, rect.y(), self.width(), rect.height())

            if rect.contains(self.editor.viewport().rect()):
                fontSize = self.editor.currentCharFormat().font().pointSize()
                self.font.setPointSize(fontSize)
                self.font.setStyle(QFont.StyleNormal)
                self.updateWidth()