Exemplo n.º 1
0
def main():
    import sys

    app = QApplication(sys.argv)

    acmeSeries = QBoxPlotSeries()
    acmeSeries.setName("Acme Ltd")

    boxWhiskSeries = QBoxPlotSeries()
    boxWhiskSeries.setName("BoxWhisk Inc")

    acmeData = QFile(":acme")
    if not acmeData.open(QIODevice.ReadOnly | QIODevice.Text):
        sys.exit(1)

    dataReader = BoxDataReader(acmeData)
    while not dataReader.atEnd():
        _set = dataReader.readBox()
        if _set is not None:
            acmeSeries.append(_set)

    boxwhiskData = QFile(":boxwhisk")
    if not boxwhiskData.open(QIODevice.ReadOnly | QIODevice.Text):
        sys.exit(1)

    dataReader.readFile(boxwhiskData)
    while not dataReader.atEnd():
        _set = dataReader.readBox()
        if _set is not None:
            boxWhiskSeries.append(_set)

    chart = QChart()
    chart.addSeries(acmeSeries)
    chart.addSeries(boxWhiskSeries)
    chart.setTitle("Acme Ltd and BoxWhisk Inc share deviation in 2012")
    chart.setAnimationOptions(QChart.SeriesAnimations)

    chart.createDefaultAxes()
    chart.axes(Qt.Vertical)[0].setMin(15.0)
    chart.axes(Qt.Vertical)[0].setMax(34.0)

    chart.legend().setVisible(True)
    chart.legend().setAlignment(Qt.AlignBottom)

    chartView = QChartView(chart)
    chartView.setRenderHint(QPainter.Antialiasing)

    window = QMainWindow()
    window.setCentralWidget(chartView)
    window.resize(800, 600)
    window.show()

    sys.exit(app.exec_())
Exemplo n.º 2
0
def main():
    import sys

    app = QApplication(sys.argv)

    set0 = QBarSet("Jane")
    set1 = QBarSet("John")
    set2 = QBarSet("Axel")
    set3 = QBarSet("Mary")
    set4 = QBarSet("Samantha")

    set0 << 1 << 2 << 3 << 4 << 5 << 6
    set1 << 5 << 0 << 0 << 4 << 0 << 7
    set2 << 3 << 5 << 8 << 13 << 8 << 5
    set3 << 5 << 6 << 7 << 3 << 4 << 5
    set4 << 9 << 7 << 5 << 3 << 1 << 2

    series = QBarSeries()
    series.append(set0)
    series.append(set1)
    series.append(set2)
    series.append(set3)
    series.append(set4)

    chart = QChart()
    chart.addSeries(series)
    chart.setTitle("Simple barchart example")
    chart.setAnimationOptions(QChart.SeriesAnimations)

    categories = ("Jan", "Feb", "Mar", "Apr", "May", "Jun")
    axisX = QBarCategoryAxis()
    axisX.append(categories)
    chart.addAxis(axisX, Qt.AlignBottom)
    series.attachAxis(axisX)

    axisY = QValueAxis()
    axisY.setRange(0, 15)
    chart.addAxis(axisY, Qt.AlignLeft)
    series.attachAxis(axisY)

    chart.legend().setVisible(True)
    chart.legend().setAlignment(Qt.AlignBottom)

    chartView = QChartView(chart)
    chartView.setRenderHint(QPainter.Antialiasing)

    window = QMainWindow()
    window.setCentralWidget(chartView)
    window.resize(420, 300)
    window.show()

    sys.exit(app.exec_())
Exemplo n.º 3
0
def main():
    import sys

    a = QApplication(sys.argv)

    acmeSeries = QCandlestickSeries()
    acmeSeries.setName("Acme Ltd")
    acmeSeries.setIncreasingColor(QColor(Qt.green))
    acmeSeries.setDecreasingColor(QColor(Qt.red))

    acmeData = QFile(":acme")
    if not acmeData.open(QIODevice.ReadOnly | QIODevice.Text):
        sys.exit(1)

    categories = []

    dataReader = CandlestickDataReader(acmeData)
    while not dataReader.atEnd():
        _set = dataReader.readCandlestickSet()
        if _set is not None:
            acmeSeries.append(_set)
            categories.append(
                QDateTime.fromMSecsSinceEpoch(int(
                    _set.timestamp())).toString("dd"))

    chart = QChart()
    chart.addSeries(acmeSeries)
    chart.setTitle("Acme Ltd Historical Data (July 2015)")
    chart.setAnimationOptions(QChart.SeriesAnimations)

    chart.createDefaultAxes()

    axisX = chart.axes(Qt.Horizontal)[0]
    axisX.setCategories(categories)

    axisY = chart.axes(Qt.Vertical)[0]
    axisY.setMax(axisY.max() * 1.01)
    axisY.setMin(axisY.min() * 0.99)

    chart.legend().setVisible(True)
    chart.legend().setAlignment(Qt.AlignBottom)

    chartView = QChartView(chart)
    chartView.setRenderHint(QPainter.Antialiasing)

    window = QMainWindow()
    window.setCentralWidget(chartView)
    window.resize(800, 600)
    window.show()

    sys.exit(a.exec_())
