Exemple #1
0
 def __init__(self,
              master,
              enableDragDrop=False,
              dragDropCallback=None,
              dataValidityCallback=None,
              sizeHint=None,
              *args):
     """
     :param master: the master widget
     :type master: OWWidget or OWComponent
     :param enableDragDrop: flag telling whether drag and drop is enabled
     :type enableDragDrop: bool
     :param dragDropCallback: callback for the end of drop event
     :type dragDropCallback: function
     :param dataValidityCallback: callback that accepts or ignores dragEnter
         and dragMove events
     :type dataValidityCallback: function with one argument (event)
     :param sizeHint: size hint
     :type sizeHint: QSize
     :param args: optional arguments for the inherited constructor
     """
     self.master = master
     super().__init__(*args)
     self.drop_callback = dragDropCallback
     self.valid_data_callback = dataValidityCallback
     if not sizeHint:
         self.size_hint = QtCore.QSize(150, 100)
     else:
         self.size_hint = sizeHint
     if enableDragDrop:
         self.setDragEnabled(True)
         self.setAcceptDrops(True)
         self.setDropIndicatorShown(True)
    def sizeHint(self, option, index):
        options = QStyleOptionViewItem(option)
        self.initStyleOption(options, index)

        doc = QtGui.QTextDocument()
        doc.setHtml(options.text)
        doc.setTextWidth(options.rect.width())
        return QtCore.QSize(doc.idealWidth(), doc.size().height())
Exemple #3
0
    def value(self, value):
        ControlBase.value.fset(self, value)
        model = QFileSystemModel(parent=None)
        self._form.setModel(model)
        model.setRootPath(QtCore.QDir.currentPath())

        self._form.setRootIndex(model.setRootPath(value))

        self._form.setIconSize(QtCore.QSize(32, 32))
Exemple #4
0
 def __init__(self, *args, **kwargs):
     global games_json
     super().__init__("NSScreenshotMaker")
     self._tmpinputfolder = tempfile.mkdtemp()
     self._settingsbutton = ControlButton("⚙️")
     self._settingsbutton.value = self.openSettings
     self._runbutton = ControlButton("Go!")
     self._runbutton.value = self.go
     self._combo = ControlCombo(
         helptext="The game the Switch will think the screenshot is from")
     self.gameslist = games_json
     for k in self.gameslist:
         self._combo.add_item(k, self.gameslist[k])
     self._combo.add_item("Custom", "Custom")
     self._combolabel = ControlLabel(
         "Game ID",
         helptext="The game the Switch will think the screenshot is from")
     self._imagelist = ControlFilesTree()
     self._imagelist._form.setDragEnabled(True)
     self._imagelist._form.setAcceptDrops(True)
     self._imagelist._form.setDropIndicatorShown(True)
     self._imagelist._form.dropEvent = self.dropEvent
     model = QFileSystemModel(parent=None)
     model.setReadOnly(False)
     self._imagelist._form.setModel(model)
     model.setRootPath(QtCore.QDir.currentPath())
     self._imagelist._form.setRootIndex(
         model.setRootPath(self._tmpinputfolder))
     self._imagelist._form.setIconSize(QtCore.QSize(32, 32))
     self.formset = [("_combolabel", "_combo", "_settingsbutton"),
                     "_imagelist", "_runbutton"]
     self._firstrunpanel = ControlDockWidget()
     self._firstrunpanel.hide()
     self._firstrunwin = FirstRun()
     if not os.path.isfile(
             appdirs.AppDirs("NSScreenshotMaker", "").user_data_dir +
             "/settings.json"):
         self._firstrunwin.parent = self
         self._firstrunpanel.value = self._firstrunwin
         self._firstrunpanel.show()
         self._firstrunwin.show()
     self._settingspanel = ControlDockWidget()
     self._settingspanel.hide()
     self._settingswin = SettingsWindow()
 def _get_buffer(size, filename):
     buffer = QtSvg.QSvgGenerator()
     buffer.setFileName(filename)
     buffer.setSize(QtCore.QSize(int(size.width()), int(size.height())))
     return buffer
Exemple #6
0
 def icon_size(self, value):
     if isinstance(value, (tuple, list)):
         self.tableWidget.setIconSize(QtCore.QSize(*value))
     else:
         self.tableWidget.setIconSize(QtCore.QSize(value, value))
    def paint(self, painter, option, index):
        dist = self.distribution(index)
        if dist is None or self.__colors is None:
            return super().paint(painter, option, index)
        if not numpy.isfinite(numpy.sum(dist)):
            return super().paint(painter, option, index)

        nvalues = len(dist)
        if len(self.__colors) < nvalues:
            colors = colorpalette.ColorPaletteGenerator(nvalues)
            colors = [colors[i] for i in range(nvalues)]
        else:
            colors = self.__colors

        if option.widget is not None:
            style = option.widget.style()
        else:
            style = QApplication.style()

        self.initStyleOption(option, index)

        text = option.text
        metrics = option.fontMetrics

        margin = style.pixelMetric(QStyle.PM_FocusFrameHMargin, option,
                                   option.widget) + 1
        bottommargin = min(margin, 1)
        rect = option.rect.adjusted(margin, margin, -margin, -bottommargin)

        textrect = style.subElementRect(QStyle.SE_ItemViewItemText, option,
                                        option.widget)
        # Are the margins included in the subElementRect?? -> No!
        textrect = textrect.adjusted(margin, margin, -margin, -bottommargin)

        text = option.fontMetrics.elidedText(text, option.textElideMode,
                                             textrect.width())

        spacing = max(metrics.leading(), 1)

        distheight = rect.height() - metrics.height() - spacing
        distheight = numpy.clip(distheight, 2, metrics.height())

        painter.save()
        painter.setClipRect(option.rect)
        painter.setFont(option.font)
        painter.setRenderHint(QPainter.Antialiasing)

        style.drawPrimitive(QStyle.PE_PanelItemViewRow, option, painter,
                            option.widget)
        style.drawPrimitive(QStyle.PE_PanelItemViewItem, option, painter,
                            option.widget)

        if option.state & QStyle.State_Selected:
            color = option.palette.highlightedText().color()
        else:
            color = option.palette.text().color()
        painter.setPen(QtGui.QPen(color))

        textrect = textrect.adjusted(0, 0, 0, -distheight - spacing)
        distrect = QtCore.QRect(
            textrect.bottomLeft() + QtCore.QPoint(0, spacing),
            QtCore.QSize(rect.width(), distheight))
        painter.setPen(QtGui.QPen(Qt.lightGray, 0.3))
        drawDistBar(painter, distrect, dist, colors)
        painter.restore()
        if text:
            style.drawItemText(painter, textrect, option.displayAlignment,
                               option.palette,
                               option.state & QStyle.State_Enabled, text)
Exemple #8
0
 def _get_buffer(size, filename):
     buffer = QtSvg.QSvgGenerator()
     buffer.setResolution(QApplication.desktop().logicalDpiX())
     buffer.setFileName(filename)
     buffer.setSize(QtCore.QSize(int(size.width()), int(size.height())))
     return buffer
Exemple #9
0
 def icon_size(self, value):
     self.setIconSize(QtCore.QSize(*value))
Exemple #10
0
 def sizeHint(self):
     """Reimplemented from QWidget.sizeHint"""
     return QtCore.QSize(100, 200)