Exemplo n.º 4
0
def main():
    import sys

    app = QApplication(sys.argv)

    series0 = QLineSeries()
    series1 = QLineSeries()

    series0 << QPointF(1, 5) << QPointF(3, 7) << QPointF(7, 6) << QPointF(
        9, 7) << QPointF(12, 6) << QPointF(16, 7) << QPointF(18, 5)
    series1 << QPointF(1, 3) << QPointF(3, 4) << QPointF(7, 3) << QPointF(
        8, 2) << QPointF(12, 3) << QPointF(16, 4) << QPointF(18, 3)

    series = QAreaSeries(series0, series1)
    series.setName("Batman")
    pen = QPen(0x059605)
    pen.setWidth(3)
    series.setPen(pen)

    gradient = QLinearGradient(QPointF(0, 0), QPointF(0, 1))
    gradient.setColorAt(0.0, QColor(0x3CC63C))
    gradient.setColorAt(1.0, QColor(0x26F626))
    gradient.setCoordinateMode(QGradient.ObjectBoundingMode)
    series.setBrush(gradient)

    chart = QChart()
    chart.addSeries(series)
    chart.setTitle("Simple areachart example")
    chart.createDefaultAxes()
    chart.axes(Qt.Horizontal)[0].setRange(0, 20)
    chart.axes(Qt.Vertical)[0].setRange(0, 10)

    chartView = QChartView(chart)
    chartView.setRenderHint(QPainter.Antialiasing)

    window = QMainWindow()
    window.setCentralWidget(chartView)
    window.resize(400, 300)
    window.show()

    sys.exit(app.exec_())
Exemplo n.º 5
0
class BootStrapWidget(maya.app.general.mayaMixin.MayaQWidgetDockableMixin, QWidget):
    width = maya.cmds.optionVar(query='workspacesWidePanelInitialWidth') * 0.75
    INITIAL_SIZE = QSize(width, 600)
    PREFERRED_SIZE = QSize(width, 420)
    MINIMUM_SIZE = QSize((width * 0.95), 220)

    def __init__(self, widget, title, icon=None, uid=None, parent=None):
        super(BootStrapWidget, self).__init__(parent=parent)

        self._preferred_size = self.PREFERRED_SIZE

        # This cannot be an empty string, otherwise Maya will get crazy
        uid = uid or title or 'BootstrapWidget'
        global BOOTSTRAP_WIDGETS
        BOOTSTRAP_WIDGETS[uid] = self

        # This was causing the dock widge to disappear after creation
        # Not sure why, maybe because the id had - characters, or because maybe there was a widget with the same
        # objectName, for now no setting an objectName seems to work fine
        # self.setObjectName(uid)
        self.setWindowTitle(title)
        if icon:
            self.setWindowIcon(icon)
        self._docking_frame = QMainWindow(self)
        self._docking_frame.layout().setContentsMargins(0, 0, 0, 0)
        self._docking_frame.setWindowFlags(Qt.Widget)
        self._docking_frame.setDockOptions(QMainWindow.AnimatedDocks)

        self.central_widget = widget
        self._docking_frame.setCentralWidget(self.central_widget)

        bootstrap_layout = layouts.VerticalLayout(spacing=0, margins=(0, 0, 0, 0))
        bootstrap_layout.addWidget(self._docking_frame, 0)
        self.setLayout(bootstrap_layout)
        widget.setProperty('bootstrapWidget', self)

    def __del__(self, *args, **kwargs):
        """
        Overriding to do nothing to avoid C++ object already deleted error
        since they try to destroy the workspace after its QObject has already been deleted
        """

        pass

    def setSizeHint(self, size):
        self._preferred_size = size

    def close(self, *args, **kwargs):
        """
        Overridden to call the bootstrap user widget.close()
        """

        self.central_widget.close()
        super(BootStrapWidget, self).close(*args, **kwargs)

    def show(self, **kwargs):
        name = self.objectName()
        name = name + "WorkspaceControl"
        if maya.cmds.workspaceControl(name, query=True, exists=True):
            maya.cmds.deleteUI(name)
            maya.cmds.workspaceControlState(name, remove=True)
        kwargs["retain"] = False
        kwargs["uiScript"] = 'try: from tpDcc.dccs.maya.ui import window;window.rebuild("{}")\n' \
                             'except ImportError: pass'.format(self.objectName())
        kwargs["closeCallback"] = 'try: from tpDcc.dccs.maya.ui import window;window.bootstrap_destroy_window("{}")\n' \
                                  'except ImportError: pass'.format(self.objectName())
        super(BootStrapWidget, self).show(**kwargs)